payload-canvas 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +500 -25
- package/dist/admin/diff/changes.js +8 -0
- package/dist/admin/editor/Inspector.js +49 -4
- package/dist/admin/editor/Outline.js +12 -10
- package/dist/admin/editor/actions.d.ts +9 -1
- package/dist/admin/editor/actions.js +38 -3
- package/dist/admin/editor/empty/EmptyStart.js +29 -3
- package/dist/admin/editor/fields/GroupField.d.ts +5 -2
- package/dist/admin/editor/fields/GroupField.js +6 -2
- package/dist/admin/editor/fields/WhereField.d.ts +17 -0
- package/dist/admin/editor/fields/WhereField.js +67 -0
- package/dist/admin/editor/fields/fields.scss +89 -0
- package/dist/admin/editor/fields/whereRows.d.ts +28 -0
- package/dist/admin/editor/fields/whereRows.js +118 -0
- package/dist/admin/editor/icons.d.ts +1 -0
- package/dist/admin/editor/icons.js +2 -0
- package/dist/admin/editor/locale/LocaleField.d.ts +1 -1
- package/dist/admin/editor/locale/LocaleField.js +3 -1
- package/dist/admin/editor/menu/blockMenu.js +5 -1
- package/dist/admin/editor/motion/MotionPanel.js +1 -1
- package/dist/admin/editor/motion/model.js +2 -2
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +13 -4
- package/dist/admin/editor/runtime.js +1 -0
- package/dist/admin/editor/styles/SiteClasses.d.ts +9 -0
- package/dist/admin/editor/styles/SiteClasses.js +31 -0
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
- package/dist/admin/editor/styles/StylesPanel.js +9 -6
- package/dist/admin/editor/styles/context.d.ts +9 -2
- package/dist/admin/editor/styles/context.js +14 -9
- package/dist/admin/editor/styles/controls.js +2 -2
- package/dist/admin/editor/styles/sections.js +1 -1
- package/dist/admin/editor/styles/styles.scss +54 -0
- package/dist/admin/editor/templates/Bindable.d.ts +13 -5
- package/dist/admin/editor/templates/Bindable.js +73 -17
- package/dist/admin/editor/templates/binding.d.ts +11 -4
- package/dist/admin/editor/templates/binding.js +23 -3
- package/dist/ai/prompt.js +8 -2
- package/dist/ai/tools.js +11 -2
- package/dist/blocks/builtins/carousel.d.ts +32 -0
- package/dist/blocks/builtins/carousel.js +122 -0
- package/dist/blocks/builtins/disclosure.d.ts +13 -0
- package/dist/blocks/builtins/disclosure.js +107 -0
- package/dist/blocks/builtins/faq.d.ts +17 -0
- package/dist/blocks/builtins/faq.js +88 -0
- package/dist/blocks/builtins/filterLink.d.ts +22 -0
- package/dist/blocks/builtins/filterLink.js +76 -0
- package/dist/blocks/builtins/headingId.d.ts +15 -0
- package/dist/blocks/builtins/headingId.js +36 -0
- package/dist/blocks/builtins/icon.d.ts +8 -0
- package/dist/blocks/builtins/icon.js +45 -0
- package/dist/blocks/builtins/index.d.ts +35 -0
- package/dist/blocks/builtins/index.js +50 -0
- package/dist/blocks/builtins/lightbox.d.ts +43 -0
- package/dist/blocks/builtins/lightbox.js +93 -0
- package/dist/blocks/builtins/mediaBackdrop.d.ts +11 -0
- package/dist/blocks/builtins/mediaBackdrop.js +79 -0
- package/dist/blocks/builtins/sectionRef.d.ts +26 -0
- package/dist/blocks/builtins/sectionRef.js +78 -0
- package/dist/blocks/builtins/shared.d.ts +33 -0
- package/dist/blocks/builtins/shared.js +70 -0
- package/dist/blocks/builtins/tableOfContents.d.ts +3 -0
- package/dist/blocks/builtins/tableOfContents.js +44 -0
- package/dist/blocks/defaults.d.ts +19 -1
- package/dist/blocks/defaults.js +413 -20
- package/dist/blocks/index.d.ts +4 -2
- package/dist/blocks/index.js +3 -1
- package/dist/core/attrs.d.ts +27 -0
- package/dist/core/attrs.js +132 -0
- package/dist/core/bindings.d.ts +122 -11
- package/dist/core/bindings.js +504 -19
- package/dist/core/blocks.d.ts +46 -1
- package/dist/core/blocks.js +136 -0
- package/dist/core/classes.d.ts +10 -2
- package/dist/core/classes.js +34 -5
- package/dist/core/headings.d.ts +21 -0
- package/dist/core/headings.js +47 -0
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +4 -2
- package/dist/core/motion.d.ts +18 -9
- package/dist/core/motion.js +20 -12
- package/dist/core/operations.js +59 -2
- package/dist/core/payloadBlocks.js +3 -1
- package/dist/core/schema.js +20 -0
- package/dist/core/tree.js +24 -1
- package/dist/core/types.d.ts +87 -0
- package/dist/core/validate.js +29 -4
- package/dist/css/tokens.d.ts +6 -3
- package/dist/css/tokens.js +48 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +50 -13
- package/dist/mcp/shared.d.ts +3 -0
- package/dist/mcp/shared.js +23 -8
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +26 -8
- package/dist/plugin/listCollections.d.ts +17 -2
- package/dist/plugin/listCollections.js +44 -7
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +1 -1
- package/dist/plugin/templates.d.ts +4 -0
- package/dist/plugin/templates.js +23 -4
- package/dist/protocol/index.d.ts +2 -0
- package/dist/react/canvas/BuilderCanvas.js +5 -3
- package/dist/react/canvas/fetchDocs.d.ts +16 -2
- package/dist/react/canvas/fetchDocs.js +42 -9
- package/dist/react/canvas/measure.d.ts +3 -1
- package/dist/react/canvas/measure.js +26 -2
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +17 -6
- package/dist/react/canvas/serverBlocks.d.ts +11 -0
- package/dist/react/canvas/serverBlocks.js +28 -1
- package/dist/react/components/Button.d.ts +11 -2
- package/dist/react/components/Button.js +43 -6
- package/dist/react/components/CollectionList.d.ts +6 -3
- package/dist/react/components/CollectionList.js +21 -7
- package/dist/react/components/Container.js +4 -1
- package/dist/react/components/Field.js +13 -2
- package/dist/react/components/Heading.js +9 -2
- package/dist/react/components/Image.d.ts +9 -0
- package/dist/react/components/Image.js +16 -1
- package/dist/react/components/List.d.ts +1 -0
- package/dist/react/components/List.js +6 -0
- package/dist/react/components/Menu.d.ts +16 -0
- package/dist/react/components/Menu.js +83 -19
- package/dist/react/components/RichText.d.ts +8 -3
- package/dist/react/components/RichText.js +25 -4
- package/dist/react/components/builtins/Accordion.d.ts +9 -0
- package/dist/react/components/builtins/Accordion.js +37 -0
- package/dist/react/components/builtins/BackdropVideo.d.ts +13 -0
- package/dist/react/components/builtins/BackdropVideo.js +16 -0
- package/dist/react/components/builtins/Carousel.d.ts +13 -0
- package/dist/react/components/builtins/Carousel.js +134 -0
- package/dist/react/components/builtins/Disclosure.d.ts +7 -0
- package/dist/react/components/builtins/Disclosure.js +13 -0
- package/dist/react/components/builtins/FilterLink.d.ts +8 -0
- package/dist/react/components/builtins/FilterLink.js +30 -0
- package/dist/react/components/builtins/Icon.d.ts +14 -0
- package/dist/react/components/builtins/Icon.js +28 -0
- package/dist/react/components/builtins/Lightbox.d.ts +45 -0
- package/dist/react/components/builtins/Lightbox.js +252 -0
- package/dist/react/components/builtins/MediaBackdrop.d.ts +14 -0
- package/dist/react/components/builtins/MediaBackdrop.js +61 -0
- package/dist/react/components/builtins/SectionRef.d.ts +7 -0
- package/dist/react/components/builtins/SectionRef.js +17 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +7 -0
- package/dist/react/components/builtins/TableOfContents.js +21 -0
- package/dist/react/components/builtins/glyphs.d.ts +8 -0
- package/dist/react/components/builtins/glyphs.js +7 -0
- package/dist/react/components/builtins/index.d.ts +32 -0
- package/dist/react/components/builtins/index.js +36 -0
- package/dist/react/components/index.js +2 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +3 -1
- package/dist/react/motion/runtime.js +10 -6
- package/dist/react/render/RenderLayout.d.ts +1 -1
- package/dist/react/render/RenderLayout.js +76 -23
- package/dist/react/render/lists.d.ts +107 -5
- package/dist/react/render/lists.js +284 -9
- package/dist/react/render/resolve.d.ts +22 -2
- package/dist/react/render/resolve.js +45 -22
- package/dist/react/render/sections.d.ts +9 -0
- package/dist/react/render/sections.js +51 -0
- package/dist/react/render/types.d.ts +6 -1
- package/dist/react/server.d.ts +3 -1
- package/dist/react/server.js +53 -2
- package/dist/react/theme/ThemeStyle.d.ts +13 -2
- package/dist/react/theme/ThemeStyle.js +12 -2
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// The where builder's rows (field, operator, value) <-> a Payload `where` object. Pure, so it is
|
|
2
|
+
// tested without React. Rows are AND-ed. A where the rows cannot show (`or`, nested groups,
|
|
3
|
+
// object values, unknown operators) returns null from `whereRows`, and the field shows raw JSON.
|
|
4
|
+
export const WHERE_OPERATORS = [
|
|
5
|
+
'equals',
|
|
6
|
+
'not_equals',
|
|
7
|
+
'in',
|
|
8
|
+
'not_in',
|
|
9
|
+
'greater_than',
|
|
10
|
+
'greater_than_equal',
|
|
11
|
+
'less_than',
|
|
12
|
+
'less_than_equal',
|
|
13
|
+
'like',
|
|
14
|
+
'contains',
|
|
15
|
+
'exists',
|
|
16
|
+
];
|
|
17
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
+
const isScalar = (value) => typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
|
|
19
|
+
const isOperator = (value) => WHERE_OPERATORS.includes(value);
|
|
20
|
+
function fitsOperator(operator, value) {
|
|
21
|
+
if (operator === 'exists')
|
|
22
|
+
return typeof value === 'boolean';
|
|
23
|
+
if (operator === 'in' || operator === 'not_in')
|
|
24
|
+
return Array.isArray(value) && value.every(isScalar);
|
|
25
|
+
return isScalar(value);
|
|
26
|
+
}
|
|
27
|
+
/** The rows of `{ field: { op: value } }` (several fields and operators allowed). Null when it does not fit. */
|
|
28
|
+
function rowsOf(where) {
|
|
29
|
+
const rows = [];
|
|
30
|
+
for (const [field, condition] of Object.entries(where)) {
|
|
31
|
+
if (field === 'and' || field === 'or' || !isRecord(condition))
|
|
32
|
+
return null;
|
|
33
|
+
const entries = Object.entries(condition);
|
|
34
|
+
if (entries.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
for (const [operator, value] of entries) {
|
|
37
|
+
if (!isOperator(operator) || !fitsOperator(operator, value))
|
|
38
|
+
return null;
|
|
39
|
+
rows.push({ field, operator, value });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return rows;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The rows of a stored where: empty for no where, null when the builder cannot show it. Takes
|
|
46
|
+
* `{ a: { equals: 1 }, b: { … } }` and `{ and: [ { a: { equals: 1 } }, … ] }`.
|
|
47
|
+
*/
|
|
48
|
+
export function whereRows(where) {
|
|
49
|
+
if (where === undefined || where === null)
|
|
50
|
+
return [];
|
|
51
|
+
if (!isRecord(where))
|
|
52
|
+
return null;
|
|
53
|
+
const keys = Object.keys(where);
|
|
54
|
+
if (keys.length === 1 && keys[0] === 'and') {
|
|
55
|
+
if (!Array.isArray(where.and))
|
|
56
|
+
return null;
|
|
57
|
+
const rows = [];
|
|
58
|
+
for (const part of where.and) {
|
|
59
|
+
if (!isRecord(part))
|
|
60
|
+
return null;
|
|
61
|
+
const partRows = rowsOf(part);
|
|
62
|
+
if (!partRows)
|
|
63
|
+
return null;
|
|
64
|
+
rows.push(...partRows);
|
|
65
|
+
}
|
|
66
|
+
return rows;
|
|
67
|
+
}
|
|
68
|
+
return rowsOf(where);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The where of the rows: one object `{ field: { op: value } }`, or `{ and: [...] }` when a field
|
|
72
|
+
* has the same operator twice. Rows without a field are left out. `undefined` for no rows.
|
|
73
|
+
*/
|
|
74
|
+
export function rowsWhere(rows) {
|
|
75
|
+
const complete = rows.filter((row) => row.field.trim());
|
|
76
|
+
if (complete.length === 0)
|
|
77
|
+
return undefined;
|
|
78
|
+
const flat = {};
|
|
79
|
+
for (const row of complete) {
|
|
80
|
+
const field = row.field.trim();
|
|
81
|
+
const condition = (flat[field] ??= {});
|
|
82
|
+
if (row.operator in condition) {
|
|
83
|
+
return { and: complete.map((r) => ({ [r.field.trim()]: { [r.operator]: r.value } })) };
|
|
84
|
+
}
|
|
85
|
+
condition[row.operator] = row.value;
|
|
86
|
+
}
|
|
87
|
+
return flat;
|
|
88
|
+
}
|
|
89
|
+
/** The text a value shows in the value input: lists as "a, b". */
|
|
90
|
+
export const whereValueText = (value) => Array.isArray(value) ? value.map(String).join(', ') : value === undefined || value === null ? '' : String(value);
|
|
91
|
+
/**
|
|
92
|
+
* The value to store for typed text. `fieldType` is the Payload field type when known: numbers
|
|
93
|
+
* become numbers and checkboxes booleans; any other text stays text (so "0412" stays a string).
|
|
94
|
+
* `in` and `not_in` split on commas. `exists` takes "true" or "false".
|
|
95
|
+
*/
|
|
96
|
+
export function parseWhereValue(text, operator, fieldType) {
|
|
97
|
+
if (operator === 'exists')
|
|
98
|
+
return text.trim() !== 'false';
|
|
99
|
+
const one = (part) => {
|
|
100
|
+
if (fieldType === 'number') {
|
|
101
|
+
const number = Number(part);
|
|
102
|
+
return part.trim() !== '' && Number.isFinite(number) ? number : part;
|
|
103
|
+
}
|
|
104
|
+
if (fieldType === 'checkbox')
|
|
105
|
+
return part.trim() === 'true';
|
|
106
|
+
return part;
|
|
107
|
+
};
|
|
108
|
+
if (operator === 'in' || operator === 'not_in') {
|
|
109
|
+
return text
|
|
110
|
+
.split(',')
|
|
111
|
+
.map((part) => part.trim())
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.map(one);
|
|
114
|
+
}
|
|
115
|
+
return one(text);
|
|
116
|
+
}
|
|
117
|
+
/** The value a row keeps when its operator changes: re-read from its text for the new operator. */
|
|
118
|
+
export const convertWhereValue = (row, operator, fieldType) => parseWhereValue(operator === 'exists' ? 'true' : whereValueText(row.value), operator, fieldType);
|
|
@@ -18,6 +18,7 @@ declare const PATHS: {
|
|
|
18
18
|
layers: import("react").JSX.Element;
|
|
19
19
|
field: import("react").JSX.Element;
|
|
20
20
|
collectionList: import("react").JSX.Element;
|
|
21
|
+
repeat: import("react").JSX.Element;
|
|
21
22
|
bind: import("react").JSX.Element;
|
|
22
23
|
template: import("react").JSX.Element;
|
|
23
24
|
calendar: import("react").JSX.Element;
|
|
@@ -23,6 +23,8 @@ const PATHS = {
|
|
|
23
23
|
// Dynamic blocks (templates and binding)
|
|
24
24
|
field: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M5.5 2.5H5A1.5 1.5 0 0 0 3.5 4v2.25L2.25 8 3.5 9.75V12A1.5 1.5 0 0 0 5 13.5h.5" }), _jsx("path", { d: "M10.5 2.5h.5A1.5 1.5 0 0 1 12.5 4v2.25L13.75 8 12.5 9.75V12a1.5 1.5 0 0 1-1.5 1.5h-.5" }), _jsx("path", { d: "M6.5 8h3" })] })),
|
|
25
25
|
collectionList: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "2", y: "2", width: "12", height: "5", rx: "1" }), _jsx("rect", { x: "2", y: "9", width: "12", height: "5", rx: "1", opacity: 0.45 }), _jsx("path", { d: "M4.5 4.5h4" }), _jsx("path", { d: "M4.5 11.5h4", opacity: 0.45 })] })),
|
|
26
|
+
// Rows of one field: braces (a field) around repeated lines.
|
|
27
|
+
repeat: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M5 2.5h-.5A1.5 1.5 0 0 0 3 4v8a1.5 1.5 0 0 0 1.5 1.5H5" }), _jsx("path", { d: "M11 2.5h.5A1.5 1.5 0 0 1 13 4v8a1.5 1.5 0 0 1-1.5 1.5H11" }), _jsx("path", { d: "M6 5.5h4" }), _jsx("path", { d: "M6 8h4", opacity: 0.6 }), _jsx("path", { d: "M6 10.5h4", opacity: 0.35 })] })),
|
|
26
28
|
bind: (_jsxs(_Fragment, { children: [_jsx("ellipse", { cx: "8", cy: "3.75", rx: "5", ry: "1.75" }), _jsx("path", { d: "M3 3.75v8.5c0 .97 2.24 1.75 5 1.75s5-.78 5-1.75v-8.5M3 8c0 .97 2.24 1.75 5 1.75S13 8.97 13 8" })] })),
|
|
27
29
|
template: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "2", y: "2", width: "12", height: "12", rx: "1.5", strokeDasharray: "2 1.6" }), _jsx("path", { d: "M5 5.5h6M5 8h3.5" })] })),
|
|
28
30
|
calendar: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1.5" }), _jsx("path", { d: "M2 6.5h12M5.25 1.75v2.5M10.75 1.75v2.5" })] })),
|
|
@@ -26,5 +26,5 @@ export declare function LocaleFieldFrame({ path, name, children }: {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare function LocaleNote({ blockId, tab }: {
|
|
28
28
|
blockId: string;
|
|
29
|
-
tab: 'content' | 'styles' | 'motion';
|
|
29
|
+
tab: 'content' | 'styles' | 'motion' | 'advanced';
|
|
30
30
|
}): import("react").JSX.Element | null;
|
|
@@ -163,5 +163,7 @@ export function LocaleNote({ blockId, tab }) {
|
|
|
163
163
|
? `Styles change every language, not only ${language}.`
|
|
164
164
|
: tab === 'motion'
|
|
165
165
|
? `Animations change every language, not only ${language}.`
|
|
166
|
-
:
|
|
166
|
+
: tab === 'advanced'
|
|
167
|
+
? `HTML attributes change every language, not only ${language}.`
|
|
168
|
+
: `Editing ${language}. Translated fields change ${language} only; other fields, blocks and styles change every language.` }), tab === 'content' && missing > 0 && (_jsxs("button", { type: "button", className: "builder-locale-field__action", onClick: () => copyFromDefault(runtime, blockId), children: ["Copy ", missing, " ", missing === 1 ? 'field' : 'fields', " from ", fallback] }))] })] }));
|
|
167
169
|
}
|
|
@@ -3,8 +3,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
// The block menu: one definition for the canvas action bar "…", the inspector header "…" and
|
|
4
4
|
// the right-click menu on the canvas and in the outline, so they never drift apart.
|
|
5
5
|
import { memo, useCallback } from 'react';
|
|
6
|
+
import { SECTION_REF_BLOCK, sectionRefId } from '../../../blocks/builtins/sectionRef.js';
|
|
6
7
|
import { findBlock, findLocation } from '../../../core/index.js';
|
|
7
|
-
import { copyBlock, copyStyles, duplicateBlock, inRow, moveBy, parseClipboard, pasteStoredBlocks, pasteStyles, removeBlock, resetStyles, siblingCount, storedClipboard, storedStyles, storesBuilderData, toggleHidden, } from '../actions.js';
|
|
8
|
+
import { copyBlock, copyStyles, detachSection, duplicateBlock, inRow, moveBy, parseClipboard, pasteStoredBlocks, pasteStyles, removeBlock, resetStyles, siblingCount, storedClipboard, storedStyles, storesBuilderData, toggleHidden, } from '../actions.js';
|
|
8
9
|
import { useRuntime } from '../runtime.js';
|
|
9
10
|
import { requestSaveSection } from '../sections/SectionDialog.js';
|
|
10
11
|
import { useEditor } from '../store.js';
|
|
@@ -91,6 +92,9 @@ export function blockMenuEntries(runtime, id, origin) {
|
|
|
91
92
|
...(runtime.sections.enabled
|
|
92
93
|
? [{ icon: 'section', label: 'Save as section…', ownFocus: true, run: () => requestSaveSection(runtime, block) }]
|
|
93
94
|
: []),
|
|
95
|
+
...(runtime.sections.enabled && block.type === SECTION_REF_BLOCK && sectionRefId(block.props?.section) !== null
|
|
96
|
+
? [{ icon: 'section', label: 'Detach section', run: () => void detachSection(runtime, id) }]
|
|
97
|
+
: []),
|
|
94
98
|
'separator',
|
|
95
99
|
{ icon: 'delete', label: 'Delete', keys: keys('delete'), danger: true, run: () => removeBlock(runtime, id) },
|
|
96
100
|
];
|
|
@@ -98,7 +98,7 @@ function HoverSection({ blockId, hover, press, edit }) {
|
|
|
98
98
|
}
|
|
99
99
|
function ScrollSection({ scroll, edit }) {
|
|
100
100
|
const n = scroll ? scrollValue(scroll) : 0;
|
|
101
|
-
return (_jsxs(Section, { title: "Scroll", set: Boolean(scroll), removeLabel: "Remove the scroll effect", onRemove: () => edit.remove(['scroll']), children: [_jsx(PresetRow, { label: "Effect", name: "Scroll effect", preset: scroll?.preset, options: OPTIONS.scroll, onChange: (p) => edit.preset('scroll', p) }), _jsx(Note, { children: scroll ? describePreset('scroll', scroll.preset) : 'Follows the scroll while the block passes through the window.' }), scroll?.preset === 'parallax' && (_jsx(NumberRow, { label: "Distance", value: n, min: -300, max: 300, step: 10, unit: "px", isSet: scroll.distance !== undefined, onChange: (value) => edit.value('scroll', 'distance', value), onReset: () => edit.value('scroll', 'distance', undefined) })), scroll?.preset === 'zoom' && (_jsx(NumberRow, { label: "Start size", value: toPercent(n), min: 50, max: 150, step: 5, unit: "%", isSet: scroll.scale !== undefined, onChange: (value) => edit.value('scroll', 'scale', fromPercent(value)), onReset: () => edit.value('scroll', 'scale', undefined) }))] }));
|
|
101
|
+
return (_jsxs(Section, { title: "Scroll", set: Boolean(scroll), removeLabel: "Remove the scroll effect", onRemove: () => edit.remove(['scroll']), children: [_jsx(PresetRow, { label: "Effect", name: "Scroll effect", preset: scroll?.preset, options: OPTIONS.scroll, onChange: (p) => edit.preset('scroll', p) }), _jsx(Note, { children: scroll ? describePreset('scroll', scroll.preset) : 'Follows the scroll while the block passes through the window.' }), scroll?.preset === 'parallax' && (_jsx(NumberRow, { label: "Distance", value: n, min: -300, max: 300, step: 10, unit: "px", isSet: scroll.distance !== undefined, onChange: (value) => edit.value('scroll', 'distance', value), onReset: () => edit.value('scroll', 'distance', undefined) })), scroll?.preset === 'zoom' && (_jsx(NumberRow, { label: "Start size", value: toPercent(n), min: 50, max: 150, step: 5, unit: "%", isSet: scroll.scale !== undefined, onChange: (value) => edit.value('scroll', 'scale', fromPercent(value)), onReset: () => edit.value('scroll', 'scale', undefined) })), scroll?.preset === 'recede' && (_jsx(NumberRow, { label: "End size", value: toPercent(n), min: 50, max: 100, step: 1, unit: "%", isSet: scroll.scale !== undefined, onChange: (value) => edit.value('scroll', 'scale', fromPercent(value)), onReset: () => edit.value('scroll', 'scale', undefined) }))] }));
|
|
102
102
|
}
|
|
103
103
|
function LoopSection({ loop, edit }) {
|
|
104
104
|
const v = loop ? loopValues(loop) : null;
|
|
@@ -9,7 +9,7 @@ export function usesDistance(preset) {
|
|
|
9
9
|
/** The number a preset of each kind uses, besides `duration` (the other numbers do not apply). */
|
|
10
10
|
const PRESET_KEYS = {
|
|
11
11
|
hover: { lift: ['distance'], grow: ['scale'], tilt: ['angle'] },
|
|
12
|
-
scroll: { parallax: ['distance'], fade: [], zoom: ['scale'] },
|
|
12
|
+
scroll: { parallax: ['distance'], fade: [], zoom: ['scale'], recede: ['scale'] },
|
|
13
13
|
loop: { float: ['duration', 'distance'], pulse: ['duration', 'scale'] },
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
@@ -66,7 +66,7 @@ export function enterValues(enter) {
|
|
|
66
66
|
}
|
|
67
67
|
export const hoverValue = (hover) => hover.preset === 'lift' ? (hover.distance ?? HOVER_DEFAULTS.distance) : hover.preset === 'grow' ? (hover.scale ?? HOVER_DEFAULTS.scale) : (hover.angle ?? HOVER_DEFAULTS.angle);
|
|
68
68
|
export const pressScale = (scale) => scale ?? PRESS_DEFAULTS.scale;
|
|
69
|
-
export const scrollValue = (scroll) => scroll.preset === 'zoom' ? (scroll.scale ?? SCROLL_DEFAULTS.scale) : (scroll.distance ?? SCROLL_DEFAULTS.distance);
|
|
69
|
+
export const scrollValue = (scroll) => scroll.preset === 'zoom' || scroll.preset === 'recede' ? (scroll.scale ?? SCROLL_DEFAULTS.scale) : (scroll.distance ?? SCROLL_DEFAULTS.distance);
|
|
70
70
|
export function loopValues(loop) {
|
|
71
71
|
const defaults = LOOP_DEFAULTS[loop.preset];
|
|
72
72
|
return {
|
|
@@ -7,6 +7,8 @@ type Props = {
|
|
|
7
7
|
readonly path: string;
|
|
8
8
|
readonly value: unknown;
|
|
9
9
|
readonly onChange: (value: unknown) => void;
|
|
10
|
+
/** The other values of the same object (block props, group or row), for fields that read a sibling. */
|
|
11
|
+
readonly siblings?: Record<string, unknown>;
|
|
10
12
|
};
|
|
11
13
|
export declare function fieldLabel(field: Field): string;
|
|
12
14
|
/**
|
|
@@ -16,7 +18,7 @@ export declare function fieldLabel(field: Field): string;
|
|
|
16
18
|
* `{ relationTo, value }`: we store IDs, or `{ relationTo, value: id }` for polymorphic fields.
|
|
17
19
|
* SelectInput returns the option object. DatePicker returns a Date, stored as an ISO string.
|
|
18
20
|
*/
|
|
19
|
-
export declare function RenderBlockField({ field, onChange, path, value }: Props): import("react").JSX.Element;
|
|
21
|
+
export declare function RenderBlockField({ field, onChange, path, value, siblings }: Props): import("react").JSX.Element;
|
|
20
22
|
type FieldsProps = {
|
|
21
23
|
readonly fields: Field[];
|
|
22
24
|
/** The object the fields read from: block props, a group value or an array row. */
|
|
@@ -8,6 +8,7 @@ import { isStructuralChange } from './fields/arrayState.js';
|
|
|
8
8
|
import { CheckedTextField, NumberField } from './fields/CheckedInputs.js';
|
|
9
9
|
import { FieldSection, GroupField } from './fields/GroupField.js';
|
|
10
10
|
import { JsonField } from './fields/JsonField.js';
|
|
11
|
+
import { WhereField } from './fields/WhereField.js';
|
|
11
12
|
import { ManyValuesField } from './fields/ManyValuesField.js';
|
|
12
13
|
import { PointField } from './fields/PointField.js';
|
|
13
14
|
import { RichTextField } from './fields/RichTextField.js';
|
|
@@ -60,7 +61,7 @@ function Unsupported({ label, reason }) {
|
|
|
60
61
|
* `{ relationTo, value }`: we store IDs, or `{ relationTo, value: id }` for polymorphic fields.
|
|
61
62
|
* SelectInput returns the option object. DatePicker returns a Date, stored as an ISO string.
|
|
62
63
|
*/
|
|
63
|
-
export function RenderBlockField({ field, onChange, path, value }) {
|
|
64
|
+
export function RenderBlockField({ field, onChange, path, value, siblings }) {
|
|
64
65
|
const { config } = useConfig();
|
|
65
66
|
// In another locale, an untranslated text shows the fallback language's text as its placeholder.
|
|
66
67
|
const placeholder = useLocalePlaceholder(path);
|
|
@@ -126,8 +127,15 @@ export function RenderBlockField({ field, onChange, path, value }) {
|
|
|
126
127
|
const pickerAppearance = field.admin?.date?.pickerAppearance ?? 'dayOnly';
|
|
127
128
|
return (_jsxs("div", { className: "field-type date-time-field", children: [_jsx(FieldLabel, { label: label, path: path, required: required }), _jsx("div", { className: "field-type__wrap", children: _jsx(DatePicker, { onChange: (date) => onChange(date ? date.toISOString() : null), pickerAppearance: pickerAppearance, value: typeof value === 'string' ? value : undefined }) })] }));
|
|
128
129
|
}
|
|
129
|
-
case 'json':
|
|
130
|
+
case 'json': {
|
|
131
|
+
// `admin.custom.builderWhere`: a Payload where query, edited as condition rows.
|
|
132
|
+
const where = field.admin?.custom?.builderWhere;
|
|
133
|
+
if (where) {
|
|
134
|
+
const collection = where.collectionField ? siblings?.[where.collectionField] : undefined;
|
|
135
|
+
return (_jsx(WhereField, { collection: typeof collection === 'string' ? collection : undefined, description: description, label: label, onChange: onChange, path: path, required: required, value: value }));
|
|
136
|
+
}
|
|
130
137
|
return _jsx(JsonField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value });
|
|
138
|
+
}
|
|
131
139
|
case 'point':
|
|
132
140
|
return _jsx(PointField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value });
|
|
133
141
|
case 'blocks':
|
|
@@ -176,7 +184,8 @@ export function RenderBlockFields({ fields, data, path, onChange, scope = fields
|
|
|
176
184
|
if (field.type === 'collapsible') {
|
|
177
185
|
const shared = _jsx(RenderBlockFields, { fields: field.fields, data: record, path: path, onChange: onChange, scope: scope });
|
|
178
186
|
const title = text(field.label);
|
|
179
|
-
|
|
187
|
+
const folded = field.admin?.initCollapsed === true;
|
|
188
|
+
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}`)));
|
|
180
189
|
return;
|
|
181
190
|
}
|
|
182
191
|
if (field.type === 'row' || (field.type === 'group' && !('name' in field && field.name))) {
|
|
@@ -210,7 +219,7 @@ export function RenderBlockFields({ fields, data, path, onChange, scope = fields
|
|
|
210
219
|
if (!access.read)
|
|
211
220
|
return;
|
|
212
221
|
const onFieldChange = (value) => setField(name, value, field);
|
|
213
|
-
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 }) }) }) }), _jsx(PeerFieldNote, { fieldPath: fieldPath }), _jsx(FieldProblem, { path: fieldPath })] }, name));
|
|
222
|
+
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 }) }) }) }), _jsx(PeerFieldNote, { fieldPath: fieldPath }), _jsx(FieldProblem, { path: fieldPath })] }, name));
|
|
214
223
|
});
|
|
215
224
|
return _jsx(_Fragment, { children: out });
|
|
216
225
|
}
|
|
@@ -73,6 +73,7 @@ export function createRuntime(config, api, document, options = {}) {
|
|
|
73
73
|
api,
|
|
74
74
|
document: { collection: document.collection, id: document.id },
|
|
75
75
|
...(config.regions?.length ? { regions: config.regions } : {}),
|
|
76
|
+
...(config.relations && Object.keys(config.relations).length > 0 ? { relations: config.relations } : {}),
|
|
76
77
|
};
|
|
77
78
|
const runtime = {
|
|
78
79
|
config,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SiteClass } from '../../../core/types.js';
|
|
2
|
+
/** The presets by group, in CSS order. Classes without a group go under "Other" (or no heading when no class has a group). */
|
|
3
|
+
export declare function groupSiteClasses(list: readonly SiteClass[]): Array<{
|
|
4
|
+
group: string | null;
|
|
5
|
+
classes: SiteClass[];
|
|
6
|
+
}>;
|
|
7
|
+
/** The class list with `name` added at the end, or removed when it is there (without variants). */
|
|
8
|
+
export declare function toggleClass(className: string, name: string): string;
|
|
9
|
+
export declare function SiteClasses(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// "Site classes": the site's own `@utility` classes (StyleTokens.siteClasses) as presets. A click
|
|
4
|
+
// adds the class to the block, or removes it when the block has it, like typing it in Classes.
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { useStyles } from './context.js';
|
|
7
|
+
import * as I from './icons.js';
|
|
8
|
+
/** The presets by group, in CSS order. Classes without a group go under "Other" (or no heading when no class has a group). */
|
|
9
|
+
export function groupSiteClasses(list) {
|
|
10
|
+
const groups = new Map();
|
|
11
|
+
const anyGroup = list.some((c) => c.group);
|
|
12
|
+
for (const item of list) {
|
|
13
|
+
const key = item.group ?? (anyGroup ? 'Other' : null);
|
|
14
|
+
groups.set(key, [...(groups.get(key) ?? []), item]);
|
|
15
|
+
}
|
|
16
|
+
return [...groups].map(([group, classes]) => ({ group, classes }));
|
|
17
|
+
}
|
|
18
|
+
/** The class list with `name` added at the end, or removed when it is there (without variants). */
|
|
19
|
+
export function toggleClass(className, name) {
|
|
20
|
+
const list = className.split(/\s+/).filter(Boolean);
|
|
21
|
+
return (list.includes(name) ? list.filter((c) => c !== name) : [...list, name]).join(' ');
|
|
22
|
+
}
|
|
23
|
+
export function SiteClasses() {
|
|
24
|
+
const { tokens, className, setClassName } = useStyles();
|
|
25
|
+
const list = tokens.siteClasses ?? [];
|
|
26
|
+
const [open, setOpen] = useState(() => list.some((c) => className.split(/\s+/).includes(c.name)));
|
|
27
|
+
if (list.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
const own = new Set(className.split(/\s+/));
|
|
30
|
+
return (_jsxs("section", { className: "builder-styles__section", "data-open": open, children: [_jsxs("button", { type: "button", className: "builder-styles__section-head", "aria-expanded": open, onClick: () => setOpen(!open), children: [_jsx("span", { className: "builder-styles__chevron", children: _jsx(I.ChevronIcon, {}) }), "Site classes", list.some((c) => own.has(c.name)) && _jsx("span", { className: "builder-styles__dot", "data-tooltip": "The block uses a site class" })] }), open && (_jsx("div", { className: "builder-styles__section-body", children: groupSiteClasses(list).map(({ group, classes }) => (_jsxs("fieldset", { className: "builder-styles__presets", "aria-label": group ? undefined : 'Site classes', children: [group && _jsx("legend", { className: "builder-styles__presets-title", children: group }), _jsx("div", { className: "builder-styles__presets-list", children: classes.map((item) => (_jsxs("button", { type: "button", className: "builder-styles__preset", "aria-pressed": own.has(item.name), "data-tooltip": item.css ? `.${item.name} { ${item.css} }` : `.${item.name}`, onClick: () => setClassName(toggleClass(className, item.name)), children: [_jsx("span", { className: "builder-styles__preset-label", children: item.label ?? item.name }), item.label && _jsx("code", { className: "builder-styles__preset-name", children: item.name })] }, item.name))) })] }, group ?? ''))) }))] }));
|
|
31
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Block } from '../../../core/types.js';
|
|
2
2
|
import './styles.scss';
|
|
3
|
-
|
|
3
|
+
/** `slot`: edit the classes of that slot's own element (`slotClassName`) instead of the block's. */
|
|
4
|
+
export declare function StylesPanel({ block, slot }: {
|
|
4
5
|
block: Block;
|
|
6
|
+
slot?: string | null;
|
|
5
7
|
}): import("react").JSX.Element;
|
|
@@ -10,11 +10,13 @@ import { StylesContext, writeClassName, writeStyle } from './context.js';
|
|
|
10
10
|
import { createReader } from './model.js';
|
|
11
11
|
import { stopEditorKeys } from './popover.js';
|
|
12
12
|
import { RawClasses } from './RawClasses.js';
|
|
13
|
+
import { SiteClasses } from './SiteClasses.js';
|
|
13
14
|
import { StyleSections } from './sections.js';
|
|
14
15
|
import { BREAKPOINTS, breakpointAt, breakpointWidths, reloadStyleTokens, useStyleTokens, withFallback } from './tokens.js';
|
|
15
16
|
import { VariantBar } from './VariantBar.js';
|
|
16
17
|
import './styles.scss';
|
|
17
|
-
|
|
18
|
+
/** `slot`: edit the classes of that slot's own element (`slotClassName`) instead of the block's. */
|
|
19
|
+
export function StylesPanel({ block, slot = null }) {
|
|
18
20
|
const runtime = useRuntime();
|
|
19
21
|
const { tokensEndpoint } = runtime.config;
|
|
20
22
|
const entry = useStyleTokens(tokensEndpoint);
|
|
@@ -23,12 +25,13 @@ export function StylesPanel({ block }) {
|
|
|
23
25
|
const frame = useValue(runtime.frame);
|
|
24
26
|
const widths = useMemo(() => breakpointWidths(tokens), [tokens]);
|
|
25
27
|
const canvasBreakpoint = frame.width > 0 ? breakpointAt(widths, frame.width) : 'base';
|
|
26
|
-
const className = block.className ?? '';
|
|
28
|
+
const className = (slot ? block.slotClassName?.[slot] : block.className) ?? '';
|
|
27
29
|
const blockId = block.id;
|
|
28
30
|
const [error] = useState(() => createValueStore(null));
|
|
29
31
|
const message = useValue(error);
|
|
30
32
|
const value = useMemo(() => ({
|
|
31
33
|
blockId,
|
|
34
|
+
slot,
|
|
32
35
|
blockType: block.type,
|
|
33
36
|
className,
|
|
34
37
|
variant,
|
|
@@ -38,9 +41,9 @@ export function StylesPanel({ block }) {
|
|
|
38
41
|
? createReader(className, { ...variant, breakpoint: canvasBreakpoint }, tokens)
|
|
39
42
|
: null,
|
|
40
43
|
canvasBreakpoint,
|
|
41
|
-
set: (property, v, options) => error.set(writeStyle(runtime, blockId, variant, tokens, property, v, options)),
|
|
42
|
-
setClassName: (next, mergeKey) => writeClassName(runtime, blockId, next, mergeKey),
|
|
44
|
+
set: (property, v, options) => error.set(writeStyle(runtime, { blockId, slot }, variant, tokens, property, v, options)),
|
|
45
|
+
setClassName: (next, mergeKey) => writeClassName(runtime, { blockId, slot }, next, mergeKey),
|
|
43
46
|
error,
|
|
44
|
-
}), [runtime, blockId, block.type, className, variant, tokens, error, canvasBreakpoint]);
|
|
45
|
-
return (_jsx(StylesContext, { value: value, children: _jsxs("div", { className: "builder-styles", onKeyDown: stopEditorKeys, children: [_jsx(VariantBar, {}), message && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", role: "alert", children: [message, ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => error.set(null), children: "Dismiss" })] })), entry.error && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", children: ["Theme tokens did not load (", entry.error, ").", ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => reloadStyleTokens(tokensEndpoint), children: "Retry" })] })), STYLE_PROPERTIES.length > 0 ? (_jsx(StyleSections, {})) : (_jsx("p", { className: "builder-styles__hint", children: "Visual style controls are not available yet. Edit the classes below." })), _jsx(RawClasses, {})] }) }));
|
|
47
|
+
}), [runtime, blockId, slot, block.type, className, variant, tokens, error, canvasBreakpoint]);
|
|
48
|
+
return (_jsx(StylesContext, { value: value, children: _jsxs("div", { className: "builder-styles", onKeyDown: stopEditorKeys, children: [_jsx(VariantBar, {}), message && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", role: "alert", children: [message, ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => error.set(null), children: "Dismiss" })] })), entry.error && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", children: ["Theme tokens did not load (", entry.error, ").", ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => reloadStyleTokens(tokensEndpoint), children: "Retry" })] })), STYLE_PROPERTIES.length > 0 ? (_jsx(StyleSections, {})) : (_jsx("p", { className: "builder-styles__hint", children: "Visual style controls are not available yet. Edit the classes below." })), _jsx(SiteClasses, {}), _jsx(RawClasses, {})] }) }));
|
|
46
49
|
}
|
|
@@ -2,8 +2,15 @@ import { type Breakpoint, type StyleTokens, type Variant } from '../../../core/i
|
|
|
2
2
|
import type { ValueStore } from '../valueStore.js';
|
|
3
3
|
import type { Runtime } from '../runtime.js';
|
|
4
4
|
import { type StyleReader } from './model.js';
|
|
5
|
+
/** What the Styles panel edits: a block's `className`, or with `slot`, that slot's `slotClassName`. */
|
|
6
|
+
export type StyleTarget = {
|
|
7
|
+
blockId: string;
|
|
8
|
+
slot?: string | null;
|
|
9
|
+
};
|
|
5
10
|
export type StylesContextValue = {
|
|
6
11
|
blockId: string;
|
|
12
|
+
/** The slot whose own classes the panel edits. Null: the block's `className`. */
|
|
13
|
+
slot: string | null;
|
|
7
14
|
/** The block type: it picks the style groups that open by default. */
|
|
8
15
|
blockType: string;
|
|
9
16
|
className: string;
|
|
@@ -28,8 +35,8 @@ export type StylesContextValue = {
|
|
|
28
35
|
};
|
|
29
36
|
export declare const StylesContext: import("react").Context<StylesContextValue | null>;
|
|
30
37
|
export declare function useStyles(): StylesContextValue;
|
|
31
|
-
export declare function writeClassName(runtime: Runtime,
|
|
38
|
+
export declare function writeClassName(runtime: Runtime, target: StyleTarget, next: string, mergeKey?: string): void;
|
|
32
39
|
/** Returns an error message when the class model refuses the value. */
|
|
33
|
-
export declare function writeStyle(runtime: Runtime,
|
|
40
|
+
export declare function writeStyle(runtime: Runtime, target: StyleTarget, variant: Variant, tokens: StyleTokens, property: string, value: string | null, options?: {
|
|
34
41
|
negative?: boolean;
|
|
35
42
|
}): string | null;
|
|
@@ -9,20 +9,25 @@ export function useStyles() {
|
|
|
9
9
|
throw new Error('useStyles must be used inside the Styles panel');
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
|
-
/** Reads the latest
|
|
13
|
-
function currentClassName(runtime, blockId) {
|
|
14
|
-
|
|
12
|
+
/** Reads the latest classes from the store, so two edits in one frame never overwrite each other. */
|
|
13
|
+
function currentClassName(runtime, { blockId, slot }) {
|
|
14
|
+
const block = findBlock(runtime.store.getState().layout, blockId);
|
|
15
|
+
return (slot ? block?.slotClassName?.[slot] : block?.className) ?? '';
|
|
15
16
|
}
|
|
16
|
-
export function writeClassName(runtime,
|
|
17
|
+
export function writeClassName(runtime, target, next, mergeKey) {
|
|
17
18
|
// One space between classes: double spaces from typing never reach the stored value.
|
|
18
19
|
const normalized = next.trim().replace(/\s+/g, ' ');
|
|
19
|
-
if (normalized === currentClassName(runtime,
|
|
20
|
+
if (normalized === currentClassName(runtime, target))
|
|
20
21
|
return;
|
|
21
|
-
|
|
22
|
+
const { blockId, slot } = target;
|
|
23
|
+
const op = slot
|
|
24
|
+
? { type: 'update', id: blockId, slotClassName: { [slot]: normalized || null } }
|
|
25
|
+
: { type: 'update', id: blockId, className: normalized || null };
|
|
26
|
+
runtime.store.apply(op, { mergeKey });
|
|
22
27
|
}
|
|
23
28
|
/** Returns an error message when the class model refuses the value. */
|
|
24
|
-
export function writeStyle(runtime,
|
|
25
|
-
const before = currentClassName(runtime,
|
|
29
|
+
export function writeStyle(runtime, target, variant, tokens, property, value, options) {
|
|
30
|
+
const before = currentClassName(runtime, target);
|
|
26
31
|
let next;
|
|
27
32
|
try {
|
|
28
33
|
next = setStyleValue(before, property, variant, value, { ...options, tokens });
|
|
@@ -33,6 +38,6 @@ export function writeStyle(runtime, blockId, variant, tokens, property, value, o
|
|
|
33
38
|
if (next === before)
|
|
34
39
|
return null;
|
|
35
40
|
// Edits to one property at one variant within a second become one undo step (sliders, typing).
|
|
36
|
-
writeClassName(runtime,
|
|
41
|
+
writeClassName(runtime, target, next, `style:${target.blockId}:${target.slot ?? ''}:${property}:${variantKey(variant)}`);
|
|
37
42
|
return null;
|
|
38
43
|
}
|
|
@@ -47,7 +47,7 @@ function useEditBreakpoint() {
|
|
|
47
47
|
*/
|
|
48
48
|
export function OverrideMark({ prop }) {
|
|
49
49
|
const runtime = useRuntime();
|
|
50
|
-
const { blockId, tokens, error } = useStyles();
|
|
50
|
+
const { blockId, slot, tokens, error } = useStyles();
|
|
51
51
|
const { def, override } = useProp(prop);
|
|
52
52
|
const edit = useEditBreakpoint();
|
|
53
53
|
const pop = usePopover('auto');
|
|
@@ -60,7 +60,7 @@ export function OverrideMark({ prop }) {
|
|
|
60
60
|
edit(breakpoint);
|
|
61
61
|
}, children: ["Edit ", breakpoint] }), _jsxs("button", { type: "button", className: "builder-styles__button", onClick: () => {
|
|
62
62
|
pop.hide();
|
|
63
|
-
error.set(writeStyle(runtime, blockId, override.variant, tokens, prop, null));
|
|
63
|
+
error.set(writeStyle(runtime, { blockId, slot }, override.variant, tokens, prop, null));
|
|
64
64
|
}, children: ["Remove ", override.className] })] })] })] }));
|
|
65
65
|
}
|
|
66
66
|
/** True when any of `props` has a value at the current variant (set, from a shorthand, or inherited). */
|
|
@@ -13,7 +13,7 @@ import { propertiesIn, propertyDef } from './model.js';
|
|
|
13
13
|
// user's own open and close choices last while the block stays selected.
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
const TEXT_TYPES = new Set(['heading', 'text', 'richText', 'quote', 'button', 'list', 'listItem', 'link', 'field']);
|
|
16
|
-
const CONTAINER_TYPES = new Set(['stack', 'grid', 'collectionList']);
|
|
16
|
+
const CONTAINER_TYPES = new Set(['stack', 'grid', 'collectionList', 'repeat']);
|
|
17
17
|
function mainGroup(blockType) {
|
|
18
18
|
if (TEXT_TYPES.has(blockType))
|
|
19
19
|
return 'typography';
|
|
@@ -298,6 +298,60 @@
|
|
|
298
298
|
padding: 0 0 10px;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
// Site classes: the site's own @utility classes as toggle buttons, by group.
|
|
302
|
+
.builder-styles__presets {
|
|
303
|
+
display: flex;
|
|
304
|
+
flex-direction: column;
|
|
305
|
+
gap: 4px;
|
|
306
|
+
min-width: 0;
|
|
307
|
+
margin: 0;
|
|
308
|
+
padding: 0;
|
|
309
|
+
border: 0;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.builder-styles__presets-title {
|
|
313
|
+
margin: 4px 0 0;
|
|
314
|
+
padding: 0;
|
|
315
|
+
color: var(--theme-elevation-500);
|
|
316
|
+
font-size: var(--be-text-s, 11px);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.builder-styles__presets-list {
|
|
320
|
+
display: flex;
|
|
321
|
+
flex-wrap: wrap;
|
|
322
|
+
gap: 4px;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.builder-styles__preset {
|
|
326
|
+
display: inline-flex;
|
|
327
|
+
align-items: baseline;
|
|
328
|
+
gap: 6px;
|
|
329
|
+
min-height: var(--bs-h);
|
|
330
|
+
padding: 2px 8px;
|
|
331
|
+
border: 1px solid var(--bs-border);
|
|
332
|
+
border-radius: var(--style-radius-s, 4px);
|
|
333
|
+
background: var(--theme-elevation-50);
|
|
334
|
+
color: var(--theme-text);
|
|
335
|
+
font: inherit;
|
|
336
|
+
text-align: left;
|
|
337
|
+
cursor: pointer;
|
|
338
|
+
|
|
339
|
+
&:hover {
|
|
340
|
+
border-color: var(--theme-elevation-300);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&[aria-pressed='true'] {
|
|
344
|
+
border-color: var(--theme-elevation-800);
|
|
345
|
+
background: var(--theme-elevation-800);
|
|
346
|
+
color: var(--theme-elevation-0);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.builder-styles__preset-name {
|
|
351
|
+
opacity: 0.7;
|
|
352
|
+
font-size: var(--be-text-s, 11px);
|
|
353
|
+
}
|
|
354
|
+
|
|
301
355
|
// Rows in a sub-section keep the panel's columns; only the label text steps in.
|
|
302
356
|
.builder-styles__sub-body {
|
|
303
357
|
display: flex;
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { Field } from 'payload';
|
|
3
|
-
import type { BindingField, Block } from '../../../core/types.js';
|
|
3
|
+
import type { BindingField, Block, TemplateContext } from '../../../core/types.js';
|
|
4
4
|
import './templates.scss';
|
|
5
|
-
/** Where the selected block's bindings read from: the template's document, or each
|
|
5
|
+
/** Where the selected block's bindings read from: the template's document, each list item, or each repeat row. */
|
|
6
6
|
export type BindingScope = {
|
|
7
|
-
kind: 'template' | 'list';
|
|
7
|
+
kind: 'template' | 'list' | 'row';
|
|
8
8
|
/** Null when the template has no target yet, or the list has no collection. */
|
|
9
9
|
collection: string | null;
|
|
10
10
|
fields: BindingField[];
|
|
11
|
-
/** The document previews read from: the template's sample,
|
|
11
|
+
/** The document previews read from: the template's sample, the list's first item, or the first row (`previewDoc`). */
|
|
12
12
|
sample: Record<string, unknown> | null;
|
|
13
|
+
/** The same sample as a binding context, for expression previews. */
|
|
14
|
+
context: TemplateContext | null;
|
|
13
15
|
sampleTitle: string;
|
|
14
16
|
loading: boolean;
|
|
17
|
+
/** Repeats only: the field whose rows repeat, e.g. "faqs". */
|
|
18
|
+
rowPath?: string;
|
|
15
19
|
};
|
|
16
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The binding scope of a block, or null when nothing can be bound (a normal page, outside lists).
|
|
22
|
+
* Inside repeats the scope narrows to the row: the row's fields, `$item`, `$index`, `$parent` and
|
|
23
|
+
* `$page`, and the first row of the sample.
|
|
24
|
+
*/
|
|
17
25
|
export declare function useBindingScope(block: Block): BindingScope | null;
|
|
18
26
|
/** Wraps a block's content fields: every field below can show binding controls. */
|
|
19
27
|
export declare function BindingScopeProvider({ block, prefix, children }: {
|