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
|
@@ -5,13 +5,13 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
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,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.
|
package/dist/ai/prompt.js
CHANGED
|
@@ -49,6 +49,11 @@ function stylingGuide(tokens) {
|
|
|
49
49
|
lines.push(`- Shadows (shadow-<name>): ${names(tokens.shadows)}.`);
|
|
50
50
|
if (tokens.containers.length > 0)
|
|
51
51
|
lines.push(`- Container widths (max-w-<name>): ${names(tokens.containers)}.`);
|
|
52
|
+
const site = tokens.siteClasses ?? [];
|
|
53
|
+
if (site.length > 0) {
|
|
54
|
+
const list = site.slice(0, 80).map((c) => (c.label ? `${c.name} (${c.group ? `${c.group}: ` : ''}${c.label})` : c.name));
|
|
55
|
+
lines.push(`- The site's own classes (its look; prefer them over rebuilding the same look from utilities): ${list.join(', ')}.`);
|
|
56
|
+
}
|
|
52
57
|
return lines.join('\n');
|
|
53
58
|
}
|
|
54
59
|
/** When and how to use animations. The presets and options are in the layout guide (MOTION), generated from the core list. */
|
|
@@ -60,6 +65,7 @@ const ANIMATIONS_GUIDE = [
|
|
|
60
65
|
'- Grids and lists of cards: "enter" with stagger 60-120 on the grid or list block. The card blocks then play in turn, so give the cards no motion of their own.',
|
|
61
66
|
'- Cards that link, and buttons: hover { preset: "lift" } and press { preset: "shrink" }.',
|
|
62
67
|
'- scroll "parallax" only on decorative images. "loop" (float, pulse) rarely, on one small decorative block.',
|
|
68
|
+
'- Stacked cards: give each card the classes "sticky top-24 origin-top" and scroll { preset: "recede" }, except the last card.',
|
|
63
69
|
'- In "update", `motion` merges per kind: a kind you send replaces that kind, null removes a kind, kinds you leave out stay. motion: null removes all animations. To remove an animation the user dislikes, send null for its kind.',
|
|
64
70
|
].join('\n');
|
|
65
71
|
const SAVED_SECTIONS_NOTE = 'Sections people saved on this site are not in this catalog. When there are any, <editor_context> lists them. Insert them with insertSection { sectionId: "saved:<id>" } like catalog sections.';
|
|
@@ -70,12 +76,12 @@ function sectionCatalog(sections, saved) {
|
|
|
70
76
|
: 'SECTION CATALOG\nThis site has no ready-made sections. Build from blocks.';
|
|
71
77
|
}
|
|
72
78
|
const entries = sections.map((s) => {
|
|
73
|
-
const head = `## ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}`;
|
|
79
|
+
const head = `## ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}${s.variantOf ? ` [variant of ${s.variantOf}]` : ''}`;
|
|
74
80
|
const description = s.description ? `\n${s.description}` : '';
|
|
75
81
|
return `${head}${description}\n${outline(s.blocks).join('\n')}`;
|
|
76
82
|
});
|
|
77
83
|
return [
|
|
78
|
-
'SECTION CATALOG. Ready-made, designed sections. Insert one with insertSection { sectionId }. The outline shows its blocks (type and start of the text). listSections { full: true } returns the full JSON.' +
|
|
84
|
+
'SECTION CATALOG. Ready-made, designed sections. Insert one with insertSection { sectionId }. The outline shows its blocks (type and start of the text). A variant ("hero/split") is another version of the section before it: pick the one that fits. listSections { full: true } returns the full JSON.' +
|
|
79
85
|
(saved ? `\n${SAVED_SECTIONS_NOTE}` : ''),
|
|
80
86
|
...entries,
|
|
81
87
|
].join('\n\n');
|
package/dist/ai/tools.js
CHANGED
|
@@ -154,9 +154,11 @@ const POSITION_SCHEMA = {
|
|
|
154
154
|
const MOTION_TEXT = 'Animations: { enter?, hover?, press?, scroll?, loop? }, each kind { preset, ...options }. Presets: ' +
|
|
155
155
|
MOTION_KINDS.map((kind) => `${kind} ${MOTION_SPECS[kind].presets.join('|')}`).join('; ') +
|
|
156
156
|
'. Example: { "enter": { "preset": "fade-up", "stagger": 80 } }.';
|
|
157
|
+
const ATTRS_TEXT = 'HTML attributes { id?, ariaLabel?, ariaHidden? }: id is an anchor for "#id" links, unique in the layout (letters, digits, - and _, starting with a letter); ariaLabel is the name screen readers read; ariaHidden true hides a decorative block from screen readers.';
|
|
158
|
+
const SLOT_CLASS_TEXT = 'Tailwind classes of a slot\'s own element, by slot name, e.g. { "empty": "col-span-full" }. Only slots marked "classes" in the block catalog take them.';
|
|
157
159
|
const BLOCK_SCHEMA = {
|
|
158
160
|
type: 'object',
|
|
159
|
-
description: 'A block: { id?, type, props?, className?, slots?, bindings?, hidden?, label?, motion? }. Children in slots have the same shape. `label` names the block for editors (e.g. "Hero"); give each top-level section one. Ids you leave out are generated; the tool result lists them.',
|
|
161
|
+
description: 'A block: { id?, type, props?, className?, slots?, bindings?, hidden?, label?, motion?, attrs?, slotClassName? }. Children in slots have the same shape. `label` names the block for editors (e.g. "Hero"); give each top-level section one. Ids you leave out are generated; the tool result lists them.',
|
|
160
162
|
properties: {
|
|
161
163
|
id: { type: 'string' },
|
|
162
164
|
type: { type: 'string' },
|
|
@@ -167,6 +169,8 @@ const BLOCK_SCHEMA = {
|
|
|
167
169
|
hidden: { type: 'boolean' },
|
|
168
170
|
label: { type: 'string', description: 'Name for editors (outline). Never rendered.' },
|
|
169
171
|
motion: { type: 'object', description: MOTION_TEXT },
|
|
172
|
+
attrs: { type: 'object', description: ATTRS_TEXT },
|
|
173
|
+
slotClassName: { type: 'object', description: SLOT_CLASS_TEXT },
|
|
170
174
|
},
|
|
171
175
|
required: ['type'],
|
|
172
176
|
};
|
|
@@ -202,6 +206,8 @@ const FLAT_OPERATIONS_SCHEMA = {
|
|
|
202
206
|
type: ['object', 'null'],
|
|
203
207
|
description: `insert (inside block) and update: ${MOTION_TEXT} update merges per kind: a kind replaces that kind, null removes it, kinds left out stay. null removes all.`,
|
|
204
208
|
},
|
|
209
|
+
attrs: { type: ['object', 'null'], description: `update: ${ATTRS_TEXT} A key replaces that key, null removes it; attrs: null removes all.` },
|
|
210
|
+
slotClassName: { type: 'object', description: `update: ${SLOT_CLASS_TEXT} Merges per slot; null removes a slot's classes.` },
|
|
205
211
|
newId: { type: 'string' },
|
|
206
212
|
},
|
|
207
213
|
required: ['type'],
|
|
@@ -280,7 +286,7 @@ export function toolDefinitions(env) {
|
|
|
280
286
|
'- move { id, to }: move a block (with children).',
|
|
281
287
|
'- remove { id }: delete a block and its children.',
|
|
282
288
|
'- duplicate { id, newId? }: copy a block right after itself.',
|
|
283
|
-
'- update { id, props?, unsetProps?, className?, hidden?, bindings?, label?, motion? }: props and bindings are merged (shallow); className REPLACES all classes, so send the full list; null removes it; a null binding removes that binding; label renames the block for editors (null removes it); motion merges per kind (a kind you send replaces that kind, null removes a kind, null alone removes all animations).',
|
|
289
|
+
'- update { id, props?, unsetProps?, className?, hidden?, bindings?, label?, motion?, attrs?, slotClassName? }: props and bindings are merged (shallow); className REPLACES all classes, so send the full list; null removes it; a null binding removes that binding; label renames the block for editors (null removes it); motion merges per kind (a kind you send replaces that kind, null removes a kind, null alone removes all animations); attrs (HTML id, ariaLabel, ariaHidden) merges per key, null removes a key; slotClassName merges per slot (null removes).',
|
|
284
290
|
'Position: { parentId (null = page root), slot? (default "children"), index (final index in the target list) }.',
|
|
285
291
|
'On success the result lists the changed ids and any warnings (e.g. a required prop is empty). On error nothing changes and the error names the failing operation; fix it and call again.',
|
|
286
292
|
'Example (ids come from the layout; block types and props from the block catalog): change a heading, then add a text block after it in the same section:',
|
|
@@ -313,6 +319,8 @@ export function toolDefinitions(env) {
|
|
|
313
319
|
type: ['object', 'null'],
|
|
314
320
|
description: `${MOTION_TEXT} Merges per kind: a kind replaces that kind, null removes it, kinds left out stay. null removes all.`,
|
|
315
321
|
},
|
|
322
|
+
attrs: { type: ['object', 'null'], description: `${ATTRS_TEXT} A key replaces that key, null removes it. null removes all.` },
|
|
323
|
+
slotClassName: { type: 'object', description: `${SLOT_CLASS_TEXT} Merges per slot; null removes a slot's classes.` },
|
|
316
324
|
},
|
|
317
325
|
required: ['type', 'id'],
|
|
318
326
|
},
|
|
@@ -626,6 +634,7 @@ export async function runTool(name, rawInput, workspace, env) {
|
|
|
626
634
|
id: s.id,
|
|
627
635
|
label: s.label,
|
|
628
636
|
...(s.savedId !== undefined ? { saved: true } : {}),
|
|
637
|
+
...(s.variantOf ? { variantOf: s.variantOf } : {}),
|
|
629
638
|
...(s.category ? { category: s.category } : {}),
|
|
630
639
|
...(input.full === true ? { blocks: s.blocks } : {}),
|
|
631
640
|
})), `Looked at ${list.length} section${list.length === 1 ? '' : 's'}`);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BlockDefinition } from '../../core/types.js';
|
|
2
|
+
export declare const CAROUSEL_BLOCK = "carousel";
|
|
3
|
+
/**
|
|
4
|
+
* Classes the carousel component adds itself: how the track moves its slides and where the
|
|
5
|
+
* controls sit. A single child of the track (a collection list or a repeat) is unwrapped with
|
|
6
|
+
* `display: contents`, so its items are the slides. No colours or sizes: those come from the
|
|
7
|
+
* block's className (see `CAROUSEL_CLASS`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const CAROUSEL_CLASS_MAP: {
|
|
10
|
+
scroll: string;
|
|
11
|
+
fade: string;
|
|
12
|
+
/** Until the script has counted the slides, only the first one shows. */
|
|
13
|
+
fadeBefore: string;
|
|
14
|
+
fadeReady: string;
|
|
15
|
+
controls: string;
|
|
16
|
+
dots: string;
|
|
17
|
+
arrows: string;
|
|
18
|
+
button: string;
|
|
19
|
+
icon: string;
|
|
20
|
+
};
|
|
21
|
+
/** The carousel's control labels and their English defaults. */
|
|
22
|
+
export declare const CAROUSEL_LABELS: {
|
|
23
|
+
previousLabel: string;
|
|
24
|
+
nextLabel: string;
|
|
25
|
+
pauseLabel: string;
|
|
26
|
+
playLabel: string;
|
|
27
|
+
dotLabel: string;
|
|
28
|
+
slideLabel: string;
|
|
29
|
+
carouselRole: string;
|
|
30
|
+
slideRole: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function carouselBlock(): BlockDefinition;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { defineBlock } from '../../core/blocks.js';
|
|
2
|
+
import { classesOf, classMap, labelsField, labelsHelp } from './shared.js';
|
|
3
|
+
export const CAROUSEL_BLOCK = 'carousel';
|
|
4
|
+
/**
|
|
5
|
+
* Classes the carousel component adds itself: how the track moves its slides and where the
|
|
6
|
+
* controls sit. A single child of the track (a collection list or a repeat) is unwrapped with
|
|
7
|
+
* `display: contents`, so its items are the slides. No colours or sizes: those come from the
|
|
8
|
+
* block's className (see `CAROUSEL_CLASS`).
|
|
9
|
+
*/
|
|
10
|
+
export const CAROUSEL_CLASS_MAP = classMap({
|
|
11
|
+
scroll: 'flex snap-x snap-mandatory overflow-x-auto overscroll-x-contain [scrollbar-width:none] *:shrink-0 *:snap-start ' +
|
|
12
|
+
'[&>*:only-child]:contents [&>*:only-child>*]:shrink-0 [&>*:only-child>*]:snap-start',
|
|
13
|
+
fade: 'grid *:col-start-1 *:row-start-1 *:transition-opacity *:duration-500 motion-reduce:*:transition-none ' +
|
|
14
|
+
'[&>*:only-child]:contents [&>*:only-child>*]:col-start-1 [&>*:only-child>*]:row-start-1 ' +
|
|
15
|
+
'[&>*:only-child>*]:transition-opacity [&>*:only-child>*]:duration-500 motion-reduce:[&>*:only-child>*]:transition-none',
|
|
16
|
+
/** Until the script has counted the slides, only the first one shows. */
|
|
17
|
+
fadeBefore: '[&>*:not(:first-child)]:opacity-0 [&>*:only-child>*:not(:first-child)]:opacity-0',
|
|
18
|
+
fadeReady: '[&_[data-slide-off]]:pointer-events-none [&_[data-slide-off]]:opacity-0',
|
|
19
|
+
controls: 'flex flex-wrap items-center justify-between gap-4',
|
|
20
|
+
dots: 'flex flex-wrap items-center',
|
|
21
|
+
arrows: 'ms-auto flex items-center gap-2',
|
|
22
|
+
button: 'inline-flex cursor-pointer items-center justify-center disabled:cursor-default',
|
|
23
|
+
icon: 'size-5',
|
|
24
|
+
});
|
|
25
|
+
const CAROUSEL_CLASS = 'flex flex-col gap-4 [&_[data-carousel-track]]:gap-4 [&_[data-carousel-arrow]]:size-11 [&_[data-carousel-arrow]]:rounded-full ' +
|
|
26
|
+
'[&_[data-carousel-arrow]]:border [&_[data-carousel-arrow]:disabled]:opacity-30 [&_[data-carousel-dot]]:size-6 ' +
|
|
27
|
+
'[&_[data-carousel-dot]]:after:size-2 [&_[data-carousel-dot]]:after:rounded-full [&_[data-carousel-dot]]:after:bg-current ' +
|
|
28
|
+
'[&_[data-carousel-dot]]:after:opacity-30 [&_[data-carousel-dot][aria-current=true]]:after:opacity-100 ' +
|
|
29
|
+
'[&_[data-carousel-pause]]:text-sm [&_[data-carousel-pause]]:underline';
|
|
30
|
+
/** The carousel's control labels and their English defaults. */
|
|
31
|
+
export const CAROUSEL_LABELS = {
|
|
32
|
+
previousLabel: 'Previous slide',
|
|
33
|
+
nextLabel: 'Next slide',
|
|
34
|
+
pauseLabel: 'Pause',
|
|
35
|
+
playLabel: 'Play',
|
|
36
|
+
dotLabel: 'Slide {n}',
|
|
37
|
+
slideLabel: '{n} of {count}',
|
|
38
|
+
carouselRole: 'carousel',
|
|
39
|
+
slideRole: 'slide',
|
|
40
|
+
};
|
|
41
|
+
const LABEL_NAMES = {
|
|
42
|
+
previousLabel: 'Previous button',
|
|
43
|
+
nextLabel: 'Next button',
|
|
44
|
+
pauseLabel: 'Pause button',
|
|
45
|
+
playLabel: 'Play button',
|
|
46
|
+
dotLabel: 'Each dot',
|
|
47
|
+
slideLabel: 'Each slide',
|
|
48
|
+
carouselRole: 'Name of the kind "carousel"',
|
|
49
|
+
slideRole: 'Name of the kind "slide"',
|
|
50
|
+
};
|
|
51
|
+
/** Content of an arrow button: an icon or a short text. */
|
|
52
|
+
const ARROW_CONTENT = ['icon', 'text', 'image'];
|
|
53
|
+
export function carouselBlock() {
|
|
54
|
+
return defineBlock({
|
|
55
|
+
type: CAROUSEL_BLOCK,
|
|
56
|
+
label: 'Carousel',
|
|
57
|
+
icon: 'right',
|
|
58
|
+
category: 'Interactive',
|
|
59
|
+
fields: [
|
|
60
|
+
{
|
|
61
|
+
name: 'mode',
|
|
62
|
+
type: 'select',
|
|
63
|
+
label: 'Movement',
|
|
64
|
+
defaultValue: 'scroll',
|
|
65
|
+
options: [
|
|
66
|
+
{ label: 'Swipe and scroll', value: 'scroll' },
|
|
67
|
+
{ label: 'Fade, one slide at a time', value: 'fade' },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{ name: 'arrows', type: 'checkbox', label: 'Arrows', defaultValue: true },
|
|
71
|
+
{ name: 'dots', type: 'checkbox', label: 'Dots', defaultValue: false },
|
|
72
|
+
{ name: 'loop', type: 'checkbox', label: 'Back to the start after the last slide', defaultValue: false },
|
|
73
|
+
{
|
|
74
|
+
name: 'autoplay',
|
|
75
|
+
type: 'number',
|
|
76
|
+
label: 'Autoplay every (ms)',
|
|
77
|
+
defaultValue: 0,
|
|
78
|
+
min: 0,
|
|
79
|
+
admin: {
|
|
80
|
+
description: '0 is off. With autoplay the carousel shows a pause button. It also stops while the pointer is over it, while it has ' +
|
|
81
|
+
'focus, and when the visitor asks for less motion.',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{ name: 'label', type: 'text', label: 'Label for screen readers', defaultValue: 'Carousel', localized: true },
|
|
85
|
+
labelsField(CAROUSEL_LABELS, LABEL_NAMES),
|
|
86
|
+
],
|
|
87
|
+
slots: {
|
|
88
|
+
slides: { label: 'Slides', styles: true },
|
|
89
|
+
previous: { label: 'Previous button', allow: ARROW_CONTENT, max: 1 },
|
|
90
|
+
next: { label: 'Next button', allow: ARROW_CONTENT, max: 1 },
|
|
91
|
+
},
|
|
92
|
+
defaultClassName: CAROUSEL_CLASS,
|
|
93
|
+
classes: classesOf(CAROUSEL_CLASS_MAP),
|
|
94
|
+
ai: {
|
|
95
|
+
description: 'Slides that swipe sideways (mode "scroll") or fade one into the next (mode "fade"), with optional arrows, dots, loop and ' +
|
|
96
|
+
'autoplay. Each direct child of the "slides" slot is one slide; give each slide its width with its own className ' +
|
|
97
|
+
'("w-[85%] md:w-1/3"). A single collectionList or repeat child makes each of its items a slide (set the width on the item). ' +
|
|
98
|
+
'The optional "previous" and "next" slots hold the arrow content (an icon); empty, they show a chevron. Style from the ' +
|
|
99
|
+
'carousel className: [&_[data-carousel-track]]: for the track (the gap between slides), [&_[data-carousel-arrow]]: for ' +
|
|
100
|
+
'the arrows, [&_[data-carousel-dot]]: for the dots (the current dot has aria-current="true"), [&_[data-carousel-controls]]: ' +
|
|
101
|
+
'for the row of controls, [&_[data-carousel-pause]]: for the pause button that autoplay adds. It is a <section> region with aria-roledescription "carousel"; each slide gets an "i of n" label. The canvas ' +
|
|
102
|
+
'always scrolls and never autoplays.' +
|
|
103
|
+
labelsHelp(CAROUSEL_LABELS) +
|
|
104
|
+
' {n} is the slide number and {count} the number of slides. "carouselRole" and "slideRole" are the aria-roledescription values.',
|
|
105
|
+
example: {
|
|
106
|
+
type: CAROUSEL_BLOCK,
|
|
107
|
+
props: { mode: 'scroll', arrows: true, dots: true, label: 'Reviews' },
|
|
108
|
+
className: CAROUSEL_CLASS,
|
|
109
|
+
slots: {
|
|
110
|
+
slides: [
|
|
111
|
+
{
|
|
112
|
+
id: 'b_example_1',
|
|
113
|
+
type: 'stack',
|
|
114
|
+
className: 'flex w-[85%] flex-col gap-2 rounded-lg border p-6 md:w-1/3',
|
|
115
|
+
slots: { children: [{ id: 'b_example_2', type: 'text', props: { text: 'A slide.' } }] },
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BlockDefinition } from '../../core/types.js';
|
|
2
|
+
export declare const DISCLOSURE_BLOCK = "disclosure";
|
|
3
|
+
export declare const ACCORDION_BLOCK = "accordion";
|
|
4
|
+
/**
|
|
5
|
+
* Classes the disclosure component adds itself. `animate`: the browser animates the content box
|
|
6
|
+
* (`::details-content`) to `height: auto`; off with reduced motion and in browsers without it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DISCLOSURE_CLASS_MAP: {
|
|
9
|
+
summary: string;
|
|
10
|
+
animate: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function disclosureBlock(): BlockDefinition;
|
|
13
|
+
export declare function accordionBlock(): BlockDefinition;
|