payload-canvas 0.5.2 → 0.7.0-next.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.
- package/README.md +350 -45
- package/dist/admin/AiKeyField.d.ts +4 -3
- package/dist/admin/AiKeyField.js +3 -3
- package/dist/admin/ArrayRowLabel.d.ts +12 -0
- package/dist/admin/ArrayRowLabel.js +21 -0
- package/dist/admin/BuilderTab.js +1 -1
- package/dist/admin/DocumentEditView.d.ts +1 -1
- package/dist/admin/DocumentEditView.js +2 -3
- package/dist/admin/LayoutField.d.ts +1 -1
- package/dist/admin/LayoutField.js +2 -2
- package/dist/admin/TemplateConditionsField.d.ts +2 -2
- package/dist/admin/TemplateConditionsField.js +2 -2
- package/dist/admin/aiKeyField.css +58 -0
- package/dist/admin/client.d.ts +1 -0
- package/dist/admin/client.js +2 -0
- package/dist/admin/diff/LayoutDiff.js +3 -3
- package/dist/admin/diff/LayoutJsonDiff.d.ts +1 -1
- package/dist/admin/diff/LayoutJsonDiff.js +1 -1
- package/dist/admin/diff/layoutDiff.css +180 -0
- package/dist/admin/editor/Editor.d.ts +2 -2
- package/dist/admin/editor/Editor.js +10 -3
- package/dist/admin/editor/Inspector.js +23 -17
- package/dist/admin/editor/Library.d.ts +2 -2
- package/dist/admin/editor/Library.js +8 -7
- 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.d.ts +1 -1
- package/dist/admin/editor/assistant/AssistantPanel.js +33 -21
- package/dist/admin/editor/assistant/{assistant.scss → assistant.css} +322 -315
- package/dist/admin/editor/classes/ClassManager.d.ts +1 -1
- package/dist/admin/editor/classes/ClassManager.js +1 -1
- package/dist/admin/editor/classes/manager.css +258 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +1 -1
- package/dist/admin/editor/comments/CommentLayer.js +1 -1
- package/dist/admin/editor/comments/CommentsPanel.d.ts +1 -1
- package/dist/admin/editor/comments/CommentsPanel.js +1 -1
- package/dist/admin/editor/comments/{comments.scss → comments.css} +121 -140
- 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/{dnd.scss → dnd.css} +78 -80
- package/dist/admin/editor/dnd/smooth.js +1 -1
- package/dist/admin/editor/{editor.scss → editor.css} +798 -751
- package/dist/admin/editor/empty/EmptyStart.d.ts +1 -1
- package/dist/admin/editor/empty/EmptyStart.js +3 -3
- package/dist/admin/editor/empty/{empty.scss → empty.css} +12 -13
- 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.css +786 -0
- package/dist/admin/editor/fields/values.d.ts +0 -2
- package/dist/admin/editor/fields/values.js +0 -14
- package/dist/admin/editor/generate/GenerateImage.d.ts +1 -1
- package/dist/admin/editor/generate/GenerateImage.js +1 -1
- package/dist/admin/editor/generate/{generate.scss → generate.css} +83 -82
- 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/layout.css +243 -0
- package/dist/admin/editor/layout/leftTabs.d.ts +15 -0
- package/dist/admin/editor/layout/leftTabs.js +18 -0
- package/dist/admin/editor/layout/panels.js +1 -1
- package/dist/admin/editor/live/PresenceUI.d.ts +1 -1
- package/dist/admin/editor/live/PresenceUI.js +2 -2
- package/dist/admin/editor/live/{presence.scss → presence.css} +5 -4
- package/dist/admin/editor/locale/LocaleField.d.ts +1 -1
- package/dist/admin/editor/locale/LocaleField.js +1 -1
- package/dist/admin/editor/locale/LocaleSwitcher.d.ts +1 -1
- package/dist/admin/editor/locale/LocaleSwitcher.js +1 -1
- package/dist/admin/editor/locale/locale.css +153 -0
- package/dist/admin/editor/media/ImageEditor.d.ts +9 -3
- package/dist/admin/editor/media/ImageEditor.js +17 -11
- package/dist/admin/editor/media/{media.scss → media.css} +70 -60
- package/dist/admin/editor/media/model.d.ts +10 -1
- package/dist/admin/editor/media/model.js +19 -0
- package/dist/admin/editor/menu/Menu.d.ts +1 -1
- package/dist/admin/editor/menu/Menu.js +1 -1
- package/dist/admin/editor/menu/blockMenu.js +3 -3
- package/dist/admin/editor/menu/menu.css +132 -0
- package/dist/admin/editor/motion/MotionPanel.d.ts +2 -2
- package/dist/admin/editor/motion/MotionPanel.js +2 -2
- package/dist/admin/editor/motion/{motion.scss → motion.css} +24 -21
- 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 +10 -3
- package/dist/admin/editor/renderField.js +87 -33
- package/dist/admin/editor/runtime.d.ts +3 -2
- package/dist/admin/editor/runtime.js +12 -18
- package/dist/admin/editor/sections/ComponentFields.d.ts +1 -1
- package/dist/admin/editor/sections/ComponentFields.js +2 -3
- package/dist/admin/editor/sections/PropertyControls.d.ts +1 -1
- package/dist/admin/editor/sections/PropertyControls.js +1 -1
- package/dist/admin/editor/sections/components.css +244 -0
- package/dist/admin/editor/sections/variants.css +93 -0
- package/dist/admin/editor/sections/variants.d.ts +1 -1
- package/dist/admin/editor/sections/variants.js +1 -1
- package/dist/admin/editor/styles/ClassBar.d.ts +1 -1
- package/dist/admin/editor/styles/ClassBar.js +1 -1
- package/dist/admin/editor/styles/StylesPanel.d.ts +1 -1
- package/dist/admin/editor/styles/StylesPanel.js +5 -3
- package/dist/admin/editor/styles/{classes.scss → classes.css} +128 -125
- package/dist/admin/editor/styles/context.js +9 -4
- package/dist/admin/editor/styles/{styles.scss → styles.css} +368 -370
- package/dist/admin/editor/templates/Bindable.d.ts +1 -1
- package/dist/admin/editor/templates/Bindable.js +1 -1
- package/dist/admin/editor/templates/binding.js +4 -1
- package/dist/admin/editor/templates/{templates.scss → templates.css} +207 -206
- package/dist/admin/editor/tooltip/Tooltips.d.ts +1 -1
- package/dist/admin/editor/tooltip/Tooltips.js +1 -1
- package/dist/admin/editor/tooltip/{tooltip.scss → tooltip.css} +11 -10
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +1 -1
- package/dist/admin/editor/topbar/ContentModeToggle.js +2 -2
- package/dist/admin/editor/topbar/DocumentActions.js +5 -5
- package/dist/admin/editor/topbar/TopBar.d.ts +1 -1
- package/dist/admin/editor/topbar/TopBar.js +2 -3
- package/dist/admin/editor/topbar/contentMode.css +25 -0
- package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/DrawerRouter.js +52 -40
- package/dist/admin/editor/topbar/screens/ScreenDrawer.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/ScreenDrawer.js +4 -5
- package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +5 -5
- package/dist/admin/editor/topbar/screens/drawerRouterSupport.js +7 -7
- package/dist/admin/editor/topbar/screens/screens.css +139 -0
- package/dist/admin/editor/topbar/settingsDrawer.css +33 -0
- package/dist/admin/editor/topbar/settingsDrawer.d.ts +1 -1
- package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
- package/dist/admin/editor/topbar/{topbar.scss → topbar.css} +189 -231
- package/dist/admin/editor/ui/Select.d.ts +1 -1
- package/dist/admin/editor/ui/Select.js +1 -1
- package/dist/admin/editor/ui/Slider.d.ts +1 -1
- package/dist/admin/editor/ui/Slider.js +1 -1
- package/dist/admin/editor/ui/Tabs.d.ts +17 -0
- package/dist/admin/editor/ui/Tabs.js +17 -0
- package/dist/admin/editor/ui/controls.css +301 -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.css +200 -0
- package/dist/admin/layoutField.css +70 -0
- package/dist/admin/rsc.d.ts +2 -0
- package/dist/admin/rsc.js +5 -0
- package/dist/admin/screen/BuilderScreen.d.ts +1 -1
- package/dist/admin/screen/BuilderScreen.js +1 -1
- package/dist/admin/templateConditions.css +25 -0
- package/dist/ai/endpoint.d.ts +5 -0
- package/dist/ai/endpoint.js +18 -8
- package/dist/ai/images/service.js +2 -2
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +30 -0
- package/dist/ai/settings/index.js +3 -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/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/classes/collection.js +1 -0
- package/dist/classes/sheet.js +2 -0
- package/dist/comments/collection.js +3 -0
- 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/fieldHooks.d.ts +1 -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/draftAccess.js +1 -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 +101 -30
- 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/plugin/sections.js +3 -0
- package/dist/plugin/templates.js +5 -1
- package/dist/react/canvas/BuilderCanvas.d.ts +2 -0
- package/dist/react/canvas/BuilderCanvas.js +29 -6
- package/dist/react/canvas/inline/candidates.js +2 -2
- package/dist/react/canvas/inline/mapper.d.ts +6 -1
- package/dist/react/canvas/inline/mapper.js +35 -4
- package/dist/react/canvas/inline/rich/editor.js +9 -1
- package/dist/react/components/Image.d.ts +1 -1
- package/dist/react/components/Image.js +2 -2
- package/dist/react/render/LayoutOutlet.d.ts +7 -3
- package/dist/react/render/LayoutOutlet.js +9 -4
- package/dist/react/render/RenderLayout.js +13 -7
- package/dist/react/render/resolve.d.ts +1 -0
- package/dist/react/render/resolve.js +7 -1
- package/dist/react/render/templates.js +3 -1
- package/dist/react/server.js +19 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/ColorField.d.ts +4 -3
- package/dist/theme/admin/ColorField.js +1 -1
- package/dist/theme/admin/FontField.d.ts +4 -3
- package/dist/theme/admin/FontField.js +1 -1
- package/dist/theme/admin/SaveSignal.js +1 -1
- package/dist/theme/admin/SliderField.d.ts +1 -1
- package/dist/theme/admin/SliderField.js +1 -1
- package/dist/theme/admin/Variables.d.ts +4 -3
- package/dist/theme/admin/Variables.js +2 -2
- package/dist/theme/admin/fields.css +327 -0
- package/dist/theme/global.js +2 -0
- package/package.json +29 -24
- package/dist/admin/aiKeyField.scss +0 -58
- package/dist/admin/diff/layoutDiff.scss +0 -181
- package/dist/admin/editor/classes/manager.scss +0 -262
- package/dist/admin/editor/fields/fields.scss +0 -628
- package/dist/admin/editor/layout/layout.scss +0 -240
- package/dist/admin/editor/locale/locale.scss +0 -154
- package/dist/admin/editor/menu/menu.scss +0 -132
- package/dist/admin/editor/sections/components.scss +0 -238
- package/dist/admin/editor/sections/variants.scss +0 -90
- package/dist/admin/editor/topbar/contentMode.scss +0 -35
- package/dist/admin/editor/topbar/screens/screens.scss +0 -134
- package/dist/admin/editor/topbar/settingsDrawer.scss +0 -32
- package/dist/admin/editor/ui/controls.scss +0 -320
- package/dist/admin/layoutField.scss +0 -69
- package/dist/admin/templateConditions.scss +0 -24
- package/dist/theme/admin/fields.scss +0 -363
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './empty.
|
|
1
|
+
import './empty.css';
|
|
2
2
|
export declare function EmptyStart(): import("react").JSX.Element | null;
|
|
@@ -21,7 +21,7 @@ import { useRuntime } from '../runtime.js';
|
|
|
21
21
|
import { useEditor } from '../store.js';
|
|
22
22
|
import { isTemplateDoc } from '../templates/state.js';
|
|
23
23
|
import { useValueSelector } from '../valueStore.js';
|
|
24
|
-
import './empty.
|
|
24
|
+
import './empty.css';
|
|
25
25
|
/** Categories of the suggested sections, in order: a page usually starts with these. */
|
|
26
26
|
const SUGGESTED = ['Heroes', 'Features', 'Calls to action'];
|
|
27
27
|
const SUGGESTION_COUNT = 3;
|
|
@@ -92,7 +92,7 @@ function TemplateNotice({ template, titleId, onIgnore }) {
|
|
|
92
92
|
const singular = collections.find((c) => c.slug === runtime.config.collection)?.labels?.singular;
|
|
93
93
|
const noun = typeof singular === 'string' ? singular.toLowerCase() : 'document';
|
|
94
94
|
const templates = runtime.config.templates;
|
|
95
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "builder-empty-start__icon", children: _jsx(Icon, { name: "template", size: 20 }) }), _jsxs("h2", { id: titleId, className: "builder-empty-start__title", children: ["This ", noun, " uses the template \u201C", template.name, "\u201D"] }), _jsxs("p", { className: "builder-empty-start__text", children: ["The site shows this ", noun, " through the template. Blocks you add here do not show while a template applies."] }), _jsxs("div", { className: "builder-empty-start__actions", children: [templates && (_jsx(Button, { el: "link", url: builderViewPath(routes.admin, templates.collection, template.id), buttonStyle: "primary", size: "
|
|
95
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "builder-empty-start__icon", children: _jsx(Icon, { name: "template", size: 20 }) }), _jsxs("h2", { id: titleId, className: "builder-empty-start__title", children: ["This ", noun, " uses the template \u201C", template.name, "\u201D"] }), _jsxs("p", { className: "builder-empty-start__text", children: ["The site shows this ", noun, " through the template. Blocks you add here do not show while a template applies."] }), _jsxs("div", { className: "builder-empty-start__actions", children: [templates && (_jsx(Button, { el: "link", url: builderViewPath(routes.admin, templates.collection, template.id), buttonStyle: "primary", size: "medium", margin: false, children: "Open the template" })), onIgnore && (_jsx(Button, { buttonStyle: "secondary", size: "medium", margin: false, onClick: onIgnore, children: "Add blocks here anyway" }))] })] }));
|
|
96
96
|
}
|
|
97
97
|
function StartOptions({ titleId }) {
|
|
98
98
|
const runtime = useRuntime();
|
|
@@ -101,5 +101,5 @@ function StartOptions({ titleId }) {
|
|
|
101
101
|
if (insertBlocks(runtime, section.blocks, sectionPosition(runtime)))
|
|
102
102
|
runtime.notify(`Added ${section.label}`);
|
|
103
103
|
};
|
|
104
|
-
return (_jsxs(_Fragment, { children: [_jsx("h2", { id: titleId, className: "builder-empty-start__title", children: "Start this page" }), _jsx("p", { className: "builder-empty-start__text", children: picks.length > 0 ? 'Add a section to begin, or build the page block by block.' : 'Add blocks from the Blocks tab, or drag them onto the canvas.' }), picks.length > 0 && (_jsx("ul", { className: "builder-empty-start__sections", "aria-label": "Suggested sections", children: picks.map((section) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "builder-editor__card builder-empty-start__section", onClick: () => insert(section), children: [_jsx(SectionThumb, { section: section }), _jsxs("span", { className: "builder-editor__card-text", children: [_jsx("span", { className: "builder-editor__card-label", children: section.label }), section.category && _jsx("span", { className: "builder-editor__card-desc", children: section.category })] })] }) }, section.id))) })), _jsxs("div", { className: "builder-empty-start__actions", children: [picks.length > 0 && (_jsx(Button, { buttonStyle: "secondary", size: "
|
|
104
|
+
return (_jsxs(_Fragment, { children: [_jsx("h2", { id: titleId, className: "builder-empty-start__title", children: "Start this page" }), _jsx("p", { className: "builder-empty-start__text", children: picks.length > 0 ? 'Add a section to begin, or build the page block by block.' : 'Add blocks from the Blocks tab, or drag them onto the canvas.' }), picks.length > 0 && (_jsx("ul", { className: "builder-empty-start__sections", "aria-label": "Suggested sections", children: picks.map((section) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "builder-editor__card builder-empty-start__section", onClick: () => insert(section), children: [_jsx(SectionThumb, { section: section }), _jsxs("span", { className: "builder-editor__card-text", children: [_jsx("span", { className: "builder-editor__card-label", children: section.label }), section.category && _jsx("span", { className: "builder-editor__card-desc", children: section.category })] })] }) }, section.id))) })), _jsxs("div", { className: "builder-empty-start__actions", children: [picks.length > 0 && (_jsx(Button, { buttonStyle: "secondary", size: "medium", margin: false, onClick: () => selectLeftTab(runtime, 'sections', { focus: true }), children: "Browse sections" })), _jsx(Button, { buttonStyle: "secondary", size: "medium", margin: false, onClick: () => selectLeftTab(runtime, 'blocks', { focus: true }), children: "Add a block" }), runtime.assistant && (_jsx(Button, { buttonStyle: "secondary", size: "medium", margin: false, icon: _jsx(Icon, { name: "sparkle", size: 14 }), iconPosition: "left", onClick: () => runtime.toggleAssistant(true), children: "Ask the assistant" }))] })] }));
|
|
105
105
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* The empty page's start card, over the canvas. Payload CSS variables only. */
|
|
3
2
|
@layer payload-default {
|
|
4
3
|
.builder-empty-start {
|
|
5
4
|
position: absolute;
|
|
@@ -10,7 +9,7 @@
|
|
|
10
9
|
align-items: flex-start;
|
|
11
10
|
padding: 72px 16px 16px;
|
|
12
11
|
overflow: auto;
|
|
13
|
-
|
|
12
|
+
/* Drops from the library pass through to the canvas around the card. */
|
|
14
13
|
pointer-events: none;
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
border: 1px solid var(--be-border);
|
|
25
24
|
border-radius: var(--be-radius-m);
|
|
26
25
|
background: var(--be-panel);
|
|
27
|
-
color: var(--
|
|
26
|
+
color: var(--color-text);
|
|
28
27
|
box-shadow: var(--be-shadow);
|
|
29
28
|
text-align: center;
|
|
30
29
|
pointer-events: auto;
|
|
@@ -43,8 +42,8 @@
|
|
|
43
42
|
|
|
44
43
|
.builder-empty-start__title {
|
|
45
44
|
margin: 0;
|
|
46
|
-
|
|
47
|
-
font-size: calc(
|
|
45
|
+
/* Payload's h4 size (16px): the start card's title is a page-level heading, not panel text. */
|
|
46
|
+
font-size: calc(1.0156rem * 0.8);
|
|
48
47
|
font-weight: var(--be-weight-strong);
|
|
49
48
|
line-height: 1.35;
|
|
50
49
|
text-wrap: balance;
|
|
@@ -53,7 +52,7 @@
|
|
|
53
52
|
.builder-empty-start__text {
|
|
54
53
|
max-width: 48ch;
|
|
55
54
|
margin: 0;
|
|
56
|
-
color: var(--
|
|
55
|
+
color: var(--color-text-secondary);
|
|
57
56
|
font-size: var(--be-text-m);
|
|
58
57
|
line-height: 1.5;
|
|
59
58
|
text-wrap: balance;
|
|
@@ -72,14 +71,14 @@
|
|
|
72
71
|
.builder-empty-start__section {
|
|
73
72
|
height: 100%;
|
|
74
73
|
cursor: pointer;
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
.builder-empty-start__section .builder-editor__thumb {
|
|
77
|
+
height: 84px;
|
|
78
|
+
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
80
|
+
.builder-empty-start__section .builder-editor__thumb--picture {
|
|
81
|
+
max-height: 84px;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
.builder-empty-start__actions {
|
|
@@ -7,9 +7,9 @@ import { Icon } from '../icons.js';
|
|
|
7
7
|
import { RenderBlockFields } from '../renderField.js';
|
|
8
8
|
import { Popover, usePopover } from '../styles/popover.js';
|
|
9
9
|
import { AddButton } from './AddButton.js';
|
|
10
|
-
import {
|
|
10
|
+
import { rowLabel } from '../../../core/rowLabel.js';
|
|
11
|
+
import { arrayStateKey, cloneRow, moveItem, toggleId, withRowIds } from './arrayRows.js';
|
|
11
12
|
import { ArrayRowContext, asStructuralChange, generatedRowId, getCollapsedRows, setCollapsedRows, useCollapsedRows } from './arrayState.js';
|
|
12
|
-
import { rowLabel } from './values.js';
|
|
13
13
|
/**
|
|
14
14
|
* Payload's array field, without a Form: collapsible rows with a row label, "Collapse all" and
|
|
15
15
|
* "Show all", drag to reorder, and a row menu (move, add below, duplicate, remove). Every edit
|
|
@@ -66,7 +66,7 @@ const ArrayFieldRow = memo(function ArrayFieldRow({ actions, collapsed, fields,
|
|
|
66
66
|
const rowPath = `${path}.${index}`;
|
|
67
67
|
const rowKey = `${stateKey}.${row.id}`;
|
|
68
68
|
const context = useMemo(() => ({ rowPath, rowKey }), [rowPath, rowKey]);
|
|
69
|
-
const title = rowLabel(row, fields
|
|
69
|
+
const title = rowLabel(row, fields, index, itemLabel);
|
|
70
70
|
return (_jsx("div", { ref: setNodeRef, className: "builder-field-array__row", "data-dragging": isDragging || undefined, style: { transform, transition, zIndex: isDragging ? 1 : undefined }, children: _jsx(Collapsible, { actions: _jsx(RowMenu, { actions: actions, full: full, index: index, rowCount: rowCount }), className: "builder-field-array__collapsible", dragHandleProps: { id: row.id, attributes: attributes, listeners }, header: _jsx("span", { className: "builder-field-array__title", children: title }), isCollapsed: collapsed, onToggle: (next) => actions.setCollapsed(row.id, next), children: !collapsed && (_jsx(ArrayRowContext, { value: context, children: _jsx("div", { className: "builder-field-array__fields", children: _jsx(RenderBlockFields, { fields: fields, data: row, path: rowPath, onChange: (next) => actions.change(row.id, next) }) }) })) }) }));
|
|
71
71
|
});
|
|
72
72
|
function RowMenu({ actions, full, index, rowCount, }) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export { FIELD_NAME_MARKER } from '../../../forms/blocks.js';
|
|
3
|
+
/** The Form block's actions, under its mode. */
|
|
4
|
+
export declare function FormBlockActions({ path }: {
|
|
5
|
+
path: string;
|
|
6
|
+
}): import("react").JSX.Element | null;
|
|
7
|
+
/**
|
|
8
|
+
* Under a form field's name: renaming a field of a form with submissions keeps the old
|
|
9
|
+
* submissions under the old name. Compares with the name the field had when it was selected.
|
|
10
|
+
*/
|
|
11
|
+
export declare function FieldNameNote({ path, value, children }: {
|
|
12
|
+
path: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* In the form builder: a form built on a page says so, with a link to that page, because the
|
|
18
|
+
* page's next publish of a change to the form writes its own version over changes made here.
|
|
19
|
+
*/
|
|
20
|
+
export declare function FormSourceNote(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Forms on pages, in the inspector:
|
|
4
|
+
// - `FormBlockActions` (`admin.custom.builderFormActions` on the Form block): for a saved form,
|
|
5
|
+
// "Edit form" (the form builder) and "Move into this page" (its fields become blocks inside this
|
|
6
|
+
// Form block); for a form built here, where its answers go.
|
|
7
|
+
// - `FieldNameNote` (`admin.custom.builderFieldName` on a form field's `name`): renaming a field of
|
|
8
|
+
// a form that has submissions warns that the old submissions keep the old name.
|
|
9
|
+
import { Button, useConfig } from '@payloadcms/ui';
|
|
10
|
+
import { useEffect, useState } from 'react';
|
|
11
|
+
import { findBlock } from '../../../core/tree.js';
|
|
12
|
+
import { FORM_SLOT, formBlockMode, formIdOf } from '../../../forms/pageForms.js';
|
|
13
|
+
import { formSourceOf, movedFormLook } from '../../../forms/pageSync.js';
|
|
14
|
+
import { getBlockDefinition } from '../../../core/blocks.js';
|
|
15
|
+
import { builderViewPath } from '../../../plugin/links.js';
|
|
16
|
+
import { withNewIds } from '../actions.js';
|
|
17
|
+
import { propPathOf } from '../live/field.js';
|
|
18
|
+
import { useRuntime } from '../runtime.js';
|
|
19
|
+
import { useEditor } from '../store.js';
|
|
20
|
+
import { formBlockAround } from './FormFieldName.js';
|
|
21
|
+
export { FIELD_NAME_MARKER } from '../../../forms/blocks.js';
|
|
22
|
+
/** Path of the claim endpoint under the live path (plugin/formsSync.ts). */
|
|
23
|
+
const FORM_CLAIM_PATH = 'form-claim';
|
|
24
|
+
/** The number of submissions of a form, or null while it loads or when it cannot be read. */
|
|
25
|
+
function useSubmissionCount(runtime, formId) {
|
|
26
|
+
const submissions = runtime.config.forms?.submissions ?? null;
|
|
27
|
+
const [count, setCount] = useState(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (formId === null || !submissions)
|
|
30
|
+
return;
|
|
31
|
+
const controller = new AbortController();
|
|
32
|
+
const url = `${runtime.api}/${submissions}?where[form][equals]=${encodeURIComponent(String(formId))}&limit=1&depth=0`;
|
|
33
|
+
fetch(url, { credentials: 'include', signal: controller.signal })
|
|
34
|
+
.then((response) => (response.ok ? response.json() : null))
|
|
35
|
+
.then((body) => {
|
|
36
|
+
if (typeof body?.totalDocs === 'number')
|
|
37
|
+
setCount({ id: formId, total: body.totalDocs });
|
|
38
|
+
})
|
|
39
|
+
.catch(() => { });
|
|
40
|
+
return () => controller.abort();
|
|
41
|
+
}, [formId, submissions, runtime.api]);
|
|
42
|
+
return count && formId !== null && count.id === formId ? count.total : null;
|
|
43
|
+
}
|
|
44
|
+
/** "Move into this page": the saved form's fields and settings become this Form block's own. One undo step. */
|
|
45
|
+
async function moveIntoPage(runtime, blockId, formId) {
|
|
46
|
+
const { collection, id } = runtime.doc.meta.get();
|
|
47
|
+
let body;
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch(`${runtime.config.liveEndpoint}/${collection}/${encodeURIComponent(id)}/${FORM_CLAIM_PATH}`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
credentials: 'include',
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
body: JSON.stringify({ block: blockId, form: formId }),
|
|
54
|
+
});
|
|
55
|
+
body = (await response.json());
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
runtime.warn('The form could not be moved. Check your connection and try again.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!body.ok) {
|
|
62
|
+
runtime.warn(body.error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const { layout } = runtime.store.getState();
|
|
66
|
+
const form = findBlock(layout, blockId);
|
|
67
|
+
if (!form)
|
|
68
|
+
return;
|
|
69
|
+
// The saved form's fields replace what the block holds (a block switched from "Build here" may
|
|
70
|
+
// still hold fields): no second set of names and Submit buttons. New ids: two blocks may move the same form in.
|
|
71
|
+
const children = body.children.map(withNewIds);
|
|
72
|
+
const unset = body.kept ? [] : ['form'];
|
|
73
|
+
// A block that was only a box around the saved form gets the Form block's layout and part classes.
|
|
74
|
+
const look = movedFormLook(form, getBlockDefinition(runtime.config.blocks, form.type));
|
|
75
|
+
const ops = [
|
|
76
|
+
...(form.slots?.[FORM_SLOT] ?? []).map((child) => ({ type: 'remove', id: child.id })),
|
|
77
|
+
{ type: 'update', id: blockId, props: body.props, ...(unset.length > 0 ? { unsetProps: unset } : {}), ...look },
|
|
78
|
+
...children.map((block, i) => ({ type: 'insert', block, to: { parentId: blockId, slot: FORM_SLOT, index: i } })),
|
|
79
|
+
];
|
|
80
|
+
if (!runtime.store.apply(ops, { select: blockId }))
|
|
81
|
+
return;
|
|
82
|
+
runtime.notify(body.kept
|
|
83
|
+
? 'The form is now part of this page. Publish the page to save changes to it; its submissions stay.'
|
|
84
|
+
: 'Copied the form into this page. Other pages use the saved form, so this page gets its own form when you publish.');
|
|
85
|
+
}
|
|
86
|
+
function Note({ children }) {
|
|
87
|
+
return _jsx("p", { className: "builder-field-note", children: children });
|
|
88
|
+
}
|
|
89
|
+
/** The Form block's actions, under its mode. */
|
|
90
|
+
export function FormBlockActions({ path }) {
|
|
91
|
+
const runtime = useRuntime();
|
|
92
|
+
const { config } = useConfig();
|
|
93
|
+
const blockId = propPathOf(path)?.blockId ?? '';
|
|
94
|
+
const block = useEditor(runtime.store, (s) => findBlock(s.view, blockId));
|
|
95
|
+
const mode = formBlockMode(block?.props, block?.slots);
|
|
96
|
+
const formId = formIdOf(block?.props?.form);
|
|
97
|
+
const count = useSubmissionCount(runtime, formId);
|
|
98
|
+
const [busy, setBusy] = useState(false);
|
|
99
|
+
const forms = runtime.config.forms;
|
|
100
|
+
if (!block || !forms)
|
|
101
|
+
return null;
|
|
102
|
+
const admin = config.routes.admin === '/' ? '' : config.routes.admin;
|
|
103
|
+
const answers = count === null ? null : count === 0 ? 'No submissions yet.' : `${count} ${count === 1 ? 'submission' : 'submissions'} so far.`;
|
|
104
|
+
const submissionsLink = formId !== null && forms.submissions ? `${admin}/collections/${forms.submissions}?where[form][equals]=${encodeURIComponent(String(formId))}` : null;
|
|
105
|
+
if (mode === 'build') {
|
|
106
|
+
return (_jsxs("div", { className: "builder-form-actions", children: [_jsx(Note, { children: formId === null
|
|
107
|
+
? 'Visitors can send this form once the page is published. Publishing saves it to Forms.'
|
|
108
|
+
: `Publishing the page saves changes to this form (Forms #${String(formId)}). ${answers ?? ''}` }), submissionsLink && count ? (_jsx(Button, { el: "link", url: submissionsLink, newTab: true, buttonStyle: "secondary", size: "medium", margin: false, children: "View submissions" })) : null] }));
|
|
109
|
+
}
|
|
110
|
+
if (formId === null)
|
|
111
|
+
return null;
|
|
112
|
+
return (_jsxs("div", { className: "builder-form-actions", children: [answers ? _jsx(Note, { children: answers }) : null, _jsxs("div", { className: "builder-form-actions__row", children: [_jsx(Button, { el: "link", url: builderViewPath(config.routes.admin, forms.collection, formId), newTab: true, buttonStyle: "secondary", size: "medium", margin: false, children: "Edit form" }), _jsx(Button, { buttonStyle: "secondary", size: "medium", margin: false, disabled: busy, tooltip: "Its fields become blocks in this form, so you edit them here", onClick: () => {
|
|
113
|
+
setBusy(true);
|
|
114
|
+
void moveIntoPage(runtime, blockId, formId).finally(() => setBusy(false));
|
|
115
|
+
}, children: "Move into this page" })] })] }));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Under a form field's name: renaming a field of a form with submissions keeps the old
|
|
119
|
+
* submissions under the old name. Compares with the name the field had when it was selected.
|
|
120
|
+
*/
|
|
121
|
+
export function FieldNameNote({ path, value, children }) {
|
|
122
|
+
const runtime = useRuntime();
|
|
123
|
+
const blockId = propPathOf(path)?.blockId ?? '';
|
|
124
|
+
// The name when the field was selected (the inspector remounts per block).
|
|
125
|
+
const [first] = useState(value);
|
|
126
|
+
const form = useEditor(runtime.store, (s) => formBlockAround(s.view, blockId));
|
|
127
|
+
const forms = runtime.config.forms;
|
|
128
|
+
// On a page: the Form block's form. In the form builder: the open form itself.
|
|
129
|
+
const meta = runtime.doc.meta.get();
|
|
130
|
+
const formId = form ? formIdOf(form.props?.form) : forms && meta.collection === forms.collection ? meta.id : null;
|
|
131
|
+
const count = useSubmissionCount(runtime, formId);
|
|
132
|
+
const renamed = typeof first === 'string' && first !== '' && value !== first;
|
|
133
|
+
return (_jsxs(_Fragment, { children: [children, renamed && count ? (_jsxs("p", { className: "builder-field-note builder-field-note--warning", children: ["This form has ", count, " ", count === 1 ? 'submission' : 'submissions', ". They keep the old name \u201C", String(first), "\u201D; new ones use the new name."] })) : null] }));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* In the form builder: a form built on a page says so, with a link to that page, because the
|
|
137
|
+
* page's next publish of a change to the form writes its own version over changes made here.
|
|
138
|
+
*/
|
|
139
|
+
export function FormSourceNote() {
|
|
140
|
+
const runtime = useRuntime();
|
|
141
|
+
const { config } = useConfig();
|
|
142
|
+
const forms = runtime.config.forms;
|
|
143
|
+
const meta = runtime.doc.meta.get();
|
|
144
|
+
const isForm = Boolean(forms && meta.collection === forms.collection);
|
|
145
|
+
const [source, setSource] = useState(null);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (!isForm || !forms)
|
|
148
|
+
return;
|
|
149
|
+
const controller = new AbortController();
|
|
150
|
+
const load = async () => {
|
|
151
|
+
const response = await fetch(`${runtime.api}/${forms.collection}/${encodeURIComponent(meta.id)}?depth=0`, { credentials: 'include', signal: controller.signal });
|
|
152
|
+
const doc = response.ok ? (await response.json()) : null;
|
|
153
|
+
const own = doc ? formSourceOf(doc) : null;
|
|
154
|
+
if (!own)
|
|
155
|
+
return;
|
|
156
|
+
const page = await fetch(`${runtime.api}/${own.collection}/${encodeURIComponent(own.document)}?depth=0&draft=true`, { credentials: 'include', signal: controller.signal });
|
|
157
|
+
const pageDoc = page.ok ? (await page.json()) : null;
|
|
158
|
+
const title = typeof pageDoc?.title === 'string' && pageDoc.title ? pageDoc.title : null;
|
|
159
|
+
setSource({ collection: own.collection, document: own.document, title });
|
|
160
|
+
};
|
|
161
|
+
load().catch(() => { });
|
|
162
|
+
return () => controller.abort();
|
|
163
|
+
}, [isForm, forms, meta.id, runtime.api]);
|
|
164
|
+
if (!source)
|
|
165
|
+
return null;
|
|
166
|
+
return (_jsxs("div", { className: "builder-form-actions builder-form-actions--source", children: [_jsxs("p", { className: "builder-field-note builder-field-note--warning", children: ["This form is built on the page ", source.title ? `“${source.title}”` : `#${source.document}`, ". Edit it there: when that page publishes a change to this form, it replaces changes made here."] }), _jsx(Button, { el: "link", url: builderViewPath(config.routes.admin, source.collection, source.document), buttonStyle: "secondary", size: "medium", margin: false, children: "Open the page" })] }));
|
|
167
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Block, Layout } from '../../../core/types.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
readonly description?: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
readonly required: boolean;
|
|
8
|
+
readonly onChange: (value: unknown) => void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The named fields of the form being edited, as options: "Topic (topic)". On a page: the fields of
|
|
12
|
+
* the Form block that holds `except` (or the selected block); in the form builder: the layout's
|
|
13
|
+
* fields. `except`: the id of a field to leave out (the field itself).
|
|
14
|
+
*/
|
|
15
|
+
export declare function useFormFieldOptions(except?: string): {
|
|
16
|
+
label: string;
|
|
17
|
+
value: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}[];
|
|
20
|
+
/** The Form block that holds `blockId` (or is it), or null: the form builder's layout is one form. */
|
|
21
|
+
export declare function formBlockAround(layout: Layout, blockId: string | null | undefined): Block | null;
|
|
22
|
+
/** The fields of the form around `blockId`: its Form block's fields, else every field of the layout. */
|
|
23
|
+
export declare function formFieldsAround(layout: Layout, blockId: string | null | undefined): Block[];
|
|
24
|
+
export declare function FormFieldNameField({ label, description, path, value, required, onChange }: Props): import("react").JSX.Element;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// `admin.custom.builderFormField`: a text field that names another field of the same form (a
|
|
4
|
+
// display condition's "Field"). The builder shows a list of the form's named fields instead of a
|
|
5
|
+
// text input, so a typo cannot break the condition. The value stays the field's name.
|
|
6
|
+
import { SelectInput } from '@payloadcms/ui';
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
import { findBlock, findLocation } from '../../../core/tree.js';
|
|
9
|
+
import { FORM_BLOCK, formBlockFields, formFieldsIn } from '../../../forms/pageForms.js';
|
|
10
|
+
import { propPathOf } from '../live/field.js';
|
|
11
|
+
import { useRuntime } from '../runtime.js';
|
|
12
|
+
import { useEditor } from '../store.js';
|
|
13
|
+
/**
|
|
14
|
+
* The named fields of the form being edited, as options: "Topic (topic)". On a page: the fields of
|
|
15
|
+
* the Form block that holds `except` (or the selected block); in the form builder: the layout's
|
|
16
|
+
* fields. `except`: the id of a field to leave out (the field itself).
|
|
17
|
+
*/
|
|
18
|
+
export function useFormFieldOptions(except) {
|
|
19
|
+
const runtime = useRuntime();
|
|
20
|
+
const layout = useEditor(runtime.store, (s) => s.view);
|
|
21
|
+
const selectedId = useEditor(runtime.store, (s) => s.selectedId);
|
|
22
|
+
return useMemo(() => {
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const block of formFieldsAround(layout, except ?? selectedId)) {
|
|
25
|
+
const name = block.props?.name;
|
|
26
|
+
if (block.id === except || typeof name !== 'string' || !name.trim())
|
|
27
|
+
continue;
|
|
28
|
+
if (out.some((o) => o.value === name))
|
|
29
|
+
continue;
|
|
30
|
+
const text = typeof block.props?.label === 'string' && block.props.label.trim() ? block.props.label.trim() : name;
|
|
31
|
+
out.push({ label: text === name ? name : `${text} (${name})`, value: name, title: text });
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}, [layout, except, selectedId]);
|
|
35
|
+
}
|
|
36
|
+
/** The Form block that holds `blockId` (or is it), or null: the form builder's layout is one form. */
|
|
37
|
+
export function formBlockAround(layout, blockId) {
|
|
38
|
+
if (!blockId)
|
|
39
|
+
return null;
|
|
40
|
+
for (let id = blockId; id; id = findLocation(layout, id)?.parentId ?? null) {
|
|
41
|
+
const block = findBlock(layout, id);
|
|
42
|
+
if (block?.type === FORM_BLOCK)
|
|
43
|
+
return block;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/** The fields of the form around `blockId`: its Form block's fields, else every field of the layout. */
|
|
48
|
+
export function formFieldsAround(layout, blockId) {
|
|
49
|
+
const form = formBlockAround(layout, blockId);
|
|
50
|
+
return form ? formBlockFields(form) : formFieldsIn(layout.blocks);
|
|
51
|
+
}
|
|
52
|
+
export function FormFieldNameField({ label, description, path, value, required, onChange }) {
|
|
53
|
+
const fields = useFormFieldOptions(propPathOf(path)?.blockId);
|
|
54
|
+
const current = typeof value === 'string' ? value : '';
|
|
55
|
+
// A name no field has any more stays visible, so the editor sees what to fix.
|
|
56
|
+
const options = current && !fields.some((o) => o.value === current) ? [...fields, { label: `${current} (not in this form)`, value: current, title: current }] : fields;
|
|
57
|
+
return (_jsx(SelectInput, { description: description, isClearable: !required, label: label, name: path, onChange: (option) => onChange(Array.isArray(option) ? (option[0]?.value ?? null) : (option?.value ?? null)), options: options, path: path, required: required, value: current || undefined }));
|
|
58
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import type { Field } from 'payload';
|
|
3
3
|
type Props = {
|
|
4
4
|
readonly fields: Field[];
|
|
5
5
|
readonly label: string;
|
|
6
6
|
readonly description?: string;
|
|
7
|
+
/** No heading and no indent: a section around the group already names it. */
|
|
8
|
+
readonly plain?: boolean;
|
|
7
9
|
readonly path: string;
|
|
8
10
|
readonly value: unknown;
|
|
9
11
|
/** The whole group object, or `undefined` when every sub-field is empty. */
|
|
@@ -21,5 +23,23 @@ export declare function FieldSection({ label, description, collapsed, children,
|
|
|
21
23
|
readonly children: ReactNode;
|
|
22
24
|
}): import("react").JSX.Element;
|
|
23
25
|
/** A named group: a small heading over its sub-fields, which edit one nested object. */
|
|
24
|
-
export declare function GroupField({ fields, label, description, path, value, onChange }: Props): import("react").JSX.Element;
|
|
26
|
+
export declare function GroupField({ fields, label, description, plain, path, value, onChange }: Props): import("react").JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* A Payload `tabs` field with several tabs: a tab strip, then the fields of the chosen tab.
|
|
29
|
+
* `render` gives the content of one tab (by index). The choice stays while the editor is open.
|
|
30
|
+
*/
|
|
31
|
+
export declare function FieldTabs({ labels, path, render }: {
|
|
32
|
+
readonly labels: string[];
|
|
33
|
+
readonly path: string;
|
|
34
|
+
readonly render: (index: number) => ReactNode;
|
|
35
|
+
}): import("react").JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* A section of a settings panel (form settings): a heading that opens and closes it, over its
|
|
38
|
+
* fields. `open`: open at first.
|
|
39
|
+
*/
|
|
40
|
+
export declare function PanelSection({ label, open, children }: {
|
|
41
|
+
readonly label: string;
|
|
42
|
+
readonly open?: boolean;
|
|
43
|
+
readonly children: ReactNode;
|
|
44
|
+
}): import("react").JSX.Element;
|
|
25
45
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Icon } from '../icons.js';
|
|
3
5
|
import { RenderBlockFields } from '../renderField.js';
|
|
6
|
+
import { Tabs } from '../ui/Tabs.js';
|
|
4
7
|
/**
|
|
5
8
|
* Fields that share the parent's data, under a small heading: a collapsible, or one of several
|
|
6
9
|
* unnamed tabs. Looks like a group, but stores nothing of its own. `collapsed`: a collapsible with
|
|
@@ -13,6 +16,32 @@ export function FieldSection({ label, description, collapsed, children, }) {
|
|
|
13
16
|
return (_jsxs("fieldset", { className: "builder-field-group", children: [_jsx("legend", { className: "builder-field-group__label", children: label }), _jsx("div", { className: "builder-field-group__fields", children: children })] }));
|
|
14
17
|
}
|
|
15
18
|
/** A named group: a small heading over its sub-fields, which edit one nested object. */
|
|
16
|
-
export function GroupField({ fields, label, description, path, value, onChange }) {
|
|
19
|
+
export function GroupField({ fields, label, description, plain, path, value, onChange }) {
|
|
20
|
+
if (plain) {
|
|
21
|
+
return (_jsxs("div", { className: "builder-field-group builder-field-group--plain", children: [description && _jsx("p", { className: "builder-field-group__description", children: description }), _jsx("div", { className: "builder-field-group__fields", children: _jsx(RenderBlockFields, { fields: fields, data: value, path: path, onChange: onChange }) })] }));
|
|
22
|
+
}
|
|
17
23
|
return (_jsxs("fieldset", { className: "builder-field-group", children: [_jsx("legend", { className: "builder-field-group__label", children: label }), description && _jsx("p", { className: "builder-field-group__description", children: description }), _jsx("div", { className: "builder-field-group__fields", children: _jsx(RenderBlockFields, { fields: fields, data: value, path: path, onChange: onChange }) })] }));
|
|
18
24
|
}
|
|
25
|
+
/** The tab each set of tabs showed last, by its tab labels: moving to another field keeps the tab. */
|
|
26
|
+
const chosenTabs = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* A Payload `tabs` field with several tabs: a tab strip, then the fields of the chosen tab.
|
|
29
|
+
* `render` gives the content of one tab (by index). The choice stays while the editor is open.
|
|
30
|
+
*/
|
|
31
|
+
export function FieldTabs({ labels, path, render }) {
|
|
32
|
+
const key = labels.join('\u0000');
|
|
33
|
+
const [chosen, setChosen] = useState(() => chosenTabs.get(key) ?? labels[0]);
|
|
34
|
+
const index = Math.max(0, labels.indexOf(chosen));
|
|
35
|
+
const panelId = (label) => `${path.replace(/\W/g, '_')}-tab-${labels.indexOf(label)}`;
|
|
36
|
+
return (_jsxs("div", { className: "builder-field-tabs", children: [_jsx(Tabs, { variant: "segmented", value: labels[index], options: labels.map((label) => ({ id: label, label })), panelId: panelId, onChange: (label) => {
|
|
37
|
+
chosenTabs.set(key, label);
|
|
38
|
+
setChosen(label);
|
|
39
|
+
} }), _jsx("div", { className: "builder-field-tabs__panel", id: panelId(labels[index]), role: "tabpanel", "aria-label": labels[index], children: render(index) })] }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A section of a settings panel (form settings): a heading that opens and closes it, over its
|
|
43
|
+
* fields. `open`: open at first.
|
|
44
|
+
*/
|
|
45
|
+
export function PanelSection({ label, open = false, children }) {
|
|
46
|
+
return (_jsxs("details", { className: "builder-panel-section", open: open, children: [_jsxs("summary", { className: "builder-panel-section__head", children: [_jsx("span", { children: label }), _jsx(Icon, { name: "chevronDown", size: 14, className: "builder-panel-section__chevron" })] }), _jsx("div", { className: "builder-panel-section__fields", children: children })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
type Props = {
|
|
3
|
+
readonly value: unknown;
|
|
4
|
+
readonly onChange: (value: unknown) => void;
|
|
5
|
+
readonly children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare function MergeTagsFrame({ value, onChange, children }: Props): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// `admin.custom.builderMergeTags`: an "Insert field" menu over a text, code or rich text input of
|
|
4
|
+
// a form's settings (an email's To, Subject, Body). It lists the form's fields as merge tags
|
|
5
|
+
// (`{{email}}`) and `{{*}}` for every answer, and inserts the tag at the cursor. Text inputs get
|
|
6
|
+
// the new value through `onChange`; rich text gets typed text, so Lexical handles it as typing.
|
|
7
|
+
import { useEffect, useRef } from 'react';
|
|
8
|
+
import { ALL_ANSWERS_TAG, mergeTag } from '../../../forms/mergeTags.js';
|
|
9
|
+
import { Icon } from '../icons.js';
|
|
10
|
+
import { MenuButton } from '../menu/Menu.js';
|
|
11
|
+
import { useFormFieldOptions } from './FormFieldName.js';
|
|
12
|
+
const TEXT_INPUT = 'textarea, input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"])';
|
|
13
|
+
export function MergeTagsFrame({ value, onChange, children }) {
|
|
14
|
+
const fields = useFormFieldOptions();
|
|
15
|
+
const root = useRef(null);
|
|
16
|
+
// The last cursor in the rich text editor: opening the menu moves the focus away from it.
|
|
17
|
+
const range = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const remember = () => {
|
|
20
|
+
const selection = document.getSelection();
|
|
21
|
+
const editable = root.current?.querySelector('[contenteditable="true"]');
|
|
22
|
+
if (editable && selection && selection.rangeCount > 0 && editable.contains(selection.anchorNode))
|
|
23
|
+
range.current = selection.getRangeAt(0).cloneRange();
|
|
24
|
+
};
|
|
25
|
+
document.addEventListener('selectionchange', remember);
|
|
26
|
+
return () => document.removeEventListener('selectionchange', remember);
|
|
27
|
+
}, []);
|
|
28
|
+
const insert = (tag) => {
|
|
29
|
+
const editable = root.current?.querySelector('[contenteditable="true"]');
|
|
30
|
+
if (editable) {
|
|
31
|
+
editable.focus();
|
|
32
|
+
const selection = document.getSelection();
|
|
33
|
+
if (selection && range.current && editable.contains(range.current.startContainer)) {
|
|
34
|
+
selection.removeAllRanges();
|
|
35
|
+
selection.addRange(range.current);
|
|
36
|
+
}
|
|
37
|
+
// A typed text: the rich text editor keeps its own state and undo.
|
|
38
|
+
// oxlint-disable-next-line typescript/no-deprecated -- the one way to type into a contenteditable as the user would
|
|
39
|
+
document.execCommand('insertText', false, tag);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const input = root.current?.querySelector(TEXT_INPUT);
|
|
43
|
+
const text = typeof value === 'string' ? value : '';
|
|
44
|
+
const start = input?.selectionStart ?? text.length;
|
|
45
|
+
const end = input?.selectionEnd ?? start;
|
|
46
|
+
onChange(`${text.slice(0, start)}${tag}${text.slice(end)}`);
|
|
47
|
+
// The cursor goes after the tag once the new value renders.
|
|
48
|
+
requestAnimationFrame(() => {
|
|
49
|
+
if (!input)
|
|
50
|
+
return;
|
|
51
|
+
input.focus();
|
|
52
|
+
input.setSelectionRange(start + tag.length, start + tag.length);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
return (_jsxs("div", { ref: root, className: "builder-merge-tags", children: [_jsxs(MenuButton, { className: "builder-merge-tags__button", triggerLabel: "Insert a field of the form", label: "Insert field", items: () => [
|
|
56
|
+
...(fields.length > 0
|
|
57
|
+
? fields.map((field) => ({ label: field.title, keys: mergeTag(field.value), ownFocus: true, run: () => insert(mergeTag(field.value)) }))
|
|
58
|
+
: [{ label: 'The form has no fields yet', disabled: true }]),
|
|
59
|
+
'separator',
|
|
60
|
+
{ label: 'All answers, as a table', keys: ALL_ANSWERS_TAG, ownFocus: true, run: () => insert(ALL_ANSWERS_TAG) },
|
|
61
|
+
], children: [_jsx(Icon, { name: "plus", size: 12 }), "Insert field"] }), children] }));
|
|
62
|
+
}
|
|
@@ -24,5 +24,3 @@ export type ParentRow = {
|
|
|
24
24
|
export declare function arrayStateKey(path: string, parent: ParentRow | null): string;
|
|
25
25
|
/** A deep copy of a row with a new id, and new ids for the rows of its nested array fields. */
|
|
26
26
|
export declare function cloneRow(row: ArrayRow, fields: readonly unknown[], newId: () => string): ArrayRow;
|
|
27
|
-
/** "Item 01": Payload's fallback row label, from the singular label and the row number. */
|
|
28
|
-
export declare function fallbackRowLabel(singular: string, index: number): string;
|
|
@@ -85,7 +85,3 @@ export function cloneRow(row, fields, newId) {
|
|
|
85
85
|
renewNestedIds(copy, fields, newId);
|
|
86
86
|
return { ...copy, id: newId() };
|
|
87
87
|
}
|
|
88
|
-
/** "Item 01": Payload's fallback row label, from the singular label and the row number. */
|
|
89
|
-
export function fallbackRowLabel(singular, index) {
|
|
90
|
-
return `${singular} ${String(index + 1).padStart(2, '0')}`;
|
|
91
|
-
}
|