@conloca/astro-cms 0.1.15 → 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.
- package/README.md +259 -247
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/ts/src/cms-handler.d.ts +18 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/ts/src/cms-handler.js +245 -0
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +160 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +170 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.js +22 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts +21 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.js +39 -0
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js +25 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js +232 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/ts/src/discovery/merge-registry.js +333 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/ts/src/discovery/scan-components.d.ts +94 -0
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-components.js +397 -0
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.js +113 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.js +34 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts +4 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/ts/src/hydration.js +5 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +41 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.js +136 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-script.js +89 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-utils.js +84 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/ts/src/lib/route-utils.d.ts +61 -0
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/route-utils.js +96 -0
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/ts/src/lib/routing-config.d.ts +38 -0
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/ts/src/lib/routing-config.js +106 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts +6 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/ts/src/lib/serialize-props.js +8 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts +33 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/ts/src/lib/withHydration.js +50 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/ts/src/loader.js +118 -0
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts +61 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/ts/src/locales-helpers.js +50 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts +3 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/ts/src/mime-types.js +20 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts +8 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/ts/src/path-validation.js +13 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/ts/src/plugin-spa.d.ts +182 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/ts/src/plugin-spa.js +1165 -0
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts +13 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/ts/src/safe-json-stringify.js +7 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js +264 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +15 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +67 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/ts/src/types.d.ts +543 -0
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +74 -0
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +198 -56
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +10 -0
- package/src/cms-handler.ts +280 -0
- package/src/collections.ts +262 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +48 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/src/lib/withHydration.ts +71 -0
- package/src/loader.ts +145 -0
- package/src/locales-helpers.ts +68 -0
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1480 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +84 -0
- package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections.d.mts +0 -36
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -65
- package/dist/collections.mjs.map +0 -1
- package/dist/components.d.mts +0 -46
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -226
- package/dist/components.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -3
- package/dist/index.d.mts +0 -139
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -66
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -26
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -267
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -85
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -19
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.mjs +0 -4
- package/dist/node/index.d.mts +0 -52
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.mjs +0 -753
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
- package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
- package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
- package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
|
@@ -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
|
+
}
|