payload-canvas 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/README.md +626 -154
  2. package/dist/admin/AiKeyField.d.ts +8 -0
  3. package/dist/admin/AiKeyField.js +54 -0
  4. package/dist/admin/BuilderTab.js +4 -1
  5. package/dist/admin/DocumentEditView.d.ts +9 -0
  6. package/dist/admin/DocumentEditView.js +45 -0
  7. package/dist/admin/LayoutField.d.ts +2 -2
  8. package/dist/admin/LayoutField.js +10 -7
  9. package/dist/admin/TemplateConditionsField.d.ts +9 -0
  10. package/dist/admin/TemplateConditionsField.js +22 -0
  11. package/dist/admin/aiKeyField.scss +58 -0
  12. package/dist/admin/client.d.ts +3 -0
  13. package/dist/admin/client.js +6 -0
  14. package/dist/admin/diff/changes.js +5 -0
  15. package/dist/admin/editor/Canvas.js +20 -5
  16. package/dist/admin/editor/Editor.d.ts +3 -1
  17. package/dist/admin/editor/Editor.js +6 -3
  18. package/dist/admin/editor/Inspector.js +75 -28
  19. package/dist/admin/editor/Library.js +40 -15
  20. package/dist/admin/editor/Outline.js +21 -16
  21. package/dist/admin/editor/Overlay.js +8 -3
  22. package/dist/admin/editor/actions.d.ts +10 -2
  23. package/dist/admin/editor/actions.js +18 -3
  24. package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
  25. package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
  26. package/dist/admin/editor/classes/ClassManager.js +56 -0
  27. package/dist/admin/editor/classes/controller.d.ts +112 -0
  28. package/dist/admin/editor/classes/controller.js +326 -0
  29. package/dist/admin/editor/classes/manager.scss +262 -0
  30. package/dist/admin/editor/classes/managerModel.d.ts +5 -0
  31. package/dist/admin/editor/classes/managerModel.js +27 -0
  32. package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
  33. package/dist/admin/editor/comments/CommentLayer.js +143 -0
  34. package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
  35. package/dist/admin/editor/comments/CommentsPanel.js +73 -0
  36. package/dist/admin/editor/comments/Thread.d.ts +26 -0
  37. package/dist/admin/editor/comments/Thread.js +84 -0
  38. package/dist/admin/editor/comments/comments.scss +539 -0
  39. package/dist/admin/editor/comments/controller.d.ts +48 -0
  40. package/dist/admin/editor/comments/controller.js +142 -0
  41. package/dist/admin/editor/contentMode.d.ts +17 -0
  42. package/dist/admin/editor/contentMode.js +37 -0
  43. package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
  44. package/dist/admin/editor/dnd/DropOutlines.js +73 -0
  45. package/dist/admin/editor/dnd/dnd.scss +43 -0
  46. package/dist/admin/editor/dnd/mode.d.ts +4 -0
  47. package/dist/admin/editor/dnd/mode.js +39 -0
  48. package/dist/admin/editor/editor.scss +13 -58
  49. package/dist/admin/editor/empty/EmptyStart.js +18 -66
  50. package/dist/admin/editor/fields/AddButton.d.ts +15 -0
  51. package/dist/admin/editor/fields/AddButton.js +14 -0
  52. package/dist/admin/editor/fields/ArrayField.js +3 -2
  53. package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
  54. package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
  55. package/dist/admin/editor/fields/ConditionRows.js +137 -0
  56. package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
  57. package/dist/admin/editor/fields/ListWhereField.js +20 -0
  58. package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
  59. package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
  60. package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
  61. package/dist/admin/editor/fields/RelatedField.js +44 -0
  62. package/dist/admin/editor/fields/SortField.d.ts +13 -0
  63. package/dist/admin/editor/fields/SortField.js +37 -0
  64. package/dist/admin/editor/fields/WhereField.d.ts +12 -4
  65. package/dist/admin/editor/fields/WhereField.js +33 -53
  66. package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
  67. package/dist/admin/editor/fields/collectionFields.js +15 -0
  68. package/dist/admin/editor/fields/conditions.d.ts +99 -0
  69. package/dist/admin/editor/fields/conditions.js +339 -0
  70. package/dist/admin/editor/fields/fields.scss +232 -9
  71. package/dist/admin/editor/fields/listOptions.d.ts +44 -0
  72. package/dist/admin/editor/fields/listOptions.js +111 -0
  73. package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
  74. package/dist/admin/editor/fields/queryFilterRows.js +29 -0
  75. package/dist/admin/editor/fields/whereRows.d.ts +11 -12
  76. package/dist/admin/editor/fields/whereRows.js +83 -34
  77. package/dist/admin/editor/icons.d.ts +16 -1
  78. package/dist/admin/editor/icons.js +30 -1
  79. package/dist/admin/editor/inline.js +9 -0
  80. package/dist/admin/editor/insert/InsertHandle.js +4 -1
  81. package/dist/admin/editor/insert/picker.d.ts +3 -1
  82. package/dist/admin/editor/insert/picker.js +17 -10
  83. package/dist/admin/editor/insert/spots.d.ts +12 -1
  84. package/dist/admin/editor/insert/spots.js +49 -10
  85. package/dist/admin/editor/layout/LeftPanel.js +11 -6
  86. package/dist/admin/editor/live/useMultiplayer.js +9 -1
  87. package/dist/admin/editor/menu/blockMenu.js +27 -17
  88. package/dist/admin/editor/names.js +11 -3
  89. package/dist/admin/editor/renderField.d.ts +3 -1
  90. package/dist/admin/editor/renderField.js +63 -12
  91. package/dist/admin/editor/runtime.d.ts +14 -0
  92. package/dist/admin/editor/runtime.js +67 -6
  93. package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
  94. package/dist/admin/editor/sections/ComponentFields.js +116 -0
  95. package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
  96. package/dist/admin/editor/sections/PropertyControls.js +65 -0
  97. package/dist/admin/editor/sections/components.d.ts +29 -0
  98. package/dist/admin/editor/sections/components.js +112 -0
  99. package/dist/admin/editor/sections/components.scss +238 -0
  100. package/dist/admin/editor/sections/variants.d.ts +32 -0
  101. package/dist/admin/editor/sections/variants.js +59 -0
  102. package/dist/admin/editor/sections/variants.scss +90 -0
  103. package/dist/admin/editor/shortcuts.d.ts +4 -1
  104. package/dist/admin/editor/shortcuts.js +19 -3
  105. package/dist/admin/editor/store.d.ts +18 -0
  106. package/dist/admin/editor/store.js +46 -0
  107. package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
  108. package/dist/admin/editor/styles/ClassBar.js +90 -0
  109. package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
  110. package/dist/admin/editor/styles/ClassCss.js +28 -0
  111. package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
  112. package/dist/admin/editor/styles/ClassDialog.js +151 -0
  113. package/dist/admin/editor/styles/ColorPicker.js +5 -2
  114. package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
  115. package/dist/admin/editor/styles/RawClasses.js +184 -32
  116. package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
  117. package/dist/admin/editor/styles/StylesPanel.js +53 -14
  118. package/dist/admin/editor/styles/VariantBar.js +2 -2
  119. package/dist/admin/editor/styles/classEdit.d.ts +4 -0
  120. package/dist/admin/editor/styles/classEdit.js +20 -0
  121. package/dist/admin/editor/styles/classes.scss +381 -0
  122. package/dist/admin/editor/styles/context.d.ts +19 -6
  123. package/dist/admin/editor/styles/context.js +24 -6
  124. package/dist/admin/editor/styles/controls.d.ts +3 -1
  125. package/dist/admin/editor/styles/controls.js +30 -12
  126. package/dist/admin/editor/styles/popover.d.ts +6 -0
  127. package/dist/admin/editor/styles/popover.js +5 -5
  128. package/dist/admin/editor/styles/styles.scss +26 -104
  129. package/dist/admin/editor/styles/suggestions.d.ts +22 -0
  130. package/dist/admin/editor/styles/suggestions.js +77 -0
  131. package/dist/admin/editor/styles/tokens.js +14 -0
  132. package/dist/admin/editor/templates/Bindable.js +86 -57
  133. package/dist/admin/editor/templates/SamplePicker.js +1 -1
  134. package/dist/admin/editor/templates/Visibility.d.ts +9 -0
  135. package/dist/admin/editor/templates/Visibility.js +54 -0
  136. package/dist/admin/editor/templates/binding.d.ts +2 -2
  137. package/dist/admin/editor/templates/binding.js +2 -2
  138. package/dist/admin/editor/templates/templates.scss +27 -0
  139. package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
  140. package/dist/admin/editor/templates/visibilityRows.js +83 -0
  141. package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
  142. package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
  143. package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
  144. package/dist/admin/editor/topbar/DocumentActions.js +5 -4
  145. package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
  146. package/dist/admin/editor/topbar/TopBar.js +15 -3
  147. package/dist/admin/editor/topbar/contentMode.scss +35 -0
  148. package/dist/admin/editor/topbar/topbar.scss +3 -1
  149. package/dist/admin/formChoice.d.ts +3 -0
  150. package/dist/admin/formChoice.js +10 -0
  151. package/dist/admin/layoutField.scss +69 -0
  152. package/dist/admin/screen/BuilderScreen.d.ts +6 -1
  153. package/dist/admin/screen/BuilderScreen.js +4 -3
  154. package/dist/admin/server/BuilderView.js +10 -3
  155. package/dist/admin/templateConditions.scss +24 -0
  156. package/dist/ai/adapters/anthropic.js +17 -4
  157. package/dist/ai/adapters/cloudflare-gateway.js +7 -1
  158. package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
  159. package/dist/ai/adapters/openai-compatible.js +1 -0
  160. package/dist/ai/adapters/openrouter.js +2 -0
  161. package/dist/ai/config.d.ts +24 -4
  162. package/dist/ai/config.js +27 -8
  163. package/dist/ai/endpoint.d.ts +5 -2
  164. package/dist/ai/endpoint.js +31 -26
  165. package/dist/ai/images/cloudflare-workers-ai.js +6 -2
  166. package/dist/ai/images/openai.js +8 -3
  167. package/dist/ai/images/openrouter.js +6 -2
  168. package/dist/ai/images/service.d.ts +10 -4
  169. package/dist/ai/images/service.js +23 -7
  170. package/dist/ai/openai-format.d.ts +7 -0
  171. package/dist/ai/openai-format.js +17 -5
  172. package/dist/ai/prompt.d.ts +8 -0
  173. package/dist/ai/prompt.js +25 -5
  174. package/dist/ai/settings/index.d.ts +62 -0
  175. package/dist/ai/settings/index.js +264 -0
  176. package/dist/ai/settings/secret.d.ts +11 -0
  177. package/dist/ai/settings/secret.js +46 -0
  178. package/dist/ai/settings/shared.d.ts +22 -0
  179. package/dist/ai/settings/shared.js +3 -0
  180. package/dist/ai/tools.d.ts +3 -0
  181. package/dist/ai/tools.js +79 -15
  182. package/dist/ai/types.d.ts +43 -0
  183. package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
  184. package/dist/blocks/builtins/adjacentLinks.js +76 -0
  185. package/dist/blocks/builtins/carousel.d.ts +2 -29
  186. package/dist/blocks/builtins/carousel.js +44 -51
  187. package/dist/blocks/builtins/disclosure.d.ts +2 -1
  188. package/dist/blocks/builtins/disclosure.js +22 -32
  189. package/dist/blocks/builtins/embed.d.ts +15 -0
  190. package/dist/blocks/builtins/embed.js +47 -0
  191. package/dist/blocks/builtins/faq.d.ts +1 -1
  192. package/dist/blocks/builtins/faq.js +2 -2
  193. package/dist/blocks/builtins/filterLink.d.ts +1 -19
  194. package/dist/blocks/builtins/filterLink.js +9 -50
  195. package/dist/blocks/builtins/icon.d.ts +2 -0
  196. package/dist/blocks/builtins/icon.js +8 -8
  197. package/dist/blocks/builtins/index.d.ts +18 -13
  198. package/dist/blocks/builtins/index.js +43 -22
  199. package/dist/blocks/builtins/marquee.d.ts +5 -0
  200. package/dist/blocks/builtins/marquee.js +68 -0
  201. package/dist/blocks/builtins/popup.d.ts +5 -0
  202. package/dist/blocks/builtins/popup.js +83 -0
  203. package/dist/blocks/builtins/sectionRef.d.ts +16 -2
  204. package/dist/blocks/builtins/sectionRef.js +34 -12
  205. package/dist/blocks/builtins/shared.d.ts +18 -23
  206. package/dist/blocks/builtins/shared.js +34 -42
  207. package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
  208. package/dist/blocks/builtins/tableOfContents.js +12 -18
  209. package/dist/blocks/builtins/tabs.d.ts +6 -0
  210. package/dist/blocks/builtins/tabs.js +87 -0
  211. package/dist/blocks/client/adjacentLinks.d.ts +4 -0
  212. package/dist/blocks/client/adjacentLinks.js +4 -0
  213. package/dist/blocks/client/carousel.d.ts +45 -0
  214. package/dist/blocks/client/carousel.js +53 -0
  215. package/dist/blocks/client/embed.d.ts +21 -0
  216. package/dist/blocks/client/embed.js +23 -0
  217. package/dist/blocks/client/field.d.ts +7 -0
  218. package/dist/blocks/client/field.js +8 -0
  219. package/dist/blocks/client/filterLink.d.ts +19 -0
  220. package/dist/blocks/client/filterLink.js +30 -0
  221. package/dist/blocks/client/helpers.d.ts +21 -0
  222. package/dist/blocks/client/helpers.js +24 -0
  223. package/dist/blocks/client/marquee.d.ts +14 -0
  224. package/dist/blocks/client/marquee.js +25 -0
  225. package/dist/blocks/client/menu.d.ts +46 -0
  226. package/dist/blocks/client/menu.js +49 -0
  227. package/dist/blocks/client/popup.d.ts +15 -0
  228. package/dist/blocks/client/popup.js +16 -0
  229. package/dist/blocks/client/tabs.d.ts +10 -0
  230. package/dist/blocks/client/tabs.js +11 -0
  231. package/dist/blocks/defaults.d.ts +15 -52
  232. package/dist/blocks/defaults.js +203 -437
  233. package/dist/blocks/index.d.ts +1 -1
  234. package/dist/blocks/index.js +2 -1
  235. package/dist/classes/actions.d.ts +97 -0
  236. package/dist/classes/actions.js +296 -0
  237. package/dist/classes/collection.d.ts +5 -0
  238. package/dist/classes/collection.js +189 -0
  239. package/dist/classes/config.d.ts +34 -0
  240. package/dist/classes/config.js +8 -0
  241. package/dist/classes/endpoints.d.ts +2 -0
  242. package/dist/classes/endpoints.js +120 -0
  243. package/dist/classes/index.d.ts +36 -0
  244. package/dist/classes/index.js +42 -0
  245. package/dist/classes/mcp.d.ts +6 -0
  246. package/dist/classes/mcp.js +161 -0
  247. package/dist/classes/shared.d.ts +131 -0
  248. package/dist/classes/shared.js +300 -0
  249. package/dist/classes/sheet.d.ts +34 -0
  250. package/dist/classes/sheet.js +126 -0
  251. package/dist/classes/usage.d.ts +57 -0
  252. package/dist/classes/usage.js +208 -0
  253. package/dist/comments/collection.d.ts +38 -0
  254. package/dist/comments/collection.js +226 -0
  255. package/dist/comments/config.d.ts +15 -0
  256. package/dist/comments/config.js +2 -0
  257. package/dist/comments/index.d.ts +20 -0
  258. package/dist/comments/index.js +22 -0
  259. package/dist/comments/shared.d.ts +54 -0
  260. package/dist/comments/shared.js +104 -0
  261. package/dist/core/bindings.d.ts +77 -32
  262. package/dist/core/bindings.js +319 -134
  263. package/dist/core/blockNames.d.ts +9 -0
  264. package/dist/core/blockNames.js +11 -0
  265. package/dist/core/blocks.d.ts +21 -8
  266. package/dist/core/blocks.js +37 -16
  267. package/dist/core/classes.d.ts +16 -8
  268. package/dist/core/classes.js +31 -27
  269. package/dist/core/components.d.ts +72 -0
  270. package/dist/core/components.js +294 -0
  271. package/dist/core/contentMode.d.ts +27 -0
  272. package/dist/core/contentMode.js +0 -0
  273. package/dist/core/dropTarget.d.ts +11 -0
  274. package/dist/core/dropTarget.js +24 -1
  275. package/dist/core/fields.d.ts +5 -0
  276. package/dist/core/fields.js +11 -0
  277. package/dist/core/headings.d.ts +5 -2
  278. package/dist/core/headings.js +14 -6
  279. package/dist/core/index.d.ts +8 -3
  280. package/dist/core/index.js +8 -3
  281. package/dist/core/layers.d.ts +9 -0
  282. package/dist/core/layers.js +29 -0
  283. package/dist/core/operations.d.ts +6 -0
  284. package/dist/core/operations.js +85 -24
  285. package/dist/core/payloadBlocks.js +5 -1
  286. package/dist/core/references.js +28 -0
  287. package/dist/core/schema.js +20 -6
  288. package/dist/core/sectionOrigin.d.ts +6 -0
  289. package/dist/core/sectionOrigin.js +21 -0
  290. package/dist/core/sections.d.ts +72 -0
  291. package/dist/core/sections.js +331 -0
  292. package/dist/core/templateChoice.d.ts +24 -0
  293. package/dist/core/templateChoice.js +43 -0
  294. package/dist/core/tree.js +18 -6
  295. package/dist/core/types.d.ts +148 -18
  296. package/dist/core/validate.d.ts +4 -1
  297. package/dist/core/validate.js +28 -11
  298. package/dist/core/visibility.d.ts +63 -0
  299. package/dist/core/visibility.js +214 -0
  300. package/dist/core/whereValues.d.ts +22 -0
  301. package/dist/core/whereValues.js +43 -0
  302. package/dist/css/classes.d.ts +16 -0
  303. package/dist/css/classes.js +172 -0
  304. package/dist/css/index.d.ts +32 -1
  305. package/dist/css/index.js +64 -5
  306. package/dist/css/tokens.d.ts +10 -0
  307. package/dist/css/tokens.js +23 -10
  308. package/dist/index.d.ts +5 -2
  309. package/dist/index.js +6 -1
  310. package/dist/live/contentMode.d.ts +24 -0
  311. package/dist/live/contentMode.js +39 -0
  312. package/dist/live/endpoints.js +3 -0
  313. package/dist/live/session.d.ts +5 -0
  314. package/dist/live/session.js +8 -0
  315. package/dist/live/types.d.ts +16 -1
  316. package/dist/mcp/index.d.ts +10 -1
  317. package/dist/mcp/index.js +146 -54
  318. package/dist/mcp/shared.d.ts +93 -3
  319. package/dist/mcp/shared.js +211 -15
  320. package/dist/plugin/hook.d.ts +7 -1
  321. package/dist/plugin/hook.js +30 -4
  322. package/dist/plugin/index.d.ts +19 -8
  323. package/dist/plugin/index.js +89 -20
  324. package/dist/plugin/links.d.ts +24 -0
  325. package/dist/plugin/links.js +27 -0
  326. package/dist/plugin/listCollections.d.ts +9 -7
  327. package/dist/plugin/listCollections.js +30 -21
  328. package/dist/plugin/sections.d.ts +14 -7
  329. package/dist/plugin/sections.js +69 -23
  330. package/dist/plugin/sectionsUsedIn.d.ts +6 -0
  331. package/dist/plugin/sectionsUsedIn.js +24 -0
  332. package/dist/plugin/templateEndpoint.d.ts +9 -0
  333. package/dist/plugin/templateEndpoint.js +49 -0
  334. package/dist/plugin/templates.js +23 -8
  335. package/dist/protocol/index.d.ts +16 -1
  336. package/dist/react/canvas/BuilderCanvas.js +144 -21
  337. package/dist/react/canvas/classes.d.ts +17 -0
  338. package/dist/react/canvas/classes.js +102 -0
  339. package/dist/react/canvas/controls.d.ts +31 -0
  340. package/dist/react/canvas/controls.js +75 -0
  341. package/dist/react/canvas/fetchDocs.d.ts +2 -2
  342. package/dist/react/canvas/fetchDocs.js +16 -8
  343. package/dist/react/canvas/measure.d.ts +9 -0
  344. package/dist/react/canvas/measure.js +106 -7
  345. package/dist/react/canvas/resolveLayout.d.ts +1 -1
  346. package/dist/react/canvas/resolveLayout.js +4 -3
  347. package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
  348. package/dist/react/classes/ClassesStyle.d.ts +27 -0
  349. package/dist/react/classes/ClassesStyle.js +27 -0
  350. package/dist/react/components/Button.d.ts +2 -11
  351. package/dist/react/components/Button.js +8 -43
  352. package/dist/react/components/CollectionList.d.ts +4 -1
  353. package/dist/react/components/CollectionList.js +10 -3
  354. package/dist/react/components/Container.d.ts +5 -2
  355. package/dist/react/components/Container.js +7 -4
  356. package/dist/react/components/Field.js +3 -14
  357. package/dist/react/components/Link.d.ts +1 -1
  358. package/dist/react/components/Link.js +5 -3
  359. package/dist/react/components/List.d.ts +1 -1
  360. package/dist/react/components/List.js +2 -2
  361. package/dist/react/components/Menu.d.ts +10 -1
  362. package/dist/react/components/Menu.js +39 -12
  363. package/dist/react/components/RichText.d.ts +3 -4
  364. package/dist/react/components/RichText.js +5 -5
  365. package/dist/react/components/builtins/Accordion.d.ts +4 -3
  366. package/dist/react/components/builtins/Accordion.js +6 -5
  367. package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
  368. package/dist/react/components/builtins/AdjacentLinks.js +20 -0
  369. package/dist/react/components/builtins/Carousel.d.ts +21 -10
  370. package/dist/react/components/builtins/Carousel.js +175 -100
  371. package/dist/react/components/builtins/Disclosure.d.ts +4 -3
  372. package/dist/react/components/builtins/Disclosure.js +6 -5
  373. package/dist/react/components/builtins/Embed.d.ts +11 -0
  374. package/dist/react/components/builtins/Embed.js +23 -0
  375. package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
  376. package/dist/react/components/builtins/EmbedHtml.js +51 -0
  377. package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
  378. package/dist/react/components/builtins/EmbedPreview.js +105 -0
  379. package/dist/react/components/builtins/FilterLink.d.ts +1 -1
  380. package/dist/react/components/builtins/FilterLink.js +4 -4
  381. package/dist/react/components/builtins/Marquee.d.ts +8 -0
  382. package/dist/react/components/builtins/Marquee.js +15 -0
  383. package/dist/react/components/builtins/Popup.d.ts +26 -0
  384. package/dist/react/components/builtins/Popup.js +146 -0
  385. package/dist/react/components/builtins/SectionRef.d.ts +4 -3
  386. package/dist/react/components/builtins/SectionRef.js +9 -5
  387. package/dist/react/components/builtins/Tab.d.ts +7 -0
  388. package/dist/react/components/builtins/Tab.js +21 -0
  389. package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
  390. package/dist/react/components/builtins/TableOfContents.js +22 -7
  391. package/dist/react/components/builtins/Tabs.d.ts +17 -0
  392. package/dist/react/components/builtins/Tabs.js +71 -0
  393. package/dist/react/components/builtins/index.d.ts +37 -20
  394. package/dist/react/components/builtins/index.js +54 -20
  395. package/dist/react/components/builtins/tabsContext.d.ts +12 -0
  396. package/dist/react/components/builtins/tabsContext.js +6 -0
  397. package/dist/react/components/index.js +11 -8
  398. package/dist/react/components/lazy.d.ts +32 -0
  399. package/dist/react/components/lazy.js +20 -0
  400. package/dist/react/components/lazyBlock.d.ts +17 -0
  401. package/dist/react/components/lazyBlock.js +23 -0
  402. package/dist/react/index.d.ts +6 -3
  403. package/dist/react/index.js +5 -2
  404. package/dist/react/render/RenderLayout.d.ts +9 -7
  405. package/dist/react/render/RenderLayout.js +96 -45
  406. package/dist/react/render/canvasMode.d.ts +13 -0
  407. package/dist/react/render/canvasMode.js +13 -0
  408. package/dist/react/render/canvasServer.js +4 -3
  409. package/dist/react/render/canvasServerTypes.d.ts +5 -0
  410. package/dist/react/render/lists.d.ts +36 -4
  411. package/dist/react/render/lists.js +132 -15
  412. package/dist/react/render/marks.d.ts +15 -0
  413. package/dist/react/render/marks.js +23 -0
  414. package/dist/react/render/payload.d.ts +8 -1
  415. package/dist/react/render/payload.js +12 -3
  416. package/dist/react/render/preview.d.ts +11 -0
  417. package/dist/react/render/preview.js +13 -0
  418. package/dist/react/render/relations.d.ts +10 -0
  419. package/dist/react/render/relations.js +39 -0
  420. package/dist/react/render/resolve.d.ts +8 -4
  421. package/dist/react/render/resolve.js +11 -5
  422. package/dist/react/render/reveal.d.ts +17 -0
  423. package/dist/react/render/reveal.js +39 -0
  424. package/dist/react/render/sections.d.ts +11 -5
  425. package/dist/react/render/sections.js +52 -24
  426. package/dist/react/render/templates.d.ts +47 -0
  427. package/dist/react/render/templates.js +139 -0
  428. package/dist/react/render/types.d.ts +62 -5
  429. package/dist/react/server.d.ts +2 -37
  430. package/dist/react/server.js +8 -133
  431. package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
  432. package/dist/react/theme/ThemeLiveLoader.js +5 -0
  433. package/dist/react/theme/ThemeStyle.js +1 -1
  434. package/dist/theme/admin/Variables.d.ts +11 -0
  435. package/dist/theme/admin/Variables.js +115 -0
  436. package/dist/theme/admin/fields.scss +113 -0
  437. package/dist/theme/client.d.ts +1 -0
  438. package/dist/theme/client.js +2 -0
  439. package/dist/theme/css.d.ts +6 -1
  440. package/dist/theme/css.js +12 -4
  441. package/dist/theme/global.js +83 -0
  442. package/dist/theme/index.d.ts +1 -0
  443. package/dist/theme/index.js +1 -0
  444. package/dist/theme/server.d.ts +15 -0
  445. package/dist/theme/server.js +43 -0
  446. package/dist/theme/usage.d.ts +23 -0
  447. package/dist/theme/usage.js +68 -0
  448. package/dist/theme/variables.d.ts +72 -0
  449. package/dist/theme/variables.js +231 -0
  450. package/package.json +4 -2
  451. package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
  452. package/dist/admin/editor/styles/SiteClasses.js +0 -31
  453. package/dist/blocks/builtins/headingId.d.ts +0 -15
  454. package/dist/blocks/builtins/headingId.js +0 -36
  455. package/dist/blocks/builtins/lightbox.d.ts +0 -43
  456. package/dist/blocks/builtins/lightbox.js +0 -93
  457. package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
  458. package/dist/blocks/builtins/mediaBackdrop.js +0 -79
  459. package/dist/react/components/Quote.d.ts +0 -3
  460. package/dist/react/components/Quote.js +0 -12
  461. package/dist/react/components/Spacer.d.ts +0 -3
  462. package/dist/react/components/Spacer.js +0 -6
  463. package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
  464. package/dist/react/components/builtins/BackdropVideo.js +0 -16
  465. package/dist/react/components/builtins/Lightbox.d.ts +0 -45
  466. package/dist/react/components/builtins/Lightbox.js +0 -252
  467. package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
  468. package/dist/react/components/builtins/MediaBackdrop.js +0 -61
@@ -0,0 +1,214 @@
1
+ // Visibility conditions of a block (`Block.visibility`): rows of { field, operator, value } that
2
+ // show the block only when they match the current document (a template's document, a collection
3
+ // list item or a repeat row). Pure: no React, no Payload. `isVisible` in bindings.ts reads the
4
+ // values; this module holds the shape, the checks and the canonical form.
5
+ /**
6
+ * The operators of a condition. The names and meanings follow Payload's `where` operators
7
+ * (`equals`, `in`, `greater_than`, `like`, …), plus `is_set` and `is_empty`, which need no value.
8
+ */
9
+ export const VISIBILITY_OPERATORS = [
10
+ 'is_set',
11
+ 'is_empty',
12
+ 'equals',
13
+ 'not_equals',
14
+ 'in',
15
+ 'not_in',
16
+ 'greater_than',
17
+ 'greater_than_equal',
18
+ 'less_than',
19
+ 'less_than_equal',
20
+ 'like',
21
+ 'contains',
22
+ ];
23
+ /** Operators that take no value. */
24
+ export const VALUELESS_OPERATORS = new Set(['is_set', 'is_empty']);
25
+ /** Operators that take a list of values. */
26
+ export const LIST_OPERATORS = new Set(['in', 'not_in']);
27
+ // Local: tree.ts imports this module (normalizeLayout), so it cannot import tree.ts back.
28
+ const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
29
+ const isScalar = (value) => typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value)) || typeof value === 'boolean';
30
+ const isOperator = (value) => typeof value === 'string' && VISIBILITY_OPERATORS.includes(value);
31
+ /** True for a group entry (`{ all: [...] }`). */
32
+ export const isVisibilityGroup = (entry) => 'all' in entry;
33
+ /** One condition in canonical form, or the error message. */
34
+ function checkCondition(value, at) {
35
+ if (!isPlainObject(value))
36
+ return `${at} must be an object`;
37
+ for (const key of Object.keys(value)) {
38
+ if (!['field', 'operator', 'value', 'valueField', 'count'].includes(key)) {
39
+ return `${at}: unknown key "${key}". Use field, operator, value (or valueField) and count.`;
40
+ }
41
+ }
42
+ const field = typeof value.field === 'string' ? value.field.trim() : '';
43
+ if (!field)
44
+ return `${at}.field must be a field path`;
45
+ if (!isOperator(value.operator))
46
+ return `${at}.operator must be one of ${VISIBILITY_OPERATORS.join(', ')}`;
47
+ const operator = value.operator;
48
+ const condition = { field, operator };
49
+ if (value.count !== undefined && typeof value.count !== 'boolean')
50
+ return `${at}.count must be a boolean`;
51
+ if (value.count === true)
52
+ condition.count = true;
53
+ if (VALUELESS_OPERATORS.has(operator))
54
+ return condition;
55
+ if (value.valueField !== undefined) {
56
+ const valueField = typeof value.valueField === 'string' ? value.valueField.trim() : '';
57
+ if (!valueField)
58
+ return `${at}.valueField must be a field path`;
59
+ if (value.value !== undefined)
60
+ return `${at}: use value or valueField, not both`;
61
+ condition.valueField = valueField;
62
+ return condition;
63
+ }
64
+ if (LIST_OPERATORS.has(operator)) {
65
+ const list = Array.isArray(value.value) ? value.value : isScalar(value.value) ? [value.value] : null;
66
+ if (!list || !list.every((item) => typeof item === 'string' || (typeof item === 'number' && Number.isFinite(item)))) {
67
+ return `${at}.value must be a list of texts or numbers`;
68
+ }
69
+ condition.value = list;
70
+ return condition;
71
+ }
72
+ if (!isScalar(value.value))
73
+ return `${at}.value must be a text, a number or a boolean`;
74
+ condition.value = value.value;
75
+ return condition;
76
+ }
77
+ /**
78
+ * One entry of `conditions`: a condition, or a group `{ all: [...] }` (a group of one condition
79
+ * becomes that condition). `strict`: the first bad condition is the error; otherwise bad
80
+ * conditions are dropped. Null: an empty group, which is dropped.
81
+ */
82
+ function checkEntry(value, at, strict) {
83
+ if (!isPlainObject(value) || !('all' in value))
84
+ return checkCondition(value, at);
85
+ if (Object.keys(value).length !== 1)
86
+ return `${at}: a group has only the key "all"`;
87
+ if (!Array.isArray(value.all))
88
+ return `${at}.all must be a list of conditions`;
89
+ const all = [];
90
+ for (const [i, raw] of value.all.entries()) {
91
+ const checked = checkCondition(raw, `${at}.all[${i}]`);
92
+ if (typeof checked !== 'string')
93
+ all.push(checked);
94
+ else if (strict)
95
+ return checked;
96
+ }
97
+ if (all.length === 0)
98
+ return strict ? `${at}.all must hold a condition` : null;
99
+ return all.length === 1 ? all[0] : { all };
100
+ }
101
+ /**
102
+ * The canonical visibility of checked entries: `undefined` without conditions, `match` only when
103
+ * "any". Without "any", groups are flattened into the conditions.
104
+ */
105
+ function canonical(entries, match) {
106
+ if (entries.length === 0)
107
+ return undefined;
108
+ if (match === 'any')
109
+ return { match: 'any', conditions: entries };
110
+ return { conditions: entries.flatMap((entry) => (isVisibilityGroup(entry) ? entry.all : [entry])) };
111
+ }
112
+ /**
113
+ * Checks stored or inserted `visibility` and returns it in canonical form: trimmed field paths,
114
+ * no value for `is_set`/`is_empty`, `match` only when "any", groups only under "any", `undefined`
115
+ * without conditions. A string is the error message.
116
+ */
117
+ export function checkVisibility(value) {
118
+ if (value === undefined || value === null)
119
+ return undefined;
120
+ if (!isPlainObject(value))
121
+ return 'visibility must be an object: { match?, conditions }';
122
+ for (const key of Object.keys(value)) {
123
+ if (key !== 'match' && key !== 'conditions')
124
+ return `Unknown visibility key "${key}". Use match and conditions.`;
125
+ }
126
+ if (value.match !== undefined && value.match !== 'all' && value.match !== 'any')
127
+ return 'visibility.match must be "all" or "any"';
128
+ if (value.conditions === undefined)
129
+ return undefined;
130
+ if (!Array.isArray(value.conditions))
131
+ return 'visibility.conditions must be a list';
132
+ const entries = [];
133
+ for (const [i, raw] of value.conditions.entries()) {
134
+ const checked = checkEntry(raw, `visibility.conditions[${i}]`, true);
135
+ if (typeof checked === 'string')
136
+ return checked;
137
+ if (checked)
138
+ entries.push(checked);
139
+ }
140
+ return canonical(entries, value.match);
141
+ }
142
+ /** `visibility` as stored, with bad conditions dropped one by one: a stored layout never fails to load. */
143
+ export function normalizeVisibility(value) {
144
+ if (!isPlainObject(value) || !Array.isArray(value.conditions))
145
+ return undefined;
146
+ const entries = value.conditions.flatMap((raw, i) => {
147
+ const checked = checkEntry(raw, `conditions[${i}]`, false);
148
+ return checked && typeof checked !== 'string' ? [checked] : [];
149
+ });
150
+ return canonical(entries, value.match);
151
+ }
152
+ /**
153
+ * The conditions as "or" groups of "and" conditions: one group without "any", one group per
154
+ * entry with "any". The block shows when every condition of one group matches.
155
+ */
156
+ export function visibilityGroups(visibility) {
157
+ const entries = visibility?.conditions ?? [];
158
+ if (entries.length === 0)
159
+ return [];
160
+ if (visibility?.match !== 'any')
161
+ return [entries.flatMap((entry) => (isVisibilityGroup(entry) ? entry.all : [entry]))];
162
+ return entries.map((entry) => (isVisibilityGroup(entry) ? entry.all : [entry]));
163
+ }
164
+ /**
165
+ * The visibility of "or" groups of "and" conditions, in canonical form. One group: its
166
+ * conditions. Several: `match: "any"`, with a group entry for each group of two or more.
167
+ */
168
+ export function groupsVisibility(groups) {
169
+ const filled = groups.filter((group) => group.length > 0);
170
+ if (filled.length <= 1)
171
+ return canonical(filled[0] ?? [], undefined);
172
+ return canonical(filled.map((group) => (group.length === 1 ? group[0] : { all: [...group] })), 'any');
173
+ }
174
+ /** Every condition, groups flattened: for readers that need only the fields or the number. */
175
+ export const visibilityConditions = (visibility) => visibilityGroups(visibility).flat();
176
+ /** JSON Schema of `visibility`, for the block schemas AI tools read. */
177
+ export function visibilityJsonSchema() {
178
+ const scalar = [{ type: 'string' }, { type: 'number' }, { type: 'boolean' }];
179
+ const condition = {
180
+ type: 'object',
181
+ properties: {
182
+ field: { type: 'string' },
183
+ operator: { type: 'string', enum: [...VISIBILITY_OPERATORS] },
184
+ value: { anyOf: [...scalar, { type: 'array', items: { anyOf: [{ type: 'string' }, { type: 'number' }] } }] },
185
+ valueField: { type: 'string' },
186
+ count: { type: 'boolean' },
187
+ },
188
+ required: ['field', 'operator'],
189
+ additionalProperties: false,
190
+ };
191
+ return {
192
+ type: 'object',
193
+ description: 'Visibility conditions: the block shows only when they match the current document (a template\'s document, a collection list item or a repeat row). ' +
194
+ 'match "all" (default) or "any". Each condition: field (a field path, or $index, $item, $parent.<path>, $page.<path>), operator, and value or valueField ' +
195
+ '(another field path to compare with). is_set and is_empty take no value; in and not_in take a list; greater_than, greater_than_equal, less_than and less_than_equal compare numbers or dates; ' +
196
+ 'like (every word, any case) and contains (any case) read text. count: true tests the number of items of an array or hasMany field. ' +
197
+ 'With match "any", an entry may be a group { all: [conditions] } that matches when all of them match ("or" of "and" groups). ' +
198
+ 'Without a current document (a normal page) the conditions are not checked.',
199
+ properties: {
200
+ match: { type: 'string', enum: ['all', 'any'] },
201
+ conditions: {
202
+ type: 'array',
203
+ items: {
204
+ anyOf: [
205
+ condition,
206
+ { type: 'object', properties: { all: { type: 'array', items: condition, minItems: 1 } }, required: ['all'], additionalProperties: false },
207
+ ],
208
+ },
209
+ },
210
+ },
211
+ required: ['conditions'],
212
+ additionalProperties: false,
213
+ };
214
+ }
@@ -0,0 +1,22 @@
1
+ /** Value prefix of a URL query value: `$query.category` reads `?category=`. */
2
+ export declare const QUERY_PATH = "$query";
3
+ /** A date token: `$now`, optionally with a shift of days or hours. */
4
+ export declare const DATE_TOKEN: RegExp;
5
+ /** A date relative to now. `amount` 0 is now; `direction` -1 is in the past ("ago"). */
6
+ export type RelativeDate = {
7
+ amount: number;
8
+ unit: 'd' | 'h';
9
+ direction: -1 | 1;
10
+ };
11
+ /** The relative date of a date token, or null for any other value. */
12
+ export declare function parseDateToken(value: unknown): RelativeDate | null;
13
+ /** The date token of a relative date: `$now` for an amount of 0. */
14
+ export declare function dateToken(date: RelativeDate): string;
15
+ /** `$page.<path>`: the value of a field of the page's document. */
16
+ export declare const pageToken: (path: string) => string;
17
+ /** The field path of a `$page.<path>` value, or null. */
18
+ export declare function pageTokenPath(value: unknown): string | null;
19
+ /** `$query.<param>`: the value of a URL query parameter. */
20
+ export declare const queryToken: (param: string) => string;
21
+ /** The parameter of a `$query.<param>` value, or null. */
22
+ export declare function queryTokenParam(value: unknown): string | null;
@@ -0,0 +1,43 @@
1
+ // Values of a collection list's `where` that are read when the query runs, not stored as such:
2
+ // - a date relative to now: `$now`, `$now-30d`, `$now+12h` (units d and h);
3
+ // - a field of the page's document: `$page.<path>` (the same `$page` as in bindings);
4
+ // - a URL query value: `$query.<param>` (`?category=news`).
5
+ // Pure: the condition rows (admin) write them, `listQueries` (react/render/lists.ts) reads them.
6
+ import { PAGE_PATH } from './bindings.js';
7
+ /** Value prefix of a URL query value: `$query.category` reads `?category=`. */
8
+ export const QUERY_PATH = '$query';
9
+ /** A date token: `$now`, optionally with a shift of days or hours. */
10
+ export const DATE_TOKEN = /^\$now(?:([+-])(\d+)([dh]))?$/;
11
+ /** The relative date of a date token, or null for any other value. */
12
+ export function parseDateToken(value) {
13
+ if (typeof value !== 'string')
14
+ return null;
15
+ const match = DATE_TOKEN.exec(value);
16
+ if (!match)
17
+ return null;
18
+ const [, sign, amount, unit] = match;
19
+ if (!sign)
20
+ return { amount: 0, unit: 'd', direction: -1 };
21
+ return { amount: Number(amount), unit: unit === 'h' ? 'h' : 'd', direction: sign === '-' ? -1 : 1 };
22
+ }
23
+ /** The date token of a relative date: `$now` for an amount of 0. */
24
+ export function dateToken(date) {
25
+ const amount = Math.max(0, Math.floor(date.amount));
26
+ return amount === 0 ? '$now' : `$now${date.direction < 0 ? '-' : '+'}${amount}${date.unit}`;
27
+ }
28
+ /** `$page.<path>`: the value of a field of the page's document. */
29
+ export const pageToken = (path) => `${PAGE_PATH}.${path}`;
30
+ /** The field path of a `$page.<path>` value, or null. */
31
+ export function pageTokenPath(value) {
32
+ if (typeof value !== 'string' || !value.startsWith(`${PAGE_PATH}.`))
33
+ return null;
34
+ return value.slice(PAGE_PATH.length + 1);
35
+ }
36
+ /** `$query.<param>`: the value of a URL query parameter. */
37
+ export const queryToken = (param) => `${QUERY_PATH}.${param}`;
38
+ /** The parameter of a `$query.<param>` value, or null. */
39
+ export function queryTokenParam(value) {
40
+ if (typeof value !== 'string' || !value.startsWith(`${QUERY_PATH}.`))
41
+ return null;
42
+ return value.slice(QUERY_PATH.length + 1);
43
+ }
@@ -0,0 +1,16 @@
1
+ import { type ClassStyleSource } from '../classes/shared.js';
2
+ import type { CanvasCssInput, TailwindPlugins } from './index.js';
3
+ export type ClassSheet = {
4
+ /** The stylesheet: `@layer utilities { .card { … } }` plus the theme variables, `@property` and `@keyframes` rules it uses. */
5
+ css: string;
6
+ /** Problems by class name. A class with a problem compiles without the part that failed, or is left out. */
7
+ errors: Record<string, string>;
8
+ /** Every name the stylesheet styles: the class names and their former names. Page compiles leave these out. */
9
+ names: string[];
10
+ };
11
+ /**
12
+ * Compiles the editable classes against the site's design system (the recorded CSS input).
13
+ * Never throws: a class with a problem is compiled without its unknown Tailwind classes or its
14
+ * broken custom CSS, or left out, and the problem goes into `errors`.
15
+ */
16
+ export declare function compileClassSheet(input: CanvasCssInput, classes: readonly ClassStyleSource[], plugins?: TailwindPlugins): Promise<ClassSheet>;
@@ -0,0 +1,172 @@
1
+ // The stylesheet of the editable classes (`builder-classes`). Browser-safe: the server compiles the
2
+ // published classes for the site, and the canvas compiles the latest drafts with the same code.
3
+ //
4
+ // Each class becomes `@utility pc-db-class-<n> { @apply <styles>; <css> }`, appended to the site's
5
+ // CSS entry, so variants (`md:`, `hover:`), theme tokens and plugins work as in the site's own
6
+ // CSS. The internal name means a code `@utility` with the same name never adds its rules: the
7
+ // classes stylesheet holds the editable class alone. Its rules are renamed back to `.card` after
8
+ // the build. Classes that use other editable classes in their styles get those classes' rules.
9
+ //
10
+ // Cascade: the rules stay in `@layer utilities`, unscoped. Load the stylesheet after the site's CSS
11
+ // (it overrides a code `@utility` with the same name) and before the page's generated CSS (a
12
+ // block's own utilities beat its class). See the README section "Editable classes".
13
+ import { classNameProblem, classTokens, cssProblem, INTERNAL_CLASS_PREFIX, splitClassToken } from '../classes/shared.js';
14
+ import { compileFromInput, countUtilityLayers, extractUtilities, splitTopLevel } from './shared.js';
15
+ const INTERNAL = new RegExp(`\\.${INTERNAL_CLASS_PREFIX}(\\d+)(?![\\w-])`, 'g');
16
+ const UNKNOWN_UTILITY = /Cannot apply unknown utility class[:\s]*[`'"]?([^`'"\s]+?)[`'"]?(?:[\s.]|$)/;
17
+ const message = (error) => (error instanceof Error ? error.message : String(error)).split('\n')[0].trim();
18
+ /** The class's custom CSS: the rule body, and the `@keyframes` that go at the top level. */
19
+ function splitCss(css) {
20
+ const value = css.trim();
21
+ if (!value)
22
+ return { body: [], top: [] };
23
+ // A last declaration without ";" would be lost by the split.
24
+ const closed = /[;}]$/.test(value) ? value : `${value};`;
25
+ const body = [];
26
+ const top = [];
27
+ for (const statement of splitTopLevel(closed))
28
+ (/^@keyframes\s/.test(statement) ? top : body).push(statement);
29
+ return { body, top };
30
+ }
31
+ /**
32
+ * Compiles the editable classes against the site's design system (the recorded CSS input).
33
+ * Never throws: a class with a problem is compiled without its unknown Tailwind classes or its
34
+ * broken custom CSS, or left out, and the problem goes into `errors`.
35
+ */
36
+ export async function compileClassSheet(input, classes, plugins) {
37
+ const errors = {};
38
+ const valid = [...classes]
39
+ .filter((item) => {
40
+ const problem = classNameProblem(item.name);
41
+ if (problem)
42
+ errors[item.name] = problem;
43
+ return !problem;
44
+ })
45
+ .toSorted((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
46
+ if (valid.length === 0)
47
+ return { css: '', errors, names: [] };
48
+ // One entry per class, then one per former name that no class has as its own name.
49
+ const own = new Set(valid.map((item) => item.name));
50
+ const entries = [];
51
+ for (const source of valid)
52
+ entries.push({ internal: '', name: source.name, owner: source.name, source });
53
+ for (const source of valid) {
54
+ for (const alias of source.previousNames ?? []) {
55
+ if (own.has(alias) || entries.some((e) => e.name === alias) || classNameProblem(alias))
56
+ continue;
57
+ entries.push({ internal: '', name: alias, owner: source.name, source });
58
+ }
59
+ }
60
+ entries.forEach((entry, index) => {
61
+ entry.internal = `${INTERNAL_CLASS_PREFIX}${index}`;
62
+ });
63
+ // A class (or a former name) used in another class's styles applies that class's rules.
64
+ const internalOf = new Map(entries.map((e) => [e.name, entries.find((o) => o.name === e.owner).internal]));
65
+ /** Tokens left out per class (unknown to Tailwind), and classes left out entirely. */
66
+ const skipped = new Map();
67
+ const failed = new Set();
68
+ const cssFailed = new Set();
69
+ for (const source of valid) {
70
+ const problem = cssProblem(source.css);
71
+ if (problem) {
72
+ cssFailed.add(source.name);
73
+ errors[source.name] = problem;
74
+ }
75
+ }
76
+ const ruleOf = (entry) => {
77
+ const skip = skipped.get(entry.owner);
78
+ const applies = [];
79
+ for (const token of classTokens(entry.source.styles)) {
80
+ if (skip?.has(token))
81
+ continue;
82
+ const { prefix, bare, important } = splitClassToken(token);
83
+ const target = internalOf.get(bare);
84
+ // A class never applies itself.
85
+ if (bare === entry.owner)
86
+ continue;
87
+ applies.push(target ? `${prefix}${target}${important ? '!' : ''}` : token);
88
+ }
89
+ const { body, top } = cssFailed.has(entry.owner) ? { body: [], top: [] } : splitCss(entry.source.css ?? '');
90
+ const lines = [...(applies.length > 0 ? [`@apply ${applies.join(' ')};`] : []), ...body];
91
+ return { rule: `@utility ${entry.internal} {\n${lines.join('\n')}\n}`, top: entry.name === entry.owner ? top : [] };
92
+ };
93
+ const build = async (list, all) => {
94
+ const rules = all.map(ruleOf);
95
+ const extra = [...rules.flatMap((r) => r.top), ...rules.map((r) => r.rule)].join('\n');
96
+ const compiler = await compileFromInput({ ...input, entry: `${input.entry}\n${extra}\n` }, plugins);
97
+ const staticLayers = countUtilityLayers(compiler.build([]));
98
+ return extractUtilities(compiler.build(list.map((e) => e.internal)), staticLayers);
99
+ };
100
+ /** Which class a Tailwind error is about: the class whose styles hold the unknown token. */
101
+ const ownerOfToken = (token, among) => among.find((e) => e.name === e.owner && classTokens(e.source.styles).some((t) => t === token && !skipped.get(e.owner)?.has(t)));
102
+ const usable = () => entries.filter((e) => !failed.has(e.owner));
103
+ let css = '';
104
+ let done = false;
105
+ // An unknown Tailwind class stops the whole compile: leave it out of its class and try again.
106
+ for (let attempt = 0; attempt < 12 && !done; attempt++) {
107
+ const list = usable();
108
+ try {
109
+ css = list.length > 0 ? await build(list, list) : '';
110
+ done = true;
111
+ }
112
+ catch (error) {
113
+ const unknown = UNKNOWN_UTILITY.exec(message(error))?.[1];
114
+ const owner = unknown ? ownerOfToken(unknown, list) : undefined;
115
+ if (!unknown || !owner)
116
+ break;
117
+ const skip = skipped.get(owner.owner) ?? new Set();
118
+ skip.add(unknown);
119
+ skipped.set(owner.owner, skip);
120
+ errors[owner.owner] = [errors[owner.owner], `“${unknown}” is not a Tailwind class, so it was left out.`].filter(Boolean).join(' ');
121
+ }
122
+ }
123
+ if (!done) {
124
+ // Another problem (a broken custom CSS rule, a class that applies itself through another):
125
+ // compile each class alone, with the classes it uses, and leave out the ones that fail.
126
+ for (const entry of entries) {
127
+ if (entry.name !== entry.owner || failed.has(entry.owner))
128
+ continue;
129
+ const needed = closure(entry, entries, internalOf);
130
+ try {
131
+ await build([entry], needed);
132
+ }
133
+ catch (error) {
134
+ failed.add(entry.owner);
135
+ errors[entry.owner] = message(error);
136
+ }
137
+ }
138
+ try {
139
+ const list = usable();
140
+ css = list.length > 0 ? await build(list, list) : '';
141
+ }
142
+ catch (error) {
143
+ css = '';
144
+ for (const source of valid)
145
+ errors[source.name] ??= message(error);
146
+ }
147
+ }
148
+ const nameOf = new Map(entries.map((e) => [e.internal, e.name]));
149
+ const renamed = css.replace(INTERNAL, (whole, index) => {
150
+ const name = nameOf.get(`${INTERNAL_CLASS_PREFIX}${index}`);
151
+ return name ? `.${name}` : whole;
152
+ });
153
+ return { css: renamed, errors, names: entries.filter((e) => !failed.has(e.owner)).map((e) => e.name).toSorted() };
154
+ }
155
+ /** An entry and every entry its styles use, directly or through another class. */
156
+ function closure(entry, entries, internalOf) {
157
+ const byInternal = new Map(entries.filter((e) => e.name === e.owner).map((e) => [e.internal, e]));
158
+ const out = new Map([[entry.internal, entry]]);
159
+ const queue = [entry];
160
+ while (queue.length > 0) {
161
+ const current = queue.shift();
162
+ for (const token of classTokens(current.source.styles)) {
163
+ const target = internalOf.get(splitClassToken(token).bare);
164
+ const next = target ? byInternal.get(target) : undefined;
165
+ if (next && !out.has(next.internal)) {
166
+ out.set(next.internal, next);
167
+ queue.push(next);
168
+ }
169
+ }
170
+ }
171
+ return [...out.values()];
172
+ }
@@ -1,5 +1,8 @@
1
1
  import type { StyleTokens } from '../core/types.js';
2
+ import { type ClassSheet } from './classes.js';
3
+ import { type ClassStyleSource, type SiteClassRule } from '../classes/shared.js';
2
4
  export { applyFontFamilies, resolveFontValue, type FontFamilies } from './tokens.js';
5
+ export type { ClassSheet } from './classes.js';
3
6
  export { BUILDER_CSS_CLASS, withBuilderCssClass } from './marker.js';
4
7
  /** Tailwind plugins by the id used in `@plugin "<id>"`, e.g. { '@tailwindcss/typography': typography }. */
5
8
  export type TailwindPlugins = Record<string, unknown>;
@@ -7,6 +10,11 @@ export type CssOptions = {
7
10
  /** Absolute path to the app's Tailwind entry CSS (the file with @import "tailwindcss" and @theme). */
8
11
  entry: string;
9
12
  plugins?: TailwindPlugins;
13
+ /**
14
+ * CSS added after the entry: the theme's design variables (`@theme inline reference { … }`, see
15
+ * `theme/variables.ts`). Set by the plugin per compile (`withThemeVariables`), not in the config.
16
+ */
17
+ themeCss?: string;
10
18
  };
11
19
  /**
12
20
  * What the canvas iframe needs to run the same compile in the browser.
@@ -23,9 +31,13 @@ export type CanvasCssInput = {
23
31
  * Every rule matches only elements with the `builder-css` class (marker.ts), so the output can
24
32
  * load after the app's own CSS without changing the order of the app's classes.
25
33
  * Unknown classes are ignored. A `@plugin` id missing from `plugins` throws.
34
+ * `filter.exclude`: class names to leave out with any variant prefix (the editable classes, which
35
+ * come from their own stylesheet, `css/classes.ts`).
26
36
  * Results are cached (LRU) by entry content, plugin ids and the sorted class set.
27
37
  */
28
- export declare function compileClasses(classes: string[], options: CssOptions): Promise<string>;
38
+ export declare function compileClasses(classes: string[], options: CssOptions, filter?: {
39
+ exclude?: Iterable<string>;
40
+ }): Promise<string>;
29
41
  /** Input for createCanvasCompiler (browser). Cached per entry file content. */
30
42
  export declare function getCanvasCssInput(options: CssOptions): Promise<CanvasCssInput>;
31
43
  /** Clears every cache: file reads, canvas inputs and compiled CSS. For tests and dev tooling. */
@@ -43,3 +55,22 @@ export declare function tracingIncludes(entryRelativeToApp: string): string[];
43
55
  * (see tokens.ts). Cached per entry path, entry content and plugin ids.
44
56
  */
45
57
  export declare function getStyleTokens(options: CssOptions): Promise<StyleTokens>;
58
+ /**
59
+ * Compiles the editable classes into one stylesheet against the app's CSS entry (see
60
+ * `compileClassSheet` in ./classes.ts). Cached (LRU) by the CSS input and the classes' data.
61
+ */
62
+ export declare function compileClassesSheet(classes: readonly ClassStyleSource[], options: CssOptions): Promise<ClassSheet>;
63
+ /**
64
+ * A key that changes when the compile's input changes: the entry, the stylesheets it imports and
65
+ * the plugin ids. A stored classes stylesheet with another key is compiled again (a deploy with a
66
+ * new theme).
67
+ */
68
+ export declare function cssInputKey(options: CssOptions): Promise<string>;
69
+ /** The site's own static `@utility` rules with their full bodies, for "Import from site CSS". */
70
+ export declare function getSiteClassRules(options: CssOptions): Promise<SiteClassRule[]>;
71
+ /**
72
+ * True when Tailwind, a Tailwind plugin or a functional `@utility` of the site has a utility with
73
+ * this name, so a class with it would clash. The site's own static `@utility` classes do not
74
+ * count: an editable class with their name replaces them.
75
+ */
76
+ export declare function isTailwindUtility(name: string, options: CssOptions): Promise<boolean>;
package/dist/css/index.js CHANGED
@@ -4,7 +4,9 @@ import fs from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import { compile } from 'tailwindcss';
6
6
  import { compileFromInput, countUtilityLayers, ENTRY_BASE, extractUtilities, loadPlugin, normalizeClasses, stylesheetKey, } from './shared.js';
7
- import { buildStyleTokens } from './tokens.js';
7
+ import { buildStyleTokens, parseSiteClasses, siteClassRules } from './tokens.js';
8
+ import { compileClassSheet } from './classes.js';
9
+ import { withoutClassNames } from '../classes/shared.js';
8
10
  export { applyFontFamilies, resolveFontValue } from './tokens.js';
9
11
  export { BUILDER_CSS_CLASS, withBuilderCssClass } from './marker.js';
10
12
  // ---------------------------------------------------------------------------------------------
@@ -147,8 +149,10 @@ async function recordInput(entryFile, entryCss, plugins) {
147
149
  staticUtilityLayers.set(data, countUtilityLayers(compiler.build([])));
148
150
  return data;
149
151
  }
152
+ /** The entry's CSS with the theme's variables after it. */
153
+ const entryCssOf = async (options) => (await readCached(options.entry)) + (options.themeCss ?? '');
150
154
  async function getInput(options) {
151
- const entryCss = await readCached(options.entry);
155
+ const entryCss = await entryCssOf(options);
152
156
  const key = hash(options.entry, entryCss);
153
157
  const cached = inputCache.get(key);
154
158
  if (cached)
@@ -167,10 +171,12 @@ const cssCache = new Lru(100);
167
171
  * Every rule matches only elements with the `builder-css` class (marker.ts), so the output can
168
172
  * load after the app's own CSS without changing the order of the app's classes.
169
173
  * Unknown classes are ignored. A `@plugin` id missing from `plugins` throws.
174
+ * `filter.exclude`: class names to leave out with any variant prefix (the editable classes, which
175
+ * come from their own stylesheet, `css/classes.ts`).
170
176
  * Results are cached (LRU) by entry content, plugin ids and the sorted class set.
171
177
  */
172
- export async function compileClasses(classes, options) {
173
- const candidates = normalizeClasses(classes);
178
+ export async function compileClasses(classes, options, filter = {}) {
179
+ const candidates = withoutClassNames(normalizeClasses(classes), new Set(filter.exclude ?? []));
174
180
  if (candidates.length === 0)
175
181
  return '';
176
182
  const input = await getInput(options);
@@ -195,6 +201,7 @@ export function clearCssCache() {
195
201
  inputCache.clear();
196
202
  cssCache.clear();
197
203
  tokensCache.clear();
204
+ sheetCache.clear();
198
205
  }
199
206
  /** Escapes glob characters that are common in Next route folders: `(group)`, `[slug]`, `{a,b}`. */
200
207
  const escapeGlob = (value) => value.replace(/[()[\]{}]/g, '\\$&');
@@ -223,7 +230,7 @@ const tokensCache = new Lru(8);
223
230
  * (see tokens.ts). Cached per entry path, entry content and plugin ids.
224
231
  */
225
232
  export async function getStyleTokens(options) {
226
- const entryCss = await readCached(options.entry);
233
+ const entryCss = await entryCssOf(options);
227
234
  const pluginIds = Object.keys(options.plugins ?? {}).toSorted().join(',');
228
235
  const key = hash('tokens', options.entry, entryCss, pluginIds);
229
236
  const cached = tokensCache.get(key);
@@ -234,3 +241,55 @@ export async function getStyleTokens(options) {
234
241
  pending.catch(() => tokensCache.delete(key));
235
242
  return pending;
236
243
  }
244
+ // ---------------------------------------------------------------------------------------------
245
+ // Editable classes (the classes collection): server side of css/classes.ts
246
+ const sheetCache = new Lru(20);
247
+ const inputKeys = new WeakMap();
248
+ /**
249
+ * Compiles the editable classes into one stylesheet against the app's CSS entry (see
250
+ * `compileClassSheet` in ./classes.ts). Cached (LRU) by the CSS input and the classes' data.
251
+ */
252
+ export async function compileClassesSheet(classes, options) {
253
+ const input = await getInput(options);
254
+ const data = classes
255
+ .map((c) => JSON.stringify([c.name, c.styles ?? '', c.css ?? '', c.previousNames ?? []]))
256
+ .toSorted()
257
+ .join('\n');
258
+ const key = hash('classes', await cssInputKey(options), data);
259
+ const cached = sheetCache.get(key);
260
+ if (cached)
261
+ return cached;
262
+ const pending = compileClassSheet(input, classes, options.plugins);
263
+ sheetCache.set(key, pending);
264
+ pending.catch(() => sheetCache.delete(key));
265
+ return pending;
266
+ }
267
+ /**
268
+ * A key that changes when the compile's input changes: the entry, the stylesheets it imports and
269
+ * the plugin ids. A stored classes stylesheet with another key is compiled again (a deploy with a
270
+ * new theme).
271
+ */
272
+ export async function cssInputKey(options) {
273
+ const input = await getInput(options);
274
+ let key = inputKeys.get(input);
275
+ if (!key) {
276
+ key = hash(JSON.stringify(input), Object.keys(options.plugins ?? {}).toSorted().join(','));
277
+ inputKeys.set(input, key);
278
+ }
279
+ return key;
280
+ }
281
+ /** The site's own static `@utility` rules with their full bodies, for "Import from site CSS". */
282
+ export async function getSiteClassRules(options) {
283
+ return siteClassRules(await getInput(options));
284
+ }
285
+ /**
286
+ * True when Tailwind, a Tailwind plugin or a functional `@utility` of the site has a utility with
287
+ * this name, so a class with it would clash. The site's own static `@utility` classes do not
288
+ * count: an editable class with their name replaces them.
289
+ */
290
+ export async function isTailwindUtility(name, options) {
291
+ const input = await getInput(options);
292
+ if (parseSiteClasses(input).some((c) => c.name === name))
293
+ return false;
294
+ return (await compileClasses([name], options)) !== '';
295
+ }
@@ -1,3 +1,4 @@
1
+ import type { SiteClassRule } from '../classes/shared.js';
1
2
  import type { SiteClass, StyleTokens, ThemeToken } from '../core/types.js';
2
3
  import type { TailwindPlugins } from './index.js';
3
4
  import { type CanvasCssData } from './shared.js';
@@ -30,6 +31,15 @@ export declare function applyFontFamilies(fonts: ThemeToken[], families: FontFam
30
31
  * a label only. A name defined twice is listed once.
31
32
  */
32
33
  export declare function parseSiteClasses(data: CanvasCssData): SiteClass[];
34
+ /**
35
+ * The same rules as `parseSiteClasses`, with each rule's full body (for "Import from site CSS",
36
+ * which turns them into editable classes).
37
+ */
38
+ export declare function siteClassRules(data: CanvasCssData): SiteClassRule[];
39
+ /**
40
+ * Builds StyleTokens from a recorded CSS input. Uses the design system API; if it is missing or
41
+ * throws, logs a warning and parses the @theme blocks instead (no class list in that case).
42
+ */
33
43
  export declare function buildStyleTokens(data: CanvasCssData, plugins?: TailwindPlugins): Promise<{
34
44
  tokens: StyleTokens;
35
45
  source: TokensSource;