payload-canvas 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/README.md +625 -153
  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 -2
  234. package/dist/blocks/index.js +1 -2
  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
@@ -298,60 +298,6 @@
298
298
  padding: 0 0 10px;
299
299
  }
300
300
 
301
- // Site classes: the site's own @utility classes as toggle buttons, by group.
302
- .builder-styles__presets {
303
- display: flex;
304
- flex-direction: column;
305
- gap: 4px;
306
- min-width: 0;
307
- margin: 0;
308
- padding: 0;
309
- border: 0;
310
- }
311
-
312
- .builder-styles__presets-title {
313
- margin: 4px 0 0;
314
- padding: 0;
315
- color: var(--theme-elevation-500);
316
- font-size: var(--be-text-s, 11px);
317
- }
318
-
319
- .builder-styles__presets-list {
320
- display: flex;
321
- flex-wrap: wrap;
322
- gap: 4px;
323
- }
324
-
325
- .builder-styles__preset {
326
- display: inline-flex;
327
- align-items: baseline;
328
- gap: 6px;
329
- min-height: var(--bs-h);
330
- padding: 2px 8px;
331
- border: 1px solid var(--bs-border);
332
- border-radius: var(--style-radius-s, 4px);
333
- background: var(--theme-elevation-50);
334
- color: var(--theme-text);
335
- font: inherit;
336
- text-align: left;
337
- cursor: pointer;
338
-
339
- &:hover {
340
- border-color: var(--theme-elevation-300);
341
- }
342
-
343
- &[aria-pressed='true'] {
344
- border-color: var(--theme-elevation-800);
345
- background: var(--theme-elevation-800);
346
- color: var(--theme-elevation-0);
347
- }
348
- }
349
-
350
- .builder-styles__preset-name {
351
- opacity: 0.7;
352
- font-size: var(--be-text-s, 11px);
353
- }
354
-
355
301
  // Rows in a sub-section keep the panel's columns; only the label text steps in.
356
302
  .builder-styles__sub-body {
357
303
  display: flex;
@@ -905,6 +851,31 @@
905
851
  }
906
852
  }
907
853
 
854
+ // A heading over a run of site classes of one group.
855
+ .builder-styles__suggest-group {
856
+ padding: 6px 6px 2px;
857
+ color: var(--bs-muted);
858
+ font-size: var(--be-text-s, 11px);
859
+
860
+ &:not(:first-child) {
861
+ margin-top: 2px;
862
+ border-top: 1px solid var(--bs-border);
863
+ }
864
+ }
865
+
866
+ // A site class: its label, with the class name small after it.
867
+ .builder-styles__suggest-label {
868
+ display: inline-flex;
869
+ align-items: baseline;
870
+ gap: 6px;
871
+ min-width: 0;
872
+ }
873
+
874
+ .builder-styles__suggest-name {
875
+ color: var(--bs-muted);
876
+ font-size: var(--be-text-s, 11px);
877
+ }
878
+
908
879
  .builder-styles__suggest-hint {
909
880
  color: var(--bs-muted);
910
881
  font-variant-numeric: tabular-nums;
@@ -1117,16 +1088,9 @@
1117
1088
  }
1118
1089
 
1119
1090
  // -------------------------------------------------------------------------
1120
- // Raw classes
1091
+ // Small labels, classes as text ("Edit as text") and the custom CSS box
1121
1092
  // -------------------------------------------------------------------------
1122
1093
 
1123
- .builder-styles__raw {
1124
- display: flex;
1125
- flex-direction: column;
1126
- gap: 4px;
1127
- padding: 10px 0 4px;
1128
- }
1129
-
1130
1094
  .builder-styles__raw-label {
1131
1095
  color: var(--bs-muted);
1132
1096
  font-size: var(--be-text-s);
@@ -1148,48 +1112,6 @@
1148
1112
  resize: vertical;
1149
1113
  }
1150
1114
 
1151
- .builder-styles__others {
1152
- display: flex;
1153
- flex-direction: column;
1154
- gap: 4px;
1155
- margin-top: 6px;
1156
- }
1157
-
1158
- .builder-styles__chips {
1159
- display: flex;
1160
- flex-wrap: wrap;
1161
- gap: 4px;
1162
- margin: 0;
1163
- padding: 0;
1164
- list-style: none;
1165
- }
1166
-
1167
- .builder-styles__class-chip {
1168
- position: relative;
1169
- display: inline-flex;
1170
- align-items: center;
1171
- gap: 2px;
1172
- padding: 1px 2px 1px 6px;
1173
- border-radius: 3px;
1174
- background: var(--theme-elevation-100);
1175
-
1176
- .builder-styles__reset {
1177
- width: 16px;
1178
- height: 16px;
1179
- }
1180
- }
1181
-
1182
- // Not in the theme's class list: probably a typo.
1183
- .builder-styles__class-chip--unknown {
1184
- outline: 1px dashed var(--theme-warning-500, #b7791f);
1185
- outline-offset: -1px;
1186
- background: color-mix(in srgb, var(--theme-warning-500, #b7791f) 12%, transparent);
1187
-
1188
- code {
1189
- text-decoration: wavy underline var(--theme-warning-500, #b7791f);
1190
- }
1191
- }
1192
-
1193
1115
  .builder-styles__visually-hidden {
1194
1116
  position: absolute;
1195
1117
  width: 1px;
@@ -0,0 +1,22 @@
1
+ import type { SiteClass, StyleTokens } from '../../../core/types.js';
2
+ import type { Suggestion } from './popover.js';
3
+ /** The site classes by group, in CSS order. Classes without a group go under "Other" (or no group when no class has one). */
4
+ export declare function groupSiteClasses(list: readonly SiteClass[]): Array<{
5
+ group: string | null;
6
+ classes: SiteClass[];
7
+ }>;
8
+ /**
9
+ * The suggestions for the word being typed (without its variant prefix). Site classes come first:
10
+ * matched on the class name or the label, grouped by their `@canvas` group in CSS order, each with
11
+ * its label. Tailwind's utilities follow. With an empty query: only the site classes, without the
12
+ * ones in `exclude` (the block has them already).
13
+ */
14
+ export declare function classSuggestions(tokens: StyleTokens, query: string, limit?: number, exclude?: ReadonlySet<string>): Suggestion[];
15
+ /**
16
+ * The site class a class on the block uses, and the variant prefix in front of it: "md:btn-primary"
17
+ * gives `{ prefix: 'md:', site: btn-primary }`. Null for any other class.
18
+ */
19
+ export declare function siteClassOf(name: string, list: readonly SiteClass[] | undefined): {
20
+ prefix: string;
21
+ site: SiteClass;
22
+ } | null;
@@ -0,0 +1,77 @@
1
+ // Suggestions of the Classes box: the site's own `@utility` classes (StyleTokens.siteClasses) with
2
+ // their labels, then Tailwind's utilities. Pure, so it is tested without React.
3
+ /** The site classes by group, in CSS order. Classes without a group go under "Other" (or no group when no class has one). */
4
+ export function groupSiteClasses(list) {
5
+ const groups = new Map();
6
+ const anyGroup = list.some((c) => c.group);
7
+ for (const item of list) {
8
+ const key = item.group ?? (anyGroup ? 'Other' : null);
9
+ groups.set(key, [...(groups.get(key) ?? []), item]);
10
+ }
11
+ return [...groups].map(([group, classes]) => ({ group, classes }));
12
+ }
13
+ /** How well a site class matches the query: 0 = name or label starts with it, 1 = contains it, -1 = no match. */
14
+ function siteMatch(item, q) {
15
+ const texts = [item.name.toLowerCase(), item.label?.toLowerCase() ?? ''];
16
+ if (texts.some((text) => text.startsWith(q) || text.split(/\s+/).some((word) => word.startsWith(q))))
17
+ return 0;
18
+ return texts.some((text) => text.includes(q)) ? 1 : -1;
19
+ }
20
+ const tailwindCache = new WeakMap();
21
+ /** Tailwind's utilities without the site classes (those come first, with their labels). */
22
+ function tailwindSuggestions(tokens) {
23
+ let list = tailwindCache.get(tokens);
24
+ if (list)
25
+ return list;
26
+ const site = new Set((tokens.siteClasses ?? []).map((c) => c.name));
27
+ list = tokens.classList.filter((value) => !site.has(value)).map((value) => ({ value }));
28
+ tailwindCache.set(tokens, list);
29
+ return list;
30
+ }
31
+ /** Prefix matches first, then substring matches. */
32
+ function filterTailwind(items, q, limit) {
33
+ const starts = [];
34
+ const contains = [];
35
+ for (const item of items) {
36
+ if (starts.length >= limit)
37
+ break;
38
+ if (item.value.startsWith(q))
39
+ starts.push(item);
40
+ else if (item.value.includes(q))
41
+ contains.push(item);
42
+ }
43
+ return [...starts, ...contains].slice(0, limit);
44
+ }
45
+ /**
46
+ * The suggestions for the word being typed (without its variant prefix). Site classes come first:
47
+ * matched on the class name or the label, grouped by their `@canvas` group in CSS order, each with
48
+ * its label. Tailwind's utilities follow. With an empty query: only the site classes, without the
49
+ * ones in `exclude` (the block has them already).
50
+ */
51
+ export function classSuggestions(tokens, query, limit = 60, exclude = new Set()) {
52
+ const q = query.trim().toLowerCase();
53
+ const site = tokens.siteClasses ?? [];
54
+ const matched = q ? site.filter((item) => siteMatch(item, q) >= 0) : site.filter((item) => !exclude.has(item.name));
55
+ // Groups stay together; inside the list, groups with a prefix match go first.
56
+ const groups = groupSiteClasses(matched).map(({ group, classes }) => ({
57
+ group,
58
+ classes: q ? classes.toSorted((a, b) => siteMatch(a, q) - siteMatch(b, q)) : classes,
59
+ }));
60
+ const ordered = q ? groups.toSorted((a, b) => siteMatch(a.classes[0], q) - siteMatch(b.classes[0], q)) : groups;
61
+ const own = ordered.flatMap(({ group, classes }) => classes.map((item) => ({ value: item.name, ...(item.label ? { label: item.label } : {}), group: group ?? 'Site classes' })));
62
+ if (!q)
63
+ return own;
64
+ return [...own, ...filterTailwind(tailwindSuggestions(tokens), q, Math.max(0, limit - own.length))];
65
+ }
66
+ /**
67
+ * The site class a class on the block uses, and the variant prefix in front of it: "md:btn-primary"
68
+ * gives `{ prefix: 'md:', site: btn-primary }`. Null for any other class.
69
+ */
70
+ export function siteClassOf(name, list) {
71
+ if (!list?.length)
72
+ return null;
73
+ const prefix = /^(?:[^\s:[\]]+:|!)*/.exec(name)?.[0] ?? '';
74
+ const bare = name.slice(prefix.length).replace(/!$/, '');
75
+ const site = list.find((item) => item.name === bare);
76
+ return site ? { prefix, site } : null;
77
+ }
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
  // Style tokens for the Styles panel. Fetched once per editor session and cached in module scope.
3
3
  import { useSyncExternalStore } from 'react';
4
+ import { THEME_CHANNEL } from '../../../theme/config.js';
4
5
  const entries = new Map();
5
6
  const listeners = new Set();
6
7
  const notify = () => {
@@ -20,10 +21,23 @@ function load(endpoint) {
20
21
  .finally(notify);
21
22
  }
22
23
  const EMPTY_ENTRY = { tokens: null, error: null, loading: true };
24
+ let themeChannel = null;
25
+ /** A theme save (any tab) can add, rename or remove design variables: load the tokens again. */
26
+ function listenToTheme() {
27
+ if (themeChannel || typeof BroadcastChannel === 'undefined')
28
+ return;
29
+ themeChannel = new BroadcastChannel(THEME_CHANNEL);
30
+ themeChannel.addEventListener('message', () => {
31
+ for (const endpoint of entries.keys())
32
+ load(endpoint);
33
+ notify();
34
+ });
35
+ }
23
36
  /** Tokens from `endpoint`, or `null` while they load or after an error. */
24
37
  export function useStyleTokens(endpoint) {
25
38
  return useSyncExternalStore((listener) => {
26
39
  listeners.add(listener);
40
+ listenToTheme();
27
41
  if (!entries.has(endpoint))
28
42
  load(endpoint);
29
43
  return () => {
@@ -1,17 +1,22 @@
1
1
  'use client';
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // Data binding in the block inspector: the "bind" button next to bindable props, the bound chip
4
- // with a live sample value, the Field block's field picker and the collection list's inputs.
5
- import { FieldLabel, SelectInput, TextInput, useConfig } from '@payloadcms/ui';
4
+ // with a live sample value and a format picker, the Field block's field picker and the collection
5
+ // list's inputs.
6
+ import { FieldLabel, SelectInput, useConfig } from '@payloadcms/ui';
6
7
  import { createContext, use, useCallback, useState } from 'react';
7
8
  import { isLinkField } from '../../../blocks/link.js';
8
- import { bindingValue, COLLECTION_LIST_BLOCK, getBlockDefinition, isBindingExpression, itemSources, listItemContext, propField, repeatAncestors, repeatRowContext, repeatRows, } from '../../../core/index.js';
9
+ import { BINDING_FORMATTER_INFO, bindingFromParts, bindingParts, bindingValue, COLLECTION_LIST_BLOCK, getBlockDefinition, itemSources, listItemContext, propField, repeatAncestors, repeatRowContext, repeatRows, } from '../../../core/index.js';
9
10
  import { Icon } from '../icons.js';
10
11
  import { useRuntime } from '../runtime.js';
11
12
  import { useEditor } from '../store.js';
12
13
  import { usePopover } from '../styles/popover.js';
14
+ import { Select } from '../ui/Select.js';
13
15
  import { useValue } from '../valueStore.js';
14
- import { bindingTrail, docTitle, FIELD_BLOCK, REPEAT_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isFieldListSource, isObviousPath, LIST_BLOCK, previewDoc, previewValue, propKind, propPathOf, URL_PATH, urlField, valueAt, } from './binding.js';
16
+ import { bindingTrail, docTitle, FIELD_BLOCK, REPEAT_BLOCK, findBindingField, hasBindableField, isCompatible, isFieldBlockSource, isRepeatSource, isObviousPath, LIST_BLOCK, previewDoc, previewValue, propKind, propPathOf, URL_PATH, urlField, valueAt, } from './binding.js';
17
+ import { propertyOf } from '../../../core/components.js';
18
+ import { editsSection, propertyTypeOf } from '../sections/components.js';
19
+ import { PropertySlot, VisibleProperty } from '../sections/PropertyControls.js';
15
20
  import { FieldPicker, fieldIcon } from './FieldPicker.js';
16
21
  import { useCollectionLabel, useListSample, useTitleField } from './useTemplate.js';
17
22
  import './templates.scss';
@@ -98,13 +103,14 @@ export function BindingScopeProvider({ block, prefix, children }) {
98
103
  const runtime = useRuntime();
99
104
  const scope = useBindingScope(block);
100
105
  const def = getBlockDefinition(runtime.config.blocks, block.type);
101
- return (_jsxs(BindingScopeContext, { value: { block, def, prefix, scope }, children: [_jsx(ScopeBanner, { block: block, scope: scope }), children] }));
106
+ return (_jsxs(BindingScopeContext, { value: { block, def, prefix, scope }, children: [_jsx(ScopeBanner, { block: block, scope: scope }), children, !scope && _jsx(VisibleProperty, { block: block })] }));
102
107
  }
103
108
  /**
104
109
  * One inspector field. Shows the normal input, plus a bind button when the prop can bind; the
105
110
  * bound chip when it is bound; or a special input for the Field block and the collection list.
106
111
  */
107
112
  export function FieldSlot(props) {
113
+ const runtime = useRuntime();
108
114
  const ctx = use(BindingScopeContext);
109
115
  if (!ctx)
110
116
  return props.children;
@@ -118,10 +124,14 @@ export function FieldSlot(props) {
118
124
  return _jsx(FieldPathInput, { ...props, scope: scope, rows: true });
119
125
  if (block.type === LIST_BLOCK && propPath === 'collection')
120
126
  return _jsx(ListCollectionInput, { ...props });
121
- if (block.type === LIST_BLOCK && propPath === 'sort')
122
- return _jsx(ListSortInput, { ...props, block: block });
123
127
  if (block.type === FIELD_BLOCK || block.type === LIST_BLOCK || block.type === REPEAT_BLOCK)
124
128
  return props.children;
129
+ // A saved section (outside lists): content fields can become the component's properties.
130
+ const inLinkGroup = def && propPath.includes('.') && isLinkField(propField(def.fields, propPath.slice(0, propPath.lastIndexOf('.'))));
131
+ const isProperty = propertyOf(block.bindings?.[propPath] ?? '') !== null;
132
+ if (!scope && !inLinkGroup && editsSection(runtime) && (isProperty || propertyTypeOf(runtime, block, propPath))) {
133
+ return (_jsx(PropertySlot, { block: block, propPath: propPath, label: props.label, children: props.children }));
134
+ }
125
135
  const kind = propKind(props.field);
126
136
  if (!kind)
127
137
  return props.children;
@@ -156,20 +166,53 @@ function useAccept(kind, field) {
156
166
  const relationTo = 'relationTo' in field ? field.relationTo : undefined;
157
167
  return useCallback((source) => isCompatible(kind, source, { type: field.type, relationTo }), [kind, field.type, relationTo]);
158
168
  }
169
+ /** Sets the prop's binding (`null` unbinds). `what` names the new source for the notice; none: no notice. */
159
170
  function useBind(block, propPath, propLabel) {
160
171
  const runtime = useRuntime();
161
- return (source) => {
162
- const done = runtime.store.apply({ type: 'update', id: block.id, bindings: { [propPath]: source ? source.path : null } });
163
- if (done)
164
- runtime.notify(source ? `${propLabel} now shows ${source.label}` : `${propLabel} is no longer bound`);
172
+ return (binding, what) => {
173
+ const done = runtime.store.apply({ type: 'update', id: block.id, bindings: { [propPath]: binding } });
174
+ if (!done)
175
+ return;
176
+ if (binding === null)
177
+ runtime.notify(`${propLabel} is no longer bound`);
178
+ else if (what)
179
+ runtime.notify(`${propLabel} now shows ${what}`);
165
180
  };
166
181
  }
182
+ const FORMAT_OPTIONS = Object.entries(BINDING_FORMATTER_INFO).map(([value, info]) => ({ value, label: info.label }));
183
+ /** ":" and "|" separate the parts of a binding, so an argument cannot hold them. */
184
+ const cleanArg = (text) => text.replace(/[:|{}]/g, '');
185
+ /**
186
+ * How a bound value shows as text: a formatter (date, number, currency, uppercase, shorten…) and
187
+ * its arguments as small inputs. Writes the binding's `|name:arg` part, so nobody types it.
188
+ */
189
+ function FormatPicker({ format, onChange, label }) {
190
+ const info = format ? BINDING_FORMATTER_INFO[format.name] : undefined;
191
+ const setArg = (index, value) => {
192
+ if (!format)
193
+ return;
194
+ const args = [...format.args];
195
+ while (args.length < index)
196
+ args.push('');
197
+ args[index] = value;
198
+ onChange({ ...format, args });
199
+ };
200
+ return (_jsxs("fieldset", { className: "builder-format", "aria-label": `${label}: format`, children: [_jsx(Select, { className: "builder-format__name", "aria-label": `${label}: format`, emptyLabel: "No format", value: format?.name ?? null, options: FORMAT_OPTIONS, onValueChange: (name) => onChange(name ? { name, args: [] } : null) }), format &&
201
+ info?.args.map((arg, index) => {
202
+ const value = format.args[index] ?? '';
203
+ if (arg.options) {
204
+ const [first, ...rest] = arg.options;
205
+ return (_jsx(Select, { "aria-label": `${label}: ${arg.label.toLowerCase()}`, emptyLabel: first?.value === '' ? first.label : undefined, value: value || null, options: first?.value === '' ? rest : [...arg.options], onValueChange: (next) => setArg(index, next ?? '') }, arg.label));
206
+ }
207
+ return (_jsx("input", { type: "text", className: "builder-where__input", "aria-label": `${label}: ${arg.label.toLowerCase()}`, placeholder: arg.placeholder ? `${arg.label}: ${arg.placeholder}` : arg.label, value: value, onChange: (e) => setArg(index, cleanArg(e.target.value)) }, arg.label));
208
+ })] }));
209
+ }
167
210
  function BindButton({ block, propPath, kind, scope, field, label, }) {
168
211
  const popover = usePopover('auto');
169
212
  const accept = useAccept(kind, field);
170
213
  const bind = useBind(block, propPath, label);
171
214
  const collectionLabel = useCollectionLabel(scope.collection);
172
- return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "builder-bind__button", "aria-label": `Bind ${label} to a field`, "aria-haspopup": "listbox", "aria-expanded": popover.open, "data-tooltip": "Bind to a field", onClick: (e) => popover.toggle(e.currentTarget), children: _jsx(Icon, { name: "bind", size: 13 }) }), _jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: null, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: bind })] }));
215
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "builder-bind__button", "aria-label": `Bind ${label} to a field`, "aria-haspopup": "listbox", "aria-expanded": popover.open, "data-tooltip": "Bind to a field", onClick: (e) => popover.toggle(e.currentTarget), children: _jsx(Icon, { name: "bind", size: 13 }) }), _jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: null, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: (source) => bind(source.path, source.label) })] }));
173
216
  }
174
217
  function BoundField({ field, label, children, block, propPath, bound, kind, scope, }) {
175
218
  const popover = usePopover('auto');
@@ -178,20 +221,27 @@ function BoundField({ field, label, children, block, propPath, bound, kind, scop
178
221
  const collectionLabel = useCollectionLabel(scope?.collection ?? null);
179
222
  const [showFallback, setShowFallback] = useState(false);
180
223
  const fields = scope?.collection ? scope.fields : [urlField(scope?.kind ?? 'list')];
181
- const expression = isBindingExpression(bound);
182
- const source = expression ? { path: bound, label: bound, type: 'text' } : findBindingField(fields, bound);
183
- const trail = source && !expression ? bindingTrail(fields, bound) : [bound];
224
+ // One field with at most one formatter shows as the field and a format; templates and fallback
225
+ // chains show as their text.
226
+ const parts = bindingParts(bound);
227
+ const single = parts && parts.paths.length === 1 ? parts.paths[0] : null;
228
+ const expression = single === null;
229
+ // In a template, `$page.<path>` is the template's own document.
230
+ const own = single && scope?.kind === 'template' && single.startsWith('$page.') ? single.slice('$page.'.length) : single;
231
+ const source = expression ? { path: bound, label: bound, type: 'text' } : findBindingField(fields, own);
232
+ const trail = source && !expression ? bindingTrail(fields, own) : [bound];
233
+ const shownPath = single ?? bound;
184
234
  const required = 'required' in field ? Boolean(field.required) : false;
185
- return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', bound) && _jsx("code", { className: "builder-bind__chip-path", children: bound })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), expression ? (_jsx(ExpressionPreview, { scope: scope, binding: bound })) : source ? (_jsx(SamplePreview, { scope: scope, source: source })) : (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
186
- ? `${collectionLabel} has no field “${bound}”. The fallback shows instead.`
187
- : 'This block is not inside a template or a collection list, so the binding has no data. Unbind it or move the block.' })), _jsxs("button", { type: "button", className: "builder-bind__fallback-toggle", "aria-expanded": showFallback, onClick: () => setShowFallback(!showFallback), children: [_jsx(Icon, { name: showFallback ? 'chevronDown' : 'chevronRight', size: 12 }), "Fallback when the field is empty"] }), showFallback && _jsx("div", { className: "builder-bind__fallback", children: children }), scope?.collection && (_jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: bound, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: bind }))] }));
235
+ return (_jsxs("div", { className: "builder-bind builder-bind--bound field-type", children: [_jsx("div", { "aria-hidden": "true", children: _jsx(FieldLabel, { as: "span", label: label, required: required }) }), _jsxs("div", { className: `builder-bind__chip${source ? '' : ' builder-bind__chip--missing'}`, children: [_jsxs("button", { type: "button", className: "builder-bind__chip-main", "aria-haspopup": "listbox", "aria-expanded": popover.open, disabled: !scope?.collection, "aria-label": `${label} shows ${trail.join(' › ')}${scope?.collection ? '. Change the field' : ''}`, title: scope?.collection ? 'Change the field' : undefined, onClick: (e) => popover.toggle(e.currentTarget.parentElement ?? e.currentTarget), children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', shownPath) && _jsx("code", { className: "builder-bind__chip-path", children: shownPath })] }), _jsx("button", { type: "button", className: "builder-bind__chip-x", "aria-label": "Unbind", "data-tooltip": "Unbind", onClick: () => bind(null), children: _jsx(Icon, { name: "close", size: 12 }) })] }), kind === 'text' && parts && (_jsx(FormatPicker, { label: label, format: parts.format, onChange: (format) => bind(bindingFromParts({ paths: parts.paths, format })) })), !expression && !source ? (_jsx("p", { className: "builder-bind__note builder-bind__note--warn", children: scope?.collection
236
+ ? `${collectionLabel} has no field “${shownPath}”. The fallback shows instead.`
237
+ : 'No data here: the block is not in a template or a collection list.' })) : expression || parts?.format ? (_jsx(ExpressionPreview, { scope: scope, binding: bound })) : (source && _jsx(SamplePreview, { scope: scope, source: source })), _jsxs("button", { type: "button", className: "builder-bind__fallback-toggle", "aria-expanded": showFallback, onClick: () => setShowFallback(!showFallback), children: [_jsx(Icon, { name: showFallback ? 'chevronDown' : 'chevronRight', size: 12 }), "Fallback when the field is empty"] }), showFallback && _jsx("div", { className: "builder-bind__fallback", children: children }), scope?.collection && (_jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields, accept: accept, sample: scope.sample, current: shownPath, emptyText: `${collectionLabel} has no ${KIND_NAMES[kind]} fields.`, onPick: (picked) => bind(bindingFromParts({ paths: [picked.path], format: parts?.format ?? null }), picked.label) }))] }));
188
238
  }
189
- /** The sample's value for a binding expression (a template string, a fallback chain, formatters). */
239
+ /** The sample's value for a binding with a format, a fallback chain or a template string. */
190
240
  function ExpressionPreview({ scope, binding }) {
191
241
  if (!scope?.context)
192
- return _jsx("p", { className: "builder-bind__note", children: "A binding expression. No sample to preview." });
242
+ return _jsx("p", { className: "builder-bind__note", children: "No sample to preview." });
193
243
  const text = previewValue(bindingValue(scope.context, binding), 'text');
194
- return (_jsxs("div", { className: "builder-bind__preview", children: [_jsx("span", { className: "builder-bind__preview-from", children: "Expression" }), text.kind === 'text' ? _jsx("span", { className: "builder-bind__preview-text", children: text.text }) : _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
244
+ return (_jsxs("div", { className: "builder-bind__preview", children: [_jsxs("span", { className: "builder-bind__preview-from", title: scope.sampleTitle, children: [scope.kind === 'list' ? 'First item' : scope.kind === 'row' ? 'First row' : 'Sample', ": ", scope.sampleTitle || 'untitled'] }), text.kind === 'text' ? _jsx("span", { className: "builder-bind__preview-text", children: text.text }) : _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
195
245
  }
196
246
  /** The sample document's value for a bound field: text, an image, or a note when it is empty. */
197
247
  export function SamplePreview({ scope, source }) {
@@ -207,24 +257,28 @@ export function SamplePreview({ scope, source }) {
207
257
  const from = scope.kind === 'list' ? 'First item' : scope.kind === 'row' ? 'First row' : 'Sample';
208
258
  return (_jsxs("div", { className: "builder-bind__preview", children: [_jsxs("span", { className: "builder-bind__preview-from", title: scope.sampleTitle, children: [from, ": ", scope.sampleTitle || 'untitled'] }), preview.kind === 'text' && _jsx("span", { className: "builder-bind__preview-text", children: preview.text }), preview.kind === 'image' && (_jsx("img", { className: "builder-bind__preview-image", src: preview.url, alt: preview.alt })), preview.kind === 'empty' && _jsx("span", { className: "builder-bind__preview-empty", children: "Empty here. The fallback shows instead." })] }));
209
259
  }
210
- /** The Field block's `path`: picks any field of the scope's document. `rows`: a field list's path (fields with rows). */
260
+ /**
261
+ * The Field block's `path`: picks any field of the scope's document, with a format. `rows`: a
262
+ * repeat's path (fields with rows), without a format.
263
+ */
211
264
  function FieldPathInput({ value, onChange, label, children, scope, rows = false }) {
212
265
  const popover = usePopover('auto');
213
- const accept = rows ? isFieldListSource : isFieldBlockSource;
266
+ const accept = rows ? isRepeatSource : isFieldBlockSource;
214
267
  const collectionLabel = useCollectionLabel(scope?.collection ?? null);
215
- const path = typeof value === 'string' && value ? value : null;
268
+ const stored = typeof value === 'string' && value ? value : null;
269
+ // The Field block's path may end in a formatter ("price|currency:EUR"): the picker shows the field.
270
+ const parts = stored && !rows ? bindingParts(stored) : null;
271
+ const path = parts && parts.paths.length === 1 ? parts.paths[0] : stored;
216
272
  if (!scope?.collection) {
217
273
  return (_jsxs("div", { className: "builder-bind__stack", children: [_jsx("p", { className: "builder-bind__note", children: scope?.kind === 'list'
218
- ? 'Choose the list’s collection first. Then pick the field each item shows.'
274
+ ? 'Choose the list’s collection first.'
219
275
  : scope?.kind === 'template'
220
- ? 'Choose which collection this template is for. Then pick a field here.'
221
- : rows
222
- ? 'A Field list repeats the rows of a field of the template’s document or of each list item. Use it in a template or inside a collection list.'
223
- : 'A Field block shows a field of the template’s document or of each list item. Use it in a template or inside a collection list.' }), children] }));
276
+ ? 'Choose the template’s collection first.'
277
+ : 'Works only in a template or a collection list.' }), children] }));
224
278
  }
225
279
  const source = path ? findBindingField(scope.fields, path) : null;
226
280
  const trail = path ? bindingTrail(scope.fields, path) : [];
227
- return (_jsxs("div", { className: "field-type builder-bind", children: [_jsx(FieldLabel, { as: "span", label: label, required: true }), _jsxs("button", { type: "button", className: `builder-bind__select${path && !source ? ' builder-bind__select--missing' : ''}`, "aria-haspopup": "listbox", "aria-expanded": popover.open, onClick: (e) => popover.toggle(e.currentTarget), children: [path ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', path) && _jsx("code", { className: "builder-bind__chip-path", children: path })] })) : (_jsx("span", { className: "builder-bind__placeholder", children: "Choose a field\u2026" })), _jsx(Icon, { name: "chevronDown", size: 12, className: "builder-bind__select-caret" })] }), source && _jsx(SamplePreview, { scope: scope, source: source }), path && !source && _jsxs("p", { className: "builder-bind__note builder-bind__note--warn", children: [collectionLabel, " has no field \u201C", path, "\u201D."] }), _jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields.filter((f) => f.path !== URL_PATH), accept: accept, sample: scope.sample, current: path, emptyText: `${collectionLabel} has no fields.`, onPick: (picked) => onChange(picked.path) })] }));
281
+ return (_jsxs("div", { className: "field-type builder-bind", children: [_jsx(FieldLabel, { as: "span", label: label, required: true }), _jsxs("button", { type: "button", className: `builder-bind__select${path && !source ? ' builder-bind__select--missing' : ''}`, "aria-haspopup": "listbox", "aria-expanded": popover.open, onClick: (e) => popover.toggle(e.currentTarget), children: [path ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: source ? fieldIcon(source) : 'warning', size: 13 }), _jsx("span", { className: "builder-bind__chip-label", children: trail.join(' › ') }), !isObviousPath(source?.label ?? '', path) && _jsx("code", { className: "builder-bind__chip-path", children: path })] })) : (_jsx("span", { className: "builder-bind__placeholder", children: "Choose a field\u2026" })), _jsx(Icon, { name: "chevronDown", size: 12, className: "builder-bind__select-caret" })] }), parts && (_jsx(FormatPicker, { label: label, format: parts.format, onChange: (format) => onChange(bindingFromParts({ paths: parts.paths, format })) })), source && (parts?.format ? _jsx(ExpressionPreview, { scope: scope, binding: stored ?? '' }) : _jsx(SamplePreview, { scope: scope, source: source })), path && !source && _jsxs("p", { className: "builder-bind__note builder-bind__note--warn", children: [collectionLabel, " has no field \u201C", path, "\u201D."] }), _jsx(FieldPicker, { popover: popover, title: scopeTitle(scope, collectionLabel), fields: scope.fields.filter((f) => f.path !== URL_PATH), accept: accept, sample: scope.sample, current: path, emptyText: `${collectionLabel} has no fields.`, onPick: (picked) => onChange(rows ? picked.path : bindingFromParts({ paths: [picked.path], format: parts?.format ?? null })) })] }));
228
282
  }
229
283
  /** Collection list: which collection it lists. Only collections with binding sources. */
230
284
  function ListCollectionInput({ value, onChange, label, path, field }) {
@@ -242,31 +296,6 @@ function ListCollectionInput({ value, onChange, label, path, field }) {
242
296
  }
243
297
  return (_jsx(SelectInput, { label: label, name: 'name' in field ? field.name : 'collection', path: path, required: true, options: options, value: typeof value === 'string' ? value : undefined, onChange: (option) => onChange(Array.isArray(option) ? null : (option?.value ?? null)) }));
244
298
  }
245
- const CUSTOM = '__custom';
246
- /** Collection list: sort presets (newest, oldest, title A–Z and Z–A) and a custom sort field. */
247
- function ListSortInput({ value, onChange, label, path, field, block }) {
248
- const collection = typeof block.props?.collection === 'string' ? block.props.collection : null;
249
- const titleField = useTitleField(collection) ?? 'title';
250
- const current = typeof value === 'string' ? value : '';
251
- const presets = [
252
- { label: 'Newest first', value: '-createdAt' },
253
- { label: 'Oldest first', value: 'createdAt' },
254
- { label: 'Title A–Z', value: titleField },
255
- { label: 'Title Z–A', value: `-${titleField}` },
256
- ];
257
- const isPreset = presets.some((p) => p.value === current);
258
- const [custom, setCustom] = useState(() => current !== '' && !isPreset);
259
- const selected = custom || (current !== '' && !isPreset) ? CUSTOM : current || undefined;
260
- return (_jsxs("div", { className: "builder-bind__stack", children: [_jsx(SelectInput, { label: label, name: 'name' in field ? field.name : 'sort', path: path, options: [...presets, { label: 'Custom…', value: CUSTOM }], value: selected, onChange: (option) => {
261
- const next = Array.isArray(option) ? null : (option?.value ?? null);
262
- if (next === CUSTOM) {
263
- setCustom(true);
264
- return;
265
- }
266
- setCustom(false);
267
- onChange(next);
268
- } }), selected === CUSTOM && (_jsx(TextInput, { label: "Sort by field", description: "A field name. Start with - for descending, e.g. -publishedAt.", path: `${path}.custom`, value: current, onChange: (e) => onChange(e.target.value.trim() || null) }))] }));
269
- }
270
299
  /** A one-line explanation above a bindable block's fields: what bindings read from, or what is missing. */
271
300
  function ScopeBanner({ block, scope }) {
272
301
  const runtime = useRuntime();
@@ -278,10 +307,10 @@ function ScopeBanner({ block, scope }) {
278
307
  if (!def || !hasBindableField(def.fields))
279
308
  return null;
280
309
  if (scope.kind === 'template' && !scope.collection) {
281
- return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "warning", size: 14 }), _jsxs("div", { children: [_jsx("p", { children: "Choose which collection this template is for. Then you can bind this block to its fields." }), _jsx("button", { type: "button", className: "builder-bind__link", onClick: () => runtime.doc.openSettings(), children: "Open the template settings" })] })] }));
310
+ return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "warning", size: 14 }), _jsxs("div", { children: [_jsx("p", { children: "Choose the template\u2019s collection first." }), _jsx("button", { type: "button", className: "builder-bind__link", onClick: () => runtime.doc.openSettings(), children: "Open the template settings" })] })] }));
282
311
  }
283
312
  if (scope.kind === 'list' && !scope.collection) {
284
- return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsx("p", { children: "This block is inside a collection list. Choose the list\u2019s collection to bind fields of each item." })] }));
313
+ return (_jsxs("div", { className: "builder-bind__banner builder-bind__banner--warn", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsx("p", { children: "Choose the list\u2019s collection first." })] }));
285
314
  }
286
315
  if (scope.kind === 'row') {
287
316
  return (_jsxs("div", { className: "builder-bind__banner", children: [_jsx(Icon, { name: "collectionList", size: 14 }), _jsxs("p", { children: ["Repeats for each row of \u201C", scope.rowPath, "\u201D. Use ", _jsx(Icon, { name: "bind", size: 12, className: "builder-bind__inline-icon" }), " next to a field to show the row\u2019s data."] })] }));
@@ -64,7 +64,7 @@ function SampleList({ collection, plural, current, onPick, }) {
64
64
  return (_jsxs("div", { className: "builder-bind__picker", onKeyDown: onKeyDown, children: [_jsx("div", { className: "builder-bind__picker-head", children: _jsxs("span", { className: "builder-bind__picker-title", children: [_jsx(Icon, { name: "eye", size: 13 }), " Preview with"] }) }), _jsxs("label", { className: "builder-bind__picker-search", children: [_jsx(Icon, { name: "search", size: 14 }), _jsx("input", { ref: inputRef, type: "search", placeholder: `Search ${plural.toLowerCase()}`, "aria-label": `Search ${plural.toLowerCase()}`, role: "combobox", "aria-expanded": true, "aria-controls": listId, "aria-activedescendant": activeDoc ? `${listId}-${activeDoc.id}` : undefined, value: query, onChange: (e) => {
65
65
  setQuery(e.target.value);
66
66
  setActive(0);
67
- } })] }), error ? (_jsxs("p", { className: "builder-bind__picker-empty", children: ["Could not load ", plural.toLowerCase(), ": ", error] })) : docs.length === 0 ? (_jsx("p", { className: "builder-bind__picker-empty", children: loading ? 'Loading…' : query.trim() ? `Nothing matches “${query.trim()}”.` : `No ${plural.toLowerCase()} yet.` })) : (_jsx("ul", { id: listId, className: "builder-bind__rows", role: "listbox", "aria-label": `${plural} to preview with`, "aria-busy": loading, children: docs.map((doc, i) => (_jsx(SampleRow, { doc: doc, id: `${listId}-${doc.id}`, active: i === active, current: doc.id === current, otherTemplate: usesOtherTemplate(doc, self, defaultId), onPick: onPick, onHover: () => setActive(i) }, String(doc.id)))) })), _jsx("p", { className: "builder-bind__picker-foot", children: "Only changes the preview. The template stays the same for every document." })] }));
67
+ } })] }), error ? (_jsxs("p", { className: "builder-bind__picker-empty", children: ["Could not load ", plural.toLowerCase(), ": ", error] })) : docs.length === 0 ? (_jsx("p", { className: "builder-bind__picker-empty", children: loading ? 'Loading…' : query.trim() ? `Nothing matches “${query.trim()}”.` : `No ${plural.toLowerCase()} yet.` })) : (_jsx("ul", { id: listId, className: "builder-bind__rows", role: "listbox", "aria-label": `${plural} to preview with`, "aria-busy": loading, children: docs.map((doc, i) => (_jsx(SampleRow, { doc: doc, id: `${listId}-${doc.id}`, active: i === active, current: doc.id === current, otherTemplate: usesOtherTemplate(doc, self, defaultId), onPick: onPick, onHover: () => setActive(i) }, String(doc.id)))) })), _jsx("p", { className: "builder-bind__picker-foot", children: "Changes only the preview." })] }));
68
68
  }
69
69
  const scrollIntoView = (el) => el?.scrollIntoView({ block: 'nearest' });
70
70
  /**
@@ -0,0 +1,9 @@
1
+ import type { Block } from '../../../core/types.js';
2
+ /**
3
+ * Visibility conditions of a block inside a template, a collection list item or a repeat. Shown
4
+ * only where a document exists to test (or when the block already has conditions). A row's value
5
+ * is a fixed value or another field of the same document.
6
+ */
7
+ export declare function VisibilityField({ block }: {
8
+ readonly block: Block;
9
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The block's visibility conditions in the inspector: condition rows over the fields of the
4
+ // block's document (template, list item, row), in "or" groups of "and" rows.
5
+ import { FieldLabel } from '@payloadcms/ui';
6
+ import { useMemo, useState } from 'react';
7
+ import { INDEX_PATH } from '../../../core/bindings.js';
8
+ import { storesBuilderData } from '../actions.js';
9
+ import { useCollectionFields } from '../fields/collectionFields.js';
10
+ import { ConditionRows } from '../fields/ConditionRows.js';
11
+ import { whereFieldOption } from '../fields/WhereField.js';
12
+ import { useRuntime } from '../runtime.js';
13
+ import { useBindingScope } from './Bindable.js';
14
+ import { rowsVisibility, visibilityFields, visibilityRows } from './visibilityRows.js';
15
+ /**
16
+ * Visibility conditions of a block inside a template, a collection list item or a repeat. Shown
17
+ * only where a document exists to test (or when the block already has conditions). A row's value
18
+ * is a fixed value or another field of the same document.
19
+ */
20
+ export function VisibilityField({ block }) {
21
+ const runtime = useRuntime();
22
+ const scope = useBindingScope(block);
23
+ // Without binding sources for the collection (templates off for it), its fields from the Payload
24
+ // config. Not for repeat rows: their fields are the row's, not the collection's.
25
+ const configFields = useCollectionFields(scope && scope.kind !== 'row' ? (scope.collection ?? undefined) : undefined);
26
+ const fields = useMemo(() => {
27
+ const inItem = scope?.kind === 'list' || scope?.kind === 'row';
28
+ const found = visibilityFields(scope?.fields ?? [], inItem);
29
+ if (found.some((f) => f.path !== INDEX_PATH) || configFields.length === 0)
30
+ return found;
31
+ return [...found, ...configFields.map(whereFieldOption)];
32
+ }, [scope?.fields, scope?.kind, configFields]);
33
+ const sources = useMemo(() => ({ field: fields }), [fields]);
34
+ const stored = block.visibility;
35
+ const storedKey = JSON.stringify(stored ?? null);
36
+ const [draft, setDraft] = useState(() => ({ groups: visibilityRows(stored), source: storedKey }));
37
+ // The conditions changed from outside (undo, AI edit): show them. Our own edits come back equal to `source`,
38
+ // so rows still being typed (no field yet, an empty list) stay.
39
+ if (storedKey !== draft.source)
40
+ setDraft({ groups: visibilityRows(stored), source: storedKey });
41
+ if (!storesBuilderData(runtime))
42
+ return null;
43
+ if (!scope && !stored)
44
+ return null;
45
+ const save = (groups) => {
46
+ const next = rowsVisibility(groups);
47
+ const key = JSON.stringify(next);
48
+ setDraft({ groups, source: key });
49
+ // A row still being typed changes nothing stored: no undo step.
50
+ if (key !== storedKey)
51
+ runtime.store.apply({ type: 'update', id: block.id, visibility: next });
52
+ };
53
+ return (_jsxs("div", { className: "builder-where builder-visibility", children: [_jsx(FieldLabel, { as: "span", label: "Show only when" }), !scope && _jsx("p", { className: "builder-field-note", children: "Works only in a template or a collection list." }), _jsx(ConditionRows, { groups: draft.groups, onChange: save, fields: fields, sources: sources, defaultOperator: "is_set" })] }));
54
+ }