payload-canvas 0.3.0-next.1 → 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 +522 -39
- package/dist/admin/BuilderTab.js +1 -1
- package/dist/admin/diff/LayoutDiff.js +3 -3
- package/dist/admin/diff/changes.js +8 -0
- package/dist/admin/diff/layoutDiff.scss +48 -48
- package/dist/admin/editor/DragLayer.js +1 -1
- package/dist/admin/editor/InlineToolbar.js +1 -1
- package/dist/admin/editor/Inspector.js +50 -5
- package/dist/admin/editor/Outline.js +13 -11
- package/dist/admin/editor/Overlay.js +1 -1
- package/dist/admin/editor/actions.d.ts +9 -1
- package/dist/admin/editor/actions.js +38 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +1 -1
- package/dist/admin/editor/assistant/ConnectAgents.js +1 -1
- package/dist/admin/editor/assistant/assistant.scss +65 -65
- package/dist/admin/editor/dnd/dnd.scss +2 -2
- package/dist/admin/editor/editor.scss +134 -134
- package/dist/admin/editor/empty/EmptyStart.js +32 -6
- package/dist/admin/editor/empty/empty.scss +3 -3
- package/dist/admin/editor/fields/ArrayField.js +2 -2
- 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/access.d.ts +1 -1
- package/dist/admin/editor/fields/fields.scss +122 -33
- package/dist/admin/editor/fields/whereRows.d.ts +28 -0
- package/dist/admin/editor/fields/whereRows.js +118 -0
- package/dist/admin/editor/generate/GenerateImage.js +1 -1
- package/dist/admin/editor/generate/generate.scss +48 -48
- package/dist/admin/editor/icons.d.ts +1 -0
- package/dist/admin/editor/icons.js +3 -1
- package/dist/admin/editor/insert/InsertHandle.js +1 -1
- package/dist/admin/editor/layout/FrameResize.js +1 -1
- package/dist/admin/editor/layout/LeftPanel.js +1 -1
- package/dist/admin/editor/layout/layout.scss +4 -4
- package/dist/admin/editor/live/PresenceUI.js +1 -1
- package/dist/admin/editor/live/presence.scss +1 -1
- package/dist/admin/editor/locale/LocaleField.d.ts +2 -2
- package/dist/admin/editor/locale/LocaleField.js +4 -2
- package/dist/admin/editor/locale/locale.scss +12 -12
- package/dist/admin/editor/media/ImageEditor.js +1 -1
- package/dist/admin/editor/media/media.scss +23 -23
- package/dist/admin/editor/menu/Menu.js +1 -1
- package/dist/admin/editor/menu/blockMenu.js +5 -1
- package/dist/admin/editor/menu/menu.scss +16 -16
- package/dist/admin/editor/motion/MotionPanel.js +2 -2
- package/dist/admin/editor/motion/model.d.ts +2 -2
- package/dist/admin/editor/motion/model.js +2 -2
- package/dist/admin/editor/motion/motion.scss +2 -2
- package/dist/admin/editor/regions/RegionOverlay.js +1 -1
- package/dist/admin/editor/regions/RegionPane.js +1 -1
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +14 -5
- package/dist/admin/editor/runtime.js +1 -0
- package/dist/admin/editor/styles/ColorPicker.js +1 -1
- 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/VariantBar.js +1 -1
- 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 +3 -3
- package/dist/admin/editor/styles/sections.js +2 -2
- package/dist/admin/editor/styles/styles.scss +147 -93
- package/dist/admin/editor/templates/Bindable.d.ts +14 -6
- package/dist/admin/editor/templates/Bindable.js +74 -18
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/binding.d.ts +11 -4
- package/dist/admin/editor/templates/binding.js +23 -3
- package/dist/admin/editor/templates/templates.scss +90 -90
- package/dist/admin/editor/tooltip/tooltip.scss +4 -4
- package/dist/admin/editor/topbar/DocumentActions.js +1 -1
- package/dist/admin/editor/topbar/DocumentTitle.js +1 -1
- package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/ScreenDrawer.js +1 -1
- package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/screens.scss +20 -20
- package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
- package/dist/admin/editor/topbar/settingsDrawer.scss +7 -7
- package/dist/admin/editor/topbar/topbar.scss +47 -47
- package/dist/admin/editor/ui/Select.js +1 -1
- package/dist/admin/editor/ui/controls.scss +26 -26
- package/dist/admin/screen/BuilderScreen.js +1 -1
- package/dist/ai/adapters/anthropic.d.ts +2 -2
- package/dist/ai/images/service.js +1 -1
- package/dist/ai/loop.d.ts +5 -5
- 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 +28 -10
- 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 +123 -12
- 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/fieldAccess.js +1 -1
- package/dist/core/fieldHooks.d.ts +1 -1
- 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 +24 -15
- 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/live/draftAccess.js +1 -1
- package/dist/live/session.d.ts +1 -1
- package/dist/live/storage.js +4 -2
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +50 -13
- package/dist/mcp/shared.d.ts +34 -31
- package/dist/mcp/shared.js +23 -8
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +30 -12
- 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 +24 -9
- package/dist/protocol/index.d.ts +3 -1
- package/dist/react/canvas/BuilderCanvas.js +6 -4
- package/dist/react/canvas/fetchDocs.d.ts +16 -2
- package/dist/react/canvas/fetchDocs.js +42 -9
- package/dist/react/canvas/inline/rich/editor.js +1 -6
- 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/canvas/thumbnail/ThumbnailCanvas.js +1 -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/motion/style.js +1 -1
- package/dist/react/render/PayloadRoot.js +1 -1
- package/dist/react/render/RenderLayout.d.ts +1 -1
- package/dist/react/render/RenderLayout.js +77 -24
- 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 -24
- 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 +4 -4
- package/dist/react/server.js +55 -7
- package/dist/react/theme/ThemeStyle.d.ts +13 -2
- package/dist/react/theme/ThemeStyle.js +13 -3
- package/dist/theme/admin/ColorField.d.ts +2 -2
- package/dist/theme/admin/ColorField.js +2 -2
- package/dist/theme/admin/FontField.d.ts +2 -2
- package/dist/theme/admin/FontField.js +2 -2
- package/dist/theme/admin/SaveSignal.js +2 -2
- package/dist/theme/admin/fields.scss +48 -48
- package/package.json +23 -28
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
// Data binding in the block inspector: the "bind" button next to bindable props, the bound chip
|
|
4
4
|
// with a live sample value, the Field block's field picker and the collection list's inputs.
|
|
5
5
|
import { FieldLabel, SelectInput, TextInput, useConfig } from '@payloadcms/ui';
|
|
6
6
|
import { createContext, use, useCallback, useState } from 'react';
|
|
7
7
|
import { isLinkField } from '../../../blocks/link.js';
|
|
8
|
-
import { getBlockDefinition, propField } from '../../../core/index.js';
|
|
8
|
+
import { bindingValue, COLLECTION_LIST_BLOCK, getBlockDefinition, isBindingExpression, itemSources, listItemContext, propField, repeatAncestors, repeatRowContext, repeatRows, } from '../../../core/index.js';
|
|
9
9
|
import { Icon } from '../icons.js';
|
|
10
10
|
import { useRuntime } from '../runtime.js';
|
|
11
11
|
import { useEditor } from '../store.js';
|
|
12
12
|
import { usePopover } from '../styles/popover.js';
|
|
13
13
|
import { useValue } from '../valueStore.js';
|
|
14
|
-
import { bindingTrail, docTitle, FIELD_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isObviousPath, LIST_BLOCK,
|
|
14
|
+
import { bindingTrail, docTitle, FIELD_BLOCK, REPEAT_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isFieldListSource, isObviousPath, LIST_BLOCK, previewDoc, previewValue, propKind, propPathOf, URL_PATH, urlField, valueAt, } from './binding.js';
|
|
15
15
|
import { FieldPicker, fieldIcon } from './FieldPicker.js';
|
|
16
16
|
import { useCollectionLabel, useListSample, useTitleField } from './useTemplate.js';
|
|
17
17
|
import './templates.scss';
|
|
@@ -20,10 +20,44 @@ const BindingScopeContext = createContext(null);
|
|
|
20
20
|
function withUrl(kind, fields) {
|
|
21
21
|
return fields.some((f) => f.path === URL_PATH) ? fields : [urlField(kind), ...fields];
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const sameBlocks = (a, b) => a.length === b.length && a.every((block, i) => block === b[i]);
|
|
24
|
+
/**
|
|
25
|
+
* The binding scope of a block, or null when nothing can be bound (a normal page, outside lists).
|
|
26
|
+
* Inside repeats the scope narrows to the row: the row's fields, `$item`, `$index`, `$parent` and
|
|
27
|
+
* `$page`, and the first row of the sample.
|
|
28
|
+
*/
|
|
24
29
|
export function useBindingScope(block) {
|
|
25
30
|
const runtime = useRuntime();
|
|
26
|
-
const
|
|
31
|
+
const template = useValue(runtime.template);
|
|
32
|
+
const repeats = useEditor(runtime.store, (s) => repeatAncestors(s.layout, block.id), sameBlocks);
|
|
33
|
+
const nearest = repeats.findLastIndex((b) => b.type === COLLECTION_LIST_BLOCK);
|
|
34
|
+
const scope = useOuterScope(block, nearest >= 0 ? repeats[nearest] : null);
|
|
35
|
+
const rows = repeats.slice(nearest + 1);
|
|
36
|
+
if (!scope || rows.length === 0)
|
|
37
|
+
return scope;
|
|
38
|
+
const sources = runtime.config.templates?.sources ?? {};
|
|
39
|
+
const page = template.isTemplate && template.target ? sources[template.target] : undefined;
|
|
40
|
+
let fields = scope.fields;
|
|
41
|
+
let context = scope.context;
|
|
42
|
+
for (const row of rows) {
|
|
43
|
+
fields = itemSources(row, fields, sources, page);
|
|
44
|
+
const first = context ? repeatRows(context, row.props)[0] : undefined;
|
|
45
|
+
const collection = typeof row.props?.collection === 'string' ? row.props.collection : '';
|
|
46
|
+
context = first === undefined || !context ? null : repeatRowContext(first, 0, context, collection);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...scope,
|
|
50
|
+
kind: 'row',
|
|
51
|
+
fields: fields ?? [],
|
|
52
|
+
sample: context ? previewDoc(context) : null,
|
|
53
|
+
context,
|
|
54
|
+
sampleTitle: context ? docTitle(context.item) : '',
|
|
55
|
+
rowPath: typeof rows.at(-1)?.props?.path === 'string' ? rows.at(-1).props.path : '',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The scope of the template or of the nearest collection list around the block. */
|
|
59
|
+
function useOuterScope(block, list) {
|
|
60
|
+
const runtime = useRuntime();
|
|
27
61
|
const template = useValue(runtime.template);
|
|
28
62
|
const sources = runtime.config.templates?.sources ?? {};
|
|
29
63
|
const listCollection = typeof list?.props?.collection === 'string' && list.props.collection ? list.props.collection : null;
|
|
@@ -33,12 +67,16 @@ export function useBindingScope(block) {
|
|
|
33
67
|
const exclude = list?.props?.excludeCurrent !== false && template.isTemplate && template.target === listCollection ? template.sample?.id : undefined;
|
|
34
68
|
const locale = useEditor(runtime.store, (s) => s.locale);
|
|
35
69
|
const listSample = useListSample(runtime.api, list ? listCollection : null, listSort, exclude, locale);
|
|
70
|
+
const page = template.isTemplate && template.target ? sources[template.target] : undefined;
|
|
71
|
+
const pageContext = template.isTemplate && template.sample?.doc ? { collection: template.target ?? '', doc: template.sample.doc } : null;
|
|
36
72
|
if (list) {
|
|
73
|
+
const context = listSample.doc ? listItemContext(listSample.doc, 0, pageContext, listCollection ?? '') : null;
|
|
37
74
|
return {
|
|
38
75
|
kind: 'list',
|
|
39
76
|
collection: listCollection,
|
|
40
|
-
fields: listCollection ? withUrl('list', sources
|
|
41
|
-
sample:
|
|
77
|
+
fields: listCollection ? withUrl('list', itemSources(list, undefined, sources, page) ?? []) : [],
|
|
78
|
+
sample: context ? previewDoc(context) : null,
|
|
79
|
+
context,
|
|
42
80
|
sampleTitle: listSample.doc ? docTitle(listSample.doc, listTitle) : '',
|
|
43
81
|
loading: listSample.loading,
|
|
44
82
|
};
|
|
@@ -50,6 +88,7 @@ export function useBindingScope(block) {
|
|
|
50
88
|
collection: template.target,
|
|
51
89
|
fields: template.target ? withUrl('template', sources[template.target] ?? []) : [],
|
|
52
90
|
sample: template.sample?.doc ?? null,
|
|
91
|
+
context: pageContext,
|
|
53
92
|
sampleTitle: template.sample?.title ?? '',
|
|
54
93
|
loading: template.status === 'loading',
|
|
55
94
|
};
|
|
@@ -75,11 +114,13 @@ export function FieldSlot(props) {
|
|
|
75
114
|
const { block, def, scope } = ctx;
|
|
76
115
|
if (block.type === FIELD_BLOCK && propPath === 'path')
|
|
77
116
|
return _jsx(FieldPathInput, { ...props, scope: scope });
|
|
117
|
+
if (block.type === REPEAT_BLOCK && propPath === 'path')
|
|
118
|
+
return _jsx(FieldPathInput, { ...props, scope: scope, rows: true });
|
|
78
119
|
if (block.type === LIST_BLOCK && propPath === 'collection')
|
|
79
120
|
return _jsx(ListCollectionInput, { ...props });
|
|
80
121
|
if (block.type === LIST_BLOCK && propPath === 'sort')
|
|
81
122
|
return _jsx(ListSortInput, { ...props, block: block });
|
|
82
|
-
if (block.type === FIELD_BLOCK || block.type === LIST_BLOCK)
|
|
123
|
+
if (block.type === FIELD_BLOCK || block.type === LIST_BLOCK || block.type === REPEAT_BLOCK)
|
|
83
124
|
return props.children;
|
|
84
125
|
const kind = propKind(props.field);
|
|
85
126
|
if (!kind)
|
|
@@ -96,6 +137,8 @@ export function FieldSlot(props) {
|
|
|
96
137
|
return (_jsxs("div", { className: "builder-bind", children: [props.children, _jsx(BindButton, { block: block, propPath: propPath, kind: kind, scope: scope, field: props.field, label: props.label })] }));
|
|
97
138
|
}
|
|
98
139
|
function scopeTitle(scope, collectionLabel) {
|
|
140
|
+
if (scope.kind === 'row')
|
|
141
|
+
return `Fields of each row · ${scope.rowPath ?? ''}`;
|
|
99
142
|
return scope.kind === 'list' ? `Fields of each item · ${collectionLabel}` : `Fields of ${collectionLabel}`;
|
|
100
143
|
}
|
|
101
144
|
const KIND_NAMES = {
|
|
@@ -135,13 +178,21 @@ function BoundField({ field, label, children, block, propPath, bound, kind, scop
|
|
|
135
178
|
const collectionLabel = useCollectionLabel(scope?.collection ?? null);
|
|
136
179
|
const [showFallback, setShowFallback] = useState(false);
|
|
137
180
|
const fields = scope?.collection ? scope.fields : [urlField(scope?.kind ?? 'list')];
|
|
138
|
-
const
|
|
139
|
-
const
|
|
181
|
+
const expression = isBindingExpression(bound);
|
|
182
|
+
const source = expression ? { path: bound, label: bound, type: 'text' } : findBindingField(fields, bound);
|
|
183
|
+
const trail = source && !expression ? bindingTrail(fields, bound) : [bound];
|
|
140
184
|
const required = 'required' in field ? Boolean(field.required) : false;
|
|
141
|
-
return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', bound) && _jsx("code", { className: "builder-bind__chip-path", children: bound })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), source ? (_jsx(SamplePreview, { scope: scope, source: source })) : (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
|
|
185
|
+
return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', bound) && _jsx("code", { className: "builder-bind__chip-path", children: bound })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), expression ? (_jsx(ExpressionPreview, { scope: scope, binding: bound })) : source ? (_jsx(SamplePreview, { scope: scope, source: source })) : (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
|
|
142
186
|
? `${collectionLabel} has no field “${bound}”. The fallback shows instead.`
|
|
143
187
|
: 'This block is not inside a template or a collection list, so the binding has no data. Unbind it or move the block.' })), _jsxs("button", { type: "button", className: "builder-bind__fallback-toggle", "aria-expanded": showFallback, onClick: () => setShowFallback(!showFallback), children: [_jsx(Icon, { name: showFallback ? 'chevronDown' : 'chevronRight', size: 12 }), "Fallback when the field is empty"] }), showFallback && _jsx("div", { className: "builder-bind__fallback", children: children }), scope?.collection && (_jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: bound, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: bind }))] }));
|
|
144
188
|
}
|
|
189
|
+
/** The sample's value for a binding expression (a template string, a fallback chain, formatters). */
|
|
190
|
+
function ExpressionPreview({ scope, binding }) {
|
|
191
|
+
if (!scope?.context)
|
|
192
|
+
return _jsx("p", { className: "builder-bind__note", children: "A binding expression. No sample to preview." });
|
|
193
|
+
const text = previewValue(bindingValue(scope.context, binding), 'text');
|
|
194
|
+
return (_jsxs("div", { className: "builder-bind__preview", children: [_jsx("span", { className: "builder-bind__preview-from", children: "Expression" }), text.kind === 'text' ? _jsx("span", { className: "builder-bind__preview-text", children: text.text }) : _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
|
|
195
|
+
}
|
|
145
196
|
/** The sample document's value for a bound field: text, an image, or a note when it is empty. */
|
|
146
197
|
export function SamplePreview({ scope, source }) {
|
|
147
198
|
if (source.path === URL_PATH) {
|
|
@@ -150,16 +201,16 @@ export function SamplePreview({ scope, source }) {
|
|
|
150
201
|
if (!scope || scope.loading)
|
|
151
202
|
return _jsx("p", { className: "builder-bind__note", children: "Loading the sample\u2026" });
|
|
152
203
|
if (!scope.sample) {
|
|
153
|
-
return (_jsx("p", { className: "builder-bind__note", children: scope.kind === 'list' ? 'The list has no items yet.' : 'No sample document to preview.' }));
|
|
204
|
+
return (_jsx("p", { className: "builder-bind__note", children: scope.kind === 'list' ? 'The list has no items yet.' : scope.kind === 'row' ? 'The field has no rows in the sample.' : 'No sample document to preview.' }));
|
|
154
205
|
}
|
|
155
206
|
const preview = previewValue(valueAt(scope.sample, source.path), source.type);
|
|
156
|
-
const from = scope.kind === 'list' ? 'First item' : 'Sample';
|
|
207
|
+
const from = scope.kind === 'list' ? 'First item' : scope.kind === 'row' ? 'First row' : 'Sample';
|
|
157
208
|
return (_jsxs("div", { className: "builder-bind__preview", children: [_jsxs("span", { className: "builder-bind__preview-from", title: scope.sampleTitle, children: [from, ": ", scope.sampleTitle || 'untitled'] }), preview.kind === 'text' && _jsx("span", { className: "builder-bind__preview-text", children: preview.text }), preview.kind === 'image' && (_jsx("img", { className: "builder-bind__preview-image", src: preview.url, alt: preview.alt })), preview.kind === 'empty' && _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
|
|
158
209
|
}
|
|
159
|
-
/** The Field block's `path`: picks any field of the scope's document. */
|
|
160
|
-
function FieldPathInput({ value, onChange, label, children, scope }) {
|
|
210
|
+
/** The Field block's `path`: picks any field of the scope's document. `rows`: a field list's path (fields with rows). */
|
|
211
|
+
function FieldPathInput({ value, onChange, label, children, scope, rows = false }) {
|
|
161
212
|
const popover = usePopover('auto');
|
|
162
|
-
const accept = isFieldBlockSource;
|
|
213
|
+
const accept = rows ? isFieldListSource : isFieldBlockSource;
|
|
163
214
|
const collectionLabel = useCollectionLabel(scope?.collection ?? null);
|
|
164
215
|
const path = typeof value === 'string' && value ? value : null;
|
|
165
216
|
if (!scope?.collection) {
|
|
@@ -167,7 +218,9 @@ function FieldPathInput({ value, onChange, label, children, scope }) {
|
|
|
167
218
|
? 'Choose the list’s collection first. Then pick the field each item shows.'
|
|
168
219
|
: scope?.kind === 'template'
|
|
169
220
|
? 'Choose which collection this template is for. Then pick a field here.'
|
|
170
|
-
:
|
|
221
|
+
: rows
|
|
222
|
+
? 'A Field list repeats the rows of a field of the template’s document or of each list item. Use it in a template or inside a collection list.'
|
|
223
|
+
: 'A Field block shows a field of the template’s document or of each list item. Use it in a template or inside a collection list.' }), children] }));
|
|
171
224
|
}
|
|
172
225
|
const source = path ? findBindingField(scope.fields, path) : null;
|
|
173
226
|
const trail = path ? bindingTrail(scope.fields, path) : [];
|
|
@@ -219,7 +272,7 @@ function ScopeBanner({ block, scope }) {
|
|
|
219
272
|
const runtime = useRuntime();
|
|
220
273
|
const collectionLabel = useCollectionLabel(scope?.collection ?? null);
|
|
221
274
|
const singular = useCollectionLabel(scope?.collection ?? null, 'singular');
|
|
222
|
-
if (!scope || block.type === FIELD_BLOCK || block.type === LIST_BLOCK)
|
|
275
|
+
if (!scope || block.type === FIELD_BLOCK || block.type === LIST_BLOCK || block.type === REPEAT_BLOCK)
|
|
223
276
|
return null;
|
|
224
277
|
const def = getBlockDefinition(runtime.config.blocks, block.type);
|
|
225
278
|
if (!def || !hasBindableField(def.fields))
|
|
@@ -230,5 +283,8 @@ function ScopeBanner({ block, scope }) {
|
|
|
230
283
|
if (scope.kind === 'list' && !scope.collection) {
|
|
231
284
|
return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsx("p", { children: "This block is inside a collection list. Choose the list\u2019s collection to bind fields of each item." })] }));
|
|
232
285
|
}
|
|
286
|
+
if (scope.kind === 'row') {
|
|
287
|
+
return (_jsxs("div", { className: "builder-bind__banner", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsxs("p", { children: ["Repeats for each row of \u201C", scope.rowPath, "\u201D. Use ", _jsx(Icon, { name: "bind", size: 12, className: "builder-bind__inline-icon" }), " next to a field to show the row\u2019s data."] })] }));
|
|
288
|
+
}
|
|
233
289
|
return (_jsxs("div", { className: "builder-bind__banner", children: [_jsx(Icon, { name: scope.kind === 'list' ? 'collectionList' : 'template', size: 14 }), _jsxs("p", { children: [scope.kind === 'list' ? `Repeats for each ${singular.toLowerCase() || 'item'} in the list. ` : `Template for ${collectionLabel}. `, "Use ", _jsx(Icon, { name: "bind", size: 12, className: "builder-bind__inline-icon" }), " next to a field to show", ' ', scope.kind === 'list' ? 'the item’s' : 'the document’s', " data."] })] }));
|
|
234
290
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
/* oxlint-disable jsx-a11y/prefer-tag-over-role, jsx-a11y/no-noninteractive-element-to-interactive-role -- the document list is a listbox with option rows */
|
|
4
4
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
5
5
|
import { Icon } from '../icons.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FIELD_BLOCK, URL_PATH } from '../../../core/bindings.js';
|
|
2
|
-
import type { BindingField, Block, Layout } from '../../../core/types.js';
|
|
3
|
-
export { FIELD_BLOCK, URL_PATH };
|
|
1
|
+
import { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH } from '../../../core/bindings.js';
|
|
2
|
+
import type { BindingField, Block, Layout, TemplateContext } from '../../../core/types.js';
|
|
3
|
+
export { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH };
|
|
4
4
|
/** Block type of the collection list block. Blocks in its `item` slot bind to each item. */
|
|
5
5
|
export declare const LIST_BLOCK = "collectionList";
|
|
6
6
|
export declare const LIST_SLOT = "item";
|
|
7
7
|
/** The `$url` virtual field: the frontend URL of the document (each item's, inside a list). */
|
|
8
|
-
export declare function urlField(scope: 'template' | 'list'): BindingField;
|
|
8
|
+
export declare function urlField(scope: 'template' | 'list' | 'row'): BindingField;
|
|
9
9
|
export declare const URL_FIELD: BindingField;
|
|
10
10
|
/**
|
|
11
11
|
* What a block prop can show, by its Payload field type. `link` is a whole link group (bound to a
|
|
@@ -22,6 +22,8 @@ type PropField = {
|
|
|
22
22
|
export declare function propKind(field: PropField): PropKind | null;
|
|
23
23
|
/** Field block: any field with a single value. Containers are offered as their leaf fields. */
|
|
24
24
|
export declare function isFieldBlockSource(source: BindingField): boolean;
|
|
25
|
+
/** Field list block: a field with rows, an array or any hasMany field. */
|
|
26
|
+
export declare function isFieldListSource(source: BindingField): boolean;
|
|
25
27
|
/** True when a prop of `kind` can bind to `source`. Containers (group, array) never bind themselves, except for `any`. */
|
|
26
28
|
export declare function isCompatible(kind: PropKind, source: BindingField, prop?: PropField): boolean;
|
|
27
29
|
/** True when the path says nothing the label does not ("Featured image" and `featuredImage`). Then the path is not shown. */
|
|
@@ -43,6 +45,11 @@ export declare function pickerRows(fields: BindingField[], accept: (field: Bindi
|
|
|
43
45
|
export declare function findBindingField(fields: BindingField[], path: string): BindingField | null;
|
|
44
46
|
/** Labels from the root to the field, e.g. ["Author", "Name"]. Falls back to the path segments. */
|
|
45
47
|
export declare function bindingTrail(fields: BindingField[], path: string): string[];
|
|
48
|
+
/**
|
|
49
|
+
* A context as one document for previews (`valueAt`, the field picker's samples): the document's
|
|
50
|
+
* fields plus `$item`, `$index`, `$parent` and `$page` as keys.
|
|
51
|
+
*/
|
|
52
|
+
export declare function previewDoc(context: TemplateContext): Record<string, unknown>;
|
|
46
53
|
/**
|
|
47
54
|
* The value at a dot path in a document loaded with depth 1, read the same way the renderer reads
|
|
48
55
|
* it: groups, populated relationships (polymorphic pairs too) and arrays.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Pure helpers for templates and data binding in the editor: which document fields a block prop
|
|
2
2
|
// can bind to, the picker rows, and sample values for previews. No React here, so they are unit tested.
|
|
3
3
|
import { isLinkField } from '../../../blocks/link.js';
|
|
4
|
-
import { COLLECTION_LIST_BLOCK, FIELD_BLOCK, getByPath, isIsoDate, isUploadDoc, LIST_ITEM_SLOT, titleOf, toPlainText, URL_PATH, } from '../../../core/bindings.js';
|
|
5
|
-
export { FIELD_BLOCK, URL_PATH };
|
|
4
|
+
import { COLLECTION_LIST_BLOCK, FIELD_BLOCK, REPEAT_BLOCK, getByPath, isIsoDate, isUploadDoc, LIST_ITEM_SLOT, titleOf, toPlainText, URL_PATH, } from '../../../core/bindings.js';
|
|
5
|
+
export { FIELD_BLOCK, REPEAT_BLOCK, URL_PATH };
|
|
6
6
|
/** Block type of the collection list block. Blocks in its `item` slot bind to each item. */
|
|
7
7
|
export const LIST_BLOCK = COLLECTION_LIST_BLOCK;
|
|
8
8
|
export const LIST_SLOT = LIST_ITEM_SLOT;
|
|
9
9
|
/** The `$url` virtual field: the frontend URL of the document (each item's, inside a list). */
|
|
10
10
|
export function urlField(scope) {
|
|
11
|
-
return { path: URL_PATH, label: scope === '
|
|
11
|
+
return { path: URL_PATH, label: scope === 'template' ? 'URL of this document' : 'URL of this item', type: '$url' };
|
|
12
12
|
}
|
|
13
13
|
export const URL_FIELD = urlField('list');
|
|
14
14
|
/** The binding kind of a block prop, or null when the prop cannot be bound. */
|
|
@@ -59,6 +59,10 @@ const CONTAINER_TYPES = new Set(['group', 'array', 'blocks', 'tabs', 'row', 'col
|
|
|
59
59
|
export function isFieldBlockSource(source) {
|
|
60
60
|
return !CONTAINER_TYPES.has(source.type);
|
|
61
61
|
}
|
|
62
|
+
/** Field list block: a field with rows, an array or any hasMany field. */
|
|
63
|
+
export function isFieldListSource(source) {
|
|
64
|
+
return source.type === 'array' || source.hasMany === true;
|
|
65
|
+
}
|
|
62
66
|
const asList = (value) => (value === undefined ? [] : Array.isArray(value) ? value : [value]);
|
|
63
67
|
/** True when the two relationTo settings share a collection, or either one is unknown. */
|
|
64
68
|
function sameTarget(a, b) {
|
|
@@ -190,6 +194,22 @@ export function bindingTrail(fields, path) {
|
|
|
190
194
|
return path.split('.');
|
|
191
195
|
}
|
|
192
196
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
197
|
+
/**
|
|
198
|
+
* A context as one document for previews (`valueAt`, the field picker's samples): the document's
|
|
199
|
+
* fields plus `$item`, `$index`, `$parent` and `$page` as keys.
|
|
200
|
+
*/
|
|
201
|
+
export function previewDoc(context) {
|
|
202
|
+
const doc = { ...context.doc };
|
|
203
|
+
if (context.item !== undefined)
|
|
204
|
+
doc.$item = context.item;
|
|
205
|
+
if (context.index !== undefined)
|
|
206
|
+
doc.$index = context.index;
|
|
207
|
+
if (context.parent)
|
|
208
|
+
doc.$parent = context.parent;
|
|
209
|
+
if (context.page)
|
|
210
|
+
doc.$page = context.page;
|
|
211
|
+
return doc;
|
|
212
|
+
}
|
|
193
213
|
/**
|
|
194
214
|
* The value at a dot path in a document loaded with depth 1, read the same way the renderer reads
|
|
195
215
|
* it: groups, populated relationships (polymorphic pairs too) and arrays.
|