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
@@ -2,8 +2,9 @@ import path from 'node:path';
2
2
  import { AI_PATH, aiEndpoints } from '../ai/endpoint.js';
3
3
  import { aiClientConfig } from '../ai/config.js';
4
4
  import { AI_IMAGES_KEY, createImageService } from '../ai/images/service.js';
5
+ import { AI_SETTINGS_KEY, aiSettingsGlobal, aiSettingsRuntime, DEFAULT_AI_SETTINGS_SLUG } from '../ai/settings/index.js';
5
6
  import { defaultBlocks } from '../blocks/index.js';
6
- import { richTextFieldName, sectionsWithDefaultClassNames, sectionsWithVariants } from '../core/blocks.js';
7
+ import { checkSectionVariants, richTextFieldName, sectionsWithDefaultClassNames } from '../core/blocks.js';
7
8
  import { bindingRelations, DEFAULT_TEMPLATES_SLUG, DOCUMENT_TEMPLATE_FIELD, TEMPLATE_TARGET_FIELD } from '../core/bindings.js';
8
9
  import { localeSettingsOf } from '../core/locale.js';
9
10
  import { resolveRegions } from '../core/regions.js';
@@ -13,19 +14,26 @@ import { applyFontFamilies, getCanvasCssInput, getStyleTokens } from '../css/ind
13
14
  import { DEFAULT_THEME_SLUG, THEME_CONFIG_KEY, THEME_PATH } from '../theme/config.js';
14
15
  import { themeFontFamilies, themeOutput } from '../theme/css.js';
15
16
  import { themeGlobal } from '../theme/global.js';
17
+ import { themeStyleTokens, withThemeVariables } from '../theme/server.js';
18
+ import { variableUsageEndpoint } from '../theme/usage.js';
16
19
  import { BUILDER_CONFIG_KEY, defaultLiveRuntime, documentEndpoints, installShutdownFlush, LIVE_PATH, LIVE_RUNTIME_KEY, liveEndpoints, } from '../live/index.js';
17
20
  import { captureFieldSemantics } from '../core/fieldSemantics.js';
18
21
  import { FIELD_REGISTRY_KEY } from '../live/fieldChecks.js';
22
+ import { CONTENT_MODE_KEY, withDesignAccess } from '../live/contentMode.js';
19
23
  import { regionEndpoints } from '../live/regions.js';
20
24
  import { defaultWriteGate, installLocalApiBoundary, installTransactionSignals, withGateSignals } from '../live/writeGate.js';
21
25
  import { keepLockBeforeOperation, layoutAfterChange, payloadBlocksAfterChange, payloadBlocksBeforeChange, layoutAfterRead, layoutBeforeChange, recordOverrideAccess, } from './hook.js';
22
26
  import { DEFAULT_SAVED_SECTIONS_SLUG, SAVED_SECTIONS_CONFIG_KEY, savedSectionsCollection, SECTION_LAYOUT_FIELD, } from './sections.js';
23
27
  import { syncSectionBlocks } from './sectionsBuilder.js';
28
+ import { withSectionUsedIn } from './sectionsUsedIn.js';
24
29
  import { toJsonSafe } from './jsonSafe.js';
25
30
  import { collectionLabel } from './labels.js';
26
31
  import { listableCollections, prepareBlocks } from './listCollections.js';
27
32
  import { addReferences, REFERENCES_CONFIG_KEY, resolveReferences } from './references.js';
28
33
  import { bindingSources, documentTemplateField, hasFieldNamed, requireBlocksForDefault, TEMPLATE_LAYOUT_FIELD, TEMPLATES_CONFIG_KEY, templatesCollection, } from './templates.js';
34
+ import { templateEndpoint } from './templateEndpoint.js';
35
+ import { CLASSES_CONFIG_KEY, resolveClasses } from '../classes/index.js';
36
+ import { resolveComments } from '../comments/index.js';
29
37
  /**
30
38
  * Server-only key in `config.custom`: what the site needs to compile one stylesheet for every
31
39
  * layout on a page (`compilePageCss` in `payload-canvas/react/server`).
@@ -38,6 +46,7 @@ export function siteCssConfigOf(payload) {
38
46
  }
39
47
  const LAYOUT_FIELD_COMPONENT = 'payload-canvas/client#LayoutField';
40
48
  const BUILDER_TAB_COMPONENT = 'payload-canvas/client#BuilderTab';
49
+ const DOCUMENT_EDIT_VIEW_COMPONENT = 'payload-canvas/client#DocumentEditView';
41
50
  const PUBLISH_BUTTON_COMPONENT = 'payload-canvas/client#PublishButton';
42
51
  const BUILDER_VIEW_COMPONENT = 'payload-canvas/rsc#BuilderView';
43
52
  const BUILDER_REDIRECT_COMPONENT = 'payload-canvas/rsc#BuilderRedirect';
@@ -60,6 +69,14 @@ export function cssFieldName(field) {
60
69
  * Editors open the builder full screen at `{admin}/builder/:collection/:id` (a root admin view
61
70
  * without Payload's nav and header). The document's "Builder" tab and the layout field link there.
62
71
  */
72
+ /** The sections, and their variants, whose blocks `fits` accepts (a Payload blocks field stores only some). */
73
+ function sectionsThatFit(sections, fits) {
74
+ return sections.flatMap((section) => {
75
+ if (!fits(section.blocks))
76
+ return [];
77
+ return [section.variants ? { ...section, variants: section.variants.filter((v) => fits(v.blocks)) } : section];
78
+ });
79
+ }
63
80
  export function websiteBuilder(options) {
64
81
  return (config) => {
65
82
  const apiRoute = config.routes?.api ?? '/api';
@@ -140,10 +157,14 @@ export function websiteBuilder(options) {
140
157
  ];
141
158
  builderOptions[templatesSlug] = { field: TEMPLATE_LAYOUT_FIELD, ...(options.templates?.localization === false ? { localization: false } : {}) };
142
159
  }
143
- // Inline blocks (`inline: true`) may sit in a link: they join its `allow` list.
144
- const blocks = prepareBlocks(options.blocks ?? defaultBlocks(), listable);
145
- // Each section variant is listed as a section of its own (`<id>/<variant id>`).
146
- const appSections = sectionsWithVariants(options.sections ?? []);
160
+ // Saved sections: a collection of sections people saved from the editor.
161
+ const savedSections = options.savedSections === false ? null : { slug: options.savedSections?.slug ?? DEFAULT_SAVED_SECTIONS_SLUG };
162
+ // Inline blocks (`inline: true`) may sit in a link: they join its `allow` list. With saved
163
+ // sections on, the live saved section block (`sectionRef`) joins the list, pointed at their collection.
164
+ const blocks = prepareBlocks(options.blocks ?? defaultBlocks(), listable, savedSections?.slug ?? null);
165
+ // Variants stay under their section (core/sections.ts): one library card, a switch on the canvas.
166
+ const appSections = options.sections ?? [];
167
+ checkSectionVariants(appSections);
147
168
  // A section block without a className gets its type's default classes (JSON layouts only).
148
169
  const sections = sectionsWithDefaultClassNames(appSections, blocks);
149
170
  const duplicate = blocks.find((b, i) => blocks.findIndex((other) => other.type === b.type) !== i);
@@ -177,15 +198,13 @@ export function websiteBuilder(options) {
177
198
  ];
178
199
  blocksStorageOf[slug] = payloadBlocksStorage([...new Set(slugs)], blocks, `"${slug}.${field}"`);
179
200
  }
180
- // Saved sections: a collection of sections people saved from the editor.
181
- const savedSections = options.savedSections === false ? null : { slug: options.savedSections?.slug ?? DEFAULT_SAVED_SECTIONS_SLUG };
182
201
  if (savedSections) {
183
202
  if (collections.some((c) => c.slug === savedSections.slug)) {
184
203
  throw new Error(`[websiteBuilder] A collection named "${savedSections.slug}" already exists. Set \`savedSections.slug\` to another name, or \`savedSections: false\`.`);
185
204
  }
186
205
  collections = [
187
206
  ...collections,
188
- savedSectionsCollection({ slug: savedSections.slug, blocks, options: options.savedSections || undefined }),
207
+ withSectionUsedIn(savedSectionsCollection({ slug: savedSections.slug, blocks, options: options.savedSections || undefined })),
189
208
  ];
190
209
  // The full-screen builder edits saved sections like pages (no drafts: changes save at once).
191
210
  builderOptions[savedSections.slug] = { field: SECTION_LAYOUT_FIELD };
@@ -233,6 +252,10 @@ export function websiteBuilder(options) {
233
252
  entry: path.resolve(process.cwd(), options.css.entry),
234
253
  plugins: options.css.plugins,
235
254
  };
255
+ // Editable classes: a collection, a hidden global with the compiled stylesheet, endpoints.
256
+ const classes = resolveClasses(options.classes, { apiRoute, css, blocks, collections, globals: config.globals ?? [] });
257
+ // Comments on the canvas: a collection the editor reads and writes over REST.
258
+ const comments = resolveComments(options.comments, { collections, userSlug: config.admin?.user ?? 'users' });
236
259
  const liveCollections = Object.fromEntries(Object.entries(builderOptions).map(([slug, o]) => [
237
260
  slug,
238
261
  {
@@ -281,7 +304,15 @@ export function websiteBuilder(options) {
281
304
  : undefined;
282
305
  const fieldNames = {};
283
306
  // Image generation: one service (and one hourly limit) for the assistant, the editor and the MCP tools.
284
- const imageService = options.ai ? createImageService(options.ai) : null;
307
+ // AI settings: a global where an admin pastes API keys. The endpoints read them per request.
308
+ const aiSettingsOptions = options.ai && options.ai.settings !== false ? (options.ai.settings ?? {}) : null;
309
+ const aiSettings = options.ai && aiSettingsOptions ? aiSettingsRuntime(options.ai, aiSettingsOptions, `${apiRoute}${AI_PATH}`) : null;
310
+ if (aiSettings && (config.globals ?? []).some((g) => g.slug === aiSettings.slug)) {
311
+ throw new Error(`[websiteBuilder] A global named "${aiSettings.slug}" already exists. Set \`ai.settings.slug\` to another name, or set \`ai.settings: false\`. (Default slug: "${DEFAULT_AI_SETTINGS_SLUG}".)`);
312
+ }
313
+ const imageService = options.ai
314
+ ? createImageService(options.ai, { resolveKey: aiSettings ? (payload) => aiSettings.keyFor(payload, 'images') : null })
315
+ : null;
285
316
  return {
286
317
  ...config,
287
318
  // The write gate hears of every commit, rollback and failed Local API save from the first one
@@ -317,14 +348,21 @@ export function websiteBuilder(options) {
317
348
  tokensEndpoint: `${apiRoute}${STYLE_TOKENS_PATH}`,
318
349
  // Only sections the field can store as they are.
319
350
  sections: storage
320
- ? appSections.filter((section) => payloadBlocksProblems({ version: 1, blocks: section.blocks }, storage).length === 0)
351
+ ? sectionsThatFit(appSections, (list) => payloadBlocksProblems({ version: 1, blocks: list }, storage).length === 0)
321
352
  : sections,
322
353
  liveEndpoint: `${apiRoute}${LIVE_PATH}`,
323
354
  templates: clientTemplates,
324
355
  ai: options.ai ? aiClientConfig(options.ai, `${apiRoute}${AI_PATH}`) : null,
325
356
  savedSections: savedSections ? { collection: savedSections.slug } : null,
326
357
  themeEndpoint: theme ? theme.endpoint : null,
327
- editor: { dragMode: options.editor?.dragMode ?? 'indicator' },
358
+ // A Payload blocks field stores no classes.
359
+ classes: classes && !storage ? classes.client : null,
360
+ comments: comments ? comments.client : null,
361
+ editor: {
362
+ dragMode: options.editor?.dragMode ?? 'indicator',
363
+ dropOutlines: options.editor?.dropOutlines ?? true,
364
+ openInBuilder: options.editor?.openInBuilder ?? false,
365
+ },
328
366
  validateTypes: [...fieldRegistry.types('validate')],
329
367
  localization: localizationOf(collection.slug),
330
368
  ...(regionsOf[collection.slug] ? { regions: toJsonSafe(regionsOf[collection.slug]) } : {}),
@@ -349,22 +387,35 @@ export function websiteBuilder(options) {
349
387
  payloadBlocks: storage,
350
388
  });
351
389
  // After the layout hook, so the references follow the layout the session guard put in.
352
- return references ? addReferences(built, references) : built;
353
- }),
390
+ // Publishing a page publishes the classes it uses that have unpublished changes.
391
+ const withClasses = classes && !storage ? classes.withPublish(built, field) : built;
392
+ return references ? addReferences(withClasses, references) : withClasses;
393
+ })
394
+ .concat(classes ? [withDesignAccess(classes.collection)] : [])
395
+ .concat(comments ? [comments.collection] : []),
354
396
  // Server-only: the MCP tools read the live runtime from here, so they share the bus and lock.
355
397
  custom: {
356
398
  ...config.custom,
357
399
  [LIVE_RUNTIME_KEY]: live,
358
400
  [FIELD_REGISTRY_KEY]: fieldRegistry,
359
401
  [BUILDER_CONFIG_KEY]: serverConfig,
402
+ [CONTENT_MODE_KEY]: { canEditDesign: options.editor?.canEditDesign },
360
403
  [SITE_CSS_KEY]: { css, blocks },
404
+ ...(classes ? { [CLASSES_CONFIG_KEY]: classes.server } : {}),
361
405
  ...(templates ? { [TEMPLATES_CONFIG_KEY]: templates } : {}),
362
406
  ...(theme ? { [THEME_CONFIG_KEY]: theme } : {}),
363
407
  ...(savedSections ? { [SAVED_SECTIONS_CONFIG_KEY]: savedSections } : {}),
364
408
  ...(references ? { [REFERENCES_CONFIG_KEY]: references } : {}),
365
409
  ...(imageService ? { [AI_IMAGES_KEY]: imageService } : {}),
410
+ ...(aiSettings ? { [AI_SETTINGS_KEY]: aiSettings } : {}),
366
411
  },
367
- globals: themeOptions ? [...(config.globals ?? []), themeGlobal(themeOptions)] : config.globals,
412
+ globals: [
413
+ ...(config.globals ?? []),
414
+ // The theme is design: content mode cannot change it (nor the classes, above).
415
+ ...(themeOptions ? [withDesignAccess(themeGlobal(themeOptions), ['update'])] : []),
416
+ ...(classes ? [classes.global] : []),
417
+ ...(options.ai && aiSettingsOptions ? [aiSettingsGlobal(options.ai, aiSettingsOptions)] : []),
418
+ ],
368
419
  // A failed GraphQL or REST request ends its builder saves without a transaction (live/writeGate.ts).
369
420
  hooks: {
370
421
  ...config.hooks,
@@ -383,15 +434,19 @@ export function websiteBuilder(options) {
383
434
  // The publish check uses the same binding rules as the save hook of each collection.
384
435
  check: { blocks, bindings: bindingCheck(templatesSlug), fieldRegistry },
385
436
  }),
437
+ // The template a document renders through, for the editor's empty page.
438
+ ...(targets.length > 0 ? [templateEndpoint({ collections: liveCollections, templatesSlug, targets })] : []),
439
+ ...(classes ? classes.endpoints : []),
386
440
  ...(options.ai
387
441
  ? aiEndpoints({
388
442
  ai: options.ai,
389
443
  images: imageService ?? undefined,
444
+ settings: aiSettings,
390
445
  collections: liveCollections,
391
446
  blocks,
392
447
  sections,
393
448
  savedSections,
394
- getTokens: () => getStyleTokens(css),
449
+ getTokens: (req) => (req ? themeStyleTokens(req.payload, css) : getStyleTokens(css)),
395
450
  templates: templates ? { slug: templatesSlug, sources: templates.sources } : null,
396
451
  })
397
452
  : []),
@@ -401,8 +456,9 @@ export function websiteBuilder(options) {
401
456
  handler: async (req) => {
402
457
  if (!req.user)
403
458
  return Response.json({ error: 'Unauthorized' }, { status: 401 });
404
- const input = await getCanvasCssInput(css);
405
- return Response.json(input, { headers: { 'Cache-Control': 'private, max-age=60' } });
459
+ // With the theme's variables, so `bg-brand` works on the canvas. Not cached: a theme save changes it.
460
+ const input = await getCanvasCssInput(await withThemeVariables(req.payload, css));
461
+ return Response.json(input, { headers: { 'Cache-Control': 'private, no-cache' } });
406
462
  },
407
463
  },
408
464
  {
@@ -411,7 +467,7 @@ export function websiteBuilder(options) {
411
467
  handler: async (req) => {
412
468
  if (!req.user)
413
469
  return Response.json({ error: 'Unauthorized' }, { status: 401 });
414
- const tokens = await getStyleTokens(css);
470
+ const tokens = await themeStyleTokens(req.payload, css);
415
471
  const custom = await Promise.resolve(options.css.fontFamilies?.(req.payload)).catch(() => undefined);
416
472
  const families = { ...(await themeFamilies(req.payload)), ...custom };
417
473
  const fonts = applyFontFamilies(tokens.fonts, families);
@@ -421,6 +477,7 @@ export function websiteBuilder(options) {
421
477
  },
422
478
  ...(theme
423
479
  ? [
480
+ variableUsageEndpoint(),
424
481
  {
425
482
  // The theme as CSS and a Google Fonts URL, for ThemeLive in the canvas. Read access applies.
426
483
  path: THEME_PATH,
@@ -511,6 +568,7 @@ function addBuilder(collection, args) {
511
568
  // Payload's edit view type mixes an index signature with known keys, so a literal never fits.
512
569
  const edit = {
513
570
  ...views?.edit,
571
+ ...openInBuilderView(views?.edit, clientConfig),
514
572
  builder: {
515
573
  Component: BUILDER_REDIRECT_COMPONENT,
516
574
  path: '/builder',
@@ -580,6 +638,7 @@ function addPayloadBlocksBuilder(collection, args, storage) {
580
638
  }
581
639
  const edit = {
582
640
  ...views?.edit,
641
+ ...openInBuilderView(views?.edit, clientConfig),
583
642
  builder: { Component: BUILDER_REDIRECT_COMPONENT, path: '/builder', tab: { Component: BUILDER_TAB_COMPONENT } },
584
643
  };
585
644
  // The builder view reads its config from here: a hidden virtual field, so the blocks field stays untouched.
@@ -622,9 +681,19 @@ function addPayloadBlocksBuilder(collection, args, storage) {
622
681
  },
623
682
  };
624
683
  }
625
- /** A block definition without style controls (classes, animations, default classes). */
684
+ /**
685
+ * `editor.openInBuilder`: the default edit view becomes `DocumentEditView`, which opens a saved
686
+ * document in the builder and otherwise renders Payload's own edit view. A collection with its own
687
+ * default edit view keeps it.
688
+ */
689
+ function openInBuilderView(edit, clientConfig) {
690
+ if (!clientConfig.editor.openInBuilder || edit?.default)
691
+ return {};
692
+ return { default: { Component: DOCUMENT_EDIT_VIEW_COMPONENT } };
693
+ }
694
+ /** A block definition without style controls (classes, parts, animations, default classes). */
626
695
  function withoutStyles(def) {
627
- const { defaultClassName: _defaultClassName, ...rest } = def;
696
+ const { defaultClassName: _defaultClassName, parts: _parts, ...rest } = def;
628
697
  return { ...rest, styles: false };
629
698
  }
630
699
  /** Name of the hidden virtual field that carries the builder's config for a Payload blocks field. */
@@ -1,6 +1,30 @@
1
1
  import type { PayloadRequest } from 'payload';
2
2
  /** The admin URL of the full-screen builder for a document, e.g. `/admin/builder/pages/12`. */
3
3
  export declare function builderViewPath(adminRoute: string, collection: string, id: string | number): string;
4
+ /**
5
+ * The search parameter that keeps Payload's edit form open when `editor.openInBuilder` is on:
6
+ * `/admin/collections/pages/12?form=1`.
7
+ */
8
+ export declare const FORM_PARAM = "form";
9
+ /** The admin URL of Payload's edit view for a document. `form`: stay there with `openInBuilder` on. */
10
+ export declare function editViewPath(adminRoute: string, collection: string, id: string | number, options?: {
11
+ form?: boolean;
12
+ }): string;
13
+ /** The admin URL of a collection's list view, e.g. `/admin/collections/pages`. */
14
+ export declare function listViewPath(adminRoute: string, collection: string): string;
15
+ /**
16
+ * True when the edit view of an existing document should open the builder instead: the option is
17
+ * on, the user can save, the document is not in the trash, the view is not in a drawer, and the
18
+ * URL does not ask for the form. Pure, so it is tested without React.
19
+ */
20
+ export declare function opensInBuilder(state: {
21
+ option: boolean;
22
+ id: string | number | null | undefined;
23
+ canSave: boolean;
24
+ trashed: boolean;
25
+ inDrawer: boolean;
26
+ formParam: string | null;
27
+ }): boolean;
4
28
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
5
29
  export declare function documentPath(url: ((doc: Record<string, unknown>) => string) | undefined, doc: Record<string, unknown>): string | null;
6
30
  /** The draft preview path from the collection's `admin.livePreview.url` or `admin.preview`. */
@@ -2,6 +2,33 @@
2
2
  export function builderViewPath(adminRoute, collection, id) {
3
3
  return `${adminRoute === '/' ? '' : adminRoute}/builder/${encodeURIComponent(collection)}/${encodeURIComponent(String(id))}`;
4
4
  }
5
+ /**
6
+ * The search parameter that keeps Payload's edit form open when `editor.openInBuilder` is on:
7
+ * `/admin/collections/pages/12?form=1`.
8
+ */
9
+ export const FORM_PARAM = 'form';
10
+ /** The admin URL of Payload's edit view for a document. `form`: stay there with `openInBuilder` on. */
11
+ export function editViewPath(adminRoute, collection, id, options = {}) {
12
+ const path = `${adminRoute === '/' ? '' : adminRoute}/collections/${encodeURIComponent(collection)}/${encodeURIComponent(String(id))}`;
13
+ return options.form ? `${path}?${FORM_PARAM}=1` : path;
14
+ }
15
+ /** The admin URL of a collection's list view, e.g. `/admin/collections/pages`. */
16
+ export function listViewPath(adminRoute, collection) {
17
+ return `${adminRoute === '/' ? '' : adminRoute}/collections/${encodeURIComponent(collection)}`;
18
+ }
19
+ /**
20
+ * True when the edit view of an existing document should open the builder instead: the option is
21
+ * on, the user can save, the document is not in the trash, the view is not in a drawer, and the
22
+ * URL does not ask for the form. Pure, so it is tested without React.
23
+ */
24
+ export function opensInBuilder(state) {
25
+ const { option, id, canSave, trashed, inDrawer, formParam } = state;
26
+ if (!option || inDrawer || trashed || !canSave)
27
+ return false;
28
+ if (id === undefined || id === null || id === '')
29
+ return false;
30
+ return formParam === null;
31
+ }
5
32
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
6
33
  export function documentPath(url, doc) {
7
34
  if (!url)
@@ -1,8 +1,10 @@
1
1
  import type { BlockDefinition } from '../core/types.js';
2
2
  /**
3
- * The collection list block shows only the given collections (see `listableCollections`): its `collection` text field
4
- * (and the field list's optional one, for `$url`) becomes a select of them, so the editor offers a list and validation rejects other values.
5
- * Returns the same list when there is nothing to change.
3
+ * The collection list block shows only the given collections (see `listableCollections`): its
4
+ * `collection` text field (and the repeat's optional one, for `$url`) becomes a select of them,
5
+ * and its picked `ids` a relationship to them, so the editor offers a list and validation rejects
6
+ * other values. The same fields as `defaultBlocks({ listCollections })`. Returns the same list
7
+ * when there is nothing to change.
6
8
  */
7
9
  export declare function listCollectionsOf(blocks: BlockDefinition[], slugs: string[]): BlockDefinition[];
8
10
  /**
@@ -15,8 +17,8 @@ export declare function listableCollections(collections: Record<string, {
15
17
  /**
16
18
  * The block list as `websiteBuilder` and `builderMcpTools` use it: `listCollectionsOf` (the
17
19
  * collection list's `collection` and `ids` point to `listCollections`, the collections with a
18
- * `url` and the `listCollections` option), then `withInlineBlocks` (inline blocks may go straight into a link). Run it on the
19
- * site's own list too, so a seed's `validateLayout` agrees with the editor. Running it twice
20
- * changes nothing.
20
+ * `url`), `withInlineBlocks` (inline blocks may go straight into a link), and the `sectionRef`
21
+ * block for the saved sections collection `sectionsCollection`. Running it twice changes nothing.
22
+ * A site's own list does not need it: `validateLayout` applies `withInlineBlocks` itself.
21
23
  */
22
- export declare function prepareBlocks(blocks: BlockDefinition[], listCollections?: string[]): BlockDefinition[];
24
+ export declare function prepareBlocks(blocks: BlockDefinition[], listCollections?: string[], sectionsCollection?: string | null): BlockDefinition[];
@@ -1,9 +1,13 @@
1
+ import { SECTION_REF_BLOCK, sectionRefBlock } from '../blocks/builtins/sectionRef.js';
2
+ import { listCollectionField, pickedDocumentsField } from '../blocks/defaults.js';
1
3
  import { COLLECTION_LIST_BLOCK, REPEAT_BLOCK } from '../core/bindings.js';
2
4
  import { withInlineBlocks } from '../core/blocks.js';
3
5
  /**
4
- * The collection list block shows only the given collections (see `listableCollections`): its `collection` text field
5
- * (and the field list's optional one, for `$url`) becomes a select of them, so the editor offers a list and validation rejects other values.
6
- * Returns the same list when there is nothing to change.
6
+ * The collection list block shows only the given collections (see `listableCollections`): its
7
+ * `collection` text field (and the repeat's optional one, for `$url`) becomes a select of them,
8
+ * and its picked `ids` a relationship to them, so the editor offers a list and validation rejects
9
+ * other values. The same fields as `defaultBlocks({ listCollections })`. Returns the same list
10
+ * when there is nothing to change.
7
11
  */
8
12
  export function listCollectionsOf(blocks, slugs) {
9
13
  if (slugs.length === 0)
@@ -11,25 +15,17 @@ export function listCollectionsOf(blocks, slugs) {
11
15
  return blocks.map((block) => {
12
16
  if (block.type !== COLLECTION_LIST_BLOCK && block.type !== REPEAT_BLOCK)
13
17
  return block;
14
- // A field list's collection is optional (only for `$url`).
18
+ // A repeat's collection is optional (only for `$url`).
15
19
  const required = block.type === COLLECTION_LIST_BLOCK;
16
20
  const fields = block.fields.map((field) => {
17
21
  if (!('name' in field))
18
22
  return field;
19
23
  if (field.name === 'collection' && field.type === 'text') {
20
- return { name: 'collection', type: 'select', label: field.label ?? 'Collection', options: slugs, required, admin: { description: field.admin?.description } };
21
- }
22
- // Picked documents: a relationship to the collections the list can show.
23
- if (block.type === COLLECTION_LIST_BLOCK && field.name === 'ids' && field.type === 'text') {
24
- return {
25
- name: 'ids',
26
- type: 'relationship',
27
- label: 'Picked documents',
28
- relationTo: slugs.length === 1 ? slugs[0] : slugs,
29
- hasMany: true,
30
- admin: { description: field.admin?.description },
31
- };
24
+ const description = typeof field.admin?.description === 'string' ? field.admin.description : undefined;
25
+ return listCollectionField(slugs, { label: typeof field.label === 'string' ? field.label : 'Collection', required, description });
32
26
  }
27
+ if (block.type === COLLECTION_LIST_BLOCK && field.name === 'ids' && field.type === 'text')
28
+ return pickedDocumentsField(slugs);
33
29
  return field;
34
30
  });
35
31
  return { ...block, fields };
@@ -43,13 +39,26 @@ export function listableCollections(collections, extra = []) {
43
39
  const routed = Object.entries(collections).filter(([, o]) => o.url).map(([slug]) => slug);
44
40
  return [...new Set([...routed, ...extra])];
45
41
  }
42
+ /**
43
+ * The live saved section block (`sectionRef`) for the saved sections collection `slug`: added
44
+ * when the list has none, or pointed at `slug` when it has one. Null `slug` (saved sections off)
45
+ * changes nothing.
46
+ */
47
+ function withSectionRef(blocks, slug) {
48
+ if (!slug)
49
+ return blocks;
50
+ const index = blocks.findIndex((block) => block.type === SECTION_REF_BLOCK);
51
+ if (index === -1)
52
+ return [...blocks, sectionRefBlock(slug)];
53
+ return blocks.map((block, i) => (i === index ? { ...block, fields: sectionRefBlock(slug).fields } : block));
54
+ }
46
55
  /**
47
56
  * The block list as `websiteBuilder` and `builderMcpTools` use it: `listCollectionsOf` (the
48
57
  * collection list's `collection` and `ids` point to `listCollections`, the collections with a
49
- * `url` and the `listCollections` option), then `withInlineBlocks` (inline blocks may go straight into a link). Run it on the
50
- * site's own list too, so a seed's `validateLayout` agrees with the editor. Running it twice
51
- * changes nothing.
58
+ * `url`), `withInlineBlocks` (inline blocks may go straight into a link), and the `sectionRef`
59
+ * block for the saved sections collection `sectionsCollection`. Running it twice changes nothing.
60
+ * A site's own list does not need it: `validateLayout` applies `withInlineBlocks` itself.
52
61
  */
53
- export function prepareBlocks(blocks, listCollections = []) {
54
- return withInlineBlocks(listCollectionsOf(blocks, listCollections));
62
+ export function prepareBlocks(blocks, listCollections = [], sectionsCollection = null) {
63
+ return withInlineBlocks(withSectionRef(listCollectionsOf(blocks, listCollections), sectionsCollection));
55
64
  }
@@ -1,10 +1,12 @@
1
1
  import type { CollectionConfig, PayloadRequest } from 'payload';
2
2
  import { type FieldRunContext } from '../core/fieldHooks.js';
3
3
  import type { FieldRegistry } from '../core/fieldSemantics.js';
4
+ import { findSection } from '../core/sections.js';
5
+ import { SAVED_SECTIONS_CONFIG_KEY } from '../blocks/builtins/sectionRef.js';
4
6
  import type { Block, BlockDefinition, Layout, LocaleSettings, SectionDefinition } from '../core/types.js';
5
7
  export declare const DEFAULT_SAVED_SECTIONS_SLUG = "builder-sections";
6
- /** Server-only key in `config.custom`: `{ slug }` of the saved sections collection, for the MCP tools. */
7
- export declare const SAVED_SECTIONS_CONFIG_KEY = "websiteBuilderSavedSections";
8
+ /** Server-only key in `config.custom`: `{ slug }` of the saved sections collection. */
9
+ export { SAVED_SECTIONS_CONFIG_KEY };
8
10
  /** A saved section's id in section lists: `saved:<document id>`. */
9
11
  export declare const SAVED_SECTION_PREFIX = "saved:";
10
12
  /** At most this many saved sections are listed (newest first). */
@@ -39,13 +41,18 @@ export declare function savedSectionData(block: Block, name: string, category?:
39
41
  category: string | null;
40
42
  blocks: Block[];
41
43
  };
42
- /**
43
- * Finds a section by its id (`hero`, `saved:12`), by a saved section's document id (`12`) or by
44
- * its name (case-insensitive, the first match). Ids win over names.
45
- */
46
- export declare function findSection(sections: readonly SectionDefinition[], ref: string): SectionDefinition | undefined;
44
+ /** Finds a section by id, saved document id or name (moved to core/sections.ts). */
45
+ export { findSection };
47
46
  /** The saved sections the request's user can read, newest first. Empty when the read fails. */
48
47
  export declare function loadSavedSections(req: PayloadRequest, slug: string): Promise<SectionDefinition[]>;
48
+ /** The saved sections that `sectionRef` blocks in `blocks` point at (any depth), as text ids. */
49
+ export declare function sectionRefIds(blocks: unknown): string[];
50
+ /**
51
+ * True when the blocks of saved section `self` would contain `self`: directly, or through the
52
+ * components they contain (up to `maxDepth` levels). `load` gives the stored blocks of saved
53
+ * sections by id (missing ones are left out).
54
+ */
55
+ export declare function containsSection(self: string, blocks: unknown, load: (ids: string[]) => Promise<Map<string, unknown>>, maxDepth?: number): Promise<boolean>;
49
56
  /**
50
57
  * The builder's layout field on saved sections. Virtual: it reads `{ version: 1, blocks }` from the
51
58
  * stored `blocks`, and `syncSectionBlocks` (./sectionsBuilder.ts) writes the builder's layout back
@@ -6,13 +6,15 @@ import { hasPropHooks, runPropHooks } from '../core/fieldHooks.js';
6
6
  import { runPropValidators } from '../core/fieldValidate.js';
7
7
  import { describeLayoutErrors } from '../core/issues.js';
8
8
  import { localeSettingsOf } from '../core/locale.js';
9
+ import { findSection, withoutSectionOrigin } from '../core/sections.js';
10
+ import { SAVED_SECTIONS_CONFIG_KEY, SECTION_REF_BLOCK, sectionRefId } from '../blocks/builtins/sectionRef.js';
9
11
  import { isPlainObject, normalizeLayout } from '../core/tree.js';
10
12
  import { isLayoutWarning, validateLayout } from '../core/validate.js';
11
13
  import { splitLayoutErrors } from '../live/apply.js';
12
14
  import { fieldRegistryOf } from '../live/fieldChecks.js';
13
15
  export const DEFAULT_SAVED_SECTIONS_SLUG = 'builder-sections';
14
- /** Server-only key in `config.custom`: `{ slug }` of the saved sections collection, for the MCP tools. */
15
- export const SAVED_SECTIONS_CONFIG_KEY = 'websiteBuilderSavedSections';
16
+ /** Server-only key in `config.custom`: `{ slug }` of the saved sections collection. */
17
+ export { SAVED_SECTIONS_CONFIG_KEY };
16
18
  /** A saved section's id in section lists: `saved:<document id>`. */
17
19
  export const SAVED_SECTION_PREFIX = 'saved:';
18
20
  /** At most this many saved sections are listed (newest first). */
@@ -58,26 +60,12 @@ export function savedSectionData(block, name, category, fallbackName = 'Untitled
58
60
  return {
59
61
  name: text(name, NAME_MAX) ?? fallbackName,
60
62
  category: text(category, CATEGORY_MAX) ?? null,
61
- blocks: normalizeLayout({ version: 1, blocks: [block] }).blocks,
63
+ // A saved section has no variants: it forgets the app section it was inserted from.
64
+ blocks: normalizeLayout({ version: 1, blocks: [withoutSectionOrigin(block)] }).blocks,
62
65
  };
63
66
  }
64
- /**
65
- * Finds a section by its id (`hero`, `saved:12`), by a saved section's document id (`12`) or by
66
- * its name (case-insensitive, the first match). Ids win over names.
67
- */
68
- export function findSection(sections, ref) {
69
- const value = ref.trim();
70
- if (!value)
71
- return undefined;
72
- const byId = sections.find((s) => s.id === value);
73
- if (byId)
74
- return byId;
75
- const bySavedId = sections.find((s) => s.savedId !== undefined && String(s.savedId) === value);
76
- if (bySavedId)
77
- return bySavedId;
78
- const name = value.toLowerCase();
79
- return sections.find((s) => s.label.trim().toLowerCase() === name);
80
- }
67
+ /** Finds a section by id, saved document id or name (moved to core/sections.ts). */
68
+ export { findSection };
81
69
  /** The saved sections the request's user can read, newest first. Empty when the read fails. */
82
70
  export async function loadSavedSections(req, slug) {
83
71
  try {
@@ -96,6 +84,59 @@ export async function loadSavedSections(req, slug) {
96
84
  return [];
97
85
  }
98
86
  }
87
+ /** The saved sections that `sectionRef` blocks in `blocks` point at (any depth), as text ids. */
88
+ export function sectionRefIds(blocks) {
89
+ const ids = new Set();
90
+ const visit = (list) => {
91
+ if (!Array.isArray(list))
92
+ return;
93
+ for (const block of list) {
94
+ if (!isPlainObject(block))
95
+ continue;
96
+ if (block.type === SECTION_REF_BLOCK) {
97
+ const id = sectionRefId(isPlainObject(block.props) ? block.props.section : undefined);
98
+ if (id !== null)
99
+ ids.add(String(id));
100
+ }
101
+ if (isPlainObject(block.slots))
102
+ for (const children of Object.values(block.slots))
103
+ visit(children);
104
+ }
105
+ };
106
+ visit(blocks);
107
+ return [...ids];
108
+ }
109
+ /**
110
+ * True when the blocks of saved section `self` would contain `self`: directly, or through the
111
+ * components they contain (up to `maxDepth` levels). `load` gives the stored blocks of saved
112
+ * sections by id (missing ones are left out).
113
+ */
114
+ export async function containsSection(self, blocks, load, maxDepth = 5) {
115
+ const seen = new Set();
116
+ let level = sectionRefIds(blocks);
117
+ for (let depth = 0; depth < maxDepth && level.length > 0; depth++) {
118
+ if (level.includes(self))
119
+ return true;
120
+ level.forEach((id) => seen.add(id));
121
+ const loaded = await load(level);
122
+ level = [...new Set([...loaded.values()].flatMap(sectionRefIds))].filter((id) => !seen.has(id) || id === self);
123
+ }
124
+ return level.includes(self);
125
+ }
126
+ /** Loads the stored blocks of saved sections, with the request's access. */
127
+ function sectionBlocksLoader(req, slug) {
128
+ return async (ids) => {
129
+ const result = await req.payload.find({
130
+ collection: slug,
131
+ where: { id: { in: ids } },
132
+ depth: 0,
133
+ limit: ids.length,
134
+ pagination: false,
135
+ req,
136
+ });
137
+ return new Map(result.docs.map((doc) => [String(doc.id), doc.blocks]));
138
+ };
139
+ }
99
140
  const signedIn = ({ req }) => Boolean(req.user);
100
141
  /**
101
142
  * The builder's layout field on saved sections. Virtual: it reads `{ version: 1, blocks }` from the
@@ -198,12 +239,17 @@ export function savedSectionsCollection(args) {
198
239
  // Canonical form, like every layout (no empty slots or props), and the props' field hooks.
199
240
  beforeValidate: [sectionBlocksHook(blocks, slug)],
200
241
  },
201
- validate: (value) => {
242
+ validate: (async (value, { id, req }) => {
202
243
  if (!Array.isArray(value) || value.length === 0)
203
244
  return 'A section needs at least one block.';
204
245
  const { blocking } = splitLayoutErrors(validateLayout({ version: 1, blocks: value }, blocks));
205
- return blocking.length === 0 ? true : blocking.slice(0, 3).map((e) => e.message).join(' ');
206
- },
246
+ if (blocking.length > 0)
247
+ return blocking.slice(0, 3).map((e) => e.message).join(' ');
248
+ if (id !== undefined && (await containsSection(String(id), value, sectionBlocksLoader(req, slug)))) {
249
+ return 'A component cannot contain itself. Remove the copy of this component from its own blocks.';
250
+ }
251
+ return true;
252
+ }),
207
253
  },
208
254
  {
209
255
  // The builder's layout (see SECTION_LAYOUT_FIELD). No database column.
@@ -0,0 +1,6 @@
1
+ import type { CollectionConfig, Endpoint } from 'payload';
2
+ export declare const SECTION_USED_IN_PATH = "/:id/used-in";
3
+ /** The endpoint, for the saved sections collection `slug`. Needs a signed-in user. */
4
+ export declare function sectionUsedInEndpoint(slug: string): Endpoint;
5
+ /** The saved sections collection with the endpoint added. */
6
+ export declare function withSectionUsedIn(collection: CollectionConfig): CollectionConfig;