payload-canvas 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/README.md +626 -154
  2. package/dist/admin/AiKeyField.d.ts +8 -0
  3. package/dist/admin/AiKeyField.js +54 -0
  4. package/dist/admin/BuilderTab.js +4 -1
  5. package/dist/admin/DocumentEditView.d.ts +9 -0
  6. package/dist/admin/DocumentEditView.js +45 -0
  7. package/dist/admin/LayoutField.d.ts +2 -2
  8. package/dist/admin/LayoutField.js +10 -7
  9. package/dist/admin/TemplateConditionsField.d.ts +9 -0
  10. package/dist/admin/TemplateConditionsField.js +22 -0
  11. package/dist/admin/aiKeyField.scss +58 -0
  12. package/dist/admin/client.d.ts +3 -0
  13. package/dist/admin/client.js +6 -0
  14. package/dist/admin/diff/changes.js +5 -0
  15. package/dist/admin/editor/Canvas.js +20 -5
  16. package/dist/admin/editor/Editor.d.ts +3 -1
  17. package/dist/admin/editor/Editor.js +6 -3
  18. package/dist/admin/editor/Inspector.js +75 -28
  19. package/dist/admin/editor/Library.js +40 -15
  20. package/dist/admin/editor/Outline.js +21 -16
  21. package/dist/admin/editor/Overlay.js +8 -3
  22. package/dist/admin/editor/actions.d.ts +10 -2
  23. package/dist/admin/editor/actions.js +18 -3
  24. package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
  25. package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
  26. package/dist/admin/editor/classes/ClassManager.js +56 -0
  27. package/dist/admin/editor/classes/controller.d.ts +112 -0
  28. package/dist/admin/editor/classes/controller.js +326 -0
  29. package/dist/admin/editor/classes/manager.scss +262 -0
  30. package/dist/admin/editor/classes/managerModel.d.ts +5 -0
  31. package/dist/admin/editor/classes/managerModel.js +27 -0
  32. package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
  33. package/dist/admin/editor/comments/CommentLayer.js +143 -0
  34. package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
  35. package/dist/admin/editor/comments/CommentsPanel.js +73 -0
  36. package/dist/admin/editor/comments/Thread.d.ts +26 -0
  37. package/dist/admin/editor/comments/Thread.js +84 -0
  38. package/dist/admin/editor/comments/comments.scss +539 -0
  39. package/dist/admin/editor/comments/controller.d.ts +48 -0
  40. package/dist/admin/editor/comments/controller.js +142 -0
  41. package/dist/admin/editor/contentMode.d.ts +17 -0
  42. package/dist/admin/editor/contentMode.js +37 -0
  43. package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
  44. package/dist/admin/editor/dnd/DropOutlines.js +73 -0
  45. package/dist/admin/editor/dnd/dnd.scss +43 -0
  46. package/dist/admin/editor/dnd/mode.d.ts +4 -0
  47. package/dist/admin/editor/dnd/mode.js +39 -0
  48. package/dist/admin/editor/editor.scss +13 -58
  49. package/dist/admin/editor/empty/EmptyStart.js +18 -66
  50. package/dist/admin/editor/fields/AddButton.d.ts +15 -0
  51. package/dist/admin/editor/fields/AddButton.js +14 -0
  52. package/dist/admin/editor/fields/ArrayField.js +3 -2
  53. package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
  54. package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
  55. package/dist/admin/editor/fields/ConditionRows.js +137 -0
  56. package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
  57. package/dist/admin/editor/fields/ListWhereField.js +20 -0
  58. package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
  59. package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
  60. package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
  61. package/dist/admin/editor/fields/RelatedField.js +44 -0
  62. package/dist/admin/editor/fields/SortField.d.ts +13 -0
  63. package/dist/admin/editor/fields/SortField.js +37 -0
  64. package/dist/admin/editor/fields/WhereField.d.ts +12 -4
  65. package/dist/admin/editor/fields/WhereField.js +33 -53
  66. package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
  67. package/dist/admin/editor/fields/collectionFields.js +15 -0
  68. package/dist/admin/editor/fields/conditions.d.ts +99 -0
  69. package/dist/admin/editor/fields/conditions.js +339 -0
  70. package/dist/admin/editor/fields/fields.scss +232 -9
  71. package/dist/admin/editor/fields/listOptions.d.ts +44 -0
  72. package/dist/admin/editor/fields/listOptions.js +111 -0
  73. package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
  74. package/dist/admin/editor/fields/queryFilterRows.js +29 -0
  75. package/dist/admin/editor/fields/whereRows.d.ts +11 -12
  76. package/dist/admin/editor/fields/whereRows.js +83 -34
  77. package/dist/admin/editor/icons.d.ts +16 -1
  78. package/dist/admin/editor/icons.js +30 -1
  79. package/dist/admin/editor/inline.js +9 -0
  80. package/dist/admin/editor/insert/InsertHandle.js +4 -1
  81. package/dist/admin/editor/insert/picker.d.ts +3 -1
  82. package/dist/admin/editor/insert/picker.js +17 -10
  83. package/dist/admin/editor/insert/spots.d.ts +12 -1
  84. package/dist/admin/editor/insert/spots.js +49 -10
  85. package/dist/admin/editor/layout/LeftPanel.js +11 -6
  86. package/dist/admin/editor/live/useMultiplayer.js +9 -1
  87. package/dist/admin/editor/menu/blockMenu.js +27 -17
  88. package/dist/admin/editor/names.js +11 -3
  89. package/dist/admin/editor/renderField.d.ts +3 -1
  90. package/dist/admin/editor/renderField.js +63 -12
  91. package/dist/admin/editor/runtime.d.ts +14 -0
  92. package/dist/admin/editor/runtime.js +67 -6
  93. package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
  94. package/dist/admin/editor/sections/ComponentFields.js +116 -0
  95. package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
  96. package/dist/admin/editor/sections/PropertyControls.js +65 -0
  97. package/dist/admin/editor/sections/components.d.ts +29 -0
  98. package/dist/admin/editor/sections/components.js +112 -0
  99. package/dist/admin/editor/sections/components.scss +238 -0
  100. package/dist/admin/editor/sections/variants.d.ts +32 -0
  101. package/dist/admin/editor/sections/variants.js +59 -0
  102. package/dist/admin/editor/sections/variants.scss +90 -0
  103. package/dist/admin/editor/shortcuts.d.ts +4 -1
  104. package/dist/admin/editor/shortcuts.js +19 -3
  105. package/dist/admin/editor/store.d.ts +18 -0
  106. package/dist/admin/editor/store.js +46 -0
  107. package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
  108. package/dist/admin/editor/styles/ClassBar.js +90 -0
  109. package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
  110. package/dist/admin/editor/styles/ClassCss.js +28 -0
  111. package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
  112. package/dist/admin/editor/styles/ClassDialog.js +151 -0
  113. package/dist/admin/editor/styles/ColorPicker.js +5 -2
  114. package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
  115. package/dist/admin/editor/styles/RawClasses.js +184 -32
  116. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
  117. package/dist/admin/editor/styles/StylesPanel.js +53 -14
  118. package/dist/admin/editor/styles/VariantBar.js +2 -2
  119. package/dist/admin/editor/styles/classEdit.d.ts +4 -0
  120. package/dist/admin/editor/styles/classEdit.js +20 -0
  121. package/dist/admin/editor/styles/classes.scss +381 -0
  122. package/dist/admin/editor/styles/context.d.ts +19 -6
  123. package/dist/admin/editor/styles/context.js +24 -6
  124. package/dist/admin/editor/styles/controls.d.ts +3 -1
  125. package/dist/admin/editor/styles/controls.js +30 -12
  126. package/dist/admin/editor/styles/popover.d.ts +6 -0
  127. package/dist/admin/editor/styles/popover.js +5 -5
  128. package/dist/admin/editor/styles/styles.scss +26 -104
  129. package/dist/admin/editor/styles/suggestions.d.ts +22 -0
  130. package/dist/admin/editor/styles/suggestions.js +77 -0
  131. package/dist/admin/editor/styles/tokens.js +14 -0
  132. package/dist/admin/editor/templates/Bindable.js +86 -57
  133. package/dist/admin/editor/templates/SamplePicker.js +1 -1
  134. package/dist/admin/editor/templates/Visibility.d.ts +9 -0
  135. package/dist/admin/editor/templates/Visibility.js +54 -0
  136. package/dist/admin/editor/templates/binding.d.ts +2 -2
  137. package/dist/admin/editor/templates/binding.js +2 -2
  138. package/dist/admin/editor/templates/templates.scss +27 -0
  139. package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
  140. package/dist/admin/editor/templates/visibilityRows.js +83 -0
  141. package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
  142. package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
  143. package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
  144. package/dist/admin/editor/topbar/DocumentActions.js +5 -4
  145. package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
  146. package/dist/admin/editor/topbar/TopBar.js +15 -3
  147. package/dist/admin/editor/topbar/contentMode.scss +35 -0
  148. package/dist/admin/editor/topbar/topbar.scss +3 -1
  149. package/dist/admin/formChoice.d.ts +3 -0
  150. package/dist/admin/formChoice.js +10 -0
  151. package/dist/admin/layoutField.scss +69 -0
  152. package/dist/admin/screen/BuilderScreen.d.ts +6 -1
  153. package/dist/admin/screen/BuilderScreen.js +4 -3
  154. package/dist/admin/server/BuilderView.js +10 -3
  155. package/dist/admin/templateConditions.scss +24 -0
  156. package/dist/ai/adapters/anthropic.js +17 -4
  157. package/dist/ai/adapters/cloudflare-gateway.js +7 -1
  158. package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
  159. package/dist/ai/adapters/openai-compatible.js +1 -0
  160. package/dist/ai/adapters/openrouter.js +2 -0
  161. package/dist/ai/config.d.ts +24 -4
  162. package/dist/ai/config.js +27 -8
  163. package/dist/ai/endpoint.d.ts +5 -2
  164. package/dist/ai/endpoint.js +31 -26
  165. package/dist/ai/images/cloudflare-workers-ai.js +6 -2
  166. package/dist/ai/images/openai.js +8 -3
  167. package/dist/ai/images/openrouter.js +6 -2
  168. package/dist/ai/images/service.d.ts +10 -4
  169. package/dist/ai/images/service.js +23 -7
  170. package/dist/ai/openai-format.d.ts +7 -0
  171. package/dist/ai/openai-format.js +17 -5
  172. package/dist/ai/prompt.d.ts +8 -0
  173. package/dist/ai/prompt.js +25 -5
  174. package/dist/ai/settings/index.d.ts +62 -0
  175. package/dist/ai/settings/index.js +264 -0
  176. package/dist/ai/settings/secret.d.ts +11 -0
  177. package/dist/ai/settings/secret.js +46 -0
  178. package/dist/ai/settings/shared.d.ts +22 -0
  179. package/dist/ai/settings/shared.js +3 -0
  180. package/dist/ai/tools.d.ts +3 -0
  181. package/dist/ai/tools.js +79 -15
  182. package/dist/ai/types.d.ts +43 -0
  183. package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
  184. package/dist/blocks/builtins/adjacentLinks.js +76 -0
  185. package/dist/blocks/builtins/carousel.d.ts +2 -29
  186. package/dist/blocks/builtins/carousel.js +44 -51
  187. package/dist/blocks/builtins/disclosure.d.ts +2 -1
  188. package/dist/blocks/builtins/disclosure.js +22 -32
  189. package/dist/blocks/builtins/embed.d.ts +15 -0
  190. package/dist/blocks/builtins/embed.js +47 -0
  191. package/dist/blocks/builtins/faq.d.ts +1 -1
  192. package/dist/blocks/builtins/faq.js +2 -2
  193. package/dist/blocks/builtins/filterLink.d.ts +1 -19
  194. package/dist/blocks/builtins/filterLink.js +9 -50
  195. package/dist/blocks/builtins/icon.d.ts +2 -0
  196. package/dist/blocks/builtins/icon.js +8 -8
  197. package/dist/blocks/builtins/index.d.ts +18 -13
  198. package/dist/blocks/builtins/index.js +43 -22
  199. package/dist/blocks/builtins/marquee.d.ts +5 -0
  200. package/dist/blocks/builtins/marquee.js +68 -0
  201. package/dist/blocks/builtins/popup.d.ts +5 -0
  202. package/dist/blocks/builtins/popup.js +83 -0
  203. package/dist/blocks/builtins/sectionRef.d.ts +16 -2
  204. package/dist/blocks/builtins/sectionRef.js +34 -12
  205. package/dist/blocks/builtins/shared.d.ts +18 -23
  206. package/dist/blocks/builtins/shared.js +34 -42
  207. package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
  208. package/dist/blocks/builtins/tableOfContents.js +12 -18
  209. package/dist/blocks/builtins/tabs.d.ts +6 -0
  210. package/dist/blocks/builtins/tabs.js +87 -0
  211. package/dist/blocks/client/adjacentLinks.d.ts +4 -0
  212. package/dist/blocks/client/adjacentLinks.js +4 -0
  213. package/dist/blocks/client/carousel.d.ts +45 -0
  214. package/dist/blocks/client/carousel.js +53 -0
  215. package/dist/blocks/client/embed.d.ts +21 -0
  216. package/dist/blocks/client/embed.js +23 -0
  217. package/dist/blocks/client/field.d.ts +7 -0
  218. package/dist/blocks/client/field.js +8 -0
  219. package/dist/blocks/client/filterLink.d.ts +19 -0
  220. package/dist/blocks/client/filterLink.js +30 -0
  221. package/dist/blocks/client/helpers.d.ts +21 -0
  222. package/dist/blocks/client/helpers.js +24 -0
  223. package/dist/blocks/client/marquee.d.ts +14 -0
  224. package/dist/blocks/client/marquee.js +25 -0
  225. package/dist/blocks/client/menu.d.ts +46 -0
  226. package/dist/blocks/client/menu.js +49 -0
  227. package/dist/blocks/client/popup.d.ts +15 -0
  228. package/dist/blocks/client/popup.js +16 -0
  229. package/dist/blocks/client/tabs.d.ts +10 -0
  230. package/dist/blocks/client/tabs.js +11 -0
  231. package/dist/blocks/defaults.d.ts +15 -52
  232. package/dist/blocks/defaults.js +203 -437
  233. package/dist/blocks/index.d.ts +1 -1
  234. package/dist/blocks/index.js +2 -1
  235. package/dist/classes/actions.d.ts +97 -0
  236. package/dist/classes/actions.js +296 -0
  237. package/dist/classes/collection.d.ts +5 -0
  238. package/dist/classes/collection.js +189 -0
  239. package/dist/classes/config.d.ts +34 -0
  240. package/dist/classes/config.js +8 -0
  241. package/dist/classes/endpoints.d.ts +2 -0
  242. package/dist/classes/endpoints.js +120 -0
  243. package/dist/classes/index.d.ts +36 -0
  244. package/dist/classes/index.js +42 -0
  245. package/dist/classes/mcp.d.ts +6 -0
  246. package/dist/classes/mcp.js +161 -0
  247. package/dist/classes/shared.d.ts +131 -0
  248. package/dist/classes/shared.js +300 -0
  249. package/dist/classes/sheet.d.ts +34 -0
  250. package/dist/classes/sheet.js +126 -0
  251. package/dist/classes/usage.d.ts +57 -0
  252. package/dist/classes/usage.js +208 -0
  253. package/dist/comments/collection.d.ts +38 -0
  254. package/dist/comments/collection.js +226 -0
  255. package/dist/comments/config.d.ts +15 -0
  256. package/dist/comments/config.js +2 -0
  257. package/dist/comments/index.d.ts +20 -0
  258. package/dist/comments/index.js +22 -0
  259. package/dist/comments/shared.d.ts +54 -0
  260. package/dist/comments/shared.js +104 -0
  261. package/dist/core/bindings.d.ts +77 -32
  262. package/dist/core/bindings.js +319 -134
  263. package/dist/core/blockNames.d.ts +9 -0
  264. package/dist/core/blockNames.js +11 -0
  265. package/dist/core/blocks.d.ts +21 -8
  266. package/dist/core/blocks.js +37 -16
  267. package/dist/core/classes.d.ts +16 -8
  268. package/dist/core/classes.js +31 -27
  269. package/dist/core/components.d.ts +72 -0
  270. package/dist/core/components.js +294 -0
  271. package/dist/core/contentMode.d.ts +27 -0
  272. package/dist/core/contentMode.js +0 -0
  273. package/dist/core/dropTarget.d.ts +11 -0
  274. package/dist/core/dropTarget.js +24 -1
  275. package/dist/core/fields.d.ts +5 -0
  276. package/dist/core/fields.js +11 -0
  277. package/dist/core/headings.d.ts +5 -2
  278. package/dist/core/headings.js +14 -6
  279. package/dist/core/index.d.ts +8 -3
  280. package/dist/core/index.js +8 -3
  281. package/dist/core/layers.d.ts +9 -0
  282. package/dist/core/layers.js +29 -0
  283. package/dist/core/operations.d.ts +6 -0
  284. package/dist/core/operations.js +85 -24
  285. package/dist/core/payloadBlocks.js +5 -1
  286. package/dist/core/references.js +28 -0
  287. package/dist/core/schema.js +20 -6
  288. package/dist/core/sectionOrigin.d.ts +6 -0
  289. package/dist/core/sectionOrigin.js +21 -0
  290. package/dist/core/sections.d.ts +72 -0
  291. package/dist/core/sections.js +331 -0
  292. package/dist/core/templateChoice.d.ts +24 -0
  293. package/dist/core/templateChoice.js +43 -0
  294. package/dist/core/tree.js +18 -6
  295. package/dist/core/types.d.ts +148 -18
  296. package/dist/core/validate.d.ts +4 -1
  297. package/dist/core/validate.js +28 -11
  298. package/dist/core/visibility.d.ts +63 -0
  299. package/dist/core/visibility.js +214 -0
  300. package/dist/core/whereValues.d.ts +22 -0
  301. package/dist/core/whereValues.js +43 -0
  302. package/dist/css/classes.d.ts +16 -0
  303. package/dist/css/classes.js +172 -0
  304. package/dist/css/index.d.ts +32 -1
  305. package/dist/css/index.js +64 -5
  306. package/dist/css/tokens.d.ts +10 -0
  307. package/dist/css/tokens.js +23 -10
  308. package/dist/index.d.ts +5 -2
  309. package/dist/index.js +6 -1
  310. package/dist/live/contentMode.d.ts +24 -0
  311. package/dist/live/contentMode.js +39 -0
  312. package/dist/live/endpoints.js +3 -0
  313. package/dist/live/session.d.ts +5 -0
  314. package/dist/live/session.js +8 -0
  315. package/dist/live/types.d.ts +16 -1
  316. package/dist/mcp/index.d.ts +10 -1
  317. package/dist/mcp/index.js +146 -54
  318. package/dist/mcp/shared.d.ts +93 -3
  319. package/dist/mcp/shared.js +211 -15
  320. package/dist/plugin/hook.d.ts +7 -1
  321. package/dist/plugin/hook.js +30 -4
  322. package/dist/plugin/index.d.ts +19 -8
  323. package/dist/plugin/index.js +89 -20
  324. package/dist/plugin/links.d.ts +24 -0
  325. package/dist/plugin/links.js +27 -0
  326. package/dist/plugin/listCollections.d.ts +9 -7
  327. package/dist/plugin/listCollections.js +30 -21
  328. package/dist/plugin/sections.d.ts +14 -7
  329. package/dist/plugin/sections.js +69 -23
  330. package/dist/plugin/sectionsUsedIn.d.ts +6 -0
  331. package/dist/plugin/sectionsUsedIn.js +24 -0
  332. package/dist/plugin/templateEndpoint.d.ts +9 -0
  333. package/dist/plugin/templateEndpoint.js +49 -0
  334. package/dist/plugin/templates.js +23 -8
  335. package/dist/protocol/index.d.ts +16 -1
  336. package/dist/react/canvas/BuilderCanvas.js +144 -21
  337. package/dist/react/canvas/classes.d.ts +17 -0
  338. package/dist/react/canvas/classes.js +102 -0
  339. package/dist/react/canvas/controls.d.ts +31 -0
  340. package/dist/react/canvas/controls.js +75 -0
  341. package/dist/react/canvas/fetchDocs.d.ts +2 -2
  342. package/dist/react/canvas/fetchDocs.js +16 -8
  343. package/dist/react/canvas/measure.d.ts +9 -0
  344. package/dist/react/canvas/measure.js +106 -7
  345. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  346. package/dist/react/canvas/resolveLayout.js +4 -3
  347. package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
  348. package/dist/react/classes/ClassesStyle.d.ts +27 -0
  349. package/dist/react/classes/ClassesStyle.js +27 -0
  350. package/dist/react/components/Button.d.ts +2 -11
  351. package/dist/react/components/Button.js +8 -43
  352. package/dist/react/components/CollectionList.d.ts +4 -1
  353. package/dist/react/components/CollectionList.js +10 -3
  354. package/dist/react/components/Container.d.ts +5 -2
  355. package/dist/react/components/Container.js +7 -4
  356. package/dist/react/components/Field.js +3 -14
  357. package/dist/react/components/Link.d.ts +1 -1
  358. package/dist/react/components/Link.js +5 -3
  359. package/dist/react/components/List.d.ts +1 -1
  360. package/dist/react/components/List.js +2 -2
  361. package/dist/react/components/Menu.d.ts +10 -1
  362. package/dist/react/components/Menu.js +39 -12
  363. package/dist/react/components/RichText.d.ts +3 -4
  364. package/dist/react/components/RichText.js +5 -5
  365. package/dist/react/components/builtins/Accordion.d.ts +4 -3
  366. package/dist/react/components/builtins/Accordion.js +6 -5
  367. package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
  368. package/dist/react/components/builtins/AdjacentLinks.js +20 -0
  369. package/dist/react/components/builtins/Carousel.d.ts +21 -10
  370. package/dist/react/components/builtins/Carousel.js +175 -100
  371. package/dist/react/components/builtins/Disclosure.d.ts +4 -3
  372. package/dist/react/components/builtins/Disclosure.js +6 -5
  373. package/dist/react/components/builtins/Embed.d.ts +11 -0
  374. package/dist/react/components/builtins/Embed.js +23 -0
  375. package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
  376. package/dist/react/components/builtins/EmbedHtml.js +51 -0
  377. package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
  378. package/dist/react/components/builtins/EmbedPreview.js +105 -0
  379. package/dist/react/components/builtins/FilterLink.d.ts +1 -1
  380. package/dist/react/components/builtins/FilterLink.js +4 -4
  381. package/dist/react/components/builtins/Marquee.d.ts +8 -0
  382. package/dist/react/components/builtins/Marquee.js +15 -0
  383. package/dist/react/components/builtins/Popup.d.ts +26 -0
  384. package/dist/react/components/builtins/Popup.js +146 -0
  385. package/dist/react/components/builtins/SectionRef.d.ts +4 -3
  386. package/dist/react/components/builtins/SectionRef.js +9 -5
  387. package/dist/react/components/builtins/Tab.d.ts +7 -0
  388. package/dist/react/components/builtins/Tab.js +21 -0
  389. package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
  390. package/dist/react/components/builtins/TableOfContents.js +22 -7
  391. package/dist/react/components/builtins/Tabs.d.ts +17 -0
  392. package/dist/react/components/builtins/Tabs.js +71 -0
  393. package/dist/react/components/builtins/index.d.ts +37 -20
  394. package/dist/react/components/builtins/index.js +54 -20
  395. package/dist/react/components/builtins/tabsContext.d.ts +12 -0
  396. package/dist/react/components/builtins/tabsContext.js +6 -0
  397. package/dist/react/components/index.js +11 -8
  398. package/dist/react/components/lazy.d.ts +32 -0
  399. package/dist/react/components/lazy.js +20 -0
  400. package/dist/react/components/lazyBlock.d.ts +17 -0
  401. package/dist/react/components/lazyBlock.js +23 -0
  402. package/dist/react/index.d.ts +6 -3
  403. package/dist/react/index.js +5 -2
  404. package/dist/react/render/RenderLayout.d.ts +9 -7
  405. package/dist/react/render/RenderLayout.js +96 -45
  406. package/dist/react/render/canvasMode.d.ts +13 -0
  407. package/dist/react/render/canvasMode.js +13 -0
  408. package/dist/react/render/canvasServer.js +4 -3
  409. package/dist/react/render/canvasServerTypes.d.ts +5 -0
  410. package/dist/react/render/lists.d.ts +36 -4
  411. package/dist/react/render/lists.js +132 -15
  412. package/dist/react/render/marks.d.ts +15 -0
  413. package/dist/react/render/marks.js +23 -0
  414. package/dist/react/render/payload.d.ts +8 -1
  415. package/dist/react/render/payload.js +12 -3
  416. package/dist/react/render/preview.d.ts +11 -0
  417. package/dist/react/render/preview.js +13 -0
  418. package/dist/react/render/relations.d.ts +10 -0
  419. package/dist/react/render/relations.js +39 -0
  420. package/dist/react/render/resolve.d.ts +8 -4
  421. package/dist/react/render/resolve.js +11 -5
  422. package/dist/react/render/reveal.d.ts +17 -0
  423. package/dist/react/render/reveal.js +39 -0
  424. package/dist/react/render/sections.d.ts +11 -5
  425. package/dist/react/render/sections.js +52 -24
  426. package/dist/react/render/templates.d.ts +47 -0
  427. package/dist/react/render/templates.js +139 -0
  428. package/dist/react/render/types.d.ts +62 -5
  429. package/dist/react/server.d.ts +2 -37
  430. package/dist/react/server.js +8 -133
  431. package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
  432. package/dist/react/theme/ThemeLiveLoader.js +5 -0
  433. package/dist/react/theme/ThemeStyle.js +1 -1
  434. package/dist/theme/admin/Variables.d.ts +11 -0
  435. package/dist/theme/admin/Variables.js +115 -0
  436. package/dist/theme/admin/fields.scss +113 -0
  437. package/dist/theme/client.d.ts +1 -0
  438. package/dist/theme/client.js +2 -0
  439. package/dist/theme/css.d.ts +6 -1
  440. package/dist/theme/css.js +12 -4
  441. package/dist/theme/global.js +83 -0
  442. package/dist/theme/index.d.ts +1 -0
  443. package/dist/theme/index.js +1 -0
  444. package/dist/theme/server.d.ts +15 -0
  445. package/dist/theme/server.js +43 -0
  446. package/dist/theme/usage.d.ts +23 -0
  447. package/dist/theme/usage.js +68 -0
  448. package/dist/theme/variables.d.ts +72 -0
  449. package/dist/theme/variables.js +231 -0
  450. package/package.json +4 -2
  451. package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
  452. package/dist/admin/editor/styles/SiteClasses.js +0 -31
  453. package/dist/blocks/builtins/headingId.d.ts +0 -15
  454. package/dist/blocks/builtins/headingId.js +0 -36
  455. package/dist/blocks/builtins/lightbox.d.ts +0 -43
  456. package/dist/blocks/builtins/lightbox.js +0 -93
  457. package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
  458. package/dist/blocks/builtins/mediaBackdrop.js +0 -79
  459. package/dist/react/components/Quote.d.ts +0 -3
  460. package/dist/react/components/Quote.js +0 -12
  461. package/dist/react/components/Spacer.d.ts +0 -3
  462. package/dist/react/components/Spacer.js +0 -6
  463. package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
  464. package/dist/react/components/builtins/BackdropVideo.js +0 -16
  465. package/dist/react/components/builtins/Lightbox.d.ts +0 -45
  466. package/dist/react/components/builtins/Lightbox.js +0 -252
  467. package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
  468. package/dist/react/components/builtins/MediaBackdrop.js +0 -61
@@ -0,0 +1,102 @@
1
+ 'use client';
2
+ // Editable classes on the canvas: the latest drafts, with the editor's unsaved edits, compiled in
3
+ // the browser with the same code as the site's stylesheet (`css/classes.ts`). The editor posts
4
+ // every change on `CLASSES_CHANNEL`, so a class edit shows on the canvas at once.
5
+ import { useEffect, useRef, useState } from 'react';
6
+ import { CLASSES_CHANNEL } from '../../classes/shared.js';
7
+ import { compileClassSheet } from '../../css/classes.js';
8
+ /** The classes from the endpoint. An empty list when it fails (the canvas then works without them). */
9
+ export async function fetchCanvasClasses(endpoint) {
10
+ try {
11
+ const res = await fetch(endpoint, { credentials: 'include', cache: 'no-store' });
12
+ if (!res.ok)
13
+ return [];
14
+ return (await res.json()).classes ?? [];
15
+ }
16
+ catch {
17
+ return [];
18
+ }
19
+ }
20
+ /**
21
+ * The classes the canvas shows. Null while the first list loads; always an empty list without an
22
+ * endpoint. Follows the editor's edits (BroadcastChannel) and loads again when the page becomes
23
+ * visible.
24
+ */
25
+ export function useCanvasClasses(endpoint) {
26
+ // Keyed by endpoint, so a new endpoint reads as loading until its list arrives.
27
+ const [state, setState] = useState(null);
28
+ useEffect(() => {
29
+ if (!endpoint)
30
+ return;
31
+ let cancelled = false;
32
+ // The editor's list wins over a fetch that started before it arrived.
33
+ let fromEditor = false;
34
+ // The same classes again (the editor's answer after a save) compile nothing new.
35
+ let last = '';
36
+ const show = (classes) => {
37
+ const key = JSON.stringify(classes.map((c) => [c.name, c.styles ?? '', c.css ?? '', c.previousNames ?? []]));
38
+ if (key === last)
39
+ return;
40
+ last = key;
41
+ setState({ endpoint, classes });
42
+ };
43
+ const reload = () => void fetchCanvasClasses(endpoint).then((list) => {
44
+ if (!cancelled && !fromEditor)
45
+ show(list);
46
+ });
47
+ const channel = typeof BroadcastChannel === 'undefined' ? null : new BroadcastChannel(CLASSES_CHANNEL);
48
+ channel?.addEventListener('message', (event) => {
49
+ if (event.data?.type !== 'classes' || !Array.isArray(event.data.classes))
50
+ return;
51
+ fromEditor = true;
52
+ show(event.data.classes);
53
+ });
54
+ const onVisible = () => {
55
+ if (document.visibilityState !== 'visible')
56
+ return;
57
+ fromEditor = false;
58
+ reload();
59
+ };
60
+ reload();
61
+ // An open editor answers with its list (its unsaved edits included).
62
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- a BroadcastChannel has no target origin
63
+ channel?.postMessage({ type: 'hello' });
64
+ document.addEventListener('visibilitychange', onVisible);
65
+ return () => {
66
+ cancelled = true;
67
+ channel?.close();
68
+ document.removeEventListener('visibilitychange', onVisible);
69
+ };
70
+ }, [endpoint]);
71
+ if (!endpoint)
72
+ return EMPTY_LIST;
73
+ return state?.endpoint === endpoint ? state.classes : null;
74
+ }
75
+ const EMPTY_LIST = [];
76
+ const EMPTY_SHEET = { css: '', errors: {}, names: [] };
77
+ /**
78
+ * The stylesheet of `classes`, compiled against the canvas's CSS input. Null until the first
79
+ * compile is done (or while `classes` loads). A result shows unless a newer one already did, so a
80
+ * slider drag updates the canvas while it moves.
81
+ */
82
+ export function useClassSheet(input, classes, plugins) {
83
+ const [sheet, setSheet] = useState(null);
84
+ const started = useRef(0);
85
+ const shown = useRef(0);
86
+ useEffect(() => {
87
+ if (!classes || classes.length === 0 || !input)
88
+ return;
89
+ const run = ++started.current;
90
+ // A short pause: typing sends many lists in a row; compile the last of them.
91
+ const timer = window.setTimeout(() => void compileClassSheet(input, classes, plugins).then((next) => {
92
+ if (run <= shown.current)
93
+ return;
94
+ shown.current = run;
95
+ setSheet(next);
96
+ }), 16);
97
+ return () => window.clearTimeout(timer);
98
+ }, [input, classes, plugins]);
99
+ if (!classes)
100
+ return null;
101
+ return classes.length === 0 ? EMPTY_SHEET : sheet;
102
+ }
@@ -0,0 +1,31 @@
1
+ /** The canvas control (an element with `data-builder-control`) at or around `target`, or null. */
2
+ export declare function controlAt(target: EventTarget | null): Element | null;
3
+ /** Elements that show over the page in the browser's top layer: an open popover or modal dialog. */
4
+ export declare const TOP_LAYER_SELECTOR = ":popover-open, :modal";
5
+ /** True when the element is in the top layer. False in browsers that do not know the selectors. */
6
+ export declare function inTopLayer(el: Element): boolean;
7
+ /**
8
+ * True when the point is on the backdrop of an open popup on the canvas: the event's target is
9
+ * the top-layer element, but the point lies outside its box. A click there closes the popup, as
10
+ * on the site, and selects nothing. The hover outline and the "+" do not show there.
11
+ */
12
+ export declare function onBackdrop(target: EventTarget | null, x: number, y: number): boolean;
13
+ /** The `<details>` whose `<summary>` holds `target`, or null. */
14
+ export declare function summaryOwner(target: EventTarget | null): HTMLDetailsElement | null;
15
+ /**
16
+ * The closed `<details>` to open for `el`, outermost first: `el` itself when it is one (a selected
17
+ * disclosure shows its content), and those whose content (not their summary) holds it. The
18
+ * summary of a closed item is visible, so it opens nothing.
19
+ */
20
+ export declare function closedDetailsAround(el: Element): HTMLDetailsElement[];
21
+ /**
22
+ * Makes a selected block visible: opens the closed `<details>` around it, then sends the reveal
23
+ * event, so interactive blocks around it (a carousel, tabs, a popup) can show it. `keepClosed`
24
+ * leaves an item closed (one the user just closed with a click on its summary).
25
+ */
26
+ export declare function revealInCanvas(el: Element, keepClosed?: (details: HTMLDetailsElement) => boolean): void;
27
+ /**
28
+ * The block's element that shows on screen: a block can render more than once (a mobile and a
29
+ * desktop copy), and only one of them has a box. Without a box (inside a closed item): the first.
30
+ */
31
+ export declare function blockElement(id: string): HTMLElement | null;
@@ -0,0 +1,75 @@
1
+ // Interactive blocks in the canvas: controls that work as on the site, disclosures that open and
2
+ // close, and the reveal step that brings a selected block out of a closed item or another slide.
3
+ import { CANVAS_CONTROL_ATTRIBUTE, revealBlock } from '../render/reveal.js';
4
+ const CONTROL_SELECTOR = `[${CANVAS_CONTROL_ATTRIBUTE}]`;
5
+ /** The canvas control (an element with `data-builder-control`) at or around `target`, or null. */
6
+ export function controlAt(target) {
7
+ return target instanceof Element ? target.closest(CONTROL_SELECTOR) : null;
8
+ }
9
+ /** Elements that show over the page in the browser's top layer: an open popover or modal dialog. */
10
+ export const TOP_LAYER_SELECTOR = ':popover-open, :modal';
11
+ /** True when the element is in the top layer. False in browsers that do not know the selectors. */
12
+ export function inTopLayer(el) {
13
+ try {
14
+ return el.matches(TOP_LAYER_SELECTOR);
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ /**
21
+ * True when the point is on the backdrop of an open popup on the canvas: the event's target is
22
+ * the top-layer element, but the point lies outside its box. A click there closes the popup, as
23
+ * on the site, and selects nothing. The hover outline and the "+" do not show there.
24
+ */
25
+ export function onBackdrop(target, x, y) {
26
+ if (!(target instanceof Element) || !inTopLayer(target))
27
+ return false;
28
+ const box = target.getBoundingClientRect();
29
+ return x < box.left || x > box.right || y < box.top || y > box.bottom;
30
+ }
31
+ /** The `<details>` whose `<summary>` holds `target`, or null. */
32
+ export function summaryOwner(target) {
33
+ const summary = target instanceof Element ? target.closest('summary') : null;
34
+ const details = summary?.parentElement;
35
+ return details instanceof HTMLDetailsElement && summary === details.querySelector(':scope > summary') ? details : null;
36
+ }
37
+ /**
38
+ * The closed `<details>` to open for `el`, outermost first: `el` itself when it is one (a selected
39
+ * disclosure shows its content), and those whose content (not their summary) holds it. The
40
+ * summary of a closed item is visible, so it opens nothing.
41
+ */
42
+ export function closedDetailsAround(el) {
43
+ const closed = [];
44
+ for (let node = el; node; node = node.parentElement) {
45
+ if (!(node instanceof HTMLDetailsElement) || node.open)
46
+ continue;
47
+ if (summaryOwner(el) === node)
48
+ continue;
49
+ closed.unshift(node);
50
+ }
51
+ return closed;
52
+ }
53
+ /**
54
+ * Makes a selected block visible: opens the closed `<details>` around it, then sends the reveal
55
+ * event, so interactive blocks around it (a carousel, tabs, a popup) can show it. `keepClosed`
56
+ * leaves an item closed (one the user just closed with a click on its summary).
57
+ */
58
+ export function revealInCanvas(el, keepClosed) {
59
+ // Outermost first: an inner item opens inside an open outer one.
60
+ for (const details of closedDetailsAround(el))
61
+ if (!keepClosed?.(details))
62
+ details.open = true;
63
+ revealBlock(el);
64
+ }
65
+ /**
66
+ * The block's element that shows on screen: a block can render more than once (a mobile and a
67
+ * desktop copy), and only one of them has a box. Without a box (inside a closed item): the first.
68
+ */
69
+ export function blockElement(id) {
70
+ const all = document.querySelectorAll(`[data-block-id="${CSS.escape(id)}"]`);
71
+ for (const el of all)
72
+ if (el.getClientRects().length > 0)
73
+ return el;
74
+ return all[0] ?? null;
75
+ }
@@ -13,8 +13,8 @@ export declare function createRestFetchDocs(api: string, locale?: string | null)
13
13
  export declare function whereParams(value: unknown, prefix?: string): Array<[string, string]>;
14
14
  /**
15
15
  * Loads a collection list's documents over REST (`depth=1`, latest drafts, in `locale`), cached
16
- * for the life of the iframe. The page's own document is filtered out here, so one request serves
17
- * every page. The query's `where` goes along as Payload's bracket query. A filter that matches
16
+ * for the life of the iframe. The query's `where` (with the current document left out) goes along
17
+ * as Payload's bracket query, so pages hold exactly `limit` documents. A filter that matches
18
18
  * nothing (`none`) loads nothing.
19
19
  */
20
20
  export declare function fetchListItems(api: string, query: ListQuery, locale?: string | null, seed?: number): Promise<Doc[]>;
@@ -60,10 +60,21 @@ export function whereParams(value, prefix = 'where') {
60
60
  return [[prefix, String(value)]];
61
61
  return Object.entries(value).flatMap(([key, inner]) => whereParams(inner, `${prefix}[${key}]`));
62
62
  }
63
+ /** The where a list query sends: the picked ids, the current document left out, and the list's own where. */
64
+ function listWhere(query) {
65
+ const parts = [];
66
+ if (query.exclude !== undefined)
67
+ parts.push({ id: { not_equals: query.exclude } });
68
+ if (query.ids)
69
+ parts.push({ id: { in: query.ids } });
70
+ if (query.where)
71
+ parts.push(query.where);
72
+ return parts.length === 0 ? undefined : parts.length === 1 ? parts[0] : { and: parts };
73
+ }
63
74
  /**
64
75
  * Loads a collection list's documents over REST (`depth=1`, latest drafts, in `locale`), cached
65
- * for the life of the iframe. The page's own document is filtered out here, so one request serves
66
- * every page. The query's `where` goes along as Payload's bracket query. A filter that matches
76
+ * for the life of the iframe. The query's `where` (with the current document left out) goes along
77
+ * as Payload's bracket query, so pages hold exactly `limit` documents. A filter that matches
67
78
  * nothing (`none`) loads nothing.
68
79
  */
69
80
  export function fetchListItems(api, query, locale, seed = 0) {
@@ -77,9 +88,9 @@ export function fetchListPage(api, query, locale, seed = 0) {
77
88
  if (query.none)
78
89
  return Promise.resolve({ docs: [], totalPages: 0 });
79
90
  const wanted = listRequest(query);
80
- const limit = wanted.limit + (query.exclude === undefined ? 0 : 1);
91
+ const limit = wanted.limit;
81
92
  const depth = String(query.depth ?? 1);
82
- const where = whereParams(query.ids ? (query.where ? { and: [{ id: { in: query.ids } }, query.where] } : { id: { in: query.ids } }) : query.where);
93
+ const where = whereParams(listWhere(query));
83
94
  const page = wanted.page ? String(wanted.page) : '';
84
95
  const key = `${api}\u0000${locale ?? ''}\u0000${query.collection}\u0000${limit}\u0000${wanted.sort}\u0000${depth}\u0000${JSON.stringify(where)}\u0000${page}`;
85
96
  let request = listCache.get(key);
@@ -102,10 +113,7 @@ export function fetchListPage(api, query, locale, seed = 0) {
102
113
  });
103
114
  listCache.set(key, request);
104
115
  }
105
- return request.then((result) => ({
106
- docs: arrangeListDocs(result.docs.filter((doc) => query.exclude === undefined || String(doc.id) !== String(query.exclude)), query, seed),
107
- totalPages: result.totalPages,
108
- }));
116
+ return request.then((result) => ({ docs: arrangeListDocs(result.docs, query, seed), totalPages: result.totalPages }));
109
117
  }
110
118
  /**
111
119
  * Drops a document from the cache (every locale) and the list results of its collection, so the
@@ -3,6 +3,15 @@ import type { Axis, CanvasMeasurement, Rect } from '../../core/index.js';
3
3
  export declare function sameMeasurement(a: CanvasMeasurement | null, b: CanvasMeasurement): boolean;
4
4
  /** The smallest rect around all the rects that have a size. Null when none has. */
5
5
  export declare function unionRect(rects: readonly Rect[]): Rect | null;
6
+ /** The area children may show in, by its edges. A missing edge does not clip. */
7
+ export type ClipArea = {
8
+ left: number;
9
+ top: number;
10
+ right: number;
11
+ bottom: number;
12
+ };
13
+ /** The part of `rect` inside `area`. Outside it: an empty rect on the area's nearest edge. */
14
+ export declare function clipRect(rect: Rect, area: ClipArea | null): Rect;
6
15
  /** The direction children flow in: from flex direction or the number of grid columns. */
7
16
  export declare function axisOf(el: Element): Axis;
8
17
  /**
@@ -1,5 +1,7 @@
1
1
  import { LAYOUT_ROOT_ATTRIBUTE, REGION_ATTRIBUTE } from '../render/regions.js';
2
+ import { inTopLayer, TOP_LAYER_SELECTOR } from './controls.js';
2
3
  const sameRect = (a, b) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
4
+ const sameLayer = (a, b) => a.layer === b.layer;
3
5
  /** True when two measurements are equal. Stops at the first difference (scrolling changes `scroll` first). */
4
6
  export function sameMeasurement(a, b) {
5
7
  if (!a)
@@ -11,13 +13,13 @@ export function sameMeasurement(a, b) {
11
13
  if (a.blocks.length !== b.blocks.length || a.slots.length !== b.slots.length)
12
14
  return false;
13
15
  for (let i = 0; i < a.blocks.length; i++) {
14
- if (a.blocks[i].id !== b.blocks[i].id || !sameRect(a.blocks[i].rect, b.blocks[i].rect))
16
+ if (a.blocks[i].id !== b.blocks[i].id || !sameRect(a.blocks[i].rect, b.blocks[i].rect) || !sameLayer(a.blocks[i], b.blocks[i]))
15
17
  return false;
16
18
  }
17
19
  for (let i = 0; i < a.slots.length; i++) {
18
20
  const x = a.slots[i];
19
21
  const y = b.slots[i];
20
- if (x.ownerId !== y.ownerId || x.slot !== y.slot || x.axis !== y.axis || x.empty !== y.empty || !sameRect(x.rect, y.rect))
22
+ if (x.ownerId !== y.ownerId || x.slot !== y.slot || x.axis !== y.axis || x.empty !== y.empty || !sameRect(x.rect, y.rect) || !sameLayer(x, y))
21
23
  return false;
22
24
  }
23
25
  if (Boolean(a.root) !== Boolean(b.root) || (a.root && b.root && !sameRect(a.root, b.root)))
@@ -30,6 +32,14 @@ export function sameMeasurement(a, b) {
30
32
  if (ra[i].name !== rb[i].name || !sameRect(ra[i].rect, rb[i].rect))
31
33
  return false;
32
34
  }
35
+ const la = a.layers ?? [];
36
+ const lb = b.layers ?? [];
37
+ if (la.length !== lb.length)
38
+ return false;
39
+ for (let i = 0; i < la.length; i++) {
40
+ if (la[i].ownerId !== lb[i].ownerId || !sameRect(la[i].rect, lb[i].rect))
41
+ return false;
42
+ }
33
43
  return true;
34
44
  }
35
45
  function toRect(r) {
@@ -56,6 +66,90 @@ function boxOf(el) {
56
66
  return own;
57
67
  return unionRect(Array.from(el.children, boxOf)) ?? own;
58
68
  }
69
+ const NO_CLIP = { left: -Infinity, top: -Infinity, right: Infinity, bottom: Infinity };
70
+ /** The part of `rect` inside `area`. Outside it: an empty rect on the area's nearest edge. */
71
+ export function clipRect(rect, area) {
72
+ if (!area)
73
+ return rect;
74
+ const left = Math.min(Math.max(rect.x, area.left), area.right);
75
+ const top = Math.min(Math.max(rect.y, area.top), area.bottom);
76
+ const right = Math.max(Math.min(rect.x + rect.width, area.right), left);
77
+ const bottom = Math.max(Math.min(rect.y + rect.height, area.bottom), top);
78
+ if (left === rect.x && top === rect.y && right === rect.x + rect.width && bottom === rect.y + rect.height)
79
+ return rect;
80
+ return { x: left, y: top, width: right - left, height: bottom - top };
81
+ }
82
+ const intersect = (a, b) => ({
83
+ left: Math.max(a.left, b.left),
84
+ top: Math.max(a.top, b.top),
85
+ right: Math.min(a.right, b.right),
86
+ bottom: Math.min(a.bottom, b.bottom),
87
+ });
88
+ /** A fixed element and an open modal or popover (the top layer) escape the clipping of their ancestors. */
89
+ function escapesClip(el, style) {
90
+ return style.position === 'fixed' || inTopLayer(el);
91
+ }
92
+ /**
93
+ * The open popups on the canvas (top-layer elements), outermost first, and a function that gives
94
+ * the index of the innermost one around an element (-1 on the page).
95
+ */
96
+ function findLayers(root) {
97
+ let elements = [];
98
+ try {
99
+ elements = Array.from(root.querySelectorAll(TOP_LAYER_SELECTOR));
100
+ }
101
+ catch {
102
+ // A browser without the selectors has no layers.
103
+ }
104
+ const layers = elements.map((el) => ({
105
+ ownerId: el.closest('[data-block-id]')?.dataset.blockId ?? null,
106
+ rect: toRect(el.getBoundingClientRect()),
107
+ }));
108
+ const layerOf = (el) => {
109
+ for (let i = elements.length - 1; i >= 0; i--)
110
+ if (elements[i].contains(el))
111
+ return i;
112
+ return -1;
113
+ };
114
+ return { layers, layerOf };
115
+ }
116
+ /** `{ layer }` for an element in a layer, else nothing: a measurement without popups stays as it was. */
117
+ const layerField = (index) => (index < 0 ? {} : { layer: index });
118
+ /**
119
+ * The area each element's children show in: its ancestors' boxes that clip their overflow
120
+ * (`overflow` other than `visible`), up to `root`. A carousel's viewport hides the slides outside
121
+ * it, so their rects shrink to the visible part (empty when hidden), and the pointer never finds
122
+ * a hidden slide. Cached per measurement.
123
+ */
124
+ function createClipper(root) {
125
+ const areas = new Map();
126
+ const areaInside = (el) => {
127
+ if (!el || el === root || !root.contains(el))
128
+ return null;
129
+ const cached = areas.get(el);
130
+ if (cached !== undefined)
131
+ return cached;
132
+ const style = getComputedStyle(el);
133
+ const outer = escapesClip(el, style) ? null : areaInside(el.parentElement);
134
+ let area = outer;
135
+ if (style.display !== 'contents' && (style.overflowX !== 'visible' || style.overflowY !== 'visible')) {
136
+ const box = el.getBoundingClientRect();
137
+ const own = {
138
+ ...NO_CLIP,
139
+ ...(style.overflowX !== 'visible' ? { left: box.left, right: box.right } : {}),
140
+ ...(style.overflowY !== 'visible' ? { top: box.top, bottom: box.bottom } : {}),
141
+ };
142
+ area = outer ? intersect(own, outer) : own;
143
+ }
144
+ areas.set(el, area);
145
+ return area;
146
+ };
147
+ /** The element's box, clipped by the ancestors that clip it. */
148
+ return (el) => {
149
+ const box = boxOf(el);
150
+ return escapesClip(el, getComputedStyle(el)) ? box : clipRect(box, areaInside(el.parentElement));
151
+ };
152
+ }
59
153
  /** The direction children flow in: from flex direction or the number of grid columns. */
60
154
  export function axisOf(el) {
61
155
  const style = getComputedStyle(el);
@@ -75,10 +169,14 @@ export function axisOf(el) {
75
169
  * The placeholder wins, so the drop target sees `empty: true`.
76
170
  */
77
171
  export function measure(root) {
78
- const blocks = Array.from(root.querySelectorAll('[data-block-id]'), (el) => ({
79
- id: el.dataset.blockId ?? '',
80
- rect: boxOf(el),
81
- }));
172
+ const visibleBox = createClipper(root);
173
+ const { layers, layerOf } = findLayers(root);
174
+ // An open popup's block takes its box, so its outline, name and action bar frame the box.
175
+ const layerBox = new Map(layers.flatMap((layer) => (layer.ownerId ? [[layer.ownerId, layer.rect]] : [])));
176
+ const blocks = Array.from(root.querySelectorAll('[data-block-id]'), (el) => {
177
+ const id = el.dataset.blockId ?? '';
178
+ return { id, rect: layerBox.get(id) ?? visibleBox(el), ...layerField(layerOf(el)) };
179
+ });
82
180
  const slots = new Map();
83
181
  for (const el of root.querySelectorAll('[data-slot-owner]')) {
84
182
  const ownerId = el.dataset.slotOwner ?? '';
@@ -89,7 +187,7 @@ export function measure(root) {
89
187
  continue;
90
188
  // An empty placeholder takes the container's axis, so the drop indicator matches the layout.
91
189
  const axis = empty && el.parentElement ? axisOf(el.parentElement) : axisOf(el);
92
- slots.set(key, { ownerId, slot, rect: boxOf(el), axis, empty });
190
+ slots.set(key, { ownerId, slot, rect: visibleBox(el), axis, empty, ...layerField(layerOf(el)) });
93
191
  }
94
192
  // In a page frame the layout fills its outlet, not the whole canvas: the root list's axis and
95
193
  // box come from the outlet, so fixed regions never count as part of the layout.
@@ -109,6 +207,7 @@ export function measure(root) {
109
207
  slots: [...slots.values()],
110
208
  rootAxis: axisOf(outlet ?? root),
111
209
  ...(outlet ? { root: toRect(outlet.getBoundingClientRect()), regions } : {}),
210
+ ...(layers.length > 0 ? { layers } : {}),
112
211
  viewport: { width: window.innerWidth, height: window.innerHeight },
113
212
  scroll: { x: window.scrollX, y: window.scrollY },
114
213
  documentHeight: document.documentElement.scrollHeight,
@@ -5,4 +5,4 @@ import { type ResolveLink } from '../index.js';
5
5
  * collection lists loaded, and upload and relationship IDs replaced with documents (over REST).
6
6
  * Documents load in `locale` (the editor's locale), as the site loads them in the page's locale.
7
7
  */
8
- export declare function resolveCanvasLayout(layout: Layout, context: TemplateContext | null, api: string, definitions: BlockDefinition[], resolveLink: ResolveLink, locale?: string | null, relations?: Record<string, Record<string, string>> | null): Promise<Layout>;
8
+ export declare function resolveCanvasLayout(layout: Layout, context: TemplateContext | null, api: string, definitions: BlockDefinition[], resolveLink: ResolveLink, locale?: string | null, relations?: Record<string, Record<string, string>> | null, savedSections?: string | null): Promise<Layout>;
@@ -10,14 +10,15 @@ const CANVAS_SEED = Math.floor(Math.random() * 4_294_967_296);
10
10
  * collection lists loaded, and upload and relationship IDs replaced with documents (over REST).
11
11
  * Documents load in `locale` (the editor's locale), as the site loads them in the page's locale.
12
12
  */
13
- export async function resolveCanvasLayout(layout, context, api, definitions, resolveLink, locale, relations) {
13
+ export async function resolveCanvasLayout(layout, context, api, definitions, resolveLink, locale, relations, savedSections) {
14
14
  const fetchDocs = createRestFetchDocs(api, locale);
15
15
  // Live saved sections: their current blocks, shown as repeats (not editable here).
16
- const withSections = await attachSections(layout, definitions, fetchDocs);
16
+ const withSections = await attachSections(layout, definitions, fetchDocs, savedSections ?? undefined);
17
17
  const bound = context
18
18
  ? resolveBindings(withSections, context, definitions, { url: urlResolver(resolveLink), ...(relations ? { relations } : {}) })
19
19
  : withSections;
20
- const queries = listQueries(bound, context);
20
+ // The canvas shows hidden blocks dimmed, so their lists load too.
21
+ const queries = listQueries(bound, context, null, { includeHidden: true });
21
22
  const lists = await Promise.all(queries.map((query) => fetchListPage(api, query, locale, CANVAS_SEED)));
22
23
  // A paginated list shows page 1 with its page links.
23
24
  const pages = new Map(queries.flatMap((query, i) => (query.page ? [[query.blockId, pageLinks(null, query.page, lists[i].totalPages, query.pageParam)]] : [])));
@@ -5,6 +5,9 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
5
5
  // components, CSS and theme, and sends back a picture (see capture.ts).
6
6
  import { collectClasses } from '../../../core/index.js';
7
7
  import { createCanvasCompiler } from '../../../css/browser.js';
8
+ import { compileClassSheet } from '../../../css/classes.js';
9
+ import { withoutClassNames } from '../../../classes/shared.js';
10
+ import { fetchCanvasClasses } from '../classes.js';
8
11
  import { post, unwrap } from '../../../protocol/index.js';
9
12
  import { useEffect, useMemo, useRef, useState } from 'react';
10
13
  import { defaultResolveLink, RenderLayout } from '../../index.js';
@@ -91,17 +94,27 @@ export function ThumbnailCanvas({ blocks, components, plugins, resolveLink, serv
91
94
  return;
92
95
  // An object, so the loop below sees the cleanup's change.
93
96
  const state = { cancelled: false, busy: false };
94
- const compiler = fetch(init.cssEndpoint, { credentials: 'include' }).then(async (res) => {
97
+ const input = fetch(init.cssEndpoint, { credentials: 'include' }).then(async (res) => {
95
98
  if (!res.ok)
96
99
  throw new Error(`Canvas CSS: ${res.status} ${res.statusText}`);
97
- return createCanvasCompiler((await res.json()), pluginsRef.current);
100
+ return (await res.json());
98
101
  });
99
- serverBlocks?.setScope({ document: init.document ?? null, context: null });
102
+ const compiler = input.then((value) => createCanvasCompiler(value, pluginsRef.current));
103
+ // Editable classes (their latest drafts), loaded once per page: their own stylesheet first.
104
+ const empty = { css: '', errors: {}, names: [] };
105
+ const classes = init.classesEndpoint
106
+ ? Promise.all([input, fetchCanvasClasses(init.classesEndpoint)])
107
+ .then(([value, list]) => (list.length > 0 ? compileClassSheet(value, list, pluginsRef.current) : empty))
108
+ .catch(() => empty)
109
+ : Promise.resolve(empty);
110
+ serverBlocks?.setScope({ document: init.document ?? null, context: null, mode: 'thumbnail' });
100
111
  const pageData = serverBlocks ? serverBlocks.pageData() : Promise.resolve(null);
101
112
  const run = async (request) => {
102
113
  const stored = { version: 1, blocks: request.blocks };
103
114
  const layout = await resolveCanvasLayout(stored, null, init.api, definitions, linkResolver);
104
- const css = (await compiler).build(collectClasses(layout, definitions));
115
+ const sheet = await classes;
116
+ const css = `${sheet.css}
117
+ ${(await compiler).build(withoutClassNames(collectClasses(layout, definitions), new Set(sheet.names)))}`;
105
118
  const done = new Promise((resolve) => {
106
119
  rendered.current = resolve;
107
120
  });
@@ -0,0 +1,27 @@
1
+ import type { Payload } from 'payload';
2
+ import { type StoredClassSheet } from '../../classes/sheet.js';
3
+ /**
4
+ * React precedence group of the classes stylesheet. React puts it in the `<head>` in the order it
5
+ * first meets each group: render `ClassesStyle` after the site's CSS and `ThemeStyle`, so the
6
+ * classes override code `@utility` rules with the same name. The page's generated CSS (a `<style>`
7
+ * in the body) comes later still, so a block's own classes beat its class.
8
+ */
9
+ export declare const CLASSES_PRECEDENCE = "payload-canvas-classes";
10
+ /** The stored stylesheet, read once per request (React `cache`). `null` with `classes: false`. */
11
+ export declare const loadClassesSheet: (payload: Payload) => Promise<StoredClassSheet | null>;
12
+ export type ClassesStyleProps = {
13
+ payload: Payload;
14
+ /**
15
+ * `link` (default): a `<link>` to `{api}/builder/classes-sheet/<hash>.css`, cached by the browser
16
+ * for a year and shared by every page; a publish changes the hash. `inline`: the CSS in a
17
+ * `<style>` tag in every page (no extra request, no browser cache).
18
+ */
19
+ mode?: 'link' | 'inline';
20
+ /** Origin to put before the API path, for a site on another host than Payload. Default: none (same origin). */
21
+ origin?: string;
22
+ };
23
+ /**
24
+ * The editable classes for the site's `<head>`. Put it in the root layout after `ThemeStyle`.
25
+ * Renders nothing without published classes or with `classes: false`.
26
+ */
27
+ export declare function ClassesStyle({ payload, mode, origin }: ClassesStyleProps): Promise<import("react").JSX.Element | null>;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cache } from 'react';
3
+ import { classesConfigOf } from '../../classes/config.js';
4
+ import { loadClassesSheet as loadStoredSheet } from '../../classes/sheet.js';
5
+ /**
6
+ * React precedence group of the classes stylesheet. React puts it in the `<head>` in the order it
7
+ * first meets each group: render `ClassesStyle` after the site's CSS and `ThemeStyle`, so the
8
+ * classes override code `@utility` rules with the same name. The page's generated CSS (a `<style>`
9
+ * in the body) comes later still, so a block's own classes beat its class.
10
+ */
11
+ export const CLASSES_PRECEDENCE = 'payload-canvas-classes';
12
+ /** The stored stylesheet, read once per request (React `cache`). `null` with `classes: false`. */
13
+ export const loadClassesSheet = cache(async (payload) => loadStoredSheet(payload));
14
+ /**
15
+ * The editable classes for the site's `<head>`. Put it in the root layout after `ThemeStyle`.
16
+ * Renders nothing without published classes or with `classes: false`.
17
+ */
18
+ export async function ClassesStyle({ payload, mode = 'link', origin = '' }) {
19
+ const config = classesConfigOf(payload);
20
+ const sheet = config ? await loadClassesSheet(payload) : null;
21
+ if (!config || !sheet?.css || !sheet.hash)
22
+ return null;
23
+ if (mode === 'inline') {
24
+ return (_jsx("style", { href: `${CLASSES_PRECEDENCE}-${sheet.hash}`, precedence: CLASSES_PRECEDENCE, children: sheet.css }));
25
+ }
26
+ return _jsx("link", { rel: "stylesheet", href: `${origin}${config.sheetPath}/${sheet.hash}.css`, precedence: CLASSES_PRECEDENCE });
27
+ }
@@ -1,12 +1,3 @@
1
- import { type ComponentType } from 'react';
2
1
  import type { BlockComponentProps } from '../render/types.js';
3
- import type { IconMap } from './builtins/Icon.js';
4
- /** An `<a>` when the link resolves to an href, otherwise a `<span>`. Icon props are ignored. */
5
- export declare function Button(props: BlockComponentProps): import("react").JSX.Element | null;
6
- /**
7
- * The `button` block's component for a site with an icon set: the `icon` prop
8
- * (`defaultBlocks({ icons })`) draws that icon before or after the label (`iconPosition`), with
9
- * the `iconClassName` classes. The icon is decoration: the label names the button.
10
- * `builtinComponents({ icons })` includes it. One component per map.
11
- */
12
- export declare function buttonComponent(icons: IconMap): ComponentType<BlockComponentProps>;
2
+ /** An `<a>` when the link resolves to an href, otherwise a `<span>`. */
3
+ export declare function Button({ props, className, attributes, mode, linkComponent }: BlockComponentProps): import("react").JSX.Element | null;