@conloca/astro-cms 0.1.16 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. package/README.md +250 -298
  2. package/dist/internal/acorn-default.mjs +11 -3
  3. package/dist/internal/page-handler.astro +137 -358
  4. package/dist/ts/node/content.d.ts +4 -0
  5. package/dist/ts/node/content.d.ts.map +1 -0
  6. package/dist/ts/node/content.js +3 -0
  7. package/dist/ts/node/content.js.map +1 -0
  8. package/dist/ts/node/index.d.ts +9 -0
  9. package/dist/ts/node/index.d.ts.map +1 -0
  10. package/dist/ts/node/index.js +14 -0
  11. package/dist/ts/node/index.js.map +1 -0
  12. package/dist/ts/src/asset-ref-base.d.ts +3 -0
  13. package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
  14. package/dist/ts/src/asset-ref-base.js +48 -0
  15. package/dist/ts/src/asset-ref-base.js.map +1 -0
  16. package/dist/ts/src/checks.d.ts +7 -0
  17. package/dist/ts/src/checks.d.ts.map +1 -0
  18. package/dist/ts/src/checks.js +7 -0
  19. package/dist/ts/src/checks.js.map +1 -0
  20. package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
  21. package/dist/ts/src/cms-handler.d.ts.map +1 -0
  22. package/dist/{src → ts/src}/cms-handler.js +9 -130
  23. package/dist/ts/src/cms-handler.js.map +1 -0
  24. package/dist/ts/src/collections.d.ts +160 -0
  25. package/dist/ts/src/collections.d.ts.map +1 -0
  26. package/dist/ts/src/collections.js +170 -0
  27. package/dist/ts/src/collections.js.map +1 -0
  28. package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
  29. package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
  30. package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
  31. package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
  32. package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
  33. package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
  34. package/dist/ts/src/components/RenderWithFragments.js +133 -0
  35. package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
  36. package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
  37. package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
  38. package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
  39. package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
  40. package/dist/ts/src/components.d.ts +4 -0
  41. package/dist/ts/src/components.d.ts.map +1 -0
  42. package/dist/ts/src/components.js +4 -0
  43. package/dist/ts/src/components.js.map +1 -0
  44. package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
  45. package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
  46. package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
  47. package/dist/ts/src/discovery/discover.d.ts +43 -0
  48. package/dist/ts/src/discovery/discover.d.ts.map +1 -0
  49. package/dist/ts/src/discovery/discover.js +87 -0
  50. package/dist/ts/src/discovery/discover.js.map +1 -0
  51. package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
  52. package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
  53. package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
  54. package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
  55. package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
  56. package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
  57. package/dist/ts/src/discovery/merge-registry.js.map +1 -0
  58. package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
  59. package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
  60. package/dist/ts/src/discovery/registry-endpoint.js +76 -0
  61. package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
  62. package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
  63. package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
  64. package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
  65. package/dist/ts/src/discovery/scan-components.js.map +1 -0
  66. package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
  67. package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
  68. package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
  69. package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
  70. package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
  71. package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
  72. package/dist/ts/src/editor-descriptors.d.ts +31 -0
  73. package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
  74. package/dist/ts/src/editor-descriptors.js +84 -0
  75. package/dist/ts/src/editor-descriptors.js.map +1 -0
  76. package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
  77. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
  78. package/dist/ts/src/handlers/collection-content-api.js +166 -0
  79. package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
  80. package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
  81. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
  82. package/dist/ts/src/handlers/page-render-core.js +315 -0
  83. package/dist/ts/src/handlers/page-render-core.js.map +1 -0
  84. package/dist/ts/src/hydration.d.ts.map +1 -0
  85. package/dist/{src → ts/src}/hydration.js +1 -0
  86. package/dist/ts/src/hydration.js.map +1 -0
  87. package/dist/ts/src/index.d.ts +21 -0
  88. package/dist/ts/src/index.d.ts.map +1 -0
  89. package/dist/ts/src/index.js +45 -0
  90. package/dist/ts/src/index.js.map +1 -0
  91. package/dist/ts/src/internal/declared-collections.d.ts +30 -0
  92. package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
  93. package/dist/ts/src/internal/declared-collections.js +84 -0
  94. package/dist/ts/src/internal/declared-collections.js.map +1 -0
  95. package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
  96. package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
  97. package/dist/ts/src/internal/page-collection-schema.js +152 -0
  98. package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
  99. package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
  100. package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
  101. package/dist/ts/src/lib/content-config-guard.js +41 -0
  102. package/dist/ts/src/lib/content-config-guard.js.map +1 -0
  103. package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
  104. package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
  105. package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
  106. package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
  107. package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
  108. package/dist/ts/src/lib/hydration-script.js.map +1 -0
  109. package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
  110. package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
  111. package/dist/ts/src/lib/hydration-utils.js.map +1 -0
  112. package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
  113. package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
  114. package/dist/ts/src/lib/resolve-locale.js +16 -0
  115. package/dist/ts/src/lib/resolve-locale.js.map +1 -0
  116. package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
  117. package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
  118. package/dist/ts/src/lib/resolve-site-name.js +12 -0
  119. package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
  120. package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
  121. package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
  122. package/dist/{src → ts/src}/lib/route-utils.js +33 -15
  123. package/dist/ts/src/lib/route-utils.js.map +1 -0
  124. package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
  125. package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
  126. package/dist/{src → ts/src}/lib/routing-config.js +13 -0
  127. package/dist/ts/src/lib/routing-config.js.map +1 -0
  128. package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
  129. package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
  130. package/dist/ts/src/lib/serialize-props.js.map +1 -0
  131. package/dist/ts/src/lib/unknown-components.d.ts +21 -0
  132. package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
  133. package/dist/ts/src/lib/unknown-components.js +49 -0
  134. package/dist/ts/src/lib/unknown-components.js.map +1 -0
  135. package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
  136. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
  137. package/dist/ts/src/lib/virtual-module-generators.js +51 -0
  138. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
  139. package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
  140. package/dist/{src → ts/src}/lib/withHydration.js +1 -0
  141. package/dist/ts/src/lib/withHydration.js.map +1 -0
  142. package/dist/ts/src/loader.d.ts +27 -0
  143. package/dist/ts/src/loader.d.ts.map +1 -0
  144. package/dist/{src → ts/src}/loader.js +33 -4
  145. package/dist/ts/src/loader.js.map +1 -0
  146. package/dist/ts/src/locales-helpers.d.ts.map +1 -0
  147. package/dist/{src → ts/src}/locales-helpers.js +1 -0
  148. package/dist/ts/src/locales-helpers.js.map +1 -0
  149. package/dist/ts/src/mime-types.d.ts.map +1 -0
  150. package/dist/{src → ts/src}/mime-types.js +1 -0
  151. package/dist/ts/src/mime-types.js.map +1 -0
  152. package/dist/ts/src/page-feed.d.ts +13 -0
  153. package/dist/ts/src/page-feed.d.ts.map +1 -0
  154. package/dist/ts/src/page-feed.js +20 -0
  155. package/dist/ts/src/page-feed.js.map +1 -0
  156. package/dist/ts/src/page-schemas.d.ts +6 -0
  157. package/dist/ts/src/page-schemas.d.ts.map +1 -0
  158. package/dist/ts/src/page-schemas.js +6 -0
  159. package/dist/ts/src/page-schemas.js.map +1 -0
  160. package/dist/ts/src/path-validation.d.ts.map +1 -0
  161. package/dist/{src → ts/src}/path-validation.js +1 -0
  162. package/dist/ts/src/path-validation.js.map +1 -0
  163. package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
  164. package/dist/ts/src/plugin-spa.d.ts.map +1 -0
  165. package/dist/{src → ts/src}/plugin-spa.js +280 -87
  166. package/dist/ts/src/plugin-spa.js.map +1 -0
  167. package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
  168. package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
  169. package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
  170. package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
  171. package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
  172. package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
  173. package/dist/ts/src/puck-manifest/field-projection.js +422 -0
  174. package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
  175. package/dist/ts/src/puck-manifest/index.d.ts +4 -0
  176. package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
  177. package/dist/ts/src/puck-manifest/index.js +3 -0
  178. package/dist/ts/src/puck-manifest/index.js.map +1 -0
  179. package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
  180. package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
  181. package/dist/ts/src/puck-manifest/literal.js +354 -0
  182. package/dist/ts/src/puck-manifest/literal.js.map +1 -0
  183. package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
  184. package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
  185. package/dist/ts/src/puck-manifest/read-config.js +517 -0
  186. package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
  187. package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
  188. package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
  189. package/dist/ts/src/puck-manifest/read-field.js +11 -0
  190. package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
  191. package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
  192. package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
  193. package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
  194. package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
  195. package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
  196. package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
  197. package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
  198. package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
  199. package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
  200. package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
  201. package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
  202. package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
  203. package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
  204. package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
  205. package/dist/ts/src/puck-manifest/source-reference.js +424 -0
  206. package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
  207. package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
  208. package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
  209. package/dist/ts/src/puck-manifest/syntax.js +79 -0
  210. package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
  211. package/dist/ts/src/puck-manifest/types.d.ts +145 -0
  212. package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
  213. package/dist/ts/src/puck-manifest/types.js +2 -0
  214. package/dist/ts/src/puck-manifest/types.js.map +1 -0
  215. package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
  216. package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
  217. package/dist/ts/src/safe-json-stringify.js.map +1 -0
  218. package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
  219. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
  220. package/dist/ts/src/sandbox-frame-handler.js +27 -0
  221. package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
  222. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
  223. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  224. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
  225. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
  226. package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
  227. package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
  228. package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
  229. package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
  230. package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
  231. package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
  232. package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
  233. package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
  234. package/dist/ts/src/sitemap-options.d.ts +21 -0
  235. package/dist/ts/src/sitemap-options.d.ts.map +1 -0
  236. package/dist/ts/src/sitemap-options.js +92 -0
  237. package/dist/ts/src/sitemap-options.js.map +1 -0
  238. package/dist/ts/src/tiptap-html-static.d.ts +15 -0
  239. package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
  240. package/dist/ts/src/tiptap-html-static.js +67 -0
  241. package/dist/ts/src/tiptap-html-static.js.map +1 -0
  242. package/dist/{src → ts/src}/types.d.ts +26 -110
  243. package/dist/ts/src/types.d.ts.map +1 -0
  244. package/dist/ts/src/types.js +2 -0
  245. package/dist/ts/src/types.js.map +1 -0
  246. package/dist/virtual-modules.d.ts +12 -93
  247. package/node/content.ts +14 -0
  248. package/node/index.ts +22 -0
  249. package/package.json +159 -73
  250. package/src/asset-ref-base.ts +48 -0
  251. package/src/checks.ts +10 -0
  252. package/src/cms-handler.ts +280 -0
  253. package/src/collections.ts +262 -0
  254. package/src/components/HydrationWrapper.tsx +41 -0
  255. package/src/components/RenderWithFragments.tsx +204 -0
  256. package/src/components/RenderWithHydration.tsx +55 -0
  257. package/src/components.ts +3 -0
  258. package/src/discovery/astro-frontmatter.ts +24 -0
  259. package/src/discovery/discover.ts +108 -0
  260. package/src/discovery/extract-props-ts.ts +255 -0
  261. package/src/discovery/merge-registry.ts +411 -0
  262. package/src/discovery/registry-endpoint.ts +80 -0
  263. package/src/discovery/scan-components.ts +458 -0
  264. package/src/discovery/scan-mdx.ts +190 -0
  265. package/src/discovery/scan-overrides.ts +92 -0
  266. package/src/editor-descriptors.ts +96 -0
  267. package/src/env.d.ts +31 -0
  268. package/src/handlers/collection-content-api.ts +196 -0
  269. package/src/handlers/page-handler.astro +320 -0
  270. package/src/handlers/page-render-core.ts +456 -0
  271. package/src/hydration.ts +7 -0
  272. package/src/index.ts +111 -0
  273. package/src/internal/acorn-default.mjs +37 -0
  274. package/src/internal/declared-collections.ts +98 -0
  275. package/src/internal/page-collection-schema.ts +210 -0
  276. package/src/lib/content-config-guard.ts +48 -0
  277. package/src/lib/hydration-scanner.ts +176 -0
  278. package/src/lib/hydration-script.ts +126 -0
  279. package/src/lib/hydration-utils.ts +120 -0
  280. package/src/lib/resolve-locale.ts +22 -0
  281. package/src/lib/resolve-site-name.ts +10 -0
  282. package/src/lib/route-utils.ts +106 -0
  283. package/src/lib/routing-config.ts +126 -0
  284. package/src/lib/serialize-props.ts +7 -0
  285. package/src/lib/unknown-components.ts +64 -0
  286. package/src/lib/virtual-module-generators.ts +58 -0
  287. package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
  288. package/src/loader.ts +145 -0
  289. package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
  290. package/src/mime-types.ts +19 -0
  291. package/src/page-feed.ts +26 -0
  292. package/src/page-schemas.ts +19 -0
  293. package/src/path-validation.ts +13 -0
  294. package/src/plugin-spa.ts +1480 -0
  295. package/src/puck-manifest/components-endpoint.ts +55 -0
  296. package/src/puck-manifest/field-projection.ts +510 -0
  297. package/src/puck-manifest/index.ts +3 -0
  298. package/src/puck-manifest/literal.ts +459 -0
  299. package/src/puck-manifest/read-config.ts +577 -0
  300. package/src/puck-manifest/read-field.ts +19 -0
  301. package/src/puck-manifest/read-wrapper.ts +1056 -0
  302. package/src/puck-manifest/reading-budget.ts +127 -0
  303. package/src/puck-manifest/resolve-reference.ts +9 -0
  304. package/src/puck-manifest/source-reference.ts +484 -0
  305. package/src/puck-manifest/syntax.ts +104 -0
  306. package/src/puck-manifest/types.ts +139 -0
  307. package/src/safe-json-stringify.ts +17 -0
  308. package/src/sandbox-frame-handler.ts +31 -0
  309. package/src/site-styles/content-wrapper-endpoint.ts +327 -0
  310. package/src/site-styles/render-endpoint.ts +331 -0
  311. package/src/site-styles/styles-endpoint.ts +184 -0
  312. package/src/sitemap-options.ts +115 -0
  313. package/src/tiptap-html-static.ts +84 -0
  314. package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
  315. package/src/virtual-modules.d.ts +74 -0
  316. package/dist/collections-Bd7EME4b.mjs +0 -129
  317. package/dist/collections-Bd7EME4b.mjs.map +0 -1
  318. package/dist/collections.d.mts +0 -35
  319. package/dist/collections.d.mts.map +0 -1
  320. package/dist/collections.mjs +0 -2
  321. package/dist/components.d.mts +0 -41
  322. package/dist/components.d.mts.map +0 -1
  323. package/dist/components.mjs +0 -223
  324. package/dist/components.mjs.map +0 -1
  325. package/dist/hydration.d.mts +0 -4
  326. package/dist/hydration.mjs +0 -2
  327. package/dist/index.d.mts +0 -108
  328. package/dist/index.d.mts.map +0 -1
  329. package/dist/index.mjs +0 -67
  330. package/dist/index.mjs.map +0 -1
  331. package/dist/internal/cms-handler.d.mts +0 -25
  332. package/dist/internal/cms-handler.d.mts.map +0 -1
  333. package/dist/internal/cms-handler.mjs +0 -314
  334. package/dist/internal/cms-handler.mjs.map +0 -1
  335. package/dist/lib/hydration-script.d.mts +0 -30
  336. package/dist/lib/hydration-script.d.mts.map +0 -1
  337. package/dist/lib/hydration-script.mjs +0 -84
  338. package/dist/lib/hydration-script.mjs.map +0 -1
  339. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
  340. package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
  341. package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
  342. package/dist/node/content.d.mts +0 -18
  343. package/dist/node/content.d.mts.map +0 -1
  344. package/dist/node/content.d.ts +0 -3
  345. package/dist/node/content.d.ts.map +0 -1
  346. package/dist/node/content.js +0 -2
  347. package/dist/node/content.mjs +0 -2
  348. package/dist/node/index.d.mts +0 -200
  349. package/dist/node/index.d.mts.map +0 -1
  350. package/dist/node/index.d.ts +0 -4
  351. package/dist/node/index.d.ts.map +0 -1
  352. package/dist/node/index.js +0 -3
  353. package/dist/node/index.mjs +0 -2513
  354. package/dist/node/index.mjs.map +0 -1
  355. package/dist/serialize-props-BHoNpzH6.mjs +0 -72
  356. package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
  357. package/dist/src/cms-handler.d.ts.map +0 -1
  358. package/dist/src/collections.d.ts +0 -32
  359. package/dist/src/collections.d.ts.map +0 -1
  360. package/dist/src/collections.js +0 -50
  361. package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
  362. package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
  363. package/dist/src/components/RenderWithBlocks.js +0 -129
  364. package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
  365. package/dist/src/components.d.ts +0 -4
  366. package/dist/src/components.d.ts.map +0 -1
  367. package/dist/src/components.js +0 -3
  368. package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
  369. package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
  370. package/dist/src/discovery/merge-registry.d.ts.map +0 -1
  371. package/dist/src/discovery/registry-endpoint.d.ts +0 -42
  372. package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
  373. package/dist/src/discovery/registry-endpoint.js +0 -81
  374. package/dist/src/discovery/scan-components.d.ts.map +0 -1
  375. package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
  376. package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
  377. package/dist/src/hydration.d.ts.map +0 -1
  378. package/dist/src/index.d.ts +0 -11
  379. package/dist/src/index.d.ts.map +0 -1
  380. package/dist/src/index.js +0 -25
  381. package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
  382. package/dist/src/lib/hydration-script.d.ts.map +0 -1
  383. package/dist/src/lib/hydration-utils.d.ts.map +0 -1
  384. package/dist/src/lib/page-api.d.ts +0 -77
  385. package/dist/src/lib/page-api.d.ts.map +0 -1
  386. package/dist/src/lib/page-api.js +0 -121
  387. package/dist/src/lib/route-utils.d.ts.map +0 -1
  388. package/dist/src/lib/routing-config.d.ts.map +0 -1
  389. package/dist/src/lib/serialize-props.d.ts.map +0 -1
  390. package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
  391. package/dist/src/lib/virtual-module-generators.js +0 -263
  392. package/dist/src/lib/withHydration.d.ts.map +0 -1
  393. package/dist/src/loader.d.ts +0 -14
  394. package/dist/src/loader.d.ts.map +0 -1
  395. package/dist/src/locales-helpers.d.ts.map +0 -1
  396. package/dist/src/mime-types.d.ts.map +0 -1
  397. package/dist/src/path-validation.d.ts.map +0 -1
  398. package/dist/src/plugin-spa.d.ts.map +0 -1
  399. package/dist/src/safe-json-stringify.d.ts.map +0 -1
  400. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
  401. package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
  402. package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
  403. package/dist/src/types.d.ts.map +0 -1
  404. package/dist/src/types.js +0 -1
  405. package/dist/types-CS9neadI.d.mts.map +0 -1
  406. package/dist/withHydration-C256ox_6.mjs +0 -49
  407. package/dist/withHydration-C256ox_6.mjs.map +0 -1
  408. package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
  409. /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
  410. /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
  411. /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
  412. /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
  413. /package/dist/{src → ts/src}/hydration.d.ts +0 -0
  414. /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
  415. /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
  416. /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
  417. /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
  418. /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
  419. /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
  420. /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
  421. /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
  422. /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
@@ -0,0 +1,262 @@
1
+ import { defineCollection } from 'astro:content';
2
+ import type { DataSchemas, PageSchemas } from '@conloca/cms-spa/page-schema-define';
3
+ import { createContentAPI } from '@conloca/content-api/reader';
4
+ import { dataMetaSchema, fragmentMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';
5
+ import { z } from 'zod';
6
+ import { ALL_FRAGMENTS_COLLECTION } from './handlers/page-render-core.js';
7
+ import { declareConlocaCollection, withDeclarationCheck } from './internal/declared-collections.js';
8
+ import { buildPageCollectionSchema, hostFieldsFromPageSchemas } from './internal/page-collection-schema.js';
9
+ import { conlocaLoader } from './loader.js';
10
+
11
+ export { ALL_FRAGMENTS_COLLECTION };
12
+
13
+ /**
14
+ * Options for createConlocaCollections().
15
+ */
16
+ export interface CreateConlocaCollectionsOptions {
17
+ /**
18
+ * Path to content root directory. Defaults to the contentRoot configured on
19
+ * conlocaCMS() in astro.config, falling back to './content'.
20
+ */
21
+ contentRoot?: string;
22
+ /** Site name for multi-site setups. @default 'default' */
23
+ site?: string;
24
+ /**
25
+ * The same `pageSchemas` object the editor loads. Host meta fields are
26
+ * validated on every page collection at build time (made optional, because
27
+ * the editor scopes a descriptor to a prefix while Astro validates the
28
+ * whole pile). Pass the object itself — not a hand-copied field list — so
29
+ * the form and the build cannot drift. Listing types come from augmenting
30
+ * `HostPageMeta`, not from Astro `entry.data`.
31
+ * The {@link pageSchemasOf} read-back is a {@link conlocaPages} contract
32
+ * and does not cover this deprecated wrapper.
33
+ */
34
+ pageSchemas?: PageSchemas;
35
+ }
36
+
37
+ /**
38
+ * Return type of createConlocaCollections().
39
+ */
40
+ export interface ConlocaCollectionsResult {
41
+ /** Astro Content Collections definitions - export this as `collections` */
42
+ collections: Record<string, ReturnType<typeof defineCollection>>;
43
+ }
44
+
45
+ /**
46
+ * @deprecated Declare collections explicitly with {@link conlocaPages},
47
+ * {@link conlocaData} and {@link conlocaFragments} — they keep the entry
48
+ * types Astro's generated `getCollection` needs, and undeclared content
49
+ * fails the build instead of silently not building. This wrapper still
50
+ * works but returns untyped entries.
51
+ *
52
+ * Creates Astro Content Collections by discovering from indexed content.
53
+ * Uses content-api to find collections that have content.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // src/content.config.ts
58
+ * import { createConlocaCollections } from '@conloca/astro-cms/node/content';
59
+ * import { pageSchemas } from './page-schemas';
60
+ *
61
+ * export const { collections } = await createConlocaCollections({ pageSchemas });
62
+ * ```
63
+ */
64
+ export async function createConlocaCollections(
65
+ options: CreateConlocaCollectionsOptions = {},
66
+ ): Promise<ConlocaCollectionsResult> {
67
+ // Default comes from the conlocaCMS integration, which publishes its raw
68
+ // contentRoot option to process.env before the content config loads — one
69
+ // contentRoot in astro.config covers both. (A missing directory is the
70
+ // integration's job to report; it warns in dev and fails the build.)
71
+ const { contentRoot = process.env.CONLOCA_CONTENT_ROOT ?? './content', site = 'default', pageSchemas } = options;
72
+
73
+ const api = await createContentAPI({ contentRoot });
74
+ const collections: Record<string, ReturnType<typeof defineCollection>> = {};
75
+
76
+ collections[ALL_FRAGMENTS_COLLECTION] = defineCollection({
77
+ loader: conlocaLoader({ contentRoot, site, kind: 'fragment' }),
78
+ schema: fragmentMetaSchema.loose(),
79
+ });
80
+
81
+ for (const name of api.fragments.collections) {
82
+ collections[name] = defineCollection({
83
+ loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment' }),
84
+ schema: fragmentMetaSchema.loose(),
85
+ });
86
+ }
87
+
88
+ for (const name of api.data.collections) {
89
+ collections[name] = defineCollection({
90
+ loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
91
+ schema: dataMetaSchema.loose(),
92
+ });
93
+ }
94
+
95
+ const hostFields = pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : undefined;
96
+ const pageSchema =
97
+ hostFields && Object.keys(hostFields.shape).length > 0
98
+ ? buildPageCollectionSchema(hostFields)
99
+ : pageMetaSchema.loose();
100
+
101
+ const siteCollections = api.getSite(site)?.collections ?? new Set<string>();
102
+ for (const name of siteCollections) {
103
+ collections[name] = defineCollection({
104
+ loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
105
+ schema: pageSchema,
106
+ });
107
+ }
108
+
109
+ return { collections };
110
+ }
111
+
112
+ const defaultContentRoot = () => process.env.CONLOCA_CONTENT_ROOT ?? './content';
113
+
114
+ /** Options for conlocaPages(). */
115
+ export interface ConlocaPagesOptions {
116
+ /**
117
+ * The same `pageSchemas` object the editor loads. Host meta fields are
118
+ * validated on every page at build time and typed via the HostPageMeta
119
+ * augmentation. Pass the object itself — not a hand-copied field list;
120
+ * {@link pageSchemasOf} reads it back off the returned collection so a
121
+ * site test can assert exactly that.
122
+ */
123
+ pageSchemas?: PageSchemas;
124
+ /** @default 'pages' — must equal the content.config key this is assigned to. */
125
+ collection?: string;
126
+ /** @default 'default' */
127
+ site?: string;
128
+ /** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
129
+ contentRoot?: string;
130
+ }
131
+
132
+ // What each conlocaPages call was handed, keyed weakly by the collection it
133
+ // returned: fresh objects per config evaluation, so a stale evaluation can
134
+ // never answer for a new one, and nothing is kept alive for it.
135
+ const pageSchemasByCollection = new WeakMap<object, PageSchemas>();
136
+
137
+ /**
138
+ * The exact pageSchemas object a conlocaPages collection was declared with,
139
+ * or undefined for anything else. Lets a site test assert the identity the
140
+ * pageSchemas option demands — against the real factory, with no module mock.
141
+ */
142
+ export function pageSchemasOf(collection: object): PageSchemas | undefined {
143
+ return pageSchemasByCollection.get(collection);
144
+ }
145
+
146
+ /**
147
+ * One typed Astro collection for Conloca pages — the explicit,
148
+ * Starlight-shaped declaration:
149
+ *
150
+ * ```ts
151
+ * export const collections = { pages: conlocaPages({ pageSchemas }) };
152
+ * ```
153
+ *
154
+ * Entry data is typed as {@link ConlocaPageEntry}; `getCollection('pages')`
155
+ * carries pathname/title/dates and the host's declared meta fields.
156
+ */
157
+ export function conlocaPages(options: ConlocaPagesOptions = {}) {
158
+ const { contentRoot = defaultContentRoot(), site = 'default', collection = 'pages', pageSchemas } = options;
159
+ declareConlocaCollection('page', collection);
160
+ const defined = defineCollection({
161
+ loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'page' }), {
162
+ contentRoot,
163
+ site,
164
+ }),
165
+ schema: buildPageCollectionSchema(pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : z.object({})),
166
+ });
167
+ if (pageSchemas) pageSchemasByCollection.set(defined, pageSchemas);
168
+ return defined;
169
+ }
170
+
171
+ /** Options for conlocaData(). */
172
+ export interface ConlocaDataOptions<DS extends DataSchemas> {
173
+ /**
174
+ * The same `dataSchemas` object the editor renders entry forms from. Its
175
+ * keys ARE the data collections — nothing is named twice. Each entry's
176
+ * payload is validated against its schema at build time.
177
+ */
178
+ dataSchemas: DS;
179
+ /** @default 'default' */
180
+ site?: string;
181
+ /** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
182
+ contentRoot?: string;
183
+ }
184
+
185
+ /**
186
+ * Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
187
+ * requiredness preserved, no rewrite guard — because the site owns it whole
188
+ * for exactly one collection, unlike host page fields folded into the shared
189
+ * pages schema. The flip side, accepted for now: a .transform or .default in
190
+ * a dataSchema runs at build time but not in the editor form, so the two can
191
+ * diverge.
192
+ */
193
+ function conlocaDataCollection<T extends z.ZodObject<z.ZodRawShape>>(
194
+ name: string,
195
+ payload: T,
196
+ contentRoot: string,
197
+ site: string,
198
+ ) {
199
+ return defineCollection({
200
+ loader: withDeclarationCheck(conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }), {
201
+ contentRoot,
202
+ site,
203
+ }),
204
+ // Base meta plus this collection's payload under `data`. `data` stays
205
+ // optional: an entry saved before any payload exists is not an error.
206
+ schema: z.looseObject({ ...dataMetaSchema.shape, data: payload.optional() }),
207
+ });
208
+ }
209
+
210
+ /**
211
+ * Typed Astro collections for Conloca data, one per `dataSchemas` key:
212
+ *
213
+ * ```ts
214
+ * export const collections = { ...conlocaData({ dataSchemas }) };
215
+ * ```
216
+ *
217
+ * `getCollection('testimonials')` entries carry `data` typed by that key's
218
+ * schema, and a stored entry that fails its schema fails the build instead
219
+ * of rendering blank.
220
+ */
221
+ export function conlocaData<DS extends DataSchemas>(options: ConlocaDataOptions<DS>) {
222
+ const { dataSchemas, contentRoot = defaultContentRoot(), site = 'default' } = options;
223
+ const entries = Object.entries(dataSchemas).map(([name, payload]) => {
224
+ declareConlocaCollection('data', name);
225
+ return [name, conlocaDataCollection(name, payload, contentRoot, site)] as const;
226
+ });
227
+ // Object.fromEntries erases per-key types; the assertion restores exactly
228
+ // what the loop built — one collection per dataSchemas key.
229
+ return Object.fromEntries(entries) as { [K in keyof DS]: ReturnType<typeof conlocaDataCollection<DS[K]>> };
230
+ }
231
+
232
+ /**
233
+ * The fragments aggregate (always) plus one collection per named fragment
234
+ * folder: `...conlocaFragments('general')`. No arguments declares only the
235
+ * aggregate the render pipeline reads. There are no per-call options:
236
+ * contentRoot comes from conlocaCMS()'s contentRoot (via
237
+ * CONLOCA_CONTENT_ROOT) and the site is always 'default'.
238
+ */
239
+ export function conlocaFragments<const N extends readonly string[]>(...names: N) {
240
+ const contentRoot = defaultContentRoot();
241
+ const site = 'default';
242
+ const fragmentCollection = (collection?: string) =>
243
+ defineCollection({
244
+ loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment' }), {
245
+ contentRoot,
246
+ site,
247
+ }),
248
+ schema: fragmentMetaSchema.loose(),
249
+ });
250
+ const named = Object.fromEntries(
251
+ names.map((name) => {
252
+ declareConlocaCollection('fragment', name);
253
+ return [name, fragmentCollection(name)] as const;
254
+ }),
255
+ );
256
+ // The computed key and Object.fromEntries both erase literal keys; the
257
+ // assertion restores exactly what was built — the aggregate plus one
258
+ // collection per name.
259
+ return { [ALL_FRAGMENTS_COLLECTION]: fragmentCollection(), ...named } as {
260
+ [ALL_FRAGMENTS_COLLECTION]: ReturnType<typeof fragmentCollection>;
261
+ } & { [K in N[number]]: ReturnType<typeof fragmentCollection> };
262
+ }
@@ -0,0 +1,41 @@
1
+ import type { ReactNode } from 'react';
2
+ import { serializeProps } from '../lib/serialize-props.js';
3
+ import type { HydrationStrategy } from '../types.js';
4
+
5
+ interface HydrationWrapperProps {
6
+ componentName: string;
7
+ strategy: HydrationStrategy;
8
+ props: Record<string, unknown>;
9
+ children: ReactNode;
10
+ }
11
+
12
+ /**
13
+ * Wraps hydratable components with data attributes for browser hydration.
14
+ *
15
+ * When strategy is 'none', renders children directly without wrapper overhead.
16
+ * Otherwise, wraps in a div with data-hydrate attributes that the browser
17
+ * hydration script uses to find and hydrate components.
18
+ */
19
+ export function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps) {
20
+ // No hydration needed - render children directly without wrapper
21
+ if (strategy === 'none') {
22
+ return <>{children}</>;
23
+ }
24
+
25
+ // Strip Puck-internal props that aren't needed for hydration.
26
+ // `puck` contains functions (renderDropZone) that can't survive JSON serialization
27
+ // and would crash on hydration if a component called them.
28
+ const { puck: _puck, ...hydrateProps } = props as Record<string, unknown> & { puck?: unknown };
29
+
30
+ // Wrap with hydration markers for the browser script to find
31
+ return (
32
+ <div
33
+ style={{ display: 'contents' }}
34
+ data-hydrate={componentName}
35
+ data-hydrate-strategy={strategy}
36
+ data-props={serializeProps(hydrateProps)}
37
+ >
38
+ {children}
39
+ </div>
40
+ );
41
+ }
@@ -0,0 +1,204 @@
1
+ import type { MDXHeading } from '@conloca/content-api';
2
+ import type { MDXFragmentEvaluationResult } from '@conloca/mdx/node';
3
+ import type { ComponentConfig, Config, Data, PuckComponent } from '@puckeditor/core';
4
+ import { Render } from '@puckeditor/core/rsc';
5
+ import type { ComponentType } from 'react';
6
+ import { hasHydratableComponents } from '../lib/hydration-utils.js';
7
+ import type { ContentFragmentSectionProps, DataContext } from '../types.js';
8
+ import { RenderWithHydration } from './RenderWithHydration.js';
9
+
10
+ interface MDXComponent {
11
+ id: string;
12
+ title: string;
13
+ Component: ComponentType;
14
+ outline: readonly MDXHeading[];
15
+ }
16
+
17
+ function isRenderableFragment(fragment: MDXFragmentEvaluationResult | MDXComponent): fragment is MDXComponent {
18
+ return 'Component' in fragment && !('ok' in fragment);
19
+ }
20
+
21
+ interface RenderWithFragmentsProps {
22
+ config: Config;
23
+ data: Data;
24
+ mdxComponents: MDXComponent[];
25
+ metadata: DataContext;
26
+ }
27
+
28
+ function createFailedFragmentComponent(fragment: Extract<MDXFragmentEvaluationResult, { ok: false }>): ComponentType {
29
+ return function FailedFragmentComponent() {
30
+ return (
31
+ <div className="p-4 bg-red-50 border border-red-200 rounded text-red-600">
32
+ <p className="font-semibold mb-2">MDX Fragment Error</p>
33
+ <p className="text-sm">Fragment: {fragment.id}</p>
34
+ <p className="text-xs mt-2">{fragment.error.message}</p>
35
+ </div>
36
+ );
37
+ };
38
+ }
39
+
40
+ function resolveRenderableFragments(fragments: (MDXFragmentEvaluationResult | MDXComponent)[]): MDXComponent[] {
41
+ return fragments.map((fragment) => {
42
+ if (isRenderableFragment(fragment)) {
43
+ return fragment;
44
+ }
45
+
46
+ if (fragment.ok) {
47
+ return fragment;
48
+ }
49
+
50
+ return {
51
+ id: fragment.id,
52
+ title: fragment.title,
53
+ Component: createFailedFragmentComponent(fragment),
54
+ outline: [],
55
+ };
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Wrap a host block's own render so it receives the resolved fragment as a
61
+ * prop. The platform owns resolution, the site owns the markup around it: the
62
+ * marker attribute makes the style scanner's content-root detection exact
63
+ * instead of heuristic.
64
+ */
65
+ function withResolvedFragment(
66
+ hostRender: PuckComponent<ContentFragmentSectionProps>,
67
+ fragmentComponentMap: Map<string, MDXComponent>,
68
+ ): PuckComponent<ContentFragmentSectionProps> {
69
+ // Rendered, never called: a site may ship its block as memo(...) or
70
+ // forwardRef(...), and those are objects React renders but nothing invokes.
71
+ const HostBlock = hostRender;
72
+
73
+ return (props) => {
74
+ const selected = fragmentComponentMap.get(props.fragmentId);
75
+ const SelectedFragmentComponent = selected?.Component;
76
+
77
+ return (
78
+ <HostBlock
79
+ {...props}
80
+ fragmentOutline={selected?.outline ?? []}
81
+ fragment={
82
+ SelectedFragmentComponent ? (
83
+ <div className="mdx-content conloca-prose" data-conloca-content-root="">
84
+ <SelectedFragmentComponent />
85
+ </div>
86
+ ) : undefined
87
+ }
88
+ />
89
+ );
90
+ };
91
+ }
92
+
93
+ // ── Main Component ──────────────────────────────────────────────────────────
94
+
95
+ /**
96
+ * Internal component for rendering Puck pages with MDX fragments.
97
+ *
98
+ * Enhances the Puck config by:
99
+ * 1. Registering each MDX fragment as a dynamic Puck component (`Fragment_{id}`)
100
+ * 2. Wrapping the host's `ContentFragmentSection` render so it receives the
101
+ * resolved fragment as a `fragment` prop
102
+ *
103
+ * MDX fragments are passed as React components (not HTML strings), which:
104
+ * - Avoids dangerouslySetInnerHTML security risks
105
+ * - More efficient (no HTML conversion round-trip)
106
+ * - Type-safe with proper React component types
107
+ *
108
+ * @internal
109
+ */
110
+ function RenderWithFragments({ config, data, mdxComponents, metadata }: RenderWithFragmentsProps) {
111
+ // Build enhanced config with MDX fragments
112
+ const fragmentComponents: Record<string, ComponentConfig> = {};
113
+ const fragmentCategoryList: string[] = [];
114
+ const fragmentComponentMap = new Map(mdxComponents.map((fragment) => [fragment.id, fragment]));
115
+
116
+ // Create component configs for each fragment
117
+ mdxComponents.forEach((fragment) => {
118
+ const componentKey = `Fragment_${fragment.id}`;
119
+
120
+ // Capture component in closure - Puck doesn't persist defaultProps reliably
121
+ const FragmentComponent = fragment.Component;
122
+
123
+ fragmentComponents[componentKey] = {
124
+ label: fragment.title,
125
+ fields: {},
126
+ defaultProps: {},
127
+ render: () => (
128
+ <div className="mdx-content conloca-prose" data-conloca-content-root="">
129
+ <FragmentComponent />
130
+ </div>
131
+ ),
132
+ };
133
+ fragmentCategoryList.push(componentKey);
134
+ });
135
+
136
+ // Merge with existing config
137
+ const existingCategories = config.categories || {};
138
+ const existingComponents = config.components || {};
139
+ const contentFragmentSection = existingComponents.ContentFragmentSection as
140
+ | ComponentConfig<ContentFragmentSectionProps>
141
+ | undefined;
142
+
143
+ const enhancedContentFragmentSection = contentFragmentSection
144
+ ? {
145
+ ...contentFragmentSection,
146
+ render: withResolvedFragment(contentFragmentSection.render, fragmentComponentMap),
147
+ }
148
+ : undefined;
149
+
150
+ // Merge fragment components with existing config components
151
+ const mergedComponents = {
152
+ ...existingComponents,
153
+ ...(enhancedContentFragmentSection && { ContentFragmentSection: enhancedContentFragmentSection }),
154
+ ...fragmentComponents,
155
+ } as Config['components'];
156
+
157
+ const enhancedConfig: Config = {
158
+ ...config,
159
+ categories: {
160
+ ...existingCategories,
161
+ fragments: {
162
+ title: 'Content Fragments',
163
+ components: fragmentCategoryList,
164
+ },
165
+ },
166
+ components: mergedComponents,
167
+ };
168
+
169
+ // Check if page has hydratable components
170
+ const needsHydration = hasHydratableComponents(data, enhancedConfig);
171
+
172
+ if (needsHydration) {
173
+ return <RenderWithHydration config={enhancedConfig} data={data} metadata={metadata} />;
174
+ }
175
+
176
+ return <Render config={enhancedConfig} data={data} metadata={metadata} />;
177
+ }
178
+
179
+ /**
180
+ * Factory function to create a PageRenderer with MDX components baked in via closure.
181
+ *
182
+ * This approach avoids dangerouslySetInnerHTML by keeping React components as components
183
+ * throughout the rendering pipeline. Components are captured in the closure and don't
184
+ * need to be passed as props (which Astro can't serialize).
185
+ *
186
+ * @param config - The Puck configuration with component definitions
187
+ * @param data - Puck page data containing component tree
188
+ * @param mdxComponents - Array of evaluated MDX fragment results
189
+ * @param metadata - The page's data context, handed to every block's render as `puck.metadata`
190
+ * @returns A PageRenderer component with no props needed (components in closure)
191
+ */
192
+ export function createPageRendererWithFragments(
193
+ config: Config,
194
+ data: Data,
195
+ mdxComponents: (MDXFragmentEvaluationResult | MDXComponent)[],
196
+ metadata: DataContext,
197
+ ): ComponentType {
198
+ const renderableFragments = resolveRenderableFragments(mdxComponents);
199
+
200
+ // Capture components in closure - no need to pass as props
201
+ return function PageRendererWithFragments() {
202
+ return <RenderWithFragments config={config} data={data} mdxComponents={renderableFragments} metadata={metadata} />;
203
+ };
204
+ }
@@ -0,0 +1,55 @@
1
+ import type { Config, Data } from '@puckeditor/core';
2
+ import { Render } from '@puckeditor/core/rsc';
3
+ import { isHydratable } from '../lib/hydration-utils.js';
4
+ import type { DataContext } from '../types.js';
5
+ import { HydrationWrapper } from './HydrationWrapper.js';
6
+
7
+ interface RenderWithHydrationProps {
8
+ config: Config;
9
+ data: Data;
10
+ metadata: DataContext;
11
+ }
12
+
13
+ /**
14
+ * Wrapper around Puck's Render component that adds hydration support.
15
+ *
16
+ * For each component with a hydration strategy configured, wraps the
17
+ * component's render output with HydrationWrapper to add data-hydrate
18
+ * attributes for browser-side hydration.
19
+ *
20
+ * Non-hydratable components render without any wrapper overhead. Every block
21
+ * renders with the page's data context as `puck.metadata` on the server; a
22
+ * hydrated block does not get `puck` in the browser.
23
+ */
24
+ export function RenderWithHydration({ config, data, metadata }: RenderWithHydrationProps) {
25
+ // Create wrapped config with hydration-aware render functions
26
+ const wrappedConfig: Config = {
27
+ ...config,
28
+ components: Object.fromEntries(
29
+ Object.entries(config.components).map(([name, componentConfig]) => {
30
+ const strategy = isHydratable(name, config);
31
+
32
+ if (strategy === 'none') {
33
+ // No wrapping needed - component stays static
34
+ return [name, componentConfig];
35
+ }
36
+
37
+ // Wrap the render function so its output becomes HydrationWrapper children
38
+ const originalRender = componentConfig.render;
39
+ return [
40
+ name,
41
+ {
42
+ ...componentConfig,
43
+ render: (props) => (
44
+ <HydrationWrapper componentName={name} strategy={strategy} props={props}>
45
+ {originalRender(props)}
46
+ </HydrationWrapper>
47
+ ),
48
+ },
49
+ ];
50
+ }),
51
+ ),
52
+ };
53
+
54
+ return <Render config={wrappedConfig} data={data} metadata={metadata} />;
55
+ }
@@ -0,0 +1,3 @@
1
+ export { evaluateMDXFragments } from '@conloca/mdx/node';
2
+ export { createPageRendererWithFragments } from './components/RenderWithFragments.js';
3
+ export { RenderWithHydration } from './components/RenderWithHydration.js';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Extract the frontmatter (the `---`-fenced TypeScript block) from
3
+ * an `.astro` source file. Returns the inner text, or `null` if no
4
+ * frontmatter is present (a valid Astro file shape — props-less
5
+ * components without `<script>` of any kind).
6
+ *
7
+ * Astro's official compiler (`@astrojs/compiler`) exposes a full
8
+ * parser, but for the props-extraction use case all we need is the
9
+ * text between the opening and closing fences. A regex is sufficient
10
+ * and keeps this synchronous (no WASM init cost, no async).
11
+ *
12
+ * The fence rule is simple: the file must start with `---\n` and
13
+ * close with `\n---` followed by either a newline or end-of-file.
14
+ * Whitespace before the opening fence is rejected — Astro itself
15
+ * requires the fence at column 0.
16
+ */
17
+ export function extractAstroFrontmatter(content: string): string | null {
18
+ // `^---\r?\n` opens; `\r?\n---\s*(?:\r?\n|$)` closes.
19
+ // Capturing the inner content lazily so a body containing `---`
20
+ // (eg a horizontal rule string inside a default-prop) doesn't
21
+ // truncate. Astro itself uses the same "first ---/--- pair" rule.
22
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
23
+ return match ? match[1] : null;
24
+ }