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
@@ -5,8 +5,10 @@
5
5
  // the bound props take the document's value. Missing values (undefined, null, "", []) keep the
6
6
  // literal prop.
7
7
  import { isLinkField } from '../blocks/link.js';
8
+ import { COLLECTION_LIST_BLOCK, PAGE_PARAM, REPEAT_BLOCK } from './blockNames.js';
8
9
  import { dataFields } from './fields.js';
9
10
  import { isPlainObject, walkBlocks } from './tree.js';
11
+ import { VALUELESS_OPERATORS, visibilityConditions, visibilityGroups } from './visibility.js';
10
12
  // ---------------------------------------------------------------------------
11
13
  // Names shared by the plugin, the renderer and the editor
12
14
  // ---------------------------------------------------------------------------
@@ -22,10 +24,15 @@ export const TEMPLATE_PREVIEW_FIELD = 'previewDocument';
22
24
  export const TEMPLATE_LAYOUT_FIELD = 'layout';
23
25
  /**
24
26
  * Templates collection: an optional Payload `where` query against the document. A document
25
- * without a template of its own uses the first published template (by name) whose conditions
26
- * match it, before the default template.
27
+ * without a template of its own uses the matching template with the highest priority
28
+ * (`TEMPLATE_PRIORITY_FIELD`), before the default template.
27
29
  */
28
30
  export const TEMPLATE_CONDITIONS_FIELD = 'conditions';
31
+ /**
32
+ * Templates collection: a number that orders templates with conditions. When several match a
33
+ * document, the highest priority wins; on equal priority the older template wins.
34
+ */
35
+ export const TEMPLATE_PRIORITY_FIELD = 'priority';
29
36
  /** Template-enabled collections: the relationship to the document's own template. */
30
37
  export const DOCUMENT_TEMPLATE_FIELD = 'template';
31
38
  /**
@@ -36,12 +43,12 @@ export function templateConditions(template) {
36
43
  const value = template?.[TEMPLATE_CONDITIONS_FIELD];
37
44
  return isPlainObject(value) && Object.keys(value).length > 0 ? value : null;
38
45
  }
46
+ // The block and query names client components need live in a module without imports.
47
+ export { COLLECTION_LIST_BLOCK, PAGE_PARAM, REPEAT_BLOCK };
39
48
  /** Virtual binding path: the frontend URL of the context document (from the link resolver). */
40
49
  export const URL_PATH = '$url';
41
50
  /** The Field block: shows the context document's value at `props.path`. */
42
51
  export const FIELD_BLOCK = 'field';
43
- /** The collection list block: renders its `item` slot once per loaded document. */
44
- export const COLLECTION_LIST_BLOCK = 'collectionList';
45
52
  /** Slot of the collection list block that holds the template for one item. */
46
53
  export const LIST_ITEM_SLOT = 'item';
47
54
  /**
@@ -51,15 +58,8 @@ export const LIST_ITEM_SLOT = 'item';
51
58
  export const LIST_ITEMS_PROP = '$items';
52
59
  /** Runtime-only prop of the Field block: the resolved value. It is never stored. */
53
60
  export const FIELD_VALUE_PROP = 'value';
54
- /**
55
- * The repeat block: renders its `item` slot once per row of an array or hasMany field of the
56
- * current document (`props.path`). The rows are its runtime-only `$items` prop.
57
- */
58
- export const REPEAT_BLOCK = 'repeat';
59
61
  /** Collection list slot shown when the list has no documents. */
60
62
  export const LIST_EMPTY_SLOT = 'empty';
61
- /** The URL query parameter of a paginated list's page (`?page=3`). Filter links drop it. */
62
- export const PAGE_PARAM = 'page';
63
63
  /** Virtual binding path inside a repeat item: the row value itself (a document, an upload, a text). */
64
64
  export const ITEM_PATH = '$item';
65
65
  /** Virtual binding path inside a collection list or repeat item: the item number, from 1. */
@@ -68,11 +68,6 @@ export const INDEX_PATH = '$index';
68
68
  export const PARENT_PATH = '$parent';
69
69
  /** Virtual path prefix: the page's own document (`$page.title`), also inside list and repeat items. */
70
70
  export const PAGE_PATH = '$page';
71
- /**
72
- * Binding key that shows or hides the block: `"field"` shows it when the field is filled,
73
- * `"!field"` when it is empty, `"field=value"` when it equals the value, `"field!=value"` when not.
74
- */
75
- export const VISIBLE_BINDING = '$visible';
76
71
  /** True for the slot that repeats per item: the `item` slot of a collection list or a repeat. */
77
72
  export function isRepeatSlot(type, slot) {
78
73
  return slot === LIST_ITEM_SLOT && (type === COLLECTION_LIST_BLOCK || type === REPEAT_BLOCK);
@@ -436,17 +431,38 @@ function pathValue(context, path, options) {
436
431
  return rest ? getByPath(root, rest) : root;
437
432
  }
438
433
  const currencyFormats = new Map();
439
- /** First sentence of plain text: up to the first ".", "!" or "?" followed by a space or the end. */
440
- function firstSentence(text) {
441
- const match = /^.*?[.!?](?=\s|$)/s.exec(text.trim());
442
- return (match ? match[0] : text).trim();
434
+ /** A number from a number or a numeric text; null otherwise. */
435
+ function numberOf(value) {
436
+ if (typeof value === 'number')
437
+ return Number.isFinite(value) ? value : null;
438
+ if (typeof value !== 'string' || value.trim() === '')
439
+ return null;
440
+ const parsed = Number(value);
441
+ return Number.isFinite(parsed) ? parsed : null;
442
+ }
443
+ /**
444
+ * `text` cut to `count` words or characters, with "…" when something was cut. A cut by characters
445
+ * ends on a whole word when that keeps at least half of them.
446
+ */
447
+ function truncate(text, count, unit) {
448
+ const flat = text.replace(/\s+/g, ' ').trim();
449
+ if (unit === 'words') {
450
+ const words = flat.split(' ');
451
+ return words.length <= count ? flat : `${words.slice(0, count).join(' ')}…`;
452
+ }
453
+ if (flat.length <= count)
454
+ return flat;
455
+ const cut = flat.slice(0, count);
456
+ const space = cut.lastIndexOf(' ');
457
+ return `${(space >= count / 2 ? cut.slice(0, space) : cut).trimEnd()}…`;
443
458
  }
444
459
  /**
445
- * Formatters for binding expressions (`price|currency:AUD`). Each takes a value that is not
446
- * missing and returns text, or undefined when it cannot format the value.
460
+ * Formatters for binding expressions (`price|currency:EUR`). Each takes a value that is not
461
+ * missing and returns text, or undefined when it cannot format the value. Arguments follow the
462
+ * name, separated by ":". The editor's format picker lists them (`BINDING_FORMATTER_INFO`).
447
463
  */
448
464
  export const BINDING_FORMATTERS = {
449
- /** `date[:locale[:timeZone]]`, e.g. `date:en-AU:Australia/Brisbane`. Default `en`, UTC. */
465
+ /** `date[:locale[:timeZone]]`, e.g. `date:en-GB:Europe/London`. Default `en`, UTC. */
450
466
  date(value, [locale, timeZone]) {
451
467
  const date = value instanceof Date ? value : typeof value === 'string' || typeof value === 'number' ? new Date(value) : null;
452
468
  if (!date || Number.isNaN(date.getTime()))
@@ -458,19 +474,21 @@ export const BINDING_FORMATTERS = {
458
474
  return formatDate(date);
459
475
  }
460
476
  },
461
- /** `currency[:code[:locale]]`, e.g. `currency:AUD` gives "$1,200". Whole amounts have no cents. */
462
- currency(value, [code = 'USD', locale = 'en']) {
463
- const n = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN;
464
- if (!Number.isFinite(n))
477
+ /** `currency[:code[:locale]]`, e.g. `currency:EUR` gives "€1,200". Whole amounts have no cents. */
478
+ currency(value, [code, locale]) {
479
+ const n = numberOf(value);
480
+ if (n === null)
465
481
  return undefined;
482
+ const currency = (code || 'USD').toUpperCase();
483
+ const language = locale || 'en';
466
484
  const whole = Number.isInteger(n);
467
- const key = `${code}\u0000${locale}\u0000${whole}`;
485
+ const key = `${currency}\u0000${language}\u0000${whole}`;
468
486
  try {
469
487
  let format = currencyFormats.get(key);
470
488
  if (!format) {
471
- format = new Intl.NumberFormat(locale, {
489
+ format = new Intl.NumberFormat(language, {
472
490
  style: 'currency',
473
- currency: code.toUpperCase(),
491
+ currency,
474
492
  currencyDisplay: 'narrowSymbol',
475
493
  ...(whole ? { minimumFractionDigits: 0, maximumFractionDigits: 0 } : {}),
476
494
  });
@@ -483,26 +501,95 @@ export const BINDING_FORMATTERS = {
483
501
  }
484
502
  },
485
503
  /** `number[:locale]`: digit grouping, e.g. "1,200". */
486
- number(value, [locale = 'en']) {
487
- const n = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN;
488
- if (!Number.isFinite(n))
504
+ number(value, [locale]) {
505
+ const n = numberOf(value);
506
+ if (n === null)
489
507
  return undefined;
490
508
  try {
491
- return new Intl.NumberFormat(locale).format(n);
509
+ return new Intl.NumberFormat(locale || 'en').format(n);
492
510
  }
493
511
  catch {
494
512
  return String(n);
495
513
  }
496
514
  },
497
- /** `firstSentence`: the first sentence of the plain text (rich text too). */
498
- firstSentence(value) {
515
+ /** `uppercase`: the plain text in capitals. */
516
+ uppercase(value) {
517
+ return toPlainText(value)?.toUpperCase();
518
+ },
519
+ /** `lowercase`: the plain text in small letters. */
520
+ lowercase(value) {
521
+ return toPlainText(value)?.toLowerCase();
522
+ },
523
+ /**
524
+ * `truncate:count[:words]`: the plain text (rich text too) cut to `count` characters, or to
525
+ * `count` words with `:words`, with "…" when something was cut. E.g. `truncate:160`, `truncate:25:words`.
526
+ */
527
+ truncate(value, [count, unit]) {
499
528
  const text = toPlainText(value);
500
- return text ? firstSentence(text) : undefined;
529
+ if (text === undefined)
530
+ return undefined;
531
+ const n = numberOf(count);
532
+ if (n === null || n < 1)
533
+ return text;
534
+ return truncate(text, Math.floor(n), unit === 'words' ? 'words' : 'characters');
535
+ },
536
+ /**
537
+ * `readingTime[:wordsPerMinute[:suffix]]`: the time to read the text (rich text too), rounded up
538
+ * to whole minutes, at least 1. E.g. "5 min read"; `readingTime:200:Min. Lesezeit` gives
539
+ * "5 Min. Lesezeit". Default 200 words per minute. Undefined for a text without words.
540
+ */
541
+ readingTime(value, [wordsPerMinute, suffix]) {
542
+ const words = toPlainText(value)?.match(/\S+/g)?.length ?? 0;
543
+ if (words === 0)
544
+ return undefined;
545
+ const rate = numberOf(wordsPerMinute);
546
+ const minutes = Math.max(1, Math.ceil(words / (rate !== null && rate > 0 ? rate : 200)));
547
+ return `${minutes} ${suffix?.trim() || 'min read'}`;
548
+ },
549
+ };
550
+ /** The formatters the editor offers: a label and the arguments in order. */
551
+ export const BINDING_FORMATTER_INFO = {
552
+ date: {
553
+ label: 'Date',
554
+ args: [
555
+ { label: 'Language', placeholder: 'en' },
556
+ { label: 'Time zone', placeholder: 'UTC' },
557
+ ],
558
+ },
559
+ number: { label: 'Number', args: [{ label: 'Language', placeholder: 'en' }] },
560
+ currency: {
561
+ label: 'Currency',
562
+ args: [
563
+ { label: 'Currency code', placeholder: 'USD' },
564
+ { label: 'Language', placeholder: 'en' },
565
+ ],
566
+ },
567
+ uppercase: { label: 'Uppercase', args: [] },
568
+ lowercase: { label: 'Lowercase', args: [] },
569
+ truncate: {
570
+ label: 'Shorten',
571
+ args: [
572
+ { label: 'Length', placeholder: '160' },
573
+ {
574
+ label: 'Count',
575
+ options: [
576
+ { value: '', label: 'characters' },
577
+ { value: 'words', label: 'words' },
578
+ ],
579
+ },
580
+ ],
581
+ },
582
+ readingTime: {
583
+ label: 'Reading time',
584
+ args: [
585
+ { label: 'Words per minute', placeholder: '200' },
586
+ { label: 'Text after the number', placeholder: 'min read' },
587
+ ],
501
588
  },
502
589
  };
503
590
  /**
504
- * A value through one formatter, written as in a binding: "currency:AUD", "date:en-AU:Australia/Brisbane",
505
- * "number" or "firstSentence". Undefined for an unknown formatter, a missing value or a value the
591
+ * A value through one formatter, written as in a binding: "currency:EUR", "date:en-GB:Europe/London",
592
+ * "number" or "truncate:160". Undefined for an unknown formatter, a missing value or a value the
506
593
  * formatter cannot read. The field block's `format` prop uses it.
507
594
  */
508
595
  export function formatBindingValue(value, format) {
@@ -511,45 +598,80 @@ export function formatBindingValue(value, format) {
511
598
  return undefined;
512
599
  return BINDING_FORMATTERS[formatter.name](value, formatter.args);
513
600
  }
514
- /** One `|` part of an expression: a formatter (by name, after the first part) or a path. */
601
+ /** One `|` part read as a formatter (`name:arg:arg`). Null when the name is not a formatter. */
515
602
  function formatterOf(part) {
516
603
  const [name = '', ...args] = part.split(':');
517
604
  return Object.hasOwn(BINDING_FORMATTERS, name) ? { name, args } : null;
518
605
  }
606
+ /** The text of a formatter: the name and the arguments joined by ":", without trailing empty arguments. */
607
+ export function bindingFormatText(format) {
608
+ const args = format.args.map((arg) => arg.trim());
609
+ while (args.length > 0 && !args.at(-1))
610
+ args.pop();
611
+ return [format.name, ...args].join(':');
612
+ }
519
613
  /**
520
- * One expression: paths separated by `|` (the first that is not missing wins), then formatters
521
- * (`a|b|date:en-AU`). The first part is always a path.
614
+ * The paths and formatters of one expression. The first part is always a path. After it, a part
615
+ * whose name (before the first ":") is a formatter is a formatter, also when a field has that
616
+ * name: `title|date` formats `title` and never falls back to a field called `date` (put such a
617
+ * field first: `date|title`). The other parts are fallback paths. Paths after a formatter are
618
+ * ignored.
522
619
  */
620
+ function splitExpression(expression) {
621
+ const paths = [];
622
+ const formatters = [];
623
+ expression.split('|').forEach((raw, i) => {
624
+ const part = raw.trim();
625
+ if (!part)
626
+ return;
627
+ const formatter = i > 0 ? formatterOf(part) : null;
628
+ if (formatter)
629
+ formatters.push(formatter);
630
+ else if (formatters.length === 0)
631
+ paths.push(part);
632
+ });
633
+ return { paths, formatters };
634
+ }
635
+ /** One expression: the first path whose value is not missing, through the formatters in order. */
523
636
  function expressionValue(context, expression, options) {
524
- const parts = expression.split('|').map((part) => part.trim());
637
+ const { paths, formatters } = splitExpression(expression);
525
638
  let value;
526
- let i = 0;
527
- for (; i < parts.length; i++) {
528
- if (i > 0 && formatterOf(parts[i]))
639
+ for (const path of paths) {
640
+ value = pathValue(context, path, options);
641
+ if (!isMissing(value))
529
642
  break;
530
- if (isMissing(value))
531
- value = pathValue(context, parts[i], options);
532
643
  }
533
- for (; i < parts.length; i++) {
534
- const formatter = formatterOf(parts[i]);
535
- if (!formatter)
536
- continue;
644
+ for (const formatter of formatters) {
537
645
  if (isMissing(value))
538
646
  return undefined;
539
647
  value = BINDING_FORMATTERS[formatter.name](value, formatter.args);
540
648
  }
541
649
  return value;
542
650
  }
651
+ export function bindingParts(binding) {
652
+ if (binding.includes('{{'))
653
+ return null;
654
+ const { paths, formatters } = splitExpression(binding);
655
+ if (paths.length === 0 || formatters.length > 1)
656
+ return null;
657
+ return { paths, format: formatters[0] ?? null };
658
+ }
659
+ /** The binding string of `BindingParts`. Trailing empty arguments are left out. */
660
+ export function bindingFromParts(parts) {
661
+ const head = parts.paths.join('|');
662
+ return parts.format ? `${head}|${bindingFormatText(parts.format)}` : head;
663
+ }
543
664
  const TEMPLATE = /\{\{([^{}]+)\}\}/g;
544
665
  /** True when a binding is more than one plain path: a template string, a fallback chain or a formatter. */
545
666
  export function isBindingExpression(binding) {
546
667
  return binding.includes('{{') || binding.includes('|');
547
668
  }
548
669
  /**
549
- * The value of a binding:
670
+ * The value of a binding. The syntax is fixed to these forms:
550
671
  * - a path: `title`, `author.name`, or a virtual path (`$url`, `$item`, `$index`, `$parent.name`, `$page.title`);
551
- * - a fallback chain: `heading|name` (the first value that is not missing);
552
- * - formatters after the paths: `publishedAt|date:en-AU:Australia/Brisbane`, `price|currency:AUD`, `bio|firstSentence`;
672
+ * - a fallback chain: `subtitle|title` (the first value that is not missing);
673
+ * - formatters after the paths: `publishedAt|date:en-GB:Europe/London`, `price|currency:EUR`, `summary|truncate:160`
674
+ * (after the first part, a name that is a formatter is always a formatter, see `expressionValue`);
553
675
  * - a template string: `Enquire about {{name}}`. Each `{{expression}}` becomes text; a missing one
554
676
  * becomes empty. When every one is missing, the value is missing (the literal prop stays).
555
677
  */
@@ -567,37 +689,20 @@ export function bindingValue(context, binding, options) {
567
689
  return found ? text : undefined;
568
690
  }
569
691
  /** The plain field paths a binding reads (no formatters, no virtual `$url`, `$item`, `$index`). */
570
- export function bindingPaths(key, binding) {
571
- const expressions = binding.includes('{{')
572
- ? [...binding.matchAll(TEMPLATE)].map((m) => m[1])
573
- : [key === VISIBLE_BINDING ? conditionOf(binding).path : binding];
574
- return expressions.flatMap((expression) => expression
575
- .split('|')
576
- .map((part) => part.trim())
577
- .filter((part, i) => part && (i === 0 || !formatterOf(part)))
578
- .map((path) => (path.endsWith(RELATED_URL_SUFFIX) ? path.slice(0, -RELATED_URL_SUFFIX.length) : path))
579
- .filter((path) => path !== URL_PATH && path.split('.')[0] !== ITEM_PATH && path !== INDEX_PATH));
580
- }
581
- /** The first operator wins, so a value may hold "=" or ">" (`title=a=b`). Two-character operators first. */
582
- const COMPARISON = /^(.+?)\s*(>=|<=|!=|>|<|=)\s*(.*)$/s;
583
- /** `path#`: the condition counts the items. */
584
- const counts = (path) => path.endsWith('#');
585
- const bare = (path) => (counts(path) ? path.slice(0, -1).trim() : path);
586
- /**
587
- * `field`, `!field`, `field=value`, `field!=value`, and for numbers `field>3`, `field>=3`,
588
- * `field<3`, `field<=3`. `field#` is the number of items of a list (0 when empty, 1 for any other
589
- * filled value), e.g. `galleryImages#>=3`.
590
- */
591
- function conditionOf(condition) {
592
- const text = condition.trim();
593
- const match = COMPARISON.exec(text);
594
- if (match && match[1].trim() !== '!') {
595
- const path = match[1].trim();
596
- return { path: bare(path), test: match[2], value: match[3].trim(), count: counts(path) };
597
- }
598
- if (text.startsWith('!'))
599
- return { path: bare(text.slice(1).trim()), test: 'empty', value: '', count: counts(text) };
600
- return { path: bare(text), test: 'filled', value: '', count: counts(text) };
692
+ export function bindingPaths(binding) {
693
+ const expressions = binding.includes('{{') ? [...binding.matchAll(TEMPLATE)].map((m) => m[1]) : [binding];
694
+ return expressions.flatMap((expression) => splitExpression(expression).paths.map(plainPath).filter(isFieldPath));
695
+ }
696
+ /** `<path>.$url` reads the field at `path`. */
697
+ const plainPath = (path) => (path.endsWith(RELATED_URL_SUFFIX) ? path.slice(0, -RELATED_URL_SUFFIX.length) : path);
698
+ /** False for virtual paths that are not fields: `$url`, `$item...`, `$index`. */
699
+ const isFieldPath = (path) => path !== URL_PATH && path.split('.')[0] !== ITEM_PATH && path !== INDEX_PATH;
700
+ /** The field paths a block's visibility conditions read (no virtual `$item`, `$index`). */
701
+ export function visibilityFieldPaths(visibility) {
702
+ return visibilityConditions(visibility)
703
+ .flatMap((condition) => [condition.field, ...(condition.valueField ? [condition.valueField] : [])])
704
+ .map(plainPath)
705
+ .filter(isFieldPath);
601
706
  }
602
707
  /** The number of items: a list's length, 0 for an empty value, 1 for any other value. */
603
708
  function itemCount(value) {
@@ -605,15 +710,6 @@ function itemCount(value) {
605
710
  return value.length;
606
711
  return isMissing(value) || value === false ? 0 : 1;
607
712
  }
608
- /** A number from a number or a numeric text; null otherwise. */
609
- function numberOf(value) {
610
- if (typeof value === 'number')
611
- return Number.isFinite(value) ? value : null;
612
- if (typeof value !== 'string' || value.trim() === '')
613
- return null;
614
- const parsed = Number(value);
615
- return Number.isFinite(parsed) ? parsed : null;
616
- }
617
713
  /** True when a value matches `expected`: itself, a document's id, or any item of a list. */
618
714
  function matches(value, expected) {
619
715
  if (Array.isArray(value))
@@ -624,48 +720,121 @@ function matches(value, expected) {
624
720
  return value.id !== undefined && String(value.id) === expected;
625
721
  return value !== undefined && value !== null && String(value) === expected;
626
722
  }
627
- /** True when the `$visible` condition holds for the context. `false` counts as empty. */
628
- export function isVisible(context, condition, options) {
629
- const { path, test, value: expected, count } = conditionOf(condition);
630
- const raw = expressionValue(context, path, options);
631
- const value = count ? itemCount(raw) : raw;
632
- const filled = count ? value !== 0 : !isMissing(value) && value !== false;
633
- if (test === 'filled')
634
- return filled;
635
- if (test === 'empty')
636
- return !filled;
637
- if (test === '=' || test === '!=')
638
- return matches(value, expected) === (test === '=');
639
- // Greater and less compare numbers only: a value that is not a number never passes.
640
- const actual = numberOf(value);
641
- const limit = numberOf(expected);
723
+ /** A number to compare: a number, a numeric text, or a date (its time). Null otherwise. */
724
+ function comparable(value) {
725
+ const number = numberOf(value);
726
+ if (number !== null)
727
+ return number;
728
+ if (value instanceof Date)
729
+ return value.getTime();
730
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
731
+ const time = Date.parse(value);
732
+ return Number.isNaN(time) ? null : time;
733
+ }
734
+ return null;
735
+ }
736
+ /** The values another field holds, to compare with: list items, document ids and plain values. */
737
+ function fieldValues(value) {
738
+ if (Array.isArray(value))
739
+ return value.flatMap(fieldValues);
740
+ if (isRelationPair(value))
741
+ return fieldValues(value.value);
742
+ if (isPlainObject(value))
743
+ return value.id === undefined || value.id === null ? [] : [String(value.id)];
744
+ return isMissing(value) ? [] : [String(value)];
745
+ }
746
+ /**
747
+ * A condition with `valueField`: compares the field's value with the other field's value
748
+ * (`other`). Equal means one shared value or document. A missing other value never equals.
749
+ */
750
+ function fieldConditionHolds(value, condition, other) {
751
+ switch (condition.operator) {
752
+ case 'equals':
753
+ case 'in':
754
+ return fieldValues(other).some((item) => matches(value, item));
755
+ case 'not_equals':
756
+ case 'not_in':
757
+ return !fieldValues(other).some((item) => matches(value, item));
758
+ case 'like':
759
+ case 'contains':
760
+ return textHolds(value, toPlainText(other) ?? '', condition.operator);
761
+ default:
762
+ return compareHolds(value, Array.isArray(other) ? other[0] : other, condition.operator);
763
+ }
764
+ }
765
+ /** `contains` (any case) or `like` (every word, any case). An empty wanted text always holds. */
766
+ function textHolds(value, wanted, operator) {
767
+ const text = (toPlainText(value) ?? '').toLowerCase();
768
+ const words = wanted.trim().toLowerCase();
769
+ if (!words)
770
+ return true;
771
+ return operator === 'contains' ? text.includes(words) : words.split(/\s+/).every((word) => text.includes(word));
772
+ }
773
+ /** Greater and less compare numbers and dates only: other values never pass. */
774
+ function compareHolds(value, limitValue, operator) {
775
+ const actual = comparable(value);
776
+ const limit = comparable(limitValue);
642
777
  if (actual === null || limit === null)
643
778
  return false;
644
- if (test === '>')
779
+ if (operator === 'greater_than')
645
780
  return actual > limit;
646
- if (test === '>=')
781
+ if (operator === 'greater_than_equal')
647
782
  return actual >= limit;
648
- if (test === '<')
783
+ if (operator === 'less_than')
649
784
  return actual < limit;
650
785
  return actual <= limit;
651
786
  }
787
+ /** True when one visibility condition holds for the context. `false` counts as empty. */
788
+ function conditionHolds(context, condition, options) {
789
+ const raw = pathValue(context, condition.field, options);
790
+ const value = condition.count ? itemCount(raw) : raw;
791
+ const filled = condition.count ? value !== 0 : !isMissing(value) && value !== false;
792
+ if (condition.valueField !== undefined && !VALUELESS_OPERATORS.has(condition.operator)) {
793
+ return fieldConditionHolds(value, condition, pathValue(context, condition.valueField, options));
794
+ }
795
+ const expected = condition.value;
796
+ switch (condition.operator) {
797
+ case 'is_set':
798
+ return filled;
799
+ case 'is_empty':
800
+ return !filled;
801
+ case 'equals':
802
+ case 'not_equals': {
803
+ // A checkbox without a value counts as false.
804
+ const actual = (value === undefined || value === null) && typeof expected === 'boolean' ? false : value;
805
+ return matches(actual, String(expected ?? '')) === (condition.operator === 'equals');
806
+ }
807
+ case 'in':
808
+ case 'not_in': {
809
+ const list = Array.isArray(expected) ? expected : expected === undefined ? [] : [expected];
810
+ return list.some((item) => matches(value, String(item))) === (condition.operator === 'in');
811
+ }
812
+ case 'like':
813
+ case 'contains':
814
+ return textHolds(value, String(expected ?? ''), condition.operator);
815
+ default:
816
+ return compareHolds(value, expected, condition.operator);
817
+ }
818
+ }
652
819
  /**
653
- * Resolves one block's bindings (not its children). Bound props with a value take it; applied
654
- * bindings are removed from the result, unresolved ones stay. A `$visible` binding that does not
655
- * hold makes the block `hidden`. A Field block gets `props.value`, a repeat its rows (`$items`).
656
- * Returns the same block when nothing changes.
820
+ * True when the block's visibility conditions match the context: all of them, or any entry with
821
+ * `match: "any"` (a group entry matches when all its conditions match). No conditions: true.
657
822
  */
658
- export function resolveBlockBindings(block, context, definition, options) {
659
- let props = block.props ?? {};
823
+ export function isVisible(context, visibility, options) {
824
+ const groups = visibilityGroups(visibility);
825
+ if (groups.length === 0)
826
+ return true;
827
+ return groups.some((group) => group.every((condition) => conditionHolds(context, condition, options)));
828
+ }
829
+ /**
830
+ * Puts the values of `bindings` (prop path -> binding) into `props`. Bindings without a value
831
+ * stay in `left`, and their props keep the literal value. Never mutates.
832
+ */
833
+ export function bindProps(props, bindings, context, definition, options) {
834
+ let next = props;
660
835
  let changed = false;
661
836
  const left = {};
662
- let hidden = false;
663
- for (const [propPath, fieldPath] of Object.entries(block.bindings ?? {})) {
664
- if (propPath === VISIBLE_BINDING) {
665
- hidden = !isVisible(context, fieldPath, options);
666
- changed = true;
667
- continue;
668
- }
837
+ for (const [propPath, fieldPath] of Object.entries(bindings)) {
669
838
  const field = definition ? propField(definition.fields, propPath) : undefined;
670
839
  const value = coerceValue(bindingValue(context, fieldPath, options), field);
671
840
  if (value === undefined) {
@@ -673,15 +842,29 @@ export function resolveBlockBindings(block, context, definition, options) {
673
842
  continue;
674
843
  }
675
844
  const path = propPath.split('.');
676
- props = setByPath(props, path, value);
845
+ next = setByPath(next, path, value);
677
846
  // Binding a link group's URL makes it a URL link.
678
847
  if (path.length > 1 && path.at(-1) === 'url' && definition) {
679
848
  const parent = propField(definition.fields, path.slice(0, -1).join('.'));
680
849
  if (parent && isLinkField(parent))
681
- props = setByPath(props, [...path.slice(0, -1), 'type'], 'url');
850
+ next = setByPath(next, [...path.slice(0, -1), 'type'], 'url');
682
851
  }
683
852
  changed = true;
684
853
  }
854
+ return { props: next, left, changed };
855
+ }
856
+ /**
857
+ * Resolves one block's bindings (not its children). Bound props with a value take it; applied
858
+ * bindings are removed from the result, unresolved ones stay. Visibility conditions that do not
859
+ * match make the block `hidden`. A Field block gets `props.value`, a repeat its rows (`$items`).
860
+ * Returns the same block when nothing changes.
861
+ */
862
+ export function resolveBlockBindings(block, context, definition, options) {
863
+ const hidden = block.visibility ? !isVisible(context, block.visibility, options) : false;
864
+ const bound = bindProps(block.props ?? {}, block.bindings ?? {}, context, definition, options);
865
+ let props = bound.props;
866
+ let changed = hidden || bound.changed;
867
+ const left = bound.left;
685
868
  if (block.type === FIELD_BLOCK && typeof props.path === 'string' && props.path) {
686
869
  const value = bindingValue(context, props.path, options);
687
870
  if (!isMissing(value)) {
@@ -874,13 +1057,15 @@ export function repeatAncestors(layout, id) {
874
1057
  return path.filter(({ block, slot }) => isRepeatSlot(block.type, slot)).map(({ block }) => block);
875
1058
  }
876
1059
  /**
877
- * The bindable fields a block reads: the template collection's sources, narrowed by every
878
- * collection list and repeat around it. Undefined when unknown (no collection, or a repeat path
1060
+ * The bindable fields a block reads: the template collection's sources (with a `$page` group),
1061
+ * narrowed by every collection list and repeat around it. Undefined when unknown (no collection, or a repeat path
879
1062
  * missing from the sources).
880
1063
  */
881
1064
  export function scopeSources(layout, id, sources, collection) {
882
1065
  const page = collection ? sources[collection] : undefined;
883
- let fields = page?.slice();
1066
+ // `$page.<path>` reads the page's document at the top level too (the same document there).
1067
+ const pageGroup = underRoot(PAGE_PATH, 'Page', page);
1068
+ let fields = page ? [...page, ...(pageGroup ? [pageGroup] : [])] : undefined;
884
1069
  for (const repeat of repeatAncestors(layout, id))
885
1070
  fields = itemSources(repeat, fields, sources, page);
886
1071
  return fields;
@@ -890,7 +1075,7 @@ export function scopeSources(layout, id, sources, collection) {
890
1075
  * target collection, inside a collection list's `item` slot the listed collection, and inside a
891
1076
  * repeat's `item` slot the row (`itemSources`). Problems have the code `binding` (they block
892
1077
  * publishing only). Paths missing from `sources` are left alone: the renderer keeps the literal
893
- * value. `$item`, `$index`, `$visible` and expressions are always allowed.
1078
+ * value. `$item`, `$index` and expressions are always allowed.
894
1079
  */
895
1080
  export function validateBindings(layout, blocks, sources, collection) {
896
1081
  const definitions = new Map(blocks.map((d) => [d.type, d]));
@@ -901,8 +1086,8 @@ export function validateBindings(layout, blocks, sources, collection) {
901
1086
  const definition = definitions.get(block.type);
902
1087
  if (definition && fields) {
903
1088
  for (const [propPath, fieldPath] of Object.entries(block.bindings ?? {})) {
904
- // Expressions (templates, fallbacks, formatters), `$visible` and the row's own value are not checked.
905
- if (propPath === VISIBLE_BINDING || isBindingExpression(fieldPath))
1089
+ // Expressions (templates, fallbacks, formatters) and the row's own value are not checked.
1090
+ if (isBindingExpression(fieldPath))
906
1091
  continue;
907
1092
  if (fieldPath.split('.')[0] === ITEM_PATH || fieldPath === INDEX_PATH)
908
1093
  continue;
@@ -0,0 +1,9 @@
1
+ /** The collection list block: renders its `item` slot once per loaded document. */
2
+ export declare const COLLECTION_LIST_BLOCK = "collectionList";
3
+ /**
4
+ * The repeat block: renders its `item` slot once per row of an array or hasMany field of the
5
+ * current document (`props.path`). The rows are its runtime-only `$items` prop.
6
+ */
7
+ export declare const REPEAT_BLOCK = "repeat";
8
+ /** The URL query parameter of a paginated list's page (`?page=3`). Filter links drop it. */
9
+ export declare const PAGE_PARAM = "page";