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
package/dist/ai/prompt.js CHANGED
@@ -4,7 +4,9 @@
4
4
  // request (layout, selection, canvas width, template sample) goes into the context message.
5
5
  import { isRichText, richTextToPlain } from '../core/bindings.js';
6
6
  import { localeLabel } from '../core/locale.js';
7
+ import { sectionVersions } from '../core/sections.js';
7
8
  import { BINDINGS_GUIDE, describeBlock, layoutGuide, outline } from '../mcp/shared.js';
9
+ import { componentProperties } from '../core/components.js';
8
10
  /** Default Tailwind palette colors (red-500 …) and keywords. The prompt lists only theme colors. */
9
11
  const PALETTE = /-\d{2,3}$/;
10
12
  const KEYWORDS = new Set(['black', 'white', 'transparent', 'current', 'inherit']);
@@ -28,7 +30,7 @@ function stylingGuide(tokens) {
28
30
  const lines = [
29
31
  'STYLING',
30
32
  "- Blocks have no built-in styles. All styling comes from each block's className: Tailwind CSS v4 utility classes. Use real Tailwind classes. Prefer the theme scale over arbitrary values like w-[37rem].",
31
- '- In an "update" operation, className REPLACES all classes. Send the full list: the current classes from the layout, changed as needed.',
33
+ '- In an "update" operation, className REPLACES all classes: send the full list, the current classes from the layout, changed as needed. To add or remove a few classes, use addClassName and removeClassName (space-separated) instead.',
32
34
  '- Mobile first: classes without a prefix apply at every width. sm:, md:, lg:, xl:, 2xl: apply from that breakpoint up.',
33
35
  '- Keep spacing, widths and type sizes consistent with the sections already on the page.',
34
36
  ];
@@ -49,6 +51,11 @@ function stylingGuide(tokens) {
49
51
  lines.push(`- Shadows (shadow-<name>): ${names(tokens.shadows)}.`);
50
52
  if (tokens.containers.length > 0)
51
53
  lines.push(`- Container widths (max-w-<name>): ${names(tokens.containers)}.`);
54
+ const variables = tokens.variables ?? [];
55
+ if (variables.length > 0) {
56
+ const list = variables.slice(0, 60).map((v) => `${v.name} (${v.type}: ${v.value}${v.darkValue ? `, dark ${v.darkValue}` : ''})`);
57
+ lines.push(`- Design variables (the site's named colors, sizes and fonts; prefer them over raw values): ${list.join(', ')}. Colors: bg-<name>, text-<name>, border-<name>. Sizes: p-<name>, m-<name>, gap-<name>, w-<name>. Fonts: font-<name>.`);
58
+ }
52
59
  const site = tokens.siteClasses ?? [];
53
60
  if (site.length > 0) {
54
61
  const list = site.slice(0, 80).map((c) => (c.label ? `${c.name} (${c.group ? `${c.group}: ` : ''}${c.label})` : c.name));
@@ -76,12 +83,16 @@ function sectionCatalog(sections, saved) {
76
83
  : 'SECTION CATALOG\nThis site has no ready-made sections. Build from blocks.';
77
84
  }
78
85
  const entries = sections.map((s) => {
79
- const head = `## ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}${s.variantOf ? ` [variant of ${s.variantOf}]` : ''}`;
86
+ const head = `## ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}`;
80
87
  const description = s.description ? `\n${s.description}` : '';
81
- return `${head}${description}\n${outline(s.blocks).join('\n')}`;
88
+ // Variants follow their section, each with its own outline.
89
+ const variants = sectionVersions(s)
90
+ .slice(1)
91
+ .map((v) => `\n### variant ${v.variant}: ${v.label}${v.description && v.description !== s.description ? `\n${v.description}` : ''}\n${outline(v.blocks).join('\n')}`);
92
+ return `${head}${description}\n${outline(s.blocks).join('\n')}${variants.join('')}`;
82
93
  });
83
94
  return [
84
- 'SECTION CATALOG. Ready-made, designed sections. Insert one with insertSection { sectionId }. The outline shows its blocks (type and start of the text). A variant ("hero/split") is another version of the section before it: pick the one that fits. listSections { full: true } returns the full JSON.' +
95
+ 'SECTION CATALOG. Ready-made, designed sections. Insert one with insertSection { sectionId }. The outline shows its blocks (type and start of the text). A "### variant" under a section is another version of it: pick the one that fits and insert it with insertSection { sectionId, variant }. listSections { full: true } returns the full JSON.' +
85
96
  (saved ? `\n${SAVED_SECTIONS_NOTE}` : ''),
86
97
  ...entries,
87
98
  ].join('\n\n');
@@ -186,7 +197,9 @@ function savedSectionsBlock(sections) {
186
197
  const lines = sections.slice(0, CONTEXT_SAVED_SECTIONS).map((s) => {
187
198
  const condensed = outline(s.blocks).map((line) => line.trim()).join(', ');
188
199
  const short = condensed.length > OUTLINE_MAX ? `${condensed.slice(0, OUTLINE_MAX)}…` : condensed;
189
- return `- ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}: ${short}`;
200
+ const propertyNames = componentProperties(s.blocks, []).map((p) => p.name);
201
+ const component = propertyNames.length > 0 ? ` [component, properties: ${propertyNames.join(', ')}; insertSection with values]` : '';
202
+ return `- ${s.id}: ${s.label}${s.category ? ` (${s.category})` : ''}${component}: ${short}`;
190
203
  });
191
204
  const more = sections.length - CONTEXT_SAVED_SECTIONS;
192
205
  if (more > 0)
@@ -230,8 +243,15 @@ export function contextText(input) {
230
243
  lines.push('Selected block: none.');
231
244
  }
232
245
  lines.push(...savedSectionsBlock(input.savedSections));
246
+ if (input.classes && input.classes.length > 0) {
247
+ const list = input.classes.slice(0, 80).map((c) => (c.label ? `${c.name} (${c.group ? `${c.group}: ` : ''}${c.label})` : c.name));
248
+ lines.push(`Editable classes (stored in the CMS; they win over a code class with the same name). Prefer them in className over rebuilding the same look from utilities: ${list.join(', ')}.`);
249
+ }
233
250
  if (input.locale)
234
251
  lines.push(...localeLines(input.locale));
252
+ if (input.contentOnly) {
253
+ lines.push('CONTENT MODE: this user may change only text, images and links (text, textarea, rich text, upload and link props). Do not add, move, delete or restyle blocks, and do not change classes, motion, visibility, bindings or other settings: such operations are refused. Inside a block with "editableItems": true you may duplicate, delete and reorder its direct children. If the user asks for a design change, say that a designer has to make it.');
254
+ }
235
255
  lines.push(`Current layout (${input.layout.blocks.length} top-level blocks):`, JSON.stringify(input.layout), '</editor_context>');
236
256
  return lines.join('\n');
237
257
  }
@@ -0,0 +1,62 @@
1
+ import { type GlobalConfig, type Payload, type PayloadRequest } from 'payload';
2
+ import type { AiAdapter, AiClientConfig, AiOptions, AiSettingsOptions } from '../types.js';
3
+ import { type AiKeyFieldName, type AiKeyStatus, type AiKeyUse } from './shared.js';
4
+ export { isSealed, openSecret, sealSecret } from './secret.js';
5
+ export { KEY_STATUS_FIELD, type AiKeyFieldCustom, type AiKeyFieldName, type AiKeyStatus, type AiKeyUse } from './shared.js';
6
+ /** Default slug of the AI settings global. */
7
+ export declare const DEFAULT_AI_SETTINGS_SLUG = "builder-ai-settings";
8
+ /** Key under `config.custom` where the plugin stores the AiSettingsRuntime. */
9
+ export declare const AI_SETTINGS_KEY = "websiteBuilderAiSettings";
10
+ /** One key field and the adapters that use it. */
11
+ export type AiKeySlot = {
12
+ name: AiKeyFieldName;
13
+ label: string;
14
+ uses: AiKeyUse[];
15
+ /** The env var of the code key, e.g. "OPENROUTER_API_KEY". */
16
+ keyEnv: string | null;
17
+ keyUrl: string | null;
18
+ /** The adapter options have no key either: without a key here the adapter does not work. */
19
+ missingKey: boolean;
20
+ };
21
+ /** Default access to the settings: a signed-in user of the admin user collection. */
22
+ export declare function defaultAiSettingsAccess({ req }: {
23
+ req: PayloadRequest;
24
+ }): boolean;
25
+ /**
26
+ * The key fields in use. When the chat and image adapters read the same env var (for example both
27
+ * use OPENROUTER_API_KEY), they share one field: `chatApiKey`.
28
+ */
29
+ export declare function aiKeySlots(ai: AiOptions): AiKeySlot[];
30
+ /** The status of one stored value. */
31
+ export declare function keyStatusOf(stored: unknown, secret: string): AiKeyStatus;
32
+ /**
33
+ * What to store for one field. A non-empty string replaces the key, `null` clears it, anything
34
+ * else (left out, empty) keeps the stored value. Throws a readable message for a bad key.
35
+ */
36
+ export declare function nextStoredKey(incoming: unknown, stored: unknown, secret: string): string | null;
37
+ /** The AI settings global. Both key fields always exist; the unused one is hidden. */
38
+ export declare function aiSettingsGlobal(ai: AiOptions, options?: AiSettingsOptions): GlobalConfig;
39
+ /** The AI settings at runtime, for the endpoints, the image service and the builder view. */
40
+ export type AiSettingsRuntime = {
41
+ slug: string;
42
+ slots: AiKeySlot[];
43
+ /** The admin's key for one use, decrypted. Undefined when none is set or it does not decrypt (logged). */
44
+ keyFor(payload: Payload, use: AiKeyUse): Promise<string | undefined>;
45
+ /** The settings page in the admin, or null when this user may not open it. */
46
+ urlFor(req: PayloadRequest): Promise<string | null>;
47
+ /** `AiClientConfig` with the readiness of this moment (keys in the settings count). */
48
+ clientConfig(req: PayloadRequest): Promise<AiClientConfig>;
49
+ };
50
+ /** The runtime of the AI settings global. `endpoint`: the AI endpoint prefix, e.g. "/api/builder/ai". */
51
+ export declare function aiSettingsRuntime(ai: AiOptions, options: AiSettingsOptions, endpoint: string): AiSettingsRuntime;
52
+ /** The plugin's AI settings runtime, or null when settings are off. */
53
+ export declare function aiSettingsOf(payload: {
54
+ config: {
55
+ custom?: Record<string, unknown>;
56
+ };
57
+ }): AiSettingsRuntime | null;
58
+ /**
59
+ * The chat adapter for one request: it gets the key from the settings (when there is one), and an
60
+ * auth error says that the settings can take a key. Readiness follows the key.
61
+ */
62
+ export declare function withSettingsKey(adapter: AiAdapter, key: string | undefined, hint: string | null): AiAdapter;
@@ -0,0 +1,264 @@
1
+ // The "AI settings" global: an admin pastes API keys for the assistant and image generation
2
+ // without a deploy. Server only.
3
+ //
4
+ // - A key there wins over the key in the adapter options (env). Not set: the options' key.
5
+ // - Keys are stored encrypted (./secret.ts). Reads through REST and the Local API never return
6
+ // them: the global's afterRead hook removes them and adds `keyStatus` ("set, ends in …4f2a").
7
+ // The global has no GraphQL schema.
8
+ // - The endpoints read and decrypt the key at request time (`keyFor`), straight from the database
9
+ // adapter, so a new key works on the next request without a restart.
10
+ // - The DB schema stays the same for any adapter: two text columns, `chatApiKey` and
11
+ // `imageApiKey`. The admin shows the ones the configured adapters use.
12
+ import { ValidationError } from 'payload';
13
+ import { adapterReady, aiClientConfig } from '../config.js';
14
+ import { isSealed, openSecret, sealSecret } from './secret.js';
15
+ import { KEY_STATUS_FIELD } from './shared.js';
16
+ export { isSealed, openSecret, sealSecret } from './secret.js';
17
+ export { KEY_STATUS_FIELD } from './shared.js';
18
+ /** Default slug of the AI settings global. */
19
+ export const DEFAULT_AI_SETTINGS_SLUG = 'builder-ai-settings';
20
+ /** Key under `config.custom` where the plugin stores the AiSettingsRuntime. */
21
+ export const AI_SETTINGS_KEY = 'websiteBuilderAiSettings';
22
+ const KEY_FIELD_COMPONENT = 'payload-canvas/client#AiKeyField';
23
+ /** Longest key the settings accept. */
24
+ const MAX_KEY_LENGTH = 2000;
25
+ /** Default access to the settings: a signed-in user of the admin user collection. */
26
+ export function defaultAiSettingsAccess({ req }) {
27
+ const user = req.user;
28
+ if (!user)
29
+ return false;
30
+ const adminUser = req.payload?.config?.admin?.user;
31
+ return !adminUser || !user.collection || user.collection === adminUser;
32
+ }
33
+ const acceptsKey = (adapter) => (adapter?.acceptsApiKey ? adapter : null);
34
+ /**
35
+ * The key fields in use. When the chat and image adapters read the same env var (for example both
36
+ * use OPENROUTER_API_KEY), they share one field: `chatApiKey`.
37
+ */
38
+ export function aiKeySlots(ai) {
39
+ const chat = acceptsKey(ai.adapter);
40
+ const images = acceptsKey(ai.images);
41
+ const shared = Boolean(chat && images && chat.keyEnv && chat.keyEnv === images.keyEnv);
42
+ const slots = [];
43
+ if (chat) {
44
+ slots.push({
45
+ name: 'chatApiKey',
46
+ label: shared ? `${chat.label} API key` : `${chat.label} API key (assistant)`,
47
+ uses: shared ? ['chat', 'images'] : ['chat'],
48
+ keyEnv: chat.keyEnv ?? null,
49
+ keyUrl: chat.keyUrl ?? null,
50
+ missingKey: Boolean(chat.missingKey) || (shared && Boolean(images?.missingKey)),
51
+ });
52
+ }
53
+ if (images && !shared) {
54
+ slots.push({
55
+ name: 'imageApiKey',
56
+ label: `${images.label} API key (images)`,
57
+ uses: ['images'],
58
+ keyEnv: images.keyEnv ?? null,
59
+ keyUrl: images.keyUrl ?? null,
60
+ missingKey: Boolean(images.missingKey),
61
+ });
62
+ }
63
+ return slots;
64
+ }
65
+ const ALL_FIELDS = ['chatApiKey', 'imageApiKey'];
66
+ /** The status of one stored value. */
67
+ export function keyStatusOf(stored, secret) {
68
+ if (typeof stored !== 'string' || !stored)
69
+ return { state: 'unset' };
70
+ const key = openSecret(stored, secret);
71
+ if (key === null)
72
+ return { state: 'unreadable' };
73
+ return { state: 'set', last4: key.length >= 12 ? key.slice(-4) : null };
74
+ }
75
+ /**
76
+ * What to store for one field. A non-empty string replaces the key, `null` clears it, anything
77
+ * else (left out, empty) keeps the stored value. Throws a readable message for a bad key.
78
+ */
79
+ export function nextStoredKey(incoming, stored, secret) {
80
+ const keep = typeof stored === 'string' && stored ? stored : null;
81
+ if (incoming === null)
82
+ return null;
83
+ if (typeof incoming !== 'string' || !incoming.trim())
84
+ return keep;
85
+ const value = incoming.trim();
86
+ // A value that is already encrypted with this secret (a copy of the raw row) stays as it is.
87
+ if (isSealed(value) && openSecret(value, secret) !== null)
88
+ return value;
89
+ if (value.length > MAX_KEY_LENGTH)
90
+ throw new Error(`The API key is too long (more than ${MAX_KEY_LENGTH} characters).`);
91
+ // Spaces and control characters would break the request header.
92
+ if (/\s/.test(value) || [...value].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127))
93
+ throw new Error('An API key has no spaces or line breaks. Paste only the key.');
94
+ return sealSecret(value, secret);
95
+ }
96
+ /** Encrypts new keys, keeps the others. Runs on every write (admin, REST, Local API). */
97
+ const writeKeys = ({ data, originalDoc, req, global }) => {
98
+ const next = { ...data };
99
+ delete next[KEY_STATUS_FIELD];
100
+ const errors = [];
101
+ for (const name of ALL_FIELDS) {
102
+ try {
103
+ next[name] = nextStoredKey(data?.[name], originalDoc?.[name], req.payload.secret);
104
+ }
105
+ catch (error) {
106
+ errors.push({ path: name, message: error instanceof Error ? error.message : String(error) });
107
+ }
108
+ }
109
+ if (errors.length > 0)
110
+ throw new ValidationError({ global: global.slug, errors, req });
111
+ return next;
112
+ };
113
+ /** Removes the stored keys from every read and adds their status. */
114
+ const hideKeys = ({ doc, req }) => {
115
+ const out = { ...doc };
116
+ const status = {};
117
+ for (const name of ALL_FIELDS) {
118
+ status[name] = keyStatusOf(out[name], req.payload.secret);
119
+ delete out[name];
120
+ }
121
+ out[KEY_STATUS_FIELD] = status;
122
+ return out;
123
+ };
124
+ function slotDescription(slot) {
125
+ const what = slot.uses.length === 2 ? 'the AI assistant and image generation' : slot.uses[0] === 'chat' ? 'the AI assistant' : 'image generation';
126
+ const env = slot.keyEnv ? ` It wins over ${slot.keyEnv} in the server environment.` : '';
127
+ return `Used for ${what}.${env} Saved encrypted. Nobody can read it back here.`;
128
+ }
129
+ /** The AI settings global. Both key fields always exist; the unused one is hidden. */
130
+ export function aiSettingsGlobal(ai, options = {}) {
131
+ const slug = options.slug ?? DEFAULT_AI_SETTINGS_SLUG;
132
+ const access = options.access ?? defaultAiSettingsAccess;
133
+ const slots = aiKeySlots(ai);
134
+ const field = (name, fallbackLabel) => {
135
+ const slot = slots.find((s) => s.name === name);
136
+ return {
137
+ name,
138
+ type: 'text',
139
+ label: slot?.label ?? fallbackLabel,
140
+ admin: {
141
+ hidden: !slot,
142
+ description: slot ? slotDescription(slot) : undefined,
143
+ components: { Field: KEY_FIELD_COMPONENT },
144
+ custom: {
145
+ aiKey: { keyEnv: slot?.keyEnv ?? null, keyUrl: slot?.keyUrl ?? null, missingKey: slot?.missingKey ?? false, uses: slot?.uses ?? [] },
146
+ },
147
+ },
148
+ };
149
+ };
150
+ return {
151
+ slug,
152
+ label: 'AI settings',
153
+ // Keys never go through GraphQL.
154
+ graphQL: false,
155
+ access: { read: access, update: access },
156
+ admin: {
157
+ description: slots.length > 0
158
+ ? 'API keys for the AI features. A key set here wins over the key in the server environment.'
159
+ : 'The configured AI adapters take no API key from here.',
160
+ },
161
+ hooks: { beforeChange: [writeKeys], afterRead: [hideKeys] },
162
+ fields: [
163
+ field('chatApiKey', 'Assistant API key'),
164
+ field('imageApiKey', 'Image API key'),
165
+ { name: KEY_STATUS_FIELD, type: 'json', virtual: true, admin: { hidden: true, readOnly: true } },
166
+ ],
167
+ };
168
+ }
169
+ /** The decrypted key of one field. Undefined when none is stored, or it does not decrypt (logged). */
170
+ function decrypt(payload, row, slot) {
171
+ if (!slot)
172
+ return undefined;
173
+ const stored = row?.[slot.name];
174
+ if (typeof stored !== 'string' || !stored)
175
+ return undefined;
176
+ const key = openSecret(stored, payload.secret);
177
+ if (key === null) {
178
+ payload.logger.warn(`website builder: the ${slot.label} in the AI settings cannot be decrypted (the Payload secret changed, or the value is damaged). It counts as not set. Paste the key again.`);
179
+ return undefined;
180
+ }
181
+ return key;
182
+ }
183
+ /** The runtime of the AI settings global. `endpoint`: the AI endpoint prefix, e.g. "/api/builder/ai". */
184
+ export function aiSettingsRuntime(ai, options, endpoint) {
185
+ const slug = options.slug ?? DEFAULT_AI_SETTINGS_SLUG;
186
+ const access = options.access ?? defaultAiSettingsAccess;
187
+ const slots = aiKeySlots(ai);
188
+ const slotFor = (use) => slots.find((slot) => slot.uses.includes(use)) ?? null;
189
+ const readRow = async (payload) => {
190
+ try {
191
+ // The database adapter: no hooks, so the encrypted values are there.
192
+ return (await payload.db.findGlobal({ slug })) ?? null;
193
+ }
194
+ catch (error) {
195
+ payload.logger.warn({ err: error }, `website builder: could not read the AI settings ("${slug}"). Using the keys from the server environment.`);
196
+ return null;
197
+ }
198
+ };
199
+ const keyFor = async (payload, use) => {
200
+ const slot = slotFor(use);
201
+ if (!slot)
202
+ return undefined;
203
+ return decrypt(payload, await readRow(payload), slot);
204
+ };
205
+ const urlFor = async (req) => {
206
+ if (slots.length === 0 || !req.user)
207
+ return null;
208
+ let allowed = false;
209
+ try {
210
+ allowed = Boolean(await access({ req }));
211
+ }
212
+ catch {
213
+ allowed = false;
214
+ }
215
+ if (!allowed)
216
+ return null;
217
+ const admin = req.payload.config.routes?.admin ?? '/admin';
218
+ return `${admin === '/' ? '' : admin}/globals/${encodeURIComponent(slug)}`;
219
+ };
220
+ return {
221
+ slug,
222
+ slots,
223
+ keyFor,
224
+ urlFor,
225
+ async clientConfig(req) {
226
+ const row = slots.length > 0 ? await readRow(req.payload) : null;
227
+ const state = {
228
+ keys: { chat: Boolean(decrypt(req.payload, row, slotFor('chat'))), images: Boolean(decrypt(req.payload, row, slotFor('images'))) },
229
+ settingsUrl: await urlFor(req),
230
+ };
231
+ return aiClientConfig(ai, endpoint, state);
232
+ },
233
+ };
234
+ }
235
+ /** The plugin's AI settings runtime, or null when settings are off. */
236
+ export function aiSettingsOf(payload) {
237
+ return payload.config.custom?.[AI_SETTINGS_KEY] ?? null;
238
+ }
239
+ /**
240
+ * The chat adapter for one request: it gets the key from the settings (when there is one), and an
241
+ * auth error says that the settings can take a key. Readiness follows the key.
242
+ */
243
+ export function withSettingsKey(adapter, key, hint) {
244
+ const useKey = Boolean(key && adapter.acceptsApiKey);
245
+ const addHint = Boolean(hint && adapter.acceptsApiKey && !useKey);
246
+ if (!useKey && !addHint)
247
+ return adapter;
248
+ return {
249
+ name: adapter.name,
250
+ label: adapter.label,
251
+ model: adapter.model,
252
+ ready: adapterReady(adapter, useKey ? key : undefined),
253
+ setupProblem: adapter.setupProblem,
254
+ keyEnv: adapter.keyEnv,
255
+ keyUrl: adapter.keyUrl,
256
+ acceptsApiKey: adapter.acceptsApiKey,
257
+ missingKey: adapter.missingKey,
258
+ async *stream(request) {
259
+ for await (const event of adapter.stream(useKey ? { ...request, apiKey: key } : request)) {
260
+ yield addHint && event.type === 'error' && event.code === 'auth' ? { ...event, message: `${event.message} ${hint}` } : event;
261
+ }
262
+ },
263
+ };
264
+ }
@@ -0,0 +1,11 @@
1
+ /** Version prefix of a stored value. A new format gets a new prefix. */
2
+ export declare const SECRET_PREFIX = "v1:";
3
+ /** True when the value has the stored format (it may still fail to decrypt). */
4
+ export declare function isSealed(value: unknown): value is string;
5
+ /** Encrypts a key for storage. Throws when the secret is empty. */
6
+ export declare function sealSecret(plain: string, secret: string): string;
7
+ /**
8
+ * Decrypts a stored key. Null when the value is not in the stored format, was changed, or was
9
+ * encrypted with another secret. Never throws.
10
+ */
11
+ export declare function openSecret(value: unknown, secret: string): string | null;
@@ -0,0 +1,46 @@
1
+ // Encryption of the API keys in the AI settings global. Server only.
2
+ //
3
+ // AES-256-GCM. The 32-byte key comes from Payload's secret through HKDF-SHA256 with a fixed label,
4
+ // so the stored keys stay readable as long as the secret does not change. Every value gets a
5
+ // random 12-byte IV. The stored string is "v1:" plus base64url(iv + auth tag + ciphertext).
6
+ import { createCipheriv, createDecipheriv, hkdfSync, randomBytes } from 'node:crypto';
7
+ /** Version prefix of a stored value. A new format gets a new prefix. */
8
+ export const SECRET_PREFIX = 'v1:';
9
+ const IV_BYTES = 12;
10
+ const TAG_BYTES = 16;
11
+ const LABEL = 'payload-canvas ai-settings api-key v1';
12
+ function keyOf(secret) {
13
+ if (!secret)
14
+ throw new Error('Payload has no secret, so the AI settings cannot encrypt API keys. Set `secret` in the Payload config.');
15
+ return Buffer.from(hkdfSync('sha256', secret, 'payload-canvas', LABEL, 32));
16
+ }
17
+ /** True when the value has the stored format (it may still fail to decrypt). */
18
+ export function isSealed(value) {
19
+ return typeof value === 'string' && value.startsWith(SECRET_PREFIX);
20
+ }
21
+ /** Encrypts a key for storage. Throws when the secret is empty. */
22
+ export function sealSecret(plain, secret) {
23
+ const iv = randomBytes(IV_BYTES);
24
+ const cipher = createCipheriv('aes-256-gcm', keyOf(secret), iv);
25
+ const ciphertext = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
26
+ return SECRET_PREFIX + Buffer.concat([iv, cipher.getAuthTag(), ciphertext]).toString('base64url');
27
+ }
28
+ /**
29
+ * Decrypts a stored key. Null when the value is not in the stored format, was changed, or was
30
+ * encrypted with another secret. Never throws.
31
+ */
32
+ export function openSecret(value, secret) {
33
+ if (!isSealed(value) || !secret)
34
+ return null;
35
+ try {
36
+ const bytes = Buffer.from(value.slice(SECRET_PREFIX.length), 'base64url');
37
+ if (bytes.length <= IV_BYTES + TAG_BYTES)
38
+ return null;
39
+ const decipher = createDecipheriv('aes-256-gcm', keyOf(secret), bytes.subarray(0, IV_BYTES));
40
+ decipher.setAuthTag(bytes.subarray(IV_BYTES, IV_BYTES + TAG_BYTES));
41
+ return Buffer.concat([decipher.update(bytes.subarray(IV_BYTES + TAG_BYTES)), decipher.final()]).toString('utf8');
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
@@ -0,0 +1,22 @@
1
+ /** The virtual field with each key's status. Read only, never stored. */
2
+ export declare const KEY_STATUS_FIELD = "keyStatus";
3
+ /** What a key is for. */
4
+ export type AiKeyUse = 'chat' | 'images';
5
+ /** The two key fields. Both always exist, so the DB schema does not change with the adapters. */
6
+ export type AiKeyFieldName = 'chatApiKey' | 'imageApiKey';
7
+ /** A key's status, as reads return it in `keyStatus`. `unreadable`: stored, but it does not decrypt (another secret). */
8
+ export type AiKeyStatus = {
9
+ state: 'set';
10
+ last4: string | null;
11
+ } | {
12
+ state: 'unset';
13
+ } | {
14
+ state: 'unreadable';
15
+ };
16
+ /** The `admin.custom.aiKey` of a key field, for the field component. */
17
+ export type AiKeyFieldCustom = {
18
+ keyEnv: string | null;
19
+ keyUrl: string | null;
20
+ missingKey: boolean;
21
+ uses: AiKeyUse[];
22
+ };
@@ -0,0 +1,3 @@
1
+ // Names and types of the AI settings global that the admin field component also needs. Client-safe.
2
+ /** The virtual field with each key's status. Read only, never stored. */
3
+ export const KEY_STATUS_FIELD = 'keyStatus';
@@ -58,9 +58,12 @@ export declare class Workspace {
58
58
  layout: Layout;
59
59
  /** The locale the assistant reads and writes. Null without localization. */
60
60
  readonly locale: string | null;
61
+ /** The user has no design rights: only content changes apply (core/contentMode.ts). */
62
+ readonly contentOnly: boolean;
61
63
  constructor(layout: Layout, blocks: BlockDefinition[], options?: {
62
64
  localization?: LocaleSettings | null;
63
65
  locale?: string | null;
66
+ contentOnly?: boolean;
64
67
  });
65
68
  /** The layout as the assistant sees it: the locale's values with fallback (the stored layout without localization). */
66
69
  get view(): Layout;