payload-canvas 0.3.0-next.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +522 -39
- package/dist/admin/BuilderTab.js +1 -1
- package/dist/admin/diff/LayoutDiff.js +3 -3
- package/dist/admin/diff/changes.js +8 -0
- package/dist/admin/diff/layoutDiff.scss +48 -48
- package/dist/admin/editor/DragLayer.js +1 -1
- package/dist/admin/editor/InlineToolbar.js +1 -1
- package/dist/admin/editor/Inspector.js +50 -5
- package/dist/admin/editor/Outline.js +13 -11
- package/dist/admin/editor/Overlay.js +1 -1
- package/dist/admin/editor/actions.d.ts +9 -1
- package/dist/admin/editor/actions.js +38 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +1 -1
- package/dist/admin/editor/assistant/ConnectAgents.js +1 -1
- package/dist/admin/editor/assistant/assistant.scss +65 -65
- package/dist/admin/editor/dnd/dnd.scss +2 -2
- package/dist/admin/editor/editor.scss +134 -134
- package/dist/admin/editor/empty/EmptyStart.js +32 -6
- package/dist/admin/editor/empty/empty.scss +3 -3
- package/dist/admin/editor/fields/ArrayField.js +2 -2
- package/dist/admin/editor/fields/GroupField.d.ts +5 -2
- package/dist/admin/editor/fields/GroupField.js +6 -2
- package/dist/admin/editor/fields/WhereField.d.ts +17 -0
- package/dist/admin/editor/fields/WhereField.js +67 -0
- package/dist/admin/editor/fields/access.d.ts +1 -1
- package/dist/admin/editor/fields/fields.scss +122 -33
- package/dist/admin/editor/fields/whereRows.d.ts +28 -0
- package/dist/admin/editor/fields/whereRows.js +118 -0
- package/dist/admin/editor/generate/GenerateImage.js +1 -1
- package/dist/admin/editor/generate/generate.scss +48 -48
- package/dist/admin/editor/icons.d.ts +1 -0
- package/dist/admin/editor/icons.js +3 -1
- package/dist/admin/editor/insert/InsertHandle.js +1 -1
- package/dist/admin/editor/layout/FrameResize.js +1 -1
- package/dist/admin/editor/layout/LeftPanel.js +1 -1
- package/dist/admin/editor/layout/layout.scss +4 -4
- package/dist/admin/editor/live/PresenceUI.js +1 -1
- package/dist/admin/editor/live/presence.scss +1 -1
- package/dist/admin/editor/locale/LocaleField.d.ts +2 -2
- package/dist/admin/editor/locale/LocaleField.js +4 -2
- package/dist/admin/editor/locale/locale.scss +12 -12
- package/dist/admin/editor/media/ImageEditor.js +1 -1
- package/dist/admin/editor/media/media.scss +23 -23
- package/dist/admin/editor/menu/Menu.js +1 -1
- package/dist/admin/editor/menu/blockMenu.js +5 -1
- package/dist/admin/editor/menu/menu.scss +16 -16
- package/dist/admin/editor/motion/MotionPanel.js +2 -2
- package/dist/admin/editor/motion/model.d.ts +2 -2
- package/dist/admin/editor/motion/model.js +2 -2
- package/dist/admin/editor/motion/motion.scss +2 -2
- package/dist/admin/editor/regions/RegionOverlay.js +1 -1
- package/dist/admin/editor/regions/RegionPane.js +1 -1
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +14 -5
- package/dist/admin/editor/runtime.js +1 -0
- package/dist/admin/editor/styles/ColorPicker.js +1 -1
- package/dist/admin/editor/styles/SiteClasses.d.ts +9 -0
- package/dist/admin/editor/styles/SiteClasses.js +31 -0
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
- package/dist/admin/editor/styles/StylesPanel.js +9 -6
- package/dist/admin/editor/styles/VariantBar.js +1 -1
- package/dist/admin/editor/styles/context.d.ts +9 -2
- package/dist/admin/editor/styles/context.js +14 -9
- package/dist/admin/editor/styles/controls.js +3 -3
- package/dist/admin/editor/styles/sections.js +2 -2
- package/dist/admin/editor/styles/styles.scss +147 -93
- package/dist/admin/editor/templates/Bindable.d.ts +14 -6
- package/dist/admin/editor/templates/Bindable.js +74 -18
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/binding.d.ts +11 -4
- package/dist/admin/editor/templates/binding.js +23 -3
- package/dist/admin/editor/templates/templates.scss +90 -90
- package/dist/admin/editor/tooltip/tooltip.scss +4 -4
- package/dist/admin/editor/topbar/DocumentActions.js +1 -1
- package/dist/admin/editor/topbar/DocumentTitle.js +1 -1
- package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/ScreenDrawer.js +1 -1
- package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +1 -1
- package/dist/admin/editor/topbar/screens/screens.scss +20 -20
- package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
- package/dist/admin/editor/topbar/settingsDrawer.scss +7 -7
- package/dist/admin/editor/topbar/topbar.scss +47 -47
- package/dist/admin/editor/ui/Select.js +1 -1
- package/dist/admin/editor/ui/controls.scss +26 -26
- package/dist/admin/screen/BuilderScreen.js +1 -1
- package/dist/ai/adapters/anthropic.d.ts +2 -2
- package/dist/ai/images/service.js +1 -1
- package/dist/ai/loop.d.ts +5 -5
- package/dist/ai/prompt.js +8 -2
- package/dist/ai/tools.js +11 -2
- package/dist/blocks/builtins/carousel.d.ts +32 -0
- package/dist/blocks/builtins/carousel.js +122 -0
- package/dist/blocks/builtins/disclosure.d.ts +13 -0
- package/dist/blocks/builtins/disclosure.js +107 -0
- package/dist/blocks/builtins/faq.d.ts +17 -0
- package/dist/blocks/builtins/faq.js +88 -0
- package/dist/blocks/builtins/filterLink.d.ts +22 -0
- package/dist/blocks/builtins/filterLink.js +76 -0
- package/dist/blocks/builtins/headingId.d.ts +15 -0
- package/dist/blocks/builtins/headingId.js +36 -0
- package/dist/blocks/builtins/icon.d.ts +8 -0
- package/dist/blocks/builtins/icon.js +45 -0
- package/dist/blocks/builtins/index.d.ts +35 -0
- package/dist/blocks/builtins/index.js +50 -0
- package/dist/blocks/builtins/lightbox.d.ts +43 -0
- package/dist/blocks/builtins/lightbox.js +93 -0
- package/dist/blocks/builtins/mediaBackdrop.d.ts +11 -0
- package/dist/blocks/builtins/mediaBackdrop.js +79 -0
- package/dist/blocks/builtins/sectionRef.d.ts +26 -0
- package/dist/blocks/builtins/sectionRef.js +78 -0
- package/dist/blocks/builtins/shared.d.ts +33 -0
- package/dist/blocks/builtins/shared.js +70 -0
- package/dist/blocks/builtins/tableOfContents.d.ts +3 -0
- package/dist/blocks/builtins/tableOfContents.js +44 -0
- package/dist/blocks/defaults.d.ts +28 -10
- package/dist/blocks/defaults.js +413 -20
- package/dist/blocks/index.d.ts +4 -2
- package/dist/blocks/index.js +3 -1
- package/dist/core/attrs.d.ts +27 -0
- package/dist/core/attrs.js +132 -0
- package/dist/core/bindings.d.ts +123 -12
- package/dist/core/bindings.js +504 -19
- package/dist/core/blocks.d.ts +46 -1
- package/dist/core/blocks.js +136 -0
- package/dist/core/classes.d.ts +10 -2
- package/dist/core/classes.js +34 -5
- package/dist/core/fieldAccess.js +1 -1
- package/dist/core/fieldHooks.d.ts +1 -1
- package/dist/core/headings.d.ts +21 -0
- package/dist/core/headings.js +47 -0
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +4 -2
- package/dist/core/motion.d.ts +24 -15
- package/dist/core/motion.js +20 -12
- package/dist/core/operations.js +59 -2
- package/dist/core/payloadBlocks.js +3 -1
- package/dist/core/schema.js +20 -0
- package/dist/core/tree.js +24 -1
- package/dist/core/types.d.ts +87 -0
- package/dist/core/validate.js +29 -4
- package/dist/css/tokens.d.ts +6 -3
- package/dist/css/tokens.js +48 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/live/draftAccess.js +1 -1
- package/dist/live/session.d.ts +1 -1
- package/dist/live/storage.js +4 -2
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +50 -13
- package/dist/mcp/shared.d.ts +34 -31
- package/dist/mcp/shared.js +23 -8
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +30 -12
- package/dist/plugin/listCollections.d.ts +17 -2
- package/dist/plugin/listCollections.js +44 -7
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +1 -1
- package/dist/plugin/templates.d.ts +4 -0
- package/dist/plugin/templates.js +24 -9
- package/dist/protocol/index.d.ts +3 -1
- package/dist/react/canvas/BuilderCanvas.js +6 -4
- package/dist/react/canvas/fetchDocs.d.ts +16 -2
- package/dist/react/canvas/fetchDocs.js +42 -9
- package/dist/react/canvas/inline/rich/editor.js +1 -6
- package/dist/react/canvas/measure.d.ts +3 -1
- package/dist/react/canvas/measure.js +26 -2
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +17 -6
- package/dist/react/canvas/serverBlocks.d.ts +11 -0
- package/dist/react/canvas/serverBlocks.js +28 -1
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +1 -1
- package/dist/react/components/Button.d.ts +11 -2
- package/dist/react/components/Button.js +43 -6
- package/dist/react/components/CollectionList.d.ts +6 -3
- package/dist/react/components/CollectionList.js +21 -7
- package/dist/react/components/Container.js +4 -1
- package/dist/react/components/Field.js +13 -2
- package/dist/react/components/Heading.js +9 -2
- package/dist/react/components/Image.d.ts +9 -0
- package/dist/react/components/Image.js +16 -1
- package/dist/react/components/List.d.ts +1 -0
- package/dist/react/components/List.js +6 -0
- package/dist/react/components/Menu.d.ts +16 -0
- package/dist/react/components/Menu.js +83 -19
- package/dist/react/components/RichText.d.ts +8 -3
- package/dist/react/components/RichText.js +25 -4
- package/dist/react/components/builtins/Accordion.d.ts +9 -0
- package/dist/react/components/builtins/Accordion.js +37 -0
- package/dist/react/components/builtins/BackdropVideo.d.ts +13 -0
- package/dist/react/components/builtins/BackdropVideo.js +16 -0
- package/dist/react/components/builtins/Carousel.d.ts +13 -0
- package/dist/react/components/builtins/Carousel.js +134 -0
- package/dist/react/components/builtins/Disclosure.d.ts +7 -0
- package/dist/react/components/builtins/Disclosure.js +13 -0
- package/dist/react/components/builtins/FilterLink.d.ts +8 -0
- package/dist/react/components/builtins/FilterLink.js +30 -0
- package/dist/react/components/builtins/Icon.d.ts +14 -0
- package/dist/react/components/builtins/Icon.js +28 -0
- package/dist/react/components/builtins/Lightbox.d.ts +45 -0
- package/dist/react/components/builtins/Lightbox.js +252 -0
- package/dist/react/components/builtins/MediaBackdrop.d.ts +14 -0
- package/dist/react/components/builtins/MediaBackdrop.js +61 -0
- package/dist/react/components/builtins/SectionRef.d.ts +7 -0
- package/dist/react/components/builtins/SectionRef.js +17 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +7 -0
- package/dist/react/components/builtins/TableOfContents.js +21 -0
- package/dist/react/components/builtins/glyphs.d.ts +8 -0
- package/dist/react/components/builtins/glyphs.js +7 -0
- package/dist/react/components/builtins/index.d.ts +32 -0
- package/dist/react/components/builtins/index.js +36 -0
- package/dist/react/components/index.js +2 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +3 -1
- package/dist/react/motion/runtime.js +10 -6
- package/dist/react/motion/style.js +1 -1
- package/dist/react/render/PayloadRoot.js +1 -1
- package/dist/react/render/RenderLayout.d.ts +1 -1
- package/dist/react/render/RenderLayout.js +77 -24
- package/dist/react/render/lists.d.ts +107 -5
- package/dist/react/render/lists.js +284 -9
- package/dist/react/render/resolve.d.ts +22 -2
- package/dist/react/render/resolve.js +45 -24
- package/dist/react/render/sections.d.ts +9 -0
- package/dist/react/render/sections.js +51 -0
- package/dist/react/render/types.d.ts +6 -1
- package/dist/react/server.d.ts +4 -4
- package/dist/react/server.js +55 -7
- package/dist/react/theme/ThemeStyle.d.ts +13 -2
- package/dist/react/theme/ThemeStyle.js +13 -3
- package/dist/theme/admin/ColorField.d.ts +2 -2
- package/dist/theme/admin/ColorField.js +2 -2
- package/dist/theme/admin/FontField.d.ts +2 -2
- package/dist/theme/admin/FontField.js +2 -2
- package/dist/theme/admin/SaveSignal.js +2 -2
- package/dist/theme/admin/fields.scss +48 -48
- package/package.json +23 -28
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A native <details>: it opens with the mouse and the keyboard without script, and the closed
|
|
4
|
+
* content stays in the HTML. The height animation is CSS only. Open on the canvas, so both slots
|
|
5
|
+
* can be edited.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Disclosure({ props, className, attributes, slotAttributes, slots, mode }: BlockComponentProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DISCLOSURE_CLASS_MAP as C } from '../../../blocks/builtins/disclosure.js';
|
|
3
|
+
import { joinClasses } from '../../../blocks/builtins/shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* A native <details>: it opens with the mouse and the keyboard without script, and the closed
|
|
6
|
+
* content stays in the HTML. The height animation is CSS only. Open on the canvas, so both slots
|
|
7
|
+
* can be edited.
|
|
8
|
+
*/
|
|
9
|
+
export function Disclosure({ props, className, attributes, slotAttributes, slots, mode }) {
|
|
10
|
+
const open = mode === 'canvas' || props.open === true;
|
|
11
|
+
const classes = props.animate === false ? className : className ? `${className} ${C.animate}` : C.animate;
|
|
12
|
+
return (_jsxs("details", { ...attributes, className: classes, open: open || undefined, children: [_jsx("summary", { ...slotAttributes.summary, className: joinClasses(C.summary, slotAttributes.summary?.className), children: slots.summary }), _jsx("div", { ...slotAttributes.content, children: slots.content })] }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A link to the current page with one URL query value set, toggled or cleared. Before hydration
|
|
4
|
+
* the href is relative (`?param=value`), so the link works and search engines can follow it.
|
|
5
|
+
* After hydration it keeps the page's other query values and marks the current filter with
|
|
6
|
+
* `aria-current="true"`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function FilterLink({ props, className, attributes, slotAttributes, slots }: BlockComponentProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { filterHref } from '../../../blocks/builtins/filterLink.js';
|
|
5
|
+
import { textOr } from '../../../blocks/builtins/shared.js';
|
|
6
|
+
const subscribe = (onChange) => {
|
|
7
|
+
window.addEventListener('popstate', onChange);
|
|
8
|
+
return () => window.removeEventListener('popstate', onChange);
|
|
9
|
+
};
|
|
10
|
+
const clientUrl = () => window.location.pathname + window.location.search;
|
|
11
|
+
// The server does not know the URL: relative hrefs, nothing active until the client hydrates.
|
|
12
|
+
const serverUrl = () => null;
|
|
13
|
+
/**
|
|
14
|
+
* A link to the current page with one URL query value set, toggled or cleared. Before hydration
|
|
15
|
+
* the href is relative (`?param=value`), so the link works and search engines can follow it.
|
|
16
|
+
* After hydration it keeps the page's other query values and marks the current filter with
|
|
17
|
+
* `aria-current="true"`.
|
|
18
|
+
*/
|
|
19
|
+
export function FilterLink({ props, className, attributes, slotAttributes, slots }) {
|
|
20
|
+
const url = useSyncExternalStore(subscribe, clientUrl, serverUrl);
|
|
21
|
+
const parsed = url === null ? null : new URL(url, 'http://localhost');
|
|
22
|
+
const { href, active } = filterHref(parsed?.pathname ?? '', parsed?.searchParams ?? new URLSearchParams(), {
|
|
23
|
+
param: textOr(props.param, ''),
|
|
24
|
+
value: textOr(props.value, ''),
|
|
25
|
+
multiple: props.multiple === true,
|
|
26
|
+
// The page parameters of the layout's lists with their own `pageParam` (`withPageParams`).
|
|
27
|
+
pageParams: Array.isArray(props.$pageParams) ? props.$pageParams.filter((item) => typeof item === 'string') : [],
|
|
28
|
+
});
|
|
29
|
+
return (_jsx("a", { ...attributes, ...slotAttributes.children, href: href, "aria-current": url !== null && active ? 'true' : undefined, className: className, children: slots.children }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ComponentType, type SVGProps } from 'react';
|
|
2
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
3
|
+
/** An icon component of the site's set. It gets `className`, the ARIA attributes and the canvas attributes. */
|
|
4
|
+
export type IconComponent = ComponentType<SVGProps<SVGSVGElement>>;
|
|
5
|
+
/**
|
|
6
|
+
* The site's icons by name: the same names as `builtinBlocks({ icons })`. Check both lists with
|
|
7
|
+
* `satisfies IconMap<(typeof ICON_NAMES)[number]>`.
|
|
8
|
+
*/
|
|
9
|
+
export type IconMap<Name extends string = string> = Record<Name, IconComponent>;
|
|
10
|
+
/**
|
|
11
|
+
* The `icon` block's component for an icon map. One component per map, so React keeps the
|
|
12
|
+
* component type. Decorative (`aria-hidden`) unless the block has a label.
|
|
13
|
+
*/
|
|
14
|
+
export declare function iconComponent(icons: IconMap): ComponentType<BlockComponentProps>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { asText, PlaceholderText } from '../placeholder.js';
|
|
4
|
+
const byMap = new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* The `icon` block's component for an icon map. One component per map, so React keeps the
|
|
7
|
+
* component type. Decorative (`aria-hidden`) unless the block has a label.
|
|
8
|
+
*/
|
|
9
|
+
export function iconComponent(icons) {
|
|
10
|
+
const known = byMap.get(icons);
|
|
11
|
+
if (known)
|
|
12
|
+
return known;
|
|
13
|
+
function Icon({ props, className, attributes, mode }) {
|
|
14
|
+
const name = asText(props.name);
|
|
15
|
+
const glyph = name && Object.hasOwn(icons, name) ? icons[name] : undefined;
|
|
16
|
+
if (!glyph) {
|
|
17
|
+
if (mode !== 'canvas')
|
|
18
|
+
return null;
|
|
19
|
+
return (_jsx("span", { ...attributes, className: className, children: _jsx(PlaceholderText, { children: name ? `Icon "${name}" is not in the icon set` : 'Icon' }) }));
|
|
20
|
+
}
|
|
21
|
+
const label = asText(props.label).trim();
|
|
22
|
+
const a11y = label ? { role: 'img', 'aria-label': label } : { 'aria-hidden': true, focusable: 'false' };
|
|
23
|
+
// A lookup in a fixed map, not a component made during render.
|
|
24
|
+
return createElement(glyph, { ...attributes, ...a11y, className });
|
|
25
|
+
}
|
|
26
|
+
byMap.set(icons, Icon);
|
|
27
|
+
return Icon;
|
|
28
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
type Photo = {
|
|
3
|
+
src: string;
|
|
4
|
+
srcSet: string;
|
|
5
|
+
alt: string;
|
|
6
|
+
};
|
|
7
|
+
/** The parts of a page image a set reads (an `HTMLImageElement`). */
|
|
8
|
+
export type SetImage = {
|
|
9
|
+
getAttribute(name: string): string | null;
|
|
10
|
+
closest(selector: string): unknown;
|
|
11
|
+
currentSrc?: string;
|
|
12
|
+
src: string;
|
|
13
|
+
srcset: string;
|
|
14
|
+
alt: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The photos of a set: the images in page order, without skipped ones (`data-lightbox-skip` on the
|
|
18
|
+
* image or round it), each source once. `images[i]` is the page image of `photos[i]`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function photoSet<T extends SetImage>(list: T[]): {
|
|
21
|
+
photos: Photo[];
|
|
22
|
+
images: T[];
|
|
23
|
+
};
|
|
24
|
+
/** Where a click on `target` opens the set: at the photo with its source, else at the first photo. */
|
|
25
|
+
export declare const openIndex: (images: SetImage[], target: SetImage) => number;
|
|
26
|
+
/** The next index in a list of `count`, wrapping around. */
|
|
27
|
+
export declare const stepIndex: (index: number, by: number, count: number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* The step of a swipe that moved `dx` sideways and `dy` down: 1 (next) for a swipe to the left,
|
|
30
|
+
* -1 (previous) for a swipe to the right, 0 when it was short or mostly vertical.
|
|
31
|
+
*/
|
|
32
|
+
export declare function swipeStep(dx: number, dy: number, distance?: number): -1 | 0 | 1;
|
|
33
|
+
/**
|
|
34
|
+
* A container whose images open full screen. The native modal dialog traps the focus, makes the
|
|
35
|
+
* page inert, closes on Escape and gives the focus back. Arrow keys step through the images.
|
|
36
|
+
* Images get `tabindex="0"` and `role="button"`, so the keyboard can open them. On touch screens a
|
|
37
|
+
* sideways swipe steps too (pointer events; a mouse drag does not). Off on the canvas,
|
|
38
|
+
* so a click selects an image there.
|
|
39
|
+
*
|
|
40
|
+
* Motion: the dialog and its backdrop fade in, and the photo grows from 96% as it loads; a step
|
|
41
|
+
* slides the old photo out and the new one in; closing fades out. Under reduced motion only the
|
|
42
|
+
* fades stay. A photo that has not loaded after a moment shows a spinning ring.
|
|
43
|
+
*/
|
|
44
|
+
export declare function Lightbox({ props, className, attributes, slotAttributes, slots, mode }: BlockComponentProps): import("react").JSX.Element;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { LIGHTBOX_CLASS_MAP as C, LIGHTBOX_CLOSE_EVENT, LIGHTBOX_LABELS as L, LIGHTBOX_SKIP_ATTRIBUTE, } from '../../../blocks/builtins/lightbox.js';
|
|
5
|
+
import { labelOf, textOr } from '../../../blocks/builtins/shared.js';
|
|
6
|
+
import { Chevron, CloseIcon } from './glyphs.js';
|
|
7
|
+
/** The opening: the backdrop fades in and the photo grows a little as it fades in. */
|
|
8
|
+
const OPEN_MS = 320;
|
|
9
|
+
/** A step: the old photo slides out as the new one slides in. */
|
|
10
|
+
const STEP_MS = 260;
|
|
11
|
+
const CLOSE_MS = 200;
|
|
12
|
+
const EASE_OUT = 'cubic-bezier(0.22, 1, 0.36, 1)';
|
|
13
|
+
const EASE_IN = 'cubic-bezier(0.4, 0, 1, 1)';
|
|
14
|
+
/** A photo that loads faster than this shows no loading ring. */
|
|
15
|
+
const LOADING_DELAY_MS = 150;
|
|
16
|
+
/** How far a photo slides when it steps, in percent of its width. */
|
|
17
|
+
const STEP_SHIFT = 4;
|
|
18
|
+
const reducedMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
19
|
+
/** The images of a lightbox, not the large photos of its own dialog. */
|
|
20
|
+
const imagesIn = (root) => [...root.querySelectorAll('img')].filter((img) => !img.closest('dialog'));
|
|
21
|
+
/** The image a click or a key on `target` opens: the image itself, or the one inside a link or button. */
|
|
22
|
+
function imageAt(target) {
|
|
23
|
+
if (!(target instanceof Element) || target.closest('dialog'))
|
|
24
|
+
return null;
|
|
25
|
+
return target.closest('img') ?? target.closest('a, button')?.querySelector('img') ?? null;
|
|
26
|
+
}
|
|
27
|
+
/** The key that makes two images one photo: the `src` attribute. */
|
|
28
|
+
const sourceOf = (img) => img.getAttribute('src') ?? img.src;
|
|
29
|
+
/**
|
|
30
|
+
* The photos of a set: the images in page order, without skipped ones (`data-lightbox-skip` on the
|
|
31
|
+
* image or round it), each source once. `images[i]` is the page image of `photos[i]`.
|
|
32
|
+
*/
|
|
33
|
+
export function photoSet(list) {
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
const images = [];
|
|
36
|
+
for (const img of list) {
|
|
37
|
+
const source = sourceOf(img);
|
|
38
|
+
if (img.closest(`[${LIGHTBOX_SKIP_ATTRIBUTE}]`) || seen.has(source))
|
|
39
|
+
continue;
|
|
40
|
+
seen.add(source);
|
|
41
|
+
images.push(img);
|
|
42
|
+
}
|
|
43
|
+
return { images, photos: images.map((img) => ({ src: img.currentSrc || img.src, srcSet: img.srcset, alt: img.alt })) };
|
|
44
|
+
}
|
|
45
|
+
/** Where a click on `target` opens the set: at the photo with its source, else at the first photo. */
|
|
46
|
+
export const openIndex = (images, target) => {
|
|
47
|
+
const source = sourceOf(target);
|
|
48
|
+
return Math.max(0, images.findIndex((img) => sourceOf(img) === source));
|
|
49
|
+
};
|
|
50
|
+
/** The next index in a list of `count`, wrapping around. */
|
|
51
|
+
export const stepIndex = (index, by, count) => (count > 0 ? (index + by + count) % count : 0);
|
|
52
|
+
/** Shortest sideways move, in CSS pixels, that counts as a swipe. */
|
|
53
|
+
const SWIPE_DISTANCE = 50;
|
|
54
|
+
/**
|
|
55
|
+
* The step of a swipe that moved `dx` sideways and `dy` down: 1 (next) for a swipe to the left,
|
|
56
|
+
* -1 (previous) for a swipe to the right, 0 when it was short or mostly vertical.
|
|
57
|
+
*/
|
|
58
|
+
export function swipeStep(dx, dy, distance = SWIPE_DISTANCE) {
|
|
59
|
+
if (Math.abs(dx) < distance || Math.abs(dx) <= Math.abs(dy))
|
|
60
|
+
return 0;
|
|
61
|
+
return dx < 0 ? 1 : -1;
|
|
62
|
+
}
|
|
63
|
+
/** Fades the dialog and its backdrop. A browser without `pseudoElement` animations skips the backdrop. */
|
|
64
|
+
function fadeDialog(dialog, frames, options) {
|
|
65
|
+
const animations = [dialog.animate(frames, options)];
|
|
66
|
+
try {
|
|
67
|
+
animations.push(dialog.animate(frames, { ...options, pseudoElement: '::backdrop' }));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// The backdrop shows at once.
|
|
71
|
+
}
|
|
72
|
+
return animations;
|
|
73
|
+
}
|
|
74
|
+
/** The loading ring fades in only when the photo is still loading after a moment. */
|
|
75
|
+
function fadeInLater(ring) {
|
|
76
|
+
const fade = ring?.animate([{ opacity: 0 }, { opacity: 1 }], { delay: LOADING_DELAY_MS, duration: 200, fill: 'both' });
|
|
77
|
+
return () => fade?.cancel();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A container whose images open full screen. The native modal dialog traps the focus, makes the
|
|
81
|
+
* page inert, closes on Escape and gives the focus back. Arrow keys step through the images.
|
|
82
|
+
* Images get `tabindex="0"` and `role="button"`, so the keyboard can open them. On touch screens a
|
|
83
|
+
* sideways swipe steps too (pointer events; a mouse drag does not). Off on the canvas,
|
|
84
|
+
* so a click selects an image there.
|
|
85
|
+
*
|
|
86
|
+
* Motion: the dialog and its backdrop fade in, and the photo grows from 96% as it loads; a step
|
|
87
|
+
* slides the old photo out and the new one in; closing fades out. Under reduced motion only the
|
|
88
|
+
* fades stay. A photo that has not loaded after a moment shows a spinning ring.
|
|
89
|
+
*/
|
|
90
|
+
export function Lightbox({ props, className, attributes, slotAttributes, slots, mode }) {
|
|
91
|
+
const root = useRef(null);
|
|
92
|
+
const dialog = useRef(null);
|
|
93
|
+
const photoRef = useRef(null);
|
|
94
|
+
const leavingRef = useRef(null);
|
|
95
|
+
const [photos, setPhotos] = useState([]);
|
|
96
|
+
const [index, setIndex] = useState(0);
|
|
97
|
+
const [loaded, setLoaded] = useState(false);
|
|
98
|
+
/** The photo that slides out during a step. */
|
|
99
|
+
const [leaving, setLeaving] = useState(null);
|
|
100
|
+
/** The page image of each photo, for the close event. */
|
|
101
|
+
const images = useRef([]);
|
|
102
|
+
/** How the next photo comes in: `open` (grows in) or the step (1 or -1, slides in). */
|
|
103
|
+
const entrance = useRef('open');
|
|
104
|
+
const closing = useRef(false);
|
|
105
|
+
const steps = useRef(0);
|
|
106
|
+
/** Where a touch or pen swipe started; `swiped` drops the click that follows a swipe. */
|
|
107
|
+
const swipe = useRef(null);
|
|
108
|
+
const swiped = useRef(false);
|
|
109
|
+
const canvas = mode === 'canvas';
|
|
110
|
+
const group = textOr(props.group, '');
|
|
111
|
+
const open = photos.length > 0;
|
|
112
|
+
// Runs after every render: repeats and lists can add images.
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!root.current || canvas)
|
|
115
|
+
return;
|
|
116
|
+
for (const img of imagesIn(root.current)) {
|
|
117
|
+
if (img.closest('a, button') || img.hasAttribute('tabindex'))
|
|
118
|
+
continue;
|
|
119
|
+
img.tabIndex = 0;
|
|
120
|
+
img.setAttribute('role', 'button');
|
|
121
|
+
img.setAttribute('aria-haspopup', 'dialog');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const element = dialog.current;
|
|
126
|
+
if (!open || !element || element.open)
|
|
127
|
+
return;
|
|
128
|
+
element.showModal();
|
|
129
|
+
fadeDialog(element, [{ opacity: 0 }, { opacity: 1 }], { duration: OPEN_MS, easing: EASE_OUT });
|
|
130
|
+
}, [open]);
|
|
131
|
+
// The photo of the last step slides out, then goes.
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const element = leavingRef.current;
|
|
134
|
+
if (!element || !leaving)
|
|
135
|
+
return;
|
|
136
|
+
const out = element.animate([
|
|
137
|
+
{ opacity: 1, transform: 'none' },
|
|
138
|
+
{ opacity: 0, transform: `translateX(${-leaving.by * STEP_SHIFT}%)` },
|
|
139
|
+
], { duration: STEP_MS, easing: EASE_OUT, fill: 'forwards' });
|
|
140
|
+
out.onfinish = () => setLeaving((current) => (current === leaving ? null : current));
|
|
141
|
+
return () => out.cancel();
|
|
142
|
+
}, [leaving]);
|
|
143
|
+
const show = (target) => {
|
|
144
|
+
const scope = group ? [...document.querySelectorAll(`[data-lightbox-group="${CSS.escape(group)}"]`)] : [root.current];
|
|
145
|
+
const set = photoSet(scope.flatMap(imagesIn));
|
|
146
|
+
images.current = set.images;
|
|
147
|
+
entrance.current = 'open';
|
|
148
|
+
closing.current = false;
|
|
149
|
+
setLeaving(null);
|
|
150
|
+
setLoaded(false);
|
|
151
|
+
setPhotos(set.photos);
|
|
152
|
+
setIndex(openIndex(set.images, target));
|
|
153
|
+
};
|
|
154
|
+
const onClick = (event) => {
|
|
155
|
+
const img = canvas ? null : imageAt(event.target);
|
|
156
|
+
if (!img)
|
|
157
|
+
return;
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
show(img);
|
|
160
|
+
};
|
|
161
|
+
const onKeyDown = (event) => {
|
|
162
|
+
if (canvas || (event.key !== 'Enter' && event.key !== ' '))
|
|
163
|
+
return;
|
|
164
|
+
if (!(event.target instanceof HTMLImageElement) || event.target.closest('dialog'))
|
|
165
|
+
return;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
show(event.target);
|
|
168
|
+
};
|
|
169
|
+
const step = (by) => {
|
|
170
|
+
if (photos.length < 2 || closing.current)
|
|
171
|
+
return;
|
|
172
|
+
// The shown photo slides out over the next one (no slide under reduced motion).
|
|
173
|
+
if (loaded && !reducedMotion())
|
|
174
|
+
setLeaving({ photo: photos[index], by, key: ++steps.current });
|
|
175
|
+
else
|
|
176
|
+
setLeaving(null);
|
|
177
|
+
entrance.current = by;
|
|
178
|
+
setLoaded(false);
|
|
179
|
+
setIndex(stepIndex(index, by, photos.length));
|
|
180
|
+
};
|
|
181
|
+
const onPhotoLoad = (event) => {
|
|
182
|
+
setLoaded(true);
|
|
183
|
+
const kind = entrance.current;
|
|
184
|
+
const still = reducedMotion();
|
|
185
|
+
const from = kind === 'open' ? 'scale(0.96)' : `translateX(${kind * STEP_SHIFT}%)`;
|
|
186
|
+
event.currentTarget.animate([
|
|
187
|
+
{ opacity: 0, transform: still ? 'none' : from },
|
|
188
|
+
{ opacity: 1, transform: 'none' },
|
|
189
|
+
], { duration: kind === 'open' ? OPEN_MS : STEP_MS, easing: EASE_OUT });
|
|
190
|
+
};
|
|
191
|
+
const close = () => {
|
|
192
|
+
const element = dialog.current;
|
|
193
|
+
if (!element?.open || closing.current)
|
|
194
|
+
return;
|
|
195
|
+
closing.current = true;
|
|
196
|
+
const options = { duration: CLOSE_MS, easing: EASE_IN, fill: 'forwards' };
|
|
197
|
+
const animations = fadeDialog(element, [{ opacity: 1 }, { opacity: 0 }], options);
|
|
198
|
+
if (!reducedMotion()) {
|
|
199
|
+
const shrink = photoRef.current?.animate([{ transform: 'none' }, { transform: 'scale(0.97)' }], options);
|
|
200
|
+
if (shrink)
|
|
201
|
+
animations.push(shrink);
|
|
202
|
+
}
|
|
203
|
+
void Promise.all(animations.map((animation) => animation.finished))
|
|
204
|
+
.catch(() => { })
|
|
205
|
+
.then(() => element.close());
|
|
206
|
+
};
|
|
207
|
+
const onClose = () => {
|
|
208
|
+
closing.current = false;
|
|
209
|
+
const image = images.current[index];
|
|
210
|
+
images.current = [];
|
|
211
|
+
setPhotos([]);
|
|
212
|
+
setLeaving(null);
|
|
213
|
+
image?.dispatchEvent(new CustomEvent(LIGHTBOX_CLOSE_EVENT, { bubbles: true, detail: { index } }));
|
|
214
|
+
};
|
|
215
|
+
const onSwipeStart = (event) => {
|
|
216
|
+
swiped.current = false;
|
|
217
|
+
swipe.current = event.pointerType === 'mouse' || !event.isPrimary ? null : { x: event.clientX, y: event.clientY, id: event.pointerId };
|
|
218
|
+
};
|
|
219
|
+
const onSwipeEnd = (event) => {
|
|
220
|
+
const start = swipe.current;
|
|
221
|
+
swipe.current = null;
|
|
222
|
+
if (!start || start.id !== event.pointerId)
|
|
223
|
+
return;
|
|
224
|
+
const by = swipeStep(event.clientX - start.x, event.clientY - start.y);
|
|
225
|
+
if (by === 0 || photos.length < 2)
|
|
226
|
+
return;
|
|
227
|
+
swiped.current = true;
|
|
228
|
+
step(by);
|
|
229
|
+
};
|
|
230
|
+
const label = (name) => labelOf(props, L, name, { n: index + 1, count: photos.length });
|
|
231
|
+
const photo = photos[index];
|
|
232
|
+
const caption = props.captions === true && photo?.alt ? photo.alt : '';
|
|
233
|
+
const showCount = props.count !== false && photos.length > 1;
|
|
234
|
+
return (_jsxs("div", { ...attributes, ...slotAttributes.children, ref: root, className: className ? `${className} ${C.root}` : C.root, "data-lightbox-group": group || undefined, onClick: onClick, onKeyDown: onKeyDown, children: [slots.children, open && photo ? (_jsxs("dialog", { ref: dialog, "aria-label": textOr(props.label, 'Photos'), className: C.dialog, onCancel: (event) => {
|
|
235
|
+
// Escape: close with the fade, not at once. The browser may refuse to wait; it then closes.
|
|
236
|
+
if (!event.cancelable)
|
|
237
|
+
return;
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
close();
|
|
240
|
+
}, onClose: onClose, onPointerDown: onSwipeStart, onPointerUp: onSwipeEnd, onPointerCancel: () => (swipe.current = null), onClickCapture: (event) => {
|
|
241
|
+
// The click after a swipe would close the dialog (a click beside the photo).
|
|
242
|
+
if (!swiped.current)
|
|
243
|
+
return;
|
|
244
|
+
swiped.current = false;
|
|
245
|
+
event.stopPropagation();
|
|
246
|
+
}, onKeyDown: (event) => {
|
|
247
|
+
if (event.key === 'ArrowRight')
|
|
248
|
+
step(1);
|
|
249
|
+
if (event.key === 'ArrowLeft')
|
|
250
|
+
step(-1);
|
|
251
|
+
}, children: [_jsxs("figure", { className: C.figure, "aria-busy": loaded ? undefined : true, onClick: (event) => event.target === event.currentTarget && close(), children: [leaving ? (_jsx("img", { ref: leavingRef, "data-lightbox-photo": "leaving", className: C.photo, src: leaving.photo.src, ...(leaving.photo.srcSet ? { srcSet: leaving.photo.srcSet, sizes: '100vw' } : {}), alt: "", "aria-hidden": "true" }, `leaving-${leaving.key}`)) : null, _jsx("img", { ref: photoRef, "data-lightbox-photo": "", className: C.photo, style: loaded ? undefined : { opacity: 0 }, src: photo.src, ...(photo.srcSet ? { srcSet: photo.srcSet, sizes: '100vw' } : {}), alt: photo.alt, onLoad: onPhotoLoad, onError: () => setLoaded(true) }, index), _jsxs("figcaption", { className: `${C.caption} ${caption ? '' : C.hidden}`, "aria-live": "polite", children: [caption ? `${caption}. ` : '', label('countLabel')] })] }), loaded ? null : _jsx("span", { ref: fadeInLater, "data-lightbox-loading": "", "aria-hidden": "true", className: C.loading, style: { opacity: 0 } }, index), showCount ? (_jsx("span", { "data-lightbox-count": "", "aria-hidden": "true", className: C.count, children: label('countLabel') })) : null, _jsx("button", { type: "button", "data-lightbox-button": "close", "aria-label": label('closeLabel'), className: `${C.button} ${C.close}`, onClick: close, children: _jsx(CloseIcon, { className: C.icon }) }), photos.length > 1 ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-lightbox-button": "previous", "aria-label": label('previousLabel'), className: `${C.button} ${C.previous}`, onClick: () => step(-1), children: _jsx(Chevron, { className: C.icon, direction: "left" }) }), _jsx("button", { type: "button", "data-lightbox-button": "next", "aria-label": label('nextLabel'), className: `${C.button} ${C.next}`, onClick: () => step(1), children: _jsx(Chevron, { className: C.icon, direction: "right" }) })] })) : null] })) : null] }));
|
|
252
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
/** Maps a stored media URL to the one the site serves, e.g. an absolute URL to its path. */
|
|
3
|
+
export type MediaUrl = (url: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* The media backdrop component, with `mediaUrl` applied to the URLs of its uploads (the photo and
|
|
6
|
+
* its sizes, the video, the poster). `builtinComponents({ mediaUrl })` uses it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mediaBackdropComponent(mediaUrl?: MediaUrl): (block: BlockComponentProps) => import("react").JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* A photo or a muted looping video behind the block's content. The media and the optional
|
|
11
|
+
* overlay are absolute children (`data-backdrop-media`, `data-backdrop-overlay`); the slot's
|
|
12
|
+
* blocks follow them, so the block's className lays out the content.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MediaBackdrop: (block: BlockComponentProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { preload } from 'react-dom';
|
|
3
|
+
import { MEDIA_BACKDROP_CLASS_MAP as C } from '../../../blocks/builtins/mediaBackdrop.js';
|
|
4
|
+
import { textOr } from '../../../blocks/builtins/shared.js';
|
|
5
|
+
import { editableImage } from '../../render/editable.js';
|
|
6
|
+
import { focalStyle, isDoc, srcSetOf } from '../Image.js';
|
|
7
|
+
import { BackdropVideo } from './BackdropVideo.js';
|
|
8
|
+
/** The media document with `mediaUrl` applied to its file and to each image size. */
|
|
9
|
+
function docOf(value, mediaUrl) {
|
|
10
|
+
if (!isDoc(value))
|
|
11
|
+
return null;
|
|
12
|
+
const doc = value;
|
|
13
|
+
if (!mediaUrl)
|
|
14
|
+
return doc;
|
|
15
|
+
const sizes = doc.sizes && typeof doc.sizes === 'object' ? doc.sizes : null;
|
|
16
|
+
return {
|
|
17
|
+
...doc,
|
|
18
|
+
url: mediaUrl(doc.url),
|
|
19
|
+
...(sizes
|
|
20
|
+
? {
|
|
21
|
+
sizes: Object.fromEntries(Object.entries(sizes).map(([name, size]) => [name, isDoc(size) ? { ...size, url: mediaUrl(size.url) } : size])),
|
|
22
|
+
}
|
|
23
|
+
: {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The media backdrop component, with `mediaUrl` applied to the URLs of its uploads (the photo and
|
|
28
|
+
* its sizes, the video, the poster). `builtinComponents({ mediaUrl })` uses it.
|
|
29
|
+
*/
|
|
30
|
+
export function mediaBackdropComponent(mediaUrl) {
|
|
31
|
+
return function MediaBackdrop(block) {
|
|
32
|
+
return backdrop(block, mediaUrl);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A photo or a muted looping video behind the block's content. The media and the optional
|
|
37
|
+
* overlay are absolute children (`data-backdrop-media`, `data-backdrop-overlay`); the slot's
|
|
38
|
+
* blocks follow them, so the block's className lays out the content.
|
|
39
|
+
*/
|
|
40
|
+
export const MediaBackdrop = mediaBackdropComponent();
|
|
41
|
+
function backdrop(block, mediaUrl) {
|
|
42
|
+
const { props, className, attributes, slotAttributes, slots, mode } = block;
|
|
43
|
+
const image = docOf(props.image, mediaUrl);
|
|
44
|
+
// `videoUrl` is a link an editor typed, not a stored upload, so it stays as it is.
|
|
45
|
+
const videoSrc = docOf(props.video, mediaUrl)?.url ?? textOr(props.videoUrl, '');
|
|
46
|
+
const priority = props.priority === true;
|
|
47
|
+
let media = null;
|
|
48
|
+
if (videoSrc) {
|
|
49
|
+
const poster = docOf(props.poster, mediaUrl) ?? image;
|
|
50
|
+
if (poster && priority)
|
|
51
|
+
preload(poster.url, { as: 'image', fetchPriority: 'high' });
|
|
52
|
+
media = (_jsx(BackdropVideo, { src: videoSrc, poster: poster?.url, className: C.media, style: focalStyle(poster), priority: priority, play: mode !== 'canvas' }, videoSrc));
|
|
53
|
+
}
|
|
54
|
+
else if (image) {
|
|
55
|
+
const srcSet = srcSetOf(image);
|
|
56
|
+
media = (_jsx("img", { ...editableImage(mode, 'image'), "data-backdrop-media": "", className: C.media, src: image.url, ...(srcSet ? { srcSet, sizes: textOr(props.sizes, '100vw') } : {}),
|
|
57
|
+
// A background is decoration unless the block names it.
|
|
58
|
+
alt: textOr(props.alt, ''), width: typeof image.width === 'number' ? image.width : undefined, height: typeof image.height === 'number' ? image.height : undefined, style: focalStyle(image), loading: priority ? 'eager' : 'lazy', ...(priority ? { fetchPriority: 'high' } : {}) }));
|
|
59
|
+
}
|
|
60
|
+
return (_jsxs("div", { ...attributes, ...slotAttributes.children, className: className, children: [media, props.overlay === true ? _jsx("div", { "data-backdrop-overlay": "", "aria-hidden": "true", className: C.overlay }) : null, slots.children] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A live saved section: its blocks, with no element of its own on the site. On the canvas an
|
|
4
|
+
* element with `display: contents` holds the editor attributes, so the editor can select it.
|
|
5
|
+
* The blocks come from `loadLayoutData` (or the canvas); without them the site shows nothing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function SectionRef({ block, slots, attributes, mode }: BlockComponentProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { SECTION_REF_SLOT } from '../../../blocks/builtins/sectionRef.js';
|
|
3
|
+
import { PlaceholderBox } from '../placeholder.js';
|
|
4
|
+
const CONTENTS = { display: 'contents' };
|
|
5
|
+
/**
|
|
6
|
+
* A live saved section: its blocks, with no element of its own on the site. On the canvas an
|
|
7
|
+
* element with `display: contents` holds the editor attributes, so the editor can select it.
|
|
8
|
+
* The blocks come from `loadLayoutData` (or the canvas); without them the site shows nothing.
|
|
9
|
+
*/
|
|
10
|
+
export function SectionRef({ block, slots, attributes, mode }) {
|
|
11
|
+
const loaded = (block.slots?.[SECTION_REF_SLOT]?.length ?? 0) > 0;
|
|
12
|
+
if (mode !== 'canvas')
|
|
13
|
+
return loaded ? slots[SECTION_REF_SLOT] : null;
|
|
14
|
+
if (!loaded)
|
|
15
|
+
return _jsx(PlaceholderBox, { attributes: attributes, label: "Saved section: pick one in the Content tab" });
|
|
16
|
+
return (_jsx("div", { ...attributes, style: CONTENTS, children: slots[SECTION_REF_SLOT] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BlockComponentProps } from '../../render/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Links to the H2 headings of the bound rich text (`content`). The ids come from `headingId`, the
|
|
4
|
+
* same function that gives the headings on the page their ids. The canvas shows sample links when
|
|
5
|
+
* there are too few headings, so the block can be selected and styled.
|
|
6
|
+
*/
|
|
7
|
+
export declare function TableOfContents({ props, className, attributes, mode }: BlockComponentProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { lexicalHeadings } from '../../../blocks/builtins/headingId.js';
|
|
3
|
+
import { textOr } from '../../../blocks/builtins/shared.js';
|
|
4
|
+
const SAMPLE = [
|
|
5
|
+
{ id: 'sample-1', text: 'First heading of the text (sample)' },
|
|
6
|
+
{ id: 'sample-2', text: 'Second heading (sample)' },
|
|
7
|
+
{ id: 'sample-3', text: 'Third heading (sample)' },
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Links to the H2 headings of the bound rich text (`content`). The ids come from `headingId`, the
|
|
11
|
+
* same function that gives the headings on the page their ids. The canvas shows sample links when
|
|
12
|
+
* there are too few headings, so the block can be selected and styled.
|
|
13
|
+
*/
|
|
14
|
+
export function TableOfContents({ props, className, attributes, mode }) {
|
|
15
|
+
const min = typeof props.minHeadings === 'number' ? props.minHeadings : 3;
|
|
16
|
+
const found = lexicalHeadings(props.content);
|
|
17
|
+
const headings = found.length >= min ? found : mode === 'canvas' ? SAMPLE : [];
|
|
18
|
+
if (headings.length === 0)
|
|
19
|
+
return null;
|
|
20
|
+
return (_jsx("nav", { ...attributes, "aria-label": textOr(props.label, 'On this page'), className: className, children: headings.map((heading, i) => (_jsx("a", { href: `#${heading.id}`, children: heading.text }, `${heading.id}-${i}`))) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type GlyphProps = {
|
|
2
|
+
className: string;
|
|
3
|
+
};
|
|
4
|
+
export declare function Chevron({ className, direction }: GlyphProps & {
|
|
5
|
+
direction: 'left' | 'right';
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
export declare function CloseIcon({ className }: GlyphProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Chevron({ className, direction }) {
|
|
3
|
+
return (_jsx("svg", { className: className, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: direction === 'left' ? 'M12.5 4.5 7 10l5.5 5.5' : 'M7.5 4.5 13 10l-5.5 5.5' }) }));
|
|
4
|
+
}
|
|
5
|
+
export function CloseIcon({ className }) {
|
|
6
|
+
return (_jsx("svg", { className: className, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M5 5l10 10M15 5L5 15" }) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BlockComponents } from '../../render/types.js';
|
|
2
|
+
import { type IconMap } from './Icon.js';
|
|
3
|
+
import { type MediaUrl } from './MediaBackdrop.js';
|
|
4
|
+
export type BuiltinComponentsOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The site's icons by name, for the `icon` block and the button's `icon` prop. The same names as
|
|
7
|
+
* `builtinBlocks({ icons })` and `defaultBlocks({ icons })`.
|
|
8
|
+
*/
|
|
9
|
+
icons?: IconMap;
|
|
10
|
+
/**
|
|
11
|
+
* Maps a stored media URL to the one the site serves, for the media backdrop's uploads. Example:
|
|
12
|
+
* `(url) => new URL(url, 'http://x').pathname` serves absolute URLs from the current host.
|
|
13
|
+
*/
|
|
14
|
+
mediaUrl?: MediaUrl;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The components of every built-in block. Merge them into your components map:
|
|
18
|
+
* `{ ...builtinComponents({ icons }), ...yours }`. A key of yours with the same type wins.
|
|
19
|
+
* Components of blocks you did not include are never rendered. To keep their code out of the
|
|
20
|
+
* bundle, import single components (`Carousel`, `Lightbox`, …) instead.
|
|
21
|
+
*/
|
|
22
|
+
export declare function builtinComponents(options?: BuiltinComponentsOptions): BlockComponents;
|
|
23
|
+
export { buttonComponent } from '../Button.js';
|
|
24
|
+
export { Accordion } from './Accordion.js';
|
|
25
|
+
export { Carousel } from './Carousel.js';
|
|
26
|
+
export { Disclosure } from './Disclosure.js';
|
|
27
|
+
export { FilterLink } from './FilterLink.js';
|
|
28
|
+
export { iconComponent, type IconComponent, type IconMap } from './Icon.js';
|
|
29
|
+
export { Lightbox } from './Lightbox.js';
|
|
30
|
+
export { MediaBackdrop, mediaBackdropComponent, type MediaUrl } from './MediaBackdrop.js';
|
|
31
|
+
export { SectionRef } from './SectionRef.js';
|
|
32
|
+
export { TableOfContents } from './TableOfContents.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Components of the opt-in built-in blocks (`builtinBlocks()` in `payload-canvas/blocks`).
|
|
2
|
+
// Client-safe: the site and the canvas use the same map.
|
|
3
|
+
import { buttonComponent } from '../Button.js';
|
|
4
|
+
import { Accordion } from './Accordion.js';
|
|
5
|
+
import { Carousel } from './Carousel.js';
|
|
6
|
+
import { Disclosure } from './Disclosure.js';
|
|
7
|
+
import { FilterLink } from './FilterLink.js';
|
|
8
|
+
import { iconComponent } from './Icon.js';
|
|
9
|
+
import { Lightbox } from './Lightbox.js';
|
|
10
|
+
import { mediaBackdropComponent } from './MediaBackdrop.js';
|
|
11
|
+
import { SectionRef } from './SectionRef.js';
|
|
12
|
+
import { TableOfContents } from './TableOfContents.js';
|
|
13
|
+
/**
|
|
14
|
+
* The components of every built-in block. Merge them into your components map:
|
|
15
|
+
* `{ ...builtinComponents({ icons }), ...yours }`. A key of yours with the same type wins.
|
|
16
|
+
* Components of blocks you did not include are never rendered. To keep their code out of the
|
|
17
|
+
* bundle, import single components (`Carousel`, `Lightbox`, …) instead.
|
|
18
|
+
*/
|
|
19
|
+
export function builtinComponents(options = {}) {
|
|
20
|
+
const components = { disclosure: Disclosure, accordion: Accordion, lightbox: Lightbox, carousel: Carousel, tableOfContents: TableOfContents, filterLink: FilterLink, mediaBackdrop: mediaBackdropComponent(options.mediaUrl), sectionRef: SectionRef };
|
|
21
|
+
if (options.icons) {
|
|
22
|
+
components.icon = iconComponent(options.icons);
|
|
23
|
+
components.button = buttonComponent(options.icons);
|
|
24
|
+
}
|
|
25
|
+
return components;
|
|
26
|
+
}
|
|
27
|
+
export { buttonComponent } from '../Button.js';
|
|
28
|
+
export { Accordion } from './Accordion.js';
|
|
29
|
+
export { Carousel } from './Carousel.js';
|
|
30
|
+
export { Disclosure } from './Disclosure.js';
|
|
31
|
+
export { FilterLink } from './FilterLink.js';
|
|
32
|
+
export { iconComponent } from './Icon.js';
|
|
33
|
+
export { Lightbox } from './Lightbox.js';
|
|
34
|
+
export { MediaBackdrop, mediaBackdropComponent } from './MediaBackdrop.js';
|
|
35
|
+
export { SectionRef } from './SectionRef.js';
|
|
36
|
+
export { TableOfContents } from './TableOfContents.js';
|