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
@@ -1,26 +1,32 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- // Every class of the block in one editable field, with autocomplete from the theme's class list.
4
- // Typed variant prefixes ("md:hover:") and "!" / "-" stay in front of the picked class.
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // The classes field of the Styles panel (`ClassChips`), like the ".cls" field of Chrome DevTools:
4
+ //
5
+ // - editable classes (the `builder-classes` collection) are solid chips. A click makes the style
6
+ // controls edit that class (`onSelect`); a second click goes back to the block.
7
+ // - the classes no style control shows ("dark:pt-4", a code `@utility` class) are quiet chips in
8
+ // monospace. A click edits one in place; × removes it.
9
+ // - the input at the end adds classes, with the site's classes and Tailwind's as suggestions.
10
+ //
11
+ // The classes the controls show (p-4, md:flex) have no chips: the controls show them. `ClassText`
12
+ // edits the whole class string as text instead ("Edit as text" in the field's menu).
5
13
  import { useEffect, useId, useMemo, useRef, useState } from 'react';
14
+ import { bareClass, classTokens } from '../../../classes/shared.js';
6
15
  import { unmanagedClasses } from '../../../core/index.js';
16
+ import { changeClasses, replaceToken } from './classEdit.js';
7
17
  import { useStyles } from './context.js';
8
18
  import { ResetIcon } from './icons.js';
9
- import { filterSuggestions, Popover, SuggestList, usePopover } from './popover.js';
10
- const classSuggestionCache = new WeakMap();
11
- function classSuggestions(tokens) {
12
- let list = classSuggestionCache.get(tokens);
13
- if (!list)
14
- classSuggestionCache.set(tokens, (list = tokens.classList.map((value) => ({ value }))));
15
- return list;
16
- }
19
+ import { Popover, SuggestList, usePopover } from './popover.js';
20
+ import { classSuggestions, siteClassOf } from './suggestions.js';
21
+ /** Variant prefixes ("md:hover:"), "!" and "-" in front of the utility being typed. */
22
+ const PREFIX = /^(?:[^\s:[\]]+:|!|-)*/;
17
23
  /** The word around the caret, split into its prefix ("md:hover:-") and the utility being typed. */
18
24
  function wordAt(text, caret) {
19
25
  const start = text.slice(0, caret).search(/\S*$/);
20
26
  const after = text.slice(caret).search(/\s|$/);
21
27
  const end = caret + after;
22
28
  const typed = text.slice(start, caret);
23
- const prefix = /^(?:[^\s:[\]]+:|!|-)*/.exec(typed)?.[0] ?? '';
29
+ const prefix = PREFIX.exec(typed)?.[0] ?? '';
24
30
  return { start, end, prefix, query: typed.slice(prefix.length) };
25
31
  }
26
32
  const knownCache = new WeakMap();
@@ -35,7 +41,8 @@ function knownClasses(tokens) {
35
41
  if (stem)
36
42
  numericStems.add(stem);
37
43
  }
38
- known = { names: new Set(tokens.classList), numericStems };
44
+ // The site's own classes count too (editable classes are in no Tailwind class list).
45
+ known = { names: new Set([...tokens.classList, ...(tokens.siteClasses ?? []).map((c) => c.name)]), numericStems };
39
46
  knownCache.set(tokens, known);
40
47
  return known;
41
48
  }
@@ -65,34 +72,174 @@ function safeUnmanaged(className, tokens) {
65
72
  return [];
66
73
  }
67
74
  }
68
- export function RawClasses() {
69
- const { blockId, className, tokens, setClassName } = useStyles();
75
+ /** True when the class token uses the editable class (also by a former name). */
76
+ const isClassOf = (token, item) => {
77
+ const name = bareClass(token);
78
+ return name === item.name || Boolean(item.previousNames?.includes(name));
79
+ };
80
+ export function ClassChips({ value, onChange, label, owner, editable = [], selected = null, onSelect }) {
81
+ const { tokens } = useStyles();
82
+ // Quiet chips: the classes no control shows, without the editable ones (those are solid chips).
83
+ const quiet = useMemo(() => safeUnmanaged(value, tokens).filter((token) => !editable.some((item) => isClassOf(token, item))), [value, tokens, editable]);
84
+ return (_jsxs("div", { className: "builder-classfield", role: "group", "aria-label": label, children: [editable.map((item) => {
85
+ const pressed = selected?.id === item.id;
86
+ return (_jsxs("span", { className: "builder-classfield__chip builder-classfield__chip--class", "data-selected": pressed || undefined, children: [_jsxs("button", { type: "button", className: "builder-classfield__chip-main", "aria-pressed": pressed, "data-tooltip": pressed ? `Stop editing .${item.name}` : `Edit .${item.name}. It changes every block that uses it.`, onClick: () => onSelect?.(pressed ? null : item), children: [_jsx("span", { className: "builder-classfield__chip-name", children: item.label || item.name }), item.status === 'draft' && _jsx("span", { className: "builder-classfield__draft-dot", "aria-label": "unpublished changes" })] }), _jsx("button", { type: "button", className: "builder-classfield__remove", "aria-label": `Remove .${item.name} from ${owner}`, onClick: () => {
87
+ if (pressed)
88
+ onSelect?.(null);
89
+ onChange(changeClasses(value, (token) => isClassOf(token, item)));
90
+ }, children: _jsx(ResetIcon, {}) })] }, item.id));
91
+ }), quiet.map((token) => (_jsx(QuietChip, { token: token, owner: owner, onReplace: (next) => onChange(replaceToken(value, token, next)) }, token))), _jsx(AddClass, { present: value, hasChips: editable.length + quiet.length > 0, onAdd: (names) => onChange(changeClasses(value, () => false, names)) })] }));
92
+ }
93
+ /** A class no control shows. A click edits it in place: Enter or leaving the field keeps the change, Escape drops it. */
94
+ function QuietChip({ token, owner, onReplace }) {
95
+ const { tokens } = useStyles();
96
+ const [draft, setDraft] = useState(null);
97
+ // The edit ends once: Enter or Escape removes the input, and a blur may follow.
98
+ const ended = useRef(false);
99
+ const unknown = isUnknownClass(token, tokens);
100
+ // A site class shows its label, with the class name small after it.
101
+ const site = siteClassOf(token, tokens.siteClasses);
102
+ const tooltip = unknown
103
+ ? `“${token}” is not in the theme’s class list, so it may have no effect. Check the spelling.`
104
+ : site?.site.css
105
+ ? `.${site.site.name} { ${site.site.css} }`
106
+ : 'Click to edit';
107
+ if (draft !== null) {
108
+ const done = (keep) => {
109
+ if (ended.current)
110
+ return;
111
+ ended.current = true;
112
+ setDraft(null);
113
+ if (keep && draft.trim() !== token)
114
+ onReplace(draft.trim());
115
+ };
116
+ return (_jsx("input", { className: "builder-classfield__edit", "aria-label": `Edit class ${token}`,
117
+ // oxlint-disable-next-line jsx-a11y/no-autofocus -- the input replaces the chip the user just clicked
118
+ autoFocus: true, value: draft, spellCheck: false, autoComplete: "off", onChange: (e) => setDraft(e.target.value), onFocus: (e) => e.currentTarget.select(), onBlur: () => done(true), onKeyDown: (e) => {
119
+ if (e.key === 'Enter') {
120
+ e.preventDefault();
121
+ done(true);
122
+ }
123
+ else if (e.key === 'Escape') {
124
+ e.stopPropagation();
125
+ done(false);
126
+ }
127
+ } }));
128
+ }
129
+ return (_jsxs("span", { className: "builder-classfield__chip builder-classfield__chip--raw", "data-unknown": unknown || undefined, children: [_jsxs("button", { type: "button", className: "builder-classfield__chip-main", "data-tooltip": tooltip, onClick: () => {
130
+ ended.current = false;
131
+ setDraft(token);
132
+ }, children: [unknown && _jsx("span", { className: "builder-styles__visually-hidden", children: "Unknown class: " }), site?.site.label ? (_jsxs("span", { className: "builder-classfield__chip-name", children: [site.prefix, site.site.label, " ", _jsx("span", { className: "builder-classfield__chip-code", children: site.site.name })] })) : (_jsx("span", { className: "builder-classfield__chip-name", children: token }))] }), _jsx("button", { type: "button", className: "builder-classfield__remove", "aria-label": `Remove ${token} from ${owner}`, onClick: () => onReplace(''), children: _jsx(ResetIcon, {}) })] }));
133
+ }
134
+ /**
135
+ * The input at the end of the field. Enter, Tab on a suggestion, or a space adds what is typed;
136
+ * pasted lists add every class. A typed variant prefix ("md:") stays in front of the picked class.
137
+ */
138
+ function AddClass({ present, hasChips, onAdd }) {
139
+ const { tokens } = useStyles();
140
+ const listId = useId();
141
+ const inputRef = useRef(null);
142
+ const pop = usePopover('manual', true);
143
+ const [text, setText] = useState('');
144
+ // The suggestion the arrow keys chose. Null: while typing, the class typed (when it is in the
145
+ // list) or else the first suggestion; with nothing typed, none, so Enter does nothing.
146
+ const [chosen, setChosen] = useState(null);
147
+ const [focused, setFocused] = useState(false);
148
+ const prefix = PREFIX.exec(text)?.[0] ?? '';
149
+ const query = text.slice(prefix.length);
150
+ const own = useMemo(() => new Set(classTokens(present).map(bareClass)), [present]);
151
+ // Focused and empty (or only a variant typed): the site's own classes, to browse.
152
+ const items = useMemo(() => (focused ? classSuggestions(tokens, query, 60, own) : []), [focused, tokens, query, own]);
153
+ const exact = items.findIndex((item) => item.value === query);
154
+ const active = chosen ?? (query ? Math.max(0, exact) : -1);
155
+ const open = focused && items.length > 0;
156
+ const { show, hide } = pop;
157
+ useEffect(() => {
158
+ const el = inputRef.current;
159
+ if (open && el)
160
+ show(el);
161
+ else
162
+ hide();
163
+ }, [open, show, hide]);
164
+ const add = (names) => {
165
+ const list = names.map((n) => n.trim()).filter(Boolean);
166
+ if (list.length > 0)
167
+ onAdd(list);
168
+ setText('');
169
+ setChosen(null);
170
+ };
171
+ const onKeyDown = (e) => {
172
+ if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && open) {
173
+ e.preventDefault();
174
+ const step = e.key === 'ArrowDown' ? 1 : -1;
175
+ setChosen(Math.max(0, Math.min(items.length - 1, active + step)));
176
+ }
177
+ else if (e.key === 'Enter' || (e.key === 'Tab' && active >= 0 && open)) {
178
+ e.preventDefault();
179
+ const item = open ? items[active] : undefined;
180
+ add([item ? `${prefix}${item.value}` : text]);
181
+ }
182
+ else if (e.key === 'Escape') {
183
+ e.stopPropagation();
184
+ if (text)
185
+ setText('');
186
+ else
187
+ inputRef.current?.blur();
188
+ }
189
+ };
190
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: inputRef, className: "builder-classfield__input", role: "combobox", "aria-label": "Add a class", "aria-expanded": open, "aria-controls": listId, "aria-autocomplete": "list", value: text, spellCheck: false, autoComplete: "off", placeholder: hasChips ? 'Add' : 'Add a class', onChange: (e) => {
191
+ // A space ends a class: the words before it are added, the rest stays typed.
192
+ const parts = e.target.value.split(/\s+/);
193
+ const rest = parts.pop() ?? '';
194
+ if (parts.some(Boolean))
195
+ add(parts);
196
+ setText(rest);
197
+ setChosen(null);
198
+ }, onFocus: () => setFocused(true), onBlur: () => {
199
+ setFocused(false);
200
+ setChosen(null);
201
+ }, onKeyDown: onKeyDown }), _jsx(Popover, { ...pop.props, className: "builder-styles__popover--list", children: _jsx("div", { id: listId, children: open && pop.open && (_jsx(SuggestList, { items: items, active: active, onHover: setChosen, onPick: (item) => add([`${prefix}${item.value}`]) })) }) })] }));
202
+ }
203
+ /**
204
+ * The whole class string as text, with autocomplete ("Edit as text" in the field's menu). Typed
205
+ * variant prefixes ("md:hover:") and "!" / "-" stay in front of the picked class.
206
+ */
207
+ export function ClassText({ value, onChange, label }) {
208
+ const { blockId, tokens } = useStyles();
70
209
  const listId = useId();
71
210
  const inputRef = useRef(null);
72
211
  const pop = usePopover('manual', true);
73
212
  const [draft, setDraft] = useState(null);
74
213
  const [caret, setCaret] = useState(0);
214
+ // -1: no item is chosen yet, so Enter and Tab keep their usual job.
75
215
  const [active, setActive] = useState(0);
76
- const text = draft ?? className;
216
+ // The field got the focus: it lists the site classes until the user types or picks one.
217
+ const [browse, setBrowse] = useState(false);
218
+ const text = draft ?? value;
77
219
  const word = wordAt(text, caret);
78
- const all = classSuggestions(tokens);
79
- const items = useMemo(() => (word.query ? filterSuggestions(all, word.query, 60) : []), [all, word.query]);
80
- const others = useMemo(() => safeUnmanaged(className, tokens), [className, tokens]);
220
+ const listSite = !word.query && (browse || (draft !== null && word.prefix !== ''));
221
+ const own = useMemo(() => new Set(value.split(/\s+/)), [value]);
222
+ const items = useMemo(() => (word.query || listSite ? classSuggestions(tokens, word.query, 60, own) : []), [tokens, word.query, listSite, own]);
81
223
  const update = (next, nextCaret) => {
82
224
  setDraft(next);
83
225
  setCaret(nextCaret);
84
226
  setActive(0);
85
- setClassName(next, `className:${blockId}`);
227
+ setBrowse(false);
228
+ onChange(next, `className:${blockId}`);
86
229
  };
230
+ // The picked class replaces the word at the caret, with the word's variant prefix. With the
231
+ // caret inside a class and nothing typed, it goes at the end instead, so no class is lost.
87
232
  const pick = (item) => {
88
- const rest = text.slice(word.end).replace(/^\s*/, '');
89
233
  const inserted = `${word.prefix}${item.value} `;
90
- const next = `${text.slice(0, word.start)}${inserted}${rest}`;
91
- const nextCaret = word.start + inserted.length;
234
+ const append = !word.query && !word.prefix && word.end > caret;
235
+ const head = append ? `${text.trimEnd()}${text.trim() ? ' ' : ''}` : text.slice(0, word.start);
236
+ const rest = append ? '' : text.slice(word.end).replace(/^\s*/, '');
237
+ const next = `${head}${inserted}${rest}`;
238
+ const nextCaret = head.length + inserted.length;
92
239
  update(next, nextCaret);
93
240
  requestAnimationFrame(() => inputRef.current?.setSelectionRange(nextCaret, nextCaret));
94
241
  };
95
- const open = draft !== null && items.length > 0;
242
+ const open = (draft !== null || browse) && items.length > 0;
96
243
  const { show, hide } = pop;
97
244
  useEffect(() => {
98
245
  const el = inputRef.current;
@@ -114,21 +261,26 @@ export function RawClasses() {
114
261
  setActive((i) => Math.max(0, Math.min(items.length - 1, i + step)));
115
262
  }
116
263
  else if (e.key === 'Enter' || e.key === 'Tab') {
117
- e.preventDefault();
118
264
  const item = items[active];
265
+ if (e.key === 'Enter' || item)
266
+ e.preventDefault();
119
267
  if (item)
120
268
  pick(item);
269
+ else
270
+ setBrowse(false);
121
271
  }
122
272
  else if (e.key === 'Escape') {
123
273
  e.stopPropagation();
124
274
  setDraft(null);
275
+ setBrowse(false);
125
276
  }
126
277
  };
127
- return (_jsxs("div", { className: "builder-styles__raw", children: [_jsx("label", { className: "builder-styles__raw-label", htmlFor: `${listId}-input`, children: "Classes" }), _jsx("textarea", { id: `${listId}-input`, ref: inputRef, className: "builder-styles__raw-input", rows: 3, value: text, spellCheck: false, autoComplete: "off", placeholder: "bg-red-500 p-8 md:flex", onChange: (e) => update(e.target.value.replace(/\n/g, ' '), e.target.selectionStart), onSelect: (e) => setCaret(e.currentTarget.selectionStart), onBlur: () => setDraft(null), onKeyDown: onKeyDown }), _jsx(Popover, { ...pop.props, className: "builder-styles__popover--list", children: _jsx("div", { id: listId, children: open && pop.open && _jsx(SuggestList, { items: items, active: active, onHover: setActive, onPick: pick }) }) }), others.length > 0 && (_jsxs("div", { className: "builder-styles__others", children: [_jsx("span", { className: "builder-styles__raw-label", children: "Other classes" }), _jsx("ul", { className: "builder-styles__chips", children: others.map((name) => {
128
- const unknown = isUnknownClass(name, tokens);
129
- return (_jsxs("li", { className: `builder-styles__class-chip${unknown ? ' builder-styles__class-chip--unknown' : ''}`, "data-tooltip": unknown ? `“${name}” is not in the theme’s class list, so it may have no effect. Check the spelling.` : undefined, children: [unknown && _jsx("span", { className: "builder-styles__visually-hidden", children: "Unknown class: " }), _jsx("code", { children: name }), _jsx("button", { type: "button", className: "builder-styles__reset", "aria-label": `Remove ${name}`, onClick: () => setClassName(className
130
- .split(/\s+/)
131
- .filter((c) => c && c !== name)
132
- .join(' ')), children: _jsx(ResetIcon, {}) })] }, name));
133
- }) })] }))] }));
278
+ return (_jsxs(_Fragment, { children: [_jsx("textarea", { ref: inputRef, "aria-label": label, className: "builder-styles__raw-input", rows: 3, value: text, spellCheck: false, autoComplete: "off", placeholder: "bg-red-500 p-8 md:flex", onChange: (e) => update(e.target.value.replace(/\n/g, ' '), e.target.selectionStart), onSelect: (e) => setCaret(e.currentTarget.selectionStart), onFocus: (e) => {
279
+ setCaret(e.currentTarget.selectionStart);
280
+ setActive(-1);
281
+ setBrowse(true);
282
+ }, onBlur: () => {
283
+ setDraft(null);
284
+ setBrowse(false);
285
+ }, onKeyDown: onKeyDown }), _jsx(Popover, { ...pop.props, className: "builder-styles__popover--list", children: _jsx("div", { id: listId, children: open && pop.open && _jsx(SuggestList, { items: items, active: active, onHover: setActive, onPick: pick }) }) })] }));
134
286
  }
@@ -1,7 +1,7 @@
1
1
  import type { Block } from '../../../core/types.js';
2
2
  import './styles.scss';
3
- /** `slot`: edit the classes of that slot's own element (`slotClassName`) instead of the block's. */
4
- export declare function StylesPanel({ block, slot }: {
3
+ /** `part`: edit the classes of that inner element (`partClassName`, see `blockParts`) instead of the block's. */
4
+ export declare function StylesPanel({ block, part }: {
5
5
  block: Block;
6
- slot?: string | null;
6
+ part?: string | null;
7
7
  }): import("react").JSX.Element;
@@ -1,38 +1,76 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- // The Styles tab: variant bar, visual controls per style group, and the raw classes field.
4
- import { useMemo, useState } from 'react';
3
+ // The Styles tab: the classes field (the block's classes; a click on an editable class makes the
4
+ // controls edit it), the variant bar, the visual controls per style group, and while a class is
5
+ // edited, its other classes and custom CSS.
6
+ import { useEffect, useMemo, useRef, useState } from 'react';
7
+ import { bareClass, classTokens, mergeSiteClasses } from '../../../classes/shared.js';
5
8
  import { STYLE_PROPERTIES } from '../../../core/index.js';
9
+ import { ClassManager } from '../classes/ClassManager.js';
6
10
  import { useRuntime } from '../runtime.js';
7
11
  import { useEditor } from '../store.js';
8
12
  import { createValueStore, useValue } from '../valueStore.js';
9
- import { StylesContext, writeClassName, writeStyle } from './context.js';
13
+ import { ClassBar, ClassExtras } from './ClassBar.js';
14
+ import { ClassCss } from './ClassCss.js';
15
+ import { ClassDialog } from './ClassDialog.js';
16
+ import { StylesContext, writeClassStyle, writeStyle } from './context.js';
10
17
  import { createReader } from './model.js';
11
18
  import { stopEditorKeys } from './popover.js';
12
- import { RawClasses } from './RawClasses.js';
13
- import { SiteClasses } from './SiteClasses.js';
14
19
  import { StyleSections } from './sections.js';
15
20
  import { BREAKPOINTS, breakpointAt, breakpointWidths, reloadStyleTokens, useStyleTokens, withFallback } from './tokens.js';
16
21
  import { VariantBar } from './VariantBar.js';
17
22
  import './styles.scss';
18
- /** `slot`: edit the classes of that slot's own element (`slotClassName`) instead of the block's. */
19
- export function StylesPanel({ block, slot = null }) {
23
+ const NO_CLASSES = createValueStore([]);
24
+ const NO_TARGET = createValueStore(null);
25
+ /** The editable classes a class string uses (also by a former name), in its order, once each. */
26
+ function classesOn(className, list) {
27
+ const out = [];
28
+ for (const token of classTokens(className)) {
29
+ const name = bareClass(token);
30
+ const item = list.find((c) => c.name === name) ?? list.find((c) => c.previousNames?.includes(name));
31
+ if (item && !out.includes(item))
32
+ out.push(item);
33
+ }
34
+ return out;
35
+ }
36
+ /** The theme's tokens with the editable classes as site classes (suggestions, labels, known names). */
37
+ const withClasses = (tokens, list) => list.length > 0 ? { ...tokens, siteClasses: mergeSiteClasses(list, tokens.siteClasses) } : tokens;
38
+ /** `part`: edit the classes of that inner element (`partClassName`, see `blockParts`) instead of the block's. */
39
+ export function StylesPanel({ block, part = null }) {
20
40
  const runtime = useRuntime();
21
41
  const { tokensEndpoint } = runtime.config;
22
42
  const entry = useStyleTokens(tokensEndpoint);
23
- const tokens = useMemo(() => withFallback(entry.tokens), [entry.tokens]);
43
+ const classes = runtime.classes;
44
+ const classList = useValue(classes?.list ?? NO_CLASSES);
45
+ const targetId = useValue(classes?.target ?? NO_TARGET);
46
+ const tokens = useMemo(() => withClasses(withFallback(entry.tokens), classList), [entry.tokens, classList]);
24
47
  const variant = useEditor(runtime.store, (s) => s.variant);
25
48
  const frame = useValue(runtime.frame);
26
49
  const widths = useMemo(() => breakpointWidths(tokens), [tokens]);
27
50
  const canvasBreakpoint = frame.width > 0 ? breakpointAt(widths, frame.width) : 'base';
28
- const className = (slot ? block.slotClassName?.[slot] : block.className) ?? '';
51
+ const blockClassName = (part ? block.partClassName?.[part] : block.className) ?? '';
52
+ const own = useMemo(() => classesOn(blockClassName, classList), [blockClassName, classList]);
53
+ // The class the controls edit: only one this block (or part) uses.
54
+ const editing = targetId === null ? null : (own.find((c) => String(c.id) === String(targetId)) ?? null);
55
+ const className = editing ? (editing.styles ?? '') : blockClassName;
29
56
  const blockId = block.id;
30
57
  const [error] = useState(() => createValueStore(null));
31
58
  const message = useValue(error);
59
+ // Another block without the class: back to "This block". (The same block may miss the class for
60
+ // a moment, while a rename reaches its layout.)
61
+ const shownBlock = useRef(blockId);
62
+ useEffect(() => {
63
+ if (shownBlock.current === blockId)
64
+ return;
65
+ shownBlock.current = blockId;
66
+ if (targetId !== null && !editing)
67
+ classes?.target.set(null);
68
+ }, [blockId, targetId, editing, classes]);
32
69
  const value = useMemo(() => ({
33
70
  blockId,
34
- slot,
71
+ part,
35
72
  blockType: block.type,
73
+ editingClass: editing,
36
74
  className,
37
75
  variant,
38
76
  tokens,
@@ -41,9 +79,10 @@ export function StylesPanel({ block, slot = null }) {
41
79
  ? createReader(className, { ...variant, breakpoint: canvasBreakpoint }, tokens)
42
80
  : null,
43
81
  canvasBreakpoint,
44
- set: (property, v, options) => error.set(writeStyle(runtime, { blockId, slot }, variant, tokens, property, v, options)),
45
- setClassName: (next, mergeKey) => writeClassName(runtime, { blockId, slot }, next, mergeKey),
82
+ set: (property, v, options) => error.set(editing && classes
83
+ ? writeClassStyle(classes, editing.id, variant, tokens, property, v, options)
84
+ : writeStyle(runtime, { blockId, part }, variant, tokens, property, v, options)),
46
85
  error,
47
- }), [runtime, blockId, slot, block.type, className, variant, tokens, error, canvasBreakpoint]);
48
- return (_jsx(StylesContext, { value: value, children: _jsxs("div", { className: "builder-styles", onKeyDown: stopEditorKeys, children: [_jsx(VariantBar, {}), message && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", role: "alert", children: [message, ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => error.set(null), children: "Dismiss" })] })), entry.error && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", children: ["Theme tokens did not load (", entry.error, ").", ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => reloadStyleTokens(tokensEndpoint), children: "Retry" })] })), STYLE_PROPERTIES.length > 0 ? (_jsx(StyleSections, {})) : (_jsx("p", { className: "builder-styles__hint", children: "Visual style controls are not available yet. Edit the classes below." })), _jsx(SiteClasses, {}), _jsx(RawClasses, {})] }) }));
86
+ }), [runtime, classes, editing, blockId, part, block.type, className, variant, tokens, error, canvasBreakpoint]);
87
+ return (_jsxs(StylesContext, { value: value, children: [_jsxs("div", { className: "builder-styles", onKeyDown: stopEditorKeys, children: [_jsx(ClassBar, { className: blockClassName, own: own }), _jsx(VariantBar, {}), message && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", role: "alert", children: [message, ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => error.set(null), children: "Dismiss" })] })), entry.error && (_jsxs("p", { className: "builder-styles__hint builder-styles__hint--error", children: ["Theme tokens did not load (", entry.error, ").", ' ', _jsx("button", { type: "button", className: "builder-styles__link", onClick: () => reloadStyleTokens(tokensEndpoint), children: "Retry" })] })), STYLE_PROPERTIES.length > 0 ? (_jsx(StyleSections, {})) : (_jsx("p", { className: "builder-styles__hint", children: "Visual style controls are not available yet. Edit the classes above." })), editing && _jsx(ClassExtras, { item: editing }), editing && _jsx(ClassCss, { item: editing })] }), classes && _jsx(ClassDialog, {}), classes && _jsx(ClassManager, {})] }));
49
88
  }
@@ -34,7 +34,7 @@ export function breakpointLabel(bp, widths) {
34
34
  export function VariantBar() {
35
35
  const runtime = useRuntime();
36
36
  const { store } = runtime;
37
- const { className, variant, tokens } = useStyles();
37
+ const { className, variant, tokens, editingClass, part } = useStyles();
38
38
  const frame = useValue(runtime.frame);
39
39
  const widths = useMemo(() => breakpointWidths(tokens), [tokens]);
40
40
  const inUse = useMemo(() => safeVariantsInUse(className, tokens), [className, tokens]);
@@ -46,5 +46,5 @@ export function VariantBar() {
46
46
  const used = id !== 'default' && inUse.some((v) => v.breakpoint === variant.breakpoint && v.state === id);
47
47
  return { value: id, label: STATE_LABELS[id], suffix: used ? _jsx("span", { className: "builder-styles__dot", "aria-label": "has classes" }) : undefined };
48
48
  }), [inUse, variant.breakpoint]);
49
- return (_jsxs("div", { className: "builder-styles__variants", children: [_jsx("fieldset", { className: "builder-styles__breakpoints", "aria-label": "Breakpoint", children: BREAKPOINTS.map((bp) => (_jsxs("button", { type: "button", className: "builder-styles__chip", "aria-pressed": variant.breakpoint === bp, "data-tooltip": bp === 'base' ? 'Styles for every screen size' : `Styles for screens ${widths[bp]} px and wider`, onClick: () => store.setVariant({ ...variant, breakpoint: bp }), children: [_jsx("span", { className: "builder-styles__chip-name", children: bp === 'base' ? 'All' : bp }), _jsx("span", { className: "builder-styles__chip-width", children: bp === 'base' ? 'sizes' : `${widths[bp]}+` }), inUse.some((v) => v.breakpoint === bp) && _jsx("span", { className: "builder-styles__dot" })] }, bp))) }), _jsxs("div", { className: "builder-styles__state-row", children: [_jsxs("p", { className: "builder-styles__variant-hint", children: ["Editing ", _jsx("strong", { children: breakpointLabel(variant.breakpoint, widths) }), prefix && (_jsxs(_Fragment, { children: [' ', _jsx("code", { children: prefix })] }))] }), _jsxs("div", { className: "builder-styles__state-field", children: [_jsx("span", { "aria-hidden": "true", children: "State" }), _jsx(Select, { size: "compact", "aria-label": "State", options: stateOptions, value: variant.state, onValueChange: (state) => state && store.setVariant({ ...variant, state: state }) })] })] }), tooNarrow && (_jsxs("output", { className: "builder-styles__width-hint", children: [_jsxs("span", { children: [variant.breakpoint, " styles don\u2019t apply at the current ", Math.round(frame.width), " px width."] }), _jsxs("button", { type: "button", className: "builder-styles__width-action", onClick: () => store.setCanvasWidth(minWidth), children: [_jsx(Icon, { name: "width", size: 14 }), " Resize canvas"] })] }))] }));
49
+ return (_jsxs("div", { className: "builder-styles__variants", children: [_jsx("fieldset", { className: "builder-styles__breakpoints", "aria-label": "Breakpoint", children: BREAKPOINTS.map((bp) => (_jsxs("button", { type: "button", className: "builder-styles__chip", "aria-pressed": variant.breakpoint === bp, "data-tooltip": bp === 'base' ? 'Styles for every screen size' : `Styles for screens ${widths[bp]} px and wider`, onClick: () => store.setVariant({ ...variant, breakpoint: bp }), children: [_jsx("span", { className: "builder-styles__chip-name", children: bp === 'base' ? 'All' : bp }), _jsx("span", { className: "builder-styles__chip-width", children: bp === 'base' ? 'sizes' : `${widths[bp]}+` }), inUse.some((v) => v.breakpoint === bp) && _jsx("span", { className: "builder-styles__dot" })] }, bp))) }), _jsxs("div", { className: "builder-styles__state-row", children: [_jsxs("p", { className: "builder-styles__variant-hint", children: ["Editing", ' ', editingClass ? (_jsxs("code", { className: "builder-styles__variant-class", children: [".", editingClass.name] })) : (_jsx("strong", { children: part ? 'this part' : 'this block' })), ' ', "at ", _jsx("strong", { children: breakpointLabel(variant.breakpoint, widths) }), prefix && (_jsxs(_Fragment, { children: [' ', _jsx("code", { children: prefix })] }))] }), _jsxs("div", { className: "builder-styles__state-field", children: [_jsx("span", { "aria-hidden": "true", children: "State" }), _jsx(Select, { size: "compact", "aria-label": "State", options: stateOptions, value: variant.state, onValueChange: (state) => state && store.setVariant({ ...variant, state: state }) })] })] }), tooNarrow && (_jsxs("output", { className: "builder-styles__width-hint", children: [_jsxs("span", { children: [variant.breakpoint, " styles don\u2019t apply at the current ", Math.round(frame.width), " px width."] }), _jsxs("button", { type: "button", className: "builder-styles__width-action", onClick: () => store.setCanvasWidth(minWidth), children: [_jsx(Icon, { name: "width", size: 14 }), " Resize canvas"] })] }))] }));
50
50
  }
@@ -0,0 +1,4 @@
1
+ /** The class string with `remove` taken out and `add` put at the end, once each. */
2
+ export declare function changeClasses(className: string, remove: (token: string) => boolean, add?: readonly string[]): string;
3
+ /** The class string with one class replaced in place by `next` (none, one or more classes). */
4
+ export declare function replaceToken(className: string, token: string, next: string): string;
@@ -0,0 +1,20 @@
1
+ // Class string edits of the classes field (RawClasses.tsx). Pure, so they are tested without React.
2
+ import { classTokens } from '../../../classes/shared.js';
3
+ /** The class string with `remove` taken out and `add` put at the end, once each. */
4
+ export function changeClasses(className, remove, add = []) {
5
+ const kept = classTokens(className).filter((token) => !remove(token));
6
+ for (const token of add)
7
+ if (!kept.includes(token))
8
+ kept.push(token);
9
+ return kept.join(' ');
10
+ }
11
+ /** The class string with one class replaced in place by `next` (none, one or more classes). */
12
+ export function replaceToken(className, token, next) {
13
+ const out = [];
14
+ for (const item of classTokens(className)) {
15
+ for (const value of item === token ? classTokens(next) : [item])
16
+ if (!out.includes(value))
17
+ out.push(value);
18
+ }
19
+ return out.join(' ');
20
+ }