payload-canvas 0.5.2 → 0.6.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 +333 -28
- 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/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/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 +5 -1
- package/dist/react/server.js +19 -0
- package/package.json +5 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The fields of a panel region (`panel: true`, for example a form's settings), edited in the
|
|
4
|
+
// inspector with the same Payload inputs as block props. The region's `sections` fold (the first
|
|
5
|
+
// starts open); a group field in no section folds on its own. Each change saves to the document
|
|
6
|
+
// through the regions controller (one undo step per save). Typing waits for a short pause, or
|
|
7
|
+
// for the focus to leave the field, so a sentence is one save, not one per key. A change that
|
|
8
|
+
// shows a required field (choosing "Redirect" shows "Document to link to") waits until that field
|
|
9
|
+
// has a value, then both save together: Payload would refuse the first one alone.
|
|
10
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
11
|
+
import { setDocPath, valueAtDocPath } from '../../../core/regions.js';
|
|
12
|
+
import { FieldAccessFrame } from '../fields/access.js';
|
|
13
|
+
import { PanelSection } from '../fields/GroupField.js';
|
|
14
|
+
import { isFieldVisible, isRecord } from '../fields/values.js';
|
|
15
|
+
import { RenderBlockFields, undoKeysHandler } from '../renderField.js';
|
|
16
|
+
import { useRuntime } from '../runtime.js';
|
|
17
|
+
import { useValue } from '../valueStore.js';
|
|
18
|
+
import { missingRequired } from './required.js';
|
|
19
|
+
/** How long typing pauses before the change saves. */
|
|
20
|
+
const SAVE_DELAY_MS = 700;
|
|
21
|
+
const parentPath = (path) => path.split('.').slice(0, -1).join('.');
|
|
22
|
+
/** The values with the unsaved changes on top. */
|
|
23
|
+
function withChanges(values, changes) {
|
|
24
|
+
let data = values;
|
|
25
|
+
for (const [path, value] of Object.entries(changes)) {
|
|
26
|
+
const next = setDocPath(data, path, value);
|
|
27
|
+
if (next.ok)
|
|
28
|
+
data = next.value;
|
|
29
|
+
}
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
/** The required fields of the region that show and are empty in `data`. */
|
|
33
|
+
function emptyRequired(region, data) {
|
|
34
|
+
const parents = [...new Set(region.fields.map((f) => parentPath(f.path)))];
|
|
35
|
+
return parents.flatMap((parent) => {
|
|
36
|
+
const fields = region.fields.filter((f) => parentPath(f.path) === parent).map((f) => f.field);
|
|
37
|
+
return missingRequired(fields, parent ? valueAtDocPath(data, parent) : data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function RegionFields({ regions, region }) {
|
|
41
|
+
const runtime = useRuntime();
|
|
42
|
+
const state = useValue(regions.state);
|
|
43
|
+
// Changes not saved yet, by document path. They show at once; the save follows after a pause.
|
|
44
|
+
const [pending, setPending] = useState({});
|
|
45
|
+
const pendingRef = useRef(pending);
|
|
46
|
+
const timer = useRef(null);
|
|
47
|
+
// Required fields a change showed and that are still empty: the change waits for them.
|
|
48
|
+
const [waiting, setWaiting] = useState([]);
|
|
49
|
+
const valuesRef = useRef(state.values);
|
|
50
|
+
const flush = () => {
|
|
51
|
+
if (timer.current !== null)
|
|
52
|
+
window.clearTimeout(timer.current);
|
|
53
|
+
timer.current = null;
|
|
54
|
+
const changes = Object.entries(pendingRef.current);
|
|
55
|
+
if (changes.length === 0)
|
|
56
|
+
return;
|
|
57
|
+
const stored = valuesRef.current ?? {};
|
|
58
|
+
const before = new Set(emptyRequired(region, stored));
|
|
59
|
+
const missing = emptyRequired(region, withChanges(stored, pendingRef.current)).filter((label) => !before.has(label));
|
|
60
|
+
setWaiting(missing);
|
|
61
|
+
if (missing.length > 0)
|
|
62
|
+
return;
|
|
63
|
+
void regions.write(changes.map(([path, value]) => ({ path, value }))).finally(() => {
|
|
64
|
+
// Keep only what changed again while this save ran.
|
|
65
|
+
setPending((current) => Object.fromEntries(Object.entries(current).filter(([path, value]) => !changes.some(([p, v]) => p === path && v === value))));
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
// Leaving the panel (a block selected, the editor closed) saves what is left, or says why not.
|
|
69
|
+
const leave = useRef(() => { });
|
|
70
|
+
// The timer, the blur and the unmount read the latest values through these refs.
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
pendingRef.current = pending;
|
|
73
|
+
valuesRef.current = state.values;
|
|
74
|
+
leave.current = () => {
|
|
75
|
+
flush();
|
|
76
|
+
if (Object.keys(pendingRef.current).length > 0)
|
|
77
|
+
runtime.warn(`${region.label}: not saved. Fill in the required fields first.`);
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
useEffect(() => () => leave.current(), []);
|
|
81
|
+
if (state.status === 'loading' && !state.values)
|
|
82
|
+
return _jsx("p", { className: "builder-editor__hint", children: "Loading the fields\u2026" });
|
|
83
|
+
if (!state.values)
|
|
84
|
+
return null;
|
|
85
|
+
// The document values with the unsaved changes on top.
|
|
86
|
+
const data = withChanges(state.values, pending);
|
|
87
|
+
const change = (path, value) => {
|
|
88
|
+
setPending((current) => ({ ...current, [path]: value ?? null }));
|
|
89
|
+
pendingRef.current = { ...pendingRef.current, [path]: value ?? null };
|
|
90
|
+
if (timer.current !== null)
|
|
91
|
+
window.clearTimeout(timer.current);
|
|
92
|
+
timer.current = window.setTimeout(flush, SAVE_DELAY_MS);
|
|
93
|
+
};
|
|
94
|
+
// Fields that share a parent object see each other as siblings (conditions, defaults).
|
|
95
|
+
const scopeOf = (path) => region.fields.filter((f) => parentPath(f.path) === parentPath(path)).map((f) => f.field);
|
|
96
|
+
// A field of the region, with its access. `own`: a group in no section is a section of its own.
|
|
97
|
+
const renderField = (field, own = false) => {
|
|
98
|
+
const parent = parentPath(field.path);
|
|
99
|
+
const siblings = parent ? valueAtDocPath(data, parent) : data;
|
|
100
|
+
const name = field.path.split('.').at(-1);
|
|
101
|
+
const locked = regions.lockedMessage(field.path) !== null && state.access !== null;
|
|
102
|
+
const config = field.field;
|
|
103
|
+
const path = `region.${region.name}${parent ? `.${parent}` : ''}`;
|
|
104
|
+
if (own && config.type === 'group') {
|
|
105
|
+
const record = isRecord(siblings) ? siblings : {};
|
|
106
|
+
if (!isFieldVisible(config, record, scopeOf(field.path)))
|
|
107
|
+
return null;
|
|
108
|
+
const description = typeof config.admin?.description === 'string' ? config.admin.description : undefined;
|
|
109
|
+
return (_jsxs(PanelSection, { label: field.label, children: [description && _jsx("p", { className: "builder-field-group__description", children: description }), _jsx(FieldAccessFrame, { locked: locked, children: _jsx(RenderBlockFields, { fields: config.fields, data: record[name], path: `${path}.${name}`, onChange: (next) => change(field.path, next) }) })] }, field.path));
|
|
110
|
+
}
|
|
111
|
+
return (_jsx(FieldAccessFrame, { locked: locked, children: _jsx(RenderBlockFields, { fields: [config], scope: scopeOf(field.path), data: siblings, path: path, onChange: (next) => change(field.path, next?.[name]) }) }, field.path));
|
|
112
|
+
};
|
|
113
|
+
// Fields in no section show first; groups in no section come last, each folded on its own.
|
|
114
|
+
const inSection = new Set(region.sections?.flatMap((section) => section.fields) ?? []);
|
|
115
|
+
const loose = region.fields.filter((field) => !inSection.has(field.path));
|
|
116
|
+
const onBlur = (e) => {
|
|
117
|
+
if (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget))
|
|
118
|
+
return;
|
|
119
|
+
flush();
|
|
120
|
+
};
|
|
121
|
+
return (_jsxs("div", { className: "builder-editor__fields", onBlur: onBlur, onKeyDown: undoKeysHandler(runtime), children: [waiting.length > 0 && Object.keys(pending).length > 0 && (_jsxs("output", { className: "builder-editor__hint", children: ["Not saved yet. Fill in ", waiting.join(', '), " to save."] })), loose.filter((field) => field.field.type !== 'group').map((field) => renderField(field)), _jsxs("div", { className: "builder-panel-sections", children: [region.sections?.map((section, index) => (_jsx(PanelSection, { label: section.label, open: index === 0, children: region.fields.filter((field) => section.fields.includes(field.path)).map((field) => renderField(field)) }, section.label))), loose.filter((field) => field.field.type === 'group').map((field) => renderField(field, true))] })] }));
|
|
122
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
// The inspector for a selected page region: what it is, its fields, and the way to edit them.
|
|
4
4
|
// The fields are edited with Payload's own form in the settings drawer (every field type, with
|
|
5
5
|
// Payload's validation and access) and, for text and images, on the canvas.
|
|
6
|
+
import { FormSourceNote } from '../fields/FormBlock.js';
|
|
6
7
|
import { Button } from '@payloadcms/ui';
|
|
7
8
|
import { regionAccessAt, regionFieldOf } from '../../../core/regions.js';
|
|
8
9
|
import { Icon } from '../icons.js';
|
|
9
10
|
import { useRuntime } from '../runtime.js';
|
|
10
11
|
import { useValue } from '../valueStore.js';
|
|
11
12
|
import { editRegionFields } from './RegionOverlay.js';
|
|
13
|
+
import { RegionFields } from './RegionFields.js';
|
|
12
14
|
export function RegionPane({ regions, name }) {
|
|
13
15
|
const runtime = useRuntime();
|
|
14
16
|
const state = useValue(regions.state);
|
|
@@ -18,9 +20,9 @@ export function RegionPane({ regions, name }) {
|
|
|
18
20
|
return null;
|
|
19
21
|
const problems = allProblems.filter((p) => p.path && regionFieldOf([region], p.path));
|
|
20
22
|
const drafts = runtime.doc.meta.get().drafts;
|
|
21
|
-
return (_jsxs("div", { className: "builder-editor__block-pane", children: [_jsxs("div", { className: "builder-editor__block-head", children: [_jsx("span", { className: "builder-editor__block-icon", children: _jsx(Icon, { name:
|
|
23
|
+
return (_jsxs("div", { className: "builder-editor__block-pane", children: [_jsxs("div", { className: "builder-editor__block-head", children: [_jsx("span", { className: "builder-editor__block-icon", children: _jsx(Icon, { name: region.panel ? 'rename' : 'lock', size: 16 }) }), _jsxs("span", { className: "builder-editor__block-name", children: [_jsx("span", { className: "builder-editor__block-title", children: region.label }), _jsx("span", { className: "builder-editor__block-sub", children: region.panel ? (drafts ? 'Changes save as a draft' : 'Changes save as you type') : 'Fixed part of the page' })] })] }), region.panel ? _jsx(FormSourceNote, {}) : null, problems.length > 0 && (_jsxs("div", { className: "builder-editor__block-problems", role: "alert", children: [_jsx(Icon, { name: "warning", size: 14 }), _jsxs("div", { children: [_jsx("p", { className: "builder-editor__block-problems-title", children: "Fix this to publish" }), _jsx("ul", { children: problems.map((p) => (_jsx("li", { children: p.message }, p.message))) })] })] })), region.panel ? (_jsxs(_Fragment, { children: [state.status === 'error' && (_jsx("p", { className: "builder-editor__hint", role: "alert", children: state.error })), _jsx(RegionFields, { regions: regions, region: region })] })) : (_jsxs("div", { className: "builder-editor__fields", children: [_jsxs("p", { className: "builder-editor__hint", children: ["It shows fields of this document, outside the layout. Double-click its text or images on the canvas to edit them. Changes save to the document", drafts ? ' as a draft, and go live when you publish' : '', "."] }), state.status === 'error' && (_jsx("p", { className: "builder-editor__hint", role: "alert", children: state.error })), region.fields.length > 0 ? (_jsx("ul", { className: "builder-region__fields", children: region.fields.map((field) => {
|
|
22
24
|
const right = state.access ? regionAccessAt(state.access, field.path) : null;
|
|
23
25
|
const locked = right !== null && !right.update;
|
|
24
26
|
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "builder-editor__menu-item", onClick: () => runtime.doc.openSettings({ path: field.path, tabs: field.tabs }), "data-tooltip": locked ? 'You may not change this field' : 'Edit in the settings', children: [_jsx(Icon, { name: locked ? 'lock' : 'rename', size: 14 }), field.label] }) }, field.path));
|
|
25
|
-
}) })) : (_jsx("p", { className: "builder-editor__hint", children: "It has no fields to edit." })), _jsx(Button, { buttonStyle: "secondary", size: "small", margin: false, onClick: () => editRegionFields(runtime, regions, region.name), children: "Edit fields in the settings" })] })] }));
|
|
27
|
+
}) })) : (_jsx("p", { className: "builder-editor__hint", children: "It has no fields to edit." })), _jsx(Button, { buttonStyle: "secondary", size: "small", margin: false, onClick: () => editRegionFields(runtime, regions, region.name), children: "Edit fields in the settings" })] }))] }));
|
|
26
28
|
}
|
|
@@ -12,12 +12,12 @@ export function RegionRows() {
|
|
|
12
12
|
const hovered = useOptionalValue(regions?.hovered ?? null);
|
|
13
13
|
if (!regions || regions.config.length === 0)
|
|
14
14
|
return null;
|
|
15
|
-
return (_jsx("section", { className: "builder-region__rows", "aria-label":
|
|
15
|
+
return (_jsx("section", { className: "builder-region__rows", "aria-label": regions.config.every((r) => r.panel) ? 'Settings' : 'Fixed parts of the page', children: regions.config.map((region) => (_jsxs("button", { type: "button", className: [
|
|
16
16
|
'builder-editor__row',
|
|
17
17
|
'builder-region__row',
|
|
18
18
|
selected === region.name && 'builder-editor__row--selected',
|
|
19
19
|
hovered === region.name && selected !== region.name && 'builder-editor__row--hovered',
|
|
20
20
|
]
|
|
21
21
|
.filter(Boolean)
|
|
22
|
-
.join(' '), "aria-pressed": selected === region.name, "data-tooltip":
|
|
22
|
+
.join(' '), "aria-pressed": selected === region.name, "data-tooltip": region.panel ? 'Settings of this document' : 'A fixed part of the page: its fields, not blocks', "data-tooltip-side": "right", onClick: () => regions.selected.set(region.name), onPointerEnter: () => regions.hovered.set(region.name), onPointerLeave: () => regions.hovered.set(null), children: [_jsx("span", { className: "builder-editor__row-icon", children: _jsx(Icon, { name: region.panel ? 'rename' : 'lock', size: 14 }) }), _jsx("span", { className: "builder-editor__row-type", children: region.label }), _jsx("span", { className: "builder-editor__row-text", children: region.panel ? 'Settings' : 'Fixed' })] }, region.name))) }));
|
|
23
23
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FieldShape } from '../fields/values.js';
|
|
2
|
+
type LooseField = FieldShape & {
|
|
3
|
+
required?: boolean;
|
|
4
|
+
label?: unknown;
|
|
5
|
+
fields?: LooseField[];
|
|
6
|
+
tabs?: Array<{
|
|
7
|
+
name?: string;
|
|
8
|
+
fields: LooseField[];
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The labels of the required fields that show and have no value. `scope`: every field that
|
|
13
|
+
* shares `data` (conditions read sibling defaults from it). Arrays are checked row by row.
|
|
14
|
+
*/
|
|
15
|
+
export declare function missingRequired(fields: readonly LooseField[], data: unknown, scope?: readonly LooseField[]): string[];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Pure: which required fields are empty while their conditions show them. The settings panel of a
|
|
2
|
+
// panel region (RegionFields) holds a change back until they are filled, because Payload refuses
|
|
3
|
+
// the save otherwise: choosing "Redirect" shows a required "Document to link to".
|
|
4
|
+
import { textOf } from '../../../core/fields.js';
|
|
5
|
+
import { isEmptyValue, isFieldVisible, isRecord } from '../fields/values.js';
|
|
6
|
+
const words = (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/^./, (c) => c.toUpperCase());
|
|
7
|
+
/**
|
|
8
|
+
* The labels of the required fields that show and have no value. `scope`: every field that
|
|
9
|
+
* shares `data` (conditions read sibling defaults from it). Arrays are checked row by row.
|
|
10
|
+
*/
|
|
11
|
+
export function missingRequired(fields, data, scope = fields) {
|
|
12
|
+
const record = isRecord(data) ? data : {};
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const field of fields) {
|
|
15
|
+
if (!isFieldVisible(field, record, scope))
|
|
16
|
+
continue;
|
|
17
|
+
if (field.type === 'row' || field.type === 'collapsible' || (field.type === 'group' && !field.name)) {
|
|
18
|
+
out.push(...missingRequired(field.fields ?? [], record, scope));
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (field.type === 'tabs') {
|
|
22
|
+
for (const tab of field.tabs ?? [])
|
|
23
|
+
out.push(...(tab.name ? missingRequired(tab.fields, record[tab.name]) : missingRequired(tab.fields, record, scope)));
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (!field.name)
|
|
27
|
+
continue;
|
|
28
|
+
const value = record[field.name];
|
|
29
|
+
if (field.type === 'group') {
|
|
30
|
+
out.push(...missingRequired(field.fields ?? [], value));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (field.type === 'array' && Array.isArray(value)) {
|
|
34
|
+
for (const row of value)
|
|
35
|
+
out.push(...missingRequired(field.fields ?? [], row));
|
|
36
|
+
}
|
|
37
|
+
// A missing value gets the field's default when Payload saves; a cleared one stays empty.
|
|
38
|
+
const effective = value === undefined ? field.defaultValue : value;
|
|
39
|
+
if (field.required && field.type !== 'checkbox' && isEmptyValue(effective))
|
|
40
|
+
out.push(textOf(field.label) ?? words(field.name));
|
|
41
|
+
}
|
|
42
|
+
return [...new Set(out)];
|
|
43
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type KeyboardEvent } from 'react';
|
|
1
2
|
import type { Field } from 'payload';
|
|
2
3
|
import type { Block } from '../../core/types.js';
|
|
4
|
+
import { useRuntime } from './runtime.js';
|
|
3
5
|
import './fields/fields.scss';
|
|
4
6
|
type Props = {
|
|
5
7
|
readonly field: Field;
|
|
@@ -37,10 +39,15 @@ type FieldsProps = {
|
|
|
37
39
|
/**
|
|
38
40
|
* Renders a list of fields against one object. Handles `admin.custom.builderCondition`, hidden
|
|
39
41
|
* fields, and layout-only fields (row, collapsible, unnamed group, unnamed tabs) that share
|
|
40
|
-
* the parent's data. Collapsibles
|
|
41
|
-
* Named tabs render as groups.
|
|
42
|
+
* the parent's data. Collapsibles get a small heading; a tabs field with several tabs gets a tab
|
|
43
|
+
* strip (`FieldTabs`). Named tabs render as groups.
|
|
42
44
|
*/
|
|
43
45
|
export declare function RenderBlockFields({ fields, data, path, onChange, scope }: FieldsProps): import("react").JSX.Element;
|
|
46
|
+
/**
|
|
47
|
+
* Ctrl+Z / Ctrl+Shift+Z (Cmd on a Mac) and Ctrl+Y in an inspector text input run the editor's undo
|
|
48
|
+
* and redo, not the browser's text undo. Put it on the element around the inputs (`onKeyDown`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function undoKeysHandler(runtime: ReturnType<typeof useRuntime>): (e: KeyboardEvent<HTMLDivElement>) => void;
|
|
44
51
|
/**
|
|
45
52
|
* The Content tab of the block inspector: every field of the selected block, with conditions.
|
|
46
53
|
* Each changed prop becomes one `update` operation.
|
|
@@ -6,7 +6,7 @@ import { getBlockDefinition, hasStaticDefault } from '../../core/index.js';
|
|
|
6
6
|
import { ArrayField } from './fields/ArrayField.js';
|
|
7
7
|
import { isStructuralChange } from './fields/arrayState.js';
|
|
8
8
|
import { CheckedTextField, NumberField } from './fields/CheckedInputs.js';
|
|
9
|
-
import { FieldSection, GroupField } from './fields/GroupField.js';
|
|
9
|
+
import { FieldSection, FieldTabs, GroupField, PanelSection } from './fields/GroupField.js';
|
|
10
10
|
import { JsonField } from './fields/JsonField.js';
|
|
11
11
|
import { QueryFiltersField } from './fields/QueryFiltersField.js';
|
|
12
12
|
import { ListWhereField } from './fields/ListWhereField.js';
|
|
@@ -14,6 +14,11 @@ import { ManyValuesField } from './fields/ManyValuesField.js';
|
|
|
14
14
|
import { PointField } from './fields/PointField.js';
|
|
15
15
|
import { RelatedField } from './fields/RelatedField.js';
|
|
16
16
|
import { RichTextField } from './fields/RichTextField.js';
|
|
17
|
+
import { FormFieldNameField } from './fields/FormFieldName.js';
|
|
18
|
+
import { MergeTagsFrame } from './fields/MergeTags.js';
|
|
19
|
+
import { FIELD_NAME_MARKER, FieldNameNote, FormBlockActions } from './fields/FormBlock.js';
|
|
20
|
+
import { FORM_ACTIONS_MARKER, PANEL_SECTION_MARKER, PLAIN_GROUP_MARKER } from '../../forms/pageForms.js';
|
|
21
|
+
import { MERGE_TAGS_MARKER } from '../../forms/fieldConfigs.js';
|
|
17
22
|
import { SortField } from './fields/SortField.js';
|
|
18
23
|
import { fieldMergeKey } from './fields/undoPath.js';
|
|
19
24
|
import { asId, formatProblem, fromRelationshipInput, isFieldVisible, isRecord, toRelationshipInput } from './fields/values.js';
|
|
@@ -53,8 +58,15 @@ export function fieldLabel(field) {
|
|
|
53
58
|
function fieldDescription(field) {
|
|
54
59
|
return text(field.admin?.description);
|
|
55
60
|
}
|
|
61
|
+
/** Words from an option value, for options whose label was a function (it does not reach the admin). */
|
|
62
|
+
const valueWords = (value) => value.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
56
63
|
function toOptions(options) {
|
|
57
|
-
return options.map((o) =>
|
|
64
|
+
return options.map((o) => {
|
|
65
|
+
if (typeof o === 'string')
|
|
66
|
+
return { label: o, value: o };
|
|
67
|
+
const option = o;
|
|
68
|
+
return option.label === undefined || option.label === null ? { ...option, label: valueWords(String(option.value)) } : option;
|
|
69
|
+
});
|
|
58
70
|
}
|
|
59
71
|
function asString(value) {
|
|
60
72
|
return typeof value === 'string' ? value : typeof value === 'number' ? String(value) : '';
|
|
@@ -87,6 +99,10 @@ export function RenderBlockField({ field, onChange, path, value, siblings, onSib
|
|
|
87
99
|
switch (field.type) {
|
|
88
100
|
case 'text':
|
|
89
101
|
case 'email': {
|
|
102
|
+
// `admin.custom.builderFormField`: the name of another field of the same form (display conditions).
|
|
103
|
+
if (field.admin?.custom?.builderFormField) {
|
|
104
|
+
return _jsx(FormFieldNameField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value });
|
|
105
|
+
}
|
|
90
106
|
if (field.type === 'text' && field.hasMany) {
|
|
91
107
|
return _jsx(ManyValuesField, { description: description, kind: "text", label: label, onChange: onChange, path: path, required: required, value: value });
|
|
92
108
|
}
|
|
@@ -175,7 +191,7 @@ export function RenderBlockField({ field, onChange, path, value, siblings, onSib
|
|
|
175
191
|
case 'richText':
|
|
176
192
|
return _jsx(RichTextField, { label: label, onChange: onChange, path: path, value: value });
|
|
177
193
|
case 'group':
|
|
178
|
-
return _jsx(GroupField, { fields: field.fields, label: label, description: description, onChange: onChange, path: path, value: value });
|
|
194
|
+
return (_jsx(GroupField, { fields: field.fields, label: label, description: description, plain: field.admin?.custom?.[PLAIN_GROUP_MARKER] === true, onChange: onChange, path: path, value: value }));
|
|
179
195
|
case 'array':
|
|
180
196
|
return (_jsx(ArrayField, { description: description, fields: field.fields, label: label, maxRows: field.maxRows, onChange: onChange, path: path, singular: text(field.labels?.singular), value: value }));
|
|
181
197
|
default:
|
|
@@ -185,8 +201,8 @@ export function RenderBlockField({ field, onChange, path, value, siblings, onSib
|
|
|
185
201
|
/**
|
|
186
202
|
* Renders a list of fields against one object. Handles `admin.custom.builderCondition`, hidden
|
|
187
203
|
* fields, and layout-only fields (row, collapsible, unnamed group, unnamed tabs) that share
|
|
188
|
-
* the parent's data. Collapsibles
|
|
189
|
-
* Named tabs render as groups.
|
|
204
|
+
* the parent's data. Collapsibles get a small heading; a tabs field with several tabs gets a tab
|
|
205
|
+
* strip (`FieldTabs`). Named tabs render as groups.
|
|
190
206
|
*/
|
|
191
207
|
export function RenderBlockFields({ fields, data, path, onChange, scope = fields }) {
|
|
192
208
|
const record = isRecord(data) ? data : {};
|
|
@@ -217,15 +233,28 @@ export function RenderBlockFields({ fields, data, path, onChange, scope = fields
|
|
|
217
233
|
onChange(Object.keys(next).length > 0 ? next : undefined);
|
|
218
234
|
};
|
|
219
235
|
const out = [];
|
|
236
|
+
// Indexes in `out` of settings panel sections: neighbours share one box (see the end).
|
|
237
|
+
const panelSections = new Set();
|
|
220
238
|
fields.forEach((field, index) => {
|
|
221
239
|
if (!isFieldVisible(field, record, scope))
|
|
222
240
|
return;
|
|
241
|
+
// `admin.custom.builderFormActions`: the Form block's "Edit form" and "Move into this page".
|
|
242
|
+
if (field.type === 'ui' && field.admin?.custom?.[FORM_ACTIONS_MARKER]) {
|
|
243
|
+
out.push(_jsx(FormBlockActions, { path: `${path}.${field.name}` }, `ui-${index}`));
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
223
246
|
if (field.type === 'ui' || field.type === 'join')
|
|
224
247
|
return;
|
|
225
248
|
if (field.type === 'collapsible') {
|
|
226
249
|
const shared = _jsx(RenderBlockFields, { fields: field.fields, data: record, path: path, onChange: onChange, scope: scope });
|
|
227
250
|
const title = text(field.label);
|
|
228
251
|
const folded = field.admin?.initCollapsed === true;
|
|
252
|
+
// A settings panel section (the Form block's General, Mail, …): the form builder's look.
|
|
253
|
+
if (title && field.admin?.custom?.[PANEL_SECTION_MARKER]) {
|
|
254
|
+
panelSections.add(out.length);
|
|
255
|
+
out.push(_jsx(PanelSection, { label: title, open: !folded, children: shared }, `layout-${index}`));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
229
258
|
out.push(title ? (_jsx(FieldSection, { label: title, description: folded ? text(field.admin?.description) : undefined, collapsed: folded ? true : undefined, children: shared }, `layout-${index}`)) : (_jsx(Fragment, { children: shared }, `layout-${index}`)));
|
|
230
259
|
return;
|
|
231
260
|
}
|
|
@@ -234,22 +263,24 @@ export function RenderBlockFields({ fields, data, path, onChange, scope = fields
|
|
|
234
263
|
return;
|
|
235
264
|
}
|
|
236
265
|
if (field.type === 'tabs') {
|
|
237
|
-
//
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
const key = `tab-${index}-${tabIndex}`;
|
|
266
|
+
// One tab shows its fields as they are; several get a tab strip.
|
|
267
|
+
const renderTab = (tabIndex, key) => {
|
|
268
|
+
const tab = field.tabs[tabIndex];
|
|
241
269
|
if ('name' in tab && tab.name) {
|
|
242
270
|
const name = tab.name;
|
|
243
271
|
const tabAccess = accessOf(`${path}.${name}`);
|
|
244
272
|
if (!tabAccess.read)
|
|
245
|
-
return;
|
|
246
|
-
|
|
247
|
-
return;
|
|
273
|
+
return null;
|
|
274
|
+
return (_jsx(FieldAccessFrame, { locked: !tabAccess.update, children: _jsx(GroupField, { fields: tab.fields, label: text(tab.label) ?? name, onChange: (value) => setField(name, value), path: `${path}.${name}`, value: record[name] }) }, key));
|
|
248
275
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
276
|
+
return _jsx(RenderBlockFields, { fields: tab.fields, data: record, path: path, onChange: onChange, scope: scope }, key);
|
|
277
|
+
};
|
|
278
|
+
if (field.tabs.length === 1) {
|
|
279
|
+
out.push(renderTab(0, `tab-${index}-0`));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const labels = field.tabs.map((tab, tabIndex) => text(tab.label) ?? ('name' in tab && tab.name ? tab.name : `Tab ${tabIndex + 1}`));
|
|
283
|
+
out.push(_jsx(FieldTabs, { labels: labels, path: `${path}.tabs-${index}`, render: (tabIndex) => renderTab(tabIndex, `tab-${index}-${tabIndex}`) }, `tabs-${index}`));
|
|
253
284
|
return;
|
|
254
285
|
}
|
|
255
286
|
if (!('name' in field) || !field.name)
|
|
@@ -265,14 +296,50 @@ export function RenderBlockFields({ fields, data, path, onChange, scope = fields
|
|
|
265
296
|
if (heading) {
|
|
266
297
|
out.push(_jsx("h4", { className: "builder-field-heading", children: heading }, `heading-${name}`));
|
|
267
298
|
}
|
|
268
|
-
out.push(_jsxs("div", { "data-builder-field": fieldPath, style: { display: 'contents' }, children: [_jsx(FieldAccessFrame, { locked: !access.update, children: _jsx(LocaleFieldFrame, { path: fieldPath, name: name, children: _jsx(FieldSlot, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, label: fieldLabel(field), children: _jsx(RenderBlockField, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, siblings: record, onSiblingsChange: setFields }) }) }) }), _jsx(PeerFieldNote, { fieldPath: fieldPath }), _jsx(FieldProblem, { path: fieldPath })] }, name));
|
|
299
|
+
out.push(_jsxs("div", { "data-builder-field": fieldPath, style: { display: 'contents' }, children: [_jsx(FieldAccessFrame, { locked: !access.update, children: _jsx(LocaleFieldFrame, { path: fieldPath, name: name, children: _jsx(FieldSlot, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, label: fieldLabel(field), children: field.admin?.custom?.[FIELD_NAME_MARKER] ? (_jsx(FieldNameNote, { path: fieldPath, value: record[name], children: _jsx(RenderBlockField, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, siblings: record, onSiblingsChange: setFields }) })) : field.admin?.custom?.[MERGE_TAGS_MARKER] ? (_jsx(MergeTagsFrame, { value: record[name], onChange: onFieldChange, children: _jsx(RenderBlockField, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, siblings: record, onSiblingsChange: setFields }) })) : (_jsx(RenderBlockField, { field: field, path: fieldPath, value: record[name], onChange: onFieldChange, siblings: record, onSiblingsChange: setFields })) }) }) }), _jsx(PeerFieldNote, { fieldPath: fieldPath }), _jsx(FieldProblem, { path: fieldPath })] }, name));
|
|
300
|
+
});
|
|
301
|
+
if (panelSections.size === 0)
|
|
302
|
+
return _jsx(_Fragment, { children: out });
|
|
303
|
+
// One box per run of panel sections, so they touch: one border between rows, no gap.
|
|
304
|
+
const grouped = [];
|
|
305
|
+
out.forEach((node, i) => {
|
|
306
|
+
if (!panelSections.has(i)) {
|
|
307
|
+
grouped.push(node);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (panelSections.has(i - 1))
|
|
311
|
+
return;
|
|
312
|
+
const run = [];
|
|
313
|
+
for (let j = i; panelSections.has(j); j++)
|
|
314
|
+
run.push(out[j]);
|
|
315
|
+
grouped.push(_jsx("div", { className: "builder-panel-sections", children: run }, `panel-sections-${i}`));
|
|
269
316
|
});
|
|
270
|
-
return _jsx(_Fragment, { children:
|
|
317
|
+
return _jsx(_Fragment, { children: grouped });
|
|
271
318
|
}
|
|
272
319
|
/** The inspector field path (`data-builder-field`) of the field around `node`, or null. */
|
|
273
320
|
const fieldAt = (node) => node instanceof Element ? (node.closest('[data-builder-field]')?.dataset.builderField ?? null) : null;
|
|
274
321
|
/** Text inputs whose native undo the editor replaces with its own (see `onUndoKeys`). */
|
|
275
322
|
const TEXT_INPUT = 'textarea, input:not([type]), input[type="text"], input[type="search"], input[type="email"], input[type="url"], input[type="number"], input[type="tel"]';
|
|
323
|
+
/**
|
|
324
|
+
* Ctrl+Z / Ctrl+Shift+Z (Cmd on a Mac) and Ctrl+Y in an inspector text input run the editor's undo
|
|
325
|
+
* and redo, not the browser's text undo. Put it on the element around the inputs (`onKeyDown`).
|
|
326
|
+
*/
|
|
327
|
+
export function undoKeysHandler(runtime) {
|
|
328
|
+
return (e) => {
|
|
329
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
330
|
+
if (!mod || e.altKey || !(e.target instanceof Element) || !e.target.matches(TEXT_INPUT))
|
|
331
|
+
return;
|
|
332
|
+
const key = e.key.toLowerCase();
|
|
333
|
+
const action = key === 'z' ? (e.shiftKey ? 'redo' : 'undo') : key === 'y' && !e.shiftKey ? 'redo' : null;
|
|
334
|
+
if (!action)
|
|
335
|
+
return;
|
|
336
|
+
e.preventDefault();
|
|
337
|
+
if (action === 'undo')
|
|
338
|
+
runtime.store.undo();
|
|
339
|
+
else
|
|
340
|
+
runtime.store.redo();
|
|
341
|
+
};
|
|
342
|
+
}
|
|
276
343
|
/**
|
|
277
344
|
* The Content tab of the block inspector: every field of the selected block, with conditions.
|
|
278
345
|
* Each changed prop becomes one `update` operation.
|
|
@@ -328,20 +395,7 @@ export function BlockContentFields({ block }) {
|
|
|
328
395
|
if (!(e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)))
|
|
329
396
|
field.set(null);
|
|
330
397
|
};
|
|
331
|
-
const onUndoKeys = (
|
|
332
|
-
const mod = e.ctrlKey || e.metaKey;
|
|
333
|
-
if (!mod || e.altKey || !(e.target instanceof Element) || !e.target.matches(TEXT_INPUT))
|
|
334
|
-
return;
|
|
335
|
-
const key = e.key.toLowerCase();
|
|
336
|
-
const action = key === 'z' ? (e.shiftKey ? 'redo' : 'undo') : key === 'y' && !e.shiftKey ? 'redo' : null;
|
|
337
|
-
if (!action)
|
|
338
|
-
return;
|
|
339
|
-
e.preventDefault();
|
|
340
|
-
if (action === 'undo')
|
|
341
|
-
runtime.store.undo();
|
|
342
|
-
else
|
|
343
|
-
runtime.store.redo();
|
|
344
|
-
};
|
|
398
|
+
const onUndoKeys = undoKeysHandler(runtime);
|
|
345
399
|
const fieldList = (_jsx(FieldProblemsProvider, { block: block, children: _jsx(LocaleFieldsProvider, { block: block, children: _jsxs(FieldAccessProvider, { block: block, prefix: `builder.${block.id}.`, children: [_jsx(RenderBlockFields, { fields: fields, scope: def.fields, data: props, path: `builder.${block.id}`, onChange: handleChange }), _jsx(HiddenFieldsNote, { block: block })] }) }) }));
|
|
346
400
|
return (_jsx("div", { className: "builder-editor__fields", onFocus: onFocus, onBlur: onBlur, onKeyDown: onUndoKeys, children: contentMode ? (fieldList) : (_jsxs(BindingScopeProvider, { block: block, prefix: `builder.${block.id}.`, children: [fieldList, _jsx(VisibilityField, { block: block })] })) }));
|
|
347
401
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RefObject } from 'react';
|
|
2
|
-
import type { Block, BuilderClientConfig, CanvasMeasurement, DragSource, DropTarget, Point, Rect } from '../../core/types.js';
|
|
2
|
+
import type { Block, BuilderClientConfig, CanvasMeasurement, DragSource, DropTarget, Point, Position, Rect } from '../../core/types.js';
|
|
3
3
|
import type { BuilderDocMeta } from '../../live/types.js';
|
|
4
4
|
import { type AdminToCanvas, type CanvasInit, type KeyAction } from '../../protocol/index.js';
|
|
5
5
|
import { type AssistantController } from './assistant/controller.js';
|
|
@@ -132,7 +132,8 @@ export type Runtime = {
|
|
|
132
132
|
blockLabel: (type: string) => string;
|
|
133
133
|
/** Icon name of a block type: the definition's `icon`, else the type itself. */
|
|
134
134
|
blockIcon: (type: string) => string;
|
|
135
|
-
|
|
135
|
+
/** A new block of `type` as the editor adds it. `to`: where it goes, for the scope of its unique props. */
|
|
136
|
+
createBlock: (type: string, to?: Pick<Position, 'parentId'>) => Block | null;
|
|
136
137
|
};
|
|
137
138
|
/**
|
|
138
139
|
* `api` is Payload's REST route (`config.routes.api`), used by the iframe to load documents.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { createContext, createRef, use } from 'react';
|
|
3
|
-
import { canvasDropTarget, createId, EMPTY_LAYOUT, findBlock, getBlockDefinition,
|
|
3
|
+
import { canvasDropTarget, createId, EMPTY_LAYOUT, findBlock, getBlockDefinition, newBlockOf, outlineDropTarget, uniquePropValuesAt, withUniqueProps, } from '../../core/index.js';
|
|
4
4
|
import { post, rectContains } from '../../protocol/index.js';
|
|
5
5
|
import { contentModeProblem } from '../../core/contentMode.js';
|
|
6
6
|
import { removeBlock } from './actions.js';
|
|
@@ -184,23 +184,16 @@ export function createRuntime(config, api, document, options = {}) {
|
|
|
184
184
|
warn: (text) => notice.set({ text, at: Date.now(), tone: 'warning' }),
|
|
185
185
|
blockLabel,
|
|
186
186
|
blockIcon: (type) => getBlockDefinition(config.blocks, type)?.icon ?? type,
|
|
187
|
-
createBlock(type) {
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
createBlock(type, to) {
|
|
188
|
+
// A Payload blocks field stores classes only for blocks that have class keys (form fields).
|
|
189
|
+
const classes = config.storage !== 'payload-blocks' || Boolean(getBlockDefinition(config.blocks, type)?.payload?.classKeys?.className);
|
|
190
|
+
const block = newBlockOf(config.blocks, type, createId, { classes });
|
|
191
|
+
if (!block)
|
|
190
192
|
return null;
|
|
191
|
-
// A Payload blocks field stores no classes: a new block there starts without them.
|
|
192
|
-
const block = config.storage === 'payload-blocks' ? { id: createId(), type } : withDefaultClasses({ id: createId(), type }, def);
|
|
193
|
-
// Field defaults that are plain data, inside groups, rows and tabs too (function defaults
|
|
194
|
-
// were stripped from the client config). From now on the block stores its own values.
|
|
195
|
-
const props = withFieldDefaults({}, def.fields);
|
|
196
|
-
if (Object.keys(props).length > 0)
|
|
197
|
-
block.props = props;
|
|
198
|
-
// A new list starts with one list item (see `starterSlots`).
|
|
199
|
-
const slots = starterSlots(config.blocks, type, createId);
|
|
200
|
-
if (slots)
|
|
201
|
-
block.slots = slots;
|
|
202
193
|
// No empty slot arrays: layouts are canonical. The canvas still shows placeholders for declared slots.
|
|
203
|
-
|
|
194
|
+
// Props that must stay unique (a form field name) get a free value in the scope they go to: `text2` next to `text`.
|
|
195
|
+
const { layout } = store.getState();
|
|
196
|
+
return withUniqueProps(block, config.blocks, uniquePropValuesAt(layout, to?.parentId ?? null, config.blocks));
|
|
204
197
|
},
|
|
205
198
|
};
|
|
206
199
|
store.onWarning((text) => runtime.warn(text));
|
|
@@ -319,13 +312,14 @@ export function computeDrop(runtime, p, source) {
|
|
|
319
312
|
const { layout } = runtime.store.getState();
|
|
320
313
|
const { blocks } = runtime.config;
|
|
321
314
|
const outline = runtime.outlineRef.current;
|
|
322
|
-
|
|
315
|
+
const area = outline ? toRect(outline.getBoundingClientRect()) : null;
|
|
316
|
+
if (outline && area && rectContains(area, p.x, p.y)) {
|
|
323
317
|
const rows = Array.from(outline.querySelectorAll('[data-outline-row]'), (el) => ({
|
|
324
318
|
id: el.dataset.outlineRow ?? '',
|
|
325
319
|
rect: toRect(el.getBoundingClientRect()),
|
|
326
320
|
depth: Number(el.dataset.depth ?? 0),
|
|
327
321
|
}));
|
|
328
|
-
return { zone: 'outline', target: outlineDropTarget(layout, blocks, rows, p, source, OUTLINE_INDENT) };
|
|
322
|
+
return { zone: 'outline', target: outlineDropTarget(layout, blocks, rows, p, source, OUTLINE_INDENT, area) };
|
|
329
323
|
}
|
|
330
324
|
const iframe = runtime.iframeRef.current;
|
|
331
325
|
const measurement = runtime.measurement.get();
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
// edited, its other classes and custom CSS.
|
|
6
6
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
import { bareClass, classTokens, mergeSiteClasses } from '../../../classes/shared.js';
|
|
8
|
-
import { STYLE_PROPERTIES } from '../../../core/index.js';
|
|
8
|
+
import { partClassNameOf, STYLE_PROPERTIES } from '../../../core/index.js';
|
|
9
9
|
import { ClassManager } from '../classes/ClassManager.js';
|
|
10
10
|
import { useRuntime } from '../runtime.js';
|
|
11
11
|
import { useEditor } from '../store.js';
|
|
@@ -48,7 +48,9 @@ export function StylesPanel({ block, part = null }) {
|
|
|
48
48
|
const frame = useValue(runtime.frame);
|
|
49
49
|
const widths = useMemo(() => breakpointWidths(tokens), [tokens]);
|
|
50
50
|
const canvasBreakpoint = frame.width > 0 ? breakpointAt(widths, frame.width) : 'base';
|
|
51
|
-
|
|
51
|
+
// A part without classes of its own shows the classes it inherits (a field's input: its form's inputs).
|
|
52
|
+
const inherited = useEditor(runtime.store, (s) => (part && !block.partClassName?.[part] ? partClassNameOf(s.layout, block.id, part, runtime.config.blocks) : ''));
|
|
53
|
+
const blockClassName = (part ? block.partClassName?.[part] || inherited : block.className) ?? '';
|
|
52
54
|
const own = useMemo(() => classesOn(blockClassName, classList), [blockClassName, classList]);
|
|
53
55
|
// The class the controls edit: only one this block (or part) uses.
|
|
54
56
|
const editing = targetId === null ? null : (own.find((c) => String(c.id) === String(targetId)) ?? null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { createContext, use } from 'react';
|
|
3
|
-
import { findBlock, setStyleValue } from '../../../core/index.js';
|
|
3
|
+
import { findBlock, partClassNameOf, setStyleValue } from '../../../core/index.js';
|
|
4
4
|
import { variantKey } from './model.js';
|
|
5
5
|
export const StylesContext = createContext(null);
|
|
6
6
|
export function useStyles() {
|
|
@@ -9,10 +9,15 @@ export function useStyles() {
|
|
|
9
9
|
throw new Error('useStyles must be used inside the Styles panel');
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Reads the latest classes from the store, so two edits in one frame never overwrite each other.
|
|
14
|
+
* A part without classes of its own starts from the classes it inherits (a field's label from its form's).
|
|
15
|
+
*/
|
|
13
16
|
function currentClassName(runtime, { blockId, part }) {
|
|
14
|
-
const
|
|
15
|
-
|
|
17
|
+
const { layout } = runtime.store.getState();
|
|
18
|
+
if (part)
|
|
19
|
+
return partClassNameOf(layout, blockId, part, runtime.config.blocks);
|
|
20
|
+
return findBlock(layout, blockId)?.className ?? '';
|
|
16
21
|
}
|
|
17
22
|
export function writeClassName(runtime, target, next, mergeKey) {
|
|
18
23
|
// One space between classes: double spaces from typing never reach the stored value.
|
|
@@ -22,5 +22,5 @@ export function PreviewAsClientToggle() {
|
|
|
22
22
|
if (!runtime.canEditDesign)
|
|
23
23
|
return null;
|
|
24
24
|
const tip = on ? 'Back to full editing' : 'Edit as a client: text, images and links only';
|
|
25
|
-
return (
|
|
25
|
+
return (_jsx("button", { type: "button", className: "builder-editor__icon-button", "aria-pressed": on, "aria-label": "Preview as client", "data-tooltip": `Preview as client · ${tip}`, onClick: () => setPreviewAsClient(runtime, !on), children: _jsx(Icon, { name: on ? 'eyeOff' : 'eye' }) }));
|
|
26
26
|
}
|