@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,98 @@
1
+ import { createContentAPI } from '@conloca/content-api/reader';
2
+ import type { Loader, LoaderContext } from 'astro/loaders';
3
+
4
+ // Both registries are per-process, not per-config-evaluation: a dev-server
5
+ // config reload re-runs content.config without clearing them. So a collection
6
+ // dropped from the config stays declared, and a passing check is not repeated
7
+ // for a directory that appears later — not until the server restarts. Both are
8
+ // deliberately open: a stale registry can only miss a complaint, never invent
9
+ // one. Only successful checks are memoised, so a failing one is retried on the
10
+ // next load and a leftover can never keep failing a build the user has since
11
+ // fixed in content.config.ts.
12
+ const declared = new Set<string>();
13
+ const checks = new Map<string, Promise<void>>();
14
+
15
+ export type ConlocaCollectionKind = 'page' | 'data' | 'fragment';
16
+
17
+ /** Registry entries carry their kind: a data collection `general` must not cover an undeclared fragment FOLDER `general`. */
18
+ export type QualifiedCollectionName = `${ConlocaCollectionKind}:${string}`;
19
+
20
+ const qualifiedName = (kind: ConlocaCollectionKind, name: string): QualifiedCollectionName => `${kind}:${name}`;
21
+
22
+ /** 'data:faqs' → 'the data collection "faqs"' — the registry key is internal, the error is for a human. */
23
+ function describeQualified(qualified: QualifiedCollectionName): string {
24
+ const separator = qualified.indexOf(':');
25
+ return `the ${qualified.slice(0, separator)} collection "${qualified.slice(separator + 1)}"`;
26
+ }
27
+
28
+ /** Factories call this as content.config evaluates; the registry is complete before any loader runs. */
29
+ export function declareConlocaCollection(kind: ConlocaCollectionKind, name: string): void {
30
+ declared.add(qualifiedName(kind, name));
31
+ }
32
+
33
+ /** Test hook — the registry is module state shared across a config evaluation. */
34
+ export function resetDeclaredCollections(): void {
35
+ declared.clear();
36
+ checks.clear();
37
+ }
38
+
39
+ /**
40
+ * Every Conloca collection on disk must be declared in content.config, or its
41
+ * entries silently never build. The reverse — declared with no directory yet —
42
+ * is the schema-first workflow (the directory appears with the first saved
43
+ * entry) and is allowed.
44
+ */
45
+ export function assertCollectionsDeclared(onDisk: Iterable<QualifiedCollectionName>): void {
46
+ // A qualified name repeats only when one iterable carries duplicates —
47
+ // dedupe so nothing is ever reported twice.
48
+ const undeclared = [...new Set(onDisk)].filter((name) => !declared.has(name));
49
+ if (undeclared.length === 0) return;
50
+ throw new Error(
51
+ `[conloca] content on disk has collections that content.config.ts does not declare: ${undeclared
52
+ .map(describeQualified)
53
+ .join(', ')}. Declare each one (conlocaPages / conlocaData / conlocaFragments) or its entries will not be built.`,
54
+ );
55
+ }
56
+
57
+ /** Enumerates every collection kind on disk and checks the registry covers them. */
58
+ async function assertDiskDeclared(options: { contentRoot: string; site: string }): Promise<void> {
59
+ const api = await createContentAPI({ contentRoot: options.contentRoot });
60
+ assertCollectionsDeclared([
61
+ ...[...(api.getSite(options.site)?.collections ?? [])].map((name) => qualifiedName('page', name)),
62
+ ...[...api.data.collections].map((name) => qualifiedName('data', name)),
63
+ ...[...api.fragments.collections].map((name) => qualifiedName('fragment', name)),
64
+ ]);
65
+ }
66
+
67
+ /**
68
+ * Wraps a factory-created loader so a config evaluation checks the disk once
69
+ * per content root and site. createConlocaCollections' loaders are not wrapped
70
+ * — its contract IS discovery.
71
+ *
72
+ * Astro runs every loader concurrently through one Promise.all, so the check is
73
+ * memoised as a promise rather than a done-flag: one scan per root and site,
74
+ * and every loader awaits the same result instead of racing past a check still
75
+ * running.
76
+ */
77
+ export function withDeclarationCheck(loader: Loader, options: { contentRoot: string; site: string }): Loader {
78
+ return {
79
+ ...loader,
80
+ async load(context: LoaderContext): Promise<void> {
81
+ // NUL separates the two halves — a space collides with paths containing spaces.
82
+ const key = `${options.contentRoot}\0${options.site}`;
83
+ let check = checks.get(key);
84
+ if (!check) {
85
+ check = assertDiskDeclared(options).catch((error: unknown) => {
86
+ // Only a successful check is memoised: module state outlives a
87
+ // dev-server config reload, so a cached rejection would keep failing
88
+ // after the user has declared the collection it asked for.
89
+ checks.delete(key);
90
+ throw error;
91
+ });
92
+ checks.set(key, check);
93
+ }
94
+ await check;
95
+ return loader.load(context);
96
+ },
97
+ };
98
+ }
@@ -0,0 +1,210 @@
1
+ import { type PageSchemas, toPageSchemaDescriptor } from '@conloca/cms-spa/page-schema-define';
2
+ import type { ContentMeta } from '@conloca/content-api';
3
+ import { type PageMeta, pageMetaSchema } from '@conloca/content-api/schemas';
4
+ import { z } from 'zod';
5
+ import { LOADER_RESERVED_FIELDS } from '../loader.js';
6
+
7
+ const CORE_FIELD_NAMES = new Set(Object.keys(pageMetaSchema.shape));
8
+ const RESERVED_FIELD_NAMES = new Set<string>(LOADER_RESERVED_FIELDS);
9
+
10
+ type RewriteKind = 'default' | 'catch' | 'transform' | 'coerce';
11
+
12
+ type ZodDef = {
13
+ type?: string;
14
+ coerce?: boolean;
15
+ innerType?: z.ZodType;
16
+ in?: z.ZodType;
17
+ shape?: Record<string, z.ZodType> | (() => Record<string, z.ZodType>);
18
+ element?: z.ZodType;
19
+ options?: z.ZodType[];
20
+ items?: z.ZodType[];
21
+ valueType?: z.ZodType;
22
+ keyType?: z.ZodType;
23
+ rest?: z.ZodType;
24
+ left?: z.ZodType;
25
+ right?: z.ZodType;
26
+ getter?: () => z.ZodType;
27
+ catchall?: z.ZodType;
28
+ };
29
+
30
+ /**
31
+ * `seen` breaks cycles through shared schema instances, but a z.lazy whose
32
+ * factory builds fresh instances on every call defeats it — the depth cap is
33
+ * the backstop. No real page-meta schema nests this deep.
34
+ */
35
+ const MAX_REWRITE_WALK_DEPTH = 32;
36
+
37
+ function findRewrite(
38
+ schema: z.ZodType,
39
+ path: string,
40
+ seen: Set<z.ZodType>,
41
+ depth = 0,
42
+ ): { kind: RewriteKind; path: string } | null {
43
+ if (seen.has(schema) || depth > MAX_REWRITE_WALK_DEPTH) return null;
44
+ seen.add(schema);
45
+ const def = schema.def as ZodDef;
46
+ if (def.type === 'default') return { kind: 'default', path };
47
+ if (def.type === 'catch') return { kind: 'catch', path };
48
+ if (def.type === 'pipe') return { kind: 'transform', path };
49
+ if (def.coerce) return { kind: 'coerce', path };
50
+
51
+ // Every child schema paired with the path it is reported under, in the
52
+ // order the walk visits them — the first rewrite found is the one named
53
+ // in the error, so this order is part of the contract.
54
+ const shape = typeof def.shape === 'function' ? def.shape() : def.shape;
55
+ const children: [z.ZodType | undefined, string][] = [[def.innerType ?? def.in, path]];
56
+ for (const [key, child] of Object.entries(shape ?? {})) {
57
+ children.push([child, path ? `${path}.${key}` : key]);
58
+ }
59
+ children.push([def.element, `${path}[]`]);
60
+ for (const option of def.options ?? []) {
61
+ children.push([option, path]);
62
+ }
63
+ for (const [index, item] of (def.items ?? []).entries()) {
64
+ children.push([item, `${path}[${index}]`]);
65
+ }
66
+ children.push(
67
+ [def.rest, `${path}[]`],
68
+ [def.keyType, path],
69
+ [def.valueType, path],
70
+ [def.left, path],
71
+ [def.right, path],
72
+ [def.getter?.(), path],
73
+ [def.catchall, `${path}[*]`],
74
+ );
75
+
76
+ for (const [child, childPath] of children) {
77
+ if (!child) continue;
78
+ const found = findRewrite(child, childPath, seen, depth + 1);
79
+ if (found) return found;
80
+ }
81
+ return null;
82
+ }
83
+
84
+ function assertHostFieldsAreSafe(shape: z.ZodRawShape): void {
85
+ for (const [name, schema] of Object.entries(shape)) {
86
+ if (CORE_FIELD_NAMES.has(name)) {
87
+ throw new Error(
88
+ `[conloca] pageSchemas cannot redeclare Conloca field "${name}". ` +
89
+ 'Title, pathname, locale, and the other core fields come from the CMS — put constraints on them in the editor schema, not here.',
90
+ );
91
+ }
92
+ if (RESERVED_FIELD_NAMES.has(name)) {
93
+ throw new Error(
94
+ `[conloca] pageSchemas cannot declare "${name}". ` +
95
+ 'That field is owned by the content loader; a host schema of the same name would replace page content on every page.',
96
+ );
97
+ }
98
+ const rewrite = findRewrite(schema as z.ZodType, name, new Set());
99
+ if (rewrite) {
100
+ throw new Error(
101
+ `[conloca] pageSchemas field "${rewrite.path}" uses .${rewrite.kind}(), which rewrites values when Astro validates the collection ` +
102
+ 'and does not run in the editor preview. Use a plain field (optional string, array, …) and parse in one reader instead.',
103
+ );
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Fold every page-schema descriptor into one Zod object of host meta fields.
110
+ * Requiredness is not preserved — the caller always `.partial()`s this for the
111
+ * collection, because Astro validates the whole `pages` pile.
112
+ *
113
+ * The merged object has one slot per field name, so two descriptors may only
114
+ * declare the same name by sharing the same field schema instance — last-wins
115
+ * would silently rewrite what the earlier prefix's pages are validated
116
+ * against, failing them with a Zod error that names neither descriptor.
117
+ */
118
+ export function hostFieldsFromPageSchemas(pageSchemas: PageSchemas): z.ZodObject<z.ZodRawShape> {
119
+ // z.ZodRawShape's index signature is readonly, so the accumulator is spelled
120
+ // with a mutable one.
121
+ const shape: Record<string, z.ZodRawShape[string]> = {};
122
+ const fieldOwner = new Map<string, string>();
123
+ for (const [key, entry] of Object.entries(pageSchemas)) {
124
+ const descriptor = toPageSchemaDescriptor(entry);
125
+ // Rebuilding from .shape below silently drops object-level refinements,
126
+ // so the refusal written for them has to run here, on the public path.
127
+ assertNoObjectRefinements(descriptor.schema);
128
+ // 'minimal'/'none' descriptors declare title for the form; strip those names so the collection guard does not fire.
129
+ const mode = descriptor.coreFields?.mode;
130
+ const stripCore = mode === 'minimal' || mode === 'none';
131
+ for (const [name, field] of Object.entries(descriptor.schema.shape)) {
132
+ if (stripCore && CORE_FIELD_NAMES.has(name)) continue;
133
+ const owner = fieldOwner.get(name);
134
+ if (owner !== undefined && shape[name] !== field) {
135
+ throw new Error(
136
+ `[conloca] pageSchemas "${owner}" and "${key}" both declare field "${name}" with different schemas. ` +
137
+ 'The merged collection schema has one slot per field name — declare the field once and import it ' +
138
+ 'into both schemas, or rename one of the fields.',
139
+ );
140
+ }
141
+ fieldOwner.set(name, owner ?? key);
142
+ shape[name] = field;
143
+ }
144
+ }
145
+ return z.object(shape);
146
+ }
147
+
148
+ /**
149
+ * A page collection entry as the loader delivers it: the validated
150
+ * `pageMetaSchema` fields, the loader-written record fields (`created`,
151
+ * `modified`, `name`, `puckData` — admitted by the loose index at runtime),
152
+ * and the host's meta fields through `ContentMeta`/`HostPageMeta`.
153
+ */
154
+ export type ConlocaPageEntry = ContentMeta &
155
+ PageMeta & {
156
+ created?: string | Date;
157
+ modified?: string | Date;
158
+ name?: string;
159
+ puckData?: unknown;
160
+ };
161
+
162
+ /**
163
+ * The schema Astro validates page entries against: the host's page-meta fields
164
+ * (all optional) with conloca's structural fields layered over them, loose so
165
+ * undeclared top-level fields still reach the rendered page.
166
+ *
167
+ * Looseness is TOP-LEVEL ONLY. A nested `z.object()` still strips undeclared
168
+ * nested keys; a host that wants them preserved has to write `z.looseObject()`.
169
+ *
170
+ * Rewrite bans (.default / .coerce / .transform / .catch) walk nested objects,
171
+ * arrays, and unions. `.partial()` is still shallow.
172
+ *
173
+ * Internal on purpose: `src/collections.ts` is a published entry (the
174
+ * `./collections` subpath), so anything exported from there is frozen under
175
+ * semver. Nothing outside this package consumes it.
176
+ */
177
+ export function buildPageCollectionSchema(hostFields: z.ZodObject<z.ZodRawShape>): z.ZodType<ConlocaPageEntry> {
178
+ assertNoObjectRefinements(hostFields);
179
+ assertHostFieldsAreSafe(hostFields.shape);
180
+ // The one declared seam in the typed-collections design: the runtime
181
+ // schema validates core + host fields and loosely admits the loader-written
182
+ // record fields, but TypeScript cannot see host fields through the loose
183
+ // index. The static type is asserted as the flattened entry instead, which
184
+ // is the same contract listings already rely on — a host declaring
185
+ // `HostPageMeta` promises it matches its `pageSchemas`. Pinned by the type
186
+ // proofs here and in the type proofs of a site that declares `HostPageMeta`.
187
+ return z.looseObject({
188
+ ...hostFields.partial().shape,
189
+ ...pageMetaSchema.shape,
190
+ }) as unknown as z.ZodType<ConlocaPageEntry>;
191
+ }
192
+
193
+ /**
194
+ * .partial() throws on a refined object, and a refined object still satisfies
195
+ * both the host-fields signature and the pageSchemas field type, so the raw
196
+ * zod error would surface while Astro loads content.config.ts naming neither
197
+ * conloca nor pageSchemas. Refuse it with something the host can act on —
198
+ * both on the fold over pageSchemas (which would otherwise silently DROP the
199
+ * refinement while rebuilding from .shape) and on direct host-fields callers.
200
+ */
201
+ function assertNoObjectRefinements(schema: z.ZodObject<z.ZodRawShape>): void {
202
+ if ((schema.def.checks?.length ?? 0) > 0) {
203
+ throw new Error(
204
+ '[conloca] pageSchemas cannot carry object-level refinements (.refine, .superRefine or .check). ' +
205
+ 'Conloca makes every host field optional — page schemas are prefix-scoped in the editor while ' +
206
+ 'Astro validates a whole collection — and Zod cannot make a refined object partial. ' +
207
+ 'Move the rule onto the individual field schemas instead.',
208
+ );
209
+ }
210
+ }
@@ -0,0 +1,48 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ /** Where Astro looks for a content config, newest location first. */
5
+ const CONTENT_CONFIG_CANDIDATES = [
6
+ 'src/content.config.ts',
7
+ 'src/content.config.mts',
8
+ 'src/content.config.mjs',
9
+ 'src/content.config.js',
10
+ 'src/content/config.ts',
11
+ 'src/content/config.mjs',
12
+ 'src/content/config.js',
13
+ ];
14
+
15
+ export type ContentConfigProblem = 'missing' | 'not-wired';
16
+
17
+ /**
18
+ * Any of these in the config means Conloca's collections get registered —
19
+ * the factories, the deprecated wrapper, or a hand-rolled
20
+ * `defineCollection({ loader: conlocaLoader(...) })` (a supported shape;
21
+ * the loader carries its own mounted-key guard).
22
+ */
23
+ const WIRED_MARKERS = ['createConlocaCollections', 'conlocaPages', 'conlocaData', 'conlocaFragments', 'conlocaLoader'];
24
+
25
+ /**
26
+ * Detect the single most common Conloca misconfiguration: a project whose
27
+ * content config never registers Conloca's collections, so every page 404s
28
+ * with no other symptom. Astro exposes no hook that reveals resolved
29
+ * collections, so this reads the file instead.
30
+ */
31
+ export function findContentConfigProblem(projectRoot: string): ContentConfigProblem | null {
32
+ const found = CONTENT_CONFIG_CANDIDATES.map((candidate) => join(projectRoot, candidate)).find((path) =>
33
+ existsSync(path),
34
+ );
35
+ if (!found) return 'missing';
36
+
37
+ const source = readFileSync(found, 'utf8');
38
+ return WIRED_MARKERS.some((marker) => source.includes(marker)) ? null : 'not-wired';
39
+ }
40
+
41
+ /** The copy-pasteable fix printed with either problem. */
42
+ export const CONTENT_CONFIG_SNIPPET = `// src/content.config.ts
43
+ import { conlocaFragments, conlocaPages } from '@conloca/astro-cms/node/content';
44
+
45
+ export const collections = {
46
+ pages: conlocaPages(),
47
+ ...conlocaFragments(),
48
+ };`;
@@ -0,0 +1,176 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { basename, dirname, extname, join, resolve } from 'node:path';
3
+ import fg from 'fast-glob';
4
+
5
+ /**
6
+ * Result of scanning a component file for withHydration usage.
7
+ */
8
+ export interface HydrationDiscovery {
9
+ /** Component name derived from filename (PascalCase) */
10
+ componentName: string;
11
+ /** Absolute path to the component file */
12
+ filePath: string;
13
+ /** Hydration strategy extracted from withHydration call */
14
+ strategy: 'load' | 'visible' | 'idle';
15
+ }
16
+
17
+ // Regex to check if file imports withHydration from @conloca/astro-cms or @conloca/astro-cms/hydration
18
+ // This is faster than es-module-lexer for JSX files and avoids parse errors
19
+ export const HYDRATION_IMPORT_PATTERN =
20
+ /import\s+\{[^}]*withHydration[^}]*\}\s+from\s+['"]@conloca\/astro-cms(?:\/hydration)?['"]/;
21
+
22
+ // Regex to find withHydration calls and extract strategy
23
+ // Matches: withHydration(ComponentName, 'strategy') or withHydration(ComponentName, "strategy")
24
+ export const HYDRATION_PATTERN = /withHydration\s*\(\s*\w+\s*,\s*['"](\w+)['"]\s*\)/g;
25
+
26
+ // Valid hydration strategies
27
+ const VALID_STRATEGIES = new Set(['load', 'visible', 'idle']);
28
+
29
+ /**
30
+ * Derives component scan paths from puckConfigPath.
31
+ *
32
+ * Convention: puckConfigPath directory + '/components/puck'
33
+ * Example: './src/puck.config.tsx' -> './src/components/puck'
34
+ *
35
+ * If explicitPaths provided, they extend (not replace) the auto-discovered path.
36
+ *
37
+ * @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
38
+ * @param explicitPaths - Optional additional paths to scan
39
+ * @returns Array of paths to scan for hydratable components
40
+ */
41
+ export function deriveComponentPaths(puckConfigPath: string, explicitPaths?: string[]): string[] {
42
+ const puckDir = dirname(puckConfigPath);
43
+ const defaultScanPath = join(puckDir, 'components', 'puck');
44
+
45
+ if (explicitPaths && explicitPaths.length > 0) {
46
+ return [defaultScanPath, ...explicitPaths];
47
+ }
48
+ return [defaultScanPath];
49
+ }
50
+
51
+ /**
52
+ * Derives a PascalCase component name from a file path.
53
+ *
54
+ * @param filePath - Absolute path to the component file
55
+ * @returns Component name in PascalCase
56
+ *
57
+ * @example
58
+ * deriveComponentName('/src/components/puck/TestimonialGrid.tsx')
59
+ * // => 'TestimonialGrid'
60
+ *
61
+ * deriveComponentName('/src/components/puck/blog-post-grid.tsx')
62
+ * // => 'BlogPostGrid'
63
+ */
64
+ function deriveComponentName(filePath: string): string {
65
+ const filename = basename(filePath, extname(filePath));
66
+ // Convert kebab-case to PascalCase if needed
67
+ if (filename.includes('-')) {
68
+ return filename
69
+ .split('-')
70
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
71
+ .join('');
72
+ }
73
+ // Ensure first letter is uppercase
74
+ return filename.charAt(0).toUpperCase() + filename.slice(1);
75
+ }
76
+
77
+ /**
78
+ * Scans component directories for files using withHydration wrapper.
79
+ *
80
+ * This function performs static analysis to discover components marked
81
+ * for hydration, without executing any component code.
82
+ *
83
+ * @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
84
+ * @param projectRoot - Absolute path to the project root
85
+ * @returns Array of discovered hydratable components with their strategies
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const discoveries = await scanForHydratableComponents(
90
+ * ['src/components/puck'],
91
+ * '/path/to/project'
92
+ * )
93
+ * // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
94
+ * ```
95
+ */
96
+ export async function scanForHydratableComponents(
97
+ componentPaths: string[],
98
+ projectRoot: string,
99
+ ): Promise<HydrationDiscovery[]> {
100
+ const discoveries: HydrationDiscovery[] = [];
101
+ const seenNames = new Map<string, string>(); // componentName -> first filePath
102
+
103
+ for (const scanPath of componentPaths) {
104
+ const absolutePath = resolve(projectRoot, scanPath);
105
+
106
+ // Find all .tsx files in the directory and subdirectories
107
+ const files = await fg('**/*.tsx', {
108
+ cwd: absolutePath,
109
+ absolute: true,
110
+ onlyFiles: true,
111
+ });
112
+
113
+ for (const filePath of files) {
114
+ try {
115
+ const content = await readFile(filePath, 'utf-8');
116
+
117
+ // Fast path: check if file imports withHydration from @conloca/astro-cms
118
+ // Using simple regex instead of es-module-lexer to avoid JSX parse errors
119
+ if (!HYDRATION_IMPORT_PATTERN.test(content)) {
120
+ continue;
121
+ }
122
+
123
+ // Find withHydration calls with regex
124
+ const matches = [...content.matchAll(HYDRATION_PATTERN)];
125
+
126
+ if (matches.length === 0) {
127
+ continue;
128
+ }
129
+
130
+ if (matches.length > 1) {
131
+ console.warn(
132
+ `[Conloca Hydration] Multiple withHydration calls in ${filePath}. ` +
133
+ 'Consider splitting into separate component files. Using first call.',
134
+ );
135
+ }
136
+
137
+ const match = matches[0];
138
+ const rawStrategy = match[1];
139
+
140
+ // Validate strategy
141
+ if (!VALID_STRATEGIES.has(rawStrategy)) {
142
+ console.warn(
143
+ `[Conloca Hydration] Invalid strategy '${rawStrategy}' in ${filePath}. ` +
144
+ `Valid options: ${[...VALID_STRATEGIES].join(', ')}. Skipping component.`,
145
+ );
146
+ continue;
147
+ }
148
+
149
+ const strategy = rawStrategy as 'load' | 'visible' | 'idle';
150
+ const componentName = deriveComponentName(filePath);
151
+
152
+ // Check for naming conflicts
153
+ const existingPath = seenNames.get(componentName);
154
+ if (existingPath) {
155
+ console.warn(
156
+ `[Conloca Hydration] Duplicate component name '${componentName}'. ` +
157
+ `Found in: ${existingPath} and ${filePath}. Using first occurrence.`,
158
+ );
159
+ continue;
160
+ }
161
+
162
+ seenNames.set(componentName, filePath);
163
+ discoveries.push({
164
+ componentName,
165
+ filePath,
166
+ strategy,
167
+ });
168
+ } catch (err) {
169
+ // Log error but continue scanning other files
170
+ console.warn(`[Conloca Hydration] Error reading ${filePath}:`, err);
171
+ }
172
+ }
173
+ }
174
+
175
+ return discoveries;
176
+ }
@@ -0,0 +1,126 @@
1
+ import { createElement } from 'react';
2
+ import { hydrateRoot } from 'react-dom/client';
3
+
4
+ import type { HydrationStrategy } from '../types.js';
5
+
6
+ /**
7
+ * Async loader that returns a React component.
8
+ * The registry generator handles extraction from ComponentConfig at build time.
9
+ */
10
+ type ComponentLoader = () => Promise<React.ComponentType<unknown>>;
11
+
12
+ /**
13
+ * Registry entry with loader and strategy.
14
+ * Generated by the scanner from withHydration metadata.
15
+ */
16
+ interface ComponentRegistryEntry {
17
+ loader: ComponentLoader;
18
+ strategy: HydrationStrategy;
19
+ }
20
+
21
+ /**
22
+ * Registry mapping component names to their loaders and strategies.
23
+ * Generated by virtual:conloca-hydration-registry at build time.
24
+ */
25
+ export type ComponentRegistry = Record<string, ComponentRegistryEntry>;
26
+
27
+ /**
28
+ * Hydrate a single element with its corresponding React component.
29
+ */
30
+ async function hydrateElement(element: HTMLElement, entry: ComponentRegistryEntry): Promise<void> {
31
+ const componentName = element.dataset.hydrate;
32
+ const propsJson = element.dataset.props || '{}';
33
+
34
+ if (!componentName) {
35
+ console.warn('[Conloca Hydration] Element missing data-hydrate attribute');
36
+ return;
37
+ }
38
+
39
+ try {
40
+ const props = JSON.parse(propsJson);
41
+ const Component = await entry.loader();
42
+ hydrateRoot(element, createElement(Component, props));
43
+
44
+ // Clean up data attributes after successful hydration
45
+ delete element.dataset.hydrate;
46
+ delete element.dataset.hydrateStrategy;
47
+ delete element.dataset.props;
48
+ } catch (error) {
49
+ console.error(`[Conloca Hydration] Failed to hydrate ${componentName}:`, error);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Hydrate immediately on page load.
55
+ */
56
+ function hydrateOnLoad(element: HTMLElement, entry: ComponentRegistryEntry): void {
57
+ hydrateElement(element, entry);
58
+ }
59
+
60
+ /**
61
+ * Hydrate when element becomes visible in viewport.
62
+ */
63
+ function hydrateOnVisible(element: HTMLElement, entry: ComponentRegistryEntry): void {
64
+ const observer = new IntersectionObserver(
65
+ (entries, obs) => {
66
+ for (const ioEntry of entries) {
67
+ if (ioEntry.isIntersecting) {
68
+ obs.unobserve(ioEntry.target);
69
+ hydrateElement(ioEntry.target as HTMLElement, entry);
70
+ }
71
+ }
72
+ },
73
+ { rootMargin: '50px' },
74
+ );
75
+ observer.observe(element);
76
+ }
77
+
78
+ /**
79
+ * Hydrate when browser is idle.
80
+ * Uses requestIdleCallback with setTimeout fallback for Safari.
81
+ */
82
+ function hydrateOnIdle(element: HTMLElement, entry: ComponentRegistryEntry): void {
83
+ const scheduleIdle =
84
+ window.requestIdleCallback ??
85
+ ((cb: IdleRequestCallback) => window.setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 50 }), 1));
86
+
87
+ scheduleIdle(() => hydrateElement(element, entry), { timeout: 2000 });
88
+ }
89
+
90
+ /**
91
+ * Initialize hydration for all marked components on the page.
92
+ *
93
+ * Finds all elements with [data-hydrate] attribute and hydrates them
94
+ * according to their strategy from the registry.
95
+ */
96
+ export function initHydration(registry: ComponentRegistry): void {
97
+ const elements = document.querySelectorAll<HTMLElement>('[data-hydrate]');
98
+
99
+ for (const element of elements) {
100
+ const componentName = element.dataset.hydrate;
101
+ if (!componentName) continue;
102
+
103
+ const entry = registry[componentName];
104
+ if (!entry) {
105
+ console.warn(`[Conloca Hydration] Unknown component: ${componentName}`);
106
+ continue;
107
+ }
108
+
109
+ // Use strategy from registry (set at build time via withHydration)
110
+ const strategy = entry.strategy;
111
+
112
+ switch (strategy) {
113
+ case 'load':
114
+ hydrateOnLoad(element, entry);
115
+ break;
116
+ case 'visible':
117
+ hydrateOnVisible(element, entry);
118
+ break;
119
+ case 'idle':
120
+ hydrateOnIdle(element, entry);
121
+ break;
122
+ default:
123
+ hydrateOnLoad(element, entry);
124
+ }
125
+ }
126
+ }