payload-canvas 0.5.2 → 0.6.1

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 (203) hide show
  1. package/README.md +342 -30
  2. package/dist/admin/ArrayRowLabel.d.ts +12 -0
  3. package/dist/admin/ArrayRowLabel.js +21 -0
  4. package/dist/admin/client.d.ts +1 -0
  5. package/dist/admin/client.js +2 -0
  6. package/dist/admin/editor/Editor.js +8 -1
  7. package/dist/admin/editor/Inspector.js +23 -17
  8. package/dist/admin/editor/Library.d.ts +2 -2
  9. package/dist/admin/editor/Library.js +7 -5
  10. package/dist/admin/editor/Outline.js +20 -12
  11. package/dist/admin/editor/Overlay.js +6 -4
  12. package/dist/admin/editor/actions.d.ts +7 -2
  13. package/dist/admin/editor/actions.js +44 -12
  14. package/dist/admin/editor/assistant/AssistantPanel.js +32 -20
  15. package/dist/admin/editor/comments/controller.d.ts +7 -0
  16. package/dist/admin/editor/comments/controller.js +12 -0
  17. package/dist/admin/editor/comments/useCommentFromURL.d.ts +2 -0
  18. package/dist/admin/editor/comments/useCommentFromURL.js +36 -0
  19. package/dist/admin/editor/dnd/smooth.js +1 -1
  20. package/dist/admin/editor/editor.scss +28 -0
  21. package/dist/admin/editor/fields/ArrayField.js +3 -3
  22. package/dist/admin/editor/fields/FormBlock.d.ts +20 -0
  23. package/dist/admin/editor/fields/FormBlock.js +167 -0
  24. package/dist/admin/editor/fields/FormFieldName.d.ts +25 -0
  25. package/dist/admin/editor/fields/FormFieldName.js +58 -0
  26. package/dist/admin/editor/fields/GroupField.d.ts +22 -2
  27. package/dist/admin/editor/fields/GroupField.js +30 -1
  28. package/dist/admin/editor/fields/MergeTags.d.ts +8 -0
  29. package/dist/admin/editor/fields/MergeTags.js +62 -0
  30. package/dist/admin/editor/fields/arrayRows.d.ts +0 -2
  31. package/dist/admin/editor/fields/arrayRows.js +0 -4
  32. package/dist/admin/editor/fields/fields.scss +150 -0
  33. package/dist/admin/editor/fields/values.d.ts +0 -2
  34. package/dist/admin/editor/fields/values.js +0 -14
  35. package/dist/admin/editor/icons.d.ts +3 -0
  36. package/dist/admin/editor/icons.js +3 -0
  37. package/dist/admin/editor/insert/InsertHandle.js +1 -1
  38. package/dist/admin/editor/insert/picker.d.ts +3 -2
  39. package/dist/admin/editor/insert/picker.js +9 -3
  40. package/dist/admin/editor/layout/LeftPanel.js +5 -3
  41. package/dist/admin/editor/layout/leftTabs.d.ts +15 -0
  42. package/dist/admin/editor/layout/leftTabs.js +18 -0
  43. package/dist/admin/editor/media/ImageEditor.d.ts +8 -2
  44. package/dist/admin/editor/media/ImageEditor.js +16 -10
  45. package/dist/admin/editor/media/media.scss +12 -2
  46. package/dist/admin/editor/media/model.d.ts +10 -1
  47. package/dist/admin/editor/media/model.js +19 -0
  48. package/dist/admin/editor/menu/blockMenu.js +3 -3
  49. package/dist/admin/editor/names.d.ts +9 -0
  50. package/dist/admin/editor/names.js +18 -0
  51. package/dist/admin/editor/regions/RegionFields.d.ts +6 -0
  52. package/dist/admin/editor/regions/RegionFields.js +122 -0
  53. package/dist/admin/editor/regions/RegionPane.js +5 -3
  54. package/dist/admin/editor/regions/RegionRows.js +2 -2
  55. package/dist/admin/editor/regions/required.d.ts +16 -0
  56. package/dist/admin/editor/regions/required.js +43 -0
  57. package/dist/admin/editor/renderField.d.ts +9 -2
  58. package/dist/admin/editor/renderField.js +86 -32
  59. package/dist/admin/editor/runtime.d.ts +3 -2
  60. package/dist/admin/editor/runtime.js +12 -18
  61. package/dist/admin/editor/styles/StylesPanel.js +4 -2
  62. package/dist/admin/editor/styles/context.js +9 -4
  63. package/dist/admin/editor/topbar/ContentModeToggle.js +1 -1
  64. package/dist/admin/editor/topbar/DocumentActions.js +4 -3
  65. package/dist/admin/editor/topbar/contentMode.scss +0 -9
  66. package/dist/admin/editor/topbar/topbar.scss +1 -41
  67. package/dist/admin/editor/ui/Tabs.d.ts +17 -0
  68. package/dist/admin/editor/ui/Tabs.js +17 -0
  69. package/dist/admin/forms/SubmissionCells.d.ts +6 -0
  70. package/dist/admin/forms/SubmissionCells.js +31 -0
  71. package/dist/admin/forms/SubmissionView.d.ts +5 -0
  72. package/dist/admin/forms/SubmissionView.js +106 -0
  73. package/dist/admin/forms/submissionData.d.ts +32 -0
  74. package/dist/admin/forms/submissionData.js +63 -0
  75. package/dist/admin/forms/submissions.scss +197 -0
  76. package/dist/admin/rsc.d.ts +2 -0
  77. package/dist/admin/rsc.js +5 -0
  78. package/dist/ai/endpoint.d.ts +5 -0
  79. package/dist/ai/endpoint.js +18 -8
  80. package/dist/ai/prompt.d.ts +8 -0
  81. package/dist/ai/prompt.js +30 -0
  82. package/dist/ai/tools.d.ts +6 -1
  83. package/dist/ai/tools.js +90 -6
  84. package/dist/blocks/builtins/carousel.js +10 -1
  85. package/dist/blocks/defaults.js +27 -2
  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 +7 -2
  181. package/dist/plugin/links.js +9 -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/components/AutoplayVideo.d.ts +20 -0
  189. package/dist/react/components/AutoplayVideo.js +34 -0
  190. package/dist/react/components/Video.d.ts +9 -1
  191. package/dist/react/components/Video.js +39 -11
  192. package/dist/react/components/lazy.d.ts +2 -0
  193. package/dist/react/components/lazy.js +2 -0
  194. package/dist/react/components/videoPlayback.d.ts +30 -0
  195. package/dist/react/components/videoPlayback.js +33 -0
  196. package/dist/react/render/LayoutOutlet.d.ts +7 -3
  197. package/dist/react/render/LayoutOutlet.js +9 -4
  198. package/dist/react/render/RenderLayout.js +18 -9
  199. package/dist/react/render/resolve.d.ts +1 -0
  200. package/dist/react/render/resolve.js +5 -1
  201. package/dist/react/render/types.d.ts +1 -1
  202. package/dist/react/server.js +19 -0
  203. package/package.json +5 -1
@@ -0,0 +1,21 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useRowLabel, useTranslation } from '@payloadcms/ui';
4
+ import { textOf } from '../core/fields.js';
5
+ import { rowLabel } from '../core/rowLabel.js';
6
+ /**
7
+ * A row label for any Payload array field: the row's most telling value ("Sales team (sales)"),
8
+ * else "Item 1" with the field's singular label. The same rule names rows in the builder's
9
+ * inspector (`rowLabel` in `payload-canvas/core`). Set it as `admin.components.RowLabel`.
10
+ */
11
+ export function ArrayRowLabel({ field }) {
12
+ const { data, rowNumber } = useRowLabel();
13
+ const { i18n } = useTranslation();
14
+ const fields = field && 'fields' in field ? field.fields : [];
15
+ const labels = field && 'labels' in field ? field.labels : undefined;
16
+ const singular = labels?.singular;
17
+ // A label is a string or one string per language.
18
+ const name = typeof singular === 'object' && singular ? (singular[i18n.language] ?? singular) : singular;
19
+ // Payload's row number here is the 0-based row index.
20
+ return (_jsx("span", { className: "row-label", style: { pointerEvents: 'none' }, children: rowLabel(data, fields, rowNumber ?? 0, textOf(name)) }));
21
+ }
@@ -1,4 +1,5 @@
1
1
  export { AiKeyField } from './AiKeyField.js';
2
+ export { ArrayRowLabel } from './ArrayRowLabel.js';
2
3
  export { BuilderTab } from './BuilderTab.js';
3
4
  export { DocumentEditView } from './DocumentEditView.js';
4
5
  export { PublishButton } from './editor/topbar/settingsDrawer.js';
@@ -6,7 +6,9 @@
6
6
  // 'payload-canvas/client#PublishButton' — Payload's Publish button, hidden in the builder's settings drawer
7
7
  // 'payload-canvas/client#TemplateConditionsField' — a template's conditions as condition rows
8
8
  // 'payload-canvas/client#AiKeyField' — an API key in the AI settings global ("Set, ends in …4f2a", Replace, Clear)
9
+ // 'payload-canvas/client#ArrayRowLabel' — a row label for any array field, from the row's own values (core `rowLabel`)
9
10
  export { AiKeyField } from './AiKeyField.js';
11
+ export { ArrayRowLabel } from './ArrayRowLabel.js';
10
12
  export { BuilderTab } from './BuilderTab.js';
11
13
  export { DocumentEditView } from './DocumentEditView.js';
12
14
  export { PublishButton } from './editor/topbar/settingsDrawer.js';
@@ -9,7 +9,9 @@ import { DragLayer } from './DragLayer.js';
9
9
  import { dropAt, endSmoothDrag, isSmoothDrag, MAKE_ROOM_EASING, SETTLE_EASING, startSmoothDrag } from './dnd/smooth.js';
10
10
  import { Inspector } from './Inspector.js';
11
11
  import { CommentsOrInspector } from './comments/CommentsPanel.js';
12
+ import { useCommentFromURL } from './comments/useCommentFromURL.js';
12
13
  import { LeftPanel } from './layout/LeftPanel.js';
14
+ import { selectLeftTab } from './layout/leftTabs.js';
13
15
  import { applySizes, readSizes } from './layout/panels.js';
14
16
  import { Splitter } from './layout/Splitter.js';
15
17
  import './layout/layout.scss';
@@ -62,6 +64,7 @@ export function Editor({ config, meta, icon, locale, canEditDesign }) {
62
64
  useFollow(runtime);
63
65
  useTemplateController(runtime);
64
66
  useComponentRefresh(runtime);
67
+ useCommentFromURL(runtime);
65
68
  useEffect(() => runtime.assistant?.setDocument(config.collection, docId), [runtime, config.collection, docId]);
66
69
  useEffect(() => () => runtime.assistant?.stop(), [runtime]);
67
70
  // The hidden thumbnail iframe goes with the editor.
@@ -117,6 +120,10 @@ export function Editor({ config, meta, icon, locale, canEditDesign }) {
117
120
  rect: initial ? { x: initial.left, y: initial.top, width: initial.width, height: initial.height } : null,
118
121
  fromOutline: String(active.id).startsWith('outline:'),
119
122
  });
123
+ // A block or section from the library: Layers opens at once (as in Webflow), so the drop can go
124
+ // in the tree or on the canvas. The library item stays mounted in its hidden panel, so the drag lives on.
125
+ if (data.source.kind === 'new')
126
+ selectLeftTab(runtime, 'layers');
120
127
  stopAutoScroll.current = startAutoScroll(runtime);
121
128
  };
122
129
  const onDragMove = ({ collisions }) => {
@@ -150,7 +157,7 @@ export function Editor({ config, meta, icon, locale, canEditDesign }) {
150
157
  return insertBlocks(runtime, section, target.to);
151
158
  if (source.kind === 'block')
152
159
  return runtime.store.apply({ type: 'move', id: source.id, to: target.to }, { select: source.id });
153
- const block = runtime.createBlock(source.blockType);
160
+ const block = runtime.createBlock(source.blockType, target.to);
154
161
  if (!block || !runtime.store.apply({ type: 'insert', block, to: target.to }, { select: block.id, newContent: true }))
155
162
  return false;
156
163
  runtime.focusRequest.set(block.id);
@@ -4,6 +4,7 @@ import { CheckboxInput, TextInput } from '@payloadcms/ui';
4
4
  import { useDeferredValue, useEffect, useState } from 'react';
5
5
  import { blockParts, findBlock, getBlockDefinition, htmlIdProblem, htmlIdsOf } from '../../core/index.js';
6
6
  import { BlockIcon, Icon } from './icons.js';
7
+ import { Tabs } from './ui/Tabs.js';
7
8
  import { useContentMode } from './contentMode.js';
8
9
  import { blockMenuEntries } from './menu/blockMenu.js';
9
10
  import { MenuButton } from './menu/Menu.js';
@@ -18,7 +19,7 @@ import { useAccessRefresh } from './fields/access.js';
18
19
  import { InputError } from './fields/CheckedInputs.js';
19
20
  import { BlockContentFields } from './renderField.js';
20
21
  import { useRuntime } from './runtime.js';
21
- import { storesBuilderData } from './actions.js';
22
+ import { storesBuilderData, storesClasses } from './actions.js';
22
23
  import { shortcutList } from './shortcuts.js';
23
24
  import { useEditor } from './store.js';
24
25
  import { StylesPanel } from './styles/StylesPanel.js';
@@ -28,9 +29,6 @@ import { useOptionalValue, useValue, useValueSelector } from './valueStore.js';
28
29
  import { RegionPane } from './regions/RegionPane.js';
29
30
  import { SECTION_REF_BLOCK } from '../../blocks/builtins/sectionRef.js';
30
31
  import { ComponentBanner, ComponentValuesPanel } from './sections/ComponentFields.js';
31
- function Tabs({ value, options, onChange, variant = 'underline' }) {
32
- return (_jsx("div", { className: variant === 'segmented' ? 'builder-editor__segmented builder-editor__segmented--full' : 'builder-editor__tabs', role: "tablist", children: options.map((option) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": value === option.id, className: variant === 'segmented' ? 'builder-editor__segment' : 'builder-editor__tab', onClick: () => onChange(option.id), children: [option.icon && _jsx(Icon, { name: option.icon, size: 13 }), option.label] }, option.id))) }));
33
- }
34
32
  export function Inspector() {
35
33
  const runtime = useRuntime();
36
34
  const { inspectorRef } = runtime;
@@ -86,8 +84,10 @@ function saveTabChoice(tab) {
86
84
  }
87
85
  }
88
86
  /** The tab a block opens on: the chosen tab, unless the block has nothing to show there. */
89
- function tabFor(chosen, def, justAdded) {
87
+ function tabFor(chosen, def, justAdded, allTabs) {
90
88
  const hasFields = (def?.fields.length ?? 0) > 0;
89
+ if (!allTabs && chosen !== 'content' && chosen !== 'styles')
90
+ return 'content';
91
91
  // A block that was just added opens on its content, so typing starts at once.
92
92
  if (justAdded && hasFields)
93
93
  return 'content';
@@ -119,7 +119,9 @@ function BlockPane() {
119
119
  const def = block ? getBlockDefinition(runtime.config.blocks, block.type) : undefined;
120
120
  // Content mode edits content only: no Styles, Motion or Advanced tab.
121
121
  const contentMode = useContentMode(runtime);
122
- const tab = storesBuilderData(runtime) && !contentMode ? tabFor(chosen, def, block !== null && block.id === addedId) : 'content';
122
+ // A Payload blocks field keeps only the classes of blocks with class keys: Content and Styles.
123
+ const styled = block !== null && storesClasses(runtime, block.type);
124
+ const tab = styled && !contentMode ? tabFor(chosen, def, block !== null && block.id === addedId, storesBuilderData(runtime)) : 'content';
123
125
  const setTab = (next) => {
124
126
  setAddedId(null);
125
127
  setChosen(next);
@@ -138,17 +140,21 @@ function BlockPane() {
138
140
  });
139
141
  return () => cancelAnimationFrame(frame);
140
142
  }, [block, focusRequest, runtime]);
141
- if (!block)
142
- return region && runtime.regions ? _jsx(RegionPane, { regions: runtime.regions, name: region }, region) : _jsx(EmptyState, {});
143
- return (_jsxs("div", { className: "builder-editor__block-pane", children: [_jsx(BlockHeader, { block: block }), _jsx(BlockProblems, { blockId: block.id }), _jsx(EditingBanner, { blockId: block.id }), _jsx(LocaleNote, { blockId: block.id, tab: tab }), !contentMode && (_jsx(Tabs, { value: tab, onChange: setTab, options: storesBuilderData(runtime)
144
- ? [
145
- { id: 'content', label: 'Content' },
146
- { id: 'styles', label: 'Styles' },
147
- { id: 'motion', label: 'Motion' },
148
- { id: 'advanced', label: 'Advanced' },
149
- ]
150
- : // A Payload blocks field holds the blocks' own fields only.
151
- [{ id: 'content', label: 'Content' }] })), tab === 'content' && _jsx(BlockContentFields, { block: block }), tab === 'content' && block.type === SECTION_REF_BLOCK && _jsx(ComponentValuesPanel, { block: block }), tab === 'styles' && storesBuilderData(runtime) && _jsx(StyleFields, { block: block }), tab === 'motion' && storesBuilderData(runtime) && _jsx(MotionPanel, { blockId: block.id, blockType: block.type, motion: block.motion }), tab === 'advanced' && storesBuilderData(runtime) && _jsx(AdvancedFields, { block: block })] }, block.id));
143
+ if (!block) {
144
+ // A selected region shows its pane. Without a selection, a panel region (a form's settings) shows its fields.
145
+ const shownRegion = region ?? runtime.regions?.config.find((r) => r.panel)?.name ?? null;
146
+ return shownRegion && runtime.regions ? _jsx(RegionPane, { regions: runtime.regions, name: shownRegion }, shownRegion) : _jsx(EmptyState, {});
147
+ }
148
+ return (_jsxs("div", { className: "builder-editor__block-pane", children: [_jsx(BlockHeader, { block: block }), _jsx(BlockProblems, { blockId: block.id }), _jsx(EditingBanner, { blockId: block.id }), _jsx(LocaleNote, { blockId: block.id, tab: tab }), !contentMode && styled && (_jsx(Tabs, { value: tab, onChange: setTab, options: [
149
+ { id: 'content', label: 'Content' },
150
+ { id: 'styles', label: 'Styles' },
151
+ ...(storesBuilderData(runtime)
152
+ ? [
153
+ { id: 'motion', label: 'Motion' },
154
+ { id: 'advanced', label: 'Advanced' },
155
+ ]
156
+ : []),
157
+ ] })), tab === 'content' && _jsx(BlockContentFields, { block: block }), tab === 'content' && block.type === SECTION_REF_BLOCK && _jsx(ComponentValuesPanel, { block: block }), tab === 'styles' && styled && _jsx(StyleFields, { block: block }), tab === 'motion' && storesBuilderData(runtime) && _jsx(MotionPanel, { blockId: block.id, blockType: block.type, motion: block.motion }), tab === 'advanced' && storesBuilderData(runtime) && _jsx(AdvancedFields, { block: block })] }, block.id));
152
158
  }
153
159
  /** What stopped the last publish, for this block. */
154
160
  function BlockProblems({ blockId }) {
@@ -1,8 +1,8 @@
1
1
  import type { SectionDefinition } from '../../core/types.js';
2
2
  /**
3
3
  * A library tab of the left panel: blocks or ready-made sections, with a search field. Drag an
4
- * item onto the canvas (or the Layers tab, which opens the tree), or click it to insert it at the
5
- * selection.
4
+ * item onto the canvas or into the Layers tree (Layers opens when the drag starts), or click it to
5
+ * insert it at the selection (Layers then opens with the new block selected).
6
6
  */
7
7
  export declare function Library({ kind }: {
8
8
  kind: 'blocks' | 'sections';
@@ -9,6 +9,7 @@ import { sectionVersion, sectionVersions } from '../../core/sections.js';
9
9
  import { builderViewPath } from '../../plugin/links.js';
10
10
  import { componentCopy, insertBlocks, insertNewBlock, plainSectionBlocks, sectionPosition } from './actions.js';
11
11
  import { BlockIcon, Icon } from './icons.js';
12
+ import { showAddedInLayers } from './layout/leftTabs.js';
12
13
  import { MenuButton } from './menu/Menu.js';
13
14
  import { useRuntime } from './runtime.js';
14
15
  import { requestDeleteSection, requestRenameSection } from './sections/SectionDialog.js';
@@ -41,8 +42,8 @@ const matches = (query, ...texts) => {
41
42
  };
42
43
  /**
43
44
  * A library tab of the left panel: blocks or ready-made sections, with a search field. Drag an
44
- * item onto the canvas (or the Layers tab, which opens the tree), or click it to insert it at the
45
- * selection.
45
+ * item onto the canvas or into the Layers tree (Layers opens when the drag starts), or click it to
46
+ * insert it at the selection (Layers then opens with the new block selected).
46
47
  */
47
48
  export function Library({ kind }) {
48
49
  const [query, setQuery] = useState('');
@@ -75,7 +76,8 @@ function BlockTile({ def }) {
75
76
  const icon = def.icon ?? def.type;
76
77
  const data = { source: { kind: 'new', blockType: def.type }, label: def.label, icon };
77
78
  const { setNodeRef, listeners, attributes } = useDraggable({ id: `library:${def.type}`, data });
78
- const insert = () => insertNewBlock(runtime, def.type);
79
+ // The inspector takes the focus (its first field).
80
+ const insert = () => showAddedInLayers(runtime, insertNewBlock(runtime, def.type));
79
81
  return (_jsxs("button", { ref: setNodeRef, type: "button", className: "builder-editor__tile", "data-tooltip": def.description ?? def.label, onClick: insert, ...listeners, ...attributes, children: [_jsx("span", { className: "builder-editor__tile-icon", children: _jsx(BlockIcon, { name: icon, size: 18 }) }), _jsx("span", { className: "builder-editor__tile-label", children: def.label })] }));
80
82
  }
81
83
  const SectionList = memo(function SectionList({ query }) {
@@ -133,7 +135,7 @@ function SectionCard({ section }) {
133
135
  };
134
136
  const { setNodeRef, listeners, attributes } = useDraggable({ id: `section:${section.id}`, data, disabled: !root });
135
137
  const insert = () => {
136
- if (insertBlocks(runtime, blocks, sectionPosition(runtime)))
138
+ if (showAddedInLayers(runtime, insertBlocks(runtime, blocks, sectionPosition(runtime)), { focus: true }))
137
139
  runtime.notify(`Added ${shown.label}`);
138
140
  };
139
141
  // Versions flip in place: the card keeps one height (one label line, two description lines).
@@ -153,7 +155,7 @@ function SavedSectionMenu({ section, component }) {
153
155
  const { config: { routes }, } = useConfig();
154
156
  const collection = runtime.config.savedSections?.collection;
155
157
  const addSaved = (blocks) => {
156
- if (insertBlocks(runtime, blocks, sectionPosition(runtime)))
158
+ if (showAddedInLayers(runtime, insertBlocks(runtime, blocks, sectionPosition(runtime)), { focus: true }))
157
159
  runtime.notify(`Added ${section.label}`);
158
160
  };
159
161
  // Opens the section in the full-screen builder, like a page.
@@ -10,7 +10,7 @@ import { PeerDots } from './live/PresenceUI.js';
10
10
  import { missingWords, useUntranslated } from './locale/locale.js';
11
11
  import { BLOCK_KEYS, keyText } from './menu/keys.js';
12
12
  import { openBlockMenu, renameRequest } from './menu/requests.js';
13
- import { blockPreview, blockSummary, childrenOf, customLabel, typeName } from './names.js';
13
+ import { blockPreview, blockSummary, childrenOf, componentMark, customLabel, typeName } from './names.js';
14
14
  import { useContentMode } from './contentMode.js';
15
15
  import { OUTLINE_INDENT, useRuntime } from './runtime.js';
16
16
  import { RegionRows } from './regions/RegionRows.js';
@@ -23,18 +23,23 @@ import { useValue, useValueSelector } from './valueStore.js';
23
23
  /** Visible rows, depth first. Children of collapsed containers are left out. */
24
24
  function visibleRows(runtime, layout, collapsed) {
25
25
  const out = [];
26
- const visit = (blocks, depth, parentText) => {
27
- for (const block of blocks) {
28
- const container = slotNames(getBlockDefinition(runtime.config.blocks, block.type)).length > 0;
26
+ const visit = (blocks, depth, parentText, itemLabel) => {
27
+ blocks.forEach((block, i) => {
28
+ const definition = getBlockDefinition(runtime.config.blocks, block.type);
29
+ const container = slotNames(definition).length > 0;
29
30
  const children = childrenOf(block);
30
31
  const open = !collapsed.has(block.id);
31
32
  const preview = blockPreview(block);
32
33
  // "Section · Our services" > "Stack · Our services" says the same thing twice.
33
34
  const text = container && preview === parentText ? '' : preview;
34
- out.push({ block, depth, container, open, childCount: children.length, text });
35
- if (open)
36
- visit(children, depth + 1, preview);
37
- }
35
+ const itemName = itemLabel ? `${itemLabel} ${i + 1}` : null;
36
+ out.push({ block, depth, container, open, childCount: children.length, text, itemName });
37
+ if (!open)
38
+ return;
39
+ // Slot by slot, in the order `childrenOf` counts them, so each slot numbers its own items.
40
+ for (const [slot, list] of Object.entries(block.slots ?? {}))
41
+ visit(list, depth + 1, preview, definition?.slots?.[slot]?.itemLabel);
42
+ });
38
43
  };
39
44
  visit(layout.blocks, 0, '');
40
45
  return out;
@@ -240,7 +245,7 @@ export function Outline() {
240
245
  ids.add(b.id);
241
246
  });
242
247
  runtime.collapsed.set(ids);
243
- }, children: _jsx(Icon, { name: "chevronRight", size: 14 }) }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Expand all", "data-tooltip": "Expand all", onClick: () => runtime.collapsed.set(new Set()), children: _jsx(Icon, { name: "chevronDown", size: 14 }) })] })] }), _jsx(RegionRows, {}), rows.length === 0 ? (_jsx("div", { ref: outlineRef, className: "builder-editor__outline", children: _jsxs("div", { className: "builder-editor__empty", children: [_jsx(Icon, { name: "layers", size: 20 }), _jsx("p", { children: "The page is empty." }), _jsx("p", { className: "builder-editor__hint", children: "Add blocks from the Blocks or Sections tab: drag them onto the canvas, or click one." })] }) })) : (_jsx("div", { ref: outlineRef, className: "builder-editor__outline", role: "tree", "aria-label": "Layers", tabIndex: -1, onKeyDown: onKeyDown, children: rows.map((row) => (_jsx(OutlineRow, { block: row.block, depth: row.depth, container: row.container, open: row.open, childCount: row.childCount, text: row.text, issues: issues.get(row.block.id) ?? NO_ISSUES, untranslated: untranslated.get(row.block.id)?.length ?? 0, missing: missing, broken: broken.has(row.block.id), focusable: noSelectedRow && row.block.id === firstId, renaming: renaming === row.block.id, onRename: onRename }, row.block.id))) }))] }));
248
+ }, children: _jsx(Icon, { name: "chevronRight", size: 14 }) }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Expand all", "data-tooltip": "Expand all", onClick: () => runtime.collapsed.set(new Set()), children: _jsx(Icon, { name: "chevronDown", size: 14 }) })] })] }), _jsx(RegionRows, {}), rows.length === 0 ? (_jsx("div", { ref: outlineRef, className: "builder-editor__outline", children: _jsxs("div", { className: "builder-editor__empty", children: [_jsx(Icon, { name: "layers", size: 20 }), _jsx("p", { children: "The page is empty." }), _jsx("p", { className: "builder-editor__hint", children: "Add blocks from the Blocks or Sections tab: drag them onto the canvas or here, or click one." })] }) })) : (_jsx("div", { ref: outlineRef, className: "builder-editor__outline", role: "tree", "aria-label": "Layers", tabIndex: -1, onKeyDown: onKeyDown, children: rows.map((row) => (_jsx(OutlineRow, { block: row.block, depth: row.depth, container: row.container, open: row.open, childCount: row.childCount, text: row.text, itemName: row.itemName, issues: issues.get(row.block.id) ?? NO_ISSUES, untranslated: untranslated.get(row.block.id)?.length ?? 0, missing: missing, broken: broken.has(row.block.id), focusable: noSelectedRow && row.block.id === firstId, renaming: renaming === row.block.id, onRename: onRename }, row.block.id))) }))] }));
244
249
  }
245
250
  /** Inline actions must not start a drag or select the row. */
246
251
  const stop = (e) => e.stopPropagation();
@@ -251,7 +256,7 @@ function openRowMenu(runtime, id, e) {
251
256
  e.preventDefault();
252
257
  openBlockMenu(runtime, id, { x: e.clientX, y: e.clientY }, 'outline');
253
258
  }
254
- const OutlineRow = memo(function OutlineRow({ block, depth, container, open, childCount, text, issues, untranslated, missing, broken, focusable, renaming, onRename, }) {
259
+ const OutlineRow = memo(function OutlineRow({ block, depth, container, open, childCount, text, itemName, issues, untranslated, missing, broken, focusable, renaming, onRename, }) {
255
260
  const runtime = useRuntime();
256
261
  const selected = useEditor(runtime.store, (s) => s.selectedId === block.id);
257
262
  const hovered = useEditor(runtime.store, (s) => s.hoveredId === block.id);
@@ -264,7 +269,9 @@ const OutlineRow = memo(function OutlineRow({ block, depth, container, open, chi
264
269
  const contentMode = useContentMode(runtime);
265
270
  const { setNodeRef, listeners, attributes } = useDraggable({ id: `outline:${block.id}`, data, disabled: renaming || contentMode });
266
271
  const label = customLabel(block);
267
- const name = label ?? typeName(block, typeLabel);
272
+ // A slide (or another slot item) without a name of its own: "Slide 2".
273
+ const slotItem = label ? null : itemName;
274
+ const name = label ?? slotItem ?? typeName(block, typeLabel);
268
275
  const bindingCount = Object.keys(block.bindings ?? {}).length;
269
276
  const tag = typeof block.props?.as === 'string' && block.props.as !== 'div' ? ` <${block.props.as}>` : '';
270
277
  const className = [
@@ -300,10 +307,11 @@ const OutlineRow = memo(function OutlineRow({ block, depth, container, open, chi
300
307
  },
301
308
  },
302
309
  ];
303
- return (_jsxs("div", { ref: setNodeRef, "data-outline-row": block.id, "data-depth": depth, className: className, onClick: () => runtime.store.select(block.id), onDoubleClick: () => !contentMode && onRename(block.id), onContextMenu: (e) => openRowMenu(runtime, block.id, e),
310
+ return (_jsxs("div", { ref: setNodeRef, "data-outline-row": block.id, "data-depth": depth, ...componentMark(block), className: className, onClick: () => runtime.store.select(block.id), onDoubleClick: () => !contentMode && onRename(block.id), onContextMenu: (e) => openRowMenu(runtime, block.id, e),
304
311
  // Not while dragging: the row actions would mount and unmount under the pointer, and every
305
312
  // DOM insert restyles the whole admin (Payload's `body:has(...)` rules).
306
313
  onPointerEnter: () => !runtime.drag.get() && runtime.store.hover(block.id), onPointerLeave: () => !runtime.drag.get() && runtime.store.hover(null), ...listeners, ...attributes, "aria-disabled": undefined, role: "treeitem", "aria-label": [
314
+ slotItem,
307
315
  blockSummary(block, typeLabel),
308
316
  block.hidden && 'hidden on the site',
309
317
  block.motion && 'animated',
@@ -11,7 +11,7 @@ import { InsertHandle } from './insert/InsertHandle.js';
11
11
  import { ImageEditor } from './media/ImageEditor.js';
12
12
  import { BlockContextMenu, blockMenuEntries } from './menu/blockMenu.js';
13
13
  import { MenuButton } from './menu/Menu.js';
14
- import { blockName } from './names.js';
14
+ import { blockName, componentMark, isComponent } from './names.js';
15
15
  import { PeerCursors, PeerSelections } from './live/PresenceUI.js';
16
16
  import { RegionOverlay } from './regions/RegionOverlay.js';
17
17
  import { SectionVariantSwitch } from './sections/variants.js';
@@ -118,6 +118,8 @@ export function Overlay() {
118
118
  return { className: classes.filter(Boolean).join(' '), style };
119
119
  };
120
120
  const taggedActors = new Set();
121
+ // The action bar sits inside the selected block's top right corner (no room above it).
122
+ const barInside = Boolean(selected && selectedRect && !editing && !drag && !roomAbove(selectedRect) && selectedRect.width * zoom >= NARROW_BLOCK);
121
123
  return (_jsxs("div", { className: "builder-editor__overlay", children: [!drag &&
122
124
  problems.map((problem, i) => {
123
125
  const rect = rectOf(problem.blockId);
@@ -128,7 +130,7 @@ export function Overlay() {
128
130
  transform: `translate3d(${smooth.placeholder.x}px, ${smooth.placeholder.y}px, 0)`,
129
131
  width: smooth.placeholder.width,
130
132
  height: smooth.placeholder.height,
131
- }, children: _jsx("span", { className: "builder-editor__drop-label builder-dnd-gap__label", hidden: !smooth.into, "data-label": smooth.into ? `Into ${smooth.into}` : '', children: _jsx(Icon, { name: "plus", size: 12 }) }) }) })), hovered && hoverRect && (_jsx("div", { className: "builder-editor__hover", style: box(hoverRect), children: _jsxs("span", { ...tagProps(hoverRect, 'hover'), children: [_jsx(BlockIcon, { name: runtime.blockIcon(hovered.type), size: 12 }), blockName(hovered, runtime.blockLabel(hovered.type))] }) })), sourceRect && _jsx("div", { className: "builder-editor__source", style: box(sourceRect) }), selected && selectedRect && (_jsxs(_Fragment, { children: [_jsxs("div", { hidden: Boolean(smooth), className: `builder-editor__selection${selected.hidden ? ' builder-editor__selection--hidden' : ''}${editing ? ' builder-editor__selection--editing' : ''}`, style: box(editing && editRect ? editRect : selectedRect), children: [editing && editRect && inline?.kind !== 'rich' && (_jsxs("span", { ...tagProps(editRect, 'editing'), children: [_jsx(Icon, { name: "rename", size: 12 }), "Editing text \u00B7 Esc to finish"] })), !drag && !editing && (_jsxs("span", { ...tagProps(selectedRect, undefined, selectedRect.width * zoom < NARROW_BLOCK), children: [_jsx(BlockIcon, { name: runtime.blockIcon(selected.type), size: 12 }), blockName(selected, runtime.blockLabel(selected.type)), selected.bindings && Object.keys(selected.bindings).length > 0 && (_jsx("span", { className: "builder-editor__tag-bound", "data-tooltip": "Shows data from a document", children: _jsx(Icon, { name: "bind", size: 11 }) })), selected.hidden && _jsx(Icon, { name: "eyeOff", size: 12 })] }))] }), _jsx(ActionBar, { id: selected.id, label: runtime.blockLabel(selected.type), icon: runtime.blockIcon(selected.type), parentId: findLocation(layout, selected.id)?.parentId ?? null, rect: selectedRect, inside: !roomAbove(selectedRect), below: selectedRect.width * zoom < NARROW_BLOCK, hidden: Boolean(drag) || Boolean(smooth) || editing }), editing && editRect && inline?.kind === 'rich' && _jsx(InlineToolbar, { inline: inline, rect: editRect, zoom: zoom })] })), _jsx(RegionOverlay, { tagProps: tagProps, editedRect: inline?.region ? editedRect(runtime.iframeRef.current) : null, zoom: zoom }), _jsx(InsertHandle, {}), _jsx(ImageEditor, {}), _jsx(BlockContextMenu, {}), _jsx(Tooltips, {}), _jsx(PeerCursors, {}), indicator && (_jsx("div", { className: `builder-editor__drop builder-editor__drop--${indicator.kind}`, style: box(indicator.rect), children: dropParent && (_jsxs("span", { className: "builder-editor__drop-label", children: [_jsx(Icon, { name: "plus", size: 12 }), " Into ", runtime.blockLabel(dropParent.type)] })) })), _jsx(PeerSelections, {}), [...(live?.changes ?? [])].map(([id, change]) => {
133
+ }, children: _jsx("span", { className: "builder-editor__drop-label builder-dnd-gap__label", hidden: !smooth.into, "data-label": smooth.into ? `Into ${smooth.into}` : '', children: _jsx(Icon, { name: "plus", size: 12 }) }) }) })), hovered && hoverRect && (_jsx("div", { className: "builder-editor__hover", style: box(hoverRect), ...componentMark(hovered), children: _jsxs("span", { ...tagProps(hoverRect, 'hover'), children: [_jsx(BlockIcon, { name: runtime.blockIcon(hovered.type), size: 12 }), blockName(hovered, runtime.blockLabel(hovered.type))] }) })), sourceRect && _jsx("div", { className: "builder-editor__source", style: box(sourceRect) }), selected && selectedRect && (_jsxs(_Fragment, { children: [_jsxs("div", { hidden: Boolean(smooth), className: `builder-editor__selection${selected.hidden ? ' builder-editor__selection--hidden' : ''}${editing ? ' builder-editor__selection--editing' : ''}`, style: box(editing && editRect ? editRect : selectedRect), ...componentMark(selected), children: [editing && editRect && inline?.kind !== 'rich' && (_jsxs("span", { ...tagProps(editRect, 'editing'), children: [_jsx(Icon, { name: "rename", size: 12 }), "Editing text \u00B7 Esc to finish"] })), !drag && !editing && (_jsxs("span", { ...tagProps(selectedRect, undefined, selectedRect.width * zoom < NARROW_BLOCK), children: [_jsx(BlockIcon, { name: runtime.blockIcon(selected.type), size: 12 }), blockName(selected, runtime.blockLabel(selected.type)), selected.bindings && Object.keys(selected.bindings).length > 0 && (_jsx("span", { className: "builder-editor__tag-bound", "data-tooltip": "Shows data from a document", children: _jsx(Icon, { name: "bind", size: 11 }) })), selected.hidden && _jsx(Icon, { name: "eyeOff", size: 12 })] }))] }), _jsx(ActionBar, { id: selected.id, label: runtime.blockLabel(selected.type), icon: runtime.blockIcon(selected.type), parentId: findLocation(layout, selected.id)?.parentId ?? null, rect: selectedRect, inside: !roomAbove(selectedRect), below: selectedRect.width * zoom < NARROW_BLOCK, hidden: Boolean(drag) || Boolean(smooth) || editing, component: isComponent(selected) }), editing && editRect && inline?.kind === 'rich' && _jsx(InlineToolbar, { inline: inline, rect: editRect, zoom: zoom })] })), _jsx(RegionOverlay, { tagProps: tagProps, editedRect: inline?.region ? editedRect(runtime.iframeRef.current) : null, zoom: zoom }), _jsx(InsertHandle, {}), _jsx(ImageEditor, { barRight: barInside && selectedRect ? selectedRect.x + selectedRect.width : null, barTop: barInside && selectedRect ? selectedRect.y : null }), _jsx(BlockContextMenu, {}), _jsx(Tooltips, {}), _jsx(PeerCursors, {}), indicator && (_jsx("div", { className: `builder-editor__drop builder-editor__drop--${indicator.kind}`, style: box(indicator.rect), children: dropParent && (_jsxs("span", { className: "builder-editor__drop-label", children: [_jsx(Icon, { name: "plus", size: 12 }), " Into ", runtime.blockLabel(dropParent.type)] })) })), _jsx(PeerSelections, {}), [...(live?.changes ?? [])].map(([id, change]) => {
132
134
  const rect = rectOf(id);
133
135
  if (!rect)
134
136
  return null;
@@ -144,7 +146,7 @@ export function Overlay() {
144
146
  })] }));
145
147
  }
146
148
  /** The bar on the selected block: drag, select parent, and a menu with the other actions. */
147
- function ActionBar({ id, label, icon, parentId, rect, inside, below, hidden }) {
149
+ function ActionBar({ id, label, icon, parentId, rect, inside, below, hidden, component }) {
148
150
  const runtime = useRuntime();
149
151
  const data = { source: { kind: 'block', id }, label, icon };
150
152
  // Content mode moves no blocks by dragging and switches no section variants.
@@ -153,5 +155,5 @@ function ActionBar({ id, label, icon, parentId, rect, inside, below, hidden }) {
153
155
  const place = below ? 'below' : inside ? 'inside' : 'above';
154
156
  const visibility = hidden ? 'hidden' : undefined;
155
157
  const style = place === 'below' ? { left: rect.x, top: rect.y + rect.height, visibility } : { left: rect.x + rect.width, top: rect.y, visibility };
156
- return (_jsxs("div", { className: `builder-editor__actions builder-editor__actions--${place}`, style: style, children: [!contentMode && _jsx(SectionVariantSwitch, { id: id }), !contentMode && (_jsx("button", { ref: setNodeRef, type: "button", className: "builder-editor__action builder-editor__handle", "aria-label": "Drag to move", "data-tooltip": "Drag to move", ...listeners, ...attributes, children: _jsx(Icon, { name: "drag", size: 14 }) })), _jsx("button", { type: "button", className: "builder-editor__action", "aria-label": "Select the parent block", "data-tooltip": "Select parent", disabled: !parentId, onClick: () => parentId && runtime.store.select(parentId), children: _jsx(Icon, { name: "parent", size: 14 }) }), _jsx(MenuButton, { className: "builder-editor__action", triggerLabel: "More block actions", tooltip: "More actions", label: "Block actions", items: () => blockMenuEntries(runtime, id, 'canvas'), children: _jsx(Icon, { name: "more", size: 14 }) })] }));
158
+ return (_jsxs("div", { className: `builder-editor__actions builder-editor__actions--${place}`, style: style, "data-component": component ? '' : undefined, children: [!contentMode && _jsx(SectionVariantSwitch, { id: id }), !contentMode && (_jsx("button", { ref: setNodeRef, type: "button", className: "builder-editor__action builder-editor__handle", "aria-label": "Drag to move", "data-tooltip": "Drag to move", ...listeners, ...attributes, children: _jsx(Icon, { name: "drag", size: 14 }) })), _jsx("button", { type: "button", className: "builder-editor__action", "aria-label": "Select the parent block", "data-tooltip": "Select parent", disabled: !parentId, onClick: () => parentId && runtime.store.select(parentId), children: _jsx(Icon, { name: "parent", size: 14 }) }), _jsx(MenuButton, { className: "builder-editor__action", triggerLabel: "More block actions", tooltip: "More actions", label: "Block actions", items: () => blockMenuEntries(runtime, id, 'canvas'), children: _jsx(Icon, { name: "more", size: 14 }) })] }));
157
159
  }
@@ -1,4 +1,4 @@
1
- import type { Block, CanvasMeasurement, Layout, Position, SectionDefinition } from '../../core/types.js';
1
+ import type { Block, CanvasMeasurement, Layout, Position, SectionDefinition, SlotDefinition } from '../../core/types.js';
2
2
  import { type CopiedStyles } from './menu/styleClipboard.js';
3
3
  import type { Runtime } from './runtime.js';
4
4
  /**
@@ -21,7 +21,7 @@ export declare function withNewIds(block: Block): Block;
21
21
  */
22
22
  export declare function insertNewBlock(runtime: Runtime, type: string): boolean;
23
23
  /** Adds a new block of `type` at `to`, selects it and asks the inspector to focus its first field. */
24
- export declare function insertNewBlockAt(runtime: Runtime, type: string, to: Position): boolean;
24
+ export declare function insertNewBlockAt(runtime: Runtime, type: string, to: Position, template?: SlotDefinition['newBlock']): boolean;
25
25
  /**
26
26
  * `to` with its index clamped to the list as it is now (the page may have changed since the
27
27
  * position was picked). Null when the parent block is gone.
@@ -53,6 +53,11 @@ export declare function toggleHidden(runtime: Runtime, id: string): void;
53
53
  * bindings, hidden blocks). False for a Payload blocks field: its blocks hold their fields only.
54
54
  */
55
55
  export declare function storesBuilderData(runtime: Pick<Runtime, 'config'>): boolean;
56
+ /**
57
+ * True when blocks of `type` keep Tailwind classes here: always in the builder's JSON layout; in a
58
+ * Payload blocks field only when the block has a class key (a form field's `cssClass`).
59
+ */
60
+ export declare function storesClasses(runtime: Pick<Runtime, 'config'>, type: string): boolean;
56
61
  /** Gives a block its own name in the outline and the breadcrumbs. An empty name removes it. */
57
62
  export declare function renameBlock(runtime: Runtime, id: string, label: string): void;
58
63
  /** How many blocks are in the list `slot` of `parentId` (the page itself when `parentId` is null). */
@@ -3,7 +3,7 @@
3
3
  // shortcuts: insert, duplicate, remove, hide, move, copy and paste (blocks and styles).
4
4
  import { SECTION_REF_BLOCK, sectionDetachOps, sectionRefId } from '../../blocks/builtins/sectionRef.js';
5
5
  import { applyComponentValues, componentValuesOf } from '../../core/components.js';
6
- import { createId, findBlock, findLocation, getBlockDefinition, htmlIdsOf, slotAcceptsAt, slotNames, withoutTakenHtmlIds } from '../../core/index.js';
6
+ import { createId, duplicateOperation, findBlock, findLocation, getBlockDefinition, placementError, htmlIdsOf, slotAcceptsAt, slotNames, uniquePropValuesAt, withoutTakenHtmlIds, withUniqueProps, } from '../../core/index.js';
7
7
  import { normalizeClasses, parseStyles, setStylesOps, stylesText } from './menu/styleClipboard.js';
8
8
  import { countText } from './counts.js';
9
9
  /**
@@ -70,15 +70,32 @@ export function insertNewBlock(runtime, type) {
70
70
  return insertNewBlockAt(runtime, type, insertPosition(runtime, type));
71
71
  }
72
72
  /** Adds a new block of `type` at `to`, selects it and asks the inspector to focus its first field. */
73
- export function insertNewBlockAt(runtime, type, to) {
74
- const block = runtime.createBlock(type);
75
- if (!block)
73
+ export function insertNewBlockAt(runtime, type, to, template) {
74
+ const created = runtime.createBlock(type, to);
75
+ if (!created)
76
+ return false;
77
+ // A block with placement rules (a form field goes only inside a Form block) says why, in words.
78
+ const refused = placementError(runtime.config.blocks, runtime.store.getState().layout, to.parentId, to.slot ?? 'children', created);
79
+ if (refused) {
80
+ const needs = getBlockDefinition(runtime.config.blocks, type)?.ancestors;
81
+ const where = needs?.map((t) => runtime.blockLabel(t)).join(' or ');
82
+ runtime.warn(where ? `${refused}. Select a ${where} first, or drag it into one.` : refused);
76
83
  return false;
84
+ }
85
+ // A slot's `newBlock` (a carousel's "Slide"): its name, classes and props over the defaults.
86
+ const block = template
87
+ ? {
88
+ ...created,
89
+ ...(template.label ? { label: template.label } : {}),
90
+ ...(template.className ? { className: template.className } : {}),
91
+ ...(template.props ? { props: { ...created.props, ...template.props } } : {}),
92
+ }
93
+ : created;
77
94
  if (!runtime.store.apply({ type: 'insert', block, to }, { select: block.id, newContent: true }))
78
95
  return false;
79
96
  runtime.focusRequest.set(block.id);
80
97
  const parent = to.parentId ? findBlock(runtime.store.getState().layout, to.parentId) : null;
81
- const label = runtime.blockLabel(type);
98
+ const label = template?.label ?? runtime.blockLabel(type);
82
99
  runtime.notify(parent ? `Added ${label} in ${parent.label?.trim() || runtime.blockLabel(parent.type)}` : `Added ${label}`);
83
100
  return true;
84
101
  }
@@ -99,18 +116,23 @@ export function currentPosition(layout, to) {
99
116
  * out the HTML ids (`attrs.id`) the page already uses, so a paste or a second section stays valid.
100
117
  */
101
118
  export function insertBlocks(runtime, blocks, to) {
102
- const fresh = freshCopies(runtime, blocks);
119
+ const fresh = freshCopies(runtime, blocks, to.parentId);
103
120
  const first = fresh[0];
104
121
  if (!first)
105
122
  return false;
106
123
  const ops = fresh.map((block, i) => ({ type: 'insert', block, to: { ...to, index: to.index + i } }));
107
124
  return runtime.store.apply(ops, { select: first.id });
108
125
  }
109
- /** Copies with new ids, without the HTML ids the page already uses. */
110
- function freshCopies(runtime, blocks) {
111
- const taken = htmlIdsOf(runtime.store.getState().layout.blocks);
126
+ /**
127
+ * Copies with new ids, without the HTML ids the page already uses, and with free unique props in
128
+ * the scope of `parentId` (see `uniqueProps`: inside a form, its own fields).
129
+ */
130
+ function freshCopies(runtime, blocks, parentId) {
131
+ const { layout } = runtime.store.getState();
132
+ const taken = htmlIdsOf(layout.blocks);
133
+ const values = uniquePropValuesAt(layout, parentId, runtime.config.blocks);
112
134
  return blocks.map((block) => {
113
- const copy = withoutTakenHtmlIds(withNewIds(block), taken);
135
+ const copy = withUniqueProps(withoutTakenHtmlIds(withNewIds(block), taken), runtime.config.blocks, values);
114
136
  htmlIdsOf([copy], taken);
115
137
  return copy;
116
138
  });
@@ -144,7 +166,7 @@ export async function detachSection(runtime, id) {
144
166
  runtime.notify('This saved section cannot be loaded. It may be deleted.');
145
167
  return;
146
168
  }
147
- const copies = freshCopies(runtime, applyComponentValues(section.blocks, componentValuesOf(ref?.props), runtime.config.blocks));
169
+ const copies = freshCopies(runtime, applyComponentValues(section.blocks, componentValuesOf(ref?.props), runtime.config.blocks), findLocation(runtime.store.getState().layout, id)?.parentId ?? null);
148
170
  const ops = sectionDetachOps(runtime.store.getState().layout, id, copies);
149
171
  if (ops && runtime.store.apply(ops, { select: copies[0].id }))
150
172
  runtime.notify(`Detached "${section.label}": this page now has its own copy`);
@@ -152,8 +174,11 @@ export async function detachSection(runtime, id) {
152
174
  runtime.notify("The section's blocks cannot go here.");
153
175
  }
154
176
  export function duplicateBlock(runtime, id) {
177
+ // One insert of a ready copy (one undo step): its blocks get free values for their unique props
178
+ // (form field names) in its scope, also inside a Stack or Grid of form fields.
155
179
  const newId = createId();
156
- if (runtime.store.apply({ type: 'duplicate', id, newId }, { select: newId }))
180
+ const op = duplicateOperation(runtime.store.getState().layout, id, newId, runtime.config.blocks);
181
+ if (op && runtime.store.apply(op, { select: newId }))
157
182
  runtime.notify('Duplicated');
158
183
  }
159
184
  export function removeBlock(runtime, id) {
@@ -179,6 +204,13 @@ export function toggleHidden(runtime, id) {
179
204
  export function storesBuilderData(runtime) {
180
205
  return runtime.config.storage !== 'payload-blocks';
181
206
  }
207
+ /**
208
+ * True when blocks of `type` keep Tailwind classes here: always in the builder's JSON layout; in a
209
+ * Payload blocks field only when the block has a class key (a form field's `cssClass`).
210
+ */
211
+ export function storesClasses(runtime, type) {
212
+ return storesBuilderData(runtime) || Boolean(getBlockDefinition(runtime.config.blocks, type)?.payload?.classKeys?.className);
213
+ }
182
214
  /** Gives a block its own name in the outline and the breadcrumbs. An empty name removes it. */
183
215
  export function renameBlock(runtime, id, label) {
184
216
  const block = findBlock(runtime.store.getState().layout, id);
@@ -14,6 +14,7 @@ import { ConnectAgents, useCopy } from './ConnectAgents.js';
14
14
  import { failedAction, failureParts, humanizeTool, retriedCalls, transcript } from './history.js';
15
15
  import { Markdown } from './MarkdownView.js';
16
16
  import './assistant.scss';
17
+ import { FORM_SETTINGS_REGION } from '../../../forms/blocks.js';
17
18
  const PROVIDER_DOCS = 'https://github.com/jon8800/payload-canvas/blob/main/docs/ai/providers.md';
18
19
  /** Distance from the bottom (px) within which new content keeps the list scrolled to the end. */
19
20
  const STICK_DISTANCE = 48;
@@ -198,6 +199,13 @@ const BLOCK_SUGGESTIONS = {
198
199
  ],
199
200
  other: ['Make this stand out more', 'Add more space around this', 'Make this look good on mobile'],
200
201
  };
202
+ /** Suggestions in the form builder: the assistant edits the form's fields there. */
203
+ const FORM_SUGGESTIONS = [
204
+ 'Add a phone field after the email',
205
+ 'Make every field required except the message',
206
+ 'Ask for the budget only when the topic is a new website',
207
+ 'Put name and email side by side',
208
+ ];
201
209
  /** The empty chat: a short intro and suggestions that fit the page, the selection or the template. */
202
210
  function Welcome({ assistant, note }) {
203
211
  const runtime = useRuntime();
@@ -206,28 +214,32 @@ function Welcome({ assistant, note }) {
206
214
  const isEmptyPage = useEditor(runtime.store, (s) => s.layout.blocks.length === 0);
207
215
  const selectedType = useEditor(runtime.store, (s) => (s.selectedId ? (findBlock(s.layout, s.selectedId)?.type ?? null) : null));
208
216
  const kind = selectedType ? blockKind(selectedType, runtime.config.blocks) : null;
209
- const suggestions = kind
210
- ? BLOCK_SUGGESTIONS[kind]
211
- : template.isTemplate && template.target
212
- ? [
213
- `Bind the heading to the ${singular} title`,
214
- `Build a layout for a ${singular}`,
215
- 'Show the featured image at the top',
216
- 'Add a related items list at the end',
217
- ]
218
- : isEmptyPage
217
+ // The form builder: forms have a settings panel region.
218
+ const isForm = Boolean(runtime.regions?.region(FORM_SETTINGS_REGION)?.panel);
219
+ const suggestions = isForm
220
+ ? FORM_SUGGESTIONS
221
+ : kind
222
+ ? BLOCK_SUGGESTIONS[kind]
223
+ : template.isTemplate && template.target
219
224
  ? [
220
- 'Build a landing page for a design studio',
221
- 'Add a hero section',
222
- 'Add a pricing section with three plans',
223
- 'Add a FAQ section',
225
+ `Bind the heading to the ${singular} title`,
226
+ `Build a layout for a ${singular}`,
227
+ 'Show the featured image at the top',
228
+ 'Add a related items list at the end',
224
229
  ]
225
- : [
226
- 'Add a testimonials section',
227
- 'Add a call to action at the end',
228
- 'Tighten the spacing across the page',
229
- 'Make the page look good on mobile',
230
- ];
230
+ : isEmptyPage
231
+ ? [
232
+ 'Build a landing page for a design studio',
233
+ 'Add a hero section',
234
+ 'Add a pricing section with three plans',
235
+ 'Add a FAQ section',
236
+ ]
237
+ : [
238
+ 'Add a testimonials section',
239
+ 'Add a call to action at the end',
240
+ 'Tighten the spacing across the page',
241
+ 'Make the page look good on mobile',
242
+ ];
231
243
  return (_jsxs("div", { className: "builder-assistant__welcome", children: [note && _jsx("p", { className: "builder-assistant__info", children: note }), _jsx(EmptyMark, {}), _jsx("p", { className: "builder-assistant__empty-title", children: selectedType ? `What should change in this ${runtime.blockLabel(selectedType).toLowerCase()}?` : 'What should we build?' }), _jsxs("p", { className: "builder-editor__hint", children: ["The assistant edits this ", template.isTemplate ? 'template' : 'page', " on the canvas as you watch. One Ctrl+Z undoes a whole reply."] }), _jsx("div", { className: "builder-assistant__suggestions", children: suggestions.map((text) => (_jsx("button", { type: "button", className: "builder-assistant__suggestion", onClick: () => void assistant.send(text), children: text }, text))) })] }));
232
244
  }
233
245
  /** What the assistant will target: the selected block, the template sample, or the whole page. */
@@ -21,6 +21,13 @@ export type CommentsController = {
21
21
  open: ValueStore<string | null>;
22
22
  /** Comment mode on or off (no argument: the other one). Off closes the composer and the thread. */
23
23
  toggle(on?: boolean): void;
24
+ /**
25
+ * Comment mode with the thread open, and the filter set so the panel lists it. Returns the
26
+ * thread's block, or null when the thread is not in the list (or is a reply).
27
+ */
28
+ focus(threadId: string): {
29
+ blockId: string | null;
30
+ } | null;
24
31
  load(): Promise<void>;
25
32
  handleEvent(event: LiveCommentsEvent): void;
26
33
  /** Places a new pin (comment mode). */