payload-canvas 0.3.0-next.1 → 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 (526) hide show
  1. package/README.md +1010 -55
  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/LayoutDiff.js +3 -3
  15. package/dist/admin/diff/changes.js +13 -0
  16. package/dist/admin/diff/layoutDiff.scss +48 -48
  17. package/dist/admin/editor/Canvas.js +20 -5
  18. package/dist/admin/editor/DragLayer.js +1 -1
  19. package/dist/admin/editor/Editor.d.ts +3 -1
  20. package/dist/admin/editor/Editor.js +6 -3
  21. package/dist/admin/editor/InlineToolbar.js +1 -1
  22. package/dist/admin/editor/Inspector.js +115 -23
  23. package/dist/admin/editor/Library.js +40 -15
  24. package/dist/admin/editor/Outline.js +26 -19
  25. package/dist/admin/editor/Overlay.js +9 -4
  26. package/dist/admin/editor/actions.d.ts +18 -2
  27. package/dist/admin/editor/actions.js +53 -3
  28. package/dist/admin/editor/assistant/AssistantPanel.js +4 -2
  29. package/dist/admin/editor/assistant/ConnectAgents.js +1 -1
  30. package/dist/admin/editor/assistant/assistant.scss +65 -65
  31. package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
  32. package/dist/admin/editor/classes/ClassManager.js +56 -0
  33. package/dist/admin/editor/classes/controller.d.ts +112 -0
  34. package/dist/admin/editor/classes/controller.js +326 -0
  35. package/dist/admin/editor/classes/manager.scss +262 -0
  36. package/dist/admin/editor/classes/managerModel.d.ts +5 -0
  37. package/dist/admin/editor/classes/managerModel.js +27 -0
  38. package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
  39. package/dist/admin/editor/comments/CommentLayer.js +143 -0
  40. package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
  41. package/dist/admin/editor/comments/CommentsPanel.js +73 -0
  42. package/dist/admin/editor/comments/Thread.d.ts +26 -0
  43. package/dist/admin/editor/comments/Thread.js +84 -0
  44. package/dist/admin/editor/comments/comments.scss +539 -0
  45. package/dist/admin/editor/comments/controller.d.ts +48 -0
  46. package/dist/admin/editor/comments/controller.js +142 -0
  47. package/dist/admin/editor/contentMode.d.ts +17 -0
  48. package/dist/admin/editor/contentMode.js +37 -0
  49. package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
  50. package/dist/admin/editor/dnd/DropOutlines.js +73 -0
  51. package/dist/admin/editor/dnd/dnd.scss +45 -2
  52. package/dist/admin/editor/dnd/mode.d.ts +4 -0
  53. package/dist/admin/editor/dnd/mode.js +39 -0
  54. package/dist/admin/editor/editor.scss +138 -183
  55. package/dist/admin/editor/empty/EmptyStart.js +21 -43
  56. package/dist/admin/editor/empty/empty.scss +3 -3
  57. package/dist/admin/editor/fields/AddButton.d.ts +15 -0
  58. package/dist/admin/editor/fields/AddButton.js +14 -0
  59. package/dist/admin/editor/fields/ArrayField.js +4 -3
  60. package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
  61. package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
  62. package/dist/admin/editor/fields/ConditionRows.js +137 -0
  63. package/dist/admin/editor/fields/GroupField.d.ts +5 -2
  64. package/dist/admin/editor/fields/GroupField.js +6 -2
  65. package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
  66. package/dist/admin/editor/fields/ListWhereField.js +20 -0
  67. package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
  68. package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
  69. package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
  70. package/dist/admin/editor/fields/RelatedField.js +44 -0
  71. package/dist/admin/editor/fields/SortField.d.ts +13 -0
  72. package/dist/admin/editor/fields/SortField.js +37 -0
  73. package/dist/admin/editor/fields/WhereField.d.ts +25 -0
  74. package/dist/admin/editor/fields/WhereField.js +47 -0
  75. package/dist/admin/editor/fields/access.d.ts +1 -1
  76. package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
  77. package/dist/admin/editor/fields/collectionFields.js +15 -0
  78. package/dist/admin/editor/fields/conditions.d.ts +99 -0
  79. package/dist/admin/editor/fields/conditions.js +339 -0
  80. package/dist/admin/editor/fields/fields.scss +346 -34
  81. package/dist/admin/editor/fields/listOptions.d.ts +44 -0
  82. package/dist/admin/editor/fields/listOptions.js +111 -0
  83. package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
  84. package/dist/admin/editor/fields/queryFilterRows.js +29 -0
  85. package/dist/admin/editor/fields/whereRows.d.ts +27 -0
  86. package/dist/admin/editor/fields/whereRows.js +167 -0
  87. package/dist/admin/editor/generate/GenerateImage.js +1 -1
  88. package/dist/admin/editor/generate/generate.scss +48 -48
  89. package/dist/admin/editor/icons.d.ts +17 -1
  90. package/dist/admin/editor/icons.js +33 -2
  91. package/dist/admin/editor/inline.js +9 -0
  92. package/dist/admin/editor/insert/InsertHandle.js +5 -2
  93. package/dist/admin/editor/insert/picker.d.ts +3 -1
  94. package/dist/admin/editor/insert/picker.js +17 -10
  95. package/dist/admin/editor/insert/spots.d.ts +12 -1
  96. package/dist/admin/editor/insert/spots.js +49 -10
  97. package/dist/admin/editor/layout/FrameResize.js +1 -1
  98. package/dist/admin/editor/layout/LeftPanel.js +12 -7
  99. package/dist/admin/editor/layout/layout.scss +4 -4
  100. package/dist/admin/editor/live/PresenceUI.js +1 -1
  101. package/dist/admin/editor/live/presence.scss +1 -1
  102. package/dist/admin/editor/live/useMultiplayer.js +9 -1
  103. package/dist/admin/editor/locale/LocaleField.d.ts +2 -2
  104. package/dist/admin/editor/locale/LocaleField.js +4 -2
  105. package/dist/admin/editor/locale/locale.scss +12 -12
  106. package/dist/admin/editor/media/ImageEditor.js +1 -1
  107. package/dist/admin/editor/media/media.scss +23 -23
  108. package/dist/admin/editor/menu/Menu.js +1 -1
  109. package/dist/admin/editor/menu/blockMenu.js +32 -18
  110. package/dist/admin/editor/menu/menu.scss +16 -16
  111. package/dist/admin/editor/motion/MotionPanel.js +2 -2
  112. package/dist/admin/editor/motion/model.d.ts +2 -2
  113. package/dist/admin/editor/motion/model.js +2 -2
  114. package/dist/admin/editor/motion/motion.scss +2 -2
  115. package/dist/admin/editor/names.js +11 -3
  116. package/dist/admin/editor/regions/RegionOverlay.js +1 -1
  117. package/dist/admin/editor/regions/RegionPane.js +1 -1
  118. package/dist/admin/editor/renderField.d.ts +5 -1
  119. package/dist/admin/editor/renderField.js +73 -13
  120. package/dist/admin/editor/runtime.d.ts +14 -0
  121. package/dist/admin/editor/runtime.js +68 -6
  122. package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
  123. package/dist/admin/editor/sections/ComponentFields.js +116 -0
  124. package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
  125. package/dist/admin/editor/sections/PropertyControls.js +65 -0
  126. package/dist/admin/editor/sections/components.d.ts +29 -0
  127. package/dist/admin/editor/sections/components.js +112 -0
  128. package/dist/admin/editor/sections/components.scss +238 -0
  129. package/dist/admin/editor/sections/variants.d.ts +32 -0
  130. package/dist/admin/editor/sections/variants.js +59 -0
  131. package/dist/admin/editor/sections/variants.scss +90 -0
  132. package/dist/admin/editor/shortcuts.d.ts +4 -1
  133. package/dist/admin/editor/shortcuts.js +19 -3
  134. package/dist/admin/editor/store.d.ts +18 -0
  135. package/dist/admin/editor/store.js +46 -0
  136. package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
  137. package/dist/admin/editor/styles/ClassBar.js +90 -0
  138. package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
  139. package/dist/admin/editor/styles/ClassCss.js +28 -0
  140. package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
  141. package/dist/admin/editor/styles/ClassDialog.js +151 -0
  142. package/dist/admin/editor/styles/ColorPicker.js +6 -3
  143. package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
  144. package/dist/admin/editor/styles/RawClasses.js +184 -32
  145. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -1
  146. package/dist/admin/editor/styles/StylesPanel.js +53 -11
  147. package/dist/admin/editor/styles/VariantBar.js +3 -3
  148. package/dist/admin/editor/styles/classEdit.d.ts +4 -0
  149. package/dist/admin/editor/styles/classEdit.js +20 -0
  150. package/dist/admin/editor/styles/classes.scss +381 -0
  151. package/dist/admin/editor/styles/context.d.ts +24 -4
  152. package/dist/admin/editor/styles/context.js +32 -9
  153. package/dist/admin/editor/styles/controls.d.ts +3 -1
  154. package/dist/admin/editor/styles/controls.js +31 -13
  155. package/dist/admin/editor/styles/popover.d.ts +6 -0
  156. package/dist/admin/editor/styles/popover.js +5 -5
  157. package/dist/admin/editor/styles/sections.js +2 -2
  158. package/dist/admin/editor/styles/styles.scss +115 -139
  159. package/dist/admin/editor/styles/suggestions.d.ts +22 -0
  160. package/dist/admin/editor/styles/suggestions.js +77 -0
  161. package/dist/admin/editor/styles/tokens.js +14 -0
  162. package/dist/admin/editor/templates/Bindable.d.ts +14 -6
  163. package/dist/admin/editor/templates/Bindable.js +146 -61
  164. package/dist/admin/editor/templates/SamplePicker.js +2 -2
  165. package/dist/admin/editor/templates/Visibility.d.ts +9 -0
  166. package/dist/admin/editor/templates/Visibility.js +54 -0
  167. package/dist/admin/editor/templates/binding.d.ts +11 -4
  168. package/dist/admin/editor/templates/binding.js +23 -3
  169. package/dist/admin/editor/templates/templates.scss +117 -90
  170. package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
  171. package/dist/admin/editor/templates/visibilityRows.js +83 -0
  172. package/dist/admin/editor/tooltip/tooltip.scss +4 -4
  173. package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
  174. package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
  175. package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
  176. package/dist/admin/editor/topbar/DocumentActions.js +6 -5
  177. package/dist/admin/editor/topbar/DocumentTitle.js +8 -3
  178. package/dist/admin/editor/topbar/TopBar.js +15 -3
  179. package/dist/admin/editor/topbar/contentMode.scss +35 -0
  180. package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
  181. package/dist/admin/editor/topbar/screens/ScreenDrawer.js +1 -1
  182. package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +1 -1
  183. package/dist/admin/editor/topbar/screens/screens.scss +20 -20
  184. package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
  185. package/dist/admin/editor/topbar/settingsDrawer.scss +7 -7
  186. package/dist/admin/editor/topbar/topbar.scss +50 -48
  187. package/dist/admin/editor/ui/Select.js +1 -1
  188. package/dist/admin/editor/ui/controls.scss +26 -26
  189. package/dist/admin/formChoice.d.ts +3 -0
  190. package/dist/admin/formChoice.js +10 -0
  191. package/dist/admin/layoutField.scss +69 -0
  192. package/dist/admin/screen/BuilderScreen.d.ts +6 -1
  193. package/dist/admin/screen/BuilderScreen.js +5 -4
  194. package/dist/admin/server/BuilderView.js +10 -3
  195. package/dist/admin/templateConditions.scss +24 -0
  196. package/dist/ai/adapters/anthropic.d.ts +2 -2
  197. package/dist/ai/adapters/anthropic.js +17 -4
  198. package/dist/ai/adapters/cloudflare-gateway.js +7 -1
  199. package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
  200. package/dist/ai/adapters/openai-compatible.js +1 -0
  201. package/dist/ai/adapters/openrouter.js +2 -0
  202. package/dist/ai/config.d.ts +24 -4
  203. package/dist/ai/config.js +27 -8
  204. package/dist/ai/endpoint.d.ts +5 -2
  205. package/dist/ai/endpoint.js +31 -26
  206. package/dist/ai/images/cloudflare-workers-ai.js +6 -2
  207. package/dist/ai/images/openai.js +8 -3
  208. package/dist/ai/images/openrouter.js +6 -2
  209. package/dist/ai/images/service.d.ts +10 -4
  210. package/dist/ai/images/service.js +24 -8
  211. package/dist/ai/loop.d.ts +5 -5
  212. package/dist/ai/openai-format.d.ts +7 -0
  213. package/dist/ai/openai-format.js +17 -5
  214. package/dist/ai/prompt.d.ts +8 -0
  215. package/dist/ai/prompt.js +30 -4
  216. package/dist/ai/settings/index.d.ts +62 -0
  217. package/dist/ai/settings/index.js +264 -0
  218. package/dist/ai/settings/secret.d.ts +11 -0
  219. package/dist/ai/settings/secret.js +46 -0
  220. package/dist/ai/settings/shared.d.ts +22 -0
  221. package/dist/ai/settings/shared.js +3 -0
  222. package/dist/ai/tools.d.ts +3 -0
  223. package/dist/ai/tools.js +83 -10
  224. package/dist/ai/types.d.ts +43 -0
  225. package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
  226. package/dist/blocks/builtins/adjacentLinks.js +76 -0
  227. package/dist/blocks/builtins/carousel.d.ts +5 -0
  228. package/dist/blocks/builtins/carousel.js +115 -0
  229. package/dist/blocks/builtins/disclosure.d.ts +14 -0
  230. package/dist/blocks/builtins/disclosure.js +97 -0
  231. package/dist/blocks/builtins/embed.d.ts +15 -0
  232. package/dist/blocks/builtins/embed.js +47 -0
  233. package/dist/blocks/builtins/faq.d.ts +17 -0
  234. package/dist/blocks/builtins/faq.js +88 -0
  235. package/dist/blocks/builtins/filterLink.d.ts +4 -0
  236. package/dist/blocks/builtins/filterLink.js +35 -0
  237. package/dist/blocks/builtins/icon.d.ts +10 -0
  238. package/dist/blocks/builtins/icon.js +45 -0
  239. package/dist/blocks/builtins/index.d.ts +40 -0
  240. package/dist/blocks/builtins/index.js +71 -0
  241. package/dist/blocks/builtins/marquee.d.ts +5 -0
  242. package/dist/blocks/builtins/marquee.js +68 -0
  243. package/dist/blocks/builtins/popup.d.ts +5 -0
  244. package/dist/blocks/builtins/popup.js +83 -0
  245. package/dist/blocks/builtins/sectionRef.d.ts +40 -0
  246. package/dist/blocks/builtins/sectionRef.js +100 -0
  247. package/dist/blocks/builtins/shared.d.ts +28 -0
  248. package/dist/blocks/builtins/shared.js +62 -0
  249. package/dist/blocks/builtins/tableOfContents.d.ts +7 -0
  250. package/dist/blocks/builtins/tableOfContents.js +38 -0
  251. package/dist/blocks/builtins/tabs.d.ts +6 -0
  252. package/dist/blocks/builtins/tabs.js +87 -0
  253. package/dist/blocks/client/adjacentLinks.d.ts +4 -0
  254. package/dist/blocks/client/adjacentLinks.js +4 -0
  255. package/dist/blocks/client/carousel.d.ts +45 -0
  256. package/dist/blocks/client/carousel.js +53 -0
  257. package/dist/blocks/client/embed.d.ts +21 -0
  258. package/dist/blocks/client/embed.js +23 -0
  259. package/dist/blocks/client/field.d.ts +7 -0
  260. package/dist/blocks/client/field.js +8 -0
  261. package/dist/blocks/client/filterLink.d.ts +19 -0
  262. package/dist/blocks/client/filterLink.js +30 -0
  263. package/dist/blocks/client/helpers.d.ts +21 -0
  264. package/dist/blocks/client/helpers.js +24 -0
  265. package/dist/blocks/client/marquee.d.ts +14 -0
  266. package/dist/blocks/client/marquee.js +25 -0
  267. package/dist/blocks/client/menu.d.ts +46 -0
  268. package/dist/blocks/client/menu.js +49 -0
  269. package/dist/blocks/client/popup.d.ts +15 -0
  270. package/dist/blocks/client/popup.js +16 -0
  271. package/dist/blocks/client/tabs.d.ts +10 -0
  272. package/dist/blocks/client/tabs.js +11 -0
  273. package/dist/blocks/defaults.d.ts +15 -34
  274. package/dist/blocks/defaults.js +339 -180
  275. package/dist/blocks/index.d.ts +4 -3
  276. package/dist/blocks/index.js +3 -2
  277. package/dist/classes/actions.d.ts +97 -0
  278. package/dist/classes/actions.js +296 -0
  279. package/dist/classes/collection.d.ts +5 -0
  280. package/dist/classes/collection.js +189 -0
  281. package/dist/classes/config.d.ts +34 -0
  282. package/dist/classes/config.js +8 -0
  283. package/dist/classes/endpoints.d.ts +2 -0
  284. package/dist/classes/endpoints.js +120 -0
  285. package/dist/classes/index.d.ts +36 -0
  286. package/dist/classes/index.js +42 -0
  287. package/dist/classes/mcp.d.ts +6 -0
  288. package/dist/classes/mcp.js +161 -0
  289. package/dist/classes/shared.d.ts +131 -0
  290. package/dist/classes/shared.js +300 -0
  291. package/dist/classes/sheet.d.ts +34 -0
  292. package/dist/classes/sheet.js +126 -0
  293. package/dist/classes/usage.d.ts +57 -0
  294. package/dist/classes/usage.js +208 -0
  295. package/dist/comments/collection.d.ts +38 -0
  296. package/dist/comments/collection.js +226 -0
  297. package/dist/comments/config.d.ts +15 -0
  298. package/dist/comments/config.js +2 -0
  299. package/dist/comments/index.d.ts +20 -0
  300. package/dist/comments/index.js +22 -0
  301. package/dist/comments/shared.d.ts +54 -0
  302. package/dist/comments/shared.js +104 -0
  303. package/dist/core/attrs.d.ts +27 -0
  304. package/dist/core/attrs.js +132 -0
  305. package/dist/core/bindings.d.ts +171 -15
  306. package/dist/core/bindings.js +697 -27
  307. package/dist/core/blockNames.d.ts +9 -0
  308. package/dist/core/blockNames.js +11 -0
  309. package/dist/core/blocks.d.ts +62 -4
  310. package/dist/core/blocks.js +164 -7
  311. package/dist/core/classes.d.ts +18 -2
  312. package/dist/core/classes.js +37 -4
  313. package/dist/core/components.d.ts +72 -0
  314. package/dist/core/components.js +294 -0
  315. package/dist/core/contentMode.d.ts +27 -0
  316. package/dist/core/contentMode.js +0 -0
  317. package/dist/core/dropTarget.d.ts +11 -0
  318. package/dist/core/dropTarget.js +24 -1
  319. package/dist/core/fieldAccess.js +1 -1
  320. package/dist/core/fieldHooks.d.ts +1 -1
  321. package/dist/core/fields.d.ts +5 -0
  322. package/dist/core/fields.js +11 -0
  323. package/dist/core/headings.d.ts +24 -0
  324. package/dist/core/headings.js +55 -0
  325. package/dist/core/index.d.ts +10 -3
  326. package/dist/core/index.js +10 -3
  327. package/dist/core/layers.d.ts +9 -0
  328. package/dist/core/layers.js +29 -0
  329. package/dist/core/motion.d.ts +24 -15
  330. package/dist/core/motion.js +20 -12
  331. package/dist/core/operations.d.ts +6 -0
  332. package/dist/core/operations.js +124 -6
  333. package/dist/core/payloadBlocks.js +7 -1
  334. package/dist/core/references.js +28 -0
  335. package/dist/core/schema.js +35 -1
  336. package/dist/core/sectionOrigin.d.ts +6 -0
  337. package/dist/core/sectionOrigin.js +21 -0
  338. package/dist/core/sections.d.ts +72 -0
  339. package/dist/core/sections.js +331 -0
  340. package/dist/core/templateChoice.d.ts +24 -0
  341. package/dist/core/templateChoice.js +43 -0
  342. package/dist/core/tree.js +37 -2
  343. package/dist/core/types.d.ts +219 -2
  344. package/dist/core/validate.d.ts +4 -1
  345. package/dist/core/validate.js +48 -6
  346. package/dist/core/visibility.d.ts +63 -0
  347. package/dist/core/visibility.js +214 -0
  348. package/dist/core/whereValues.d.ts +22 -0
  349. package/dist/core/whereValues.js +43 -0
  350. package/dist/css/classes.d.ts +16 -0
  351. package/dist/css/classes.js +172 -0
  352. package/dist/css/index.d.ts +32 -1
  353. package/dist/css/index.js +64 -5
  354. package/dist/css/tokens.d.ts +14 -1
  355. package/dist/css/tokens.js +61 -2
  356. package/dist/index.d.ts +6 -3
  357. package/dist/index.js +7 -2
  358. package/dist/live/contentMode.d.ts +24 -0
  359. package/dist/live/contentMode.js +39 -0
  360. package/dist/live/draftAccess.js +1 -1
  361. package/dist/live/endpoints.js +3 -0
  362. package/dist/live/session.d.ts +6 -1
  363. package/dist/live/session.js +8 -0
  364. package/dist/live/storage.js +4 -2
  365. package/dist/live/types.d.ts +16 -1
  366. package/dist/mcp/index.d.ts +12 -1
  367. package/dist/mcp/index.js +177 -48
  368. package/dist/mcp/shared.d.ts +123 -30
  369. package/dist/mcp/shared.js +222 -11
  370. package/dist/plugin/hook.d.ts +7 -1
  371. package/dist/plugin/hook.js +30 -4
  372. package/dist/plugin/index.d.ts +27 -8
  373. package/dist/plugin/index.js +113 -26
  374. package/dist/plugin/links.d.ts +24 -0
  375. package/dist/plugin/links.js +27 -0
  376. package/dist/plugin/listCollections.d.ts +20 -3
  377. package/dist/plugin/listCollections.js +54 -8
  378. package/dist/plugin/references.d.ts +5 -0
  379. package/dist/plugin/references.js +1 -1
  380. package/dist/plugin/sections.d.ts +14 -7
  381. package/dist/plugin/sections.js +69 -23
  382. package/dist/plugin/sectionsUsedIn.d.ts +6 -0
  383. package/dist/plugin/sectionsUsedIn.js +24 -0
  384. package/dist/plugin/templateEndpoint.d.ts +9 -0
  385. package/dist/plugin/templateEndpoint.js +49 -0
  386. package/dist/plugin/templates.d.ts +4 -0
  387. package/dist/plugin/templates.js +42 -12
  388. package/dist/protocol/index.d.ts +19 -2
  389. package/dist/react/canvas/BuilderCanvas.js +149 -24
  390. package/dist/react/canvas/classes.d.ts +17 -0
  391. package/dist/react/canvas/classes.js +102 -0
  392. package/dist/react/canvas/controls.d.ts +31 -0
  393. package/dist/react/canvas/controls.js +75 -0
  394. package/dist/react/canvas/fetchDocs.d.ts +17 -3
  395. package/dist/react/canvas/fetchDocs.js +51 -10
  396. package/dist/react/canvas/inline/rich/editor.js +1 -6
  397. package/dist/react/canvas/measure.d.ts +12 -1
  398. package/dist/react/canvas/measure.js +130 -7
  399. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  400. package/dist/react/canvas/resolveLayout.js +19 -7
  401. package/dist/react/canvas/serverBlocks.d.ts +11 -0
  402. package/dist/react/canvas/serverBlocks.js +28 -1
  403. package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +18 -5
  404. package/dist/react/classes/ClassesStyle.d.ts +27 -0
  405. package/dist/react/classes/ClassesStyle.js +27 -0
  406. package/dist/react/components/Button.d.ts +1 -1
  407. package/dist/react/components/Button.js +4 -2
  408. package/dist/react/components/CollectionList.d.ts +9 -3
  409. package/dist/react/components/CollectionList.js +28 -7
  410. package/dist/react/components/Container.d.ts +5 -2
  411. package/dist/react/components/Container.js +10 -4
  412. package/dist/react/components/Field.js +2 -2
  413. package/dist/react/components/Heading.js +9 -2
  414. package/dist/react/components/Image.d.ts +9 -0
  415. package/dist/react/components/Image.js +16 -1
  416. package/dist/react/components/Link.d.ts +1 -1
  417. package/dist/react/components/Link.js +5 -3
  418. package/dist/react/components/List.d.ts +2 -1
  419. package/dist/react/components/List.js +8 -2
  420. package/dist/react/components/Menu.d.ts +26 -1
  421. package/dist/react/components/Menu.js +116 -25
  422. package/dist/react/components/RichText.d.ts +6 -2
  423. package/dist/react/components/RichText.js +23 -2
  424. package/dist/react/components/builtins/Accordion.d.ts +10 -0
  425. package/dist/react/components/builtins/Accordion.js +38 -0
  426. package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
  427. package/dist/react/components/builtins/AdjacentLinks.js +20 -0
  428. package/dist/react/components/builtins/Carousel.d.ts +24 -0
  429. package/dist/react/components/builtins/Carousel.js +209 -0
  430. package/dist/react/components/builtins/Disclosure.d.ts +8 -0
  431. package/dist/react/components/builtins/Disclosure.js +14 -0
  432. package/dist/react/components/builtins/Embed.d.ts +11 -0
  433. package/dist/react/components/builtins/Embed.js +23 -0
  434. package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
  435. package/dist/react/components/builtins/EmbedHtml.js +51 -0
  436. package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
  437. package/dist/react/components/builtins/EmbedPreview.js +105 -0
  438. package/dist/react/components/builtins/FilterLink.d.ts +8 -0
  439. package/dist/react/components/builtins/FilterLink.js +30 -0
  440. package/dist/react/components/builtins/Icon.d.ts +14 -0
  441. package/dist/react/components/builtins/Icon.js +28 -0
  442. package/dist/react/components/builtins/Marquee.d.ts +8 -0
  443. package/dist/react/components/builtins/Marquee.js +15 -0
  444. package/dist/react/components/builtins/Popup.d.ts +26 -0
  445. package/dist/react/components/builtins/Popup.js +146 -0
  446. package/dist/react/components/builtins/SectionRef.d.ts +8 -0
  447. package/dist/react/components/builtins/SectionRef.js +21 -0
  448. package/dist/react/components/builtins/Tab.d.ts +7 -0
  449. package/dist/react/components/builtins/Tab.js +21 -0
  450. package/dist/react/components/builtins/TableOfContents.d.ts +21 -0
  451. package/dist/react/components/builtins/TableOfContents.js +36 -0
  452. package/dist/react/components/builtins/Tabs.d.ts +17 -0
  453. package/dist/react/components/builtins/Tabs.js +71 -0
  454. package/dist/react/components/builtins/glyphs.d.ts +8 -0
  455. package/dist/react/components/builtins/glyphs.js +7 -0
  456. package/dist/react/components/builtins/index.d.ts +49 -0
  457. package/dist/react/components/builtins/index.js +70 -0
  458. package/dist/react/components/builtins/tabsContext.d.ts +12 -0
  459. package/dist/react/components/builtins/tabsContext.js +6 -0
  460. package/dist/react/components/index.js +13 -8
  461. package/dist/react/components/lazy.d.ts +32 -0
  462. package/dist/react/components/lazy.js +20 -0
  463. package/dist/react/components/lazyBlock.d.ts +17 -0
  464. package/dist/react/components/lazyBlock.js +23 -0
  465. package/dist/react/index.d.ts +8 -3
  466. package/dist/react/index.js +7 -2
  467. package/dist/react/motion/runtime.js +10 -6
  468. package/dist/react/motion/style.js +1 -1
  469. package/dist/react/render/PayloadRoot.js +1 -1
  470. package/dist/react/render/RenderLayout.d.ts +9 -7
  471. package/dist/react/render/RenderLayout.js +145 -41
  472. package/dist/react/render/canvasMode.d.ts +13 -0
  473. package/dist/react/render/canvasMode.js +13 -0
  474. package/dist/react/render/canvasServer.js +4 -3
  475. package/dist/react/render/canvasServerTypes.d.ts +5 -0
  476. package/dist/react/render/lists.d.ts +139 -5
  477. package/dist/react/render/lists.js +401 -9
  478. package/dist/react/render/marks.d.ts +15 -0
  479. package/dist/react/render/marks.js +23 -0
  480. package/dist/react/render/payload.d.ts +8 -1
  481. package/dist/react/render/payload.js +12 -3
  482. package/dist/react/render/preview.d.ts +11 -0
  483. package/dist/react/render/preview.js +13 -0
  484. package/dist/react/render/relations.d.ts +10 -0
  485. package/dist/react/render/relations.js +39 -0
  486. package/dist/react/render/resolve.d.ts +26 -2
  487. package/dist/react/render/resolve.js +52 -25
  488. package/dist/react/render/reveal.d.ts +17 -0
  489. package/dist/react/render/reveal.js +39 -0
  490. package/dist/react/render/sections.d.ts +15 -0
  491. package/dist/react/render/sections.js +79 -0
  492. package/dist/react/render/templates.d.ts +47 -0
  493. package/dist/react/render/templates.js +139 -0
  494. package/dist/react/render/types.d.ts +66 -4
  495. package/dist/react/server.d.ts +3 -38
  496. package/dist/react/server.js +9 -86
  497. package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
  498. package/dist/react/theme/ThemeLiveLoader.js +5 -0
  499. package/dist/react/theme/ThemeStyle.d.ts +13 -2
  500. package/dist/react/theme/ThemeStyle.js +14 -4
  501. package/dist/theme/admin/ColorField.d.ts +2 -2
  502. package/dist/theme/admin/ColorField.js +2 -2
  503. package/dist/theme/admin/FontField.d.ts +2 -2
  504. package/dist/theme/admin/FontField.js +2 -2
  505. package/dist/theme/admin/SaveSignal.js +2 -2
  506. package/dist/theme/admin/Variables.d.ts +11 -0
  507. package/dist/theme/admin/Variables.js +115 -0
  508. package/dist/theme/admin/fields.scss +161 -48
  509. package/dist/theme/client.d.ts +1 -0
  510. package/dist/theme/client.js +2 -0
  511. package/dist/theme/css.d.ts +6 -1
  512. package/dist/theme/css.js +12 -4
  513. package/dist/theme/global.js +83 -0
  514. package/dist/theme/index.d.ts +1 -0
  515. package/dist/theme/index.js +1 -0
  516. package/dist/theme/server.d.ts +15 -0
  517. package/dist/theme/server.js +43 -0
  518. package/dist/theme/usage.d.ts +23 -0
  519. package/dist/theme/usage.js +68 -0
  520. package/dist/theme/variables.d.ts +72 -0
  521. package/dist/theme/variables.js +231 -0
  522. package/package.json +25 -28
  523. package/dist/react/components/Quote.d.ts +0 -3
  524. package/dist/react/components/Quote.js +0 -12
  525. package/dist/react/components/Spacer.d.ts +0 -3
  526. package/dist/react/components/Spacer.js +0 -6
@@ -0,0 +1,143 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Comment mode on the canvas: a layer over the iframe that takes the pointer (a click places a
4
+ // pin on the block under it, the wheel still scrolls the page), the pins of the threads, and the
5
+ // popover with the composer or the open thread. Renders nothing outside comment mode, so the
6
+ // canvas does no comment work while people edit.
7
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
8
+ import { createPortal } from 'react-dom';
9
+ import { deepestBlockAt } from '../../../core/index.js';
10
+ import { threadsOf } from '../../../comments/shared.js';
11
+ import { Icon } from '../icons.js';
12
+ import { cursorAt, cursorPoint } from '../live/presence.js';
13
+ import { toCanvasPoint, useRuntime } from '../runtime.js';
14
+ import { useEditor } from '../store.js';
15
+ import { useValue } from '../valueStore.js';
16
+ import { Avatar, CommentInput, Thread } from './Thread.js';
17
+ import './comments.scss';
18
+ const noSubscription = () => () => { };
19
+ const editorRoot = () => document.querySelector('.builder-editor');
20
+ const noRoot = () => null;
21
+ /** Space between the pin and its popover, and from the window edge, in screen pixels. */
22
+ const GAP = 10;
23
+ /** The pin's size on screen (`.builder-comment-pin`): the popover sits beside it, never over it. */
24
+ const PIN = 30;
25
+ const POPOVER_WIDTH = 300;
26
+ export function CommentLayer() {
27
+ const { comments } = useRuntime();
28
+ if (!comments)
29
+ return null;
30
+ return _jsx(ModeGate, { comments: comments });
31
+ }
32
+ function ModeGate({ comments }) {
33
+ const on = useValue(comments.mode);
34
+ return on ? _jsx(ModeLayer, { comments: comments }) : null;
35
+ }
36
+ function ModeLayer({ comments }) {
37
+ const runtime = useRuntime();
38
+ const measurement = useValue(runtime.measurement);
39
+ const list = useValue(comments.list);
40
+ const filter = useValue(comments.filter);
41
+ const draft = useValue(comments.draft);
42
+ const openId = useValue(comments.open);
43
+ const layout = useEditor(runtime.store, (s) => s.layout);
44
+ // The block under the pointer, by id: its outline follows the block when the page scrolls or changes.
45
+ const [hoveredId, setHoveredId] = useState(null);
46
+ const hovered = hoveredId ? (measurement?.blocks.find((b) => b.id === hoveredId)?.rect ?? null) : null;
47
+ const threads = useMemo(() => threadsOf(list, filter), [list, filter]);
48
+ const openThread = useMemo(() => (openId ? threadsOf(list).find((t) => t.root.id === openId) : undefined), [list, openId]);
49
+ const pointAt = (e) => {
50
+ const iframe = runtime.iframeRef.current;
51
+ return iframe ? toCanvasPoint(iframe, { x: e.clientX, y: e.clientY }) : null;
52
+ };
53
+ const onMove = (e) => {
54
+ const p = pointAt(e);
55
+ setHoveredId(p && measurement ? deepestBlockAt(layout, measurement, p) : null);
56
+ };
57
+ const onClick = (e) => {
58
+ const p = pointAt(e);
59
+ if (!p || !measurement)
60
+ return;
61
+ const cursor = cursorAt(layout, measurement, p);
62
+ // Over the page background, not a block: close what is open.
63
+ if (!cursor.blockId) {
64
+ comments.draft.set(null);
65
+ comments.open.set(null);
66
+ return;
67
+ }
68
+ // A click while a thread or the composer is open only closes it.
69
+ if (comments.draft.get() || comments.open.get()) {
70
+ comments.draft.set(null);
71
+ comments.open.set(null);
72
+ return;
73
+ }
74
+ comments.place(cursor);
75
+ };
76
+ const pinAt = (blockId, x, y) => (measurement && blockId ? cursorPoint(measurement, { blockId, x, y }) : null);
77
+ const draftPoint = draft ? pinAt(draft.blockId, draft.x, draft.y) : null;
78
+ const openPoint = openThread ? pinAt(openThread.root.blockId, openThread.root.x, openThread.root.y) : null;
79
+ return (_jsxs("div", { className: "builder-comments-layer", children: [_jsx("div", { className: "builder-comments-layer__capture", "aria-label": "Click a block to comment", onPointerMove: onMove, onPointerLeave: () => setHoveredId(null), onPointerDown: (e) => {
80
+ if (e.button !== 0)
81
+ return;
82
+ // The composer focuses its text box as it opens; the default mousedown would take focus back.
83
+ e.preventDefault();
84
+ onClick(e);
85
+ }, onWheel: (e) => runtime.postToCanvas({ type: 'scrollBy', dx: e.deltaX, dy: e.deltaY }) }), hovered && (_jsx("div", { className: "builder-comments-layer__hover", style: { left: hovered.x, top: hovered.y, width: hovered.width, height: hovered.height } })), threads.map((thread) => {
86
+ const point = pinAt(thread.root.blockId, thread.root.x, thread.root.y);
87
+ if (!point)
88
+ return null;
89
+ return _jsx(Pin, { thread: thread, point: point, open: thread.root.id === openId, comments: comments }, thread.root.id);
90
+ }), draftPoint && (_jsx("span", { className: "builder-comment-pin builder-comment-pin--draft", style: { left: draftPoint.x, top: draftPoint.y }, "aria-hidden": true, children: _jsx(Icon, { name: "plus", size: 12 }) })), draft && draftPoint && (_jsx(Popover, { runtime: runtime, point: draftPoint, label: "New comment", onClose: () => comments.draft.set(null), children: _jsx("div", { className: "builder-thread builder-thread--new", children: _jsx(CommentInput, { placeholder: "Add a comment", submitLabel: "Comment", focusOnMount: true, onCancel: () => comments.draft.set(null), onSubmit: (body) => comments.create(body) }) }) })), openThread && openPoint && (_jsx(Popover, { runtime: runtime, point: openPoint, label: "Comment thread", onClose: () => comments.open.set(null), children: _jsx(Thread, { thread: openThread, comments: comments, onClose: () => comments.open.set(null) }) }))] }));
91
+ }
92
+ function Pin({ thread, point, open, comments }) {
93
+ const { root, replies } = thread;
94
+ const classes = ['builder-comment-pin', open && 'builder-comment-pin--open', root.resolved && 'builder-comment-pin--resolved'].filter(Boolean).join(' ');
95
+ return (_jsx("button", { type: "button", className: classes, style: { left: point.x, top: point.y }, "aria-label": `Comment by ${root.authorName}${replies.length ? `, ${replies.length} ${replies.length === 1 ? 'reply' : 'replies'}` : ''}`, "aria-expanded": open, onClick: () => {
96
+ comments.draft.set(null);
97
+ comments.open.set(open ? null : root.id);
98
+ }, children: root.resolved ? _jsx(Icon, { name: "check", size: 12 }) : _jsx(Avatar, { name: root.authorName }) }));
99
+ }
100
+ /**
101
+ * The composer or the thread next to its pin, in the editor root (outside the zoomed frame, so it
102
+ * keeps its size). Hidden while the pin is scrolled out of the canvas.
103
+ */
104
+ function Popover({ runtime, point, label, onClose, children }) {
105
+ const host = useSyncExternalStore(noSubscription, editorRoot, noRoot);
106
+ const ref = useRef(null);
107
+ // Escape inside the popover closes it (a text box that cancels an edit handles it first).
108
+ useEffect(() => {
109
+ const el = ref.current;
110
+ if (!el)
111
+ return;
112
+ const onKey = (e) => {
113
+ if (e.key !== 'Escape' || e.defaultPrevented)
114
+ return;
115
+ e.preventDefault();
116
+ e.stopPropagation();
117
+ onClose();
118
+ };
119
+ el.addEventListener('keydown', onKey);
120
+ return () => el.removeEventListener('keydown', onKey);
121
+ }, [onClose]);
122
+ const iframe = runtime.iframeRef.current;
123
+ const box = iframe?.getBoundingClientRect();
124
+ const scale = iframe && box && iframe.offsetWidth ? box.width / iframe.offsetWidth : 1;
125
+ const screen = box ? { x: box.left + point.x * scale, y: box.top + point.y * scale } : null;
126
+ const visible = Boolean(box && screen && screen.y >= box.top && screen.y <= box.bottom && screen.x >= box.left && screen.x <= box.right);
127
+ // Right of the pin when it fits, else left. Kept inside the window vertically.
128
+ useLayoutEffect(() => {
129
+ const el = ref.current;
130
+ if (!el || !screen)
131
+ return;
132
+ const right = screen.x + PIN + GAP + POPOVER_WIDTH <= window.innerWidth - GAP;
133
+ const left = right ? screen.x + PIN + GAP : screen.x - GAP - POPOVER_WIDTH;
134
+ // The popover's top lines up with the pin's top.
135
+ const top = Math.min(Math.max(GAP, screen.y - PIN), window.innerHeight - el.offsetHeight - GAP);
136
+ el.style.left = `${Math.max(GAP, left)}px`;
137
+ el.style.top = `${Math.max(GAP, top)}px`;
138
+ });
139
+ if (!host || !visible)
140
+ return null;
141
+ const style = { width: POPOVER_WIDTH };
142
+ return createPortal(_jsx("dialog", { ref: ref, open: true, className: "builder-comments-popover", "aria-label": label, style: style, children: children }), host);
143
+ }
@@ -0,0 +1,8 @@
1
+ import { type ReactNode } from 'react';
2
+ import './comments.scss';
3
+ /** Top bar: comment mode on or off, with the number of open threads. */
4
+ export declare function CommentsButton(): import("react").JSX.Element | null;
5
+ /** In comment mode the panel takes the inspector's place. The inspector stays mounted. */
6
+ export declare function CommentsOrInspector({ children }: {
7
+ children: ReactNode;
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,73 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The comments panel (the right sidebar in comment mode) and the top bar button with the count of
4
+ // open threads.
5
+ import { useMemo } from 'react';
6
+ import { findBlock } from '../../../core/index.js';
7
+ import { openCount, threadsOf } from '../../../comments/shared.js';
8
+ import { Icon } from '../icons.js';
9
+ import { blockName } from '../names.js';
10
+ import { useRuntime } from '../runtime.js';
11
+ import { useEditor } from '../store.js';
12
+ import { formatSaveTime } from '../topbar/saveTime.js';
13
+ import { useOptionalValue, useValue, useValueSelector } from '../valueStore.js';
14
+ import { Avatar, Thread } from './Thread.js';
15
+ import './comments.scss';
16
+ /** Top bar: comment mode on or off, with the number of open threads. */
17
+ export function CommentsButton() {
18
+ const { comments } = useRuntime();
19
+ if (!comments)
20
+ return null;
21
+ return _jsx(CommentsToggle, { comments: comments });
22
+ }
23
+ function CommentsToggle({ comments }) {
24
+ const on = useValue(comments.mode);
25
+ const count = useValueSelector(comments.list, openCount);
26
+ const label = count > 0 ? `Comments, ${count} open` : 'Comments';
27
+ return (_jsxs("button", { type: "button", className: "builder-editor__icon-button builder-comments-button", "aria-pressed": on, "aria-label": label, "aria-keyshortcuts": "C", "data-tooltip": `${on ? 'Leave comment mode' : 'Comments'} · C`, onClick: () => comments.toggle(), children: [_jsx(Icon, { name: "comment" }), count > 0 && _jsx("span", { className: "builder-comments-button__badge", children: count > 99 ? '99+' : count })] }));
28
+ }
29
+ /** In comment mode the panel takes the inspector's place. The inspector stays mounted. */
30
+ export function CommentsOrInspector({ children }) {
31
+ const { comments } = useRuntime();
32
+ const on = useOptionalValue(comments?.mode ?? null) === true;
33
+ return (_jsxs(_Fragment, { children: [on && comments && _jsx(CommentsPanel, { comments: comments }), _jsx("div", { className: "builder-comments-keep", hidden: on, children: children })] }));
34
+ }
35
+ const FILTERS = [
36
+ { id: 'all', label: 'All' },
37
+ { id: 'open', label: 'Open' },
38
+ { id: 'resolved', label: 'Resolved' },
39
+ ];
40
+ function CommentsPanel({ comments }) {
41
+ const runtime = useRuntime();
42
+ const list = useValue(comments.list);
43
+ const loaded = useValue(comments.loaded);
44
+ const filter = useValue(comments.filter);
45
+ const openId = useValue(comments.open);
46
+ const threads = useMemo(() => threadsOf(list, filter), [list, filter]);
47
+ const counts = useMemo(() => {
48
+ const all = threadsOf(list);
49
+ const open = all.filter((t) => !t.root.resolved).length;
50
+ return { all: all.length, open, resolved: all.length - open };
51
+ }, [list]);
52
+ return (_jsxs("section", { className: "builder-comments-panel", "aria-label": "Comments", children: [_jsxs("header", { className: "builder-comments-panel__head", children: [_jsx("h2", { className: "builder-comments-panel__title", children: "Comments" }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Close comments", "data-tooltip": "Close \u00B7 C", onClick: () => comments.toggle(false), children: _jsx(Icon, { name: "close", size: 14 }) })] }), _jsx("div", { className: "builder-comments-panel__filter", children: _jsx("div", { className: "builder-editor__segmented builder-editor__segmented--full builder-editor__segmented--small", role: "tablist", "aria-label": "Show", children: FILTERS.map((option) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": filter === option.id, className: "builder-editor__segment", onClick: () => comments.filter.set(option.id), children: [option.label, counts[option.id] > 0 && _jsx("span", { className: "builder-editor__segment-count", children: counts[option.id] })] }, option.id))) }) }), _jsx("div", { className: "builder-comments-panel__list", children: threads.length === 0 ? (_jsxs("div", { className: "builder-editor__empty", children: [_jsx(Icon, { name: "comment", size: 20 }), _jsx("p", { children: !loaded ? 'Loading comments' : filter === 'resolved' ? 'No resolved comments' : filter === 'open' && counts.all > 0 ? 'All resolved' : 'No comments yet' }), loaded && filter !== 'resolved' && _jsx("p", { className: "builder-editor__hint", children: "Click a block on the canvas to comment on it." })] })) : (threads.map((thread) => _jsx(ThreadCard, { thread: thread, open: openId === thread.root.id, runtime: runtime, comments: comments }, thread.root.id))) })] }));
53
+ }
54
+ function ThreadCard({ thread, open, runtime, comments }) {
55
+ const { root, replies } = thread;
56
+ const block = useEditor(runtime.store, (s) => (root.blockId ? findBlock(s.view, root.blockId) : null));
57
+ const where = block ? blockName(block, runtime.blockLabel(block.type)) : null;
58
+ const last = replies.at(-1);
59
+ const show = () => {
60
+ comments.draft.set(null);
61
+ if (open) {
62
+ comments.open.set(null);
63
+ return;
64
+ }
65
+ comments.open.set(root.id);
66
+ if (!block)
67
+ return;
68
+ runtime.store.select(block.id);
69
+ runtime.postToCanvas({ type: 'scrollIntoView', id: block.id });
70
+ };
71
+ const classes = ['builder-comment-card', open && 'builder-comment-card--open', root.resolved && 'builder-comment-card--resolved'].filter(Boolean).join(' ');
72
+ return (_jsxs("div", { className: classes, children: [_jsxs("button", { type: "button", className: "builder-comment-card__summary", "aria-expanded": open, onClick: show, children: [_jsx(Avatar, { name: root.authorName }), _jsxs("span", { className: "builder-comment-card__main", children: [_jsxs("span", { className: "builder-comment__head", children: [_jsx("span", { className: "builder-comment__name", children: root.authorName }), _jsx("time", { className: "builder-comment__time", dateTime: root.createdAt, children: formatSaveTime(root.createdAt) }), root.resolved && (_jsx("span", { className: "builder-comment-card__resolved", "aria-label": "Resolved", children: _jsx(Icon, { name: "check", size: 12 }) }))] }), _jsx("span", { className: "builder-comment-card__body", children: root.body }), _jsxs("span", { className: "builder-comment-card__meta", children: [where ? (_jsx("span", { className: "builder-comment-card__where", children: where })) : (_jsx("span", { className: "builder-comment-card__deleted", children: "Block deleted" })), replies.length > 0 && (_jsxs("span", { children: [replies.length, " ", replies.length === 1 ? 'reply' : 'replies', last && ` · ${last.authorName}`] }))] })] })] }), open && !block && _jsx(Thread, { thread: thread, comments: comments })] }));
73
+ }
@@ -0,0 +1,26 @@
1
+ import { type CommentThread } from '../../../comments/shared.js';
2
+ import type { CommentsController } from './controller.js';
3
+ /** The signed-in user's author key, to tell their own comments. */
4
+ export declare function useAuthorKey(): string | null;
5
+ export declare function Avatar({ name }: {
6
+ name: string;
7
+ }): import("react").JSX.Element;
8
+ type InputProps = {
9
+ placeholder: string;
10
+ submitLabel: string;
11
+ initial?: string;
12
+ focusOnMount?: boolean;
13
+ /** Shows Cancel, and Escape cancels. */
14
+ onCancel?: () => void;
15
+ /** True when the text was saved: the box empties. */
16
+ onSubmit: (body: string) => Promise<boolean>;
17
+ };
18
+ /** A text box that grows with its text. Enter sends, Shift+Enter adds a line, Escape cancels. */
19
+ export declare function CommentInput({ placeholder, submitLabel, initial, focusOnMount, onCancel, onSubmit }: InputProps): import("react").JSX.Element;
20
+ /** The thread: resolve and close in the head, the comments, and a reply box. */
21
+ export declare function Thread({ thread, comments, onClose }: {
22
+ thread: CommentThread;
23
+ comments: CommentsController;
24
+ onClose?: () => void;
25
+ }): import("react").JSX.Element;
26
+ export {};
@@ -0,0 +1,84 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // A comment thread (the popover at a pin, and the panel for threads whose block is gone) and the
4
+ // text box that writes comments and replies.
5
+ import { useAuth, useConfig } from '@payloadcms/ui';
6
+ import { useEffect, useRef, useState } from 'react';
7
+ import { authorKeyOf, COMMENT_MAX } from '../../../comments/shared.js';
8
+ import { Icon } from '../icons.js';
9
+ import { initials } from '../live/presence.js';
10
+ import { formatSaveTime } from '../topbar/saveTime.js';
11
+ /** The signed-in user's author key, to tell their own comments. */
12
+ export function useAuthorKey() {
13
+ const { user } = useAuth();
14
+ const { config } = useConfig();
15
+ if (!user)
16
+ return null;
17
+ const u = user;
18
+ return authorKeyOf({ ...user, collection: typeof u.collection === 'string' ? u.collection : config.admin.user });
19
+ }
20
+ export function Avatar({ name }) {
21
+ return (_jsx("span", { className: "builder-comment__avatar", "aria-hidden": true, children: initials(name) }));
22
+ }
23
+ /** A text box that grows with its text. Enter sends, Shift+Enter adds a line, Escape cancels. */
24
+ export function CommentInput({ placeholder, submitLabel, initial = '', focusOnMount, onCancel, onSubmit }) {
25
+ const [text, setText] = useState(initial);
26
+ const [busy, setBusy] = useState(false);
27
+ const ref = useRef(null);
28
+ useEffect(() => {
29
+ if (!focusOnMount)
30
+ return;
31
+ const el = ref.current;
32
+ el?.focus();
33
+ el?.setSelectionRange(el.value.length, el.value.length);
34
+ }, [focusOnMount]);
35
+ const submit = async () => {
36
+ if (busy || !text.trim())
37
+ return;
38
+ setBusy(true);
39
+ const saved = await onSubmit(text);
40
+ setBusy(false);
41
+ if (saved)
42
+ setText('');
43
+ ref.current?.focus();
44
+ };
45
+ const onKeyDown = (e) => {
46
+ if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
47
+ e.preventDefault();
48
+ void submit();
49
+ }
50
+ if (e.key === 'Escape' && onCancel) {
51
+ e.preventDefault();
52
+ e.stopPropagation();
53
+ onCancel();
54
+ }
55
+ };
56
+ return (_jsxs("div", { className: "builder-comment-input", children: [_jsx("textarea", { ref: ref, rows: 1, value: text, maxLength: COMMENT_MAX, placeholder: placeholder, "aria-label": placeholder, onChange: (e) => setText(e.target.value), onKeyDown: onKeyDown }), _jsxs("div", { className: "builder-comment-input__actions", children: [onCancel && (_jsx("button", { type: "button", className: "builder-comment__text-button", onClick: onCancel, children: "Cancel" })), _jsx("button", { type: "button", className: "builder-comment__send", disabled: busy || !text.trim(), "aria-label": submitLabel, "data-tooltip": `${submitLabel} · Enter`, onClick: () => void submit(), children: _jsx(Icon, { name: "arrowUp", size: 14 }) })] })] }));
57
+ }
58
+ /** One comment: author, time, text, and Edit / Delete for its author. */
59
+ function CommentItem({ comment, own, comments, isRoot }) {
60
+ const [editing, setEditing] = useState(false);
61
+ const [confirming, setConfirming] = useState(false);
62
+ const time = formatSaveTime(comment.createdAt);
63
+ return (_jsxs("article", { className: "builder-comment", children: [_jsx(Avatar, { name: comment.authorName }), _jsxs("div", { className: "builder-comment__main", children: [_jsxs("header", { className: "builder-comment__head", children: [_jsx("span", { className: "builder-comment__name", children: comment.authorName }), _jsxs("time", { className: "builder-comment__time", dateTime: comment.createdAt, children: [time, comment.editedAt && ' · edited'] }), own && !editing && (_jsxs("span", { className: "builder-comment__tools", children: [_jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Edit", "data-tooltip": "Edit", onClick: () => setEditing(true), children: _jsx(Icon, { name: "rename", size: 13 }) }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Delete", "data-tooltip": "Delete", onClick: () => setConfirming(true), children: _jsx(Icon, { name: "delete", size: 13 }) })] }))] }), editing ? (_jsx(CommentInput, { placeholder: "Edit comment", submitLabel: "Save", initial: comment.body, focusOnMount: true, onCancel: () => setEditing(false), onSubmit: async (body) => {
64
+ const saved = await comments.edit(comment.id, body);
65
+ if (saved)
66
+ setEditing(false);
67
+ return saved;
68
+ } })) : (_jsx("p", { className: "builder-comment__body", children: comment.body })), confirming && (_jsxs("div", { className: "builder-comment__confirm", role: "alert", children: [_jsx("span", { children: isRoot ? 'Delete this thread and its replies?' : 'Delete this reply?' }), _jsx("button", { type: "button", className: "builder-comment__text-button", onClick: () => setConfirming(false), children: "Cancel" }), _jsx("button", { type: "button", className: "builder-comment__text-button builder-comment__text-button--danger", onClick: () => void comments.remove(comment.id), children: "Delete" })] }))] })] }));
69
+ }
70
+ /** The thread: resolve and close in the head, the comments, and a reply box. */
71
+ export function Thread({ thread, comments, onClose }) {
72
+ const me = useAuthorKey();
73
+ const { root, replies } = thread;
74
+ const [busy, setBusy] = useState(false);
75
+ const toggleResolved = async () => {
76
+ setBusy(true);
77
+ const done = await comments.setResolved(root.id, !root.resolved);
78
+ setBusy(false);
79
+ // Resolving closes the thread, as in Figma: it leaves the open list.
80
+ if (done && !root.resolved)
81
+ onClose?.();
82
+ };
83
+ return (_jsxs("div", { className: "builder-thread", children: [_jsxs("div", { className: "builder-thread__head", children: [_jsx("span", { className: "builder-thread__status", children: root.resolved ? `Resolved${root.resolvedByName ? ` by ${root.resolvedByName}` : ''}` : replies.length > 0 ? `${replies.length + 1} comments` : 'Comment' }), _jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-pressed": root.resolved, "aria-label": root.resolved ? 'Reopen' : 'Resolve', "data-tooltip": root.resolved ? 'Reopen' : 'Resolve', disabled: busy, onClick: () => void toggleResolved(), children: _jsx(Icon, { name: root.resolved ? 'undo' : 'check', size: 14 }) }), onClose && (_jsx("button", { type: "button", className: "builder-editor__icon-button builder-editor__icon-button--small", "aria-label": "Close", "data-tooltip": "Close \u00B7 Esc", onClick: onClose, children: _jsx(Icon, { name: "close", size: 14 }) }))] }), _jsx("div", { className: "builder-thread__items", children: [root, ...replies].map((comment) => (_jsx(CommentItem, { comment: comment, own: comment.authorKey === me, comments: comments, isRoot: comment === root }, comment.id))) }), _jsx("div", { className: "builder-thread__reply", children: _jsx(CommentInput, { placeholder: "Reply", submitLabel: "Reply", focusOnMount: Boolean(onClose), onSubmit: (body) => comments.reply(root.id, body) }, root.id) })] }));
84
+ }