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.
- package/README.md +342 -30
- package/dist/admin/ArrayRowLabel.d.ts +12 -0
- package/dist/admin/ArrayRowLabel.js +21 -0
- package/dist/admin/client.d.ts +1 -0
- package/dist/admin/client.js +2 -0
- package/dist/admin/editor/Editor.js +8 -1
- package/dist/admin/editor/Inspector.js +23 -17
- package/dist/admin/editor/Library.d.ts +2 -2
- package/dist/admin/editor/Library.js +7 -5
- package/dist/admin/editor/Outline.js +20 -12
- package/dist/admin/editor/Overlay.js +6 -4
- package/dist/admin/editor/actions.d.ts +7 -2
- package/dist/admin/editor/actions.js +44 -12
- package/dist/admin/editor/assistant/AssistantPanel.js +32 -20
- package/dist/admin/editor/comments/controller.d.ts +7 -0
- package/dist/admin/editor/comments/controller.js +12 -0
- package/dist/admin/editor/comments/useCommentFromURL.d.ts +2 -0
- package/dist/admin/editor/comments/useCommentFromURL.js +36 -0
- package/dist/admin/editor/dnd/smooth.js +1 -1
- package/dist/admin/editor/editor.scss +28 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -3
- package/dist/admin/editor/fields/FormBlock.d.ts +20 -0
- package/dist/admin/editor/fields/FormBlock.js +167 -0
- package/dist/admin/editor/fields/FormFieldName.d.ts +25 -0
- package/dist/admin/editor/fields/FormFieldName.js +58 -0
- package/dist/admin/editor/fields/GroupField.d.ts +22 -2
- package/dist/admin/editor/fields/GroupField.js +30 -1
- package/dist/admin/editor/fields/MergeTags.d.ts +8 -0
- package/dist/admin/editor/fields/MergeTags.js +62 -0
- package/dist/admin/editor/fields/arrayRows.d.ts +0 -2
- package/dist/admin/editor/fields/arrayRows.js +0 -4
- package/dist/admin/editor/fields/fields.scss +150 -0
- package/dist/admin/editor/fields/values.d.ts +0 -2
- package/dist/admin/editor/fields/values.js +0 -14
- package/dist/admin/editor/icons.d.ts +3 -0
- package/dist/admin/editor/icons.js +3 -0
- package/dist/admin/editor/insert/InsertHandle.js +1 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -2
- package/dist/admin/editor/insert/picker.js +9 -3
- package/dist/admin/editor/layout/LeftPanel.js +5 -3
- package/dist/admin/editor/layout/leftTabs.d.ts +15 -0
- package/dist/admin/editor/layout/leftTabs.js +18 -0
- package/dist/admin/editor/media/ImageEditor.d.ts +8 -2
- package/dist/admin/editor/media/ImageEditor.js +16 -10
- package/dist/admin/editor/media/media.scss +12 -2
- package/dist/admin/editor/media/model.d.ts +10 -1
- package/dist/admin/editor/media/model.js +19 -0
- package/dist/admin/editor/menu/blockMenu.js +3 -3
- package/dist/admin/editor/names.d.ts +9 -0
- package/dist/admin/editor/names.js +18 -0
- package/dist/admin/editor/regions/RegionFields.d.ts +6 -0
- package/dist/admin/editor/regions/RegionFields.js +122 -0
- package/dist/admin/editor/regions/RegionPane.js +5 -3
- package/dist/admin/editor/regions/RegionRows.js +2 -2
- package/dist/admin/editor/regions/required.d.ts +16 -0
- package/dist/admin/editor/regions/required.js +43 -0
- package/dist/admin/editor/renderField.d.ts +9 -2
- package/dist/admin/editor/renderField.js +86 -32
- package/dist/admin/editor/runtime.d.ts +3 -2
- package/dist/admin/editor/runtime.js +12 -18
- package/dist/admin/editor/styles/StylesPanel.js +4 -2
- package/dist/admin/editor/styles/context.js +9 -4
- package/dist/admin/editor/topbar/ContentModeToggle.js +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +4 -3
- package/dist/admin/editor/topbar/contentMode.scss +0 -9
- package/dist/admin/editor/topbar/topbar.scss +1 -41
- package/dist/admin/editor/ui/Tabs.d.ts +17 -0
- package/dist/admin/editor/ui/Tabs.js +17 -0
- package/dist/admin/forms/SubmissionCells.d.ts +6 -0
- package/dist/admin/forms/SubmissionCells.js +31 -0
- package/dist/admin/forms/SubmissionView.d.ts +5 -0
- package/dist/admin/forms/SubmissionView.js +106 -0
- package/dist/admin/forms/submissionData.d.ts +32 -0
- package/dist/admin/forms/submissionData.js +63 -0
- package/dist/admin/forms/submissions.scss +197 -0
- package/dist/admin/rsc.d.ts +2 -0
- package/dist/admin/rsc.js +5 -0
- package/dist/ai/endpoint.d.ts +5 -0
- package/dist/ai/endpoint.js +18 -8
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +30 -0
- package/dist/ai/tools.d.ts +6 -1
- package/dist/ai/tools.js +90 -6
- package/dist/blocks/builtins/carousel.js +10 -1
- package/dist/blocks/defaults.js +27 -2
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +1 -1
- package/dist/blocks/payload.d.ts +7 -0
- package/dist/blocks/payload.js +16 -2
- package/dist/comments/shared.d.ts +5 -0
- package/dist/comments/shared.js +5 -0
- package/dist/core/blocks.d.ts +17 -3
- package/dist/core/blocks.js +92 -10
- package/dist/core/classes.d.ts +5 -0
- package/dist/core/classes.js +26 -1
- package/dist/core/conditions.d.ts +7 -0
- package/dist/core/conditions.js +22 -0
- package/dist/core/dropTarget.d.ts +3 -2
- package/dist/core/dropTarget.js +7 -1
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +6 -3
- package/dist/core/payloadBlocks.js +25 -3
- package/dist/core/references.d.ts +7 -0
- package/dist/core/references.js +29 -11
- package/dist/core/regions.d.ts +14 -0
- package/dist/core/regions.js +17 -1
- package/dist/core/rowLabel.d.ts +8 -0
- package/dist/core/rowLabel.js +98 -0
- package/dist/core/starter.d.ts +10 -0
- package/dist/core/starter.js +40 -0
- package/dist/core/tree.js +4 -0
- package/dist/core/types.d.ts +96 -0
- package/dist/core/uniqueProps.d.ts +40 -0
- package/dist/core/uniqueProps.js +156 -0
- package/dist/core/validate.js +43 -3
- package/dist/forms/answers.d.ts +21 -0
- package/dist/forms/answers.js +82 -0
- package/dist/forms/blocks.d.ts +33 -0
- package/dist/forms/blocks.js +178 -0
- package/dist/forms/conditions.d.ts +78 -0
- package/dist/forms/conditions.js +184 -0
- package/dist/forms/emails.d.ts +23 -0
- package/dist/forms/emails.js +64 -0
- package/dist/forms/fieldConfigs.d.ts +35 -0
- package/dist/forms/fieldConfigs.js +167 -0
- package/dist/forms/fieldOps.d.ts +78 -0
- package/dist/forms/fieldOps.js +378 -0
- package/dist/forms/fieldSettings.d.ts +81 -0
- package/dist/forms/fieldSettings.js +239 -0
- package/dist/forms/files.d.ts +54 -0
- package/dist/forms/files.js +128 -0
- package/dist/forms/index.d.ts +16 -0
- package/dist/forms/index.js +18 -0
- package/dist/forms/mergeTags.d.ts +103 -0
- package/dist/forms/mergeTags.js +150 -0
- package/dist/forms/noScript.d.ts +60 -0
- package/dist/forms/noScript.js +109 -0
- package/dist/forms/pageForms.d.ts +99 -0
- package/dist/forms/pageForms.js +294 -0
- package/dist/forms/pageSync.d.ts +91 -0
- package/dist/forms/pageSync.js +325 -0
- package/dist/forms/rateLimit.d.ts +21 -0
- package/dist/forms/rateLimit.js +50 -0
- package/dist/forms/settings.d.ts +13 -0
- package/dist/forms/settings.js +92 -0
- package/dist/forms/spam.d.ts +100 -0
- package/dist/forms/spam.js +218 -0
- package/dist/forms/spamSettings.d.ts +43 -0
- package/dist/forms/spamSettings.js +25 -0
- package/dist/forms/submission.d.ts +34 -0
- package/dist/forms/submission.js +89 -0
- package/dist/forms/submissionsAdmin.d.ts +26 -0
- package/dist/forms/submissionsAdmin.js +108 -0
- package/dist/forms/summary.d.ts +60 -0
- package/dist/forms/summary.js +113 -0
- package/dist/forms/uploads.d.ts +41 -0
- package/dist/forms/uploads.js +132 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +8 -2
- package/dist/live/document.d.ts +12 -0
- package/dist/live/document.js +8 -1
- package/dist/live/endpoints.d.ts +1 -0
- package/dist/live/session.js +3 -1
- package/dist/live/storage.d.ts +13 -2
- package/dist/live/storage.js +18 -7
- package/dist/mcp/forms.d.ts +26 -0
- package/dist/mcp/forms.js +280 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.js +29 -10
- package/dist/mcp/shared.d.ts +1 -0
- package/dist/mcp/shared.js +1 -0
- package/dist/plugin/forms.d.ts +30 -0
- package/dist/plugin/forms.js +63 -0
- package/dist/plugin/formsSync.d.ts +138 -0
- package/dist/plugin/formsSync.js +345 -0
- package/dist/plugin/hook.d.ts +22 -0
- package/dist/plugin/hook.js +19 -7
- package/dist/plugin/index.d.ts +14 -0
- package/dist/plugin/index.js +99 -28
- package/dist/plugin/links.d.ts +7 -2
- package/dist/plugin/links.js +9 -3
- package/dist/plugin/references.d.ts +6 -0
- package/dist/plugin/references.js +12 -0
- package/dist/react/canvas/BuilderCanvas.d.ts +2 -0
- package/dist/react/canvas/BuilderCanvas.js +29 -6
- package/dist/react/canvas/inline/mapper.d.ts +6 -1
- package/dist/react/canvas/inline/mapper.js +35 -4
- package/dist/react/components/AutoplayVideo.d.ts +20 -0
- package/dist/react/components/AutoplayVideo.js +34 -0
- package/dist/react/components/Video.d.ts +9 -1
- package/dist/react/components/Video.js +39 -11
- package/dist/react/components/lazy.d.ts +2 -0
- package/dist/react/components/lazy.js +2 -0
- package/dist/react/components/videoPlayback.d.ts +30 -0
- package/dist/react/components/videoPlayback.js +33 -0
- package/dist/react/render/LayoutOutlet.d.ts +7 -3
- package/dist/react/render/LayoutOutlet.js +9 -4
- package/dist/react/render/RenderLayout.js +18 -9
- package/dist/react/render/resolve.d.ts +1 -0
- package/dist/react/render/resolve.js +5 -1
- package/dist/react/render/types.d.ts +1 -1
- package/dist/react/server.js +19 -0
- package/package.json +5 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const poster =
|
|
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:
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 &&
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
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;
|
package/dist/react/server.js
CHANGED
|
@@ -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.
|
|
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",
|