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
|
@@ -212,8 +212,16 @@ function blockDetails(ctx, from, to) {
|
|
|
212
212
|
}
|
|
213
213
|
if (!sameValue(from.motion, to.motion))
|
|
214
214
|
out.push({ kind: 'note', label: 'Animation', text: motionNote(from.motion, to.motion) });
|
|
215
|
+
for (const key of Object.keys(ATTR_NAMES)) {
|
|
216
|
+
const before = from.attrs?.[key];
|
|
217
|
+
const after = to.attrs?.[key];
|
|
218
|
+
if (before !== after)
|
|
219
|
+
out.push({ kind: 'value', label: ATTR_NAMES[key], from: attrText(before), to: attrText(after) });
|
|
220
|
+
}
|
|
215
221
|
return out;
|
|
216
222
|
}
|
|
223
|
+
const ATTR_NAMES = { id: 'HTML id', ariaLabel: 'ARIA label', ariaHidden: 'Hidden from screen readers' };
|
|
224
|
+
const attrText = (value) => (value === true ? 'Yes' : value === undefined ? '' : String(value));
|
|
217
225
|
/** Ids of `list` that keep their relative order (longest common subsequence with `other`). */
|
|
218
226
|
function stableIds(list, other) {
|
|
219
227
|
const n = list.length;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { CheckboxInput } from '@payloadcms/ui';
|
|
3
|
+
import { CheckboxInput, TextInput } from '@payloadcms/ui';
|
|
4
4
|
import { useDeferredValue, useEffect, useState } from 'react';
|
|
5
|
-
import { findBlock, getBlockDefinition } from '../../core/index.js';
|
|
5
|
+
import { findBlock, getBlockDefinition, htmlIdProblem, htmlIdsOf } from '../../core/index.js';
|
|
6
6
|
import { BlockIcon, Icon } from './icons.js';
|
|
7
7
|
import { blockMenuEntries } from './menu/blockMenu.js';
|
|
8
8
|
import { MenuButton } from './menu/Menu.js';
|
|
@@ -14,12 +14,14 @@ import { LocaleNote } from './locale/LocaleField.js';
|
|
|
14
14
|
import { MotionPanel } from './motion/MotionPanel.js';
|
|
15
15
|
import { AssistantPanel } from './assistant/AssistantPanel.js';
|
|
16
16
|
import { useAccessRefresh } from './fields/access.js';
|
|
17
|
+
import { InputError } from './fields/CheckedInputs.js';
|
|
17
18
|
import { BlockContentFields } from './renderField.js';
|
|
18
19
|
import { useRuntime } from './runtime.js';
|
|
19
20
|
import { storesBuilderData } from './actions.js';
|
|
20
21
|
import { shortcutList } from './shortcuts.js';
|
|
21
22
|
import { useEditor } from './store.js';
|
|
22
23
|
import { StylesPanel } from './styles/StylesPanel.js';
|
|
24
|
+
import { Select } from './ui/Select.js';
|
|
23
25
|
import { usePayloadControlNames } from './ui/payloadA11y.js';
|
|
24
26
|
import { useOptionalValue, useValue, useValueSelector } from './valueStore.js';
|
|
25
27
|
import { RegionPane } from './regions/RegionPane.js';
|
|
@@ -99,9 +101,10 @@ function BlockPane() {
|
|
|
99
101
|
{ id: 'content', label: 'Content' },
|
|
100
102
|
{ id: 'styles', label: 'Styles' },
|
|
101
103
|
{ id: 'motion', label: 'Motion' },
|
|
104
|
+
{ id: 'advanced', label: 'Advanced' },
|
|
102
105
|
]
|
|
103
106
|
: // A Payload blocks field holds the blocks' own fields only.
|
|
104
|
-
[{ id: 'content', label: 'Content' }] }), tab === 'content' && _jsx(BlockContentFields, { block: block }), tab === 'styles' && storesBuilderData(runtime) && _jsx(StyleFields, { block: block }), tab === 'motion' && storesBuilderData(runtime) && _jsx(MotionPanel, { blockId: block.id, blockType: block.type, motion: block.motion })] }, block.id));
|
|
107
|
+
[{ id: 'content', label: 'Content' }] }), tab === 'content' && _jsx(BlockContentFields, { block: block }), tab === 'styles' && storesBuilderData(runtime) && _jsx(StyleFields, { block: block }), tab === 'motion' && storesBuilderData(runtime) && _jsx(MotionPanel, { blockId: block.id, blockType: block.type, motion: block.motion }), tab === 'advanced' && storesBuilderData(runtime) && _jsx(AdvancedFields, { block: block })] }, block.id));
|
|
105
108
|
}
|
|
106
109
|
/** What stopped the last publish, for this block. */
|
|
107
110
|
function BlockProblems({ blockId }) {
|
|
@@ -134,5 +137,47 @@ function BlockHeader({ block }) {
|
|
|
134
137
|
function StyleFields({ block }) {
|
|
135
138
|
const runtime = useRuntime();
|
|
136
139
|
const def = getBlockDefinition(runtime.config.blocks, block.type);
|
|
137
|
-
|
|
140
|
+
// Slots with an element of their own (`styles: true`) are style targets next to the block.
|
|
141
|
+
const styledSlots = Object.entries(def?.slots ?? {}).filter(([, slot]) => slot.styles);
|
|
142
|
+
const [target, setTarget] = useState(null);
|
|
143
|
+
const slot = target && styledSlots.some(([name]) => name === target) ? target : null;
|
|
144
|
+
const blockStyles = def?.styles !== false;
|
|
145
|
+
return (_jsxs("div", { className: "builder-editor__fields", children: [styledSlots.length > 0 && (_jsx(Select, { "aria-label": "Style target", emptyLabel: blockStyles ? 'This block' : undefined, placeholder: "Pick a slot", value: slot, onValueChange: setTarget, options: styledSlots.map(([name, s]) => ({
|
|
146
|
+
value: name,
|
|
147
|
+
label: `Slot: ${s.label?.trim() || name}`,
|
|
148
|
+
...(block.slotClassName?.[name] ? { suffix: _jsx("span", { className: "builder-styles__dot", "aria-label": "has classes" }) } : {}),
|
|
149
|
+
})) })), slot ? (_jsx(StylesPanel, { block: block, slot: slot }, slot)) : !blockStyles ? (_jsx("p", { className: "builder-editor__hint", children: "This block has no style controls." })) : (_jsx(StylesPanel, { block: block })), _jsx(CheckboxInput, { id: `builder-${block.id}-hidden`, name: `builder.${block.id}.hidden`, label: "Hide on the site", checked: block.hidden === true, onToggle: (e) => runtime.store.apply({ type: 'update', id: block.id, hidden: e.target.checked }) })] }));
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The block's HTML attributes (`block.attrs`): an id for "#id" links, an ARIA label and
|
|
153
|
+
* aria-hidden. The id is stored only when it is valid and no other block of the page has it.
|
|
154
|
+
*/
|
|
155
|
+
function AdvancedFields({ block }) {
|
|
156
|
+
const runtime = useRuntime();
|
|
157
|
+
const layout = useEditor(runtime.store, (s) => s.layout);
|
|
158
|
+
const stored = block.attrs?.id ?? '';
|
|
159
|
+
// `source` is the stored id the draft belongs to: another stored id (undo, AI edit) replaces the draft.
|
|
160
|
+
const [draft, setDraft] = useState({ text: stored, source: stored });
|
|
161
|
+
if (draft.source !== stored)
|
|
162
|
+
setDraft({ text: stored, source: stored });
|
|
163
|
+
const idProblem = (text) => {
|
|
164
|
+
if (!text)
|
|
165
|
+
return null;
|
|
166
|
+
const owner = htmlIdsOf(layout.blocks).get(text);
|
|
167
|
+
if (owner && owner !== block.id)
|
|
168
|
+
return `Another block of this page has the id "${text}".`;
|
|
169
|
+
return htmlIdProblem(text);
|
|
170
|
+
};
|
|
171
|
+
const problem = idProblem(draft.text.trim());
|
|
172
|
+
const setAttr = (attrs) => runtime.store.apply({ type: 'update', id: block.id, attrs });
|
|
173
|
+
return (_jsxs("div", { className: "builder-editor__fields", children: [_jsxs("div", { children: [_jsx(TextInput, { description: 'Links to this block with "#id", for example "contact".', label: "HTML id", onChange: (e) => {
|
|
174
|
+
const text = e.target.value;
|
|
175
|
+
const id = text.trim();
|
|
176
|
+
if (id === stored || idProblem(id)) {
|
|
177
|
+
setDraft({ text, source: stored });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
setDraft({ text, source: id });
|
|
181
|
+
setAttr({ id: id || null });
|
|
182
|
+
}, path: `builder.${block.id}.attrs.id`, showError: problem !== null, value: draft.text }), problem && _jsx(InputError, { children: problem })] }), _jsx(TextInput, { description: "The name screen readers read, for example for a link that shows only an icon.", label: "ARIA label", onChange: (e) => setAttr({ ariaLabel: e.target.value || null }), path: `builder.${block.id}.attrs.ariaLabel`, value: block.attrs?.ariaLabel ?? '' }), _jsx(CheckboxInput, { id: `builder-${block.id}-aria-hidden`, name: `builder.${block.id}.attrs.ariaHidden`, label: "Hide from screen readers", checked: block.attrs?.ariaHidden === true, onToggle: (e) => setAttr({ ariaHidden: e.target.checked || null }) })] }));
|
|
138
183
|
}
|
|
@@ -14,7 +14,8 @@ import { blockPreview, blockSummary, childrenOf, customLabel, typeName } from '.
|
|
|
14
14
|
import { OUTLINE_INDENT, useRuntime } from './runtime.js';
|
|
15
15
|
import { RegionRows } from './regions/RegionRows.js';
|
|
16
16
|
import { useEditor } from './store.js';
|
|
17
|
-
import {
|
|
17
|
+
import { bindingPaths, scopeSources } from '../../core/bindings.js';
|
|
18
|
+
import { findBindingField } from './templates/binding.js';
|
|
18
19
|
import { useValue, useValueSelector } from './valueStore.js';
|
|
19
20
|
/** Visible rows, depth first. Children of collapsed containers are left out. */
|
|
20
21
|
function visibleRows(runtime, layout, collapsed) {
|
|
@@ -82,18 +83,19 @@ function brokenBindingIds(runtime, layout, templateTarget) {
|
|
|
82
83
|
return out;
|
|
83
84
|
}
|
|
84
85
|
const NO_ISSUES = [];
|
|
85
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* True when a binding of the block reads a field its document does not have (or there is no
|
|
88
|
+
* document): the template's, each list item's, or each field list row's.
|
|
89
|
+
*/
|
|
86
90
|
function hasBrokenBinding(runtime, layout, block, templateTarget) {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
91
|
+
const bindings = Object.entries(block.bindings ?? {});
|
|
92
|
+
if (bindings.length === 0)
|
|
89
93
|
return false;
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const collection = list ? listCollection : templateTarget;
|
|
93
|
-
if (!collection)
|
|
94
|
+
const fields = scopeSources(layout, block.id, runtime.config.templates?.sources ?? {}, templateTarget);
|
|
95
|
+
if (!fields)
|
|
94
96
|
return true;
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
+
// Every plain path a binding reads (templates and fallback chains have several).
|
|
98
|
+
return bindings.some(([key, binding]) => bindingPaths(key, binding).some((path) => !findBindingField(fields, path)));
|
|
97
99
|
}
|
|
98
100
|
/**
|
|
99
101
|
* The outline tree. Rows stay a flat list, which keeps them simple to measure for drop targets.
|
|
@@ -27,8 +27,16 @@ export declare function insertNewBlockAt(runtime: Runtime, type: string, to: Pos
|
|
|
27
27
|
* position was picked). Null when the parent block is gone.
|
|
28
28
|
*/
|
|
29
29
|
export declare function currentPosition(layout: Layout, to: Position): Position | null;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Inserts copies (new ids) of `blocks` as one undo step and selects the first one. A copy leaves
|
|
32
|
+
* out the HTML ids (`attrs.id`) the page already uses, so a paste or a second section stays valid.
|
|
33
|
+
*/
|
|
31
34
|
export declare function insertBlocks(runtime: Runtime, blocks: Block[], to: Position): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* "Detach section": replaces a live saved section (`sectionRef`) with a copy of its blocks, as one
|
|
37
|
+
* undo step. Later changes to the saved section no longer reach this page.
|
|
38
|
+
*/
|
|
39
|
+
export declare function detachSection(runtime: Runtime, id: string): Promise<void>;
|
|
32
40
|
export declare function duplicateBlock(runtime: Runtime, id: string): void;
|
|
33
41
|
export declare function removeBlock(runtime: Runtime, id: string): void;
|
|
34
42
|
export declare function toggleHidden(runtime: Runtime, id: string): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
// Editor actions shared by the toolbar, the overlay, the outline, the inspector, the menus and the
|
|
3
3
|
// shortcuts: insert, duplicate, remove, hide, move, copy and paste (blocks and styles).
|
|
4
|
-
import {
|
|
4
|
+
import { sectionDetachOps, sectionRefId } from '../../blocks/builtins/sectionRef.js';
|
|
5
|
+
import { createId, findBlock, findLocation, getBlockDefinition, htmlIdsOf, slotAcceptsAt, slotNames, withoutTakenHtmlIds } from '../../core/index.js';
|
|
5
6
|
import { normalizeClasses, parseStyles, setStylesOps, stylesText } from './menu/styleClipboard.js';
|
|
6
7
|
import { countText } from './counts.js';
|
|
7
8
|
/**
|
|
@@ -92,15 +93,49 @@ export function currentPosition(layout, to) {
|
|
|
92
93
|
return null;
|
|
93
94
|
return { ...to, index: Math.min(to.index, parent.slots?.[to.slot ?? 'children']?.length ?? 0) };
|
|
94
95
|
}
|
|
95
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Inserts copies (new ids) of `blocks` as one undo step and selects the first one. A copy leaves
|
|
98
|
+
* out the HTML ids (`attrs.id`) the page already uses, so a paste or a second section stays valid.
|
|
99
|
+
*/
|
|
96
100
|
export function insertBlocks(runtime, blocks, to) {
|
|
97
|
-
const fresh = blocks
|
|
101
|
+
const fresh = freshCopies(runtime, blocks);
|
|
98
102
|
const first = fresh[0];
|
|
99
103
|
if (!first)
|
|
100
104
|
return false;
|
|
101
105
|
const ops = fresh.map((block, i) => ({ type: 'insert', block, to: { ...to, index: to.index + i } }));
|
|
102
106
|
return runtime.store.apply(ops, { select: first.id });
|
|
103
107
|
}
|
|
108
|
+
/** Copies with new ids, without the HTML ids the page already uses. */
|
|
109
|
+
function freshCopies(runtime, blocks) {
|
|
110
|
+
const taken = htmlIdsOf(runtime.store.getState().layout.blocks);
|
|
111
|
+
return blocks.map((block) => {
|
|
112
|
+
const copy = withoutTakenHtmlIds(withNewIds(block), taken);
|
|
113
|
+
htmlIdsOf([copy], taken);
|
|
114
|
+
return copy;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* "Detach section": replaces a live saved section (`sectionRef`) with a copy of its blocks, as one
|
|
119
|
+
* undo step. Later changes to the saved section no longer reach this page.
|
|
120
|
+
*/
|
|
121
|
+
export async function detachSection(runtime, id) {
|
|
122
|
+
const ref = findBlock(runtime.store.getState().layout, id);
|
|
123
|
+
const sectionId = ref ? sectionRefId(ref.props?.section) : null;
|
|
124
|
+
if (sectionId === null)
|
|
125
|
+
return;
|
|
126
|
+
await runtime.sections.load();
|
|
127
|
+
const section = runtime.sections.saved.get()?.find((s) => s.savedId !== undefined && String(s.savedId) === String(sectionId));
|
|
128
|
+
if (!section) {
|
|
129
|
+
runtime.notify('This saved section cannot be loaded. It may be deleted.');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const copies = freshCopies(runtime, section.blocks);
|
|
133
|
+
const ops = sectionDetachOps(runtime.store.getState().layout, id, copies);
|
|
134
|
+
if (ops && runtime.store.apply(ops, { select: copies[0].id }))
|
|
135
|
+
runtime.notify(`Detached "${section.label}": this page now has its own copy`);
|
|
136
|
+
else
|
|
137
|
+
runtime.notify("The section's blocks cannot go here.");
|
|
138
|
+
}
|
|
104
139
|
export function duplicateBlock(runtime, id) {
|
|
105
140
|
const newId = createId();
|
|
106
141
|
if (runtime.store.apply({ type: 'duplicate', id, newId }, { select: newId }))
|
|
@@ -9,8 +9,9 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
9
9
|
// while something is dragged.
|
|
10
10
|
import { Button, useConfig } from '@payloadcms/ui';
|
|
11
11
|
import { useEffect, useId, useMemo, useState } from 'react';
|
|
12
|
-
import { DOCUMENT_TEMPLATE_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_TARGET_FIELD } from '../../../core/bindings.js';
|
|
12
|
+
import { DOCUMENT_TEMPLATE_FIELD, TEMPLATE_CONDITIONS_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_TARGET_FIELD, templateConditions, } from '../../../core/bindings.js';
|
|
13
13
|
import { builderViewPath } from '../../../plugin/links.js';
|
|
14
|
+
import { whereParams } from '../../../react/canvas/fetchDocs.js';
|
|
14
15
|
import { insertBlocks, sectionPosition } from '../actions.js';
|
|
15
16
|
import { Icon } from '../icons.js';
|
|
16
17
|
import { selectLeftTab } from '../layout/leftTabs.js';
|
|
@@ -23,7 +24,9 @@ import './empty.scss';
|
|
|
23
24
|
/** Categories of the suggested sections, in order: a page usually starts with these. */
|
|
24
25
|
const SUGGESTED = ['Heroes', 'Features', 'Calls to action'];
|
|
25
26
|
const SUGGESTION_COUNT = 3;
|
|
26
|
-
function suggestions(
|
|
27
|
+
function suggestions(all) {
|
|
28
|
+
// One version of each section: its variants stay in the library.
|
|
29
|
+
const sections = all.filter((s) => !s.variantOf);
|
|
27
30
|
const picked = SUGGESTED.flatMap((category) => sections.find((s) => s.category === category) ?? []);
|
|
28
31
|
const rest = sections.filter((s) => !picked.includes(s));
|
|
29
32
|
return [...picked, ...rest].slice(0, SUGGESTION_COUNT);
|
|
@@ -38,7 +41,8 @@ async function getJson(url) {
|
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* The published template the site renders this document through: its own template, else the
|
|
41
|
-
*
|
|
44
|
+
* first template (by name) whose conditions match the latest draft, else the collection's newest
|
|
45
|
+
* default template with blocks. The same rule as `loadTemplate`.
|
|
42
46
|
*/
|
|
43
47
|
async function appliedTemplate(runtime, id) {
|
|
44
48
|
const templates = runtime.config.templates;
|
|
@@ -58,6 +62,28 @@ async function appliedTemplate(runtime, id) {
|
|
|
58
62
|
if (template && hasBlocks(template))
|
|
59
63
|
return { id: ownId, name: String(template.name ?? 'Untitled') };
|
|
60
64
|
}
|
|
65
|
+
const conditioned = await getJson(`${base}?${new URLSearchParams({
|
|
66
|
+
[`where[and][0][${TEMPLATE_TARGET_FIELD}][equals]`]: runtime.config.collection,
|
|
67
|
+
'where[and][1][_status][equals]': 'published',
|
|
68
|
+
[`select[${TEMPLATE_CONDITIONS_FIELD}]`]: 'true',
|
|
69
|
+
sort: 'name',
|
|
70
|
+
depth: '0',
|
|
71
|
+
limit: '100',
|
|
72
|
+
}).toString()}`);
|
|
73
|
+
for (const candidate of conditioned?.docs ?? []) {
|
|
74
|
+
const where = templateConditions(candidate);
|
|
75
|
+
if (!where)
|
|
76
|
+
continue;
|
|
77
|
+
const match = new URLSearchParams({ 'where[and][0][id][equals]': String(id), depth: '0', limit: '1', draft: 'true', 'select[id]': 'true' });
|
|
78
|
+
for (const [name, value] of whereParams(where, 'where[and][1]'))
|
|
79
|
+
match.append(name, value);
|
|
80
|
+
const found = await getJson(`${runtime.api}/${encodeURIComponent(runtime.config.collection)}?${match.toString()}`);
|
|
81
|
+
if (!found?.docs?.length)
|
|
82
|
+
continue;
|
|
83
|
+
const template = await getJson(`${base}/${encodeURIComponent(String(candidate.id))}?depth=0`);
|
|
84
|
+
if (template && hasBlocks(template))
|
|
85
|
+
return { id: candidate.id, name: String(template.name ?? 'Untitled') };
|
|
86
|
+
}
|
|
61
87
|
const query = new URLSearchParams({
|
|
62
88
|
[`where[and][0][${TEMPLATE_TARGET_FIELD}][equals]`]: runtime.config.collection,
|
|
63
89
|
[`where[and][1][${TEMPLATE_DEFAULT_FIELD}][equals]`]: 'true',
|
|
@@ -11,10 +11,13 @@ type Props = {
|
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Fields that share the parent's data, under a small heading: a collapsible, or one of several
|
|
14
|
-
* unnamed tabs. Looks like a group, but stores nothing of its own.
|
|
14
|
+
* unnamed tabs. Looks like a group, but stores nothing of its own. `collapsed`: a collapsible with
|
|
15
|
+
* `admin.initCollapsed` starts folded, and its heading opens it.
|
|
15
16
|
*/
|
|
16
|
-
export declare function FieldSection({ label, children }: {
|
|
17
|
+
export declare function FieldSection({ label, description, collapsed, children, }: {
|
|
17
18
|
readonly label: string;
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
readonly collapsed?: boolean;
|
|
18
21
|
readonly children: ReactNode;
|
|
19
22
|
}): import("react").JSX.Element;
|
|
20
23
|
/** A named group: a small heading over its sub-fields, which edit one nested object. */
|
|
@@ -3,9 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { RenderBlockFields } from '../renderField.js';
|
|
4
4
|
/**
|
|
5
5
|
* Fields that share the parent's data, under a small heading: a collapsible, or one of several
|
|
6
|
-
* unnamed tabs. Looks like a group, but stores nothing of its own.
|
|
6
|
+
* unnamed tabs. Looks like a group, but stores nothing of its own. `collapsed`: a collapsible with
|
|
7
|
+
* `admin.initCollapsed` starts folded, and its heading opens it.
|
|
7
8
|
*/
|
|
8
|
-
export function FieldSection({ label, children }) {
|
|
9
|
+
export function FieldSection({ label, description, collapsed, children, }) {
|
|
10
|
+
if (collapsed !== undefined) {
|
|
11
|
+
return (_jsxs("details", { className: "builder-field-group builder-field-group--fold", open: !collapsed, children: [_jsx("summary", { className: "builder-field-group__label", children: label }), description && _jsx("p", { className: "builder-field-group__description", children: description }), _jsx("div", { className: "builder-field-group__fields", children: children })] }));
|
|
12
|
+
}
|
|
9
13
|
return (_jsxs("fieldset", { className: "builder-field-group", children: [_jsx("legend", { className: "builder-field-group__label", children: label }), _jsx("div", { className: "builder-field-group__fields", children: children })] }));
|
|
10
14
|
}
|
|
11
15
|
/** A named group: a small heading over its sub-fields, which edit one nested object. */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
readonly label: string;
|
|
3
|
+
readonly description?: string;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly required: boolean;
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
readonly onChange: (value: unknown) => void;
|
|
8
|
+
/** The slug of the collection the query runs on, when known: its fields fill the field select. */
|
|
9
|
+
readonly collection?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A Payload `where` query as rows: field, operator and value, AND-ed. Stores the same where
|
|
13
|
+
* object as the JSON editor. A where the rows cannot show (`or`, nested groups) opens as JSON.
|
|
14
|
+
* "Edit as JSON" switches to the JSON editor.
|
|
15
|
+
*/
|
|
16
|
+
export declare function WhereField({ label, description, path, required, value, onChange, collection }: Props): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button, FieldLabel, useConfig } from '@payloadcms/ui';
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
5
|
+
import { dataFields } from '../../../core/fields.js';
|
|
6
|
+
import { Select } from '../ui/Select.js';
|
|
7
|
+
import { JsonField } from './JsonField.js';
|
|
8
|
+
import { convertWhereValue, parseWhereValue, rowsWhere, WHERE_OPERATORS, whereRows, whereValueText, } from './whereRows.js';
|
|
9
|
+
const OPERATOR_LABELS = {
|
|
10
|
+
equals: 'is',
|
|
11
|
+
not_equals: 'is not',
|
|
12
|
+
in: 'is one of',
|
|
13
|
+
not_in: 'is none of',
|
|
14
|
+
greater_than: 'greater than',
|
|
15
|
+
greater_than_equal: 'at least',
|
|
16
|
+
less_than: 'less than',
|
|
17
|
+
less_than_equal: 'at most',
|
|
18
|
+
like: 'has the words',
|
|
19
|
+
contains: 'contains',
|
|
20
|
+
exists: 'exists',
|
|
21
|
+
};
|
|
22
|
+
const OPERATOR_OPTIONS = WHERE_OPERATORS.map((value) => ({ value, label: OPERATOR_LABELS[value] }));
|
|
23
|
+
const YES_NO = [
|
|
24
|
+
{ value: 'true', label: 'yes' },
|
|
25
|
+
{ value: 'false', label: 'no' },
|
|
26
|
+
];
|
|
27
|
+
const editRows = (value) => (whereRows(value) ?? []).map((row) => ({ ...row, text: whereValueText(row.value) }));
|
|
28
|
+
/**
|
|
29
|
+
* A Payload `where` query as rows: field, operator and value, AND-ed. Stores the same where
|
|
30
|
+
* object as the JSON editor. A where the rows cannot show (`or`, nested groups) opens as JSON.
|
|
31
|
+
* "Edit as JSON" switches to the JSON editor.
|
|
32
|
+
*/
|
|
33
|
+
export function WhereField({ label, description, path, required, value, onChange, collection }) {
|
|
34
|
+
const { config } = useConfig();
|
|
35
|
+
const fields = useMemo(() => {
|
|
36
|
+
const found = config.collections.find((c) => c.slug === collection);
|
|
37
|
+
return found ? dataFields(found.fields).filter((f) => f.type !== 'group' && f.type !== 'array' && f.type !== 'blocks') : [];
|
|
38
|
+
}, [config.collections, collection]);
|
|
39
|
+
const [json, setJson] = useState(false);
|
|
40
|
+
const [draft, setDraft] = useState(() => ({ rows: editRows(value), source: value }));
|
|
41
|
+
// The value changed from outside (undo, AI edit): show it. Our own edits come back as `source`.
|
|
42
|
+
if (value !== draft.source)
|
|
43
|
+
setDraft({ rows: editRows(value), source: value });
|
|
44
|
+
const fits = whereRows(value) !== null;
|
|
45
|
+
if (json || !fits) {
|
|
46
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsx(JsonField, { description: description, label: label, onChange: onChange, path: path, required: required, value: value }), fits ? (_jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(false), children: "Edit as conditions" })) : (_jsx("p", { className: "builder-field-group__description", children: "This query uses parts the condition rows cannot show (for example \"or\"), so it opens as JSON." }))] }));
|
|
47
|
+
}
|
|
48
|
+
const typeOf = (name) => fields.find((f) => f.name === name)?.type;
|
|
49
|
+
const update = (rows) => {
|
|
50
|
+
const where = rowsWhere(rows);
|
|
51
|
+
setDraft({ rows, source: where });
|
|
52
|
+
onChange(where);
|
|
53
|
+
};
|
|
54
|
+
const change = (index, patch) => update(draft.rows.map((row, i) => (i === index ? { ...row, ...patch } : row)));
|
|
55
|
+
const fieldOptions = (current) => {
|
|
56
|
+
const options = fields.map((f) => ({ value: f.name, label: f.name }));
|
|
57
|
+
return current && !options.some((o) => o.value === current) ? [{ value: current, label: current }, ...options] : options;
|
|
58
|
+
};
|
|
59
|
+
return (_jsxs("div", { className: "builder-where", children: [_jsxs("div", { className: "builder-where__head", children: [_jsx(FieldLabel, { label: label, path: path, required: required }), _jsx("button", { type: "button", className: "builder-where__switch", onClick: () => setJson(true), children: "Edit as JSON" })] }), description && _jsx("p", { className: "builder-field-group__description", children: description }), draft.rows.map((row, index) => {
|
|
60
|
+
const name = `Condition ${index + 1}`;
|
|
61
|
+
return (_jsxs("fieldset", { className: "builder-where__row", "aria-label": name, children: [fields.length > 0 ? (_jsx(Select, { "aria-label": `${name}: field`, placeholder: "Field", value: row.field || null, options: fieldOptions(row.field), onValueChange: (field) => change(index, { field: field ?? '', value: parseWhereValue(row.text, row.operator, typeOf(field ?? '')) }) })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: field`, placeholder: "Field", value: row.field, onChange: (e) => change(index, { field: e.target.value }) })), _jsx(Select, { "aria-label": `${name}: operator`, value: row.operator, options: OPERATOR_OPTIONS, onValueChange: (next) => {
|
|
62
|
+
const operator = (next ?? 'equals');
|
|
63
|
+
const converted = convertWhereValue(row, operator, typeOf(row.field));
|
|
64
|
+
change(index, { operator, value: converted, text: whereValueText(converted) });
|
|
65
|
+
} }), row.operator === 'exists' ? (_jsx(Select, { "aria-label": `${name}: value`, value: row.value === false ? 'false' : 'true', options: YES_NO, onValueChange: (next) => change(index, { value: next !== 'false', text: next ?? 'true' }) })) : (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${name}: value`, placeholder: row.operator === 'in' || row.operator === 'not_in' ? 'a, b, c' : 'Value', value: row.text, onChange: (e) => change(index, { text: e.target.value, value: parseWhereValue(e.target.value, row.operator, typeOf(row.field)) }) })), _jsx("button", { type: "button", className: "builder-where__remove", "aria-label": `Remove ${name.toLowerCase()}`, onClick: () => update(draft.rows.filter((_, i) => i !== index)), children: "\u00D7" })] }, index));
|
|
66
|
+
}), _jsx(Button, { buttonStyle: "secondary", icon: "plus", iconPosition: "left", iconStyle: "with-border", margin: false, onClick: () => update([...draft.rows, { field: '', operator: 'equals', value: '', text: '' }]), size: "small", children: "Add condition" })] }));
|
|
67
|
+
}
|
|
@@ -32,12 +32,101 @@
|
|
|
32
32
|
text-transform: uppercase;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// A collapsible with `initCollapsed`: the heading opens and closes it.
|
|
36
|
+
.builder-field-group--fold > .builder-field-group__label {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.builder-field-group--fold:not([open]) {
|
|
41
|
+
padding-bottom: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
.builder-field-group__description {
|
|
36
45
|
margin: 0;
|
|
37
46
|
color: var(--theme-elevation-600);
|
|
38
47
|
font-size: var(--be-text-m);
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
// The where builder (WhereField): rows of field, operator, value and a remove button.
|
|
51
|
+
.builder-where {
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
gap: calc(var(--base) * 0.4);
|
|
55
|
+
align-items: flex-start;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.builder-where__head {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: baseline;
|
|
61
|
+
justify-content: space-between;
|
|
62
|
+
align-self: stretch;
|
|
63
|
+
gap: 8px;
|
|
64
|
+
|
|
65
|
+
.field-label {
|
|
66
|
+
margin: 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.builder-where__switch {
|
|
71
|
+
padding: 0;
|
|
72
|
+
border: 0;
|
|
73
|
+
background: none;
|
|
74
|
+
color: var(--theme-elevation-800);
|
|
75
|
+
font: inherit;
|
|
76
|
+
font-size: var(--be-text-m);
|
|
77
|
+
text-decoration: underline;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.builder-where__row {
|
|
82
|
+
display: grid;
|
|
83
|
+
grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.2fr) auto;
|
|
84
|
+
align-items: center;
|
|
85
|
+
align-self: stretch;
|
|
86
|
+
gap: 4px;
|
|
87
|
+
min-width: 0;
|
|
88
|
+
margin: 0;
|
|
89
|
+
padding: 0;
|
|
90
|
+
border: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.builder-where__input {
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
width: 100%;
|
|
96
|
+
min-width: 0;
|
|
97
|
+
height: calc(var(--base) * 2);
|
|
98
|
+
padding: 0 calc(var(--base) * 0.5);
|
|
99
|
+
border: 1px solid var(--theme-elevation-150);
|
|
100
|
+
border-radius: var(--style-radius-s);
|
|
101
|
+
background: var(--theme-input-bg, var(--theme-elevation-0));
|
|
102
|
+
color: var(--theme-elevation-800);
|
|
103
|
+
font: inherit;
|
|
104
|
+
font-size: var(--be-text-m);
|
|
105
|
+
|
|
106
|
+
&:focus-visible {
|
|
107
|
+
outline: 2px solid var(--theme-success-500);
|
|
108
|
+
outline-offset: 1px;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.builder-where__remove {
|
|
113
|
+
width: calc(var(--base) * 1.5);
|
|
114
|
+
height: calc(var(--base) * 1.5);
|
|
115
|
+
padding: 0;
|
|
116
|
+
border: 0;
|
|
117
|
+
border-radius: var(--style-radius-s);
|
|
118
|
+
background: none;
|
|
119
|
+
color: var(--theme-elevation-600);
|
|
120
|
+
font-size: 18px;
|
|
121
|
+
line-height: 1;
|
|
122
|
+
cursor: pointer;
|
|
123
|
+
|
|
124
|
+
&:hover {
|
|
125
|
+
background: var(--theme-elevation-100);
|
|
126
|
+
color: var(--theme-elevation-900);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
41
130
|
.builder-field-group__fields {
|
|
42
131
|
display: flex;
|
|
43
132
|
flex-direction: column;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const WHERE_OPERATORS: readonly ['equals', 'not_equals', 'in', 'not_in', 'greater_than', 'greater_than_equal', 'less_than', 'less_than_equal', 'like', 'contains', 'exists'];
|
|
2
|
+
export type WhereOperator = (typeof WHERE_OPERATORS)[number];
|
|
3
|
+
/** One condition. `value` is the stored value (a string, number, boolean, or a list for in/not_in). */
|
|
4
|
+
export type WhereRow = {
|
|
5
|
+
field: string;
|
|
6
|
+
operator: WhereOperator;
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The rows of a stored where: empty for no where, null when the builder cannot show it. Takes
|
|
11
|
+
* `{ a: { equals: 1 }, b: { … } }` and `{ and: [ { a: { equals: 1 } }, … ] }`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function whereRows(where: unknown): WhereRow[] | null;
|
|
14
|
+
/**
|
|
15
|
+
* The where of the rows: one object `{ field: { op: value } }`, or `{ and: [...] }` when a field
|
|
16
|
+
* has the same operator twice. Rows without a field are left out. `undefined` for no rows.
|
|
17
|
+
*/
|
|
18
|
+
export declare function rowsWhere(rows: readonly WhereRow[]): Record<string, unknown> | undefined;
|
|
19
|
+
/** The text a value shows in the value input: lists as "a, b". */
|
|
20
|
+
export declare const whereValueText: (value: unknown) => string;
|
|
21
|
+
/**
|
|
22
|
+
* The value to store for typed text. `fieldType` is the Payload field type when known: numbers
|
|
23
|
+
* become numbers and checkboxes booleans; any other text stays text (so "0412" stays a string).
|
|
24
|
+
* `in` and `not_in` split on commas. `exists` takes "true" or "false".
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseWhereValue(text: string, operator: WhereOperator, fieldType?: string): unknown;
|
|
27
|
+
/** The value a row keeps when its operator changes: re-read from its text for the new operator. */
|
|
28
|
+
export declare const convertWhereValue: (row: WhereRow, operator: WhereOperator, fieldType?: string) => unknown;
|