payload-canvas 0.5.1 → 0.6.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 (194) hide show
  1. package/README.md +333 -28
  2. package/dist/admin/ArrayRowLabel.d.ts +12 -0
  3. package/dist/admin/ArrayRowLabel.js +21 -0
  4. package/dist/admin/DocumentEditView.js +9 -2
  5. package/dist/admin/client.d.ts +1 -0
  6. package/dist/admin/client.js +2 -0
  7. package/dist/admin/editor/Editor.js +8 -1
  8. package/dist/admin/editor/Inspector.js +23 -17
  9. package/dist/admin/editor/Library.d.ts +2 -2
  10. package/dist/admin/editor/Library.js +7 -5
  11. package/dist/admin/editor/Outline.js +20 -12
  12. package/dist/admin/editor/Overlay.js +6 -4
  13. package/dist/admin/editor/actions.d.ts +7 -2
  14. package/dist/admin/editor/actions.js +44 -12
  15. package/dist/admin/editor/assistant/AssistantPanel.js +32 -20
  16. package/dist/admin/editor/comments/controller.d.ts +7 -0
  17. package/dist/admin/editor/comments/controller.js +12 -0
  18. package/dist/admin/editor/comments/useCommentFromURL.d.ts +2 -0
  19. package/dist/admin/editor/comments/useCommentFromURL.js +36 -0
  20. package/dist/admin/editor/dnd/smooth.js +1 -1
  21. package/dist/admin/editor/editor.scss +28 -0
  22. package/dist/admin/editor/fields/ArrayField.js +3 -3
  23. package/dist/admin/editor/fields/FormBlock.d.ts +20 -0
  24. package/dist/admin/editor/fields/FormBlock.js +167 -0
  25. package/dist/admin/editor/fields/FormFieldName.d.ts +25 -0
  26. package/dist/admin/editor/fields/FormFieldName.js +58 -0
  27. package/dist/admin/editor/fields/GroupField.d.ts +22 -2
  28. package/dist/admin/editor/fields/GroupField.js +30 -1
  29. package/dist/admin/editor/fields/MergeTags.d.ts +8 -0
  30. package/dist/admin/editor/fields/MergeTags.js +62 -0
  31. package/dist/admin/editor/fields/arrayRows.d.ts +0 -2
  32. package/dist/admin/editor/fields/arrayRows.js +0 -4
  33. package/dist/admin/editor/fields/fields.scss +150 -0
  34. package/dist/admin/editor/fields/values.d.ts +0 -2
  35. package/dist/admin/editor/fields/values.js +0 -14
  36. package/dist/admin/editor/icons.d.ts +3 -0
  37. package/dist/admin/editor/icons.js +3 -0
  38. package/dist/admin/editor/insert/InsertHandle.js +1 -1
  39. package/dist/admin/editor/insert/picker.d.ts +3 -2
  40. package/dist/admin/editor/insert/picker.js +9 -3
  41. package/dist/admin/editor/layout/LeftPanel.js +5 -3
  42. package/dist/admin/editor/layout/leftTabs.d.ts +15 -0
  43. package/dist/admin/editor/layout/leftTabs.js +18 -0
  44. package/dist/admin/editor/media/ImageEditor.d.ts +8 -2
  45. package/dist/admin/editor/media/ImageEditor.js +16 -10
  46. package/dist/admin/editor/media/media.scss +12 -2
  47. package/dist/admin/editor/media/model.d.ts +10 -1
  48. package/dist/admin/editor/media/model.js +19 -0
  49. package/dist/admin/editor/menu/blockMenu.js +3 -3
  50. package/dist/admin/editor/names.d.ts +9 -0
  51. package/dist/admin/editor/names.js +18 -0
  52. package/dist/admin/editor/regions/RegionFields.d.ts +6 -0
  53. package/dist/admin/editor/regions/RegionFields.js +122 -0
  54. package/dist/admin/editor/regions/RegionPane.js +5 -3
  55. package/dist/admin/editor/regions/RegionRows.js +2 -2
  56. package/dist/admin/editor/regions/required.d.ts +16 -0
  57. package/dist/admin/editor/regions/required.js +43 -0
  58. package/dist/admin/editor/renderField.d.ts +9 -2
  59. package/dist/admin/editor/renderField.js +86 -32
  60. package/dist/admin/editor/runtime.d.ts +3 -2
  61. package/dist/admin/editor/runtime.js +12 -18
  62. package/dist/admin/editor/styles/StylesPanel.js +4 -2
  63. package/dist/admin/editor/styles/context.js +9 -4
  64. package/dist/admin/editor/topbar/ContentModeToggle.js +1 -1
  65. package/dist/admin/editor/topbar/DocumentActions.js +4 -3
  66. package/dist/admin/editor/topbar/contentMode.scss +0 -9
  67. package/dist/admin/editor/topbar/topbar.scss +1 -41
  68. package/dist/admin/editor/ui/Tabs.d.ts +17 -0
  69. package/dist/admin/editor/ui/Tabs.js +17 -0
  70. package/dist/admin/forms/SubmissionCells.d.ts +6 -0
  71. package/dist/admin/forms/SubmissionCells.js +31 -0
  72. package/dist/admin/forms/SubmissionView.d.ts +5 -0
  73. package/dist/admin/forms/SubmissionView.js +106 -0
  74. package/dist/admin/forms/submissionData.d.ts +32 -0
  75. package/dist/admin/forms/submissionData.js +63 -0
  76. package/dist/admin/forms/submissions.scss +197 -0
  77. package/dist/admin/rsc.d.ts +2 -0
  78. package/dist/admin/rsc.js +5 -0
  79. package/dist/ai/endpoint.d.ts +5 -0
  80. package/dist/ai/endpoint.js +18 -8
  81. package/dist/ai/prompt.d.ts +8 -0
  82. package/dist/ai/prompt.js +30 -0
  83. package/dist/ai/tools.d.ts +6 -1
  84. package/dist/ai/tools.js +90 -6
  85. package/dist/blocks/builtins/carousel.js +10 -1
  86. package/dist/blocks/index.d.ts +1 -1
  87. package/dist/blocks/index.js +1 -1
  88. package/dist/blocks/payload.d.ts +7 -0
  89. package/dist/blocks/payload.js +16 -2
  90. package/dist/comments/shared.d.ts +5 -0
  91. package/dist/comments/shared.js +5 -0
  92. package/dist/core/blocks.d.ts +17 -3
  93. package/dist/core/blocks.js +92 -10
  94. package/dist/core/classes.d.ts +5 -0
  95. package/dist/core/classes.js +26 -1
  96. package/dist/core/conditions.d.ts +7 -0
  97. package/dist/core/conditions.js +22 -0
  98. package/dist/core/dropTarget.d.ts +3 -2
  99. package/dist/core/dropTarget.js +7 -1
  100. package/dist/core/index.d.ts +6 -3
  101. package/dist/core/index.js +6 -3
  102. package/dist/core/payloadBlocks.js +25 -3
  103. package/dist/core/references.d.ts +7 -0
  104. package/dist/core/references.js +29 -11
  105. package/dist/core/regions.d.ts +14 -0
  106. package/dist/core/regions.js +17 -1
  107. package/dist/core/rowLabel.d.ts +8 -0
  108. package/dist/core/rowLabel.js +98 -0
  109. package/dist/core/starter.d.ts +10 -0
  110. package/dist/core/starter.js +40 -0
  111. package/dist/core/tree.js +4 -0
  112. package/dist/core/types.d.ts +96 -0
  113. package/dist/core/uniqueProps.d.ts +40 -0
  114. package/dist/core/uniqueProps.js +156 -0
  115. package/dist/core/validate.js +43 -3
  116. package/dist/forms/answers.d.ts +21 -0
  117. package/dist/forms/answers.js +82 -0
  118. package/dist/forms/blocks.d.ts +33 -0
  119. package/dist/forms/blocks.js +178 -0
  120. package/dist/forms/conditions.d.ts +78 -0
  121. package/dist/forms/conditions.js +184 -0
  122. package/dist/forms/emails.d.ts +23 -0
  123. package/dist/forms/emails.js +64 -0
  124. package/dist/forms/fieldConfigs.d.ts +35 -0
  125. package/dist/forms/fieldConfigs.js +167 -0
  126. package/dist/forms/fieldOps.d.ts +78 -0
  127. package/dist/forms/fieldOps.js +378 -0
  128. package/dist/forms/fieldSettings.d.ts +81 -0
  129. package/dist/forms/fieldSettings.js +239 -0
  130. package/dist/forms/files.d.ts +54 -0
  131. package/dist/forms/files.js +128 -0
  132. package/dist/forms/index.d.ts +16 -0
  133. package/dist/forms/index.js +18 -0
  134. package/dist/forms/mergeTags.d.ts +103 -0
  135. package/dist/forms/mergeTags.js +150 -0
  136. package/dist/forms/noScript.d.ts +60 -0
  137. package/dist/forms/noScript.js +109 -0
  138. package/dist/forms/pageForms.d.ts +99 -0
  139. package/dist/forms/pageForms.js +294 -0
  140. package/dist/forms/pageSync.d.ts +91 -0
  141. package/dist/forms/pageSync.js +325 -0
  142. package/dist/forms/rateLimit.d.ts +21 -0
  143. package/dist/forms/rateLimit.js +50 -0
  144. package/dist/forms/settings.d.ts +13 -0
  145. package/dist/forms/settings.js +92 -0
  146. package/dist/forms/spam.d.ts +100 -0
  147. package/dist/forms/spam.js +218 -0
  148. package/dist/forms/spamSettings.d.ts +43 -0
  149. package/dist/forms/spamSettings.js +25 -0
  150. package/dist/forms/submission.d.ts +34 -0
  151. package/dist/forms/submission.js +89 -0
  152. package/dist/forms/submissionsAdmin.d.ts +26 -0
  153. package/dist/forms/submissionsAdmin.js +108 -0
  154. package/dist/forms/summary.d.ts +60 -0
  155. package/dist/forms/summary.js +113 -0
  156. package/dist/forms/uploads.d.ts +41 -0
  157. package/dist/forms/uploads.js +132 -0
  158. package/dist/index.d.ts +8 -2
  159. package/dist/index.js +8 -2
  160. package/dist/live/document.d.ts +12 -0
  161. package/dist/live/document.js +8 -1
  162. package/dist/live/endpoints.d.ts +1 -0
  163. package/dist/live/session.js +3 -1
  164. package/dist/live/storage.d.ts +13 -2
  165. package/dist/live/storage.js +18 -7
  166. package/dist/mcp/forms.d.ts +26 -0
  167. package/dist/mcp/forms.js +280 -0
  168. package/dist/mcp/index.d.ts +7 -0
  169. package/dist/mcp/index.js +29 -10
  170. package/dist/mcp/shared.d.ts +1 -0
  171. package/dist/mcp/shared.js +1 -0
  172. package/dist/plugin/forms.d.ts +30 -0
  173. package/dist/plugin/forms.js +63 -0
  174. package/dist/plugin/formsSync.d.ts +138 -0
  175. package/dist/plugin/formsSync.js +345 -0
  176. package/dist/plugin/hook.d.ts +22 -0
  177. package/dist/plugin/hook.js +19 -7
  178. package/dist/plugin/index.d.ts +14 -0
  179. package/dist/plugin/index.js +99 -28
  180. package/dist/plugin/links.d.ts +21 -2
  181. package/dist/plugin/links.js +32 -3
  182. package/dist/plugin/references.d.ts +6 -0
  183. package/dist/plugin/references.js +12 -0
  184. package/dist/react/canvas/BuilderCanvas.d.ts +2 -0
  185. package/dist/react/canvas/BuilderCanvas.js +29 -6
  186. package/dist/react/canvas/inline/mapper.d.ts +6 -1
  187. package/dist/react/canvas/inline/mapper.js +35 -4
  188. package/dist/react/render/LayoutOutlet.d.ts +7 -3
  189. package/dist/react/render/LayoutOutlet.js +9 -4
  190. package/dist/react/render/RenderLayout.js +13 -7
  191. package/dist/react/render/resolve.d.ts +1 -0
  192. package/dist/react/render/resolve.js +5 -1
  193. package/dist/react/server.js +19 -0
  194. package/package.json +5 -1
@@ -34,6 +34,10 @@ import { bindingSources, documentTemplateField, hasFieldNamed, requireBlocksForD
34
34
  import { templateEndpoint } from './templateEndpoint.js';
35
35
  import { CLASSES_CONFIG_KEY, resolveClasses } from '../classes/index.js';
36
36
  import { resolveComments } from '../comments/index.js';
37
+ import { withBuilderConditions } from '../core/conditions.js';
38
+ import { resolveForms } from './forms.js';
39
+ import { formClaimEndpoint, formLiveCheck, formSourceField, formSyncAfterCreate, pageFormSync, sectionFormSync } from './formsSync.js';
40
+ import { FORM_BLOCK, FORM_SLOT, withPageForms } from '../forms/pageForms.js';
37
41
  /**
38
42
  * Server-only key in `config.custom`: what the site needs to compile one stylesheet for every
39
43
  * layout on a page (`compilePageCss` in `payload-canvas/react/server`).
@@ -82,6 +86,9 @@ export function websiteBuilder(options) {
82
86
  const apiRoute = config.routes?.api ?? '/api';
83
87
  const canvasPath = options.canvasPath ?? '/builder-canvas';
84
88
  const sourceCollections = config.collections ?? [];
89
+ // The form builder: the forms collection joins the builder collections, with its own blocks.
90
+ const forms = resolveForms(options.forms, sourceCollections, options.collections);
91
+ const listedCollections = forms ? { ...options.collections, [forms.slug]: forms.collection } : options.collections;
85
92
  const live = defaultLiveRuntime();
86
93
  const writeGate = defaultWriteGate();
87
94
  // Payload's locales. Each builder collection uses them unless it sets `localization: false`.
@@ -98,7 +105,7 @@ export function websiteBuilder(options) {
98
105
  }
99
106
  return option === false ? null : locales;
100
107
  };
101
- for (const slug of Object.keys(options.collections)) {
108
+ for (const slug of Object.keys(listedCollections)) {
102
109
  if (!sourceCollections.some((c) => c.slug === slug)) {
103
110
  throw new Error(`[websiteBuilder] Collection "${slug}" does not exist. Known collections: ${sourceCollections.map((c) => c.slug).join(', ')}.`);
104
111
  }
@@ -123,18 +130,20 @@ export function websiteBuilder(options) {
123
130
  return themeFontFamilies(doc);
124
131
  };
125
132
  // Templates: a collection of layouts for the template-enabled collections.
126
- const targets = Object.entries(options.collections).filter(([, o]) => o.templates).map(([slug]) => slug);
133
+ const targets = Object.entries(listedCollections).filter(([, o]) => o.templates).map(([slug]) => slug);
127
134
  const templatesSlug = options.templates?.slug ?? DEFAULT_TEMPLATES_SLUG;
128
- const withUrl = new Set(Object.entries(options.collections).filter(([, o]) => o.url).map(([slug]) => slug));
135
+ const withUrl = new Set(Object.entries(listedCollections).filter(([, o]) => o.url).map(([slug]) => slug));
129
136
  for (const slug of options.listCollections ?? []) {
130
137
  if (!sourceCollections.some((c) => c.slug === slug)) {
131
138
  throw new Error(`[websiteBuilder] \`listCollections\` names "${slug}", which is not a collection. Known collections: ${sourceCollections.map((c) => c.slug).join(', ')}.`);
132
139
  }
133
140
  }
134
141
  // The collections the collection list block can show: with a `url`, then `listCollections`.
135
- const listable = listableCollections(options.collections, options.listCollections);
136
- const builderOptions = { ...options.collections };
137
- let collections = sourceCollections;
142
+ const listable = listableCollections(listedCollections, options.listCollections);
143
+ const builderOptions = { ...listedCollections };
144
+ // Forms on pages: the app lists a Form block (`formBlocks()`), and each form remembers its block.
145
+ const pageForms = Boolean(forms && options.blocks?.some((b) => b.type === FORM_BLOCK && b.slots?.[FORM_SLOT]));
146
+ let collections = pageForms && forms ? sourceCollections.map((c) => (c.slug === forms.slug ? { ...c, fields: [...c.fields, formSourceField()] } : c)) : sourceCollections;
138
147
  if (targets.length > 0) {
139
148
  if (sourceCollections.some((c) => c.slug === templatesSlug)) {
140
149
  throw new Error(`[websiteBuilder] A collection named "${templatesSlug}" already exists. Set \`templates.slug\` to another name.`);
@@ -146,7 +155,7 @@ export function websiteBuilder(options) {
146
155
  }
147
156
  }
148
157
  collections = [
149
- ...sourceCollections.map((c) => targets.includes(c.slug) ? { ...c, fields: [...c.fields, documentTemplateField(c.slug, templatesSlug)] } : c),
158
+ ...collections.map((c) => targets.includes(c.slug) ? { ...c, fields: [...c.fields, documentTemplateField(c.slug, templatesSlug)] } : c),
150
159
  templatesCollection({
151
160
  slug: templatesSlug,
152
161
  targets,
@@ -161,20 +170,24 @@ export function websiteBuilder(options) {
161
170
  const savedSections = options.savedSections === false ? null : { slug: options.savedSections?.slug ?? DEFAULT_SAVED_SECTIONS_SLUG };
162
171
  // Inline blocks (`inline: true`) may sit in a link: they join its `allow` list. With saved
163
172
  // sections on, the live saved section block (`sectionRef`) joins the list, pointed at their collection.
164
- const blocks = prepareBlocks(options.blocks ?? defaultBlocks(), listable, savedSections?.slug ?? null);
173
+ const prepared = prepareBlocks(options.blocks ?? defaultBlocks(), listable, savedSections?.slug ?? null);
174
+ // Forms on pages: the Form block gets the forms collection's settings, and its field blocks join the list.
175
+ const blocks = pageForms && forms ? withPageForms(prepared, { fields: forms.blocks, settings: forms.settingsFields, collection: forms.slug }) : prepared;
165
176
  // Variants stay under their section (core/sections.ts): one library card, a switch on the canvas.
166
177
  const appSections = options.sections ?? [];
167
178
  checkSectionVariants(appSections);
168
179
  // A section block without a className gets its type's default classes (JSON layouts only).
169
180
  const sections = sectionsWithDefaultClassNames(appSections, blocks);
170
- const duplicate = blocks.find((b, i) => blocks.findIndex((other) => other.type === b.type) !== i);
181
+ // With forms on pages the field blocks are in `blocks` already.
182
+ const allTypes = [...blocks, ...(forms && !pageForms ? forms.blocks : [])];
183
+ const duplicate = allTypes.find((b, i) => allTypes.findIndex((other) => other.type === b.type) !== i);
171
184
  if (duplicate) {
172
185
  throw new Error(`[websiteBuilder] Two blocks have the type "${duplicate.type}". Every block type must be unique. For blocks made with fromPayloadBlocks(), set \`prefix\` (for example \`prefix: 'site'\` makes "${duplicate.type}" "site${duplicate.type.charAt(0).toUpperCase()}${duplicate.type.slice(1)}").`);
173
186
  }
174
187
  // The props' validate, hooks and access, read now: Payload's config sanitizing later adds its
175
188
  // default validators and editor hooks to the same field objects (core/fieldSemantics.ts).
176
189
  const fieldRegistry = captureFieldSemantics(blocks);
177
- for (const [slug, o] of Object.entries(options.collections)) {
190
+ for (const [slug, o] of Object.entries(listedCollections)) {
178
191
  for (const name of o.legacyFields ?? []) {
179
192
  const source = sourceCollections.find((c) => c.slug === slug);
180
193
  if (name === (o.field ?? 'layout') || !source || !hasFieldNamed(source.fields, name)) {
@@ -183,7 +196,7 @@ export function websiteBuilder(options) {
183
196
  }
184
197
  }
185
198
  // A builder field that is the collection's own Payload blocks field stays the source of truth.
186
- for (const [slug, o] of Object.entries(options.collections)) {
199
+ for (const [slug, o] of Object.entries(listedCollections)) {
187
200
  const source = sourceCollections.find((c) => c.slug === slug);
188
201
  const field = o.field ?? 'layout';
189
202
  const found = source ? takeField(source.fields, field).found : undefined;
@@ -196,7 +209,9 @@ export function websiteBuilder(options) {
196
209
  ...(found.blocks ?? []).map((b) => (typeof b === 'string' ? b : b.slug)),
197
210
  ...(found.blockReferences ?? []).map((b) => (typeof b === 'string' ? b : b.slug)),
198
211
  ];
199
- blocksStorageOf[slug] = payloadBlocksStorage([...new Set(slugs)], blocks, `"${slug}.${field}"`);
212
+ // The form's field blocks are its own (first: the page versions go only inside a Form block).
213
+ const definitions = slug === forms?.slug ? [...forms.blocks, ...blocks] : blocks;
214
+ blocksStorageOf[slug] = payloadBlocksStorage([...new Set(slugs)], definitions, `"${slug}.${field}"`);
200
215
  }
201
216
  if (savedSections) {
202
217
  if (collections.some((c) => c.slug === savedSections.slug)) {
@@ -209,6 +224,13 @@ export function websiteBuilder(options) {
209
224
  // The full-screen builder edits saved sections like pages (no drafts: changes save at once).
210
225
  builderOptions[savedSections.slug] = { field: SECTION_LAYOUT_FIELD };
211
226
  }
227
+ // Forms on pages: a new submission to a form built on a page or a saved section needs that
228
+ // page or section to still show the form (formLiveCheck), before the app's own checks.
229
+ if (pageForms && forms?.submissions) {
230
+ const sourceField = (slug) => slug === savedSections?.slug ? { field: 'blocks', blocks: 'list' } : builderOptions[slug] && slug !== forms.slug ? { field: builderOptions[slug].field ?? 'layout', blocks: 'layout' } : null;
231
+ const check = formLiveCheck({ forms: forms.slug, sourceField });
232
+ collections = collections.map((c) => c.slug === forms.submissions ? { ...c, hooks: { ...c.hooks, beforeValidate: [check, ...(c.hooks?.beforeValidate ?? [])] } } : c);
233
+ }
212
234
  // References: which media and documents each layout uses ("Used in", delete protection).
213
235
  const references = resolveReferences({
214
236
  options: options.references,
@@ -217,7 +239,7 @@ export function websiteBuilder(options) {
217
239
  // Live saved sections (sectionRef): the section lists the pages that show it, and stays while one does.
218
240
  ...(savedSections ? { shared: [savedSections.slug] } : {}),
219
241
  sources: {
220
- ...Object.fromEntries(Object.entries(builderOptions).map(([slug, o]) => {
242
+ ...Object.fromEntries(Object.entries(builderOptions).filter(([slug]) => slug !== forms?.slug).map(([slug, o]) => {
221
243
  const storage = blocksStorageOf[slug];
222
244
  if (!storage)
223
245
  return [slug, { layout: o.field ?? 'layout' }];
@@ -233,7 +255,7 @@ export function websiteBuilder(options) {
233
255
  });
234
256
  // Page regions: document fields outside the layout that the builder shows and edits.
235
257
  const regionsOf = {};
236
- for (const [slug, o] of Object.entries(options.collections)) {
258
+ for (const [slug, o] of Object.entries(listedCollections)) {
237
259
  if (!o.regions)
238
260
  continue;
239
261
  if (!Array.isArray(o.regions))
@@ -264,10 +286,16 @@ export function websiteBuilder(options) {
264
286
  ...(o.legacyFields?.length ? { legacyFields: o.legacyFields } : {}),
265
287
  localization: localizationOf(slug),
266
288
  ...(regionsOf[slug] ? { regions: regionsOf[slug] } : {}),
267
- ...(blocksStorageOf[slug] ? { payloadBlocks: blocksStorageOf[slug] } : {}),
289
+ ...(blocksStorageOf[slug] ? { payloadBlocks: blocksStorageOf[slug] } : blocks.some((def) => def.upgrade) ? { blocks } : {}),
268
290
  },
269
291
  ]));
270
- const serverConfig = { collections: liveCollections, templates: targets.length > 0 ? templatesSlug : null };
292
+ const serverConfig = {
293
+ collections: liveCollections,
294
+ templates: targets.length > 0 ? templatesSlug : null,
295
+ // The block list the plugin checks against (with forms on pages completed), for the MCP tools.
296
+ blocks,
297
+ ...(pageForms && forms ? { pageForms: { collection: forms.slug, settings: forms.settings } } : {}),
298
+ };
271
299
  const views = config.admin?.components?.views;
272
300
  if (views?.[BUILDER_VIEW_KEY]) {
273
301
  throw new Error(`[websiteBuilder] An admin view named "${BUILDER_VIEW_KEY}" already exists. The plugin needs this name for the builder view.`);
@@ -341,19 +369,22 @@ export function websiteBuilder(options) {
341
369
  field,
342
370
  // A Payload blocks field offers its own block types only.
343
371
  // Its blocks have no style controls there: a Payload block stores no classes or animations,
344
- // also when the definition turns styles on for the builder's JSON layouts.
372
+ // also when the definition turns styles on for the builder's JSON layouts. Blocks with
373
+ // class keys (form fields) keep their classes.
345
374
  blocks: storage ? toJsonSafe(storage.blocks.map(withoutStyles)) : clientBlocks,
346
375
  canvasPath,
347
376
  cssEndpoint: `${apiRoute}${CANVAS_CSS_PATH}`,
348
377
  tokensEndpoint: `${apiRoute}${STYLE_TOKENS_PATH}`,
349
378
  // Only sections the field can store as they are.
350
- sections: storage
351
- ? sectionsThatFit(appSections, (list) => payloadBlocksProblems({ version: 1, blocks: list }, storage).length === 0)
352
- : sections,
379
+ sections: collectionOptions.sections === false
380
+ ? []
381
+ : storage
382
+ ? sectionsThatFit(appSections, (list) => payloadBlocksProblems({ version: 1, blocks: list }, storage).length === 0)
383
+ : sections,
353
384
  liveEndpoint: `${apiRoute}${LIVE_PATH}`,
354
385
  templates: clientTemplates,
355
386
  ai: options.ai ? aiClientConfig(options.ai, `${apiRoute}${AI_PATH}`) : null,
356
- savedSections: savedSections ? { collection: savedSections.slug } : null,
387
+ savedSections: savedSections && collectionOptions.sections !== false ? { collection: savedSections.slug } : null,
357
388
  themeEndpoint: theme ? theme.endpoint : null,
358
389
  // A Payload blocks field stores no classes.
359
390
  classes: classes && !storage ? classes.client : null,
@@ -365,11 +396,16 @@ export function websiteBuilder(options) {
365
396
  },
366
397
  validateTypes: [...fieldRegistry.types('validate')],
367
398
  localization: localizationOf(collection.slug),
368
- ...(regionsOf[collection.slug] ? { regions: toJsonSafe(regionsOf[collection.slug]) } : {}),
399
+ // Simple `admin.condition` functions become JSON rules, so the inspector can show and hide panel fields.
400
+ ...(regionsOf[collection.slug]
401
+ ? { regions: toJsonSafe(regionsOf[collection.slug].map((r) => ({ ...r, fields: r.fields.map((f) => ({ ...f, field: withBuilderConditions(f.field) })) }))) }
402
+ : {}),
369
403
  ...(storage ? { storage: 'payload-blocks', payloadRootTypes: [...storage.rootTypes] } : {}),
370
404
  ...(Object.keys(relations).length > 0 ? { relations } : {}),
405
+ ...(forms ? { forms: { collection: forms.slug, submissions: forms.submissions } } : {}),
371
406
  };
372
407
  const isSections = collection.slug === savedSections?.slug;
408
+ const formSync = pageForms && forms && !storage ? pageFormSync({ collection: collection.slug, layoutField: field, forms: forms.slug, settings: forms.settings }) : null;
373
409
  const built = addBuilder(collection, {
374
410
  field,
375
411
  clientConfig,
@@ -385,10 +421,15 @@ export function websiteBuilder(options) {
385
421
  localization: localizationOf(collection.slug),
386
422
  writeGate,
387
423
  payloadBlocks: storage,
424
+ // Forms on pages are written to the forms collection on publish. Saved sections write theirs
425
+ // from their `blocks`, after those are set (sectionFormSync, below).
426
+ ...(formSync && !isSections ? { formSync } : {}),
388
427
  });
428
+ // A new document has no id in the save hook: its forms are written after the create.
429
+ const withForms = formSync ? withFormSyncHooks(built, { collection: collection.slug, field, isSections, formSync }) : built;
389
430
  // After the layout hook, so the references follow the layout the session guard put in.
390
431
  // Publishing a page publishes the classes it uses that have unpublished changes.
391
- const withClasses = classes && !storage ? classes.withPublish(built, field) : built;
432
+ const withClasses = classes && !storage ? classes.withPublish(withForms, field) : withForms;
392
433
  return references ? addReferences(withClasses, references) : withClasses;
393
434
  })
394
435
  .concat(classes ? [withDesignAccess(classes.collection)] : [])
@@ -436,6 +477,8 @@ export function websiteBuilder(options) {
436
477
  }),
437
478
  // The template a document renders through, for the editor's empty page.
438
479
  ...(targets.length > 0 ? [templateEndpoint({ collections: liveCollections, templatesSlug, targets })] : []),
480
+ // "Move into this page": the Form block takes over a saved form that no other page uses.
481
+ ...(pageForms && forms ? [formClaimEndpoint({ forms: forms.slug, settings: forms.settings, collections: liveCollections, runtime: live })] : []),
439
482
  ...(classes ? classes.endpoints : []),
440
483
  ...(options.ai
441
484
  ? aiEndpoints({
@@ -448,6 +491,7 @@ export function websiteBuilder(options) {
448
491
  savedSections,
449
492
  getTokens: (req) => (req ? themeStyleTokens(req.payload, css) : getStyleTokens(css)),
450
493
  templates: templates ? { slug: templatesSlug, sources: templates.sources } : null,
494
+ forms: forms ? { slug: forms.slug, blocks: forms.blocks } : null,
451
495
  })
452
496
  : []),
453
497
  {
@@ -516,10 +560,28 @@ export function websiteBuilder(options) {
516
560
  };
517
561
  };
518
562
  }
563
+ /**
564
+ * Forms on pages: the form sync after a create (`formSyncAfterCreate`), and for saved sections the
565
+ * sync of their `blocks` after `syncSectionBlocks` (`sectionFormSync`).
566
+ */
567
+ function withFormSyncHooks(collection, args) {
568
+ const source = args.isSections ? { field: 'blocks', blocks: 'list' } : { field: args.field, blocks: 'layout' };
569
+ return {
570
+ ...collection,
571
+ hooks: {
572
+ ...collection.hooks,
573
+ beforeChange: [
574
+ ...(collection.hooks?.beforeChange ?? []),
575
+ ...(args.isSections ? [sectionFormSync({ collection: args.collection, layoutField: args.field, formSync: args.formSync })] : []),
576
+ ],
577
+ afterChange: [...(collection.hooks?.afterChange ?? []), formSyncAfterCreate({ collection: args.collection, source, formSync: args.formSync })],
578
+ },
579
+ };
580
+ }
519
581
  function addBuilder(collection, args) {
520
582
  if (args.payloadBlocks)
521
583
  return addPayloadBlocksBuilder(collection, args, args.payloadBlocks);
522
- const { field, clientConfig, blocks, css, sessions, bindings, afterLayout = [], ownFields, fieldRegistry, localization } = args;
584
+ const { field, clientConfig, blocks, css, sessions, bindings, afterLayout = [], ownFields, fieldRegistry, localization, formSync } = args;
523
585
  const cssField = cssFieldName(field);
524
586
  const gate = args.writeGate.hooks(collection.slug);
525
587
  // An existing field with this name (also inside rows, collapsibles or unnamed tabs) is reused
@@ -591,7 +653,7 @@ function addBuilder(collection, args) {
591
653
  afterError: [...(collection.hooks?.afterError ?? []), gate.afterError],
592
654
  beforeChange: [
593
655
  ...(collection.hooks?.beforeChange ?? []),
594
- layoutBeforeChange({ collection: collection.slug, field, cssField, blocks, css, sessions, bindings, ownFields, fieldRegistry, localization }),
656
+ layoutBeforeChange({ collection: collection.slug, field, cssField, blocks, css, sessions, bindings, ownFields, fieldRegistry, localization, formSync }),
595
657
  ...afterLayout,
596
658
  ],
597
659
  afterChange: [
@@ -691,10 +753,19 @@ function openInBuilderView(edit, clientConfig) {
691
753
  return {};
692
754
  return { default: { Component: DOCUMENT_EDIT_VIEW_COMPONENT } };
693
755
  }
694
- /** A block definition without style controls (classes, parts, animations, default classes). */
756
+ /**
757
+ * A block definition without the style controls a Payload blocks field cannot store. A block with
758
+ * class keys (a form field's `cssClass` and `partClasses`) keeps the classes those keys store.
759
+ */
695
760
  function withoutStyles(def) {
696
- const { defaultClassName: _defaultClassName, parts: _parts, ...rest } = def;
697
- return { ...rest, styles: false };
761
+ const keys = def.payload?.classKeys;
762
+ const { defaultClassName: _defaultClassName, parts, ...rest } = def;
763
+ return {
764
+ ...rest,
765
+ ...(keys?.partClassName && parts ? { parts } : {}),
766
+ ...(keys?.className && def.defaultClassName ? { defaultClassName: def.defaultClassName } : {}),
767
+ styles: Boolean(keys?.className),
768
+ };
698
769
  }
699
770
  /** Name of the hidden virtual field that carries the builder's config for a Payload blocks field. */
700
771
  export function builderConfigFieldName(field) {
@@ -1,6 +1,11 @@
1
1
  import type { PayloadRequest } from 'payload';
2
- /** The admin URL of the full-screen builder for a document, e.g. `/admin/builder/pages/12`. */
3
- export declare function builderViewPath(adminRoute: string, collection: string, id: string | number): string;
2
+ /**
3
+ * The admin URL of the full-screen builder for a document, e.g. `/admin/builder/pages/12`.
4
+ * `comment`: open that thread in comment mode (`?comment=34`).
5
+ */
6
+ export declare function builderViewPath(adminRoute: string, collection: string, id: string | number, options?: {
7
+ comment?: string | number;
8
+ }): string;
4
9
  /**
5
10
  * The search parameter that keeps Payload's edit form open when `editor.openInBuilder` is on:
6
11
  * `/admin/collections/pages/12?form=1`.
@@ -25,6 +30,20 @@ export declare function opensInBuilder(state: {
25
30
  inDrawer: boolean;
26
31
  formParam: string | null;
27
32
  }): boolean;
33
+ /**
34
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
35
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
36
+ * navigation, for an edit view that Next's router opened (a link in the admin).
37
+ *
38
+ * A client navigation right after a full load can lock React in a render loop in development
39
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
40
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
41
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
42
+ * From then on every render applies that close again and makes a new `modalState` object, and the
43
+ * effects that read it set state again, so the idle close never runs. A full page load gives
44
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
45
+ */
46
+ export declare function builderOpening(loadedUrl: string | null | undefined, currentUrl: string): 'page' | 'router';
28
47
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
29
48
  export declare function documentPath(url: ((doc: Record<string, unknown>) => string) | undefined, doc: Record<string, unknown>): string | null;
30
49
  /** The draft preview path from the collection's `admin.livePreview.url` or `admin.preview`. */
@@ -1,6 +1,12 @@
1
- /** The admin URL of the full-screen builder for a document, e.g. `/admin/builder/pages/12`. */
2
- export function builderViewPath(adminRoute, collection, id) {
3
- return `${adminRoute === '/' ? '' : adminRoute}/builder/${encodeURIComponent(collection)}/${encodeURIComponent(String(id))}`;
1
+ import { COMMENT_PARAM } from '../comments/shared.js';
2
+ /**
3
+ * The admin URL of the full-screen builder for a document, e.g. `/admin/builder/pages/12`.
4
+ * `comment`: open that thread in comment mode (`?comment=34`).
5
+ */
6
+ export function builderViewPath(adminRoute, collection, id, options = {}) {
7
+ const path = `${adminRoute === '/' ? '' : adminRoute}/builder/${encodeURIComponent(collection)}/${encodeURIComponent(String(id))}`;
8
+ const comment = options.comment === undefined ? '' : String(options.comment);
9
+ return comment ? `${path}?${COMMENT_PARAM}=${encodeURIComponent(comment)}` : path;
4
10
  }
5
11
  /**
6
12
  * The search parameter that keeps Payload's edit form open when `editor.openInBuilder` is on:
@@ -29,6 +35,29 @@ export function opensInBuilder(state) {
29
35
  return false;
30
36
  return formParam === null;
31
37
  }
38
+ /**
39
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
40
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
41
+ * navigation, for an edit view that Next's router opened (a link in the admin).
42
+ *
43
+ * A client navigation right after a full load can lock React in a render loop in development
44
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
45
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
46
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
47
+ * From then on every render applies that close again and makes a new `modalState` object, and the
48
+ * effects that read it set state again, so the idle close never runs. A full page load gives
49
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
50
+ */
51
+ export function builderOpening(loadedUrl, currentUrl) {
52
+ if (!loadedUrl)
53
+ return 'router';
54
+ try {
55
+ return new URL(loadedUrl).pathname === new URL(currentUrl).pathname ? 'page' : 'router';
56
+ }
57
+ catch {
58
+ return 'router';
59
+ }
60
+ }
32
61
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
33
62
  export function documentPath(url, doc) {
34
63
  if (!url)
@@ -69,6 +69,12 @@ export declare function resolveReferences(args: {
69
69
  shared?: string[];
70
70
  }): ReferencesServerConfig | null;
71
71
  type Id = string | number;
72
+ /**
73
+ * Every document one builder document's stored layout references (links, images, sections), as
74
+ * written: also documents that were deleted since. `null` when the collection stores no layout.
75
+ * Read the document with `context: { builderRawLayout: true }` so every locale counts.
76
+ */
77
+ export declare function layoutReferences(config: ReferencesServerConfig, slug: string, doc: Record<string, unknown>): Reference[] | null;
72
78
  /**
73
79
  * Fills the references field from the layout on every save that sends the layout (the session's
74
80
  * drafts, publish, the Edit view, the REST and Local APIs). The field is server-owned: what the
@@ -119,6 +119,18 @@ function layoutOf(source, data) {
119
119
  return source.decode(value);
120
120
  return source.blocksOnly ? normalizeLayout({ version: 1, blocks: value }) : normalizeLayout(value);
121
121
  }
122
+ /**
123
+ * Every document one builder document's stored layout references (links, images, sections), as
124
+ * written: also documents that were deleted since. `null` when the collection stores no layout.
125
+ * Read the document with `context: { builderRawLayout: true }` so every locale counts.
126
+ */
127
+ export function layoutReferences(config, slug, doc) {
128
+ const source = config.sources[slug];
129
+ if (!source)
130
+ return null;
131
+ const layout = layoutOf(source, doc);
132
+ return layout ? collectReferences(layout, config.blocks) : [];
133
+ }
122
134
  /** The references of one document's layout, checked against the database. */
123
135
  async function computeReferences(args) {
124
136
  const { config } = args;
@@ -24,6 +24,8 @@ export type BuilderCanvasProps = {
24
24
  */
25
25
  server?: CanvasServer;
26
26
  };
27
+ /** The app's definitions plus the admin's for types the app lacks. `own` alone when nothing is missing. */
28
+ export declare function withAdminDefinitions(own: BlockDefinition[] | undefined, admin: BlockDefinition[] | undefined): BlockDefinition[] | undefined;
27
29
  /**
28
30
  * The canvas iframe page. `?mode=thumbnail` turns it into the hidden renderer of the library's
29
31
  * section thumbnails; otherwise it is the editor's canvas.
@@ -41,13 +41,24 @@ const EDITOR_CSS = `
41
41
  border-radius: 4px;
42
42
  background: repeating-linear-gradient(45deg, rgb(0 0 0 / 0.03) 0 6px, transparent 6px 12px);
43
43
  }
44
+ /* An empty slot with a description: the description, centered. */
45
+ [data-slot-empty][data-slot-hint] { display: grid; place-items: center; padding: 8px; }
46
+ [data-slot-empty][data-slot-hint]::before {
47
+ content: attr(data-slot-hint);
48
+ font: 12px/1.4 system-ui, sans-serif;
49
+ color: rgb(0 0 0 / 0.55);
50
+ text-align: center;
51
+ pointer-events: none;
52
+ }
44
53
  [data-builder-hidden] { opacity: 0.35; }
45
- /* Repeated collection list items (2nd, 3rd, …): shown dimmed, never selectable. */
54
+ /* Repeated collection list items (2nd, 3rd, …): shown dimmed, never selectable. A component's
55
+ blocks are not selectable either (the component is), but they show as on the site. */
46
56
  [data-builder-repeat] { pointer-events: none; }
47
- [data-builder-repeat]:not([data-builder-repeat] [data-builder-repeat]) { opacity: 0.6; }
57
+ [data-builder-repeat]:not([data-builder-component]):not([data-builder-repeat] [data-builder-repeat]) { opacity: 0.6; }
48
58
  [data-builder-empty-page] { min-height: 240px; }
49
- /* The layout inside the page frame: the same box the canvas root gives a layout without a frame. */
50
- [data-builder-layout] { display: flow-root; }
59
+ /* The layout inside the page frame: the same box the canvas root gives a layout without a frame.
60
+ A frame that gives the box its own classes (\`<LayoutOutlet className>\`) styles it itself. */
61
+ [data-builder-layout]:not([class]) { display: flow-root; }
51
62
  /* Fixed regions of the page frame: text and images edit in place, but they never drag. */
52
63
  [data-builder-region] { user-select: none; }
53
64
  /* Inline text editing. The admin overlay draws the editing outline. */
@@ -101,6 +112,16 @@ const SCROLL_MARGIN = 48;
101
112
  * unless a double-click (which edits the text) follows. Other summary clicks act at once.
102
113
  */
103
114
  const SUMMARY_TOGGLE_DELAY_MS = 260;
115
+ /** The app's definitions plus the admin's for types the app lacks. `own` alone when nothing is missing. */
116
+ export function withAdminDefinitions(own, admin) {
117
+ if (!own)
118
+ return admin;
119
+ if (!admin)
120
+ return own;
121
+ const types = new Set(own.map((d) => d.type));
122
+ const missing = admin.filter((d) => !types.has(d.type));
123
+ return missing.length > 0 ? [...own, ...missing] : own;
124
+ }
104
125
  function send(message) {
105
126
  post(window.parent, message);
106
127
  }
@@ -900,7 +921,9 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
900
921
  // Bind the template to the sample document, load collection lists, then replace upload and
901
922
  // relationship IDs with documents. The newest layout wins.
902
923
  const resolveRun = useRef(0);
903
- const definitions = ownBlocks ?? init?.blocks;
924
+ // The app's definitions, plus the admin's for types the app does not list (a collection's own
925
+ // blocks, such as the form builder's field blocks). The same list object while both stay.
926
+ const definitions = useMemo(() => withAdminDefinitions(ownBlocks, init?.blocks), [ownBlocks, init?.blocks]);
904
927
  const [linkResolver] = useState(() => resolveLink ?? defaultResolveLink);
905
928
  useEffect(() => {
906
929
  if (!layout || !init || !definitions)
@@ -1077,7 +1100,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
1077
1100
  page = (_jsxs(_Fragment, { children: [_jsx(FrameProblem, { text: frame.error }), outlet] }));
1078
1101
  }
1079
1102
  else if (frame.status === 'ready' && frame.node) {
1080
- page = (_jsxs(LayoutOutletContext.Provider, { value: outlet, children: [_jsx(LayoutOutletPresence.Provider, { value: registerOutlet, children: _jsx(FrameBoundary, { resetKey: frame.node, renderError: (error) => (_jsxs(_Fragment, { children: [_jsx(FrameProblem, { text: error }), _jsx(LayoutOutlet, {})] })), children: frame.node }) }), outletMissing && (_jsxs(_Fragment, { children: [_jsx(FrameProblem, { text: NO_OUTLET }), _jsx("div", { [LAYOUT_ROOT_ATTRIBUTE]: '', "data-builder-outlet-fallback": "", children: layoutContent })] }))] }));
1103
+ page = (_jsxs(LayoutOutletContext.Provider, { value: layoutContent, children: [_jsx(LayoutOutletPresence.Provider, { value: registerOutlet, children: _jsx(FrameBoundary, { resetKey: frame.node, renderError: (error) => (_jsxs(_Fragment, { children: [_jsx(FrameProblem, { text: error }), _jsx(LayoutOutlet, {})] })), children: frame.node }) }), outletMissing && (_jsxs(_Fragment, { children: [_jsx(FrameProblem, { text: NO_OUTLET }), _jsx("div", { [LAYOUT_ROOT_ATTRIBUTE]: '', "data-builder-outlet-fallback": "", children: layoutContent })] }))] }));
1081
1104
  }
1082
1105
  else {
1083
1106
  page = outlet;
@@ -1,4 +1,4 @@
1
- import type { Block, BlockDefinition, Layout } from '../../../core/index.js';
1
+ import type { Block, BlockDefinition, Layout, Rect } from '../../../core/index.js';
2
2
  import type { CanvasImageTarget } from '../../../protocol/index.js';
3
3
  /** The attribute the mapping puts on an element that shows a text prop. Its value is the prop path. */
4
4
  export declare const AUTO_TEXT_ATTRIBUTE = "data-builder-text-auto";
@@ -19,6 +19,11 @@ export type MapOwner = {
19
19
  element: HTMLElement;
20
20
  };
21
21
  /** The block or region element `el` belongs to: its own or the nearest one above it. */
22
+ /**
23
+ * The part of an element's box that shows: its box cut by every ancestor up to `root` that clips
24
+ * its overflow (a carousel's viewport, a card with `overflow: hidden`).
25
+ */
26
+ export declare function shownRect(element: Element, root: Element): Rect;
22
27
  export declare function ownerOf(el: Element | null | undefined): MapOwner | null;
23
28
  export type MapperStats = {
24
29
  /** Mapping passes that mapped at least one block. */
@@ -23,6 +23,37 @@ export const OWNER_SELECTOR = `[data-block-id], [${REGION_ATTRIBUTE}]`;
23
23
  /** Where an element's own content stops: a nested block, a region, or the layout outlet of the page frame. */
24
24
  const BOUNDARY = `[data-block-id], [${REGION_ATTRIBUTE}], [${LAYOUT_ROOT_ATTRIBUTE}]`;
25
25
  /** The block or region element `el` belongs to: its own or the nearest one above it. */
26
+ /**
27
+ * The part of an element's box that shows: its box cut by every ancestor up to `root` that clips
28
+ * its overflow (a carousel's viewport, a card with `overflow: hidden`).
29
+ */
30
+ export function shownRect(element, root) {
31
+ const box = element.getBoundingClientRect();
32
+ let left = box.left;
33
+ let top = box.top;
34
+ let right = box.right;
35
+ let bottom = box.bottom;
36
+ const view = element.ownerDocument.defaultView;
37
+ if (!view)
38
+ return { x: left, y: top, width: box.width, height: box.height };
39
+ for (let el = element.parentElement; el && el !== root; el = el.parentElement) {
40
+ const style = view.getComputedStyle(el);
41
+ const clipX = style.overflowX !== 'visible';
42
+ const clipY = style.overflowY !== 'visible';
43
+ if (!clipX && !clipY)
44
+ continue;
45
+ const clip = el.getBoundingClientRect();
46
+ if (clipX) {
47
+ left = Math.max(left, clip.left);
48
+ right = Math.min(right, clip.right);
49
+ }
50
+ if (clipY) {
51
+ top = Math.max(top, clip.top);
52
+ bottom = Math.min(bottom, clip.bottom);
53
+ }
54
+ }
55
+ return { x: left, y: top, width: Math.max(0, right - left), height: Math.max(0, bottom - top) };
56
+ }
26
57
  export function ownerOf(el) {
27
58
  const element = el?.closest(OWNER_SELECTOR);
28
59
  if (!element)
@@ -418,10 +449,11 @@ export function createCanvasMapper(options) {
418
449
  return null;
419
450
  const hits = [];
420
451
  for (const image of entry.images) {
421
- const rect = image.element.getBoundingClientRect();
452
+ // The part of the image that shows: a carousel or a card may cut the rest off.
453
+ const rect = shownRect(image.element, root);
422
454
  if (rect.width < 1 || rect.height < 1)
423
455
  continue;
424
- if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
456
+ if (x < rect.x || x > rect.x + rect.width || y < rect.y || y > rect.y + rect.height)
425
457
  continue;
426
458
  hits.push({ ...image, rect });
427
459
  }
@@ -442,8 +474,7 @@ export function createCanvasMapper(options) {
442
474
  if (seen.has(key))
443
475
  return [];
444
476
  seen.add(key);
445
- const { left, top: y0, width, height } = hit.rect;
446
- return [{ path: hit.path, kind: hit.kind, rect: { x: left, y: y0, width, height } }];
477
+ return [{ path: hit.path, kind: hit.kind, rect: hit.rect }];
447
478
  });
448
479
  return owner.kind === 'region' ? { id: '', region: owner.name, spots } : { id: owner.id, spots };
449
480
  },
@@ -1,11 +1,15 @@
1
1
  import { type ReactNode } from 'react';
2
- /** Canvas only. The live layout the canvas renders. `BuilderCanvas` provides it around the page frame. */
2
+ /** Canvas only. The live layout's blocks the canvas renders. `BuilderCanvas` provides them around the page frame. */
3
3
  export declare const LayoutOutletContext: import("react").Context<ReactNode>;
4
4
  /** Mount notifications include outlets that appear later through Suspense. */
5
5
  export declare const LayoutOutletPresence: import("react").Context<(() => () => void) | null>;
6
6
  /**
7
7
  * Stands in for the layout in the page frame the canvas server action renders. The canvas fills
8
8
  * it with the layout it renders itself, so every block stays live: selectable, draggable and
9
- * edited in place, with no request to the server.
9
+ * edited in place, with no request to the server. The blocks sit in one `div` (the layout's box);
10
+ * `className` styles it, for example `flex flex-wrap gap-4` when the page puts the blocks in a
11
+ * flex row. Without it the box is a plain block.
10
12
  */
11
- export declare function LayoutOutlet(): ReactNode;
13
+ export declare function LayoutOutlet({ className }?: {
14
+ className?: string;
15
+ }): ReactNode;
@@ -1,16 +1,21 @@
1
1
  'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { createContext, useContext, useLayoutEffect } from 'react';
3
- /** Canvas only. The live layout the canvas renders. `BuilderCanvas` provides it around the page frame. */
4
+ import { LAYOUT_ROOT_ATTRIBUTE } from './regions.js';
5
+ /** Canvas only. The live layout's blocks the canvas renders. `BuilderCanvas` provides them around the page frame. */
4
6
  export const LayoutOutletContext = createContext(null);
5
7
  /** Mount notifications include outlets that appear later through Suspense. */
6
8
  export const LayoutOutletPresence = createContext(null);
7
9
  /**
8
10
  * Stands in for the layout in the page frame the canvas server action renders. The canvas fills
9
11
  * it with the layout it renders itself, so every block stays live: selectable, draggable and
10
- * edited in place, with no request to the server.
12
+ * edited in place, with no request to the server. The blocks sit in one `div` (the layout's box);
13
+ * `className` styles it, for example `flex flex-wrap gap-4` when the page puts the blocks in a
14
+ * flex row. Without it the box is a plain block.
11
15
  */
12
- export function LayoutOutlet() {
16
+ export function LayoutOutlet({ className } = {}) {
13
17
  const register = useContext(LayoutOutletPresence);
14
18
  useLayoutEffect(() => register?.(), [register]);
15
- return useContext(LayoutOutletContext);
19
+ const content = useContext(LayoutOutletContext);
20
+ return (_jsx("div", { [LAYOUT_ROOT_ATTRIBUTE]: '', className: className || undefined, children: content }));
16
21
  }