@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,411 @@
1
+ import type { MdxComponentProp, MdxJsxComponentDescriptor } from '@conloca/cms-spa/mdx-components';
2
+ import type { LocalComponentScanResult, ParsedProp } from './scan-components.js';
3
+ import type { MdxImport, MdxScanResult } from './scan-mdx.js';
4
+ import type { CmsOverride } from './scan-overrides.js';
5
+
6
+ /**
7
+ * Combine the MDX usage scan with the local-component folder scan
8
+ * into the final flat list of component descriptors the editor
9
+ * registry consumes.
10
+ *
11
+ * Rules (chosen to match the decisions locked in earlier this
12
+ * session — usage-only inference for npm, full interface schema
13
+ * for local, per-file context wins on name collisions, aliases
14
+ * preserved per file):
15
+ *
16
+ * 1. Every component referenced by an `import` in any MDX file
17
+ * becomes a descriptor. The `name` is the canonical export
18
+ * name (`Aside`, not `Callout`), the `source` is the import
19
+ * path. This catches npm packages we can't statically scan.
20
+ *
21
+ * 2. Every component found by the local folder scan is also a
22
+ * descriptor. Its props come from the parsed `Props` interface.
23
+ * If the same canonical (name, source) was also seen in MDX,
24
+ * we merge — interface props win on the schema, usage-observed
25
+ * string values enrich `options`.
26
+ *
27
+ * 3. Components seen in MDX but never declared in any import
28
+ * (raw HTML tags like `<div>` or unresolved names) are dropped —
29
+ * `GenericBlock` already has its own HTML-passthrough path.
30
+ *
31
+ * 4. Across all usages, observed string values per attribute are
32
+ * collected. When ≤5 distinct values are seen (and the prop
33
+ * doesn't already have explicit options from the interface),
34
+ * they're added as dropdown choices.
35
+ *
36
+ * 5. Aliases (file-local imports renaming the canonical export,
37
+ * eg `import { Aside as Callout }`) are tracked on the
38
+ * descriptor's `aliases` map keyed by file path. The save
39
+ * serializer reads this to preserve the alias when writing
40
+ * the file back out.
41
+ *
42
+ * 6. Name collisions across different sources (local `<Card>` vs
43
+ * Starlight `<Card>`) — the higher-usage source wins; ties
44
+ * break in favor of the source whose props came from an
45
+ * interface schema. The dropped alternative isn't lost from
46
+ * the merge itself — it just doesn't surface in the registry
47
+ * until per-file disambiguation exists in the insert flow.
48
+ */
49
+
50
+ /** Same shape as `MdxJsxComponentDescriptor` from cms-spa, extended
51
+ * with `aliases` so save serialization can preserve `import { X as Y }`
52
+ * per file. Cms-spa's runtime type doesn't need to know about
53
+ * aliases — they're picked up server-side at save time. */
54
+ export interface DiscoveredComponent extends MdxJsxComponentDescriptor {
55
+ /** Per-file local alias (when the file uses `import { X as Y }`).
56
+ * Map key is the absolute MDX file path. */
57
+ aliases?: Record<string, string>;
58
+ }
59
+
60
+ export function mergeRegistry(
61
+ mdxScans: MdxScanResult[],
62
+ localComponents: LocalComponentScanResult[],
63
+ overrides?: Map<string, CmsOverride>,
64
+ ): DiscoveredComponent[] {
65
+ // Key descriptors by `${source}::${exportName}` so we can merge
66
+ // local-folder data with MDX-usage data and so two components
67
+ // with the same name but different sources stay separate.
68
+ const byKey = new Map<string, DescriptorBuilder>();
69
+
70
+ // Pass 1: seed from local folder scan.
71
+ for (const comp of localComponents) {
72
+ const key = `${comp.source}::${comp.name}`;
73
+ byKey.set(
74
+ key,
75
+ new DescriptorBuilder({
76
+ name: comp.name,
77
+ source: comp.source,
78
+ defaultExport: false,
79
+ kind: comp.kind,
80
+ propsFromInterface: comp.props,
81
+ }),
82
+ );
83
+ }
84
+
85
+ // Pass 2: seed/enrich from MDX usage scans.
86
+ for (const scan of mdxScans) {
87
+ for (const usage of scan.usages) {
88
+ const imp = scan.imports[usage.name];
89
+ if (!imp) continue; // raw HTML tag or unresolved — skip.
90
+ const canonicalName = imp.exportName === 'default' ? usage.name : imp.exportName;
91
+ const key = `${imp.source}::${canonicalName}`;
92
+
93
+ let builder = byKey.get(key);
94
+ if (!builder) {
95
+ builder = new DescriptorBuilder({
96
+ name: canonicalName,
97
+ source: imp.source,
98
+ defaultExport: imp.defaultExport,
99
+ kind: usage.kind,
100
+ });
101
+ byKey.set(key, builder);
102
+ }
103
+ builder.observeUsage(usage.attrs, scan.filepath, usage.name, imp, usage.kind);
104
+ }
105
+ }
106
+
107
+ // Resolve name collisions: when two (source, name) pairs share a
108
+ // `name`, the editor registry can only key one descriptor by that
109
+ // name. Pick the source that has the most MDX usage; the dropped
110
+ // alternative isn't lost forever — it just doesn't surface in the
111
+ // registry until the disambiguation UI exists.
112
+ const grouped = new Map<string, DescriptorBuilder[]>();
113
+ for (const builder of byKey.values()) {
114
+ const arr = grouped.get(builder.name) ?? [];
115
+ arr.push(builder);
116
+ grouped.set(builder.name, arr);
117
+ }
118
+ const winners: DiscoveredComponent[] = [];
119
+ for (const candidates of grouped.values()) {
120
+ candidates.sort((a, b) => {
121
+ // Higher actual MDX usage wins.
122
+ if (a.usageCount !== b.usageCount) return b.usageCount - a.usageCount;
123
+ // Tie: prefer the one with an interface-derived schema (more
124
+ // likely to be the right one).
125
+ const aHasSchema = a.hasInterfaceSchema();
126
+ const bHasSchema = b.hasInterfaceSchema();
127
+ if (aHasSchema !== bHasSchema) return aHasSchema ? -1 : 1;
128
+ return 0;
129
+ });
130
+ let descriptor = candidates[0].toDescriptor();
131
+ const override = overrides?.get(descriptor.name);
132
+ if (override) descriptor = applyOverride(descriptor, override);
133
+ winners.push(descriptor);
134
+ }
135
+ return winners;
136
+ }
137
+
138
+ /**
139
+ * Apply a host-provided override to an auto-discovered descriptor.
140
+ *
141
+ * Three kinds of merges happen:
142
+ *
143
+ * 1. **Shallow object merges** for `insert` and `defaults` — host
144
+ * fields overwrite inferred fields one key at a time, so a host
145
+ * can tweak only the label without losing the inferred category.
146
+ *
147
+ * 2. **Per-prop merges** for the `props` array — match by `name`,
148
+ * override individual fields (`required`, `label`, `help`,
149
+ * `options`) while keeping the rest of the prop's inferred
150
+ * schema (type, defaultValue). Props the override doesn't mention
151
+ * stay untouched.
152
+ *
153
+ * 3. **Scalar overrides** for `hasChildren` and `kind` — host value
154
+ * replaces inferred value directly.
155
+ *
156
+ * The override is INTENTIONALLY a subset of `MdxJsxComponentDescriptor`
157
+ * — fields the host can sensibly customize. Things like `name` and
158
+ * `import` come from the actual file system / MDX scan and can't be
159
+ * meaningfully overridden by a sidecar JSON.
160
+ */
161
+ function applyOverride(descriptor: DiscoveredComponent, override: CmsOverride): DiscoveredComponent {
162
+ const next: DiscoveredComponent = { ...descriptor };
163
+
164
+ if (override.insert) {
165
+ next.insert = { ...(descriptor.insert ?? { label: descriptor.name }), ...override.insert };
166
+ }
167
+ if (override.defaults) {
168
+ next.defaults = {
169
+ ...(descriptor.defaults ?? {}),
170
+ ...override.defaults,
171
+ ...(override.defaults.attributes
172
+ ? { attributes: { ...(descriptor.defaults?.attributes ?? {}), ...override.defaults.attributes } }
173
+ : {}),
174
+ };
175
+ }
176
+ if (override.hasChildren !== undefined) {
177
+ next.hasChildren = override.hasChildren;
178
+ }
179
+ if (override.kind) {
180
+ next.kind = override.kind;
181
+ }
182
+ if (override.props && descriptor.props) {
183
+ const overridesByName = override.props;
184
+ next.props = descriptor.props.map((p) => {
185
+ const o = overridesByName[p.name];
186
+ if (!o) return p;
187
+ // Cast through string-type narrowing — `options` and `defaultValue`
188
+ // shape vary per prop type, so we merge field-by-field and
189
+ // preserve the discriminated union by keeping the original
190
+ // `type` value.
191
+ const merged: MdxComponentProp = { ...p };
192
+ if (o.required !== undefined) merged.required = o.required;
193
+ if (o.label !== undefined) merged.label = o.label;
194
+ if (o.help !== undefined) merged.help = o.help;
195
+ if (o.options && merged.type === 'string') {
196
+ (merged as MdxComponentProp & { options?: ReadonlyArray<{ value: string; label: string }> }).options =
197
+ o.options;
198
+ }
199
+ return merged;
200
+ });
201
+ }
202
+
203
+ return next;
204
+ }
205
+
206
+ /** Internal accumulator. Combines interface-derived schema with
207
+ * usage-derived observations as scans arrive. */
208
+ class DescriptorBuilder {
209
+ readonly name: string;
210
+ private readonly source: string;
211
+ private readonly defaultExport: boolean;
212
+ /**
213
+ * Component flow/text kind. Mutable across `observeUsage` calls
214
+ * because mdast classifies the SAME component differently based on
215
+ * how each instance is authored in source: `<Steps>...</Steps>` on
216
+ * one line parses as `mdxJsxTextElement` (inline), but the same
217
+ * component with blank-line-separated children parses as
218
+ * `mdxJsxFlowElement` (block). The component's intrinsic nature is
219
+ * "block" — so any single flow observation must promote the kind
220
+ * from text to flow. Without this, one stray inline usage in a
221
+ * fixture poisons the registry, MDXEditor mounts the JSX as inline,
222
+ * and saves serialize block components as single-line MDX — which
223
+ * Starlight's strict-slot validators (Steps wants `<ol>`, FileTree
224
+ * wants `<ul>`) then reject at render time.
225
+ *
226
+ * Demotion in the other direction never happens: a component seen
227
+ * as flow even once is intrinsically flow-capable, regardless of
228
+ * other inline observations.
229
+ */
230
+ private kind: 'flow' | 'text';
231
+ private readonly propsFromInterface: ParsedProp[];
232
+ /** propName → set of distinct string values observed in MDX. */
233
+ private readonly observedValues = new Map<string, Set<string>>();
234
+ /** filepath → local alias used in that file (when ≠ canonical). */
235
+ private readonly aliases: Record<string, string> = {};
236
+ /** Names of props we've seen in usage but that aren't in the
237
+ * interface (or for npm components where there's no interface). */
238
+ private readonly observedPropNames = new Set<string>();
239
+ /** How many `<Foo>` usages of this component were seen across all
240
+ * MDX files. Used to pick a winner on name collisions. */
241
+ usageCount = 0;
242
+
243
+ constructor(init: {
244
+ name: string;
245
+ source: string;
246
+ defaultExport: boolean;
247
+ kind: 'flow' | 'text';
248
+ propsFromInterface?: ParsedProp[];
249
+ }) {
250
+ this.name = init.name;
251
+ this.source = init.source;
252
+ this.defaultExport = init.defaultExport;
253
+ this.kind = init.kind;
254
+ this.propsFromInterface = init.propsFromInterface ?? [];
255
+ }
256
+
257
+ observeUsage(
258
+ attrs: Record<string, string>,
259
+ filepath: string,
260
+ localName: string,
261
+ imp: MdxImport,
262
+ observedKind: 'flow' | 'text',
263
+ ): void {
264
+ this.usageCount++;
265
+ // Flow-wins promotion (see kind field doc above).
266
+ if (observedKind === 'flow') this.kind = 'flow';
267
+ if (imp.aliasedFrom && localName !== this.name) {
268
+ this.aliases[filepath] = localName;
269
+ }
270
+ for (const [propName, value] of Object.entries(attrs)) {
271
+ this.observedPropNames.add(propName);
272
+ if (!this.observedValues.has(propName)) this.observedValues.set(propName, new Set());
273
+ this.observedValues.get(propName)!.add(value);
274
+ }
275
+ }
276
+
277
+ hasInterfaceSchema(): boolean {
278
+ return this.propsFromInterface.length > 0;
279
+ }
280
+
281
+ toDescriptor(): DiscoveredComponent {
282
+ const interfacePropNames = new Set(this.propsFromInterface.map((p) => p.name));
283
+
284
+ const props: MdxComponentProp[] = [];
285
+
286
+ // Interface props first — full schema with types and (interface-
287
+ // declared) options.
288
+ for (const ip of this.propsFromInterface) {
289
+ props.push(toMdxComponentProp(ip, this.observedValues.get(ip.name)));
290
+ }
291
+
292
+ // Usage-observed props that weren't in the interface (or were
293
+ // never in any interface — npm components). Inferred as plain
294
+ // strings; we don't auto-promote observed values to a dropdown
295
+ // because there's no interface declaration telling us the prop
296
+ // is meant to be enum-like. Authors who want a curated picker
297
+ // can declare options via the sidecar `cmsConfig` override
298
+ // (see scan-overrides.ts).
299
+ for (const name of this.observedPropNames) {
300
+ if (interfacePropNames.has(name)) continue;
301
+ props.push({ name, type: 'string' });
302
+ }
303
+
304
+ // Build `defaults.attributes` for every required prop. The insert
305
+ // flow (buildInsertPayload) merges these as starter attributes when
306
+ // a fresh `<Component>` is dropped in, so components like
307
+ // `<TabItem label="...">` never get inserted as `<TabItem />` and
308
+ // immediately fail Astro's component validation at render time.
309
+ //
310
+ // Placeholder priority per prop:
311
+ // 1. First literal-union option if the prop has one (Aside.type
312
+ // → 'note'). The component's own type system says this is a
313
+ // valid value, so it's the safest choice.
314
+ // 2. First observed usage value if any author file already passes
315
+ // something (TabItem.label → 'Bun' from a Starlight fixture).
316
+ // Reuses authored content as the starter so the insert looks
317
+ // stylistically consistent with the rest of the project.
318
+ // 3. Title-cased prop name as final fallback (Card.title →
319
+ // 'Title'). Always editable — the placeholder text becomes the
320
+ // first thing the author clicks and overwrites.
321
+ const requiredAttributes: Record<string, string | number | boolean> = {};
322
+ for (const p of props) {
323
+ if (!p.required) continue;
324
+ requiredAttributes[p.name] = placeholderForProp(p, this.observedValues.get(p.name));
325
+ }
326
+
327
+ const descriptor: DiscoveredComponent = {
328
+ name: this.name,
329
+ kind: this.kind,
330
+ hasChildren: true, // default — most components accept a body slot.
331
+ props,
332
+ import: { from: this.source, ...(this.defaultExport ? { default: true } : {}) },
333
+ // Default `insert` metadata so the toolbar's "Insert component"
334
+ // dropdown surfaces every auto-discovered component. Without
335
+ // this, the toolbar's filter (`if (!d.insert) return false`)
336
+ // hides the entry and users have no way to add the block from
337
+ // the UI — only typed-out JSX would work. Hosts can still
338
+ // override label/category via sidecar `cmsConfig` on the
339
+ // component file (when that lands), but the sensible default
340
+ // is the component's own name in a single "Components" bucket.
341
+ insert: { label: this.name, category: 'Components' },
342
+ ...(Object.keys(requiredAttributes).length > 0 ? { defaults: { attributes: requiredAttributes } } : {}),
343
+ };
344
+ if (Object.keys(this.aliases).length > 0) descriptor.aliases = this.aliases;
345
+ return descriptor;
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Pick a sensible starter value for a required prop so the insert flow
351
+ * has something to put on the attribute. See the call site in
352
+ * `DescriptorBuilder.toDescriptor` for the priority rationale; this
353
+ * function just executes it.
354
+ *
355
+ * Number and boolean placeholders are intentionally trivial — `0` and
356
+ * `true` — because numeric/boolean props are rare in MDX components and
357
+ * any concrete value beats `undefined`. The interesting work is on the
358
+ * string path, where union options and observed usage give us real
359
+ * authored values to reuse.
360
+ */
361
+ function placeholderForProp(prop: MdxComponentProp, observed: Set<string> | undefined): string | number | boolean {
362
+ if (prop.type === 'number') return 0;
363
+ if (prop.type === 'boolean') return true;
364
+ // string
365
+ if (prop.options && prop.options.length > 0) return prop.options[0].value;
366
+ if (observed && observed.size > 0) {
367
+ const first = observed.values().next();
368
+ if (!first.done) return first.value;
369
+ }
370
+ // Title-case the prop name (`label` → `Label`). The author sees this
371
+ // as the placeholder text on first insert; one click selects it for
372
+ // overwrite.
373
+ return prop.name.charAt(0).toUpperCase() + prop.name.slice(1);
374
+ }
375
+
376
+ function toMdxComponentProp(parsed: ParsedProp, observed: Set<string> | undefined): MdxComponentProp {
377
+ // Only emit dropdown `options` when the interface itself declared a
378
+ // literal union (eg `type?: 'note' | 'tip' | 'caution' | 'danger'`).
379
+ // Free-form string props like `title`, `description`, `href` have no
380
+ // such union — emitting an `options` array based purely on what we
381
+ // observed in usage would lock authors to past values when the field
382
+ // is meant to accept any text. The side panel renders prop fields with
383
+ // options as `<select>` and prop fields without as `<input type=text>`,
384
+ // so this single switch decides which one shows up. Observed values
385
+ // can still enrich a real enum: when `parsed.options` IS set, append
386
+ // any usage-seen values the interface didn't list (capped at 5 distinct).
387
+ let optionStrings: string[] | undefined = parsed.options;
388
+ if (optionStrings && observed && observed.size > 0) {
389
+ const combined = new Set<string>(optionStrings);
390
+ for (const v of observed) combined.add(v);
391
+ if (combined.size <= 5) optionStrings = Array.from(combined);
392
+ }
393
+
394
+ if (parsed.type === 'number') {
395
+ return { name: parsed.name, type: 'number', required: parsed.required };
396
+ }
397
+ if (parsed.type === 'boolean') {
398
+ return { name: parsed.name, type: 'boolean', required: parsed.required };
399
+ }
400
+ // 'string' and 'expression' both render as a text input by default.
401
+ // Treat 'expression' as a free-form string for editor purposes —
402
+ // it's an escape hatch already.
403
+ return {
404
+ name: parsed.name,
405
+ type: 'string',
406
+ required: parsed.required,
407
+ ...(optionStrings && optionStrings.length > 0
408
+ ? { options: optionStrings.map((v) => ({ value: v, label: v })) }
409
+ : {}),
410
+ };
411
+ }
@@ -0,0 +1,80 @@
1
+ import type { Connect } from 'vite';
2
+ import { discoverMdxComponents, type MdxRegistryScanOptions } from './discover.js';
3
+ import type { DiscoveredComponent } from './merge-registry.js';
4
+
5
+ /**
6
+ * Vite middleware that returns the auto-discovered MDX component
7
+ * registry as JSON. The SPA fetches this on mount and seeds its
8
+ * `setMdxComponents` registry — replacing the hand-written
9
+ * `mdx-components.tsx` flow.
10
+ *
11
+ * The scan itself lives in `discoverMdxComponents` (./discover) so a
12
+ * build-time integration can run it without a dev server; this endpoint adds the
13
+ * dev-only concerns: memoization keyed on the configured inputs, plus
14
+ * invalidation by an external watcher (set up in `plugin-spa.ts`) any
15
+ * time a watched MDX or component file changes — so editing a `.mdx`
16
+ * to use a new component refreshes the registry without a manual
17
+ * reload.
18
+ *
19
+ * Errors are returned as JSON `{ error: "..." }` with 500 rather
20
+ * than thrown — the SPA falls back to host-provided descriptors when
21
+ * the endpoint fails, and a noisy stack trace would just spam the
22
+ * dev console.
23
+ */
24
+ export function createRegistryEndpoint(options: MdxRegistryScanOptions): {
25
+ handler: Connect.NextHandleFunction;
26
+ invalidate: () => void;
27
+ getAllowedSources: () => Promise<Set<string>>;
28
+ } {
29
+ let cached: Promise<DiscoveredComponent[]> | null = null;
30
+ const compute = (): Promise<DiscoveredComponent[]> => {
31
+ // Memoized per endpoint instance; the plugin's watcher calls
32
+ // `invalidate()` when an MDX/component/sidecar file changes.
33
+ if (!cached) cached = discoverMdxComponents(options);
34
+ return cached;
35
+ };
36
+
37
+ const handler: Connect.NextHandleFunction = async (_req, res, _next) => {
38
+ try {
39
+ const components = await compute();
40
+ res.statusCode = 200;
41
+ res.setHeader('content-type', 'application/json; charset=utf-8');
42
+ res.setHeader('cache-control', 'no-store');
43
+ res.end(JSON.stringify({ components }));
44
+ } catch (err) {
45
+ const message = err instanceof Error ? err.message : String(err);
46
+ console.warn('[conloca:discovery] registry endpoint failed:', message);
47
+ res.statusCode = 500;
48
+ res.setHeader('content-type', 'application/json; charset=utf-8');
49
+ res.end(JSON.stringify({ error: message }));
50
+ }
51
+ };
52
+
53
+ return {
54
+ handler,
55
+ invalidate: () => {
56
+ cached = null;
57
+ },
58
+ /**
59
+ * Set of import sources the render endpoint is allowed to load.
60
+ *
61
+ * Reuses the same memoized scan as `handler`, so the allowlist stays
62
+ * in sync with the registry the SPA sees — invalidation in one place
63
+ * invalidates both. Failing closed (returning an empty set) on scan
64
+ * error is intentional: better to refuse all renders than to fall
65
+ * back to "trust the request body".
66
+ */
67
+ getAllowedSources: async (): Promise<Set<string>> => {
68
+ try {
69
+ const components = await compute();
70
+ const sources = new Set<string>();
71
+ for (const c of components) {
72
+ if (c.import?.from) sources.add(c.import.from);
73
+ }
74
+ return sources;
75
+ } catch {
76
+ return new Set();
77
+ }
78
+ },
79
+ };
80
+ }