payload-canvas 0.4.0 → 0.5.1

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 (468) hide show
  1. package/README.md +626 -154
  2. package/dist/admin/AiKeyField.d.ts +8 -0
  3. package/dist/admin/AiKeyField.js +54 -0
  4. package/dist/admin/BuilderTab.js +4 -1
  5. package/dist/admin/DocumentEditView.d.ts +9 -0
  6. package/dist/admin/DocumentEditView.js +45 -0
  7. package/dist/admin/LayoutField.d.ts +2 -2
  8. package/dist/admin/LayoutField.js +10 -7
  9. package/dist/admin/TemplateConditionsField.d.ts +9 -0
  10. package/dist/admin/TemplateConditionsField.js +22 -0
  11. package/dist/admin/aiKeyField.scss +58 -0
  12. package/dist/admin/client.d.ts +3 -0
  13. package/dist/admin/client.js +6 -0
  14. package/dist/admin/diff/changes.js +5 -0
  15. package/dist/admin/editor/Canvas.js +20 -5
  16. package/dist/admin/editor/Editor.d.ts +3 -1
  17. package/dist/admin/editor/Editor.js +6 -3
  18. package/dist/admin/editor/Inspector.js +75 -28
  19. package/dist/admin/editor/Library.js +40 -15
  20. package/dist/admin/editor/Outline.js +21 -16
  21. package/dist/admin/editor/Overlay.js +8 -3
  22. package/dist/admin/editor/actions.d.ts +10 -2
  23. package/dist/admin/editor/actions.js +18 -3
  24. package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
  25. package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
  26. package/dist/admin/editor/classes/ClassManager.js +56 -0
  27. package/dist/admin/editor/classes/controller.d.ts +112 -0
  28. package/dist/admin/editor/classes/controller.js +326 -0
  29. package/dist/admin/editor/classes/manager.scss +262 -0
  30. package/dist/admin/editor/classes/managerModel.d.ts +5 -0
  31. package/dist/admin/editor/classes/managerModel.js +27 -0
  32. package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
  33. package/dist/admin/editor/comments/CommentLayer.js +143 -0
  34. package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
  35. package/dist/admin/editor/comments/CommentsPanel.js +73 -0
  36. package/dist/admin/editor/comments/Thread.d.ts +26 -0
  37. package/dist/admin/editor/comments/Thread.js +84 -0
  38. package/dist/admin/editor/comments/comments.scss +539 -0
  39. package/dist/admin/editor/comments/controller.d.ts +48 -0
  40. package/dist/admin/editor/comments/controller.js +142 -0
  41. package/dist/admin/editor/contentMode.d.ts +17 -0
  42. package/dist/admin/editor/contentMode.js +37 -0
  43. package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
  44. package/dist/admin/editor/dnd/DropOutlines.js +73 -0
  45. package/dist/admin/editor/dnd/dnd.scss +43 -0
  46. package/dist/admin/editor/dnd/mode.d.ts +4 -0
  47. package/dist/admin/editor/dnd/mode.js +39 -0
  48. package/dist/admin/editor/editor.scss +13 -58
  49. package/dist/admin/editor/empty/EmptyStart.js +18 -66
  50. package/dist/admin/editor/fields/AddButton.d.ts +15 -0
  51. package/dist/admin/editor/fields/AddButton.js +14 -0
  52. package/dist/admin/editor/fields/ArrayField.js +3 -2
  53. package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
  54. package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
  55. package/dist/admin/editor/fields/ConditionRows.js +137 -0
  56. package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
  57. package/dist/admin/editor/fields/ListWhereField.js +20 -0
  58. package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
  59. package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
  60. package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
  61. package/dist/admin/editor/fields/RelatedField.js +44 -0
  62. package/dist/admin/editor/fields/SortField.d.ts +13 -0
  63. package/dist/admin/editor/fields/SortField.js +37 -0
  64. package/dist/admin/editor/fields/WhereField.d.ts +12 -4
  65. package/dist/admin/editor/fields/WhereField.js +33 -53
  66. package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
  67. package/dist/admin/editor/fields/collectionFields.js +15 -0
  68. package/dist/admin/editor/fields/conditions.d.ts +99 -0
  69. package/dist/admin/editor/fields/conditions.js +339 -0
  70. package/dist/admin/editor/fields/fields.scss +232 -9
  71. package/dist/admin/editor/fields/listOptions.d.ts +44 -0
  72. package/dist/admin/editor/fields/listOptions.js +111 -0
  73. package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
  74. package/dist/admin/editor/fields/queryFilterRows.js +29 -0
  75. package/dist/admin/editor/fields/whereRows.d.ts +11 -12
  76. package/dist/admin/editor/fields/whereRows.js +83 -34
  77. package/dist/admin/editor/icons.d.ts +16 -1
  78. package/dist/admin/editor/icons.js +30 -1
  79. package/dist/admin/editor/inline.js +9 -0
  80. package/dist/admin/editor/insert/InsertHandle.js +4 -1
  81. package/dist/admin/editor/insert/picker.d.ts +3 -1
  82. package/dist/admin/editor/insert/picker.js +17 -10
  83. package/dist/admin/editor/insert/spots.d.ts +12 -1
  84. package/dist/admin/editor/insert/spots.js +49 -10
  85. package/dist/admin/editor/layout/LeftPanel.js +11 -6
  86. package/dist/admin/editor/live/useMultiplayer.js +9 -1
  87. package/dist/admin/editor/menu/blockMenu.js +27 -17
  88. package/dist/admin/editor/names.js +11 -3
  89. package/dist/admin/editor/renderField.d.ts +3 -1
  90. package/dist/admin/editor/renderField.js +63 -12
  91. package/dist/admin/editor/runtime.d.ts +14 -0
  92. package/dist/admin/editor/runtime.js +67 -6
  93. package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
  94. package/dist/admin/editor/sections/ComponentFields.js +116 -0
  95. package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
  96. package/dist/admin/editor/sections/PropertyControls.js +65 -0
  97. package/dist/admin/editor/sections/components.d.ts +29 -0
  98. package/dist/admin/editor/sections/components.js +112 -0
  99. package/dist/admin/editor/sections/components.scss +238 -0
  100. package/dist/admin/editor/sections/variants.d.ts +32 -0
  101. package/dist/admin/editor/sections/variants.js +59 -0
  102. package/dist/admin/editor/sections/variants.scss +90 -0
  103. package/dist/admin/editor/shortcuts.d.ts +4 -1
  104. package/dist/admin/editor/shortcuts.js +19 -3
  105. package/dist/admin/editor/store.d.ts +18 -0
  106. package/dist/admin/editor/store.js +46 -0
  107. package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
  108. package/dist/admin/editor/styles/ClassBar.js +90 -0
  109. package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
  110. package/dist/admin/editor/styles/ClassCss.js +28 -0
  111. package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
  112. package/dist/admin/editor/styles/ClassDialog.js +151 -0
  113. package/dist/admin/editor/styles/ColorPicker.js +5 -2
  114. package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
  115. package/dist/admin/editor/styles/RawClasses.js +184 -32
  116. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
  117. package/dist/admin/editor/styles/StylesPanel.js +53 -14
  118. package/dist/admin/editor/styles/VariantBar.js +2 -2
  119. package/dist/admin/editor/styles/classEdit.d.ts +4 -0
  120. package/dist/admin/editor/styles/classEdit.js +20 -0
  121. package/dist/admin/editor/styles/classes.scss +381 -0
  122. package/dist/admin/editor/styles/context.d.ts +19 -6
  123. package/dist/admin/editor/styles/context.js +24 -6
  124. package/dist/admin/editor/styles/controls.d.ts +3 -1
  125. package/dist/admin/editor/styles/controls.js +30 -12
  126. package/dist/admin/editor/styles/popover.d.ts +6 -0
  127. package/dist/admin/editor/styles/popover.js +5 -5
  128. package/dist/admin/editor/styles/styles.scss +26 -104
  129. package/dist/admin/editor/styles/suggestions.d.ts +22 -0
  130. package/dist/admin/editor/styles/suggestions.js +77 -0
  131. package/dist/admin/editor/styles/tokens.js +14 -0
  132. package/dist/admin/editor/templates/Bindable.js +86 -57
  133. package/dist/admin/editor/templates/SamplePicker.js +1 -1
  134. package/dist/admin/editor/templates/Visibility.d.ts +9 -0
  135. package/dist/admin/editor/templates/Visibility.js +54 -0
  136. package/dist/admin/editor/templates/binding.d.ts +2 -2
  137. package/dist/admin/editor/templates/binding.js +2 -2
  138. package/dist/admin/editor/templates/templates.scss +27 -0
  139. package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
  140. package/dist/admin/editor/templates/visibilityRows.js +83 -0
  141. package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
  142. package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
  143. package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
  144. package/dist/admin/editor/topbar/DocumentActions.js +5 -4
  145. package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
  146. package/dist/admin/editor/topbar/TopBar.js +15 -3
  147. package/dist/admin/editor/topbar/contentMode.scss +35 -0
  148. package/dist/admin/editor/topbar/topbar.scss +3 -1
  149. package/dist/admin/formChoice.d.ts +3 -0
  150. package/dist/admin/formChoice.js +10 -0
  151. package/dist/admin/layoutField.scss +69 -0
  152. package/dist/admin/screen/BuilderScreen.d.ts +6 -1
  153. package/dist/admin/screen/BuilderScreen.js +4 -3
  154. package/dist/admin/server/BuilderView.js +10 -3
  155. package/dist/admin/templateConditions.scss +24 -0
  156. package/dist/ai/adapters/anthropic.js +17 -4
  157. package/dist/ai/adapters/cloudflare-gateway.js +7 -1
  158. package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
  159. package/dist/ai/adapters/openai-compatible.js +1 -0
  160. package/dist/ai/adapters/openrouter.js +2 -0
  161. package/dist/ai/config.d.ts +24 -4
  162. package/dist/ai/config.js +27 -8
  163. package/dist/ai/endpoint.d.ts +5 -2
  164. package/dist/ai/endpoint.js +31 -26
  165. package/dist/ai/images/cloudflare-workers-ai.js +6 -2
  166. package/dist/ai/images/openai.js +8 -3
  167. package/dist/ai/images/openrouter.js +6 -2
  168. package/dist/ai/images/service.d.ts +10 -4
  169. package/dist/ai/images/service.js +23 -7
  170. package/dist/ai/openai-format.d.ts +7 -0
  171. package/dist/ai/openai-format.js +17 -5
  172. package/dist/ai/prompt.d.ts +8 -0
  173. package/dist/ai/prompt.js +25 -5
  174. package/dist/ai/settings/index.d.ts +62 -0
  175. package/dist/ai/settings/index.js +264 -0
  176. package/dist/ai/settings/secret.d.ts +11 -0
  177. package/dist/ai/settings/secret.js +46 -0
  178. package/dist/ai/settings/shared.d.ts +22 -0
  179. package/dist/ai/settings/shared.js +3 -0
  180. package/dist/ai/tools.d.ts +3 -0
  181. package/dist/ai/tools.js +79 -15
  182. package/dist/ai/types.d.ts +43 -0
  183. package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
  184. package/dist/blocks/builtins/adjacentLinks.js +76 -0
  185. package/dist/blocks/builtins/carousel.d.ts +2 -29
  186. package/dist/blocks/builtins/carousel.js +44 -51
  187. package/dist/blocks/builtins/disclosure.d.ts +2 -1
  188. package/dist/blocks/builtins/disclosure.js +22 -32
  189. package/dist/blocks/builtins/embed.d.ts +15 -0
  190. package/dist/blocks/builtins/embed.js +47 -0
  191. package/dist/blocks/builtins/faq.d.ts +1 -1
  192. package/dist/blocks/builtins/faq.js +2 -2
  193. package/dist/blocks/builtins/filterLink.d.ts +1 -19
  194. package/dist/blocks/builtins/filterLink.js +9 -50
  195. package/dist/blocks/builtins/icon.d.ts +2 -0
  196. package/dist/blocks/builtins/icon.js +8 -8
  197. package/dist/blocks/builtins/index.d.ts +18 -13
  198. package/dist/blocks/builtins/index.js +43 -22
  199. package/dist/blocks/builtins/marquee.d.ts +5 -0
  200. package/dist/blocks/builtins/marquee.js +68 -0
  201. package/dist/blocks/builtins/popup.d.ts +5 -0
  202. package/dist/blocks/builtins/popup.js +83 -0
  203. package/dist/blocks/builtins/sectionRef.d.ts +16 -2
  204. package/dist/blocks/builtins/sectionRef.js +34 -12
  205. package/dist/blocks/builtins/shared.d.ts +18 -23
  206. package/dist/blocks/builtins/shared.js +34 -42
  207. package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
  208. package/dist/blocks/builtins/tableOfContents.js +12 -18
  209. package/dist/blocks/builtins/tabs.d.ts +6 -0
  210. package/dist/blocks/builtins/tabs.js +87 -0
  211. package/dist/blocks/client/adjacentLinks.d.ts +4 -0
  212. package/dist/blocks/client/adjacentLinks.js +4 -0
  213. package/dist/blocks/client/carousel.d.ts +45 -0
  214. package/dist/blocks/client/carousel.js +53 -0
  215. package/dist/blocks/client/embed.d.ts +21 -0
  216. package/dist/blocks/client/embed.js +23 -0
  217. package/dist/blocks/client/field.d.ts +7 -0
  218. package/dist/blocks/client/field.js +8 -0
  219. package/dist/blocks/client/filterLink.d.ts +19 -0
  220. package/dist/blocks/client/filterLink.js +30 -0
  221. package/dist/blocks/client/helpers.d.ts +21 -0
  222. package/dist/blocks/client/helpers.js +24 -0
  223. package/dist/blocks/client/marquee.d.ts +14 -0
  224. package/dist/blocks/client/marquee.js +25 -0
  225. package/dist/blocks/client/menu.d.ts +46 -0
  226. package/dist/blocks/client/menu.js +49 -0
  227. package/dist/blocks/client/popup.d.ts +15 -0
  228. package/dist/blocks/client/popup.js +16 -0
  229. package/dist/blocks/client/tabs.d.ts +10 -0
  230. package/dist/blocks/client/tabs.js +11 -0
  231. package/dist/blocks/defaults.d.ts +15 -52
  232. package/dist/blocks/defaults.js +203 -437
  233. package/dist/blocks/index.d.ts +1 -1
  234. package/dist/blocks/index.js +2 -1
  235. package/dist/classes/actions.d.ts +97 -0
  236. package/dist/classes/actions.js +296 -0
  237. package/dist/classes/collection.d.ts +5 -0
  238. package/dist/classes/collection.js +189 -0
  239. package/dist/classes/config.d.ts +34 -0
  240. package/dist/classes/config.js +8 -0
  241. package/dist/classes/endpoints.d.ts +2 -0
  242. package/dist/classes/endpoints.js +120 -0
  243. package/dist/classes/index.d.ts +36 -0
  244. package/dist/classes/index.js +42 -0
  245. package/dist/classes/mcp.d.ts +6 -0
  246. package/dist/classes/mcp.js +161 -0
  247. package/dist/classes/shared.d.ts +131 -0
  248. package/dist/classes/shared.js +300 -0
  249. package/dist/classes/sheet.d.ts +34 -0
  250. package/dist/classes/sheet.js +126 -0
  251. package/dist/classes/usage.d.ts +57 -0
  252. package/dist/classes/usage.js +208 -0
  253. package/dist/comments/collection.d.ts +38 -0
  254. package/dist/comments/collection.js +226 -0
  255. package/dist/comments/config.d.ts +15 -0
  256. package/dist/comments/config.js +2 -0
  257. package/dist/comments/index.d.ts +20 -0
  258. package/dist/comments/index.js +22 -0
  259. package/dist/comments/shared.d.ts +54 -0
  260. package/dist/comments/shared.js +104 -0
  261. package/dist/core/bindings.d.ts +77 -32
  262. package/dist/core/bindings.js +319 -134
  263. package/dist/core/blockNames.d.ts +9 -0
  264. package/dist/core/blockNames.js +11 -0
  265. package/dist/core/blocks.d.ts +21 -8
  266. package/dist/core/blocks.js +37 -16
  267. package/dist/core/classes.d.ts +16 -8
  268. package/dist/core/classes.js +31 -27
  269. package/dist/core/components.d.ts +72 -0
  270. package/dist/core/components.js +294 -0
  271. package/dist/core/contentMode.d.ts +27 -0
  272. package/dist/core/contentMode.js +0 -0
  273. package/dist/core/dropTarget.d.ts +11 -0
  274. package/dist/core/dropTarget.js +24 -1
  275. package/dist/core/fields.d.ts +5 -0
  276. package/dist/core/fields.js +11 -0
  277. package/dist/core/headings.d.ts +5 -2
  278. package/dist/core/headings.js +14 -6
  279. package/dist/core/index.d.ts +8 -3
  280. package/dist/core/index.js +8 -3
  281. package/dist/core/layers.d.ts +9 -0
  282. package/dist/core/layers.js +29 -0
  283. package/dist/core/operations.d.ts +6 -0
  284. package/dist/core/operations.js +85 -24
  285. package/dist/core/payloadBlocks.js +5 -1
  286. package/dist/core/references.js +28 -0
  287. package/dist/core/schema.js +20 -6
  288. package/dist/core/sectionOrigin.d.ts +6 -0
  289. package/dist/core/sectionOrigin.js +21 -0
  290. package/dist/core/sections.d.ts +72 -0
  291. package/dist/core/sections.js +331 -0
  292. package/dist/core/templateChoice.d.ts +24 -0
  293. package/dist/core/templateChoice.js +43 -0
  294. package/dist/core/tree.js +18 -6
  295. package/dist/core/types.d.ts +148 -18
  296. package/dist/core/validate.d.ts +4 -1
  297. package/dist/core/validate.js +28 -11
  298. package/dist/core/visibility.d.ts +63 -0
  299. package/dist/core/visibility.js +214 -0
  300. package/dist/core/whereValues.d.ts +22 -0
  301. package/dist/core/whereValues.js +43 -0
  302. package/dist/css/classes.d.ts +16 -0
  303. package/dist/css/classes.js +172 -0
  304. package/dist/css/index.d.ts +32 -1
  305. package/dist/css/index.js +64 -5
  306. package/dist/css/tokens.d.ts +10 -0
  307. package/dist/css/tokens.js +23 -10
  308. package/dist/index.d.ts +5 -2
  309. package/dist/index.js +6 -1
  310. package/dist/live/contentMode.d.ts +24 -0
  311. package/dist/live/contentMode.js +39 -0
  312. package/dist/live/endpoints.js +3 -0
  313. package/dist/live/session.d.ts +5 -0
  314. package/dist/live/session.js +8 -0
  315. package/dist/live/types.d.ts +16 -1
  316. package/dist/mcp/index.d.ts +10 -1
  317. package/dist/mcp/index.js +146 -54
  318. package/dist/mcp/shared.d.ts +93 -3
  319. package/dist/mcp/shared.js +211 -15
  320. package/dist/plugin/hook.d.ts +7 -1
  321. package/dist/plugin/hook.js +30 -4
  322. package/dist/plugin/index.d.ts +19 -8
  323. package/dist/plugin/index.js +89 -20
  324. package/dist/plugin/links.d.ts +24 -0
  325. package/dist/plugin/links.js +27 -0
  326. package/dist/plugin/listCollections.d.ts +9 -7
  327. package/dist/plugin/listCollections.js +30 -21
  328. package/dist/plugin/sections.d.ts +14 -7
  329. package/dist/plugin/sections.js +69 -23
  330. package/dist/plugin/sectionsUsedIn.d.ts +6 -0
  331. package/dist/plugin/sectionsUsedIn.js +24 -0
  332. package/dist/plugin/templateEndpoint.d.ts +9 -0
  333. package/dist/plugin/templateEndpoint.js +49 -0
  334. package/dist/plugin/templates.js +23 -8
  335. package/dist/protocol/index.d.ts +16 -1
  336. package/dist/react/canvas/BuilderCanvas.js +144 -21
  337. package/dist/react/canvas/classes.d.ts +17 -0
  338. package/dist/react/canvas/classes.js +102 -0
  339. package/dist/react/canvas/controls.d.ts +31 -0
  340. package/dist/react/canvas/controls.js +75 -0
  341. package/dist/react/canvas/fetchDocs.d.ts +2 -2
  342. package/dist/react/canvas/fetchDocs.js +16 -8
  343. package/dist/react/canvas/measure.d.ts +9 -0
  344. package/dist/react/canvas/measure.js +106 -7
  345. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  346. package/dist/react/canvas/resolveLayout.js +4 -3
  347. package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
  348. package/dist/react/classes/ClassesStyle.d.ts +27 -0
  349. package/dist/react/classes/ClassesStyle.js +27 -0
  350. package/dist/react/components/Button.d.ts +2 -11
  351. package/dist/react/components/Button.js +8 -43
  352. package/dist/react/components/CollectionList.d.ts +4 -1
  353. package/dist/react/components/CollectionList.js +10 -3
  354. package/dist/react/components/Container.d.ts +5 -2
  355. package/dist/react/components/Container.js +7 -4
  356. package/dist/react/components/Field.js +3 -14
  357. package/dist/react/components/Link.d.ts +1 -1
  358. package/dist/react/components/Link.js +5 -3
  359. package/dist/react/components/List.d.ts +1 -1
  360. package/dist/react/components/List.js +2 -2
  361. package/dist/react/components/Menu.d.ts +10 -1
  362. package/dist/react/components/Menu.js +39 -12
  363. package/dist/react/components/RichText.d.ts +3 -4
  364. package/dist/react/components/RichText.js +5 -5
  365. package/dist/react/components/builtins/Accordion.d.ts +4 -3
  366. package/dist/react/components/builtins/Accordion.js +6 -5
  367. package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
  368. package/dist/react/components/builtins/AdjacentLinks.js +20 -0
  369. package/dist/react/components/builtins/Carousel.d.ts +21 -10
  370. package/dist/react/components/builtins/Carousel.js +175 -100
  371. package/dist/react/components/builtins/Disclosure.d.ts +4 -3
  372. package/dist/react/components/builtins/Disclosure.js +6 -5
  373. package/dist/react/components/builtins/Embed.d.ts +11 -0
  374. package/dist/react/components/builtins/Embed.js +23 -0
  375. package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
  376. package/dist/react/components/builtins/EmbedHtml.js +51 -0
  377. package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
  378. package/dist/react/components/builtins/EmbedPreview.js +105 -0
  379. package/dist/react/components/builtins/FilterLink.d.ts +1 -1
  380. package/dist/react/components/builtins/FilterLink.js +4 -4
  381. package/dist/react/components/builtins/Marquee.d.ts +8 -0
  382. package/dist/react/components/builtins/Marquee.js +15 -0
  383. package/dist/react/components/builtins/Popup.d.ts +26 -0
  384. package/dist/react/components/builtins/Popup.js +146 -0
  385. package/dist/react/components/builtins/SectionRef.d.ts +4 -3
  386. package/dist/react/components/builtins/SectionRef.js +9 -5
  387. package/dist/react/components/builtins/Tab.d.ts +7 -0
  388. package/dist/react/components/builtins/Tab.js +21 -0
  389. package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
  390. package/dist/react/components/builtins/TableOfContents.js +22 -7
  391. package/dist/react/components/builtins/Tabs.d.ts +17 -0
  392. package/dist/react/components/builtins/Tabs.js +71 -0
  393. package/dist/react/components/builtins/index.d.ts +37 -20
  394. package/dist/react/components/builtins/index.js +54 -20
  395. package/dist/react/components/builtins/tabsContext.d.ts +12 -0
  396. package/dist/react/components/builtins/tabsContext.js +6 -0
  397. package/dist/react/components/index.js +11 -8
  398. package/dist/react/components/lazy.d.ts +32 -0
  399. package/dist/react/components/lazy.js +20 -0
  400. package/dist/react/components/lazyBlock.d.ts +17 -0
  401. package/dist/react/components/lazyBlock.js +23 -0
  402. package/dist/react/index.d.ts +6 -3
  403. package/dist/react/index.js +5 -2
  404. package/dist/react/render/RenderLayout.d.ts +9 -7
  405. package/dist/react/render/RenderLayout.js +96 -45
  406. package/dist/react/render/canvasMode.d.ts +13 -0
  407. package/dist/react/render/canvasMode.js +13 -0
  408. package/dist/react/render/canvasServer.js +4 -3
  409. package/dist/react/render/canvasServerTypes.d.ts +5 -0
  410. package/dist/react/render/lists.d.ts +36 -4
  411. package/dist/react/render/lists.js +132 -15
  412. package/dist/react/render/marks.d.ts +15 -0
  413. package/dist/react/render/marks.js +23 -0
  414. package/dist/react/render/payload.d.ts +8 -1
  415. package/dist/react/render/payload.js +12 -3
  416. package/dist/react/render/preview.d.ts +11 -0
  417. package/dist/react/render/preview.js +13 -0
  418. package/dist/react/render/relations.d.ts +10 -0
  419. package/dist/react/render/relations.js +39 -0
  420. package/dist/react/render/resolve.d.ts +8 -4
  421. package/dist/react/render/resolve.js +11 -5
  422. package/dist/react/render/reveal.d.ts +17 -0
  423. package/dist/react/render/reveal.js +39 -0
  424. package/dist/react/render/sections.d.ts +11 -5
  425. package/dist/react/render/sections.js +52 -24
  426. package/dist/react/render/templates.d.ts +47 -0
  427. package/dist/react/render/templates.js +139 -0
  428. package/dist/react/render/types.d.ts +62 -5
  429. package/dist/react/server.d.ts +2 -37
  430. package/dist/react/server.js +8 -133
  431. package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
  432. package/dist/react/theme/ThemeLiveLoader.js +5 -0
  433. package/dist/react/theme/ThemeStyle.js +1 -1
  434. package/dist/theme/admin/Variables.d.ts +11 -0
  435. package/dist/theme/admin/Variables.js +115 -0
  436. package/dist/theme/admin/fields.scss +113 -0
  437. package/dist/theme/client.d.ts +1 -0
  438. package/dist/theme/client.js +2 -0
  439. package/dist/theme/css.d.ts +6 -1
  440. package/dist/theme/css.js +12 -4
  441. package/dist/theme/global.js +83 -0
  442. package/dist/theme/index.d.ts +1 -0
  443. package/dist/theme/index.js +1 -0
  444. package/dist/theme/server.d.ts +15 -0
  445. package/dist/theme/server.js +43 -0
  446. package/dist/theme/usage.d.ts +23 -0
  447. package/dist/theme/usage.js +68 -0
  448. package/dist/theme/variables.d.ts +72 -0
  449. package/dist/theme/variables.js +231 -0
  450. package/package.json +4 -2
  451. package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
  452. package/dist/admin/editor/styles/SiteClasses.js +0 -31
  453. package/dist/blocks/builtins/headingId.d.ts +0 -15
  454. package/dist/blocks/builtins/headingId.js +0 -36
  455. package/dist/blocks/builtins/lightbox.d.ts +0 -43
  456. package/dist/blocks/builtins/lightbox.js +0 -93
  457. package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
  458. package/dist/blocks/builtins/mediaBackdrop.js +0 -79
  459. package/dist/react/components/Quote.d.ts +0 -3
  460. package/dist/react/components/Quote.js +0 -12
  461. package/dist/react/components/Spacer.d.ts +0 -3
  462. package/dist/react/components/Spacer.js +0 -6
  463. package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
  464. package/dist/react/components/builtins/BackdropVideo.js +0 -16
  465. package/dist/react/components/builtins/Lightbox.d.ts +0 -45
  466. package/dist/react/components/builtins/Lightbox.js +0 -252
  467. package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
  468. package/dist/react/components/builtins/MediaBackdrop.js +0 -61
@@ -1,9 +1,15 @@
1
- import type { BlockDefinition, Layout } from '../../core/index.js';
1
+ import { type BlockDefinition, type Layout } from '../../core/index.js';
2
2
  import type { FetchDocs } from './types.js';
3
+ /** How deep components may sit inside components. Deeper ones render nothing. */
4
+ export declare const MAX_COMPONENT_DEPTH = 5;
3
5
  /**
4
6
  * Fills the runtime slot (`SECTION_REF_SLOT`) of every `sectionRef` block with its saved section's
5
- * blocks, loaded with `fetchDocs` (one call). One level: a sectionRef inside a saved section stays
6
- * empty, so a section can never include itself. A missing section leaves the slot out. Returns
7
- * the same layout when there is nothing to load. Never mutates.
7
+ * blocks, loaded with `fetchDocs` (one call per level of nesting). A component's copy gets its own
8
+ * values (`applyComponentValues`). Components inside components load too, up to
9
+ * `MAX_COMPONENT_DEPTH`; one that would contain itself gets `SECTION_REF_MISSING`, like one that
10
+ * cannot be loaded. Returns the same layout when there is nothing to load. Never mutates.
11
+ *
12
+ * `collection` is the saved sections collection. Default: the one the sectionRef definition in
13
+ * `blocks` points at (the plugin adds that definition; a site's own list usually has none).
8
14
  */
9
- export declare function attachSections(layout: Layout, blocks: readonly BlockDefinition[], fetchDocs: FetchDocs): Promise<Layout>;
15
+ export declare function attachSections(layout: Layout, blocks: readonly BlockDefinition[], fetchDocs: FetchDocs, collection?: string | null): Promise<Layout>;
@@ -1,51 +1,79 @@
1
1
  // Live saved sections: puts the current blocks of each `sectionRef` block's saved section into its
2
2
  // runtime slot, before the rest of the data loading (so the section's lists, images and
3
3
  // translations load like the page's own). Shared by `loadLayoutData` and the canvas.
4
- import { SECTION_REF_BLOCK, SECTION_REF_SLOT, sectionRefBlocks, sectionRefId } from '../../blocks/builtins/sectionRef.js';
4
+ //
5
+ // It names the built-in `sectionRef` block on purpose: putting stored blocks into a layout before
6
+ // the data loading is a step of the renderer, not of a block component, and the block contract has
7
+ // no loader hook. A general hook would be added when a second block needs one.
8
+ import { SECTION_REF_BLOCK, SECTION_REF_MISSING, SECTION_REF_SLOT, sectionRefBlocks, sectionRefId, } from '../../blocks/builtins/sectionRef.js';
9
+ import { applyComponentValues, componentValuesOf, normalizeLayout } from '../../core/index.js';
10
+ /** How deep components may sit inside components. Deeper ones render nothing. */
11
+ export const MAX_COMPONENT_DEPTH = 5;
5
12
  /** The collection the sectionRef definition's `section` field points at. */
6
13
  function sectionsCollectionOf(blocks) {
7
14
  const field = blocks.find((def) => def.type === SECTION_REF_BLOCK)?.fields.find((f) => 'name' in f && f.name === 'section');
8
15
  const relationTo = field && 'relationTo' in field ? field.relationTo : null;
9
16
  return typeof relationTo === 'string' ? relationTo : null;
10
17
  }
18
+ /** The ids of the saved sections that `sectionRef` blocks point at. Skips filled runtime slots. */
11
19
  function collectIds(blocks, ids) {
12
20
  for (const block of blocks) {
13
21
  if (block.type === SECTION_REF_BLOCK) {
14
22
  const id = sectionRefId(block.props?.section);
15
- if (id !== null)
16
- ids.add(id);
23
+ if (id !== null && !ids.has(String(id)))
24
+ ids.set(String(id), id);
25
+ continue;
17
26
  }
18
27
  for (const list of Object.values(block.slots ?? {}))
19
28
  collectIds(list, ids);
20
29
  }
21
30
  }
31
+ const missing = (block) => ({ ...block, props: { ...block.props, [SECTION_REF_MISSING]: true } });
22
32
  /**
23
33
  * Fills the runtime slot (`SECTION_REF_SLOT`) of every `sectionRef` block with its saved section's
24
- * blocks, loaded with `fetchDocs` (one call). One level: a sectionRef inside a saved section stays
25
- * empty, so a section can never include itself. A missing section leaves the slot out. Returns
26
- * the same layout when there is nothing to load. Never mutates.
34
+ * blocks, loaded with `fetchDocs` (one call per level of nesting). A component's copy gets its own
35
+ * values (`applyComponentValues`). Components inside components load too, up to
36
+ * `MAX_COMPONENT_DEPTH`; one that would contain itself gets `SECTION_REF_MISSING`, like one that
37
+ * cannot be loaded. Returns the same layout when there is nothing to load. Never mutates.
38
+ *
39
+ * `collection` is the saved sections collection. Default: the one the sectionRef definition in
40
+ * `blocks` points at (the plugin adds that definition; a site's own list usually has none).
27
41
  */
28
- export async function attachSections(layout, blocks, fetchDocs) {
29
- const collection = sectionsCollectionOf(blocks);
42
+ export async function attachSections(layout, blocks, fetchDocs, collection = sectionsCollectionOf(blocks)) {
30
43
  if (!collection)
31
44
  return layout;
32
- const ids = new Set();
45
+ const docs = new Map();
46
+ const fill = async (list, chain) => {
47
+ const ids = new Map();
48
+ collectIds(list, ids);
49
+ const wanted = [...ids].filter(([key]) => !docs.has(key)).map(([, id]) => id);
50
+ if (wanted.length > 0) {
51
+ const found = await fetchDocs(collection, wanted);
52
+ for (const [id, doc] of found)
53
+ docs.set(String(id), doc);
54
+ }
55
+ return Promise.all(list.map(async (block) => {
56
+ if (block.type === SECTION_REF_BLOCK) {
57
+ const id = sectionRefId(block.props?.section);
58
+ if (id === null)
59
+ return block;
60
+ const key = String(id);
61
+ const doc = docs.get(key);
62
+ if (!doc || chain.includes(key) || chain.length >= MAX_COMPONENT_DEPTH)
63
+ return missing(block);
64
+ const stored = normalizeLayout({ version: 1, blocks: doc.blocks }).blocks;
65
+ const own = sectionRefBlocks(block.id, applyComponentValues(stored, componentValuesOf(block.props), blocks));
66
+ return { ...block, slots: { ...block.slots, [SECTION_REF_SLOT]: await fill(own, [...chain, key]) } };
67
+ }
68
+ if (!block.slots)
69
+ return block;
70
+ const slots = await Promise.all(Object.entries(block.slots).map(async ([name, children]) => [name, await fill(children, chain)]));
71
+ return { ...block, slots: Object.fromEntries(slots) };
72
+ }));
73
+ };
74
+ const ids = new Map();
33
75
  collectIds(layout.blocks, ids);
34
76
  if (ids.size === 0)
35
77
  return layout;
36
- const docs = await fetchDocs(collection, [...ids]);
37
- const docOf = (id) => docs.get(id) ?? docs.get(String(id)) ?? docs.get(Number(id));
38
- const fill = (list) => list.map((block) => {
39
- if (block.type === SECTION_REF_BLOCK) {
40
- const id = sectionRefId(block.props?.section);
41
- const doc = id === null ? undefined : docOf(id);
42
- if (!doc)
43
- return block;
44
- return { ...block, slots: { ...block.slots, [SECTION_REF_SLOT]: sectionRefBlocks(block.id, doc.blocks) } };
45
- }
46
- if (!block.slots)
47
- return block;
48
- return { ...block, slots: Object.fromEntries(Object.entries(block.slots).map(([name, children]) => [name, fill(children)])) };
49
- });
50
- return { ...layout, blocks: fill(layout.blocks) };
78
+ return { ...layout, blocks: await fill(layout.blocks, []) };
51
79
  }
@@ -0,0 +1,47 @@
1
+ import type { Payload } from 'payload';
2
+ import { type Layout } from '../../core/index.js';
3
+ import { type RenderLocale } from './locale.js';
4
+ type Doc = Record<string, unknown>;
5
+ export type LoadedTemplate = {
6
+ /** The template document (depth 0). */
7
+ template: Doc;
8
+ layout: Layout;
9
+ /** The template's generated CSS, for `RenderLayout`'s `css`. */
10
+ css: string | null;
11
+ };
12
+ export type LoadTemplateArgs = RenderLocale & {
13
+ /** Slug of the document's collection, e.g. "posts". */
14
+ collection: string;
15
+ /** The document (any generated Payload type). Its `template` field may hold an ID or a loaded template. */
16
+ doc: Record<string, any>;
17
+ /** Slug of the templates collection. Default "builder-templates". */
18
+ templatesSlug?: string;
19
+ /** Draft mode: use the latest template drafts. Otherwise only published templates. */
20
+ draft?: boolean;
21
+ };
22
+ /**
23
+ * `loadTemplate` with one more choice: `documentDraft` matches the conditions against the latest
24
+ * draft of the document (the editor) while `draft: false` still uses published templates only.
25
+ * Default: the same as `draft`.
26
+ */
27
+ export declare function findTemplate(payload: Payload, args: LoadTemplateArgs & {
28
+ documentDraft?: boolean;
29
+ }): Promise<LoadedTemplate | null>;
30
+ /**
31
+ * The template a document renders through: the document's own template (its `template` field),
32
+ * else the template with the highest `priority` whose `conditions` match the document (equal
33
+ * priority: the older template), else the collection's default template, else `null`. Templates
34
+ * with an empty layout are skipped. Costs one query for the template list, one per template with
35
+ * conditions (in parallel, none without conditions) and one for the chosen template.
36
+ *
37
+ * Render it with the document as context. Load the document with the visitor's access, so the
38
+ * template cannot show fields the visitor may not read (for example an author's email):
39
+ *
40
+ * const post = await payload.find({ collection: 'posts', where, depth: 1, draft, overrideAccess: false, user })
41
+ * const found = await loadTemplate(payload, { collection: 'posts', doc: post, draft })
42
+ * const context = { collection: 'posts', doc: post }
43
+ * const layout = await loadLayoutData(found.layout, blocks, payload, { draft, context, resolveLink, user })
44
+ * <RenderLayout layout={layout} context={context} blocks={blocks} resolveLink={resolveLink} />
45
+ */
46
+ export declare function loadTemplate(payload: Payload, args: LoadTemplateArgs): Promise<LoadedTemplate | null>;
47
+ export {};
@@ -0,0 +1,139 @@
1
+ // Server only: which template a document renders through (`loadTemplate`). The order is the pure
2
+ // rule in core/templateChoice.ts; this module asks Payload's Local API for the data.
3
+ import { DEFAULT_TEMPLATES_SLUG, DOCUMENT_TEMPLATE_FIELD, normalizeLayout, TEMPLATE_CONDITIONS_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_PRIORITY_FIELD, TEMPLATE_TARGET_FIELD, } from '../../core/index.js';
4
+ import { conditionedTemplates, defaultTemplates } from '../../core/templateChoice.js';
5
+ import { isRecord } from './fields.js';
6
+ import { withDateTokens } from './lists.js';
7
+ import { localeArgs } from './locale.js';
8
+ /** The generated CSS stored next to a layout field (`{ hash, css }`). */
9
+ function cssOf(template) {
10
+ const value = template[`${TEMPLATE_LAYOUT_FIELD}Css`];
11
+ return isRecord(value) && typeof value.css === 'string' ? value.css : null;
12
+ }
13
+ function usable(template, collection, draft) {
14
+ if (!template)
15
+ return null;
16
+ if (template[TEMPLATE_TARGET_FIELD] !== collection)
17
+ return null;
18
+ if (!draft && template._status === 'draft')
19
+ return null;
20
+ // Read with the render's `locale`, so the layout already holds that locale's values.
21
+ const layout = normalizeLayout(template[TEMPLATE_LAYOUT_FIELD]);
22
+ if (layout.blocks.length === 0)
23
+ return null;
24
+ return { template, layout, css: cssOf(template) };
25
+ }
26
+ /** How many templates of one collection `loadTemplate` looks at. */
27
+ const CANDIDATES = 100;
28
+ /**
29
+ * Whether the stored document matches a template's conditions: one Payload query, so every
30
+ * operator and field path Payload knows works. Date tokens (`$now-30d`) become dates. A query Payload refuses (an unknown field) counts
31
+ * as no match and is logged.
32
+ */
33
+ async function matchesConditions(payload, collection, id, where, draft, locale) {
34
+ try {
35
+ const found = await payload.find({
36
+ collection: collection,
37
+ // Date tokens (`$now-30d`) work as in collection lists.
38
+ where: { and: [{ id: { equals: id } }, withDateTokens(where)] },
39
+ draft,
40
+ depth: 0,
41
+ limit: 1,
42
+ pagination: false,
43
+ select: { id: true },
44
+ ...locale,
45
+ });
46
+ return found.docs.length > 0;
47
+ }
48
+ catch (error) {
49
+ payload.logger.error({ err: error, msg: '[builder] Template conditions failed. The template is skipped.' });
50
+ return false;
51
+ }
52
+ }
53
+ /**
54
+ * `loadTemplate` with one more choice: `documentDraft` matches the conditions against the latest
55
+ * draft of the document (the editor) while `draft: false` still uses published templates only.
56
+ * Default: the same as `draft`.
57
+ */
58
+ export async function findTemplate(payload, args) {
59
+ const { collection, doc } = args;
60
+ const slug = args.templatesSlug ?? DEFAULT_TEMPLATES_SLUG;
61
+ const draft = args.draft ?? false;
62
+ if (!payload.collections[slug])
63
+ return null;
64
+ // Localized sites: the template's localized props in the render's locale.
65
+ const locale = localeArgs(args);
66
+ const loadFull = async (id) => {
67
+ if (typeof id !== 'string' && typeof id !== 'number')
68
+ return null;
69
+ try {
70
+ return usable((await payload.findByID({ collection: slug, id, depth: 0, draft, ...locale })), collection, draft);
71
+ }
72
+ catch {
73
+ // A deleted template falls back to the next one.
74
+ return null;
75
+ }
76
+ };
77
+ // 1. The document's own template.
78
+ const own = doc[DOCUMENT_TEMPLATE_FIELD];
79
+ const found = await loadFull(isRecord(own) ? own.id : own);
80
+ if (found)
81
+ return found;
82
+ // One light read of the collection's templates: only what the order needs, no layouts.
83
+ const candidates = (await payload.find({
84
+ collection: slug,
85
+ where: { and: [{ [TEMPLATE_TARGET_FIELD]: { equals: collection } }, ...(draft ? [] : [{ _status: { equals: 'published' } }])] },
86
+ sort: 'createdAt',
87
+ depth: 0,
88
+ limit: CANDIDATES,
89
+ draft,
90
+ select: {
91
+ [TEMPLATE_CONDITIONS_FIELD]: true,
92
+ [TEMPLATE_PRIORITY_FIELD]: true,
93
+ [TEMPLATE_DEFAULT_FIELD]: true,
94
+ createdAt: true,
95
+ updatedAt: true,
96
+ },
97
+ ...locale,
98
+ })).docs;
99
+ // 2. Templates with conditions: the match queries run at the same time; the order picks the winner.
100
+ const conditioned = conditionedTemplates(candidates);
101
+ const docId = doc.id;
102
+ if (conditioned.length > 0 && (typeof docId === 'string' || typeof docId === 'number')) {
103
+ const documentDraft = args.documentDraft ?? draft;
104
+ const matched = await Promise.all(conditioned.map(({ where }) => matchesConditions(payload, collection, docId, where, documentDraft, locale)));
105
+ for (const [i, { template }] of conditioned.entries()) {
106
+ if (!matched[i])
107
+ continue;
108
+ const loaded = await loadFull(template.id);
109
+ if (loaded)
110
+ return loaded;
111
+ }
112
+ }
113
+ // 3. The default template. An empty default (older data) falls back to the next one.
114
+ for (const template of defaultTemplates(candidates)) {
115
+ const loaded = await loadFull(template.id);
116
+ if (loaded)
117
+ return loaded;
118
+ }
119
+ return null;
120
+ }
121
+ /**
122
+ * The template a document renders through: the document's own template (its `template` field),
123
+ * else the template with the highest `priority` whose `conditions` match the document (equal
124
+ * priority: the older template), else the collection's default template, else `null`. Templates
125
+ * with an empty layout are skipped. Costs one query for the template list, one per template with
126
+ * conditions (in parallel, none without conditions) and one for the chosen template.
127
+ *
128
+ * Render it with the document as context. Load the document with the visitor's access, so the
129
+ * template cannot show fields the visitor may not read (for example an author's email):
130
+ *
131
+ * const post = await payload.find({ collection: 'posts', where, depth: 1, draft, overrideAccess: false, user })
132
+ * const found = await loadTemplate(payload, { collection: 'posts', doc: post, draft })
133
+ * const context = { collection: 'posts', doc: post }
134
+ * const layout = await loadLayoutData(found.layout, blocks, payload, { draft, context, resolveLink, user })
135
+ * <RenderLayout layout={layout} context={context} blocks={blocks} resolveLink={resolveLink} />
136
+ */
137
+ export function loadTemplate(payload, args) {
138
+ return findTemplate(payload, args);
139
+ }
@@ -1,4 +1,4 @@
1
- import type { ComponentType, ReactNode } from 'react';
1
+ import type { AnchorHTMLAttributes, ComponentType, ReactNode } from 'react';
2
2
  import type { BindingRelations, Block, BlockDefinition, Layout, TemplateContext } from '../../core/index.js';
3
3
  /**
4
4
  * "site" renders the public page. "canvas" adds editor attributes and empty-slot placeholders.
@@ -54,8 +54,15 @@ export type BlockComponentProps = {
54
54
  slots: Record<string, ReactNode>;
55
55
  /** Spread on the component's root element. In canvas mode it holds `data-block-id`. */
56
56
  attributes: Record<string, string>;
57
- /** Spread on the element that directly contains each slot's children. */
58
- slotAttributes: Record<string, Record<string, string>>;
57
+ /**
58
+ * By slot or part name. Spread a slot's entry on the element that directly contains the slot's
59
+ * children (in the canvas it marks the drop zone). A part's entry (a slot with `styles: true`
60
+ * or a name in `BlockDefinition.parts`) carries the part's `className`, with the `builder-css`
61
+ * marker: join it with the element's own classes. Always set for every slot and part.
62
+ */
63
+ partAttributes: Record<string, Record<string, string>>;
64
+ /** @deprecated The same object as `partAttributes` (its name before 0.4). */
65
+ slotAttributes?: Record<string, Record<string, string>>;
59
66
  mode: RenderMode;
60
67
  /**
61
68
  * The page data (`RenderLayout`'s `pageData`; in the canvas, the `pageData` loader of
@@ -63,7 +70,34 @@ export type BlockComponentProps = {
63
70
  * `fromPayloadComponent` component.
64
71
  */
65
72
  pageData?: PageData;
73
+ /**
74
+ * Set only when the block renders on the server for the editor (`createCanvasServer`):
75
+ * `'canvas'`, or `'thumbnail'` for the pictures of the section library. Missing on the site.
76
+ * Server components read this; client components call `useCanvasMode()` instead.
77
+ */
78
+ canvasMode?: 'canvas' | 'thumbnail';
79
+ /**
80
+ * The site's link component (`RenderLayout`'s `linkComponent`, for example `next/link`). Only
81
+ * components marked with `withLinkComponent` get it, and only on the site. Render it in place
82
+ * of `<a>` when it is set. Server components only: a function cannot reach a client component.
83
+ */
84
+ linkComponent?: LinkComponent;
85
+ /**
86
+ * Set on the site when `RenderLayout` has a `linkComponent`, for client components marked with
87
+ * `withClientLinks`. Render `next/link` in place of `<a>` when it is true.
88
+ */
89
+ clientLinks?: boolean;
90
+ };
91
+ /** What a link component gets: the `<a>` attributes, with `href` always set. */
92
+ export type LinkComponentProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
93
+ href: string;
66
94
  };
95
+ /**
96
+ * Renders a link in place of `<a>`, for example `next/link` for client-side navigation and
97
+ * prefetching. Server-rendered blocks get it as a prop. Client blocks cannot get a function from the
98
+ * server (Next's server `next/link` is one), so they get `clientLinks` and render `next/link` themselves.
99
+ */
100
+ export type LinkComponent = ComponentType<LinkComponentProps>;
67
101
  /** Data the page loads once for all its blocks, for example a list of services or review totals. */
68
102
  export type PageData = Record<string, unknown>;
69
103
  export type BlockComponents = Record<string, ComponentType<BlockComponentProps>>;
@@ -93,8 +127,10 @@ export type RenderLayoutProps = {
93
127
  */
94
128
  context?: TemplateContext | null;
95
129
  /**
96
- * Which collection each relationship field points to (`bindingRelations(payload.config.collections)`
97
- * from `payload-canvas/core`), for `<path>.$url` bindings such as `categories.0.$url`.
130
+ * Which collection each relationship field points to (`bindingRelations`), for `<path>.$url`
131
+ * bindings such as `categories.0.$url`. Sites leave it out: `loadLayoutData` reads it from the
132
+ * Payload config and gives it to the collection lists and repeats that need it. The canvas,
133
+ * which has no Payload config, gets it from the plugin.
98
134
  */
99
135
  relations?: BindingRelations | null;
100
136
  /**
@@ -103,6 +139,27 @@ export type RenderLayoutProps = {
103
139
  * comes from the `pageData` loader of `createCanvasServer`: use the same loader on the site.
104
140
  */
105
141
  pageData?: PageData | null;
142
+ /**
143
+ * Renders the links of the built-in button, link and menu blocks (and of components marked with
144
+ * `withLinkComponent`) on the site. Default: a plain `<a>`. Pass `next/link` for client-side
145
+ * navigation and prefetching. Server-rendered blocks render it; client blocks marked with
146
+ * `withClientLinks` (the menu) get `clientLinks: true` and render `next/link`. Ignored in the editor canvas.
147
+ */
148
+ linkComponent?: LinkComponent | null;
149
+ /**
150
+ * How many images of the layout's first section load first (`fetchpriority="high"`, not lazy):
151
+ * image blocks (and other blocks with a `priority` prop), in page order, unless their **Load first** prop
152
+ * is off. Default `1`: the first image of the first section, often the largest thing on screen.
153
+ * Give a layout further down the page (a footer) `0`. Site only.
154
+ */
155
+ priorityImages?: number;
156
+ /**
157
+ * Site only. Default `true`: when an accordion in the layout has "Mark up as FAQ for search
158
+ * engines" on (`faqSchema`), the layout outputs one `<script type="application/ld+json">` with
159
+ * FAQPage data for those items (`faqItems`, `faqJsonLd`). `false` leaves it out, for a site that
160
+ * outputs its own.
161
+ */
162
+ faqJsonLd?: boolean;
106
163
  };
107
164
  /** Loads documents for a batch of ids in one collection. */
108
165
  export type FetchDocs = (collection: string, ids: Array<string | number>) => Promise<Map<string | number, Record<string, unknown>>>;
@@ -1,49 +1,14 @@
1
1
  import type { Payload } from 'payload';
2
2
  import { type Layout } from '../core/index.js';
3
- import { type RenderLocale } from './render/locale.js';
4
3
  export { loadLayoutData, type LoadLayoutOptions } from './render/resolve.js';
4
+ export { loadTemplate, type LoadedTemplate, type LoadTemplateArgs } from './render/templates.js';
5
5
  export { loadedLists, type LoadedList } from './render/lists.js';
6
6
  export { localeArgs, localizeLayout, type RenderLocale } from './render/locale.js';
7
7
  export { createCanvasServer, type CanvasFrameArgs, type CanvasServerOptions, type PageDataArgs } from './render/canvasServer.js';
8
8
  export { siteRegion, type RegionMark } from './render/regions.js';
9
9
  export type { CanvasServerRequest, CanvasServerResponse } from './render/canvasServerTypes.js';
10
10
  export { loadTheme, ThemeStyle, type LoadedTheme, type ThemeStyleProps } from './theme/ThemeStyle.js';
11
- type Doc = Record<string, unknown>;
12
- export type LoadedTemplate = {
13
- /** The template document (depth 0). */
14
- template: Doc;
15
- layout: Layout;
16
- /** The template's generated CSS, for `RenderLayout`'s `css`. */
17
- css: string | null;
18
- };
19
- export type LoadTemplateArgs = RenderLocale & {
20
- /** Slug of the document's collection, e.g. "posts". */
21
- collection: string;
22
- /** The document (any generated Payload type). Its `template` field may hold an ID or a loaded template. */
23
- doc: Record<string, any>;
24
- /** Slug of the templates collection. Default "builder-templates". */
25
- templatesSlug?: string;
26
- /** Draft mode: use the latest template drafts. Otherwise only published templates. */
27
- draft?: boolean;
28
- };
29
- /**
30
- * The template a document renders through: the document's own template (its `template` field),
31
- * else the first template (by name) whose `conditions` match the document, else the collection's
32
- * default template, else `null`. Templates with an empty layout are
33
- * skipped: an empty own template falls back to the default, and an empty default falls back to
34
- * the next most recently changed default (the plugin refuses to publish an empty default, so
35
- * this only matters for older data).
36
- *
37
- * Render it with the document as context. Load the document with the visitor's access, so the
38
- * template cannot show fields the visitor may not read (for example an author's email):
39
- *
40
- * const post = await payload.find({ collection: 'posts', where, depth: 1, draft, overrideAccess: false, user })
41
- * const found = await loadTemplate(payload, { collection: 'posts', doc: post, draft })
42
- * const context = { collection: 'posts', doc: post }
43
- * const layout = await loadLayoutData(found.layout, blocks, payload, { draft, context, resolveLink, user })
44
- * <RenderLayout layout={layout} context={context} blocks={blocks} resolveLink={resolveLink} />
45
- */
46
- export declare function loadTemplate(payload: Payload, args: LoadTemplateArgs): Promise<LoadedTemplate | null>;
11
+ export { ClassesStyle, CLASSES_PRECEDENCE, loadClassesSheet, type ClassesStyleProps } from './classes/ClassesStyle.js';
47
12
  /** One layout rendered on a page, with the CSS stored for it (used when the compile is not possible). */
48
13
  export type PageCssPart = {
49
14
  layout: Layout;
@@ -1,145 +1,18 @@
1
1
  // Server-only helpers: `payload-canvas/react/server`. They call Payload's Local API, so
2
2
  // keep them out of client components (the main entry stays client-safe).
3
3
  import { siteCssConfigOf } from '../plugin/index.js';
4
- import { collectClasses, DEFAULT_TEMPLATES_SLUG, DOCUMENT_TEMPLATE_FIELD, normalizeLayout, TEMPLATE_CONDITIONS_FIELD, TEMPLATE_DEFAULT_FIELD, TEMPLATE_LAYOUT_FIELD, TEMPLATE_TARGET_FIELD, templateConditions, } from '../core/index.js';
4
+ import { collectClasses } from '../core/index.js';
5
5
  import { compileClasses } from '../css/index.js';
6
- import { isRecord } from './render/fields.js';
7
- import { localeArgs } from './render/locale.js';
6
+ import { withThemeVariables } from '../theme/server.js';
7
+ import { loadClassesSheet } from './classes/ClassesStyle.js';
8
8
  export { loadLayoutData } from './render/resolve.js';
9
+ export { loadTemplate } from './render/templates.js';
9
10
  export { loadedLists } from './render/lists.js';
10
11
  export { localeArgs, localizeLayout } from './render/locale.js';
11
12
  export { createCanvasServer } from './render/canvasServer.js';
12
13
  export { siteRegion } from './render/regions.js';
13
14
  export { loadTheme, ThemeStyle } from './theme/ThemeStyle.js';
14
- /** The generated CSS stored next to a layout field (`{ hash, css }`). */
15
- function cssOf(template) {
16
- const value = template[`${TEMPLATE_LAYOUT_FIELD}Css`];
17
- return isRecord(value) && typeof value.css === 'string' ? value.css : null;
18
- }
19
- function usable(template, collection, draft) {
20
- if (!template)
21
- return null;
22
- if (template[TEMPLATE_TARGET_FIELD] !== collection)
23
- return null;
24
- if (!draft && template._status === 'draft')
25
- return null;
26
- // Read with the render's `locale`, so the layout already holds that locale's values.
27
- const layout = normalizeLayout(template[TEMPLATE_LAYOUT_FIELD]);
28
- if (layout.blocks.length === 0)
29
- return null;
30
- return { template, layout, css: cssOf(template) };
31
- }
32
- /** How many templates with conditions `loadTemplate` tries, in name order. */
33
- const CONDITION_CANDIDATES = 100;
34
- /**
35
- * Whether the stored document (the latest draft in draft mode) matches a template's conditions:
36
- * one Payload query, so every operator and field path Payload knows works. A query Payload
37
- * refuses (an unknown field) counts as no match and is logged.
38
- */
39
- async function matchesConditions(payload, collection, id, where, draft, locale) {
40
- try {
41
- const found = await payload.find({
42
- collection: collection,
43
- where: { and: [{ id: { equals: id } }, where] },
44
- draft,
45
- depth: 0,
46
- limit: 1,
47
- pagination: false,
48
- select: { id: true },
49
- ...locale,
50
- });
51
- return found.docs.length > 0;
52
- }
53
- catch (error) {
54
- payload.logger.error({ err: error, msg: '[builder] Template conditions failed. The template is skipped.' });
55
- return false;
56
- }
57
- }
58
- /** How many default templates `loadTemplate` looks at (one normally; more only with old data). */
59
- const DEFAULT_CANDIDATES = 5;
60
- /**
61
- * The template a document renders through: the document's own template (its `template` field),
62
- * else the first template (by name) whose `conditions` match the document, else the collection's
63
- * default template, else `null`. Templates with an empty layout are
64
- * skipped: an empty own template falls back to the default, and an empty default falls back to
65
- * the next most recently changed default (the plugin refuses to publish an empty default, so
66
- * this only matters for older data).
67
- *
68
- * Render it with the document as context. Load the document with the visitor's access, so the
69
- * template cannot show fields the visitor may not read (for example an author's email):
70
- *
71
- * const post = await payload.find({ collection: 'posts', where, depth: 1, draft, overrideAccess: false, user })
72
- * const found = await loadTemplate(payload, { collection: 'posts', doc: post, draft })
73
- * const context = { collection: 'posts', doc: post }
74
- * const layout = await loadLayoutData(found.layout, blocks, payload, { draft, context, resolveLink, user })
75
- * <RenderLayout layout={layout} context={context} blocks={blocks} resolveLink={resolveLink} />
76
- */
77
- export async function loadTemplate(payload, args) {
78
- const { collection, doc } = args;
79
- const slug = args.templatesSlug ?? DEFAULT_TEMPLATES_SLUG;
80
- const draft = args.draft ?? false;
81
- if (!payload.collections[slug])
82
- return null;
83
- // Localized sites: the template's localized props in the render's locale.
84
- const locale = localeArgs(args);
85
- const own = doc[DOCUMENT_TEMPLATE_FIELD];
86
- const ownId = isRecord(own) ? own.id : own;
87
- if (typeof ownId === 'string' || typeof ownId === 'number') {
88
- try {
89
- const template = (await payload.findByID({ collection: slug, id: ownId, depth: 0, draft, ...locale }));
90
- const found = usable(template, collection, draft);
91
- if (found)
92
- return found;
93
- }
94
- catch {
95
- // A deleted template falls back to the default.
96
- }
97
- }
98
- const docId = doc.id;
99
- if (typeof docId === 'string' || typeof docId === 'number') {
100
- // Only the conditions are read here; the matching template loads in full below.
101
- const candidates = await payload.find({
102
- collection: slug,
103
- where: { and: [{ [TEMPLATE_TARGET_FIELD]: { equals: collection } }, ...(draft ? [] : [{ _status: { equals: 'published' } }])] },
104
- sort: 'name',
105
- depth: 0,
106
- limit: CONDITION_CANDIDATES,
107
- draft,
108
- select: { [TEMPLATE_CONDITIONS_FIELD]: true },
109
- ...locale,
110
- });
111
- for (const candidate of candidates.docs) {
112
- const where = templateConditions(candidate);
113
- if (!where || !(await matchesConditions(payload, collection, docId, where, draft, locale)))
114
- continue;
115
- const template = (await payload.findByID({ collection: slug, id: candidate.id, depth: 0, draft, ...locale }));
116
- const found = usable(template, collection, draft);
117
- if (found)
118
- return found;
119
- }
120
- }
121
- const result = await payload.find({
122
- collection: slug,
123
- where: {
124
- and: [
125
- { [TEMPLATE_TARGET_FIELD]: { equals: collection } },
126
- { [TEMPLATE_DEFAULT_FIELD]: { equals: true } },
127
- ...(draft ? [] : [{ _status: { equals: 'published' } }]),
128
- ],
129
- },
130
- sort: '-updatedAt',
131
- depth: 0,
132
- limit: DEFAULT_CANDIDATES,
133
- draft,
134
- ...locale,
135
- });
136
- for (const candidate of result.docs) {
137
- const found = usable(candidate, collection, draft);
138
- if (found)
139
- return found;
140
- }
141
- return null;
142
- }
15
+ export { ClassesStyle, CLASSES_PRECEDENCE, loadClassesSheet } from './classes/ClassesStyle.js';
143
16
  /**
144
17
  * One stylesheet for every layout a page renders (for example header, page or template, footer).
145
18
  *
@@ -165,7 +38,9 @@ export async function compilePageCss(payload, parts) {
165
38
  if (classes.size === 0)
166
39
  return null;
167
40
  try {
168
- return (await compileClasses([...classes], config.css)) || null;
41
+ // Editable classes come from their own stylesheet (`ClassesStyle`): the page leaves them out.
42
+ const sheet = await loadClassesSheet(payload).catch(() => null);
43
+ return (await compileClasses([...classes], await withThemeVariables(payload, config.css), { exclude: sheet?.names ?? [] })) || null;
169
44
  }
170
45
  catch (error) {
171
46
  payload.logger.error({ err: error, msg: '[builder] Page CSS compile failed. Using the stored CSS of each layout.' });
@@ -0,0 +1,4 @@
1
+ export declare const ThemeLive: import("react").ComponentType<{
2
+ endpoint: string;
3
+ fonts?: boolean;
4
+ }>;
@@ -0,0 +1,5 @@
1
+ 'use client';
2
+ // `ThemeLive` in a chunk of its own: only the canvas renders it (`<ThemeStyle live>`), but the
3
+ // root layout imports `ThemeStyle`, and a page ships every client component its modules import.
4
+ import dynamic from 'next/dynamic';
5
+ export const ThemeLive = dynamic(() => import('./ThemeLive.js').then((module) => module.ThemeLive));
@@ -3,7 +3,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
3
3
  import { themeConfigOf, themeOutput } from '../../theme/index.js';
4
4
  import { cache, Suspense } from 'react';
5
5
  import { THEME_PRECEDENCE, themeStyleHref } from './constants.js';
6
- import { ThemeLive } from './ThemeLive.js';
6
+ import { ThemeLive } from './ThemeLiveLoader.js';
7
7
  /**
8
8
  * Reads the theme global and turns it into CSS (`:root:root { --primary: …; … }`) and a Google
9
9
  * Fonts URL. `null` when the plugin runs with `theme: false`. Read once per request (React