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
@@ -0,0 +1,107 @@
1
+ import { defineBlock } from '../../core/blocks.js';
2
+ import { classesOf, classMap, INTERACTIVE } from './shared.js';
3
+ export const DISCLOSURE_BLOCK = 'disclosure';
4
+ export const ACCORDION_BLOCK = 'accordion';
5
+ /**
6
+ * Classes the disclosure component adds itself. `animate`: the browser animates the content box
7
+ * (`::details-content`) to `height: auto`; off with reduced motion and in browsers without it.
8
+ */
9
+ export const DISCLOSURE_CLASS_MAP = classMap({
10
+ summary: 'cursor-pointer list-none [&::-webkit-details-marker]:hidden',
11
+ animate: '[interpolate-size:allow-keywords] details-content:h-0 details-content:overflow-clip ' +
12
+ 'details-content:transition-[height,content-visibility] details-content:duration-300 ' +
13
+ 'details-content:[transition-behavior:allow-discrete] open:details-content:h-auto motion-reduce:details-content:transition-none',
14
+ });
15
+ const DISCLOSURE_CLASS = 'group [&>summary]:flex [&>summary]:items-center [&>summary]:justify-between [&>summary]:gap-4 [&>summary]:py-4 [&>div]:pb-4';
16
+ export function disclosureBlock() {
17
+ return defineBlock({
18
+ type: DISCLOSURE_BLOCK,
19
+ label: 'Disclosure',
20
+ icon: 'chevronDown',
21
+ category: 'Interactive',
22
+ fields: [
23
+ { name: 'open', type: 'checkbox', label: 'Open at first', defaultValue: false },
24
+ {
25
+ name: 'animate',
26
+ type: 'checkbox',
27
+ label: 'Animate the height',
28
+ defaultValue: true,
29
+ admin: { description: 'Opens and closes in 300 ms. Off when the visitor asks for less motion.' },
30
+ },
31
+ ],
32
+ slots: {
33
+ // A <summary> is the button: links and controls inside it are invalid HTML.
34
+ summary: { label: 'Summary', disallow: INTERACTIVE, styles: true },
35
+ content: { label: 'Content', styles: true },
36
+ },
37
+ defaultClassName: DISCLOSURE_CLASS,
38
+ classes: classesOf(DISCLOSURE_CLASS_MAP),
39
+ ai: {
40
+ description: 'One show/hide item: an FAQ question and answer, a "read more". The "summary" slot is always visible (a heading or ' +
41
+ 'text, often with an icon); the "content" slot opens below it. A native <details>, so it works without script, opens ' +
42
+ 'with the keyboard and closed content stays in the HTML for search engines. The canvas shows it open. Style the ' +
43
+ 'summary row with [&>summary]: classes and the content with [&>div]: classes on the disclosure; open: and ' +
44
+ 'group-open: classes style the open state (e.g. "group-open:rotate-45" on an icon in the summary).',
45
+ example: {
46
+ type: DISCLOSURE_BLOCK,
47
+ className: DISCLOSURE_CLASS,
48
+ slots: {
49
+ summary: [{ id: 'b_example_1', type: 'heading', props: { text: 'How do I book?', level: '3' }, className: 'text-lg font-medium' }],
50
+ content: [{ id: 'b_example_2', type: 'text', props: { text: 'Send us a message with a date and a time.' } }],
51
+ },
52
+ },
53
+ },
54
+ });
55
+ }
56
+ export function accordionBlock() {
57
+ return defineBlock({
58
+ type: ACCORDION_BLOCK,
59
+ label: 'Accordion',
60
+ icon: 'list',
61
+ category: 'Interactive',
62
+ fields: [
63
+ {
64
+ name: 'multiple',
65
+ type: 'checkbox',
66
+ label: 'Several open at a time',
67
+ defaultValue: true,
68
+ admin: { description: 'Off: opening one item closes the others.' },
69
+ },
70
+ {
71
+ name: 'faqSchema',
72
+ type: 'checkbox',
73
+ label: 'FAQ for search engines',
74
+ defaultValue: true,
75
+ admin: {
76
+ description: "The page's FAQPage JSON-LD lists this accordion's items: the summary text is the question, the content text the answer.",
77
+ },
78
+ },
79
+ ],
80
+ slots: { items: { label: 'Items', allow: [DISCLOSURE_BLOCK, 'repeat', 'collectionList'] } },
81
+ defaultClassName: 'flex flex-col divide-y border-y',
82
+ ai: {
83
+ description: 'A list of disclosure blocks in its "items" slot. "multiple": false keeps one item open at a time. With "faqSchema" ' +
84
+ '(on by default) its items feed the page\'s FAQPage JSON-LD: the summary text is the question, the content text the ' +
85
+ 'answer. In a template, repeat one disclosure over the document\'s FAQs: the items slot holds a repeat with path ' +
86
+ '"faqs" whose item is a disclosure with a text bound to "question" in "summary" and a text bound to "answer" in "content".',
87
+ example: {
88
+ type: ACCORDION_BLOCK,
89
+ props: { multiple: false },
90
+ className: 'flex flex-col divide-y border-y',
91
+ slots: {
92
+ items: [
93
+ {
94
+ id: 'b_example_1',
95
+ type: DISCLOSURE_BLOCK,
96
+ className: DISCLOSURE_CLASS,
97
+ slots: {
98
+ summary: [{ id: 'b_example_2', type: 'text', props: { text: 'How far ahead should I book?' } }],
99
+ content: [{ id: 'b_example_3', type: 'text', props: { text: 'A day ahead is best.' } }],
100
+ },
101
+ },
102
+ ],
103
+ },
104
+ },
105
+ },
106
+ });
107
+ }
@@ -0,0 +1,17 @@
1
+ import type { BlockDefinition } from '../../core/types.js';
2
+ export type FaqItem = {
3
+ question: string;
4
+ answer: string;
5
+ };
6
+ /**
7
+ * The questions and answers of a layout's accordions with "FAQ for search engines" on: the summary
8
+ * text of each disclosure is the question, the content text the answer. Call it after
9
+ * `loadLayoutData`, so bound props, Field blocks, collection lists and repeats hold the document's
10
+ * values. `blocks` is the site's block list (it types bound values). Hidden blocks count as absent.
11
+ */
12
+ export declare function faqItems(layout: unknown, blocks?: readonly BlockDefinition[]): FaqItem[];
13
+ /**
14
+ * FAQPage JSON-LD for the items, or null when there are none. Escape it for a `<script>` tag
15
+ * (`JSON.stringify(...).replace(/</g, '\\u003c')`).
16
+ */
17
+ export declare function faqJsonLd(items: readonly FaqItem[]): Record<string, unknown> | null;
@@ -0,0 +1,88 @@
1
+ import { COLLECTION_LIST_BLOCK, FIELD_BLOCK, FIELD_VALUE_PROP, isRichText, LIST_ITEM_SLOT, LIST_ITEMS_PROP, listItemContext, REPEAT_BLOCK, repeatRowContext, resolveBindings, richTextToPlain, } from '../../core/bindings.js';
2
+ import { normalizeLayout } from '../../core/tree.js';
3
+ import { ACCORDION_BLOCK, DISCLOSURE_BLOCK } from './disclosure.js';
4
+ const isRecord = (value) => typeof value === 'object' && value !== null;
5
+ /** The item design of a collection list or repeat, once per loaded document or row, with its values bound. */
6
+ function expanded(block, blocks) {
7
+ const rows = block.props?.[LIST_ITEMS_PROP];
8
+ const item = block.slots?.[LIST_ITEM_SLOT] ?? [];
9
+ if (!Array.isArray(rows) || item.length === 0)
10
+ return [];
11
+ const collection = typeof block.props?.collection === 'string' ? block.props.collection : '';
12
+ return rows.flatMap((row, index) => {
13
+ const context = block.type === REPEAT_BLOCK ? repeatRowContext(row, index, null, collection) : listItemContext(isRecord(row) ? row : {}, index, null, collection);
14
+ return resolveBindings({ version: 1, blocks: item }, context, blocks).blocks;
15
+ });
16
+ }
17
+ /** Every block in order, list and repeat items expanded. Hidden blocks and their children are skipped. */
18
+ function* walk(list, blocks) {
19
+ for (const block of list) {
20
+ if (block.hidden)
21
+ continue;
22
+ yield block;
23
+ if (block.type === REPEAT_BLOCK || block.type === COLLECTION_LIST_BLOCK) {
24
+ yield* walk(expanded(block, blocks), blocks);
25
+ continue;
26
+ }
27
+ for (const children of Object.values(block.slots ?? {}))
28
+ yield* walk(children, blocks);
29
+ }
30
+ }
31
+ /** The readable text of blocks: text props, rich text and Field block values. */
32
+ function plainText(list, blocks) {
33
+ const parts = [];
34
+ for (const block of walk(list, blocks)) {
35
+ const props = block.props ?? {};
36
+ if (typeof props.text === 'string')
37
+ parts.push(props.text);
38
+ if (isRichText(props.content))
39
+ parts.push(richTextToPlain(props.content));
40
+ if (block.type !== FIELD_BLOCK)
41
+ continue;
42
+ const value = props[FIELD_VALUE_PROP];
43
+ if (typeof value === 'string' || typeof value === 'number')
44
+ parts.push(String(value));
45
+ else if (isRichText(value))
46
+ parts.push(richTextToPlain(value));
47
+ }
48
+ return parts.map((part) => part.trim()).filter(Boolean).join(' ').replace(/\s+/g, ' ');
49
+ }
50
+ /**
51
+ * The questions and answers of a layout's accordions with "FAQ for search engines" on: the summary
52
+ * text of each disclosure is the question, the content text the answer. Call it after
53
+ * `loadLayoutData`, so bound props, Field blocks, collection lists and repeats hold the document's
54
+ * values. `blocks` is the site's block list (it types bound values). Hidden blocks count as absent.
55
+ */
56
+ export function faqItems(layout, blocks = []) {
57
+ const items = [];
58
+ for (const block of walk(normalizeLayout(layout).blocks, blocks)) {
59
+ if (block.type !== ACCORDION_BLOCK || block.props?.faqSchema === false)
60
+ continue;
61
+ for (const item of walk(block.slots?.items ?? [], blocks)) {
62
+ if (item.type !== DISCLOSURE_BLOCK)
63
+ continue;
64
+ const question = plainText(item.slots?.summary ?? [], blocks);
65
+ const answer = plainText(item.slots?.content ?? [], blocks);
66
+ if (question && answer)
67
+ items.push({ question, answer });
68
+ }
69
+ }
70
+ return items;
71
+ }
72
+ /**
73
+ * FAQPage JSON-LD for the items, or null when there are none. Escape it for a `<script>` tag
74
+ * (`JSON.stringify(...).replace(/</g, '\\u003c')`).
75
+ */
76
+ export function faqJsonLd(items) {
77
+ if (items.length === 0)
78
+ return null;
79
+ return {
80
+ '@context': 'https://schema.org',
81
+ '@type': 'FAQPage',
82
+ mainEntity: items.map((item) => ({
83
+ '@type': 'Question',
84
+ name: item.question,
85
+ acceptedAnswer: { '@type': 'Answer', text: item.answer },
86
+ })),
87
+ };
88
+ }
@@ -0,0 +1,22 @@
1
+ import type { BlockDefinition } from '../../core/types.js';
2
+ export declare const FILTER_LINK_BLOCK = "filterLink";
3
+ /** A URL query: `URLSearchParams`, or the `searchParams` object of a Next.js page. */
4
+ export type FilterQuery = URLSearchParams | Record<string, string | string[] | undefined>;
5
+ export type FilterLinkTarget = {
6
+ param: string;
7
+ value: string;
8
+ multiple?: boolean;
9
+ /** Page parameters of lists with their own `pageParam`, dropped like `page`. */
10
+ pageParams?: readonly string[];
11
+ };
12
+ /**
13
+ * Where a filter link goes and whether it is the current filter. An empty `param` clears every
14
+ * query value ("All"). An empty `value` clears its param. `multiple` toggles the value in the
15
+ * param's comma list; otherwise the value replaces the param's values. Other params stay.
16
+ * `path` is the page path; with an empty path the href is relative (`?a=b`, or `?` for none).
17
+ */
18
+ export declare function filterHref(path: string, query: FilterQuery, { param, value, multiple, pageParams }: FilterLinkTarget): {
19
+ href: string;
20
+ active: boolean;
21
+ };
22
+ export declare function filterLinkBlock(): BlockDefinition;
@@ -0,0 +1,76 @@
1
+ import { PAGE_PARAM } from '../../core/bindings.js';
2
+ import { defineBlock } from '../../core/blocks.js';
3
+ import { INTERACTIVE } from './shared.js';
4
+ export const FILTER_LINK_BLOCK = 'filterLink';
5
+ /** The values of one param: repeated params and comma lists both count. */
6
+ function valuesOf(query, param) {
7
+ const raw = query instanceof URLSearchParams ? query.getAll(param) : [].concat(query[param] ?? []);
8
+ return raw.flatMap((value) => value.split(',')).map((value) => value.trim()).filter(Boolean);
9
+ }
10
+ const keysOf = (query) => [...new Set(query instanceof URLSearchParams ? query.keys() : Object.keys(query))];
11
+ /**
12
+ * Where a filter link goes and whether it is the current filter. An empty `param` clears every
13
+ * query value ("All"). An empty `value` clears its param. `multiple` toggles the value in the
14
+ * param's comma list; otherwise the value replaces the param's values. Other params stay.
15
+ * `path` is the page path; with an empty path the href is relative (`?a=b`, or `?` for none).
16
+ */
17
+ export function filterHref(path, query, { param, value, multiple, pageParams = [] }) {
18
+ // A new filter starts again at page 1, so the page numbers are dropped.
19
+ const pages = new Set([PAGE_PARAM, ...pageParams]);
20
+ const params = keysOf(query).filter((key) => !pages.has(key) && valuesOf(query, key).length > 0);
21
+ const link = (search) => (search ? `${path}?${search}` : path || '?');
22
+ if (!param)
23
+ return { href: link(''), active: params.length === 0 };
24
+ const current = valuesOf(query, param);
25
+ const active = value ? current.includes(value) : current.length === 0;
26
+ const next = !value ? [] : !multiple ? [value] : active ? current.filter((item) => item !== value) : [...current, value];
27
+ const search = [...params.filter((key) => key !== param), ...(next.length > 0 ? [param] : [])]
28
+ .map((key) => `${encodeURIComponent(key)}=${(key === param ? next : valuesOf(query, key)).map(encodeURIComponent).join(',')}`)
29
+ .join('&');
30
+ return { href: link(search), active };
31
+ }
32
+ const FILTER_CLASS = 'inline-flex items-center gap-2 rounded-full border px-4 py-2 text-sm aria-[current=true]:font-semibold';
33
+ export function filterLinkBlock() {
34
+ return defineBlock({
35
+ type: FILTER_LINK_BLOCK,
36
+ label: 'Filter link',
37
+ icon: 'link',
38
+ category: 'Dynamic',
39
+ fields: [
40
+ {
41
+ name: 'param',
42
+ type: 'text',
43
+ label: 'URL parameter',
44
+ admin: { description: 'The query parameter this link sets, for example "available". Empty: the link clears every filter ("All").' },
45
+ },
46
+ {
47
+ name: 'value',
48
+ type: 'text',
49
+ label: 'Value',
50
+ admin: { description: 'The value it sets, for example "today" (makes ?available=today). Empty: the link clears this parameter.' },
51
+ },
52
+ {
53
+ name: 'multiple',
54
+ type: 'checkbox',
55
+ label: 'Several values',
56
+ admin: { description: 'The link adds or removes its value in a comma list (?hair=blonde,red) instead of replacing it.' },
57
+ },
58
+ ],
59
+ slots: { children: { label: 'Content', disallow: INTERACTIVE } },
60
+ defaultClassName: FILTER_CLASS,
61
+ ai: {
62
+ description: 'A link to the current page with one URL query value set, toggled or cleared, for the "queryFilters" of a collection ' +
63
+ 'list (a filterLink with param "available" and value "today" goes to ?available=today). Other query values stay. An ' +
64
+ 'empty param clears every filter (the "All" link); an empty value clears its param. "multiple" toggles the value in a ' +
65
+ 'comma list. It drops the page numbers of paginated lists ("page", and the "pageParam" of each list in the same ' +
66
+ 'layout). The current filter gets aria-current="true": style it with aria-[current=true]: classes. Its "children" ' +
67
+ 'slot holds the label (a text, an icon). Filtered URLs should be noindex, follow.',
68
+ example: {
69
+ type: FILTER_LINK_BLOCK,
70
+ props: { param: 'available', value: 'today' },
71
+ className: FILTER_CLASS,
72
+ slots: { children: [{ id: 'b_example_1', type: 'text', props: { text: 'Available today' } }] },
73
+ },
74
+ },
75
+ });
76
+ }
@@ -0,0 +1,15 @@
1
+ import { headingId } from '../../core/headings.js';
2
+ export { headingId };
3
+ /** One entry of a table of contents. */
4
+ export type RichTextHeading = {
5
+ id: string;
6
+ text: string;
7
+ };
8
+ /** The plain text of one Lexical node and its children, with whitespace runs as one space. */
9
+ export declare function lexicalText(node: unknown): string;
10
+ /**
11
+ * The top-level headings of one level (default `h2`) of Lexical rich text, with the same ids the
12
+ * rendered rich text gives them (`richTextHeadings`: repeated texts get "-2", "-3"). Headings
13
+ * without letters or digits are left out.
14
+ */
15
+ export declare function lexicalHeadings(value: unknown, tag?: string): RichTextHeading[];
@@ -0,0 +1,36 @@
1
+ // Heading ids shared by the tableOfContents block and the rich text that holds the headings, so a
2
+ // table of contents link (`#id`) finds its heading. Pure and client-safe. The ids come from
3
+ // `richTextHeadings` in core, which the field and richText blocks (`headingIds`) use too.
4
+ import { headingId, richTextHeadings } from '../../core/headings.js';
5
+ export { headingId };
6
+ function collect(node, parts) {
7
+ if (!node || typeof node !== 'object')
8
+ return;
9
+ const { text, children } = node;
10
+ if (typeof text === 'string')
11
+ parts.push(text);
12
+ if (Array.isArray(children))
13
+ for (const child of children)
14
+ collect(child, parts);
15
+ }
16
+ /** The plain text of one Lexical node and its children, with whitespace runs as one space. */
17
+ export function lexicalText(node) {
18
+ const parts = [];
19
+ collect(node, parts);
20
+ return parts.join('').replace(/\s+/g, ' ').trim();
21
+ }
22
+ /**
23
+ * The top-level headings of one level (default `h2`) of Lexical rich text, with the same ids the
24
+ * rendered rich text gives them (`richTextHeadings`: repeated texts get "-2", "-3"). Headings
25
+ * without letters or digits are left out.
26
+ */
27
+ export function lexicalHeadings(value, tag = 'h2') {
28
+ const children = value?.root?.children;
29
+ if (!Array.isArray(children))
30
+ return [];
31
+ const level = Number(tag.slice(1)) || 2;
32
+ const topLevel = new Set(children);
33
+ return richTextHeadings(value)
34
+ .filter((heading) => heading.level === level && topLevel.has(heading.node) && headingId(heading.text))
35
+ .map((heading) => ({ id: heading.id, text: lexicalText(heading.node) }));
36
+ }
@@ -0,0 +1,8 @@
1
+ import type { BlockDefinition } from '../../core/types.js';
2
+ export declare const ICON_BLOCK = "icon";
3
+ /**
4
+ * One icon from the site's own icon set. `names` are the keys of the site's icon map, as plain
5
+ * strings, so the Payload config never loads the icon components. The components come from
6
+ * `builtinComponents({ icons })` in `payload-canvas/react`.
7
+ */
8
+ export declare function iconBlock(names: readonly string[]): BlockDefinition;
@@ -0,0 +1,45 @@
1
+ import { defineBlock } from '../../core/blocks.js';
2
+ import { iconLabel } from '../defaults.js';
3
+ export const ICON_BLOCK = 'icon';
4
+ /**
5
+ * One icon from the site's own icon set. `names` are the keys of the site's icon map, as plain
6
+ * strings, so the Payload config never loads the icon components. The components come from
7
+ * `builtinComponents({ icons })` in `payload-canvas/react`.
8
+ */
9
+ export function iconBlock(names) {
10
+ return defineBlock({
11
+ type: ICON_BLOCK,
12
+ label: 'Icon',
13
+ icon: 'image',
14
+ category: 'Content',
15
+ // An icon may go straight into a link (an arrow at the end of a linked row).
16
+ inline: true,
17
+ fields: [
18
+ {
19
+ name: 'name',
20
+ type: 'select',
21
+ label: 'Icon',
22
+ required: true,
23
+ defaultValue: names[0],
24
+ options: names.map((value) => ({ label: iconLabel(value), value })),
25
+ },
26
+ {
27
+ name: 'label',
28
+ type: 'text',
29
+ label: 'Label for screen readers',
30
+ localized: true,
31
+ admin: {
32
+ description: 'Empty: the icon is decoration and screen readers skip it. Fill it when the icon says something on its own, ' +
33
+ 'for example "Yes" for a check mark in a table.',
34
+ },
35
+ },
36
+ ],
37
+ defaultClassName: 'size-6',
38
+ ai: {
39
+ description: `One icon from the site's icon set, drawn in the current text colour. Its className sets the size and colour ` +
40
+ `("size-5 text-primary"). Names: ${names.join(', ')}. Leave "label" empty when the icon is decoration; set it ` +
41
+ '("Yes", "No") when the icon is the only thing that says something.',
42
+ example: { type: ICON_BLOCK, props: { name: names[0] }, className: 'size-6' },
43
+ },
44
+ });
45
+ }
@@ -0,0 +1,35 @@
1
+ import type { BlockDefinition } from '../../core/types.js';
2
+ export declare const BUILTIN_TYPES: readonly ['icon', 'disclosure', 'accordion', 'lightbox', 'carousel', 'tableOfContents', 'filterLink', 'mediaBackdrop', 'sectionRef'];
3
+ export type BuiltinType = (typeof BUILTIN_TYPES)[number];
4
+ export type BuiltinBlocksOptions = {
5
+ /**
6
+ * The built-ins to add. Default: all of them, but `icon` only when `icons` is given and
7
+ * `sectionRef` only when listed here (it needs the plugin's saved sections).
8
+ */
9
+ include?: readonly BuiltinType[];
10
+ /**
11
+ * The names of the site's icons, for the `icon` block: the keys of the map the site gives
12
+ * `builtinComponents({ icons })`. Plain strings, so the Payload config loads no React.
13
+ */
14
+ icons?: readonly string[];
15
+ /** Upload collection for the mediaBackdrop block. Default "media". */
16
+ mediaCollection?: string;
17
+ /** The saved sections collection, for the sectionRef block. Default "builder-sections" (`websiteBuilder({ savedSections: { slug } })`). */
18
+ sectionsCollection?: string;
19
+ };
20
+ /**
21
+ * The opt-in built-in blocks. Add them next to `defaultBlocks()`:
22
+ * `[...defaultBlocks(), ...builtinBlocks({ include: ['carousel'] })]`. To replace one with your
23
+ * own block of the same type, leave it out of `include`.
24
+ */
25
+ export declare function builtinBlocks(options?: BuiltinBlocksOptions): BlockDefinition[];
26
+ export { CAROUSEL_BLOCK, CAROUSEL_CLASS_MAP, carouselBlock } from './carousel.js';
27
+ export { ACCORDION_BLOCK, accordionBlock, DISCLOSURE_BLOCK, DISCLOSURE_CLASS_MAP, disclosureBlock } from './disclosure.js';
28
+ export { FILTER_LINK_BLOCK, filterHref, filterLinkBlock, type FilterLinkTarget, type FilterQuery } from './filterLink.js';
29
+ export { faqItems, faqJsonLd, type FaqItem } from './faq.js';
30
+ export { headingId, lexicalHeadings, lexicalText, type RichTextHeading } from './headingId.js';
31
+ export { ICON_BLOCK, iconBlock } from './icon.js';
32
+ export { LIGHTBOX_BLOCK, LIGHTBOX_CLASS_MAP, LIGHTBOX_CLOSE_EVENT, LIGHTBOX_SKIP_ATTRIBUTE, lightboxBlock } from './lightbox.js';
33
+ export { MEDIA_BACKDROP_BLOCK, MEDIA_BACKDROP_CLASS_MAP, mediaBackdropBlock } from './mediaBackdrop.js';
34
+ export { SECTION_REF_BLOCK, SECTION_REF_SLOT, sectionDetachOps, sectionRefBlock, sectionRefBlocks, sectionRefId } from './sectionRef.js';
35
+ export { TABLE_OF_CONTENTS_BLOCK, tableOfContentsBlock } from './tableOfContents.js';
@@ -0,0 +1,50 @@
1
+ // Opt-in built-in blocks: `builtinBlocks()` from `payload-canvas/blocks`. Client-safe, like the
2
+ // default blocks: plain data, no React. The components come from `builtinComponents()` in
3
+ // `payload-canvas/react`.
4
+ import { carouselBlock } from './carousel.js';
5
+ import { accordionBlock, disclosureBlock } from './disclosure.js';
6
+ import { filterLinkBlock } from './filterLink.js';
7
+ import { iconBlock } from './icon.js';
8
+ import { lightboxBlock } from './lightbox.js';
9
+ import { mediaBackdropBlock } from './mediaBackdrop.js';
10
+ import { sectionRefBlock } from './sectionRef.js';
11
+ import { tableOfContentsBlock } from './tableOfContents.js';
12
+ export const BUILTIN_TYPES = ['icon', 'disclosure', 'accordion', 'lightbox', 'carousel', 'tableOfContents', 'filterLink', 'mediaBackdrop', 'sectionRef'];
13
+ /**
14
+ * The opt-in built-in blocks. Add them next to `defaultBlocks()`:
15
+ * `[...defaultBlocks(), ...builtinBlocks({ include: ['carousel'] })]`. To replace one with your
16
+ * own block of the same type, leave it out of `include`.
17
+ */
18
+ export function builtinBlocks(options = {}) {
19
+ const icons = options.icons ?? [];
20
+ const include = new Set(options.include ?? BUILTIN_TYPES.filter((type) => type !== 'sectionRef' && (type !== 'icon' || icons.length > 0)));
21
+ for (const type of include) {
22
+ if (!BUILTIN_TYPES.includes(type))
23
+ throw new Error(`builtinBlocks: there is no built-in block "${type}".`);
24
+ }
25
+ if (include.has('icon') && icons.length === 0) {
26
+ throw new Error('builtinBlocks: the "icon" block needs `icons`, the names of your icon set.');
27
+ }
28
+ const make = {
29
+ icon: () => iconBlock(icons),
30
+ disclosure: disclosureBlock,
31
+ accordion: accordionBlock,
32
+ lightbox: lightboxBlock,
33
+ carousel: carouselBlock,
34
+ tableOfContents: tableOfContentsBlock,
35
+ filterLink: filterLinkBlock,
36
+ mediaBackdrop: () => mediaBackdropBlock(options.mediaCollection),
37
+ sectionRef: () => sectionRefBlock(options.sectionsCollection),
38
+ };
39
+ return BUILTIN_TYPES.filter((type) => include.has(type)).map((type) => make[type]());
40
+ }
41
+ export { CAROUSEL_BLOCK, CAROUSEL_CLASS_MAP, carouselBlock } from './carousel.js';
42
+ export { ACCORDION_BLOCK, accordionBlock, DISCLOSURE_BLOCK, DISCLOSURE_CLASS_MAP, disclosureBlock } from './disclosure.js';
43
+ export { FILTER_LINK_BLOCK, filterHref, filterLinkBlock } from './filterLink.js';
44
+ export { faqItems, faqJsonLd } from './faq.js';
45
+ export { headingId, lexicalHeadings, lexicalText } from './headingId.js';
46
+ export { ICON_BLOCK, iconBlock } from './icon.js';
47
+ export { LIGHTBOX_BLOCK, LIGHTBOX_CLASS_MAP, LIGHTBOX_CLOSE_EVENT, LIGHTBOX_SKIP_ATTRIBUTE, lightboxBlock } from './lightbox.js';
48
+ export { MEDIA_BACKDROP_BLOCK, MEDIA_BACKDROP_CLASS_MAP, mediaBackdropBlock } from './mediaBackdrop.js';
49
+ export { SECTION_REF_BLOCK, SECTION_REF_SLOT, sectionDetachOps, sectionRefBlock, sectionRefBlocks, sectionRefId } from './sectionRef.js';
50
+ export { TABLE_OF_CONTENTS_BLOCK, tableOfContentsBlock } from './tableOfContents.js';
@@ -0,0 +1,43 @@
1
+ import type { BlockDefinition } from '../../core/types.js';
2
+ export declare const LIGHTBOX_BLOCK = "lightbox";
3
+ /**
4
+ * Leaves an image out of every lightbox set: put it on the image or on an element round it. A click
5
+ * on a skipped image still opens the set, at the photo with the same `src`. Use it for a large
6
+ * photo that repeats one of the set's thumbnails.
7
+ */
8
+ export declare const LIGHTBOX_SKIP_ATTRIBUTE = "data-lightbox-skip";
9
+ /**
10
+ * The event a lightbox sends when it closes, to the page image of the photo it showed last. It
11
+ * bubbles; `detail.index` is the photo's place in the set. An image switcher can show that photo.
12
+ */
13
+ export declare const LIGHTBOX_CLOSE_EVENT = "lightbox-close";
14
+ /**
15
+ * Classes the lightbox component adds itself: the position and size of the dialog and its
16
+ * controls. No colours: those come from the block's className (see `LIGHTBOX_CLASS`).
17
+ */
18
+ export declare const LIGHTBOX_CLASS_MAP: {
19
+ root: string;
20
+ /** `touch-pan-y`: a sideways swipe reaches the script as pointer events (pinch zoom still works). */
21
+ dialog: string;
22
+ /** One grid cell: the photo that leaves and the photo that comes in stack in it. */
23
+ figure: string;
24
+ photo: string;
25
+ /** Shown when the photo takes longer than a moment to load. Its colour is the dialog's text colour. */
26
+ loading: string;
27
+ count: string;
28
+ caption: string;
29
+ hidden: string;
30
+ button: string;
31
+ close: string;
32
+ previous: string;
33
+ next: string;
34
+ icon: string;
35
+ };
36
+ /** The lightbox's control labels and their English defaults. */
37
+ export declare const LIGHTBOX_LABELS: {
38
+ closeLabel: string;
39
+ previousLabel: string;
40
+ nextLabel: string;
41
+ countLabel: string;
42
+ };
43
+ export declare function lightboxBlock(): BlockDefinition;
@@ -0,0 +1,93 @@
1
+ import { defineBlock } from '../../core/blocks.js';
2
+ import { classesOf, classMap, labelsField, labelsHelp } from './shared.js';
3
+ export const LIGHTBOX_BLOCK = 'lightbox';
4
+ /**
5
+ * Leaves an image out of every lightbox set: put it on the image or on an element round it. A click
6
+ * on a skipped image still opens the set, at the photo with the same `src`. Use it for a large
7
+ * photo that repeats one of the set's thumbnails.
8
+ */
9
+ export const LIGHTBOX_SKIP_ATTRIBUTE = 'data-lightbox-skip';
10
+ /**
11
+ * The event a lightbox sends when it closes, to the page image of the photo it showed last. It
12
+ * bubbles; `detail.index` is the photo's place in the set. An image switcher can show that photo.
13
+ */
14
+ export const LIGHTBOX_CLOSE_EVENT = 'lightbox-close';
15
+ /**
16
+ * Classes the lightbox component adds itself: the position and size of the dialog and its
17
+ * controls. No colours: those come from the block's className (see `LIGHTBOX_CLASS`).
18
+ */
19
+ export const LIGHTBOX_CLASS_MAP = classMap({
20
+ root: '[&_img:not([data-lightbox-photo])]:cursor-zoom-in',
21
+ /** `touch-pan-y`: a sideways swipe reaches the script as pointer events (pinch zoom still works). */
22
+ dialog: 'fixed inset-0 m-0 size-full max-h-none max-w-none touch-pan-y touch-pinch-zoom overflow-hidden bg-transparent p-0',
23
+ /** One grid cell: the photo that leaves and the photo that comes in stack in it. */
24
+ figure: 'm-0 box-border grid size-full grid-cols-1 grid-rows-1 place-items-center p-4 md:p-16',
25
+ photo: 'col-start-1 row-start-1 max-h-full max-w-full object-contain',
26
+ /** Shown when the photo takes longer than a moment to load. Its colour is the dialog's text colour. */
27
+ loading: 'pointer-events-none absolute inset-0 m-auto size-8 animate-spin rounded-full border-2 border-current border-r-transparent',
28
+ count: 'pointer-events-none absolute top-4 left-4 inline-flex min-h-11 items-center px-1',
29
+ caption: 'absolute inset-x-0 bottom-4 px-16 text-center',
30
+ hidden: 'sr-only',
31
+ button: 'absolute inline-flex cursor-pointer items-center justify-center',
32
+ close: 'top-4 right-4',
33
+ previous: 'top-1/2 left-4 -translate-y-1/2',
34
+ next: 'top-1/2 right-4 -translate-y-1/2',
35
+ icon: 'size-5',
36
+ });
37
+ /** The lightbox's control labels and their English defaults. */
38
+ export const LIGHTBOX_LABELS = {
39
+ closeLabel: 'Close',
40
+ previousLabel: 'Previous photo',
41
+ nextLabel: 'Next photo',
42
+ countLabel: '{n} of {count}',
43
+ };
44
+ const LABEL_NAMES = { closeLabel: 'Close button', previousLabel: 'Previous button', nextLabel: 'Next button', countLabel: 'Photo number' };
45
+ const LIGHTBOX_CLASS = 'grid grid-cols-2 gap-3 md:grid-cols-3 [&_dialog]:text-white [&_dialog]:backdrop:bg-black/85 ' +
46
+ '[&_[data-lightbox-button]]:size-11 [&_[data-lightbox-button]]:rounded-full [&_[data-lightbox-button]]:bg-black/50';
47
+ export function lightboxBlock() {
48
+ return defineBlock({
49
+ type: LIGHTBOX_BLOCK,
50
+ label: 'Lightbox',
51
+ icon: 'image',
52
+ category: 'Media',
53
+ fields: [
54
+ { name: 'label', type: 'text', label: 'Label for screen readers', defaultValue: 'Photos', localized: true },
55
+ {
56
+ name: 'group',
57
+ type: 'text',
58
+ label: 'Group',
59
+ admin: { description: 'Lightboxes with the same group on a page open as one set. Optional.' },
60
+ },
61
+ { name: 'captions', type: 'checkbox', label: 'Show the alt text as a caption', defaultValue: false },
62
+ { name: 'count', type: 'checkbox', label: 'Show the photo number', defaultValue: true },
63
+ labelsField(LIGHTBOX_LABELS, LABEL_NAMES),
64
+ ],
65
+ slots: { children: { label: 'Content' } },
66
+ defaultClassName: LIGHTBOX_CLASS,
67
+ classes: classesOf(LIGHTBOX_CLASS_MAP),
68
+ ai: {
69
+ description: 'A container whose images open full screen in a modal dialog: a click, or Enter on a focused image. Arrow keys, a ' +
70
+ 'sideways swipe on touch screens and the arrow buttons step through the images; Escape closes. Lightboxes with the same "group" open as one set; ' +
71
+ 'each photo shows once in a set (by its src). The dialog fades in and out and the photos slide when they step (fades only under reduced motion). ' +
72
+ '"count" (default on) shows "2 of 6" at the top left. Lay out the ' +
73
+ 'images with its className (a grid), or put a repeat of images in it (path "galleryImages", image bound to "$item"). ' +
74
+ 'Style the dialog from the className: [&_dialog]: for its text colour and backdrop ([&_dialog]:backdrop:bg-black/85), ' +
75
+ '[&_[data-lightbox-button]]: for the close, previous and next buttons, [&_[data-lightbox-photo]]: for the large photo, ' +
76
+ '[&_[data-lightbox-count]]: for the photo number, [&_[data-lightbox-loading]]: for the ring shown while a photo loads. ' +
77
+ 'The canvas does not open it.' +
78
+ labelsHelp(LIGHTBOX_LABELS) +
79
+ ' In "countLabel", {n} is the photo number and {count} the number of photos.',
80
+ example: {
81
+ type: LIGHTBOX_BLOCK,
82
+ props: { label: 'Gallery' },
83
+ className: LIGHTBOX_CLASS,
84
+ slots: {
85
+ children: [
86
+ { id: 'b_example_1', type: 'image', props: { image: 1, alt: 'The lounge' }, className: 'aspect-square w-full object-cover' },
87
+ { id: 'b_example_2', type: 'image', props: { image: 2, alt: 'The terrace' }, className: 'aspect-square w-full object-cover' },
88
+ ],
89
+ },
90
+ },
91
+ },
92
+ });
93
+ }