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
@@ -1,6 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { isDoc } from './Image.js';
2
+ import { preload } from 'react-dom';
3
+ import { focalStyle, isDoc } from './Image.js';
4
+ // The script that starts an autoplaying video loads only on pages that render one.
5
+ import { AutoplayVideo } from './lazy.js';
3
6
  import { PlaceholderBox } from './placeholder.js';
7
+ import { decorativeAttributes, videoPreload, videoSettingsOf } from './videoPlayback.js';
4
8
  import { isPlayableVideoUrl, parseVideoUrl } from './videoUrl.js';
5
9
  /** Classes that already give the element a height. Without one, an embed gets a 16:9 ratio. */
6
10
  const SIZE_CLASS = /(^|\s|:)(aspect-|h-|size-|min-h-)/;
@@ -27,15 +31,23 @@ function InvalidUrl({ attributes, className }) {
27
31
  /**
28
32
  * An uploaded video or a URL. YouTube and Vimeo URLs become an `<iframe>`; other URLs play in
29
33
  * `<video>`. In the canvas the iframe ignores the pointer, so clicks select the block.
34
+ *
35
+ * - Autoplay: a `<video>` never gets the `autoplay` attribute. On the site a small client
36
+ * component (`AutoplayVideo`) starts it after mount, unless the visitor asks for less motion.
37
+ * On the canvas (and in section thumbnails) an autoplay video stays paused on its poster, and an
38
+ * embed gets no autoplay.
39
+ * - `priority` (Load first): `preload="auto"`, and the poster preloads with high fetch priority.
40
+ * - The poster's focal point sets `object-position`, with the image block's rule (`focalStyle`).
41
+ * - `decorative`: `aria-hidden="true"`, no controls, no tab stop. For a background video.
30
42
  */
31
- export function Video({ props, className, attributes, mode }) {
32
- const options = {
33
- autoplay: props.autoplay === true,
34
- loop: props.loop === true,
35
- muted: props.muted === true,
36
- controls: props.controls !== false,
37
- };
38
- const poster = isDoc(props.poster) ? props.poster.url : undefined;
43
+ export function Video({ props, className, attributes, mode, canvasMode }) {
44
+ const canvas = mode === 'canvas' || canvasMode !== undefined;
45
+ const settings = videoSettingsOf(props);
46
+ // The canvas never autoplays: editing stays calm.
47
+ const options = { autoplay: settings.autoplay && !canvas, loop: settings.loop, muted: settings.muted, controls: settings.controls };
48
+ const hidden = decorativeAttributes(settings.decorative);
49
+ const posterDoc = isDoc(props.poster) ? props.poster : undefined;
50
+ const poster = posterDoc ? posterDoc.url : undefined;
39
51
  // A missing source means the default ("upload"), unless only a URL is set.
40
52
  const fromUrl = props.source === 'url' || (props.source == null && props.video == null && typeof props.url === 'string');
41
53
  let src = null;
@@ -52,7 +64,7 @@ export function Video({ props, className, attributes, mode }) {
52
64
  Object.assign(style, { aspectRatio: '16 / 9', height: 'auto' });
53
65
  if (mode === 'canvas')
54
66
  style.pointerEvents = 'none';
55
- return (_jsx("iframe", { ...attributes, className: className, src: embed.embedUrl, title: embed.kind === 'youtube' ? 'YouTube video' : 'Vimeo video', allow: "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share", allowFullScreen: true, loading: "lazy", referrerPolicy: "strict-origin-when-cross-origin", style: style }));
67
+ return (_jsx("iframe", { ...attributes, ...hidden, className: className, src: embed.embedUrl, title: embed.kind === 'youtube' ? 'YouTube video' : 'Vimeo video', allow: "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share", allowFullScreen: true, loading: settings.priority ? 'eager' : 'lazy', referrerPolicy: "strict-origin-when-cross-origin", style: style }));
56
68
  }
57
69
  src = embed?.src ?? null;
58
70
  }
@@ -64,5 +76,21 @@ export function Video({ props, className, attributes, mode }) {
64
76
  return null;
65
77
  return _jsx(PlaceholderBox, { attributes: attributes, className: className, label: "Video", style: { aspectRatio: '16 / 9' } });
66
78
  }
67
- return (_jsx("video", { ...attributes, className: className, src: src, poster: poster, autoPlay: options.autoplay, loop: options.loop, muted: options.muted, controls: options.controls, playsInline: true, preload: "metadata" }));
79
+ // The poster is what a visitor sees first, so it loads like a priority image.
80
+ if (settings.priority && poster && !canvas)
81
+ preload(poster, { as: 'image', fetchPriority: 'high' });
82
+ const video = {
83
+ attributes: { ...attributes, ...hidden },
84
+ className,
85
+ src,
86
+ poster,
87
+ loop: options.loop,
88
+ muted: options.muted,
89
+ controls: options.controls,
90
+ preload: videoPreload(settings.priority),
91
+ style: focalStyle(posterDoc),
92
+ };
93
+ if (options.autoplay)
94
+ return _jsx(AutoplayVideo, { ...video });
95
+ return (_jsx("video", { ...video.attributes, className: className, src: src, poster: poster, loop: video.loop, muted: video.muted, controls: video.controls, playsInline: true, preload: video.preload, style: video.style }));
68
96
  }
@@ -1,4 +1,5 @@
1
1
  import type { BlockComponentProps } from '../render/types.js';
2
+ import type { AutoplayVideoProps } from './AutoplayVideo.js';
2
3
  import type { CarouselLabels } from './builtins/Carousel.js';
3
4
  import type { PopupLabels } from './builtins/Popup.js';
4
5
  import type { TabsLabels } from './builtins/Tabs.js';
@@ -29,4 +30,5 @@ export declare const EmbedPreview: import("react").ComponentType<{
29
30
  className?: string;
30
31
  attributes: Record<string, string>;
31
32
  }>;
33
+ export declare const AutoplayVideo: import("react").ComponentType<AutoplayVideoProps>;
32
34
  export declare const Tab: import("react").ComponentType<BlockComponentProps>;
@@ -17,4 +17,6 @@ export const Tabs = lazyBlock(dynamic(() => import('./builtins/Tabs.js').then((m
17
17
  // Not blocks: the parts of the embed block that need JavaScript (`./builtins/Embed`).
18
18
  export const EmbedHtml = dynamic(() => import('./builtins/EmbedHtml.js').then((module) => module.EmbedHtml));
19
19
  export const EmbedPreview = dynamic(() => import('./builtins/EmbedPreview.js').then((module) => module.EmbedPreview));
20
+ // Not a block: the part of the video block that starts an autoplaying video (`./AutoplayVideo`).
21
+ export const AutoplayVideo = dynamic(() => import('./AutoplayVideo.js').then((module) => module.AutoplayVideo));
20
22
  export const Tab = lazyBlock(dynamic(() => import('./builtins/Tab.js').then((module) => module.Tab)));
@@ -0,0 +1,30 @@
1
+ /** The media query of a visitor who asks for less motion. */
2
+ export declare const REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
3
+ export type VideoSettings = {
4
+ autoplay: boolean;
5
+ loop: boolean;
6
+ muted: boolean;
7
+ controls: boolean;
8
+ /** Decoration only (a background): hidden from screen readers, no controls, no tab stop. */
9
+ decorative: boolean;
10
+ /** Load first: `preload="auto"` and the poster preloaded with high fetch priority. */
11
+ priority: boolean;
12
+ };
13
+ /** The block's props as settings. Defaults: everything off but `controls`. */
14
+ export declare function videoSettingsOf(props: Record<string, unknown>): VideoSettings;
15
+ /**
16
+ * True when an autoplaying video may play now: never on the editor's canvas (editing stays calm),
17
+ * and never for a visitor who asks for less motion (the video shows its poster and stays paused).
18
+ */
19
+ export declare function startsPlaying(args: {
20
+ autoplay: boolean;
21
+ canvas: boolean;
22
+ reducedMotion: boolean;
23
+ }): boolean;
24
+ /** The `preload` attribute: the whole video for a video that loads first, else only its metadata. */
25
+ export declare function videoPreload(priority: boolean): 'auto' | 'metadata';
26
+ /** The attributes that take a decorative video out of the accessibility tree and the tab order. */
27
+ export declare function decorativeAttributes(decorative: boolean): {
28
+ 'aria-hidden'?: 'true';
29
+ tabIndex?: -1;
30
+ };
@@ -0,0 +1,33 @@
1
+ // Pure rules of the video block, shared by the server component (`./Video`) and the small client
2
+ // component that starts an autoplaying video (`./AutoplayVideo`). No imports: a client module
3
+ // reaches this file.
4
+ /** The media query of a visitor who asks for less motion. */
5
+ export const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
6
+ /** The block's props as settings. Defaults: everything off but `controls`. */
7
+ export function videoSettingsOf(props) {
8
+ const decorative = props.decorative === true;
9
+ return {
10
+ autoplay: props.autoplay === true,
11
+ loop: props.loop === true,
12
+ muted: props.muted === true,
13
+ // A decorative video has no controls, whatever "Show controls" says.
14
+ controls: props.controls !== false && !decorative,
15
+ decorative,
16
+ priority: props.priority === true,
17
+ };
18
+ }
19
+ /**
20
+ * True when an autoplaying video may play now: never on the editor's canvas (editing stays calm),
21
+ * and never for a visitor who asks for less motion (the video shows its poster and stays paused).
22
+ */
23
+ export function startsPlaying(args) {
24
+ return args.autoplay && !args.canvas && !args.reducedMotion;
25
+ }
26
+ /** The `preload` attribute: the whole video for a video that loads first, else only its metadata. */
27
+ export function videoPreload(priority) {
28
+ return priority ? 'auto' : 'metadata';
29
+ }
30
+ /** The attributes that take a decorative video out of the accessibility tree and the tab order. */
31
+ export function decorativeAttributes(decorative) {
32
+ return decorative ? { 'aria-hidden': 'true', tabIndex: -1 } : {};
33
+ }
@@ -1,11 +1,15 @@
1
1
  import { type ReactNode } from 'react';
2
- /** Canvas only. The live layout the canvas renders. `BuilderCanvas` provides it around the page frame. */
2
+ /** Canvas only. The live layout's blocks the canvas renders. `BuilderCanvas` provides them around the page frame. */
3
3
  export declare const LayoutOutletContext: import("react").Context<ReactNode>;
4
4
  /** Mount notifications include outlets that appear later through Suspense. */
5
5
  export declare const LayoutOutletPresence: import("react").Context<(() => () => void) | null>;
6
6
  /**
7
7
  * Stands in for the layout in the page frame the canvas server action renders. The canvas fills
8
8
  * it with the layout it renders itself, so every block stays live: selectable, draggable and
9
- * edited in place, with no request to the server.
9
+ * edited in place, with no request to the server. The blocks sit in one `div` (the layout's box);
10
+ * `className` styles it, for example `flex flex-wrap gap-4` when the page puts the blocks in a
11
+ * flex row. Without it the box is a plain block.
10
12
  */
11
- export declare function LayoutOutlet(): ReactNode;
13
+ export declare function LayoutOutlet({ className }?: {
14
+ className?: string;
15
+ }): ReactNode;
@@ -1,16 +1,21 @@
1
1
  'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { createContext, useContext, useLayoutEffect } from 'react';
3
- /** Canvas only. The live layout the canvas renders. `BuilderCanvas` provides it around the page frame. */
4
+ import { LAYOUT_ROOT_ATTRIBUTE } from './regions.js';
5
+ /** Canvas only. The live layout's blocks the canvas renders. `BuilderCanvas` provides them around the page frame. */
4
6
  export const LayoutOutletContext = createContext(null);
5
7
  /** Mount notifications include outlets that appear later through Suspense. */
6
8
  export const LayoutOutletPresence = createContext(null);
7
9
  /**
8
10
  * Stands in for the layout in the page frame the canvas server action renders. The canvas fills
9
11
  * it with the layout it renders itself, so every block stays live: selectable, draggable and
10
- * edited in place, with no request to the server.
12
+ * edited in place, with no request to the server. The blocks sit in one `div` (the layout's box);
13
+ * `className` styles it, for example `flex flex-wrap gap-4` when the page puts the blocks in a
14
+ * flex row. Without it the box is a plain block.
11
15
  */
12
- export function LayoutOutlet() {
16
+ export function LayoutOutlet({ className } = {}) {
13
17
  const register = useContext(LayoutOutletPresence);
14
18
  useLayoutEffect(() => register?.(), [register]);
15
- return useContext(LayoutOutletContext);
19
+ const content = useContext(LayoutOutletContext);
20
+ return (_jsx("div", { [LAYOUT_ROOT_ATTRIBUTE]: '', className: className || undefined, children: content }));
16
21
  }
@@ -54,7 +54,9 @@ function renderSlot(block, slot, ctx) {
54
54
  return renderBlocks(children, ctx, staggersChildren(block.motion));
55
55
  if (!isEditor(ctx))
56
56
  return null;
57
- return (_jsx("div", { "data-slot-empty": "", "data-slot-owner": block.id, "data-slot": slot, style: PLACEHOLDER_STYLE }));
57
+ // The slot's description ("Each block here is one slide") shows inside the empty slot.
58
+ const hint = ctx.definitions.get(block.type)?.slots?.[slot]?.description;
59
+ return (_jsx("div", { "data-slot-empty": "", "data-slot-owner": block.id, "data-slot": slot, "data-slot-hint": hint, style: PLACEHOLDER_STYLE }));
58
60
  }
59
61
  /** The contexts a list block's `item` slot renders with: one per listed document or repeat row. */
60
62
  function repeatContexts(block, around) {
@@ -108,14 +110,17 @@ function componentPropsOf(block, ctx) {
108
110
  }
109
111
  /**
110
112
  * True when the block's image loads first: its `priority` prop is on, or not set while the
111
- * first section still has images to give priority to (`priorityImages`). Each one counts.
113
+ * first section still has images to give priority to (`priorityImages`). Each one counts. A
114
+ * `priority` field with `custom.builderAutoPriority: false` (the video block's) is never set this way.
112
115
  */
113
116
  function takesPriority(block, ctx) {
114
117
  const own = block.props?.priority;
115
118
  if (!ctx.priority || ctx.priority.left <= 0 || own === false)
116
119
  return own === true;
117
120
  const definition = ctx.definitions.get(block.type);
118
- const hasPriority = definition?.fields?.some((field) => 'name' in field && field.name === 'priority');
121
+ const hasPriority = definition?.fields?.some((field) => 'name' in field &&
122
+ field.name === 'priority' &&
123
+ field.custom?.builderAutoPriority !== false);
119
124
  if (!hasPriority)
120
125
  return own === true;
121
126
  ctx.priority.left -= 1;
@@ -142,7 +147,7 @@ function renderBlock(stored, ctx, preview = false, item = false) {
142
147
  : editor
143
148
  ? { 'data-block-id': block.id, 'data-block-type': block.type }
144
149
  : canvas
145
- ? { 'data-builder-repeat': '' }
150
+ ? { 'data-builder-repeat': '', ...(ctx.component ? { 'data-builder-component': '' } : {}) }
146
151
  : {};
147
152
  if (editor && !preview && block.hidden)
148
153
  attributes['data-builder-hidden'] = 'true';
@@ -175,7 +180,7 @@ function renderBlock(stored, ctx, preview = false, item = false) {
175
180
  if (slot === SECTION_REF_SLOT) {
176
181
  // A live saved section: its blocks render as repeats on the canvas (the ref is what the
177
182
  // editor selects), and its runtime slot is never a drop target.
178
- slots[slot] = renderBlocks(block.slots?.[slot] ?? [], { ...ctx, repeat: ctx.repeat || canvas });
183
+ slots[slot] = renderBlocks(block.slots?.[slot] ?? [], { ...ctx, repeat: ctx.repeat || canvas, component: canvas });
179
184
  partAttributes[slot] = {};
180
185
  continue;
181
186
  }
@@ -193,10 +198,13 @@ function renderBlock(stored, ctx, preview = false, item = false) {
193
198
  slots[LIST_ITEM_SLOT] = renderListItems(block, ctx);
194
199
  partAttributes[LIST_ITEM_SLOT] = {};
195
200
  }
196
- // Parts (styled slots and `parts`) carry their own classes, with the marker class.
197
- for (const part of blockParts(definition)) {
198
- const own = (partAttributes[part.name] ??= {});
199
- const partClass = withBuilderCssClass(stored.partClassName?.[part.name]);
201
+ // Parts (styled slots and `parts`) carry their own classes, with the marker class. A block whose
202
+ // definition this list lacks (form fields the plugin adds from the forms collection) keeps the
203
+ // parts it stores.
204
+ const partNames = definition ? blockParts(definition).map((part) => part.name) : Object.keys(stored.partClassName ?? {});
205
+ for (const name of partNames) {
206
+ const own = (partAttributes[name] ??= {});
207
+ const partClass = withBuilderCssClass(stored.partClassName?.[name]);
200
208
  if (partClass)
201
209
  own.className = partClass;
202
210
  }
@@ -233,6 +241,7 @@ function createContext(mode, components, blocks, resolveLink, context, pageData,
233
241
  binding: { url: urlResolver(resolveLink), ...(relations ? { relations } : {}) },
234
242
  context,
235
243
  repeat: false,
244
+ component: false,
236
245
  copy: false,
237
246
  pageData,
238
247
  // The editor keeps plain links: a client-side router link would navigate the canvas.
@@ -54,5 +54,6 @@ export type LoadLayoutOptions = RenderLocale & {
54
54
  * 2. Loads every collection list's documents (`depth: 1` or the list's `depth`; published only unless `draft`), with the
55
55
  * access of `options.user` (anonymous without it).
56
56
  * 3. Replaces upload/relationship IDs in block props with documents (one batched `find` per collection).
57
+ * 4. Gives each Form block that shows a saved form that form's fields as its children (`withSavedFormFields`).
57
58
  */
58
59
  export declare function loadLayoutData(layout: Layout, blocks: BlockDefinition[], payload: Payload, options?: LoadLayoutOptions): Promise<Layout>;
@@ -1,4 +1,5 @@
1
1
  // Replaces upload/relationship IDs in block props with documents.
2
+ import { withSavedFormFields } from '../../forms/pageSync.js';
2
3
  import { resolveBindings } from '../../core/index.js';
3
4
  import { isRecord, mapFieldValues } from './fields.js';
4
5
  import { arrangeListDocs, attachListItems, listQueries, listRequest, pageLinks, withPageParams } from './lists.js';
@@ -123,6 +124,7 @@ export function urlResolver(resolveLink) {
123
124
  * 2. Loads every collection list's documents (`depth: 1` or the list's `depth`; published only unless `draft`), with the
124
125
  * access of `options.user` (anonymous without it).
125
126
  * 3. Replaces upload/relationship IDs in block props with documents (one batched `find` per collection).
127
+ * 4. Gives each Form block that shows a saved form that form's fields as its children (`withSavedFormFields`).
126
128
  */
127
129
  export async function loadLayoutData(layout, blocks, payload, options) {
128
130
  const draft = options?.draft ?? false;
@@ -167,7 +169,9 @@ export async function loadLayoutData(layout, blocks, payload, options) {
167
169
  }));
168
170
  const withItems = withPageParams(attachListItems(bound, items, pages), queries);
169
171
  // List items and repeat rows resolve their bindings in `RenderLayout`: they take the relations along.
170
- return resolveLayoutData(withRelations(withItems, relations), blocks, fetchDocs);
172
+ const loaded = await resolveLayoutData(withRelations(withItems, relations), blocks, fetchDocs);
173
+ // A Form block that shows a saved form renders that form's fields as its own blocks.
174
+ return withSavedFormFields(loaded);
171
175
  }
172
176
  /**
173
177
  * One collection list's documents. An unknown collection, a filter that matches nothing (`none`) or
@@ -149,7 +149,7 @@ export type RenderLayoutProps = {
149
149
  /**
150
150
  * How many images of the layout's first section load first (`fetchpriority="high"`, not lazy):
151
151
  * image blocks (and other blocks with a `priority` prop), in page order, unless their **Load first** prop
152
- * is off. Default `1`: the first image of the first section, often the largest thing on screen.
152
+ * is off. A `priority` field with `custom.builderAutoPriority: false` (the video block's) never counts. Default `1`: the first image of the first section, often the largest thing on screen.
153
153
  * Give a layout further down the page (a footer) `0`. Site only.
154
154
  */
155
155
  priorityImages?: number;
@@ -5,6 +5,8 @@ import { collectClasses } from '../core/index.js';
5
5
  import { compileClasses } from '../css/index.js';
6
6
  import { withThemeVariables } from '../theme/server.js';
7
7
  import { loadClassesSheet } from './classes/ClassesStyle.js';
8
+ import { builderConfigOf } from '../live/document.js';
9
+ import { savedFormIds, savedFormsClasses } from '../forms/pageSync.js';
8
10
  export { loadLayoutData } from './render/resolve.js';
9
11
  export { loadTemplate } from './render/templates.js';
10
12
  export { loadedLists } from './render/lists.js';
@@ -35,6 +37,9 @@ export async function compilePageCss(payload, parts) {
35
37
  for (const part of present)
36
38
  for (const name of collectClasses(part.layout, config.blocks))
37
39
  classes.add(name);
40
+ // A Form block that shows a saved form renders that form's fields: their classes count too.
41
+ for (const name of await savedFormClasses(payload, present.map((part) => part.layout)))
42
+ classes.add(name);
38
43
  if (classes.size === 0)
39
44
  return null;
40
45
  try {
@@ -47,3 +52,17 @@ export async function compilePageCss(payload, parts) {
47
52
  return stored();
48
53
  }
49
54
  }
55
+ /** The classes of the fields of the saved forms the layouts show ("Use a saved form"). One query. */
56
+ async function savedFormClasses(payload, layouts) {
57
+ const forms = builderConfigOf(payload)?.pageForms?.collection;
58
+ const ids = savedFormIds(layouts);
59
+ if (!forms || ids.length === 0)
60
+ return [];
61
+ try {
62
+ const { docs } = await payload.find({ collection: forms, where: { id: { in: ids } }, depth: 0, limit: ids.length, pagination: false, select: { fields: true } });
63
+ return savedFormsClasses(docs);
64
+ }
65
+ catch {
66
+ return [];
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-canvas",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "description": "Payload Canvas: a visual drag-and-drop website builder for Payload CMS 3. Nested layout blocks, Tailwind styling, sections, templates, live AI editing over MCP, and the React renderer for your site.",
5
5
  "keywords": [
6
6
  "payload",
@@ -138,6 +138,10 @@
138
138
  "./react/server": {
139
139
  "types": "./dist/react/server.d.ts",
140
140
  "default": "./dist/react/server.js"
141
+ },
142
+ "./forms": {
143
+ "types": "./dist/forms/index.d.ts",
144
+ "default": "./dist/forms/index.js"
141
145
  }
142
146
  },
143
147
  "main": "./dist/index.js",