payload-canvas 0.3.0-next.1 → 0.4.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 (236) hide show
  1. package/README.md +522 -39
  2. package/dist/admin/BuilderTab.js +1 -1
  3. package/dist/admin/diff/LayoutDiff.js +3 -3
  4. package/dist/admin/diff/changes.js +8 -0
  5. package/dist/admin/diff/layoutDiff.scss +48 -48
  6. package/dist/admin/editor/DragLayer.js +1 -1
  7. package/dist/admin/editor/InlineToolbar.js +1 -1
  8. package/dist/admin/editor/Inspector.js +50 -5
  9. package/dist/admin/editor/Outline.js +13 -11
  10. package/dist/admin/editor/Overlay.js +1 -1
  11. package/dist/admin/editor/actions.d.ts +9 -1
  12. package/dist/admin/editor/actions.js +38 -3
  13. package/dist/admin/editor/assistant/AssistantPanel.js +1 -1
  14. package/dist/admin/editor/assistant/ConnectAgents.js +1 -1
  15. package/dist/admin/editor/assistant/assistant.scss +65 -65
  16. package/dist/admin/editor/dnd/dnd.scss +2 -2
  17. package/dist/admin/editor/editor.scss +134 -134
  18. package/dist/admin/editor/empty/EmptyStart.js +32 -6
  19. package/dist/admin/editor/empty/empty.scss +3 -3
  20. package/dist/admin/editor/fields/ArrayField.js +2 -2
  21. package/dist/admin/editor/fields/GroupField.d.ts +5 -2
  22. package/dist/admin/editor/fields/GroupField.js +6 -2
  23. package/dist/admin/editor/fields/WhereField.d.ts +17 -0
  24. package/dist/admin/editor/fields/WhereField.js +67 -0
  25. package/dist/admin/editor/fields/access.d.ts +1 -1
  26. package/dist/admin/editor/fields/fields.scss +122 -33
  27. package/dist/admin/editor/fields/whereRows.d.ts +28 -0
  28. package/dist/admin/editor/fields/whereRows.js +118 -0
  29. package/dist/admin/editor/generate/GenerateImage.js +1 -1
  30. package/dist/admin/editor/generate/generate.scss +48 -48
  31. package/dist/admin/editor/icons.d.ts +1 -0
  32. package/dist/admin/editor/icons.js +3 -1
  33. package/dist/admin/editor/insert/InsertHandle.js +1 -1
  34. package/dist/admin/editor/layout/FrameResize.js +1 -1
  35. package/dist/admin/editor/layout/LeftPanel.js +1 -1
  36. package/dist/admin/editor/layout/layout.scss +4 -4
  37. package/dist/admin/editor/live/PresenceUI.js +1 -1
  38. package/dist/admin/editor/live/presence.scss +1 -1
  39. package/dist/admin/editor/locale/LocaleField.d.ts +2 -2
  40. package/dist/admin/editor/locale/LocaleField.js +4 -2
  41. package/dist/admin/editor/locale/locale.scss +12 -12
  42. package/dist/admin/editor/media/ImageEditor.js +1 -1
  43. package/dist/admin/editor/media/media.scss +23 -23
  44. package/dist/admin/editor/menu/Menu.js +1 -1
  45. package/dist/admin/editor/menu/blockMenu.js +5 -1
  46. package/dist/admin/editor/menu/menu.scss +16 -16
  47. package/dist/admin/editor/motion/MotionPanel.js +2 -2
  48. package/dist/admin/editor/motion/model.d.ts +2 -2
  49. package/dist/admin/editor/motion/model.js +2 -2
  50. package/dist/admin/editor/motion/motion.scss +2 -2
  51. package/dist/admin/editor/regions/RegionOverlay.js +1 -1
  52. package/dist/admin/editor/regions/RegionPane.js +1 -1
  53. package/dist/admin/editor/renderField.d.ts +3 -1
  54. package/dist/admin/editor/renderField.js +14 -5
  55. package/dist/admin/editor/runtime.js +1 -0
  56. package/dist/admin/editor/styles/ColorPicker.js +1 -1
  57. package/dist/admin/editor/styles/SiteClasses.d.ts +9 -0
  58. package/dist/admin/editor/styles/SiteClasses.js +31 -0
  59. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
  60. package/dist/admin/editor/styles/StylesPanel.js +9 -6
  61. package/dist/admin/editor/styles/VariantBar.js +1 -1
  62. package/dist/admin/editor/styles/context.d.ts +9 -2
  63. package/dist/admin/editor/styles/context.js +14 -9
  64. package/dist/admin/editor/styles/controls.js +3 -3
  65. package/dist/admin/editor/styles/sections.js +2 -2
  66. package/dist/admin/editor/styles/styles.scss +147 -93
  67. package/dist/admin/editor/templates/Bindable.d.ts +14 -6
  68. package/dist/admin/editor/templates/Bindable.js +74 -18
  69. package/dist/admin/editor/templates/SamplePicker.js +1 -1
  70. package/dist/admin/editor/templates/binding.d.ts +11 -4
  71. package/dist/admin/editor/templates/binding.js +23 -3
  72. package/dist/admin/editor/templates/templates.scss +90 -90
  73. package/dist/admin/editor/tooltip/tooltip.scss +4 -4
  74. package/dist/admin/editor/topbar/DocumentActions.js +1 -1
  75. package/dist/admin/editor/topbar/DocumentTitle.js +1 -1
  76. package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
  77. package/dist/admin/editor/topbar/screens/ScreenDrawer.js +1 -1
  78. package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +1 -1
  79. package/dist/admin/editor/topbar/screens/screens.scss +20 -20
  80. package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
  81. package/dist/admin/editor/topbar/settingsDrawer.scss +7 -7
  82. package/dist/admin/editor/topbar/topbar.scss +47 -47
  83. package/dist/admin/editor/ui/Select.js +1 -1
  84. package/dist/admin/editor/ui/controls.scss +26 -26
  85. package/dist/admin/screen/BuilderScreen.js +1 -1
  86. package/dist/ai/adapters/anthropic.d.ts +2 -2
  87. package/dist/ai/images/service.js +1 -1
  88. package/dist/ai/loop.d.ts +5 -5
  89. package/dist/ai/prompt.js +8 -2
  90. package/dist/ai/tools.js +11 -2
  91. package/dist/blocks/builtins/carousel.d.ts +32 -0
  92. package/dist/blocks/builtins/carousel.js +122 -0
  93. package/dist/blocks/builtins/disclosure.d.ts +13 -0
  94. package/dist/blocks/builtins/disclosure.js +107 -0
  95. package/dist/blocks/builtins/faq.d.ts +17 -0
  96. package/dist/blocks/builtins/faq.js +88 -0
  97. package/dist/blocks/builtins/filterLink.d.ts +22 -0
  98. package/dist/blocks/builtins/filterLink.js +76 -0
  99. package/dist/blocks/builtins/headingId.d.ts +15 -0
  100. package/dist/blocks/builtins/headingId.js +36 -0
  101. package/dist/blocks/builtins/icon.d.ts +8 -0
  102. package/dist/blocks/builtins/icon.js +45 -0
  103. package/dist/blocks/builtins/index.d.ts +35 -0
  104. package/dist/blocks/builtins/index.js +50 -0
  105. package/dist/blocks/builtins/lightbox.d.ts +43 -0
  106. package/dist/blocks/builtins/lightbox.js +93 -0
  107. package/dist/blocks/builtins/mediaBackdrop.d.ts +11 -0
  108. package/dist/blocks/builtins/mediaBackdrop.js +79 -0
  109. package/dist/blocks/builtins/sectionRef.d.ts +26 -0
  110. package/dist/blocks/builtins/sectionRef.js +78 -0
  111. package/dist/blocks/builtins/shared.d.ts +33 -0
  112. package/dist/blocks/builtins/shared.js +70 -0
  113. package/dist/blocks/builtins/tableOfContents.d.ts +3 -0
  114. package/dist/blocks/builtins/tableOfContents.js +44 -0
  115. package/dist/blocks/defaults.d.ts +28 -10
  116. package/dist/blocks/defaults.js +413 -20
  117. package/dist/blocks/index.d.ts +4 -2
  118. package/dist/blocks/index.js +3 -1
  119. package/dist/core/attrs.d.ts +27 -0
  120. package/dist/core/attrs.js +132 -0
  121. package/dist/core/bindings.d.ts +123 -12
  122. package/dist/core/bindings.js +504 -19
  123. package/dist/core/blocks.d.ts +46 -1
  124. package/dist/core/blocks.js +136 -0
  125. package/dist/core/classes.d.ts +10 -2
  126. package/dist/core/classes.js +34 -5
  127. package/dist/core/fieldAccess.js +1 -1
  128. package/dist/core/fieldHooks.d.ts +1 -1
  129. package/dist/core/headings.d.ts +21 -0
  130. package/dist/core/headings.js +47 -0
  131. package/dist/core/index.d.ts +4 -2
  132. package/dist/core/index.js +4 -2
  133. package/dist/core/motion.d.ts +24 -15
  134. package/dist/core/motion.js +20 -12
  135. package/dist/core/operations.js +59 -2
  136. package/dist/core/payloadBlocks.js +3 -1
  137. package/dist/core/schema.js +20 -0
  138. package/dist/core/tree.js +24 -1
  139. package/dist/core/types.d.ts +87 -0
  140. package/dist/core/validate.js +29 -4
  141. package/dist/css/tokens.d.ts +6 -3
  142. package/dist/css/tokens.js +48 -2
  143. package/dist/index.d.ts +3 -3
  144. package/dist/index.js +2 -2
  145. package/dist/live/draftAccess.js +1 -1
  146. package/dist/live/session.d.ts +1 -1
  147. package/dist/live/storage.js +4 -2
  148. package/dist/mcp/index.d.ts +2 -0
  149. package/dist/mcp/index.js +50 -13
  150. package/dist/mcp/shared.d.ts +34 -31
  151. package/dist/mcp/shared.js +23 -8
  152. package/dist/plugin/index.d.ts +8 -0
  153. package/dist/plugin/index.js +30 -12
  154. package/dist/plugin/listCollections.d.ts +17 -2
  155. package/dist/plugin/listCollections.js +44 -7
  156. package/dist/plugin/references.d.ts +5 -0
  157. package/dist/plugin/references.js +1 -1
  158. package/dist/plugin/templates.d.ts +4 -0
  159. package/dist/plugin/templates.js +24 -9
  160. package/dist/protocol/index.d.ts +3 -1
  161. package/dist/react/canvas/BuilderCanvas.js +6 -4
  162. package/dist/react/canvas/fetchDocs.d.ts +16 -2
  163. package/dist/react/canvas/fetchDocs.js +42 -9
  164. package/dist/react/canvas/inline/rich/editor.js +1 -6
  165. package/dist/react/canvas/measure.d.ts +3 -1
  166. package/dist/react/canvas/measure.js +26 -2
  167. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  168. package/dist/react/canvas/resolveLayout.js +17 -6
  169. package/dist/react/canvas/serverBlocks.d.ts +11 -0
  170. package/dist/react/canvas/serverBlocks.js +28 -1
  171. package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +1 -1
  172. package/dist/react/components/Button.d.ts +11 -2
  173. package/dist/react/components/Button.js +43 -6
  174. package/dist/react/components/CollectionList.d.ts +6 -3
  175. package/dist/react/components/CollectionList.js +21 -7
  176. package/dist/react/components/Container.js +4 -1
  177. package/dist/react/components/Field.js +13 -2
  178. package/dist/react/components/Heading.js +9 -2
  179. package/dist/react/components/Image.d.ts +9 -0
  180. package/dist/react/components/Image.js +16 -1
  181. package/dist/react/components/List.d.ts +1 -0
  182. package/dist/react/components/List.js +6 -0
  183. package/dist/react/components/Menu.d.ts +16 -0
  184. package/dist/react/components/Menu.js +83 -19
  185. package/dist/react/components/RichText.d.ts +8 -3
  186. package/dist/react/components/RichText.js +25 -4
  187. package/dist/react/components/builtins/Accordion.d.ts +9 -0
  188. package/dist/react/components/builtins/Accordion.js +37 -0
  189. package/dist/react/components/builtins/BackdropVideo.d.ts +13 -0
  190. package/dist/react/components/builtins/BackdropVideo.js +16 -0
  191. package/dist/react/components/builtins/Carousel.d.ts +13 -0
  192. package/dist/react/components/builtins/Carousel.js +134 -0
  193. package/dist/react/components/builtins/Disclosure.d.ts +7 -0
  194. package/dist/react/components/builtins/Disclosure.js +13 -0
  195. package/dist/react/components/builtins/FilterLink.d.ts +8 -0
  196. package/dist/react/components/builtins/FilterLink.js +30 -0
  197. package/dist/react/components/builtins/Icon.d.ts +14 -0
  198. package/dist/react/components/builtins/Icon.js +28 -0
  199. package/dist/react/components/builtins/Lightbox.d.ts +45 -0
  200. package/dist/react/components/builtins/Lightbox.js +252 -0
  201. package/dist/react/components/builtins/MediaBackdrop.d.ts +14 -0
  202. package/dist/react/components/builtins/MediaBackdrop.js +61 -0
  203. package/dist/react/components/builtins/SectionRef.d.ts +7 -0
  204. package/dist/react/components/builtins/SectionRef.js +17 -0
  205. package/dist/react/components/builtins/TableOfContents.d.ts +7 -0
  206. package/dist/react/components/builtins/TableOfContents.js +21 -0
  207. package/dist/react/components/builtins/glyphs.d.ts +8 -0
  208. package/dist/react/components/builtins/glyphs.js +7 -0
  209. package/dist/react/components/builtins/index.d.ts +32 -0
  210. package/dist/react/components/builtins/index.js +36 -0
  211. package/dist/react/components/index.js +2 -0
  212. package/dist/react/index.d.ts +3 -1
  213. package/dist/react/index.js +3 -1
  214. package/dist/react/motion/runtime.js +10 -6
  215. package/dist/react/motion/style.js +1 -1
  216. package/dist/react/render/PayloadRoot.js +1 -1
  217. package/dist/react/render/RenderLayout.d.ts +1 -1
  218. package/dist/react/render/RenderLayout.js +77 -24
  219. package/dist/react/render/lists.d.ts +107 -5
  220. package/dist/react/render/lists.js +284 -9
  221. package/dist/react/render/resolve.d.ts +22 -2
  222. package/dist/react/render/resolve.js +45 -24
  223. package/dist/react/render/sections.d.ts +9 -0
  224. package/dist/react/render/sections.js +51 -0
  225. package/dist/react/render/types.d.ts +6 -1
  226. package/dist/react/server.d.ts +4 -4
  227. package/dist/react/server.js +55 -7
  228. package/dist/react/theme/ThemeStyle.d.ts +13 -2
  229. package/dist/react/theme/ThemeStyle.js +13 -3
  230. package/dist/theme/admin/ColorField.d.ts +2 -2
  231. package/dist/theme/admin/ColorField.js +2 -2
  232. package/dist/theme/admin/FontField.d.ts +2 -2
  233. package/dist/theme/admin/FontField.js +2 -2
  234. package/dist/theme/admin/SaveSignal.js +2 -2
  235. package/dist/theme/admin/fields.scss +48 -48
  236. package/package.json +23 -28
@@ -1,17 +1,17 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // Data binding in the block inspector: the "bind" button next to bindable props, the bound chip
4
4
  // with a live sample value, the Field block's field picker and the collection list's inputs.
5
5
  import { FieldLabel, SelectInput, TextInput, useConfig } from '@payloadcms/ui';
6
6
  import { createContext, use, useCallback, useState } from 'react';
7
7
  import { isLinkField } from '../../../blocks/link.js';
8
- import { getBlockDefinition, propField } from '../../../core/index.js';
8
+ import { bindingValue, COLLECTION_LIST_BLOCK, getBlockDefinition, isBindingExpression, itemSources, listItemContext, propField, repeatAncestors, repeatRowContext, repeatRows, } from '../../../core/index.js';
9
9
  import { Icon } from '../icons.js';
10
10
  import { useRuntime } from '../runtime.js';
11
11
  import { useEditor } from '../store.js';
12
12
  import { usePopover } from '../styles/popover.js';
13
13
  import { useValue } from '../valueStore.js';
14
- import { bindingTrail, docTitle, FIELD_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isObviousPath, LIST_BLOCK, listAncestor, previewValue, propKind, propPathOf, URL_PATH, urlField, valueAt, } from './binding.js';
14
+ import { bindingTrail, docTitle, FIELD_BLOCK, REPEAT_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isFieldListSource, isObviousPath, LIST_BLOCK, previewDoc, previewValue, propKind, propPathOf, URL_PATH, urlField, valueAt, } from './binding.js';
15
15
  import { FieldPicker, fieldIcon } from './FieldPicker.js';
16
16
  import { useCollectionLabel, useListSample, useTitleField } from './useTemplate.js';
17
17
  import './templates.scss';
@@ -20,10 +20,44 @@ const BindingScopeContext = createContext(null);
20
20
  function withUrl(kind, fields) {
21
21
  return fields.some((f) => f.path === URL_PATH) ? fields : [urlField(kind), ...fields];
22
22
  }
23
- /** The binding scope of a block, or null when nothing can be bound (a normal page, outside lists). */
23
+ const sameBlocks = (a, b) => a.length === b.length && a.every((block, i) => block === b[i]);
24
+ /**
25
+ * The binding scope of a block, or null when nothing can be bound (a normal page, outside lists).
26
+ * Inside repeats the scope narrows to the row: the row's fields, `$item`, `$index`, `$parent` and
27
+ * `$page`, and the first row of the sample.
28
+ */
24
29
  export function useBindingScope(block) {
25
30
  const runtime = useRuntime();
26
- const list = useEditor(runtime.store, (s) => listAncestor(s.layout, block.id));
31
+ const template = useValue(runtime.template);
32
+ const repeats = useEditor(runtime.store, (s) => repeatAncestors(s.layout, block.id), sameBlocks);
33
+ const nearest = repeats.findLastIndex((b) => b.type === COLLECTION_LIST_BLOCK);
34
+ const scope = useOuterScope(block, nearest >= 0 ? repeats[nearest] : null);
35
+ const rows = repeats.slice(nearest + 1);
36
+ if (!scope || rows.length === 0)
37
+ return scope;
38
+ const sources = runtime.config.templates?.sources ?? {};
39
+ const page = template.isTemplate && template.target ? sources[template.target] : undefined;
40
+ let fields = scope.fields;
41
+ let context = scope.context;
42
+ for (const row of rows) {
43
+ fields = itemSources(row, fields, sources, page);
44
+ const first = context ? repeatRows(context, row.props)[0] : undefined;
45
+ const collection = typeof row.props?.collection === 'string' ? row.props.collection : '';
46
+ context = first === undefined || !context ? null : repeatRowContext(first, 0, context, collection);
47
+ }
48
+ return {
49
+ ...scope,
50
+ kind: 'row',
51
+ fields: fields ?? [],
52
+ sample: context ? previewDoc(context) : null,
53
+ context,
54
+ sampleTitle: context ? docTitle(context.item) : '',
55
+ rowPath: typeof rows.at(-1)?.props?.path === 'string' ? rows.at(-1).props.path : '',
56
+ };
57
+ }
58
+ /** The scope of the template or of the nearest collection list around the block. */
59
+ function useOuterScope(block, list) {
60
+ const runtime = useRuntime();
27
61
  const template = useValue(runtime.template);
28
62
  const sources = runtime.config.templates?.sources ?? {};
29
63
  const listCollection = typeof list?.props?.collection === 'string' && list.props.collection ? list.props.collection : null;
@@ -33,12 +67,16 @@ export function useBindingScope(block) {
33
67
  const exclude = list?.props?.excludeCurrent !== false && template.isTemplate && template.target === listCollection ? template.sample?.id : undefined;
34
68
  const locale = useEditor(runtime.store, (s) => s.locale);
35
69
  const listSample = useListSample(runtime.api, list ? listCollection : null, listSort, exclude, locale);
70
+ const page = template.isTemplate && template.target ? sources[template.target] : undefined;
71
+ const pageContext = template.isTemplate && template.sample?.doc ? { collection: template.target ?? '', doc: template.sample.doc } : null;
36
72
  if (list) {
73
+ const context = listSample.doc ? listItemContext(listSample.doc, 0, pageContext, listCollection ?? '') : null;
37
74
  return {
38
75
  kind: 'list',
39
76
  collection: listCollection,
40
- fields: listCollection ? withUrl('list', sources[listCollection] ?? []) : [],
41
- sample: listSample.doc,
77
+ fields: listCollection ? withUrl('list', itemSources(list, undefined, sources, page) ?? []) : [],
78
+ sample: context ? previewDoc(context) : null,
79
+ context,
42
80
  sampleTitle: listSample.doc ? docTitle(listSample.doc, listTitle) : '',
43
81
  loading: listSample.loading,
44
82
  };
@@ -50,6 +88,7 @@ export function useBindingScope(block) {
50
88
  collection: template.target,
51
89
  fields: template.target ? withUrl('template', sources[template.target] ?? []) : [],
52
90
  sample: template.sample?.doc ?? null,
91
+ context: pageContext,
53
92
  sampleTitle: template.sample?.title ?? '',
54
93
  loading: template.status === 'loading',
55
94
  };
@@ -75,11 +114,13 @@ export function FieldSlot(props) {
75
114
  const { block, def, scope } = ctx;
76
115
  if (block.type === FIELD_BLOCK && propPath === 'path')
77
116
  return _jsx(FieldPathInput, { ...props, scope: scope });
117
+ if (block.type === REPEAT_BLOCK && propPath === 'path')
118
+ return _jsx(FieldPathInput, { ...props, scope: scope, rows: true });
78
119
  if (block.type === LIST_BLOCK && propPath === 'collection')
79
120
  return _jsx(ListCollectionInput, { ...props });
80
121
  if (block.type === LIST_BLOCK && propPath === 'sort')
81
122
  return _jsx(ListSortInput, { ...props, block: block });
82
- if (block.type === FIELD_BLOCK || block.type === LIST_BLOCK)
123
+ if (block.type === FIELD_BLOCK || block.type === LIST_BLOCK || block.type === REPEAT_BLOCK)
83
124
  return props.children;
84
125
  const kind = propKind(props.field);
85
126
  if (!kind)
@@ -96,6 +137,8 @@ export function FieldSlot(props) {
96
137
  return (_jsxs("div", { className: "builder-bind", children: [props.children, _jsx(BindButton, { block: block, propPath: propPath, kind: kind, scope: scope, field: props.field, label: props.label })] }));
97
138
  }
98
139
  function scopeTitle(scope, collectionLabel) {
140
+ if (scope.kind === 'row')
141
+ return `Fields of each row · ${scope.rowPath ?? ''}`;
99
142
  return scope.kind === 'list' ? `Fields of each item · ${collectionLabel}` : `Fields of ${collectionLabel}`;
100
143
  }
101
144
  const KIND_NAMES = {
@@ -135,13 +178,21 @@ function BoundField({ field, label, children, block, propPath, bound, kind, scop
135
178
  const collectionLabel = useCollectionLabel(scope?.collection ?? null);
136
179
  const [showFallback, setShowFallback] = useState(false);
137
180
  const fields = scope?.collection ? scope.fields : [urlField(scope?.kind ?? 'list')];
138
- const source = findBindingField(fields, bound);
139
- const trail = source ? bindingTrail(fields, bound) : bound.split('.');
181
+ const expression = isBindingExpression(bound);
182
+ const source = expression ? { path: bound, label: bound, type: 'text' } : findBindingField(fields, bound);
183
+ const trail = source && !expression ? bindingTrail(fields, bound) : [bound];
140
184
  const required = 'required' in field ? Boolean(field.required) : false;
141
- return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', bound) && _jsx("code", { className: "builder-bind__chip-path", children: bound })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), source ? (_jsx(SamplePreview, { scope: scope, source: source })) : (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
185
+ return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', bound) && _jsx("code", { className: "builder-bind__chip-path", children: bound })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), expression ? (_jsx(ExpressionPreview, { scope: scope, binding: bound })) : source ? (_jsx(SamplePreview, { scope: scope, source: source })) : (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
142
186
  ? `${collectionLabel} has no field “${bound}”. The fallback shows instead.`
143
187
  : 'This block is not inside a template or a collection list, so the binding has no data. Unbind it or move the block.' })), _jsxs("button", { type: "button", className: "builder-bind__fallback-toggle", "aria-expanded": showFallback, onClick: () => setShowFallback(!showFallback), children: [_jsx(Icon, { name: showFallback ? 'chevronDown' : 'chevronRight', size: 12 }), "Fallback when the field is empty"] }), showFallback && _jsx("div", { className: "builder-bind__fallback", children: children }), scope?.collection && (_jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: bound, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: bind }))] }));
144
188
  }
189
+ /** The sample's value for a binding expression (a template string, a fallback chain, formatters). */
190
+ function ExpressionPreview({ scope, binding }) {
191
+ if (!scope?.context)
192
+ return _jsx("p", { className: "builder-bind__note", children: "A binding expression. No sample to preview." });
193
+ const text = previewValue(bindingValue(scope.context, binding), 'text');
194
+ return (_jsxs("div", { className: "builder-bind__preview", children: [_jsx("span", { className: "builder-bind__preview-from", children: "Expression" }), text.kind === 'text' ? _jsx("span", { className: "builder-bind__preview-text", children: text.text }) : _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
195
+ }
145
196
  /** The sample document's value for a bound field: text, an image, or a note when it is empty. */
146
197
  export function SamplePreview({ scope, source }) {
147
198
  if (source.path === URL_PATH) {
@@ -150,16 +201,16 @@ export function SamplePreview({ scope, source }) {
150
201
  if (!scope || scope.loading)
151
202
  return _jsx("p", { className: "builder-bind__note", children: "Loading the sample\u2026" });
152
203
  if (!scope.sample) {
153
- return (_jsx("p", { className: "builder-bind__note", children: scope.kind === 'list' ? 'The list has no items yet.' : 'No sample document to preview.' }));
204
+ return (_jsx("p", { className: "builder-bind__note", children: scope.kind === 'list' ? 'The list has no items yet.' : scope.kind === 'row' ? 'The field has no rows in the sample.' : 'No sample document to preview.' }));
154
205
  }
155
206
  const preview = previewValue(valueAt(scope.sample, source.path), source.type);
156
- const from = scope.kind === 'list' ? 'First item' : 'Sample';
207
+ const from = scope.kind === 'list' ? 'First item' : scope.kind === 'row' ? 'First row' : 'Sample';
157
208
  return (_jsxs("div", { className: "builder-bind__preview", children: [_jsxs("span", { className: "builder-bind__preview-from", title: scope.sampleTitle, children: [from, ": ", scope.sampleTitle || 'untitled'] }), preview.kind === 'text' && _jsx("span", { className: "builder-bind__preview-text", children: preview.text }), preview.kind === 'image' && (_jsx("img", { className: "builder-bind__preview-image", src: preview.url, alt: preview.alt })), preview.kind === 'empty' && _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
158
209
  }
159
- /** The Field block's `path`: picks any field of the scope's document. */
160
- function FieldPathInput({ value, onChange, label, children, scope }) {
210
+ /** The Field block's `path`: picks any field of the scope's document. `rows`: a field list's path (fields with rows). */
211
+ function FieldPathInput({ value, onChange, label, children, scope, rows = false }) {
161
212
  const popover = usePopover('auto');
162
- const accept = isFieldBlockSource;
213
+ const accept = rows ? isFieldListSource : isFieldBlockSource;
163
214
  const collectionLabel = useCollectionLabel(scope?.collection ?? null);
164
215
  const path = typeof value === 'string' && value ? value : null;
165
216
  if (!scope?.collection) {
@@ -167,7 +218,9 @@ function FieldPathInput({ value, onChange, label, children, scope }) {
167
218
  ? 'Choose the list’s collection first. Then pick the field each item shows.'
168
219
  : scope?.kind === 'template'
169
220
  ? 'Choose which collection this template is for. Then pick a field here.'
170
- : 'A Field block shows a field of the template’s document or of each list item. Use it in a template or inside a collection list.' }), children] }));
221
+ : rows
222
+ ? 'A Field list repeats the rows of a field of the template’s document or of each list item. Use it in a template or inside a collection list.'
223
+ : 'A Field block shows a field of the template’s document or of each list item. Use it in a template or inside a collection list.' }), children] }));
171
224
  }
172
225
  const source = path ? findBindingField(scope.fields, path) : null;
173
226
  const trail = path ? bindingTrail(scope.fields, path) : [];
@@ -219,7 +272,7 @@ function ScopeBanner({ block, scope }) {
219
272
  const runtime = useRuntime();
220
273
  const collectionLabel = useCollectionLabel(scope?.collection ?? null);
221
274
  const singular = useCollectionLabel(scope?.collection ?? null, 'singular');
222
- if (!scope || block.type === FIELD_BLOCK || block.type === LIST_BLOCK)
275
+ if (!scope || block.type === FIELD_BLOCK || block.type === LIST_BLOCK || block.type === REPEAT_BLOCK)
223
276
  return null;
224
277
  const def = getBlockDefinition(runtime.config.blocks, block.type);
225
278
  if (!def || !hasBindableField(def.fields))
@@ -230,5 +283,8 @@ function ScopeBanner({ block, scope }) {
230
283
  if (scope.kind === 'list' && !scope.collection) {
231
284
  return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsx("p", { children: "This block is inside a collection list. Choose the list\u2019s collection to bind fields of each item." })] }));
232
285
  }
286
+ if (scope.kind === 'row') {
287
+ return (_jsxs("div", { className: "builder-bind__banner", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsxs("p", { children: ["Repeats for each row of \u201C", scope.rowPath, "\u201D. Use ", _jsx(Icon, { name: "bind", size: 12, className: "builder-bind__inline-icon" }), " next to a field to show the row\u2019s data."] })] }));
288
+ }
233
289
  return (_jsxs("div", { className: "builder-bind__banner", children: [_jsx(Icon, { name: scope.kind === 'list' ? 'collectionList' : 'template', size: 14 }), _jsxs("p", { children: [scope.kind === 'list' ? `Repeats for each ${singular.toLowerCase() || 'item'} in the list. ` : `Template for ${collectionLabel}. `, "Use ", _jsx(Icon, { name: "bind", size: 12, className: "builder-bind__inline-icon" }), " next to a field to show", ' ', scope.kind === 'list' ? 'the item’s' : 'the document’s', " data."] })] }));
234
290
  }
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /* oxlint-disable jsx-a11y/prefer-tag-over-role, jsx-a11y/no-noninteractive-element-to-interactive-role -- the document list is a listbox with option rows */
4
4
  import { useEffect, useId, useRef, useState } from 'react';
5
5
  import { Icon } from '../icons.js';
@@ -1,11 +1,11 @@
1
- import { FIELD_BLOCK, URL_PATH } from '../../../core/bindings.js';
2
- import type { BindingField, Block, Layout } from '../../../core/types.js';
3
- export { FIELD_BLOCK, URL_PATH };
1
+ import { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH } from '../../../core/bindings.js';
2
+ import type { BindingField, Block, Layout, TemplateContext } from '../../../core/types.js';
3
+ export { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH };
4
4
  /** Block type of the collection list block. Blocks in its `item` slot bind to each item. */
5
5
  export declare const LIST_BLOCK = "collectionList";
6
6
  export declare const LIST_SLOT = "item";
7
7
  /** The `$url` virtual field: the frontend URL of the document (each item's, inside a list). */
8
- export declare function urlField(scope: 'template' | 'list'): BindingField;
8
+ export declare function urlField(scope: 'template' | 'list' | 'row'): BindingField;
9
9
  export declare const URL_FIELD: BindingField;
10
10
  /**
11
11
  * What a block prop can show, by its Payload field type. `link` is a whole link group (bound to a
@@ -22,6 +22,8 @@ type PropField = {
22
22
  export declare function propKind(field: PropField): PropKind | null;
23
23
  /** Field block: any field with a single value. Containers are offered as their leaf fields. */
24
24
  export declare function isFieldBlockSource(source: BindingField): boolean;
25
+ /** Field list block: a field with rows, an array or any hasMany field. */
26
+ export declare function isFieldListSource(source: BindingField): boolean;
25
27
  /** True when a prop of `kind` can bind to `source`. Containers (group, array) never bind themselves, except for `any`. */
26
28
  export declare function isCompatible(kind: PropKind, source: BindingField, prop?: PropField): boolean;
27
29
  /** True when the path says nothing the label does not ("Featured image" and `featuredImage`). Then the path is not shown. */
@@ -43,6 +45,11 @@ export declare function pickerRows(fields: BindingField[], accept: (field: Bindi
43
45
  export declare function findBindingField(fields: BindingField[], path: string): BindingField | null;
44
46
  /** Labels from the root to the field, e.g. ["Author", "Name"]. Falls back to the path segments. */
45
47
  export declare function bindingTrail(fields: BindingField[], path: string): string[];
48
+ /**
49
+ * A context as one document for previews (`valueAt`, the field picker's samples): the document's
50
+ * fields plus `$item`, `$index`, `$parent` and `$page` as keys.
51
+ */
52
+ export declare function previewDoc(context: TemplateContext): Record<string, unknown>;
46
53
  /**
47
54
  * The value at a dot path in a document loaded with depth 1, read the same way the renderer reads
48
55
  * it: groups, populated relationships (polymorphic pairs too) and arrays.
@@ -1,14 +1,14 @@
1
1
  // Pure helpers for templates and data binding in the editor: which document fields a block prop
2
2
  // can bind to, the picker rows, and sample values for previews. No React here, so they are unit tested.
3
3
  import { isLinkField } from '../../../blocks/link.js';
4
- import { COLLECTION_LIST_BLOCK, FIELD_BLOCK, getByPath, isIsoDate, isUploadDoc, LIST_ITEM_SLOT, titleOf, toPlainText, URL_PATH, } from '../../../core/bindings.js';
5
- export { FIELD_BLOCK, URL_PATH };
4
+ import { COLLECTION_LIST_BLOCK, FIELD_BLOCK, REPEAT_BLOCK, getByPath, isIsoDate, isUploadDoc, LIST_ITEM_SLOT, titleOf, toPlainText, URL_PATH, } from '../../../core/bindings.js';
5
+ export { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH };
6
6
  /** Block type of the collection list block. Blocks in its `item` slot bind to each item. */
7
7
  export const LIST_BLOCK = COLLECTION_LIST_BLOCK;
8
8
  export const LIST_SLOT = LIST_ITEM_SLOT;
9
9
  /** The `$url` virtual field: the frontend URL of the document (each item's, inside a list). */
10
10
  export function urlField(scope) {
11
- return { path: URL_PATH, label: scope === 'list' ? 'URL of this item' : 'URL of this document', type: '$url' };
11
+ return { path: URL_PATH, label: scope === 'template' ? 'URL of this document' : 'URL of this item', type: '$url' };
12
12
  }
13
13
  export const URL_FIELD = urlField('list');
14
14
  /** The binding kind of a block prop, or null when the prop cannot be bound. */
@@ -59,6 +59,10 @@ const CONTAINER_TYPES = new Set(['group', 'array', 'blocks', 'tabs', 'row', 'col
59
59
  export function isFieldBlockSource(source) {
60
60
  return !CONTAINER_TYPES.has(source.type);
61
61
  }
62
+ /** Field list block: a field with rows, an array or any hasMany field. */
63
+ export function isFieldListSource(source) {
64
+ return source.type === 'array' || source.hasMany === true;
65
+ }
62
66
  const asList = (value) => (value === undefined ? [] : Array.isArray(value) ? value : [value]);
63
67
  /** True when the two relationTo settings share a collection, or either one is unknown. */
64
68
  function sameTarget(a, b) {
@@ -190,6 +194,22 @@ export function bindingTrail(fields, path) {
190
194
  return path.split('.');
191
195
  }
192
196
  const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
197
+ /**
198
+ * A context as one document for previews (`valueAt`, the field picker's samples): the document's
199
+ * fields plus `$item`, `$index`, `$parent` and `$page` as keys.
200
+ */
201
+ export function previewDoc(context) {
202
+ const doc = { ...context.doc };
203
+ if (context.item !== undefined)
204
+ doc.$item = context.item;
205
+ if (context.index !== undefined)
206
+ doc.$index = context.index;
207
+ if (context.parent)
208
+ doc.$parent = context.parent;
209
+ if (context.page)
210
+ doc.$page = context.page;
211
+ return doc;
212
+ }
193
213
  /**
194
214
  * The value at a dot path in a document loaded with depth 1, read the same way the renderer reads
195
215
  * it: groups, populated relationships (polymorphic pairs too) and arrays.