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.
Files changed (170) hide show
  1. package/README.md +500 -25
  2. package/dist/admin/diff/changes.js +8 -0
  3. package/dist/admin/editor/Inspector.js +49 -4
  4. package/dist/admin/editor/Outline.js +12 -10
  5. package/dist/admin/editor/actions.d.ts +9 -1
  6. package/dist/admin/editor/actions.js +38 -3
  7. package/dist/admin/editor/empty/EmptyStart.js +29 -3
  8. package/dist/admin/editor/fields/GroupField.d.ts +5 -2
  9. package/dist/admin/editor/fields/GroupField.js +6 -2
  10. package/dist/admin/editor/fields/WhereField.d.ts +17 -0
  11. package/dist/admin/editor/fields/WhereField.js +67 -0
  12. package/dist/admin/editor/fields/fields.scss +89 -0
  13. package/dist/admin/editor/fields/whereRows.d.ts +28 -0
  14. package/dist/admin/editor/fields/whereRows.js +118 -0
  15. package/dist/admin/editor/icons.d.ts +1 -0
  16. package/dist/admin/editor/icons.js +2 -0
  17. package/dist/admin/editor/locale/LocaleField.d.ts +1 -1
  18. package/dist/admin/editor/locale/LocaleField.js +3 -1
  19. package/dist/admin/editor/menu/blockMenu.js +5 -1
  20. package/dist/admin/editor/motion/MotionPanel.js +1 -1
  21. package/dist/admin/editor/motion/model.js +2 -2
  22. package/dist/admin/editor/renderField.d.ts +3 -1
  23. package/dist/admin/editor/renderField.js +13 -4
  24. package/dist/admin/editor/runtime.js +1 -0
  25. package/dist/admin/editor/styles/SiteClasses.d.ts +9 -0
  26. package/dist/admin/editor/styles/SiteClasses.js +31 -0
  27. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
  28. package/dist/admin/editor/styles/StylesPanel.js +9 -6
  29. package/dist/admin/editor/styles/context.d.ts +9 -2
  30. package/dist/admin/editor/styles/context.js +14 -9
  31. package/dist/admin/editor/styles/controls.js +2 -2
  32. package/dist/admin/editor/styles/sections.js +1 -1
  33. package/dist/admin/editor/styles/styles.scss +54 -0
  34. package/dist/admin/editor/templates/Bindable.d.ts +13 -5
  35. package/dist/admin/editor/templates/Bindable.js +73 -17
  36. package/dist/admin/editor/templates/binding.d.ts +11 -4
  37. package/dist/admin/editor/templates/binding.js +23 -3
  38. package/dist/ai/prompt.js +8 -2
  39. package/dist/ai/tools.js +11 -2
  40. package/dist/blocks/builtins/carousel.d.ts +32 -0
  41. package/dist/blocks/builtins/carousel.js +122 -0
  42. package/dist/blocks/builtins/disclosure.d.ts +13 -0
  43. package/dist/blocks/builtins/disclosure.js +107 -0
  44. package/dist/blocks/builtins/faq.d.ts +17 -0
  45. package/dist/blocks/builtins/faq.js +88 -0
  46. package/dist/blocks/builtins/filterLink.d.ts +22 -0
  47. package/dist/blocks/builtins/filterLink.js +76 -0
  48. package/dist/blocks/builtins/headingId.d.ts +15 -0
  49. package/dist/blocks/builtins/headingId.js +36 -0
  50. package/dist/blocks/builtins/icon.d.ts +8 -0
  51. package/dist/blocks/builtins/icon.js +45 -0
  52. package/dist/blocks/builtins/index.d.ts +35 -0
  53. package/dist/blocks/builtins/index.js +50 -0
  54. package/dist/blocks/builtins/lightbox.d.ts +43 -0
  55. package/dist/blocks/builtins/lightbox.js +93 -0
  56. package/dist/blocks/builtins/mediaBackdrop.d.ts +11 -0
  57. package/dist/blocks/builtins/mediaBackdrop.js +79 -0
  58. package/dist/blocks/builtins/sectionRef.d.ts +26 -0
  59. package/dist/blocks/builtins/sectionRef.js +78 -0
  60. package/dist/blocks/builtins/shared.d.ts +33 -0
  61. package/dist/blocks/builtins/shared.js +70 -0
  62. package/dist/blocks/builtins/tableOfContents.d.ts +3 -0
  63. package/dist/blocks/builtins/tableOfContents.js +44 -0
  64. package/dist/blocks/defaults.d.ts +19 -1
  65. package/dist/blocks/defaults.js +413 -20
  66. package/dist/blocks/index.d.ts +4 -2
  67. package/dist/blocks/index.js +3 -1
  68. package/dist/core/attrs.d.ts +27 -0
  69. package/dist/core/attrs.js +132 -0
  70. package/dist/core/bindings.d.ts +122 -11
  71. package/dist/core/bindings.js +504 -19
  72. package/dist/core/blocks.d.ts +46 -1
  73. package/dist/core/blocks.js +136 -0
  74. package/dist/core/classes.d.ts +10 -2
  75. package/dist/core/classes.js +34 -5
  76. package/dist/core/headings.d.ts +21 -0
  77. package/dist/core/headings.js +47 -0
  78. package/dist/core/index.d.ts +4 -2
  79. package/dist/core/index.js +4 -2
  80. package/dist/core/motion.d.ts +18 -9
  81. package/dist/core/motion.js +20 -12
  82. package/dist/core/operations.js +59 -2
  83. package/dist/core/payloadBlocks.js +3 -1
  84. package/dist/core/schema.js +20 -0
  85. package/dist/core/tree.js +24 -1
  86. package/dist/core/types.d.ts +87 -0
  87. package/dist/core/validate.js +29 -4
  88. package/dist/css/tokens.d.ts +6 -3
  89. package/dist/css/tokens.js +48 -2
  90. package/dist/index.d.ts +3 -3
  91. package/dist/index.js +2 -2
  92. package/dist/mcp/index.d.ts +2 -0
  93. package/dist/mcp/index.js +50 -13
  94. package/dist/mcp/shared.d.ts +3 -0
  95. package/dist/mcp/shared.js +23 -8
  96. package/dist/plugin/index.d.ts +8 -0
  97. package/dist/plugin/index.js +26 -8
  98. package/dist/plugin/listCollections.d.ts +17 -2
  99. package/dist/plugin/listCollections.js +44 -7
  100. package/dist/plugin/references.d.ts +5 -0
  101. package/dist/plugin/references.js +1 -1
  102. package/dist/plugin/templates.d.ts +4 -0
  103. package/dist/plugin/templates.js +23 -4
  104. package/dist/protocol/index.d.ts +2 -0
  105. package/dist/react/canvas/BuilderCanvas.js +5 -3
  106. package/dist/react/canvas/fetchDocs.d.ts +16 -2
  107. package/dist/react/canvas/fetchDocs.js +42 -9
  108. package/dist/react/canvas/measure.d.ts +3 -1
  109. package/dist/react/canvas/measure.js +26 -2
  110. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  111. package/dist/react/canvas/resolveLayout.js +17 -6
  112. package/dist/react/canvas/serverBlocks.d.ts +11 -0
  113. package/dist/react/canvas/serverBlocks.js +28 -1
  114. package/dist/react/components/Button.d.ts +11 -2
  115. package/dist/react/components/Button.js +43 -6
  116. package/dist/react/components/CollectionList.d.ts +6 -3
  117. package/dist/react/components/CollectionList.js +21 -7
  118. package/dist/react/components/Container.js +4 -1
  119. package/dist/react/components/Field.js +13 -2
  120. package/dist/react/components/Heading.js +9 -2
  121. package/dist/react/components/Image.d.ts +9 -0
  122. package/dist/react/components/Image.js +16 -1
  123. package/dist/react/components/List.d.ts +1 -0
  124. package/dist/react/components/List.js +6 -0
  125. package/dist/react/components/Menu.d.ts +16 -0
  126. package/dist/react/components/Menu.js +83 -19
  127. package/dist/react/components/RichText.d.ts +8 -3
  128. package/dist/react/components/RichText.js +25 -4
  129. package/dist/react/components/builtins/Accordion.d.ts +9 -0
  130. package/dist/react/components/builtins/Accordion.js +37 -0
  131. package/dist/react/components/builtins/BackdropVideo.d.ts +13 -0
  132. package/dist/react/components/builtins/BackdropVideo.js +16 -0
  133. package/dist/react/components/builtins/Carousel.d.ts +13 -0
  134. package/dist/react/components/builtins/Carousel.js +134 -0
  135. package/dist/react/components/builtins/Disclosure.d.ts +7 -0
  136. package/dist/react/components/builtins/Disclosure.js +13 -0
  137. package/dist/react/components/builtins/FilterLink.d.ts +8 -0
  138. package/dist/react/components/builtins/FilterLink.js +30 -0
  139. package/dist/react/components/builtins/Icon.d.ts +14 -0
  140. package/dist/react/components/builtins/Icon.js +28 -0
  141. package/dist/react/components/builtins/Lightbox.d.ts +45 -0
  142. package/dist/react/components/builtins/Lightbox.js +252 -0
  143. package/dist/react/components/builtins/MediaBackdrop.d.ts +14 -0
  144. package/dist/react/components/builtins/MediaBackdrop.js +61 -0
  145. package/dist/react/components/builtins/SectionRef.d.ts +7 -0
  146. package/dist/react/components/builtins/SectionRef.js +17 -0
  147. package/dist/react/components/builtins/TableOfContents.d.ts +7 -0
  148. package/dist/react/components/builtins/TableOfContents.js +21 -0
  149. package/dist/react/components/builtins/glyphs.d.ts +8 -0
  150. package/dist/react/components/builtins/glyphs.js +7 -0
  151. package/dist/react/components/builtins/index.d.ts +32 -0
  152. package/dist/react/components/builtins/index.js +36 -0
  153. package/dist/react/components/index.js +2 -0
  154. package/dist/react/index.d.ts +3 -1
  155. package/dist/react/index.js +3 -1
  156. package/dist/react/motion/runtime.js +10 -6
  157. package/dist/react/render/RenderLayout.d.ts +1 -1
  158. package/dist/react/render/RenderLayout.js +76 -23
  159. package/dist/react/render/lists.d.ts +107 -5
  160. package/dist/react/render/lists.js +284 -9
  161. package/dist/react/render/resolve.d.ts +22 -2
  162. package/dist/react/render/resolve.js +45 -22
  163. package/dist/react/render/sections.d.ts +9 -0
  164. package/dist/react/render/sections.js +51 -0
  165. package/dist/react/render/types.d.ts +6 -1
  166. package/dist/react/server.d.ts +3 -1
  167. package/dist/react/server.js +53 -2
  168. package/dist/react/theme/ThemeStyle.d.ts +13 -2
  169. package/dist/react/theme/ThemeStyle.js +12 -2
  170. package/package.json +1 -1
@@ -3,6 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  // `RichText` from `@payloadcms/richtext-lexical/react` has no hooks and no client-only code, so it
4
4
  // renders in server components and inside the client canvas.
5
5
  import { LinkJSXConverter, RichText as LexicalRichText } from '@payloadcms/richtext-lexical/react';
6
+ import { createElement } from 'react';
7
+ import { richTextHeadings } from '../../core/headings.js';
6
8
  import { editableText } from '../render/editable.js';
7
9
  import { defaultResolveLink } from '../render/link.js';
8
10
  import { PlaceholderText } from './placeholder.js';
@@ -38,14 +40,33 @@ function converters(resolveLink) {
38
40
  });
39
41
  }
40
42
  const convertersByResolver = new WeakMap();
41
- /** Lexical rich text as React elements, with internal links resolved by `resolveLink`. No wrapper. */
42
- export function renderRichText(content, resolveLink) {
43
+ const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
44
+ /**
45
+ * Converters whose headings get the ids of `richTextHeadings` (made per value, because the ids
46
+ * belong to this value's headings).
47
+ */
48
+ function withHeadingIds(base, content) {
49
+ const ids = new WeakMap(richTextHeadings(content).map((heading) => [heading.node, heading.id]));
50
+ return (args) => ({
51
+ ...base(args),
52
+ heading: ({ node, nodesToJSX }) => {
53
+ const tag = typeof node.tag === 'string' && HEADING_TAGS.has(node.tag) ? node.tag : 'h1';
54
+ return createElement(tag, { id: ids.get(node) }, nodesToJSX({ nodes: node.children }));
55
+ },
56
+ });
57
+ }
58
+ /**
59
+ * Lexical rich text as React elements, with internal links resolved by `resolveLink`. No wrapper.
60
+ * `headingIds`: each heading gets an id from its text (`richTextHeadings`), for `#id` links.
61
+ */
62
+ export function renderRichText(content, resolveLink, options) {
43
63
  let rendererConverters = convertersByResolver.get(resolveLink);
44
64
  if (!rendererConverters) {
45
65
  rendererConverters = converters(resolveLink);
46
66
  convertersByResolver.set(resolveLink, rendererConverters);
47
67
  }
48
- return _jsx(LexicalRichText, { data: content, disableContainer: true, converters: rendererConverters });
68
+ const used = options?.headingIds ? withHeadingIds(rendererConverters, content) : rendererConverters;
69
+ return _jsx(LexicalRichText, { data: content, disableContainer: true, converters: used });
49
70
  }
50
71
  /**
51
72
  * Makes the built-in rich text component for one link resolver. RenderLayout calls it with its
@@ -60,7 +81,7 @@ function createRichText(resolveLink) {
60
81
  return null;
61
82
  return (_jsx("div", { ...attributes, ...editableText(mode, 'content'), className: className, children: _jsx("p", { children: _jsx(PlaceholderText, { children: "Rich text" }) }) }));
62
83
  }
63
- return (_jsx("div", { ...attributes, ...editableText(mode, 'content'), className: className, children: renderRichText(content, resolveLink) }));
84
+ return (_jsx("div", { ...attributes, ...editableText(mode, 'content'), className: className, children: renderRichText(content, resolveLink, { headingIds: props.headingIds === true }) }));
64
85
  };
65
86
  }
66
87
  const byResolver = new WeakMap();
@@ -0,0 +1,9 @@
1
+ import type { BlockComponentProps } from '../../render/types.js';
2
+ /** The accordion's own disclosures: <details> inside it that are not inside another <details> of it. */
3
+ export declare function ownDetails(root: HTMLElement): HTMLDetailsElement[];
4
+ /**
5
+ * A list of disclosures. With "Several open at a time" off it gives its own disclosures one
6
+ * `name`, so the browser keeps one open (exclusive <details>). Not on the canvas, where every
7
+ * disclosure stays open for editing. The FAQ JSON-LD reads it with `faqItems`.
8
+ */
9
+ export declare function Accordion({ block, props, className, attributes, slotAttributes, slots, mode }: BlockComponentProps): import("react").JSX.Element;
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from 'react';
4
+ /** The accordion's own disclosures: <details> inside it that are not inside another <details> of it. */
5
+ export function ownDetails(root) {
6
+ return [...root.querySelectorAll('details')].filter((item) => {
7
+ const outer = item.parentElement?.closest('details');
8
+ return !outer || !root.contains(outer);
9
+ });
10
+ }
11
+ /**
12
+ * A list of disclosures. With "Several open at a time" off it gives its own disclosures one
13
+ * `name`, so the browser keeps one open (exclusive <details>). Not on the canvas, where every
14
+ * disclosure stays open for editing. The FAQ JSON-LD reads it with `faqItems`.
15
+ */
16
+ export function Accordion({ block, props, className, attributes, slotAttributes, slots, mode }) {
17
+ const ref = useRef(null);
18
+ const single = props.multiple === false && mode !== 'canvas';
19
+ useEffect(() => {
20
+ const root = ref.current;
21
+ if (!root)
22
+ return;
23
+ const name = single ? `accordion-${block.id}` : '';
24
+ const apply = () => {
25
+ for (const item of ownDetails(root))
26
+ item.name = name;
27
+ };
28
+ apply();
29
+ if (!single)
30
+ return;
31
+ // Repeats and lists can add items later.
32
+ const observer = new MutationObserver(apply);
33
+ observer.observe(root, { childList: true, subtree: true });
34
+ return () => observer.disconnect();
35
+ }, [single, block.id]);
36
+ return (_jsx("div", { ...attributes, ...slotAttributes.items, ref: ref, className: className, children: slots.items }));
37
+ }
@@ -0,0 +1,13 @@
1
+ import { type CSSProperties } from 'react';
2
+ /**
3
+ * A muted, looping background video. It starts from script, so with reduced motion it never
4
+ * plays and the poster stays. `play` is false on the canvas. A new `src` remounts it (key).
5
+ */
6
+ export declare function BackdropVideo({ src, poster, className, style, priority, play, }: {
7
+ src: string;
8
+ poster?: string;
9
+ className: string;
10
+ style?: CSSProperties;
11
+ priority: boolean;
12
+ play: boolean;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from 'react';
4
+ /**
5
+ * A muted, looping background video. It starts from script, so with reduced motion it never
6
+ * plays and the poster stays. `play` is false on the canvas. A new `src` remounts it (key).
7
+ */
8
+ export function BackdropVideo({ src, poster, className, style, priority, play, }) {
9
+ const ref = useRef(null);
10
+ useEffect(() => {
11
+ if (!play || window.matchMedia('(prefers-reduced-motion: reduce)').matches)
12
+ return;
13
+ ref.current?.play().catch(() => { });
14
+ }, [play]);
15
+ return (_jsx("video", { ref: ref, "data-backdrop-media": "", "aria-hidden": "true", className: className, style: style, src: src, poster: poster, muted: true, loop: true, playsInline: true, preload: priority ? 'auto' : 'metadata' }));
16
+ }
@@ -0,0 +1,13 @@
1
+ import type { BlockComponentProps } from '../../render/types.js';
2
+ /** The slide to show for `target`: wrapped around with `loop`, else kept in range. */
3
+ export declare function slideIndex(target: number, count: number, loop: boolean): number;
4
+ /** The slide whose start is nearest the scroll position. At the end of the track: the last one. */
5
+ export declare function nearestSlide(offsets: number[], scrollLeft: number, maxScroll: number): number;
6
+ /**
7
+ * Slides from the "slides" slot in a scroll-snap track (or stacked, fading), with arrows, dots,
8
+ * loop and autoplay. A region with `aria-roledescription="carousel"`; each slide is a group
9
+ * labelled "i of n". Arrow keys on the track move one slide. Autoplay shows a pause button, stops
10
+ * on hover and focus, and never runs with reduced motion. On the canvas the slides always scroll
11
+ * and never autoplay, so each one can be selected.
12
+ */
13
+ export declare function Carousel({ block, props, className, attributes, slotAttributes, slots, mode }: BlockComponentProps): import("react").JSX.Element;
@@ -0,0 +1,134 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { CAROUSEL_CLASS_MAP as C, CAROUSEL_LABELS as L } from '../../../blocks/builtins/carousel.js';
5
+ import { joinClasses, labelOf, textOr } from '../../../blocks/builtins/shared.js';
6
+ import { Chevron } from './glyphs.js';
7
+ /** The slides: the track's children, looking through `display: contents` wrappers. */
8
+ function slidesOf(track) {
9
+ return [...track.children].flatMap((child) => {
10
+ if (!(child instanceof HTMLElement))
11
+ return [];
12
+ return getComputedStyle(child).display === 'contents' ? slidesOf(child) : [child];
13
+ });
14
+ }
15
+ const reducedMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;
16
+ /** The slide to show for `target`: wrapped around with `loop`, else kept in range. */
17
+ export function slideIndex(target, count, loop) {
18
+ if (count <= 0)
19
+ return 0;
20
+ return loop ? (target + count) % count : Math.min(Math.max(target, 0), count - 1);
21
+ }
22
+ /** The slide whose start is nearest the scroll position. At the end of the track: the last one. */
23
+ export function nearestSlide(offsets, scrollLeft, maxScroll) {
24
+ if (offsets.length === 0)
25
+ return 0;
26
+ if (scrollLeft >= maxScroll - 2)
27
+ return offsets.length - 1;
28
+ const start = offsets[0];
29
+ return offsets.reduce((best, offset, i) => (Math.abs(offset - start - scrollLeft) < Math.abs(offsets[best] - start - scrollLeft) ? i : best), 0);
30
+ }
31
+ /**
32
+ * Slides from the "slides" slot in a scroll-snap track (or stacked, fading), with arrows, dots,
33
+ * loop and autoplay. A region with `aria-roledescription="carousel"`; each slide is a group
34
+ * labelled "i of n". Arrow keys on the track move one slide. Autoplay shows a pause button, stops
35
+ * on hover and focus, and never runs with reduced motion. On the canvas the slides always scroll
36
+ * and never autoplay, so each one can be selected.
37
+ */
38
+ export function Carousel({ block, props, className, attributes, slotAttributes, slots, mode }) {
39
+ const track = useRef(null);
40
+ const [count, setCount] = useState(0);
41
+ const [index, setIndex] = useState(0);
42
+ const [paused, setPaused] = useState(false);
43
+ const [stopped, setStopped] = useState(false);
44
+ const canvas = mode === 'canvas';
45
+ const fade = props.mode === 'fade' && !canvas;
46
+ const loop = props.loop === true;
47
+ const autoplay = typeof props.autoplay === 'number' && props.autoplay > 0 && !canvas ? props.autoplay : 0;
48
+ const playing = autoplay > 0 && !paused && !stopped && count > 1;
49
+ // Count the slides, and again whenever they change.
50
+ useEffect(() => {
51
+ const el = track.current;
52
+ if (!el)
53
+ return;
54
+ const measure = () => setCount(slidesOf(el).length);
55
+ measure();
56
+ const observer = new MutationObserver(measure);
57
+ observer.observe(el, { childList: true, subtree: true });
58
+ return () => observer.disconnect();
59
+ }, []);
60
+ const label = (name, values) => labelOf(props, L, name, values);
61
+ const slideRole = label('slideRole');
62
+ const slideLabel = textOr(props.slideLabel, L.slideLabel);
63
+ // Label each slide "i of n"; in fade mode hide all but the current one.
64
+ useEffect(() => {
65
+ const el = track.current;
66
+ if (!el || canvas)
67
+ return;
68
+ slidesOf(el).forEach((slide, i) => {
69
+ slide.setAttribute('role', 'group');
70
+ slide.setAttribute('aria-roledescription', slideRole);
71
+ slide.setAttribute('aria-label', labelOf({ slideLabel }, L, 'slideLabel', { n: i + 1, count }));
72
+ if (!fade)
73
+ return;
74
+ slide.toggleAttribute('data-slide-off', i !== index);
75
+ slide.inert = i !== index;
76
+ });
77
+ }, [canvas, count, fade, index, slideLabel, slideRole]);
78
+ // Scroll mode: the current slide follows the scroll position.
79
+ useEffect(() => {
80
+ const el = track.current;
81
+ if (!el || fade)
82
+ return;
83
+ let frame = 0;
84
+ const onScroll = () => {
85
+ cancelAnimationFrame(frame);
86
+ frame = requestAnimationFrame(() => {
87
+ const offsets = slidesOf(el).map((slide) => slide.offsetLeft);
88
+ setIndex(nearestSlide(offsets, el.scrollLeft, el.scrollWidth - el.clientWidth));
89
+ });
90
+ };
91
+ el.addEventListener('scroll', onScroll, { passive: true });
92
+ return () => {
93
+ cancelAnimationFrame(frame);
94
+ el.removeEventListener('scroll', onScroll);
95
+ };
96
+ }, [fade]);
97
+ const goTo = useCallback((target) => {
98
+ const el = track.current;
99
+ if (!el)
100
+ return;
101
+ const slides = slidesOf(el);
102
+ if (slides.length === 0)
103
+ return;
104
+ const next = slideIndex(target, slides.length, loop);
105
+ setIndex(next);
106
+ if (fade)
107
+ return;
108
+ el.scrollTo({ left: slides[next].offsetLeft - slides[0].offsetLeft, behavior: reducedMotion() ? 'auto' : 'smooth' });
109
+ }, [fade, loop]);
110
+ // Autoplay always wraps to the first slide.
111
+ useEffect(() => {
112
+ if (!playing || reducedMotion())
113
+ return;
114
+ const timer = window.setTimeout(() => goTo(index + 1 >= count ? 0 : index + 1), autoplay);
115
+ return () => window.clearTimeout(timer);
116
+ }, [autoplay, count, goTo, index, playing]);
117
+ const onTrackKey = (event) => {
118
+ if (event.target !== event.currentTarget)
119
+ return;
120
+ if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft')
121
+ return;
122
+ event.preventDefault();
123
+ goTo(index + (event.key === 'ArrowRight' ? 1 : -1));
124
+ };
125
+ const showArrows = props.arrows !== false && count > 1;
126
+ const showDots = props.dots === true && count > 1;
127
+ const trackClass = fade ? `${C.fade} ${count ? C.fadeReady : C.fadeBefore}` : C.scroll;
128
+ // An empty arrow slot shows a chevron; on the canvas a filled one shows its blocks.
129
+ const arrowContent = (slot) => (block.slots?.[slot]?.length ?? 0) > 0 ? slots[slot] : _jsx(Chevron, { className: C.icon, direction: slot === 'previous' ? 'left' : 'right' });
130
+ return (_jsxs("section", { ...attributes, "aria-roledescription": label('carouselRole'), "aria-label": textOr(props.label, 'Carousel'), className: className, onFocus: () => setPaused(true), onBlur: (event) => {
131
+ if (!event.currentTarget.contains(event.relatedTarget))
132
+ setPaused(false);
133
+ }, onPointerEnter: () => setPaused(true), onPointerLeave: () => setPaused(false), children: [_jsx("div", { ...slotAttributes.slides, ref: track, "data-carousel-track": "", className: joinClasses(trackClass, slotAttributes.slides?.className), "aria-live": playing ? 'off' : 'polite', tabIndex: fade || canvas ? undefined : 0, onKeyDown: onTrackKey, children: slots.slides }), showArrows || showDots || autoplay > 0 ? (_jsxs("div", { "data-carousel-controls": "", className: C.controls, children: [showDots ? (_jsx("div", { "data-carousel-dots": "", className: C.dots, children: Array.from({ length: count }, (_, i) => (_jsx("button", { type: "button", "data-carousel-dot": "", className: C.button, "aria-label": label('dotLabel', { n: i + 1, count }), "aria-current": i === index ? 'true' : undefined, onClick: () => goTo(i) }, i))) })) : null, _jsxs("div", { "data-carousel-arrows": "", className: C.arrows, children: [autoplay > 0 ? (_jsx("button", { type: "button", "data-carousel-pause": "", className: C.button, onClick: () => setStopped((value) => !value), children: stopped ? label('playLabel') : label('pauseLabel') })) : null, showArrows ? (_jsxs(_Fragment, { children: [_jsx("button", { ...slotAttributes.previous, type: "button", "data-carousel-arrow": "previous", className: C.button, "aria-label": label('previousLabel'), disabled: !loop && index <= 0, onClick: () => goTo(index - 1), children: arrowContent('previous') }), _jsx("button", { ...slotAttributes.next, type: "button", "data-carousel-arrow": "next", className: C.button, "aria-label": label('nextLabel'), disabled: !loop && index >= count - 1, onClick: () => goTo(index + 1), children: arrowContent('next') })] })) : null] })] })) : null] }));
134
+ }
@@ -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 {};