payload-canvas 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +500 -25
- package/dist/admin/diff/changes.js +8 -0
- package/dist/admin/editor/Inspector.js +49 -4
- package/dist/admin/editor/Outline.js +12 -10
- package/dist/admin/editor/actions.d.ts +9 -1
- package/dist/admin/editor/actions.js +38 -3
- package/dist/admin/editor/empty/EmptyStart.js +29 -3
- package/dist/admin/editor/fields/GroupField.d.ts +5 -2
- package/dist/admin/editor/fields/GroupField.js +6 -2
- package/dist/admin/editor/fields/WhereField.d.ts +17 -0
- package/dist/admin/editor/fields/WhereField.js +67 -0
- package/dist/admin/editor/fields/fields.scss +89 -0
- package/dist/admin/editor/fields/whereRows.d.ts +28 -0
- package/dist/admin/editor/fields/whereRows.js +118 -0
- package/dist/admin/editor/icons.d.ts +1 -0
- package/dist/admin/editor/icons.js +2 -0
- package/dist/admin/editor/locale/LocaleField.d.ts +1 -1
- package/dist/admin/editor/locale/LocaleField.js +3 -1
- package/dist/admin/editor/menu/blockMenu.js +5 -1
- package/dist/admin/editor/motion/MotionPanel.js +1 -1
- package/dist/admin/editor/motion/model.js +2 -2
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +13 -4
- package/dist/admin/editor/runtime.js +1 -0
- package/dist/admin/editor/styles/SiteClasses.d.ts +9 -0
- package/dist/admin/editor/styles/SiteClasses.js +31 -0
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
- package/dist/admin/editor/styles/StylesPanel.js +9 -6
- package/dist/admin/editor/styles/context.d.ts +9 -2
- package/dist/admin/editor/styles/context.js +14 -9
- package/dist/admin/editor/styles/controls.js +2 -2
- package/dist/admin/editor/styles/sections.js +1 -1
- package/dist/admin/editor/styles/styles.scss +54 -0
- package/dist/admin/editor/templates/Bindable.d.ts +13 -5
- package/dist/admin/editor/templates/Bindable.js +73 -17
- package/dist/admin/editor/templates/binding.d.ts +11 -4
- package/dist/admin/editor/templates/binding.js +23 -3
- package/dist/ai/prompt.js +8 -2
- package/dist/ai/tools.js +11 -2
- package/dist/blocks/builtins/carousel.d.ts +32 -0
- package/dist/blocks/builtins/carousel.js +122 -0
- package/dist/blocks/builtins/disclosure.d.ts +13 -0
- package/dist/blocks/builtins/disclosure.js +107 -0
- package/dist/blocks/builtins/faq.d.ts +17 -0
- package/dist/blocks/builtins/faq.js +88 -0
- package/dist/blocks/builtins/filterLink.d.ts +22 -0
- package/dist/blocks/builtins/filterLink.js +76 -0
- package/dist/blocks/builtins/headingId.d.ts +15 -0
- package/dist/blocks/builtins/headingId.js +36 -0
- package/dist/blocks/builtins/icon.d.ts +8 -0
- package/dist/blocks/builtins/icon.js +45 -0
- package/dist/blocks/builtins/index.d.ts +35 -0
- package/dist/blocks/builtins/index.js +50 -0
- package/dist/blocks/builtins/lightbox.d.ts +43 -0
- package/dist/blocks/builtins/lightbox.js +93 -0
- package/dist/blocks/builtins/mediaBackdrop.d.ts +11 -0
- package/dist/blocks/builtins/mediaBackdrop.js +79 -0
- package/dist/blocks/builtins/sectionRef.d.ts +26 -0
- package/dist/blocks/builtins/sectionRef.js +78 -0
- package/dist/blocks/builtins/shared.d.ts +33 -0
- package/dist/blocks/builtins/shared.js +70 -0
- package/dist/blocks/builtins/tableOfContents.d.ts +3 -0
- package/dist/blocks/builtins/tableOfContents.js +44 -0
- package/dist/blocks/defaults.d.ts +19 -1
- package/dist/blocks/defaults.js +413 -20
- package/dist/blocks/index.d.ts +4 -2
- package/dist/blocks/index.js +3 -1
- package/dist/core/attrs.d.ts +27 -0
- package/dist/core/attrs.js +132 -0
- package/dist/core/bindings.d.ts +122 -11
- package/dist/core/bindings.js +504 -19
- package/dist/core/blocks.d.ts +46 -1
- package/dist/core/blocks.js +136 -0
- package/dist/core/classes.d.ts +10 -2
- package/dist/core/classes.js +34 -5
- package/dist/core/headings.d.ts +21 -0
- package/dist/core/headings.js +47 -0
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +4 -2
- package/dist/core/motion.d.ts +18 -9
- package/dist/core/motion.js +20 -12
- package/dist/core/operations.js +59 -2
- package/dist/core/payloadBlocks.js +3 -1
- package/dist/core/schema.js +20 -0
- package/dist/core/tree.js +24 -1
- package/dist/core/types.d.ts +87 -0
- package/dist/core/validate.js +29 -4
- package/dist/css/tokens.d.ts +6 -3
- package/dist/css/tokens.js +48 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +50 -13
- package/dist/mcp/shared.d.ts +3 -0
- package/dist/mcp/shared.js +23 -8
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +26 -8
- package/dist/plugin/listCollections.d.ts +17 -2
- package/dist/plugin/listCollections.js +44 -7
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +1 -1
- package/dist/plugin/templates.d.ts +4 -0
- package/dist/plugin/templates.js +23 -4
- package/dist/protocol/index.d.ts +2 -0
- package/dist/react/canvas/BuilderCanvas.js +5 -3
- package/dist/react/canvas/fetchDocs.d.ts +16 -2
- package/dist/react/canvas/fetchDocs.js +42 -9
- package/dist/react/canvas/measure.d.ts +3 -1
- package/dist/react/canvas/measure.js +26 -2
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +17 -6
- package/dist/react/canvas/serverBlocks.d.ts +11 -0
- package/dist/react/canvas/serverBlocks.js +28 -1
- package/dist/react/components/Button.d.ts +11 -2
- package/dist/react/components/Button.js +43 -6
- package/dist/react/components/CollectionList.d.ts +6 -3
- package/dist/react/components/CollectionList.js +21 -7
- package/dist/react/components/Container.js +4 -1
- package/dist/react/components/Field.js +13 -2
- package/dist/react/components/Heading.js +9 -2
- package/dist/react/components/Image.d.ts +9 -0
- package/dist/react/components/Image.js +16 -1
- package/dist/react/components/List.d.ts +1 -0
- package/dist/react/components/List.js +6 -0
- package/dist/react/components/Menu.d.ts +16 -0
- package/dist/react/components/Menu.js +83 -19
- package/dist/react/components/RichText.d.ts +8 -3
- package/dist/react/components/RichText.js +25 -4
- package/dist/react/components/builtins/Accordion.d.ts +9 -0
- package/dist/react/components/builtins/Accordion.js +37 -0
- package/dist/react/components/builtins/BackdropVideo.d.ts +13 -0
- package/dist/react/components/builtins/BackdropVideo.js +16 -0
- package/dist/react/components/builtins/Carousel.d.ts +13 -0
- package/dist/react/components/builtins/Carousel.js +134 -0
- package/dist/react/components/builtins/Disclosure.d.ts +7 -0
- package/dist/react/components/builtins/Disclosure.js +13 -0
- package/dist/react/components/builtins/FilterLink.d.ts +8 -0
- package/dist/react/components/builtins/FilterLink.js +30 -0
- package/dist/react/components/builtins/Icon.d.ts +14 -0
- package/dist/react/components/builtins/Icon.js +28 -0
- package/dist/react/components/builtins/Lightbox.d.ts +45 -0
- package/dist/react/components/builtins/Lightbox.js +252 -0
- package/dist/react/components/builtins/MediaBackdrop.d.ts +14 -0
- package/dist/react/components/builtins/MediaBackdrop.js +61 -0
- package/dist/react/components/builtins/SectionRef.d.ts +7 -0
- package/dist/react/components/builtins/SectionRef.js +17 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +7 -0
- package/dist/react/components/builtins/TableOfContents.js +21 -0
- package/dist/react/components/builtins/glyphs.d.ts +8 -0
- package/dist/react/components/builtins/glyphs.js +7 -0
- package/dist/react/components/builtins/index.d.ts +32 -0
- package/dist/react/components/builtins/index.js +36 -0
- package/dist/react/components/index.js +2 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +3 -1
- package/dist/react/motion/runtime.js +10 -6
- package/dist/react/render/RenderLayout.d.ts +1 -1
- package/dist/react/render/RenderLayout.js +76 -23
- package/dist/react/render/lists.d.ts +107 -5
- package/dist/react/render/lists.js +284 -9
- package/dist/react/render/resolve.d.ts +22 -2
- package/dist/react/render/resolve.js +45 -22
- package/dist/react/render/sections.d.ts +9 -0
- package/dist/react/render/sections.js +51 -0
- package/dist/react/render/types.d.ts +6 -1
- package/dist/react/server.d.ts +3 -1
- package/dist/react/server.js +53 -2
- package/dist/react/theme/ThemeStyle.d.ts +13 -2
- package/dist/react/theme/ThemeStyle.js +12 -2
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BlockDefinition } from '../../core/types.js';
|
|
2
|
+
export declare const MEDIA_BACKDROP_BLOCK = "mediaBackdrop";
|
|
3
|
+
/**
|
|
4
|
+
* Classes the backdrop component adds to the media and the overlay: they fill the block behind
|
|
5
|
+
* its content. The block itself needs `relative isolate` (in its default className).
|
|
6
|
+
*/
|
|
7
|
+
export declare const MEDIA_BACKDROP_CLASS_MAP: {
|
|
8
|
+
media: string;
|
|
9
|
+
overlay: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function mediaBackdropBlock(mediaCollection?: string): BlockDefinition;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineBlock } from '../../core/blocks.js';
|
|
2
|
+
import { classesOf, classMap } from './shared.js';
|
|
3
|
+
export const MEDIA_BACKDROP_BLOCK = 'mediaBackdrop';
|
|
4
|
+
/**
|
|
5
|
+
* Classes the backdrop component adds to the media and the overlay: they fill the block behind
|
|
6
|
+
* its content. The block itself needs `relative isolate` (in its default className).
|
|
7
|
+
*/
|
|
8
|
+
export const MEDIA_BACKDROP_CLASS_MAP = classMap({
|
|
9
|
+
media: 'pointer-events-none absolute inset-0 -z-10 size-full object-cover',
|
|
10
|
+
overlay: 'pointer-events-none absolute inset-0 -z-10',
|
|
11
|
+
});
|
|
12
|
+
const BACKDROP_CLASS = 'relative isolate flex min-h-96 flex-col justify-end gap-4 overflow-hidden p-8 [&>[data-backdrop-overlay]]:bg-black/40';
|
|
13
|
+
export function mediaBackdropBlock(mediaCollection = 'media') {
|
|
14
|
+
const relationTo = mediaCollection;
|
|
15
|
+
return defineBlock({
|
|
16
|
+
type: MEDIA_BACKDROP_BLOCK,
|
|
17
|
+
label: 'Media backdrop',
|
|
18
|
+
icon: 'image',
|
|
19
|
+
category: 'Media',
|
|
20
|
+
fields: [
|
|
21
|
+
{ name: 'image', type: 'upload', relationTo, label: 'Photo' },
|
|
22
|
+
{
|
|
23
|
+
name: 'alt',
|
|
24
|
+
type: 'text',
|
|
25
|
+
label: 'Alt text',
|
|
26
|
+
localized: true,
|
|
27
|
+
admin: { description: 'Empty: the photo is decoration, as most backgrounds are.' },
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'video',
|
|
31
|
+
type: 'upload',
|
|
32
|
+
relationTo,
|
|
33
|
+
label: 'Video',
|
|
34
|
+
admin: { description: 'A muted, looping video. It does not play when the visitor asks for less motion: the poster shows instead.' },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'videoUrl',
|
|
38
|
+
type: 'text',
|
|
39
|
+
label: 'Video URL',
|
|
40
|
+
admin: { description: 'Instead of an upload: a link to a video file, for example /video/hero.mp4.' },
|
|
41
|
+
},
|
|
42
|
+
{ name: 'poster', type: 'upload', relationTo, label: 'Video poster', admin: { description: 'Empty: the photo above.' } },
|
|
43
|
+
{
|
|
44
|
+
name: 'priority',
|
|
45
|
+
type: 'checkbox',
|
|
46
|
+
label: 'Load first',
|
|
47
|
+
admin: { description: 'For the backdrop at the top of the page (the hero): the photo or poster loads at once, with high priority.' },
|
|
48
|
+
},
|
|
49
|
+
{ name: 'sizes', type: 'text', label: 'Sizes', admin: { description: 'The HTML sizes attribute of the photo. Empty: 100vw.' } },
|
|
50
|
+
{
|
|
51
|
+
name: 'overlay',
|
|
52
|
+
type: 'checkbox',
|
|
53
|
+
label: 'Overlay',
|
|
54
|
+
admin: { description: 'A layer between the media and the content, to keep text readable. Its colour comes from [&>[data-backdrop-overlay]]: classes.' },
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
slots: { children: { label: 'Content' } },
|
|
58
|
+
defaultClassName: BACKDROP_CLASS,
|
|
59
|
+
classes: classesOf(MEDIA_BACKDROP_CLASS_MAP),
|
|
60
|
+
ai: {
|
|
61
|
+
description: `A section with a photo or a muted looping video behind its "children" slot content (a hero, a banner). Media from the ` +
|
|
62
|
+
`"${mediaCollection}" collection: "image" (a photo), or "video" (an upload) or "videoUrl" with an optional "poster" ` +
|
|
63
|
+
'(empty: the photo). The video does not play under reduced motion. The media focal point sets object-position. Set ' +
|
|
64
|
+
'"priority" on the hero only. "overlay" adds a layer for readable text, coloured with [&>[data-backdrop-overlay]]: ' +
|
|
65
|
+
'classes ("[&>[data-backdrop-overlay]]:bg-black/40"). Style the media with [&>[data-backdrop-media]]: classes (blur, ' +
|
|
66
|
+
'object-position). Keep "relative isolate" in its className: the media sits behind the content.',
|
|
67
|
+
example: {
|
|
68
|
+
type: MEDIA_BACKDROP_BLOCK,
|
|
69
|
+
props: { image: 1, priority: true, overlay: true },
|
|
70
|
+
className: BACKDROP_CLASS,
|
|
71
|
+
slots: {
|
|
72
|
+
children: [
|
|
73
|
+
{ id: 'b_example_1', type: 'heading', props: { text: 'Welcome', level: '1' }, className: 'text-5xl font-bold text-white' },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Block, BlockDefinition, Layout, Operation } from '../../core/types.js';
|
|
2
|
+
export declare const SECTION_REF_BLOCK = "sectionRef";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime-only slot: the saved section's blocks, put there by `attachSections` (data loading).
|
|
5
|
+
* Never stored. Its blocks are copies with ids prefixed by the ref's id.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SECTION_REF_SLOT = "$section";
|
|
8
|
+
/** The id of the saved section a `section` prop points at: an id, or a loaded document. */
|
|
9
|
+
export declare function sectionRefId(value: unknown): string | number | null;
|
|
10
|
+
/**
|
|
11
|
+
* The saved section's blocks as a ref renders them: canonical, with each id prefixed by the ref's
|
|
12
|
+
* id, so two refs to one section (or a ref on the page the section came from) never share an id.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sectionRefBlocks(refId: string, stored: unknown): Block[];
|
|
15
|
+
/**
|
|
16
|
+
* "Detach section": the operations that put `copies` (the section's blocks with new ids) where the
|
|
17
|
+
* ref is, and remove the ref. Apply them in one `store.apply`: one undo step. Null when the ref
|
|
18
|
+
* is not in the layout or there is nothing to put in.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sectionDetachOps(layout: Layout, refId: string, copies: readonly Block[]): Operation[] | null;
|
|
21
|
+
/**
|
|
22
|
+
* A saved section, live: the page shows the section's current blocks, so a change to the section
|
|
23
|
+
* shows on every page that uses it. "Detach" in the block menu replaces it with a copy. The
|
|
24
|
+
* collection is the plugin's saved sections collection (`websiteBuilder({ savedSections })`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function sectionRefBlock(collection?: string): BlockDefinition;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineBlock } from '../../core/blocks.js';
|
|
2
|
+
import { findLocation, normalizeLayout } from '../../core/tree.js';
|
|
3
|
+
export const SECTION_REF_BLOCK = 'sectionRef';
|
|
4
|
+
/**
|
|
5
|
+
* Runtime-only slot: the saved section's blocks, put there by `attachSections` (data loading).
|
|
6
|
+
* Never stored. Its blocks are copies with ids prefixed by the ref's id.
|
|
7
|
+
*/
|
|
8
|
+
export const SECTION_REF_SLOT = '$section';
|
|
9
|
+
/** The id of the saved section a `section` prop points at: an id, or a loaded document. */
|
|
10
|
+
export function sectionRefId(value) {
|
|
11
|
+
if (typeof value === 'number' || (typeof value === 'string' && value))
|
|
12
|
+
return value;
|
|
13
|
+
if (value && typeof value === 'object' && 'id' in value)
|
|
14
|
+
return sectionRefId(value.id);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The saved section's blocks as a ref renders them: canonical, with each id prefixed by the ref's
|
|
19
|
+
* id, so two refs to one section (or a ref on the page the section came from) never share an id.
|
|
20
|
+
*/
|
|
21
|
+
export function sectionRefBlocks(refId, stored) {
|
|
22
|
+
const prefix = (block) => ({
|
|
23
|
+
...block,
|
|
24
|
+
id: `${refId}_${block.id}`,
|
|
25
|
+
...(block.slots
|
|
26
|
+
? { slots: Object.fromEntries(Object.entries(block.slots).map(([name, list]) => [name, list.map(prefix)])) }
|
|
27
|
+
: {}),
|
|
28
|
+
});
|
|
29
|
+
return normalizeLayout({ version: 1, blocks: stored }).blocks.map(prefix);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* "Detach section": the operations that put `copies` (the section's blocks with new ids) where the
|
|
33
|
+
* ref is, and remove the ref. Apply them in one `store.apply`: one undo step. Null when the ref
|
|
34
|
+
* is not in the layout or there is nothing to put in.
|
|
35
|
+
*/
|
|
36
|
+
export function sectionDetachOps(layout, refId, copies) {
|
|
37
|
+
const location = findLocation(layout, refId);
|
|
38
|
+
if (!location || copies.length === 0)
|
|
39
|
+
return null;
|
|
40
|
+
const to = (i) => ({ parentId: location.parentId, slot: location.slot, index: location.index + i });
|
|
41
|
+
return [...copies.map((block, i) => ({ type: 'insert', block, to: to(i) })), { type: 'remove', id: refId }];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A saved section, live: the page shows the section's current blocks, so a change to the section
|
|
45
|
+
* shows on every page that uses it. "Detach" in the block menu replaces it with a copy. The
|
|
46
|
+
* collection is the plugin's saved sections collection (`websiteBuilder({ savedSections })`).
|
|
47
|
+
*/
|
|
48
|
+
export function sectionRefBlock(collection = 'builder-sections') {
|
|
49
|
+
return defineBlock({
|
|
50
|
+
type: SECTION_REF_BLOCK,
|
|
51
|
+
label: 'Saved section (live)',
|
|
52
|
+
icon: 'section',
|
|
53
|
+
category: 'Dynamic',
|
|
54
|
+
// It renders the section's blocks with their own classes and no element of its own.
|
|
55
|
+
styles: false,
|
|
56
|
+
fields: [
|
|
57
|
+
{
|
|
58
|
+
name: 'section',
|
|
59
|
+
type: 'relationship',
|
|
60
|
+
label: 'Saved section',
|
|
61
|
+
relationTo: collection,
|
|
62
|
+
required: true,
|
|
63
|
+
admin: {
|
|
64
|
+
description: 'Shows this saved section as it is now: edit the section and every page that uses it changes. ' +
|
|
65
|
+
'To change it on this page only, use "Detach section" in the block menu.',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
ai: {
|
|
70
|
+
description: `Shows a saved section (the "${collection}" collection) live: the page renders the section's current blocks, so one ` +
|
|
71
|
+
'edit of the section changes every page that uses it. Set "section" to the saved section\'s document id ' +
|
|
72
|
+
'(listSections shows saved sections as "saved:<id>"; use the number). It has no className and no slots. ' +
|
|
73
|
+
'Use it for blocks many pages share (a call to action, a footer band). To insert a copy that the page can change, ' +
|
|
74
|
+
'use insertSection instead. A sectionRef inside a saved section renders nothing.',
|
|
75
|
+
example: { type: SECTION_REF_BLOCK, props: { section: 1 } },
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the marker class to every class string of a flat map (see `BUILDER_CSS_CLASS`). A built-in
|
|
4
|
+
* component puts these strings on its own elements; its definition lists them in `classes`
|
|
5
|
+
* (`classesOf`), so the generated CSS has them. Same rule as `withMarker` in `../defaults.ts`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function classMap<T extends Record<string, string>>(map: T): T;
|
|
8
|
+
/** The classes of a class map, for a definition's `classes`, without the marker. */
|
|
9
|
+
export declare function classesOf(map: Record<string, string>): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Block types that hold links or controls. Slots that render inside an `<a>`, a `<button>` or a
|
|
12
|
+
* `<summary>` refuse them at any depth. A type that does not exist is ignored.
|
|
13
|
+
*/
|
|
14
|
+
export declare const INTERACTIVE: string[];
|
|
15
|
+
/** Plain string props: trimmed, or the fallback when empty. */
|
|
16
|
+
export declare const textOr: (value: unknown, fallback: string) => string;
|
|
17
|
+
/** Prop name -> English default of a control label (`{n}` and `{count}` are filled in where noted). */
|
|
18
|
+
export type ControlLabels = Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* A collapsed **Labels** group of localized text props, one per control label, with the English
|
|
21
|
+
* text as the default. The props are flat (`props.closeLabel`); the group only folds them in the
|
|
22
|
+
* inspector. A component reads each one with `labelOf(props, LABELS, name)`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function labelsField(labels: ControlLabels, names: Record<string, string>): Field;
|
|
25
|
+
/**
|
|
26
|
+
* A control label: the prop, or its English default when empty. `values` fill `{n}`-style
|
|
27
|
+
* placeholders ("Slide {n} of {count}").
|
|
28
|
+
*/
|
|
29
|
+
export declare function labelOf(props: Record<string, unknown>, labels: ControlLabels, name: string, values?: Record<string, string | number>): string;
|
|
30
|
+
/** The AI description of a block's label props. */
|
|
31
|
+
export declare const labelsHelp: (labels: ControlLabels) => string;
|
|
32
|
+
/** Class strings joined with spaces; empty and missing ones are left out. */
|
|
33
|
+
export declare const joinClasses: (...classes: (string | undefined)[]) => string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { BUILDER_CSS_CLASS } from '../../css/marker.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the marker class to every class string of a flat map (see `BUILDER_CSS_CLASS`). A built-in
|
|
4
|
+
* component puts these strings on its own elements; its definition lists them in `classes`
|
|
5
|
+
* (`classesOf`), so the generated CSS has them. Same rule as `withMarker` in `../defaults.ts`.
|
|
6
|
+
*/
|
|
7
|
+
export function classMap(map) {
|
|
8
|
+
return Object.fromEntries(Object.entries(map).map(([key, value]) => [key, `${value} ${BUILDER_CSS_CLASS}`]));
|
|
9
|
+
}
|
|
10
|
+
/** The classes of a class map, for a definition's `classes`, without the marker. */
|
|
11
|
+
export function classesOf(map) {
|
|
12
|
+
const all = Object.values(map).flatMap((value) => value.split(' '));
|
|
13
|
+
return [...new Set(all)].filter((cls) => cls && cls !== BUILDER_CSS_CLASS);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Block types that hold links or controls. Slots that render inside an `<a>`, a `<button>` or a
|
|
17
|
+
* `<summary>` refuse them at any depth. A type that does not exist is ignored.
|
|
18
|
+
*/
|
|
19
|
+
export const INTERACTIVE = [
|
|
20
|
+
'link',
|
|
21
|
+
'button',
|
|
22
|
+
'menu',
|
|
23
|
+
'richText',
|
|
24
|
+
'video',
|
|
25
|
+
'collectionList',
|
|
26
|
+
'form',
|
|
27
|
+
'filterLink',
|
|
28
|
+
'carousel',
|
|
29
|
+
'lightbox',
|
|
30
|
+
'accordion',
|
|
31
|
+
'disclosure',
|
|
32
|
+
];
|
|
33
|
+
/** Plain string props: trimmed, or the fallback when empty. */
|
|
34
|
+
export const textOr = (value, fallback) => typeof value === 'string' && value.trim() ? value.trim() : fallback;
|
|
35
|
+
/**
|
|
36
|
+
* A collapsed **Labels** group of localized text props, one per control label, with the English
|
|
37
|
+
* text as the default. The props are flat (`props.closeLabel`); the group only folds them in the
|
|
38
|
+
* inspector. A component reads each one with `labelOf(props, LABELS, name)`.
|
|
39
|
+
*/
|
|
40
|
+
export function labelsField(labels, names) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'collapsible',
|
|
43
|
+
label: 'Labels',
|
|
44
|
+
admin: {
|
|
45
|
+
initCollapsed: true,
|
|
46
|
+
description: 'The text of the controls, for screen readers and visible buttons. Translate them per locale.',
|
|
47
|
+
},
|
|
48
|
+
fields: Object.entries(labels).map(([name, text]) => ({
|
|
49
|
+
name,
|
|
50
|
+
type: 'text',
|
|
51
|
+
label: names[name] ?? name,
|
|
52
|
+
defaultValue: text,
|
|
53
|
+
localized: true,
|
|
54
|
+
...(text.includes('{') ? { admin: { description: `${braces(text)} are filled in.` } } : {}),
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const braces = (text) => [...new Set(text.match(/\{\w+\}/g) ?? [])].join(' and ');
|
|
59
|
+
/**
|
|
60
|
+
* A control label: the prop, or its English default when empty. `values` fill `{n}`-style
|
|
61
|
+
* placeholders ("Slide {n} of {count}").
|
|
62
|
+
*/
|
|
63
|
+
export function labelOf(props, labels, name, values = {}) {
|
|
64
|
+
const template = textOr(props[name], labels[name] ?? '');
|
|
65
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
|
|
66
|
+
}
|
|
67
|
+
/** The AI description of a block's label props. */
|
|
68
|
+
export const labelsHelp = (labels) => ` Control labels (localized, English defaults): ${Object.entries(labels).map(([name, text]) => `"${name}" ("${text}")`).join(', ')}.`;
|
|
69
|
+
/** Class strings joined with spaces; empty and missing ones are left out. */
|
|
70
|
+
export const joinClasses = (...classes) => classes.filter(Boolean).join(' ');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineBlock } from '../../core/blocks.js';
|
|
2
|
+
export const TABLE_OF_CONTENTS_BLOCK = 'tableOfContents';
|
|
3
|
+
const TOC_CLASS = 'flex flex-col gap-2 text-sm [&>a]:opacity-75 [&>a:hover]:opacity-100';
|
|
4
|
+
export function tableOfContentsBlock() {
|
|
5
|
+
return defineBlock({
|
|
6
|
+
type: TABLE_OF_CONTENTS_BLOCK,
|
|
7
|
+
label: 'Table of contents',
|
|
8
|
+
icon: 'hash',
|
|
9
|
+
category: 'Dynamic',
|
|
10
|
+
fields: [
|
|
11
|
+
{
|
|
12
|
+
name: 'content',
|
|
13
|
+
type: 'richText',
|
|
14
|
+
label: 'Rich text',
|
|
15
|
+
admin: {
|
|
16
|
+
description: 'Bind it to the rich text field of the document, for example "content". Its H2 headings become the links. ' +
|
|
17
|
+
'The heading ids come from headingId(), the same as the rich text on the page.',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'minHeadings',
|
|
22
|
+
type: 'number',
|
|
23
|
+
label: 'Fewest headings',
|
|
24
|
+
defaultValue: 3,
|
|
25
|
+
min: 1,
|
|
26
|
+
admin: { description: 'With fewer H2 headings the block shows nothing.' },
|
|
27
|
+
},
|
|
28
|
+
{ name: 'label', type: 'text', label: 'Label for screen readers', defaultValue: 'On this page', localized: true },
|
|
29
|
+
],
|
|
30
|
+
defaultClassName: TOC_CLASS,
|
|
31
|
+
ai: {
|
|
32
|
+
description: 'Links to the H2 headings of a rich text field of the current document (templates): bind its "content" prop to that ' +
|
|
33
|
+
'field, e.g. bindings { "content": "content" }. It renders a <nav> of bare <a href="#id"> elements: style them with ' +
|
|
34
|
+
'[&>a]: classes. The heading ids come from headingId(text), which the rich text on the page uses too. Put a visible ' +
|
|
35
|
+
'title ("On this page") in a block above it. Shows nothing with fewer than "minHeadings" headings; the canvas shows ' +
|
|
36
|
+
'sample links then.',
|
|
37
|
+
example: {
|
|
38
|
+
type: TABLE_OF_CONTENTS_BLOCK,
|
|
39
|
+
bindings: { content: 'content' },
|
|
40
|
+
className: TOC_CLASS,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -12,7 +12,15 @@ export type DefaultBlocksOptions = {
|
|
|
12
12
|
* Default: a text field. The plugin turns it into a select of its collections that have a `url`.
|
|
13
13
|
*/
|
|
14
14
|
listCollections?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* The names of the site's icons: the same list as `builtinBlocks({ icons })`. With names, the
|
|
17
|
+
* button block gets the props `icon`, `iconPosition` and `iconClassName`, and
|
|
18
|
+
* `builtinComponents({ icons })` renders them. Without names the button has no icon props.
|
|
19
|
+
*/
|
|
20
|
+
icons?: readonly string[];
|
|
15
21
|
};
|
|
22
|
+
/** "arrowUpRight" -> "arrow up right". */
|
|
23
|
+
export declare const iconLabel: (name: string) => string;
|
|
16
24
|
/**
|
|
17
25
|
* Classes the menu component uses itself (the toggle, the panel and the links). They are listed in
|
|
18
26
|
* the block's `classes`, so the generated CSS has them. Each string also holds `builder-css`:
|
|
@@ -37,6 +45,16 @@ export declare const MENU_CLASS_MAP: {
|
|
|
37
45
|
readonly panel: string;
|
|
38
46
|
readonly panelList: 'flex flex-col';
|
|
39
47
|
readonly panelLink: string;
|
|
48
|
+
/** A link with children (one level): a <details> dropdown next to, or in place of, the link. */
|
|
49
|
+
readonly submenu: 'relative flex items-center gap-1';
|
|
50
|
+
readonly submenuDetails: 'group/submenu';
|
|
51
|
+
readonly submenuToggle: string;
|
|
52
|
+
readonly submenuIcon: 'size-4 transition-transform group-open/submenu:rotate-180 motion-reduce:transition-none';
|
|
53
|
+
readonly submenuList: 'absolute top-full left-0 z-50 flex min-w-48 flex-col border border-border bg-background p-2 text-foreground shadow-md';
|
|
54
|
+
readonly submenuLink: string;
|
|
55
|
+
/** The children of a link in the small-screen panel: a nested list. */
|
|
56
|
+
readonly panelSubList: 'flex flex-col pl-4';
|
|
57
|
+
readonly panelSubLink: string;
|
|
40
58
|
/** The optional button after the links in the panel. */
|
|
41
59
|
readonly panelCta: string;
|
|
42
60
|
};
|
|
@@ -49,6 +67,6 @@ export declare const FIELD_CLASS_MAP: {
|
|
|
49
67
|
};
|
|
50
68
|
/**
|
|
51
69
|
* The built-in blocks: stack, grid, heading, text, richText, image, button, link, menu, list (with
|
|
52
|
-
* its listItem blocks), quote, divider, spacer, video, and the dynamic blocks field and
|
|
70
|
+
* its listItem blocks), quote, divider, spacer, video, and the dynamic blocks field, collectionList and repeat.
|
|
53
71
|
*/
|
|
54
72
|
export declare function defaultBlocks(options?: DefaultBlocksOptions): BlockDefinition[];
|