create-nextblock 0.15.5 → 0.15.9

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 (79) hide show
  1. package/package.json +50 -26
  2. package/templates/nextblock-template/app/ToasterProvider.tsx +26 -17
  3. package/templates/nextblock-template/app/actions/contactSellerActions.test.ts +280 -0
  4. package/templates/nextblock-template/app/actions/contactSellerActions.ts +222 -0
  5. package/templates/nextblock-template/app/actions/email-retry.test.ts +62 -0
  6. package/templates/nextblock-template/app/actions/email.ts +241 -110
  7. package/templates/nextblock-template/app/actions/formActions.ts +245 -116
  8. package/templates/nextblock-template/app/actions/interactions.ts +489 -396
  9. package/templates/nextblock-template/app/actions/threadActions.ts +166 -0
  10. package/templates/nextblock-template/app/api/checkout/route.ts +162 -146
  11. package/templates/nextblock-template/app/api/cron/reset-sandbox/route.ts +14 -0
  12. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +664 -1
  13. package/templates/nextblock-template/app/checkout/page.tsx +57 -52
  14. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +552 -529
  15. package/templates/nextblock-template/app/cms/blocks/editors/FormBlockEditor.tsx +304 -181
  16. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -0
  17. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -0
  18. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -528
  19. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -0
  20. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -0
  21. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -51
  22. package/templates/nextblock-template/app/cms/layout.tsx +101 -73
  23. package/templates/nextblock-template/app/cms/messages/MessagesClient.tsx +661 -0
  24. package/templates/nextblock-template/app/cms/messages/actions.ts +404 -0
  25. package/templates/nextblock-template/app/cms/messages/loadInbox.ts +333 -0
  26. package/templates/nextblock-template/app/cms/messages/page.tsx +87 -0
  27. package/templates/nextblock-template/app/cms/messages/require-admin.ts +37 -0
  28. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -362
  29. package/templates/nextblock-template/app/cms/revisions/service.ts +20 -0
  30. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -185
  31. package/templates/nextblock-template/app/layout.tsx +671 -667
  32. package/templates/nextblock-template/app/lib/seo.ts +319 -311
  33. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -482
  34. package/templates/nextblock-template/app/providers.tsx +96 -96
  35. package/templates/nextblock-template/app/thread/ThreadView.tsx +164 -0
  36. package/templates/nextblock-template/app/thread/[token]/route.ts +57 -0
  37. package/templates/nextblock-template/app/thread/layout.tsx +15 -0
  38. package/templates/nextblock-template/app/thread/page.tsx +98 -0
  39. package/templates/nextblock-template/components/BlockRenderer.tsx +312 -296
  40. package/templates/nextblock-template/components/ContactSellerSection.tsx +188 -0
  41. package/templates/nextblock-template/components/PostCommentsSection.tsx +378 -369
  42. package/templates/nextblock-template/components/ProductReviewsSection.tsx +426 -419
  43. package/templates/nextblock-template/components/StaffReplies.tsx +102 -0
  44. package/templates/nextblock-template/components/blocks/renderers/CartBlockRenderer.tsx +18 -17
  45. package/templates/nextblock-template/components/blocks/renderers/CheckoutBlockRenderer.tsx +20 -19
  46. package/templates/nextblock-template/components/blocks/renderers/FeaturedProductBlockRenderer.tsx +25 -22
  47. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +385 -381
  48. package/templates/nextblock-template/components/blocks/renderers/ProductDetailsBlockRenderer.tsx +157 -92
  49. package/templates/nextblock-template/components/blocks/renderers/ProductGridBlockRenderer.tsx +34 -31
  50. package/templates/nextblock-template/components/blocks/renderers/SectionBlockRenderer.tsx +612 -600
  51. package/templates/nextblock-template/components/commerce/PaymentReadinessBoundary.tsx +32 -0
  52. package/templates/nextblock-template/docs/05-DEVELOPER-GUIDE.md +25 -19
  53. package/templates/nextblock-template/docs/06-CLI-AND-SCAFFOLDING.md +1 -1
  54. package/templates/nextblock-template/docs/08-NEXTBLOCK-CORTEX-AI-ARCHITECTURE.md +2 -2
  55. package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +32 -9
  56. package/templates/nextblock-template/docs/14-MESSAGES-INBOX.md +309 -0
  57. package/templates/nextblock-template/docs/README.md +42 -41
  58. package/templates/nextblock-template/docs/TECHNICAL_SPECIFICATION.md +540 -542
  59. package/templates/nextblock-template/docs/assets/lighthouse-scores.png +0 -0
  60. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +22 -2
  61. package/templates/nextblock-template/lib/blocks/blockColors.ts +44 -1
  62. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +761 -753
  63. package/templates/nextblock-template/lib/cms/contact-reminder.ts +64 -0
  64. package/templates/nextblock-template/lib/cms/payments-reminder.ts +98 -0
  65. package/templates/nextblock-template/lib/cms/unread-messages.ts +42 -0
  66. package/templates/nextblock-template/lib/commerce/seller-contact.ts +162 -0
  67. package/templates/nextblock-template/lib/config/email-settings.ts +323 -254
  68. package/templates/nextblock-template/lib/config/email-tls.test.ts +57 -0
  69. package/templates/nextblock-template/lib/email/placeholder-address.test.ts +59 -0
  70. package/templates/nextblock-template/lib/email/placeholder-address.ts +39 -0
  71. package/templates/nextblock-template/lib/messages/thread-reference.test.ts +70 -0
  72. package/templates/nextblock-template/lib/messages/thread-token.test.ts +93 -0
  73. package/templates/nextblock-template/lib/messages/thread-token.ts +157 -0
  74. package/templates/nextblock-template/lib/messages/threads.ts +579 -0
  75. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +20 -0
  76. package/templates/nextblock-template/lib/site-url.test.ts +89 -0
  77. package/templates/nextblock-template/lib/site-url.ts +102 -48
  78. package/templates/nextblock-template/package.json +14 -1
  79. package/templates/nextblock-template/public/assets/nextblock-banner.jpg +0 -0
@@ -1,600 +1,612 @@
1
- // components/blocks/renderers/SectionBlockRenderer.tsx
2
- import React from "react";
3
- import Image from "next/image";
4
- import type { SectionBlockContent } from "../../../lib/blocks/blockRegistry";
5
- import { buildVisualEditAttributes } from "../../../lib/visual-editing/edit-info";
6
- import type {
7
- VisualEditAttributes,
8
- VisualEditingDocumentContext,
9
- } from "../../../lib/visual-editing/types";
10
- import { getPublicBlockRendererLoader } from "../publicRendererLoaders";
11
- import SectionSlider from "./SectionSlider";
12
- import { getCachedCustomBlockDefinitionBySlug } from "../../../lib/custom-block-definitions";
13
- import { CachedDynamicLayoutEngine } from "../../renderers/CachedDynamicLayoutEngine";
14
- import { resolveBlockRelations } from "../../../lib/resolve-block-relations";
15
-
16
- // Static imports for core block renderers for LCP/performance optimization
17
- import TextBlockRenderer from "./TextBlockRenderer";
18
- import HeadingBlockRenderer from "./HeadingBlockRenderer";
19
- import ImageBlockRenderer from "./ImageBlockRenderer";
20
- import ButtonBlockRenderer from "./ButtonBlockRenderer";
21
- import { StockPhotoCredit } from "./StockPhotoCredit";
22
-
23
- const R2_BASE_URL = process.env.NEXT_PUBLIC_R2_BASE_URL || "";
24
- const BACKGROUND_COMPOSITING_CLASSES =
25
- "isolate transform-gpu [backface-visibility:hidden] [transform-style:preserve-3d]";
26
- const ABSOLUTE_BACKGROUND_CLASSES =
27
- "pointer-events-none absolute inset-[-1px] -z-10 transform-gpu [backface-visibility:hidden] [transform-style:preserve-3d]";
28
- const ECOMMERCE_BLOCK_TYPES = new Set([
29
- "product_grid",
30
- "featured_product",
31
- "cart",
32
- "checkout",
33
- "product_details",
34
- ]);
35
-
36
- function loadEcommerceBlockRenderer(blockType: string) {
37
- return import("../ecommerceRendererLoaders").then((module) =>
38
- module.loadEcommerceBlockRenderer(blockType)
39
- );
40
- }
41
-
42
- type SectionBackgroundImage = NonNullable<
43
- NonNullable<SectionBlockContent["background"]>["image"]
44
- >;
45
-
46
- // Renders a section's background image. External https URLs (e.g. AI-inserted
47
- // stock photos) use a plain <img> so any allowlisted host works without Next
48
- // image remotePatterns config; stored R2 media keeps the optimized next/image
49
- // path. Returns null when neither a URL nor an object key is present.
50
- function renderBackgroundImageElement(image: SectionBackgroundImage, priority: boolean) {
51
- const externalUrl =
52
- typeof image.external_url === "string" && /^https?:\/\//i.test(image.external_url.trim())
53
- ? image.external_url.trim()
54
- : null;
55
- const objectFit: "cover" | "contain" = image.size === "contain" ? "contain" : "cover";
56
- const objectPosition = image.position || "center";
57
-
58
- if (externalUrl) {
59
- return (
60
- // eslint-disable-next-line @next/next/no-img-element
61
- <img
62
- src={externalUrl}
63
- alt={image.alt_text || ""}
64
- loading={priority ? "eager" : "lazy"}
65
- fetchPriority={priority ? "high" : "auto"}
66
- decoding="async"
67
- className="absolute inset-0 h-full w-full"
68
- style={{ objectFit, objectPosition }}
69
- />
70
- );
71
- }
72
-
73
- if (!image.object_key) {
74
- return null;
75
- }
76
-
77
- return (
78
- <Image
79
- src={`${R2_BASE_URL}/${image.object_key}`}
80
- alt={image.alt_text || ""}
81
- fill
82
- priority={priority}
83
- fetchPriority={priority ? "high" : "auto"}
84
- placeholder={image.blur_data_url ? "blur" : "empty"}
85
- blurDataURL={image.blur_data_url || undefined}
86
- quality={image.quality || 80}
87
- sizes="100vw"
88
- style={{ objectFit, objectPosition }}
89
- />
90
- );
91
- }
92
-
93
- interface SectionBlockRendererProps {
94
- content: SectionBlockContent;
95
- languageId: number;
96
- visualEditAttributes?: VisualEditAttributes;
97
- visualEditing?: VisualEditingDocumentContext;
98
- parentBlockId?: number;
99
- parentBlockIndex?: number;
100
- blockType?: "section";
101
- botProtectionPublic?: BotProtectionPublicSettings;
102
- scriptNonce?: string;
103
- }
104
-
105
- type BotProtectionPublicSettings = {
106
- provider: 'none' | 'turnstile' | 'recaptcha';
107
- siteKey: string;
108
- };
109
-
110
- // Container class mapping
111
- const containerClasses = {
112
- 'full-width': 'w-full',
113
- 'container': 'container mx-auto px-4',
114
- 'container-sm': 'container mx-auto px-4 max-w-screen-sm',
115
- 'container-lg': 'container mx-auto px-4 max-w-screen-lg',
116
- 'container-xl': 'container mx-auto px-4 max-w-screen-xl'
117
- };
118
-
119
- // Column grid classes
120
- const columnClasses = {
121
- 1: 'grid-cols-1',
122
- 2: 'grid-cols-1 md:grid-cols-2',
123
- 3: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
124
- 4: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4'
125
- };
126
-
127
- // Gap classes
128
- const gapClasses = {
129
- none: 'gap-0',
130
- sm: 'gap-2',
131
- md: 'gap-4',
132
- lg: 'gap-6',
133
- xl: 'gap-8'
134
- };
135
-
136
- // Padding classes
137
- const paddingClasses = {
138
- none: '',
139
- sm: 'py-2',
140
- md: 'py-4',
141
- lg: 'py-8',
142
- xl: 'py-12'
143
- };
144
-
145
- // Vertical alignment classes
146
- const verticalAlignmentClasses = {
147
- start: 'items-start',
148
- center: 'items-center',
149
- end: 'items-end',
150
- stretch: 'items-stretch'
151
- };
152
-
153
- function formatMinHeight(value?: string) {
154
- if (!value) return undefined;
155
- const trimmed = value.trim();
156
- if (/^\d+$/.test(trimmed)) {
157
- return `${trimmed}px`;
158
- }
159
- return trimmed;
160
- }
161
-
162
- function formatStopPosition(position: number) {
163
- return Number.isInteger(position) ? String(position) : position.toFixed(1);
164
- }
165
-
166
- function formatGradientStops(stops: Array<{ color: string; position: number }>) {
167
- return stops
168
- .map((stop, index) => {
169
- const previous = stops[index - 1];
170
- const next = stops[index + 1];
171
- let position = stop.position;
172
-
173
- if (next && next.position === stop.position && stop.position > 0) {
174
- position = stop.position - 0.1;
175
- } else if (previous && previous.position === stop.position && stop.position < 100) {
176
- position = stop.position + 0.1;
177
- }
178
-
179
- return `${stop.color} ${formatStopPosition(position)}%`;
180
- })
181
- .join(', ');
182
- }
183
-
184
- // Background style generator (handles solid, theme and gradients; image handled in JSX)
185
- function generateBackgroundStyles(background: SectionBlockContent['background']) {
186
- const styles: React.CSSProperties = {};
187
- let className = '';
188
-
189
- switch (background.type) {
190
- case 'theme': {
191
- // Theme-based backgrounds using CSS classes
192
- const themeClasses = {
193
- primary: 'bg-primary text-primary-foreground',
194
- secondary: 'bg-secondary text-secondary-foreground',
195
- muted: 'bg-muted text-muted-foreground',
196
- accent: 'bg-accent text-accent-foreground',
197
- destructive: 'bg-destructive text-destructive-foreground'
198
- };
199
- className = background.theme ? themeClasses[background.theme] || '' : '';
200
- break;
201
- }
202
-
203
- case 'solid':
204
- styles.backgroundColor = background.solid_color;
205
- break;
206
-
207
- case 'gradient':
208
- if (background.gradient) {
209
- const { type, direction, stops } = background.gradient;
210
- const gradientStops = formatGradientStops(stops);
211
- styles.background = `${type}-gradient(${direction || 'to right'}, ${gradientStops})`;
212
- }
213
- break;
214
-
215
- case 'image':
216
- // Handled via absolute next/image in the render tree for LCP & sizing optimization
217
- break;
218
-
219
- default:
220
- break;
221
- }
222
-
223
- return { styles, className };
224
- }
225
-
226
- function generateGradientOverlayStyle(gradient: any): React.CSSProperties {
227
- const { type, direction, stops } = gradient;
228
- const gradientStops = formatGradientStops(stops);
229
- return {
230
- background: `${type}-gradient(${direction || 'to right'}, ${gradientStops})`,
231
- };
232
- }
233
-
234
- interface NestedBlockRendererProps {
235
- block: SectionBlockContent['column_blocks'][0][0];
236
- languageId: number;
237
- parentBlockId?: number;
238
- parentBlockIndex?: number;
239
- visualEditing?: VisualEditingDocumentContext;
240
- visualEditAttributes?: VisualEditAttributes;
241
- botProtectionPublic?: BotProtectionPublicSettings;
242
- scriptNonce?: string;
243
- priority?: boolean;
244
- }
245
-
246
- async function renderNestedBlock({
247
- block,
248
- languageId,
249
- parentBlockId,
250
- parentBlockIndex,
251
- visualEditing,
252
- visualEditAttributes,
253
- botProtectionPublic,
254
- scriptNonce,
255
- priority = false,
256
- }: NestedBlockRendererProps) {
257
- // Statically resolve core block types first to avoid dynamic imports overhead
258
- if (block.block_type === 'text') {
259
- return (
260
- <TextBlockRenderer
261
- content={block.content as any}
262
- languageId={languageId}
263
- visualEditAttributes={visualEditAttributes}
264
- renderContext="section"
265
- />
266
- );
267
- }
268
-
269
- if (block.block_type === 'heading') {
270
- return (
271
- <HeadingBlockRenderer
272
- content={block.content as any}
273
- languageId={languageId}
274
- visualEditAttributes={visualEditAttributes}
275
- />
276
- );
277
- }
278
-
279
- if (block.block_type === 'button') {
280
- return (
281
- <ButtonBlockRenderer
282
- content={block.content as any}
283
- languageId={languageId}
284
- visualEditAttributes={visualEditAttributes}
285
- />
286
- );
287
- }
288
-
289
- if (block.block_type === 'image') {
290
- return (
291
- <ImageBlockRenderer
292
- content={block.content as any}
293
- languageId={languageId}
294
- priority={priority}
295
- visualEditAttributes={visualEditAttributes}
296
- />
297
- );
298
- }
299
-
300
- // Fallback to dynamic loader for custom/other block types
301
- const rendererLoader = getPublicBlockRendererLoader(block.block_type);
302
-
303
- if (!rendererLoader) {
304
- if (ECOMMERCE_BLOCK_TYPES.has(block.block_type)) {
305
- const { default: EcommerceRendererComponent } = await loadEcommerceBlockRenderer(
306
- block.block_type
307
- );
308
-
309
- return (
310
- <EcommerceRendererComponent
311
- content={block.content}
312
- languageId={languageId}
313
- visualEditAttributes={visualEditAttributes}
314
- />
315
- );
316
- }
317
-
318
- // Custom block definitions are data-rendered the same way as at the top
319
- // level. A custom block's block_type is the definition slug.
320
- const definition = await getCachedCustomBlockDefinitionBySlug(block.block_type);
321
- if (definition) {
322
- const resolvedBlock = (await resolveBlockRelations({
323
- data: block.content as Record<string, any>,
324
- fields: definition.fields,
325
- })) as any;
326
-
327
- return (
328
- <div {...visualEditAttributes}>
329
- <CachedDynamicLayoutEngine
330
- definition={definition}
331
- layoutSchema={definition.layout_schema}
332
- fields={definition.fields}
333
- data={{
334
- ...(resolvedBlock.data || {}),
335
- resolved_relations: resolvedBlock.resolved_relations || {},
336
- }}
337
- />
338
- </div>
339
- );
340
- }
341
-
342
- // Unknown type with no matching definition: keep the diagnostic out of the
343
- // public-facing page (only show it inside the live editor).
344
- if (!visualEditing?.enabled) {
345
- return null;
346
- }
347
-
348
- return (
349
- <div
350
- className="p-2 border rounded bg-destructive/10 text-destructive text-sm"
351
- {...visualEditAttributes}
352
- >
353
- <strong>Unsupported block type:</strong> {block.block_type}
354
- </div>
355
- );
356
- }
357
-
358
- const { default: RendererComponent } = await rendererLoader();
359
-
360
- // Handle different prop requirements for different renderers
361
- if (block.block_type === 'posts_grid') {
362
- return (
363
- <RendererComponent
364
- content={block.content}
365
- languageId={languageId}
366
- block={{ ...block, id: 0, language_id: languageId, order: 0, created_at: '', updated_at: '' }}
367
- visualEditAttributes={visualEditAttributes}
368
- />
369
- );
370
- }
371
-
372
- return (
373
- <RendererComponent
374
- content={block.content}
375
- languageId={languageId}
376
- visualEditAttributes={visualEditAttributes}
377
- visualEditing={visualEditing}
378
- parentBlockId={parentBlockId}
379
- parentBlockIndex={parentBlockIndex}
380
- botProtectionPublic={botProtectionPublic}
381
- scriptNonce={scriptNonce}
382
- // Hero sections also carry LCP-eligible media in dynamically loaded
383
- // renderers (e.g. video_embed's poster frame), not just nested images.
384
- priority={priority}
385
- />
386
- );
387
- }
388
-
389
- export default async function SectionBlockRenderer({
390
- content,
391
- languageId,
392
- visualEditAttributes,
393
- visualEditing,
394
- parentBlockId,
395
- parentBlockIndex,
396
- blockType,
397
- botProtectionPublic,
398
- scriptNonce,
399
- }: SectionBlockRendererProps) {
400
- const isHero = content.is_hero === true;
401
-
402
- // Build CSS classes
403
- const containerClass = containerClasses[content.container_type] || containerClasses.container;
404
- const gridClass = columnClasses[content.responsive_columns.desktop] || columnClasses[3];
405
- const gapClass = gapClasses[content.column_gap] || gapClasses.md;
406
- const paddingTopClass = paddingClasses[content.padding.top] || paddingClasses.md;
407
- const paddingBottomClass = paddingClasses[content.padding.bottom] || paddingClasses.md;
408
- const alignmentClass = content.vertical_alignment ? verticalAlignmentClasses[content.vertical_alignment] : 'items-start';
409
-
410
- // --- Render Slide-based Carousel Section ---
411
- if (content.slider && content.slides && content.slides.length > 0) {
412
- const renderedSlides = await Promise.all(
413
- content.slides.map(async (slide, slideIndex) => {
414
- const isFirstSlide = slideIndex === 0;
415
- // Priority loading for the first slide of a hero carousel
416
- const slidePriority = isHero && isFirstSlide;
417
-
418
- const slideBackground = slide.background || { type: "none" };
419
- const { styles: slideBgStyles, className: slideBgClassName } = generateBackgroundStyles(slideBackground);
420
-
421
- const renderedColumns = await Promise.all(
422
- slide.column_blocks.map(async (columnBlocks, columnIndex) => {
423
- const blocks = Array.isArray(columnBlocks) ? columnBlocks : [];
424
- const renderedBlocks = await Promise.all(
425
- blocks.map(async (block, blockIndex) => ({
426
- key: `${block.block_type}-${columnIndex}-${blockIndex}`,
427
- node: await renderNestedBlock({
428
- block,
429
- languageId,
430
- parentBlockId,
431
- parentBlockIndex,
432
- visualEditing,
433
- botProtectionPublic,
434
- scriptNonce,
435
- priority: slidePriority, // Pass down priority
436
- visualEditAttributes:
437
- typeof parentBlockId === "number" && typeof parentBlockIndex === "number"
438
- ? buildVisualEditAttributes(visualEditing, {
439
- kind: "nested",
440
- parentBlockId,
441
- parentBlockIndex,
442
- parentBlockType: "section",
443
- columnIndex,
444
- blockIndex,
445
- blockType: block.block_type,
446
- })
447
- : undefined,
448
- }),
449
- }))
450
- );
451
-
452
- return { columnIndex, renderedBlocks };
453
- })
454
- );
455
-
456
- return (
457
- <div
458
- key={`slide-${slideIndex}`}
459
- className={`relative w-full flex items-center ${BACKGROUND_COMPOSITING_CLASSES} ${paddingTopClass} ${paddingBottomClass} ${slideBgClassName}`}
460
- style={{
461
- ...slideBgStyles,
462
- minHeight: formatMinHeight(slideBackground.min_height) || '400px'
463
- }}
464
- >
465
- {/* Background image Layer for slide */}
466
- {slideBackground.type === 'image' && slideBackground.image && (
467
- <div className={ABSOLUTE_BACKGROUND_CLASSES}>
468
- {renderBackgroundImageElement(slideBackground.image, slidePriority)}
469
- {slideBackground.image.overlay && slideBackground.image.overlay.gradient && (
470
- <div
471
- className="absolute inset-0 transform-gpu [backface-visibility:hidden]"
472
- style={generateGradientOverlayStyle(slideBackground.image.overlay.gradient)}
473
- />
474
- )}
475
- </div>
476
- )}
477
-
478
- <div className={`${containerClass} w-full`}>
479
- <div className={`grid ${gridClass} ${gapClass} ${alignmentClass}`}>
480
- {renderedColumns.map(({ columnIndex, renderedBlocks }) => (
481
- <div key={`column-${columnIndex}`} className="min-h-0 space-y-4">
482
- {renderedBlocks.map(({ key, node }) => (
483
- <React.Fragment key={key}>{node}</React.Fragment>
484
- ))}
485
- </div>
486
- ))}
487
- </div>
488
- </div>
489
- </div>
490
- );
491
- })
492
- );
493
-
494
- // Determine the slider's container min-height from configured slides
495
- let sliderMinHeight = '400px';
496
- if (content.slides && content.slides.length > 0) {
497
- const configuredHeight = content.slides
498
- .map(s => s.background?.min_height)
499
- .find(Boolean);
500
- if (configuredHeight) {
501
- sliderMinHeight = formatMinHeight(configuredHeight) || '400px';
502
- }
503
- }
504
-
505
- return (
506
- <section
507
- className={`relative w-full overflow-hidden ${BACKGROUND_COMPOSITING_CLASSES}`}
508
- {...visualEditAttributes}
509
- >
510
- <SectionSlider
511
- autoplay={content.autoplay}
512
- timeframe={content.timeframe}
513
- minHeight={sliderMinHeight}
514
- >
515
- {renderedSlides}
516
- </SectionSlider>
517
- </section>
518
- );
519
- }
520
-
521
- // --- Render Standard Single Layout Section ---
522
- const { styles, className: backgroundClassName } = generateBackgroundStyles(content.background);
523
-
524
- const renderedColumns = await Promise.all(
525
- content.column_blocks.map(async (columnBlocks, columnIndex) => {
526
- const blocks = Array.isArray(columnBlocks) ? columnBlocks : [];
527
- const renderedBlocks = await Promise.all(
528
- blocks.map(async (block, blockIndex) => ({
529
- key: `${block.block_type}-${columnIndex}-${blockIndex}`,
530
- node: await renderNestedBlock({
531
- block,
532
- languageId,
533
- parentBlockId,
534
- parentBlockIndex,
535
- visualEditing,
536
- botProtectionPublic,
537
- scriptNonce,
538
- priority: isHero, // Pass priority down to nested image blocks
539
- visualEditAttributes:
540
- typeof parentBlockId === "number" && typeof parentBlockIndex === "number"
541
- ? buildVisualEditAttributes(visualEditing, {
542
- kind: "nested",
543
- parentBlockId,
544
- parentBlockIndex,
545
- parentBlockType: "section",
546
- columnIndex,
547
- blockIndex,
548
- blockType: block.block_type,
549
- })
550
- : undefined,
551
- }),
552
- }))
553
- );
554
-
555
- return { columnIndex, renderedBlocks };
556
- })
557
- );
558
-
559
- return (
560
- <section
561
- className={`relative w-full ${BACKGROUND_COMPOSITING_CLASSES} ${paddingTopClass} ${paddingBottomClass} ${backgroundClassName}`.trim()}
562
- style={{
563
- ...styles,
564
- minHeight: formatMinHeight(content.background?.min_height)
565
- }}
566
- {...visualEditAttributes}
567
- >
568
- {/* Background image Layer */}
569
- {content.background?.type === 'image' && content.background.image?.attribution && (
570
- <StockPhotoCredit
571
- attribution={content.background.image.attribution}
572
- className="pointer-events-auto absolute bottom-1 right-2 z-10 rounded bg-black/40 px-1.5 py-0.5 text-[10px] text-white/90 backdrop-blur-sm [&_a]:text-white"
573
- />
574
- )}
575
- {content.background?.type === 'image' && content.background.image && (
576
- <div className={ABSOLUTE_BACKGROUND_CLASSES}>
577
- {renderBackgroundImageElement(content.background.image, isHero)}
578
- {content.background.image.overlay && content.background.image.overlay.gradient && (
579
- <div
580
- className="absolute inset-0 transform-gpu [backface-visibility:hidden]"
581
- style={generateGradientOverlayStyle(content.background.image.overlay.gradient)}
582
- />
583
- )}
584
- </div>
585
- )}
586
-
587
- <div className={containerClass}>
588
- <div className={`grid ${gridClass} ${gapClass} ${alignmentClass}`}>
589
- {renderedColumns.map(({ columnIndex, renderedBlocks }) => (
590
- <div key={`column-${columnIndex}`} className="min-h-0 space-y-4">
591
- {renderedBlocks.map(({ key, node }) => (
592
- <React.Fragment key={key}>{node}</React.Fragment>
593
- ))}
594
- </div>
595
- ))}
596
- </div>
597
- </div>
598
- </section>
599
- );
600
- }
1
+ // components/blocks/renderers/SectionBlockRenderer.tsx
2
+ import React from "react";
3
+ import Image from "next/image";
4
+ import type { SectionBlockContent } from "../../../lib/blocks/blockRegistry";
5
+ import { buildVisualEditAttributes } from "../../../lib/visual-editing/edit-info";
6
+ import type {
7
+ VisualEditAttributes,
8
+ VisualEditingDocumentContext,
9
+ } from "../../../lib/visual-editing/types";
10
+ import { getPublicBlockRendererLoader } from "../publicRendererLoaders";
11
+ import SectionSlider from "./SectionSlider";
12
+ import { getCachedCustomBlockDefinitionBySlug } from "../../../lib/custom-block-definitions";
13
+ import { CachedDynamicLayoutEngine } from "../../renderers/CachedDynamicLayoutEngine";
14
+ import { resolveBlockRelations } from "../../../lib/resolve-block-relations";
15
+
16
+ // Static imports for core block renderers for LCP/performance optimization
17
+ import TextBlockRenderer from "./TextBlockRenderer";
18
+ import HeadingBlockRenderer from "./HeadingBlockRenderer";
19
+ import ImageBlockRenderer from "./ImageBlockRenderer";
20
+ import ButtonBlockRenderer from "./ButtonBlockRenderer";
21
+ import { StockPhotoCredit } from "./StockPhotoCredit";
22
+
23
+ const R2_BASE_URL = process.env.NEXT_PUBLIC_R2_BASE_URL || "";
24
+ const BACKGROUND_COMPOSITING_CLASSES =
25
+ "isolate transform-gpu [backface-visibility:hidden] [transform-style:preserve-3d]";
26
+ const ABSOLUTE_BACKGROUND_CLASSES =
27
+ "pointer-events-none absolute inset-[-1px] -z-10 transform-gpu [backface-visibility:hidden] [transform-style:preserve-3d]";
28
+ const ECOMMERCE_BLOCK_TYPES = new Set([
29
+ "product_grid",
30
+ "featured_product",
31
+ "cart",
32
+ "checkout",
33
+ "product_details",
34
+ ]);
35
+
36
+ function loadEcommerceBlockRenderer(blockType: string) {
37
+ return import("../ecommerceRendererLoaders").then((module) =>
38
+ module.loadEcommerceBlockRenderer(blockType)
39
+ );
40
+ }
41
+
42
+ type SectionBackgroundImage = NonNullable<
43
+ NonNullable<SectionBlockContent["background"]>["image"]
44
+ >;
45
+
46
+ // Renders a section's background image. External https URLs (e.g. AI-inserted
47
+ // stock photos) use a plain <img> so any allowlisted host works without Next
48
+ // image remotePatterns config; stored R2 media keeps the optimized next/image
49
+ // path. Returns null when neither a URL nor an object key is present.
50
+ function renderBackgroundImageElement(image: SectionBackgroundImage, priority: boolean) {
51
+ const externalUrl =
52
+ typeof image.external_url === "string" && /^https?:\/\//i.test(image.external_url.trim())
53
+ ? image.external_url.trim()
54
+ : null;
55
+ const objectFit: "cover" | "contain" = image.size === "contain" ? "contain" : "cover";
56
+ const objectPosition = image.position || "center";
57
+
58
+ if (externalUrl) {
59
+ return (
60
+ // eslint-disable-next-line @next/next/no-img-element
61
+ <img
62
+ src={externalUrl}
63
+ alt={image.alt_text || ""}
64
+ loading={priority ? "eager" : "lazy"}
65
+ fetchPriority={priority ? "high" : "auto"}
66
+ decoding="async"
67
+ className="absolute inset-0 h-full w-full"
68
+ style={{ objectFit, objectPosition }}
69
+ />
70
+ );
71
+ }
72
+
73
+ if (!image.object_key) {
74
+ return null;
75
+ }
76
+
77
+ return (
78
+ <Image
79
+ src={`${R2_BASE_URL}/${image.object_key}`}
80
+ alt={image.alt_text || ""}
81
+ fill
82
+ priority={priority}
83
+ fetchPriority={priority ? "high" : "auto"}
84
+ placeholder={image.blur_data_url ? "blur" : "empty"}
85
+ blurDataURL={image.blur_data_url || undefined}
86
+ quality={image.quality || 80}
87
+ sizes="100vw"
88
+ style={{ objectFit, objectPosition }}
89
+ />
90
+ );
91
+ }
92
+
93
+ interface SectionBlockRendererProps {
94
+ content: SectionBlockContent;
95
+ languageId: number;
96
+ visualEditAttributes?: VisualEditAttributes;
97
+ visualEditing?: VisualEditingDocumentContext;
98
+ parentBlockId?: number;
99
+ parentBlockIndex?: number;
100
+ blockType?: "section";
101
+ botProtectionPublic?: BotProtectionPublicSettings;
102
+ scriptNonce?: string;
103
+ }
104
+
105
+ type BotProtectionPublicSettings = {
106
+ provider: 'none' | 'turnstile' | 'recaptcha';
107
+ siteKey: string;
108
+ };
109
+
110
+ // Container class mapping
111
+ const containerClasses = {
112
+ 'full-width': 'w-full',
113
+ 'container': 'container mx-auto px-4',
114
+ 'container-sm': 'container mx-auto px-4 max-w-screen-sm',
115
+ 'container-lg': 'container mx-auto px-4 max-w-screen-lg',
116
+ 'container-xl': 'container mx-auto px-4 max-w-screen-xl'
117
+ };
118
+
119
+ // Column grid classes
120
+ const columnClasses = {
121
+ 1: 'grid-cols-1',
122
+ 2: 'grid-cols-1 md:grid-cols-2',
123
+ 3: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
124
+ 4: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4'
125
+ };
126
+
127
+ // Gap classes
128
+ const gapClasses = {
129
+ none: 'gap-0',
130
+ sm: 'gap-2',
131
+ md: 'gap-4',
132
+ lg: 'gap-6',
133
+ xl: 'gap-8'
134
+ };
135
+
136
+ // Padding classes
137
+ const paddingClasses = {
138
+ none: '',
139
+ sm: 'py-2',
140
+ md: 'py-4',
141
+ lg: 'py-8',
142
+ xl: 'py-12'
143
+ };
144
+
145
+ // Vertical alignment classes
146
+ const verticalAlignmentClasses = {
147
+ start: 'items-start',
148
+ center: 'items-center',
149
+ end: 'items-end',
150
+ stretch: 'items-stretch'
151
+ };
152
+
153
+ function formatMinHeight(value?: string) {
154
+ if (!value) return undefined;
155
+ const trimmed = value.trim();
156
+ if (/^\d+$/.test(trimmed)) {
157
+ return `${trimmed}px`;
158
+ }
159
+ return trimmed;
160
+ }
161
+
162
+ function formatStopPosition(position: number) {
163
+ return Number.isInteger(position) ? String(position) : position.toFixed(1);
164
+ }
165
+
166
+ function formatGradientStops(stops: Array<{ color: string; position: number }>) {
167
+ return stops
168
+ .map((stop, index) => {
169
+ const previous = stops[index - 1];
170
+ const next = stops[index + 1];
171
+ let position = stop.position;
172
+
173
+ if (next && next.position === stop.position && stop.position > 0) {
174
+ position = stop.position - 0.1;
175
+ } else if (previous && previous.position === stop.position && stop.position < 100) {
176
+ position = stop.position + 0.1;
177
+ }
178
+
179
+ return `${stop.color} ${formatStopPosition(position)}%`;
180
+ })
181
+ .join(', ');
182
+ }
183
+
184
+ // Background style generator (handles solid, theme and gradients; image handled in JSX)
185
+ function generateBackgroundStyles(background: SectionBlockContent['background']) {
186
+ const styles: React.CSSProperties = {};
187
+ let className = '';
188
+
189
+ switch (background.type) {
190
+ case 'theme': {
191
+ // Theme-based backgrounds using CSS classes
192
+ const themeClasses = {
193
+ primary: 'bg-primary text-primary-foreground',
194
+ secondary: 'bg-secondary text-secondary-foreground',
195
+ muted: 'bg-muted text-muted-foreground',
196
+ accent: 'bg-accent text-accent-foreground',
197
+ destructive: 'bg-destructive text-destructive-foreground'
198
+ };
199
+ className = background.theme ? themeClasses[background.theme] || '' : '';
200
+ break;
201
+ }
202
+
203
+ case 'solid':
204
+ styles.backgroundColor = background.solid_color;
205
+ break;
206
+
207
+ case 'gradient':
208
+ if (background.gradient) {
209
+ const { type, direction, stops } = background.gradient;
210
+ const gradientStops = formatGradientStops(stops);
211
+ styles.background = `${type}-gradient(${direction || 'to right'}, ${gradientStops})`;
212
+ }
213
+ break;
214
+
215
+ case 'image':
216
+ // Handled via absolute next/image in the render tree for LCP & sizing optimization
217
+ break;
218
+
219
+ default:
220
+ break;
221
+ }
222
+
223
+ return { styles, className };
224
+ }
225
+
226
+ function generateGradientOverlayStyle(gradient: any): React.CSSProperties {
227
+ const { type, direction, stops } = gradient;
228
+ const gradientStops = formatGradientStops(stops);
229
+ return {
230
+ background: `${type}-gradient(${direction || 'to right'}, ${gradientStops})`,
231
+ };
232
+ }
233
+
234
+ interface NestedBlockRendererProps {
235
+ block: SectionBlockContent['column_blocks'][0][0];
236
+ languageId: number;
237
+ parentBlockId?: number;
238
+ parentBlockIndex?: number;
239
+ visualEditing?: VisualEditingDocumentContext;
240
+ visualEditAttributes?: VisualEditAttributes;
241
+ botProtectionPublic?: BotProtectionPublicSettings;
242
+ scriptNonce?: string;
243
+ priority?: boolean;
244
+ }
245
+
246
+ /**
247
+ * A form nested inside a section has no `blocks` row of its own — it lives in the
248
+ * section's jsonb — so the same strip the top-level renderer performs has to happen
249
+ * here too. See BlockRenderer.stripServerOnlyContent for why.
250
+ */
251
+ function stripServerOnlyContent(blockType: string, content: unknown): unknown {
252
+ if (blockType !== 'form' || !content || typeof content !== 'object') return content;
253
+ if (!('recipient_email' in (content as Record<string, unknown>))) return content;
254
+ const { recipient_email: _dropped, ...safe } = content as Record<string, unknown>;
255
+ return safe;
256
+ }
257
+
258
+ async function renderNestedBlock({
259
+ block,
260
+ languageId,
261
+ parentBlockId,
262
+ parentBlockIndex,
263
+ visualEditing,
264
+ visualEditAttributes,
265
+ botProtectionPublic,
266
+ scriptNonce,
267
+ priority = false,
268
+ }: NestedBlockRendererProps) {
269
+ // Statically resolve core block types first to avoid dynamic imports overhead
270
+ if (block.block_type === 'text') {
271
+ return (
272
+ <TextBlockRenderer
273
+ content={block.content as any}
274
+ languageId={languageId}
275
+ visualEditAttributes={visualEditAttributes}
276
+ renderContext="section"
277
+ />
278
+ );
279
+ }
280
+
281
+ if (block.block_type === 'heading') {
282
+ return (
283
+ <HeadingBlockRenderer
284
+ content={block.content as any}
285
+ languageId={languageId}
286
+ visualEditAttributes={visualEditAttributes}
287
+ />
288
+ );
289
+ }
290
+
291
+ if (block.block_type === 'button') {
292
+ return (
293
+ <ButtonBlockRenderer
294
+ content={block.content as any}
295
+ languageId={languageId}
296
+ visualEditAttributes={visualEditAttributes}
297
+ />
298
+ );
299
+ }
300
+
301
+ if (block.block_type === 'image') {
302
+ return (
303
+ <ImageBlockRenderer
304
+ content={block.content as any}
305
+ languageId={languageId}
306
+ priority={priority}
307
+ visualEditAttributes={visualEditAttributes}
308
+ />
309
+ );
310
+ }
311
+
312
+ // Fallback to dynamic loader for custom/other block types
313
+ const rendererLoader = getPublicBlockRendererLoader(block.block_type);
314
+
315
+ if (!rendererLoader) {
316
+ if (ECOMMERCE_BLOCK_TYPES.has(block.block_type)) {
317
+ const { default: EcommerceRendererComponent } = await loadEcommerceBlockRenderer(
318
+ block.block_type
319
+ );
320
+
321
+ return (
322
+ <EcommerceRendererComponent
323
+ content={block.content}
324
+ languageId={languageId}
325
+ visualEditAttributes={visualEditAttributes}
326
+ />
327
+ );
328
+ }
329
+
330
+ // Custom block definitions are data-rendered the same way as at the top
331
+ // level. A custom block's block_type is the definition slug.
332
+ const definition = await getCachedCustomBlockDefinitionBySlug(block.block_type);
333
+ if (definition) {
334
+ const resolvedBlock = (await resolveBlockRelations({
335
+ data: block.content as Record<string, any>,
336
+ fields: definition.fields,
337
+ })) as any;
338
+
339
+ return (
340
+ <div {...visualEditAttributes}>
341
+ <CachedDynamicLayoutEngine
342
+ definition={definition}
343
+ layoutSchema={definition.layout_schema}
344
+ fields={definition.fields}
345
+ data={{
346
+ ...(resolvedBlock.data || {}),
347
+ resolved_relations: resolvedBlock.resolved_relations || {},
348
+ }}
349
+ />
350
+ </div>
351
+ );
352
+ }
353
+
354
+ // Unknown type with no matching definition: keep the diagnostic out of the
355
+ // public-facing page (only show it inside the live editor).
356
+ if (!visualEditing?.enabled) {
357
+ return null;
358
+ }
359
+
360
+ return (
361
+ <div
362
+ className="p-2 border rounded bg-destructive/10 text-destructive text-sm"
363
+ {...visualEditAttributes}
364
+ >
365
+ <strong>Unsupported block type:</strong> {block.block_type}
366
+ </div>
367
+ );
368
+ }
369
+
370
+ const { default: RendererComponent } = await rendererLoader();
371
+
372
+ // Handle different prop requirements for different renderers
373
+ if (block.block_type === 'posts_grid') {
374
+ return (
375
+ <RendererComponent
376
+ content={block.content}
377
+ languageId={languageId}
378
+ block={{ ...block, id: 0, language_id: languageId, order: 0, created_at: '', updated_at: '' }}
379
+ visualEditAttributes={visualEditAttributes}
380
+ />
381
+ );
382
+ }
383
+
384
+ return (
385
+ <RendererComponent
386
+ content={stripServerOnlyContent(block.block_type, block.content)}
387
+ languageId={languageId}
388
+ visualEditAttributes={visualEditAttributes}
389
+ visualEditing={visualEditing}
390
+ parentBlockId={parentBlockId}
391
+ parentBlockIndex={parentBlockIndex}
392
+ botProtectionPublic={botProtectionPublic}
393
+ scriptNonce={scriptNonce}
394
+ // Hero sections also carry LCP-eligible media in dynamically loaded
395
+ // renderers (e.g. video_embed's poster frame), not just nested images.
396
+ priority={priority}
397
+ />
398
+ );
399
+ }
400
+
401
+ export default async function SectionBlockRenderer({
402
+ content,
403
+ languageId,
404
+ visualEditAttributes,
405
+ visualEditing,
406
+ parentBlockId,
407
+ parentBlockIndex,
408
+ blockType,
409
+ botProtectionPublic,
410
+ scriptNonce,
411
+ }: SectionBlockRendererProps) {
412
+ const isHero = content.is_hero === true;
413
+
414
+ // Build CSS classes
415
+ const containerClass = containerClasses[content.container_type] || containerClasses.container;
416
+ const gridClass = columnClasses[content.responsive_columns.desktop] || columnClasses[3];
417
+ const gapClass = gapClasses[content.column_gap] || gapClasses.md;
418
+ const paddingTopClass = paddingClasses[content.padding.top] || paddingClasses.md;
419
+ const paddingBottomClass = paddingClasses[content.padding.bottom] || paddingClasses.md;
420
+ const alignmentClass = content.vertical_alignment ? verticalAlignmentClasses[content.vertical_alignment] : 'items-start';
421
+
422
+ // --- Render Slide-based Carousel Section ---
423
+ if (content.slider && content.slides && content.slides.length > 0) {
424
+ const renderedSlides = await Promise.all(
425
+ content.slides.map(async (slide, slideIndex) => {
426
+ const isFirstSlide = slideIndex === 0;
427
+ // Priority loading for the first slide of a hero carousel
428
+ const slidePriority = isHero && isFirstSlide;
429
+
430
+ const slideBackground = slide.background || { type: "none" };
431
+ const { styles: slideBgStyles, className: slideBgClassName } = generateBackgroundStyles(slideBackground);
432
+
433
+ const renderedColumns = await Promise.all(
434
+ slide.column_blocks.map(async (columnBlocks, columnIndex) => {
435
+ const blocks = Array.isArray(columnBlocks) ? columnBlocks : [];
436
+ const renderedBlocks = await Promise.all(
437
+ blocks.map(async (block, blockIndex) => ({
438
+ key: `${block.block_type}-${columnIndex}-${blockIndex}`,
439
+ node: await renderNestedBlock({
440
+ block,
441
+ languageId,
442
+ parentBlockId,
443
+ parentBlockIndex,
444
+ visualEditing,
445
+ botProtectionPublic,
446
+ scriptNonce,
447
+ priority: slidePriority, // Pass down priority
448
+ visualEditAttributes:
449
+ typeof parentBlockId === "number" && typeof parentBlockIndex === "number"
450
+ ? buildVisualEditAttributes(visualEditing, {
451
+ kind: "nested",
452
+ parentBlockId,
453
+ parentBlockIndex,
454
+ parentBlockType: "section",
455
+ columnIndex,
456
+ blockIndex,
457
+ blockType: block.block_type,
458
+ })
459
+ : undefined,
460
+ }),
461
+ }))
462
+ );
463
+
464
+ return { columnIndex, renderedBlocks };
465
+ })
466
+ );
467
+
468
+ return (
469
+ <div
470
+ key={`slide-${slideIndex}`}
471
+ className={`relative w-full flex items-center ${BACKGROUND_COMPOSITING_CLASSES} ${paddingTopClass} ${paddingBottomClass} ${slideBgClassName}`}
472
+ style={{
473
+ ...slideBgStyles,
474
+ minHeight: formatMinHeight(slideBackground.min_height) || '400px'
475
+ }}
476
+ >
477
+ {/* Background image Layer for slide */}
478
+ {slideBackground.type === 'image' && slideBackground.image && (
479
+ <div className={ABSOLUTE_BACKGROUND_CLASSES}>
480
+ {renderBackgroundImageElement(slideBackground.image, slidePriority)}
481
+ {slideBackground.image.overlay && slideBackground.image.overlay.gradient && (
482
+ <div
483
+ className="absolute inset-0 transform-gpu [backface-visibility:hidden]"
484
+ style={generateGradientOverlayStyle(slideBackground.image.overlay.gradient)}
485
+ />
486
+ )}
487
+ </div>
488
+ )}
489
+
490
+ <div className={`${containerClass} w-full`}>
491
+ <div className={`grid ${gridClass} ${gapClass} ${alignmentClass}`}>
492
+ {renderedColumns.map(({ columnIndex, renderedBlocks }) => (
493
+ <div key={`column-${columnIndex}`} className="min-h-0 space-y-4">
494
+ {renderedBlocks.map(({ key, node }) => (
495
+ <React.Fragment key={key}>{node}</React.Fragment>
496
+ ))}
497
+ </div>
498
+ ))}
499
+ </div>
500
+ </div>
501
+ </div>
502
+ );
503
+ })
504
+ );
505
+
506
+ // Determine the slider's container min-height from configured slides
507
+ let sliderMinHeight = '400px';
508
+ if (content.slides && content.slides.length > 0) {
509
+ const configuredHeight = content.slides
510
+ .map(s => s.background?.min_height)
511
+ .find(Boolean);
512
+ if (configuredHeight) {
513
+ sliderMinHeight = formatMinHeight(configuredHeight) || '400px';
514
+ }
515
+ }
516
+
517
+ return (
518
+ <section
519
+ className={`relative w-full overflow-hidden ${BACKGROUND_COMPOSITING_CLASSES}`}
520
+ {...visualEditAttributes}
521
+ >
522
+ <SectionSlider
523
+ autoplay={content.autoplay}
524
+ timeframe={content.timeframe}
525
+ minHeight={sliderMinHeight}
526
+ >
527
+ {renderedSlides}
528
+ </SectionSlider>
529
+ </section>
530
+ );
531
+ }
532
+
533
+ // --- Render Standard Single Layout Section ---
534
+ const { styles, className: backgroundClassName } = generateBackgroundStyles(content.background);
535
+
536
+ const renderedColumns = await Promise.all(
537
+ content.column_blocks.map(async (columnBlocks, columnIndex) => {
538
+ const blocks = Array.isArray(columnBlocks) ? columnBlocks : [];
539
+ const renderedBlocks = await Promise.all(
540
+ blocks.map(async (block, blockIndex) => ({
541
+ key: `${block.block_type}-${columnIndex}-${blockIndex}`,
542
+ node: await renderNestedBlock({
543
+ block,
544
+ languageId,
545
+ parentBlockId,
546
+ parentBlockIndex,
547
+ visualEditing,
548
+ botProtectionPublic,
549
+ scriptNonce,
550
+ priority: isHero, // Pass priority down to nested image blocks
551
+ visualEditAttributes:
552
+ typeof parentBlockId === "number" && typeof parentBlockIndex === "number"
553
+ ? buildVisualEditAttributes(visualEditing, {
554
+ kind: "nested",
555
+ parentBlockId,
556
+ parentBlockIndex,
557
+ parentBlockType: "section",
558
+ columnIndex,
559
+ blockIndex,
560
+ blockType: block.block_type,
561
+ })
562
+ : undefined,
563
+ }),
564
+ }))
565
+ );
566
+
567
+ return { columnIndex, renderedBlocks };
568
+ })
569
+ );
570
+
571
+ return (
572
+ <section
573
+ className={`relative w-full ${BACKGROUND_COMPOSITING_CLASSES} ${paddingTopClass} ${paddingBottomClass} ${backgroundClassName}`.trim()}
574
+ style={{
575
+ ...styles,
576
+ minHeight: formatMinHeight(content.background?.min_height)
577
+ }}
578
+ {...visualEditAttributes}
579
+ >
580
+ {/* Background image Layer */}
581
+ {content.background?.type === 'image' && content.background.image?.attribution && (
582
+ <StockPhotoCredit
583
+ attribution={content.background.image.attribution}
584
+ className="pointer-events-auto absolute bottom-1 right-2 z-10 rounded bg-black/40 px-1.5 py-0.5 text-[10px] text-white/90 backdrop-blur-sm [&_a]:text-white"
585
+ />
586
+ )}
587
+ {content.background?.type === 'image' && content.background.image && (
588
+ <div className={ABSOLUTE_BACKGROUND_CLASSES}>
589
+ {renderBackgroundImageElement(content.background.image, isHero)}
590
+ {content.background.image.overlay && content.background.image.overlay.gradient && (
591
+ <div
592
+ className="absolute inset-0 transform-gpu [backface-visibility:hidden]"
593
+ style={generateGradientOverlayStyle(content.background.image.overlay.gradient)}
594
+ />
595
+ )}
596
+ </div>
597
+ )}
598
+
599
+ <div className={containerClass}>
600
+ <div className={`grid ${gridClass} ${gapClass} ${alignmentClass}`}>
601
+ {renderedColumns.map(({ columnIndex, renderedBlocks }) => (
602
+ <div key={`column-${columnIndex}`} className="min-h-0 space-y-4">
603
+ {renderedBlocks.map(({ key, node }) => (
604
+ <React.Fragment key={key}>{node}</React.Fragment>
605
+ ))}
606
+ </div>
607
+ ))}
608
+ </div>
609
+ </div>
610
+ </section>
611
+ );
612
+ }