@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,204 @@
|
|
|
1
|
+
import type { MDXHeading } from '@conloca/content-api';
|
|
2
|
+
import type { MDXFragmentEvaluationResult } from '@conloca/mdx/node';
|
|
3
|
+
import type { ComponentConfig, Config, Data, PuckComponent } from '@puckeditor/core';
|
|
4
|
+
import { Render } from '@puckeditor/core/rsc';
|
|
5
|
+
import type { ComponentType } from 'react';
|
|
6
|
+
import { hasHydratableComponents } from '../lib/hydration-utils.js';
|
|
7
|
+
import type { ContentFragmentSectionProps, DataContext } from '../types.js';
|
|
8
|
+
import { RenderWithHydration } from './RenderWithHydration.js';
|
|
9
|
+
|
|
10
|
+
interface MDXComponent {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
Component: ComponentType;
|
|
14
|
+
outline: readonly MDXHeading[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isRenderableFragment(fragment: MDXFragmentEvaluationResult | MDXComponent): fragment is MDXComponent {
|
|
18
|
+
return 'Component' in fragment && !('ok' in fragment);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface RenderWithFragmentsProps {
|
|
22
|
+
config: Config;
|
|
23
|
+
data: Data;
|
|
24
|
+
mdxComponents: MDXComponent[];
|
|
25
|
+
metadata: DataContext;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createFailedFragmentComponent(fragment: Extract<MDXFragmentEvaluationResult, { ok: false }>): ComponentType {
|
|
29
|
+
return function FailedFragmentComponent() {
|
|
30
|
+
return (
|
|
31
|
+
<div className="p-4 bg-red-50 border border-red-200 rounded text-red-600">
|
|
32
|
+
<p className="font-semibold mb-2">MDX Fragment Error</p>
|
|
33
|
+
<p className="text-sm">Fragment: {fragment.id}</p>
|
|
34
|
+
<p className="text-xs mt-2">{fragment.error.message}</p>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function resolveRenderableFragments(fragments: (MDXFragmentEvaluationResult | MDXComponent)[]): MDXComponent[] {
|
|
41
|
+
return fragments.map((fragment) => {
|
|
42
|
+
if (isRenderableFragment(fragment)) {
|
|
43
|
+
return fragment;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (fragment.ok) {
|
|
47
|
+
return fragment;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id: fragment.id,
|
|
52
|
+
title: fragment.title,
|
|
53
|
+
Component: createFailedFragmentComponent(fragment),
|
|
54
|
+
outline: [],
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Wrap a host block's own render so it receives the resolved fragment as a
|
|
61
|
+
* prop. The platform owns resolution, the site owns the markup around it: the
|
|
62
|
+
* marker attribute makes the style scanner's content-root detection exact
|
|
63
|
+
* instead of heuristic.
|
|
64
|
+
*/
|
|
65
|
+
function withResolvedFragment(
|
|
66
|
+
hostRender: PuckComponent<ContentFragmentSectionProps>,
|
|
67
|
+
fragmentComponentMap: Map<string, MDXComponent>,
|
|
68
|
+
): PuckComponent<ContentFragmentSectionProps> {
|
|
69
|
+
// Rendered, never called: a site may ship its block as memo(...) or
|
|
70
|
+
// forwardRef(...), and those are objects React renders but nothing invokes.
|
|
71
|
+
const HostBlock = hostRender;
|
|
72
|
+
|
|
73
|
+
return (props) => {
|
|
74
|
+
const selected = fragmentComponentMap.get(props.fragmentId);
|
|
75
|
+
const SelectedFragmentComponent = selected?.Component;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<HostBlock
|
|
79
|
+
{...props}
|
|
80
|
+
fragmentOutline={selected?.outline ?? []}
|
|
81
|
+
fragment={
|
|
82
|
+
SelectedFragmentComponent ? (
|
|
83
|
+
<div className="mdx-content conloca-prose" data-conloca-content-root="">
|
|
84
|
+
<SelectedFragmentComponent />
|
|
85
|
+
</div>
|
|
86
|
+
) : undefined
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Main Component ──────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Internal component for rendering Puck pages with MDX fragments.
|
|
97
|
+
*
|
|
98
|
+
* Enhances the Puck config by:
|
|
99
|
+
* 1. Registering each MDX fragment as a dynamic Puck component (`Fragment_{id}`)
|
|
100
|
+
* 2. Wrapping the host's `ContentFragmentSection` render so it receives the
|
|
101
|
+
* resolved fragment as a `fragment` prop
|
|
102
|
+
*
|
|
103
|
+
* MDX fragments are passed as React components (not HTML strings), which:
|
|
104
|
+
* - Avoids dangerouslySetInnerHTML security risks
|
|
105
|
+
* - More efficient (no HTML conversion round-trip)
|
|
106
|
+
* - Type-safe with proper React component types
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
function RenderWithFragments({ config, data, mdxComponents, metadata }: RenderWithFragmentsProps) {
|
|
111
|
+
// Build enhanced config with MDX fragments
|
|
112
|
+
const fragmentComponents: Record<string, ComponentConfig> = {};
|
|
113
|
+
const fragmentCategoryList: string[] = [];
|
|
114
|
+
const fragmentComponentMap = new Map(mdxComponents.map((fragment) => [fragment.id, fragment]));
|
|
115
|
+
|
|
116
|
+
// Create component configs for each fragment
|
|
117
|
+
mdxComponents.forEach((fragment) => {
|
|
118
|
+
const componentKey = `Fragment_${fragment.id}`;
|
|
119
|
+
|
|
120
|
+
// Capture component in closure - Puck doesn't persist defaultProps reliably
|
|
121
|
+
const FragmentComponent = fragment.Component;
|
|
122
|
+
|
|
123
|
+
fragmentComponents[componentKey] = {
|
|
124
|
+
label: fragment.title,
|
|
125
|
+
fields: {},
|
|
126
|
+
defaultProps: {},
|
|
127
|
+
render: () => (
|
|
128
|
+
<div className="mdx-content conloca-prose" data-conloca-content-root="">
|
|
129
|
+
<FragmentComponent />
|
|
130
|
+
</div>
|
|
131
|
+
),
|
|
132
|
+
};
|
|
133
|
+
fragmentCategoryList.push(componentKey);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Merge with existing config
|
|
137
|
+
const existingCategories = config.categories || {};
|
|
138
|
+
const existingComponents = config.components || {};
|
|
139
|
+
const contentFragmentSection = existingComponents.ContentFragmentSection as
|
|
140
|
+
| ComponentConfig<ContentFragmentSectionProps>
|
|
141
|
+
| undefined;
|
|
142
|
+
|
|
143
|
+
const enhancedContentFragmentSection = contentFragmentSection
|
|
144
|
+
? {
|
|
145
|
+
...contentFragmentSection,
|
|
146
|
+
render: withResolvedFragment(contentFragmentSection.render, fragmentComponentMap),
|
|
147
|
+
}
|
|
148
|
+
: undefined;
|
|
149
|
+
|
|
150
|
+
// Merge fragment components with existing config components
|
|
151
|
+
const mergedComponents = {
|
|
152
|
+
...existingComponents,
|
|
153
|
+
...(enhancedContentFragmentSection && { ContentFragmentSection: enhancedContentFragmentSection }),
|
|
154
|
+
...fragmentComponents,
|
|
155
|
+
} as Config['components'];
|
|
156
|
+
|
|
157
|
+
const enhancedConfig: Config = {
|
|
158
|
+
...config,
|
|
159
|
+
categories: {
|
|
160
|
+
...existingCategories,
|
|
161
|
+
fragments: {
|
|
162
|
+
title: 'Content Fragments',
|
|
163
|
+
components: fragmentCategoryList,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
components: mergedComponents,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Check if page has hydratable components
|
|
170
|
+
const needsHydration = hasHydratableComponents(data, enhancedConfig);
|
|
171
|
+
|
|
172
|
+
if (needsHydration) {
|
|
173
|
+
return <RenderWithHydration config={enhancedConfig} data={data} metadata={metadata} />;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return <Render config={enhancedConfig} data={data} metadata={metadata} />;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Factory function to create a PageRenderer with MDX components baked in via closure.
|
|
181
|
+
*
|
|
182
|
+
* This approach avoids dangerouslySetInnerHTML by keeping React components as components
|
|
183
|
+
* throughout the rendering pipeline. Components are captured in the closure and don't
|
|
184
|
+
* need to be passed as props (which Astro can't serialize).
|
|
185
|
+
*
|
|
186
|
+
* @param config - The Puck configuration with component definitions
|
|
187
|
+
* @param data - Puck page data containing component tree
|
|
188
|
+
* @param mdxComponents - Array of evaluated MDX fragment results
|
|
189
|
+
* @param metadata - The page's data context, handed to every block's render as `puck.metadata`
|
|
190
|
+
* @returns A PageRenderer component with no props needed (components in closure)
|
|
191
|
+
*/
|
|
192
|
+
export function createPageRendererWithFragments(
|
|
193
|
+
config: Config,
|
|
194
|
+
data: Data,
|
|
195
|
+
mdxComponents: (MDXFragmentEvaluationResult | MDXComponent)[],
|
|
196
|
+
metadata: DataContext,
|
|
197
|
+
): ComponentType {
|
|
198
|
+
const renderableFragments = resolveRenderableFragments(mdxComponents);
|
|
199
|
+
|
|
200
|
+
// Capture components in closure - no need to pass as props
|
|
201
|
+
return function PageRendererWithFragments() {
|
|
202
|
+
return <RenderWithFragments config={config} data={data} mdxComponents={renderableFragments} metadata={metadata} />;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
2
|
+
import { Render } from '@puckeditor/core/rsc';
|
|
3
|
+
import { isHydratable } from '../lib/hydration-utils.js';
|
|
4
|
+
import type { DataContext } from '../types.js';
|
|
5
|
+
import { HydrationWrapper } from './HydrationWrapper.js';
|
|
6
|
+
|
|
7
|
+
interface RenderWithHydrationProps {
|
|
8
|
+
config: Config;
|
|
9
|
+
data: Data;
|
|
10
|
+
metadata: DataContext;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrapper around Puck's Render component that adds hydration support.
|
|
15
|
+
*
|
|
16
|
+
* For each component with a hydration strategy configured, wraps the
|
|
17
|
+
* component's render output with HydrationWrapper to add data-hydrate
|
|
18
|
+
* attributes for browser-side hydration.
|
|
19
|
+
*
|
|
20
|
+
* Non-hydratable components render without any wrapper overhead. Every block
|
|
21
|
+
* renders with the page's data context as `puck.metadata` on the server; a
|
|
22
|
+
* hydrated block does not get `puck` in the browser.
|
|
23
|
+
*/
|
|
24
|
+
export function RenderWithHydration({ config, data, metadata }: RenderWithHydrationProps) {
|
|
25
|
+
// Create wrapped config with hydration-aware render functions
|
|
26
|
+
const wrappedConfig: Config = {
|
|
27
|
+
...config,
|
|
28
|
+
components: Object.fromEntries(
|
|
29
|
+
Object.entries(config.components).map(([name, componentConfig]) => {
|
|
30
|
+
const strategy = isHydratable(name, config);
|
|
31
|
+
|
|
32
|
+
if (strategy === 'none') {
|
|
33
|
+
// No wrapping needed - component stays static
|
|
34
|
+
return [name, componentConfig];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Wrap the render function so its output becomes HydrationWrapper children
|
|
38
|
+
const originalRender = componentConfig.render;
|
|
39
|
+
return [
|
|
40
|
+
name,
|
|
41
|
+
{
|
|
42
|
+
...componentConfig,
|
|
43
|
+
render: (props) => (
|
|
44
|
+
<HydrationWrapper componentName={name} strategy={strategy} props={props}>
|
|
45
|
+
{originalRender(props)}
|
|
46
|
+
</HydrationWrapper>
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return <Render config={wrappedConfig} data={data} metadata={metadata} />;
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the frontmatter (the `---`-fenced TypeScript block) from
|
|
3
|
+
* an `.astro` source file. Returns the inner text, or `null` if no
|
|
4
|
+
* frontmatter is present (a valid Astro file shape — props-less
|
|
5
|
+
* components without `<script>` of any kind).
|
|
6
|
+
*
|
|
7
|
+
* Astro's official compiler (`@astrojs/compiler`) exposes a full
|
|
8
|
+
* parser, but for the props-extraction use case all we need is the
|
|
9
|
+
* text between the opening and closing fences. A regex is sufficient
|
|
10
|
+
* and keeps this synchronous (no WASM init cost, no async).
|
|
11
|
+
*
|
|
12
|
+
* The fence rule is simple: the file must start with `---\n` and
|
|
13
|
+
* close with `\n---` followed by either a newline or end-of-file.
|
|
14
|
+
* Whitespace before the opening fence is rejected — Astro itself
|
|
15
|
+
* requires the fence at column 0.
|
|
16
|
+
*/
|
|
17
|
+
export function extractAstroFrontmatter(content: string): string | null {
|
|
18
|
+
// `^---\r?\n` opens; `\r?\n---\s*(?:\r?\n|$)` closes.
|
|
19
|
+
// Capturing the inner content lazily so a body containing `---`
|
|
20
|
+
// (eg a horizontal rule string inside a default-prop) doesn't
|
|
21
|
+
// truncate. Astro itself uses the same "first ---/--- pair" rule.
|
|
22
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
|
|
23
|
+
return match ? match[1] : null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
import { type DiscoveredComponent, mergeRegistry } from './merge-registry.js';
|
|
3
|
+
import { scanExternalComponents, scanLocalComponents } from './scan-components.js';
|
|
4
|
+
import { scanMdxFiles } from './scan-mdx.js';
|
|
5
|
+
import { loadCmsOverrides } from './scan-overrides.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Inputs for the MDX component registry scan. Resolved ONCE by the
|
|
9
|
+
* integration so the dev endpoint and a build-time integration cannot drift.
|
|
10
|
+
*/
|
|
11
|
+
export interface MdxRegistryScanOptions {
|
|
12
|
+
/** Absolute or project-relative path to the MDX content directory. */
|
|
13
|
+
contentRoot: string;
|
|
14
|
+
/** Project-relative paths to scan for local components. */
|
|
15
|
+
componentFolders: string[];
|
|
16
|
+
/** Project-relative folder of `*.cms.json` sidecar override files,
|
|
17
|
+
* keyed by component basename (`Card.cms.json` → overrides `Card`).
|
|
18
|
+
* Defaults to `src/cms-overrides` — hosts can omit it when they
|
|
19
|
+
* don't need any overrides yet. */
|
|
20
|
+
overridesFolder?: string;
|
|
21
|
+
/** Base for resolving the paths above. Defaults to `process.cwd()`. */
|
|
22
|
+
projectRoot?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The three-stage auto-discovery pipeline behind the editor's MDX
|
|
27
|
+
* component registry (scan-mdx + scan-components + merge-registry).
|
|
28
|
+
*
|
|
29
|
+
* Free of any dev-server dependency on purpose: dev serves the result
|
|
30
|
+
* from `/__cms/api/registry`, and a build-time caller, where no dev server
|
|
31
|
+
* runs, calls this same function. One scan implementation is the only way
|
|
32
|
+
* both can agree.
|
|
33
|
+
*/
|
|
34
|
+
export async function discoverMdxComponents(options: MdxRegistryScanOptions): Promise<DiscoveredComponent[]> {
|
|
35
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
36
|
+
const contentRoot = resolve(projectRoot, options.contentRoot);
|
|
37
|
+
// MDX scan first — its results feed BOTH the merge step AND the
|
|
38
|
+
// external-package scan (which uses the imports to know what
|
|
39
|
+
// packages to walk into).
|
|
40
|
+
const mdxScans = await scanMdxFiles(contentRoot);
|
|
41
|
+
const overridesFolder = options.overridesFolder ?? 'src/cms-overrides';
|
|
42
|
+
const [localComponents, externalComponents, overrides] = await Promise.all([
|
|
43
|
+
scanLocalComponents(options.componentFolders, projectRoot),
|
|
44
|
+
scanExternalComponents(mdxScans, projectRoot),
|
|
45
|
+
loadCmsOverrides(overridesFolder, projectRoot),
|
|
46
|
+
]);
|
|
47
|
+
// External (npm) and local components live in disjoint key
|
|
48
|
+
// spaces — external source strings are npm specifiers, local
|
|
49
|
+
// source strings are absolute paths — so they never collide on
|
|
50
|
+
// the `${source}::${name}` dedup key. The interesting collision
|
|
51
|
+
// case is two sources sharing a `name`; that pass is resolved
|
|
52
|
+
// inside `mergeRegistry` by usage count (see rule 6 in its top
|
|
53
|
+
// doc). Host sidecar overrides apply last as the highest-priority
|
|
54
|
+
// layer (see `applyOverride` in merge-registry).
|
|
55
|
+
return mergeRegistry(mdxScans, [...externalComponents, ...localComponents], overrides);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Rewrites absolute local-component import specifiers to project-relative
|
|
60
|
+
* ones (`/src/components/mdx/Aside.tsx`), and `aliases` keys — absolute MDX
|
|
61
|
+
* file paths of the scanning machine — the same way.
|
|
62
|
+
*
|
|
63
|
+
* The scanner records a local component's `import.from` as its absolute file
|
|
64
|
+
* path, which is what the dev render endpoint hands to `ssrLoadModule`. That
|
|
65
|
+
* path is machine-specific: descriptors that outlive the scan (saved with the
|
|
66
|
+
* site's MDX files, say) would carry the scanning machine's prefix into the
|
|
67
|
+
* repository and break the next build elsewhere. Callers whose descriptors
|
|
68
|
+
* outlive the scan apply it; the dev endpoint keeps the paths its loader
|
|
69
|
+
* expects. npm specifiers and paths outside the project are left untouched.
|
|
70
|
+
*/
|
|
71
|
+
export function toPortableImports(components: DiscoveredComponent[], projectRoot: string): DiscoveredComponent[] {
|
|
72
|
+
return components.map((component) => {
|
|
73
|
+
let next = component;
|
|
74
|
+
const imported = component.import;
|
|
75
|
+
const portableFrom = imported === undefined ? undefined : toProjectRelative(imported.from, projectRoot);
|
|
76
|
+
if (imported && portableFrom !== undefined) {
|
|
77
|
+
next = { ...next, import: { ...imported, from: portableFrom } };
|
|
78
|
+
}
|
|
79
|
+
if (component.aliases) {
|
|
80
|
+
next = {
|
|
81
|
+
...next,
|
|
82
|
+
aliases: Object.fromEntries(
|
|
83
|
+
Object.entries(component.aliases).map(([file, alias]) => [
|
|
84
|
+
toProjectRelative(file, projectRoot) ?? file,
|
|
85
|
+
alias,
|
|
86
|
+
]),
|
|
87
|
+
),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return next;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* One absolute path → project-relative `/src/...` specifier, or `undefined`
|
|
96
|
+
* when the path is not absolute or falls outside the project. The
|
|
97
|
+
* outside-project guard matches `..` segments only (a directory literally
|
|
98
|
+
* named `..foo` is INSIDE the project and must rewrite); `isAbsolute` catches
|
|
99
|
+
* the Windows different-drive case, where `relative()` returns an absolute
|
|
100
|
+
* path instead of `..` hops.
|
|
101
|
+
*/
|
|
102
|
+
function toProjectRelative(path: string, projectRoot: string): string | undefined {
|
|
103
|
+
if (!isAbsolute(path)) return undefined;
|
|
104
|
+
const relativePath = relative(projectRoot, path);
|
|
105
|
+
if (relativePath === '' || relativePath === '..' || relativePath.startsWith(`..${sep}`) || isAbsolute(relativePath))
|
|
106
|
+
return undefined;
|
|
107
|
+
return `/${relativePath.replace(/\\/g, '/')}`;
|
|
108
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript-aware extraction of a component's `Props` interface,
|
|
3
|
+
* replacing the regex-based path in `scan-components.ts`. Uses
|
|
4
|
+
* `ts-morph` (a thin wrapper over the TypeScript compiler API) so
|
|
5
|
+
* derived types — `(typeof asideVariants)[number]`, mapped types,
|
|
6
|
+
* imported aliases, conditional types — resolve to their concrete
|
|
7
|
+
* literal-union values. The regex scanner couldn't follow any
|
|
8
|
+
* indirection and silently dropped options for those props (Aside's
|
|
9
|
+
* `type` being the canonical example).
|
|
10
|
+
*
|
|
11
|
+
* The output shape is identical to the regex path (`ParsedProp[]`)
|
|
12
|
+
* so the rest of the discovery pipeline doesn't change.
|
|
13
|
+
*
|
|
14
|
+
* Astro files are handled by extracting the frontmatter block and
|
|
15
|
+
* feeding it to the Project as a virtual `.ts` source — see
|
|
16
|
+
* `extractAstroFrontmatter` in `astro-frontmatter.ts`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
type InterfaceDeclaration,
|
|
21
|
+
ModuleKind,
|
|
22
|
+
ModuleResolutionKind,
|
|
23
|
+
Project,
|
|
24
|
+
type PropertySignature,
|
|
25
|
+
ScriptTarget,
|
|
26
|
+
type SourceFile,
|
|
27
|
+
type Type,
|
|
28
|
+
type TypeAliasDeclaration,
|
|
29
|
+
type TypeLiteralNode,
|
|
30
|
+
} from 'ts-morph';
|
|
31
|
+
import type { ParsedProp } from './scan-components.js';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One Project per scan run, reused across `extractPropsViaTs` calls
|
|
35
|
+
* within the same scan. Building the Project loads `lib.dom.d.ts`
|
|
36
|
+
* etc. which dominates cold-start cost (~500ms-2s); sharing across
|
|
37
|
+
* files in a scan amortises that. A fresh Project is built per scan
|
|
38
|
+
* run so file changes are picked up — ts-morph's `addSourceFile`
|
|
39
|
+
* caches by path and wouldn't see external edits otherwise.
|
|
40
|
+
*/
|
|
41
|
+
export function createScanProject(tsConfigFilePath?: string): Project {
|
|
42
|
+
// When the host has a tsconfig, use it — that's how cross-file
|
|
43
|
+
// `typeof` refs and path mappings (`@/foo`) resolve. Without one,
|
|
44
|
+
// fall back to permissive defaults that still handle the common
|
|
45
|
+
// shapes (literal unions inside a single file, simple imports).
|
|
46
|
+
if (tsConfigFilePath) {
|
|
47
|
+
try {
|
|
48
|
+
return new Project({
|
|
49
|
+
tsConfigFilePath,
|
|
50
|
+
// Add files explicitly per scan; don't auto-load every file
|
|
51
|
+
// referenced by tsconfig.include — that would slow scans on
|
|
52
|
+
// big projects.
|
|
53
|
+
skipAddingFilesFromTsConfig: true,
|
|
54
|
+
});
|
|
55
|
+
} catch {
|
|
56
|
+
// tsconfig parse failure — fall through to defaults
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return new Project({
|
|
60
|
+
compilerOptions: {
|
|
61
|
+
target: ScriptTarget.ES2022,
|
|
62
|
+
module: ModuleKind.ESNext,
|
|
63
|
+
moduleResolution: ModuleResolutionKind.Bundler,
|
|
64
|
+
allowJs: true,
|
|
65
|
+
esModuleInterop: true,
|
|
66
|
+
skipLibCheck: true,
|
|
67
|
+
strict: false,
|
|
68
|
+
},
|
|
69
|
+
skipAddingFilesFromTsConfig: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Extract the Props interface from a source string and return the
|
|
75
|
+
* parsed prop list. `filepath` is used as the virtual file's path
|
|
76
|
+
* inside the Project so error messages and source-map debugging
|
|
77
|
+
* point back at the right file; the actual content comes from
|
|
78
|
+
* `sourceText`. `.astro` callers pass the extracted frontmatter as
|
|
79
|
+
* `sourceText` and `${filepath}.virtual.ts` as `filepath`.
|
|
80
|
+
*
|
|
81
|
+
* Returns `[]` when no Props interface is found — same contract as
|
|
82
|
+
* the regex path so callers don't need a special-case branch.
|
|
83
|
+
*/
|
|
84
|
+
export function extractPropsViaTs(
|
|
85
|
+
project: Project,
|
|
86
|
+
filepath: string,
|
|
87
|
+
sourceText: string,
|
|
88
|
+
componentName?: string,
|
|
89
|
+
): ParsedProp[] {
|
|
90
|
+
let sf: SourceFile;
|
|
91
|
+
try {
|
|
92
|
+
sf = project.createSourceFile(filepath, sourceText, { overwrite: true });
|
|
93
|
+
} catch (err) {
|
|
94
|
+
// Source parse failure — eg the .astro frontmatter contained
|
|
95
|
+
// syntax the TS compiler rejected (rare; most front-matter is
|
|
96
|
+
// valid TS). Return empty so the merge layer can still surface
|
|
97
|
+
// the component, just without prop schema.
|
|
98
|
+
console.warn(`[conloca:ts-morph] parse failed for ${filepath}:`, err instanceof Error ? err.message : err);
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Try `${ComponentName}Props` first (matches the convention
|
|
103
|
+
// `interface CardProps {...}` used by some libraries), then the
|
|
104
|
+
// bare `Props` name (Astro components and most React components).
|
|
105
|
+
// Try interface declarations first, then type aliases — same
|
|
106
|
+
// priority the regex scanner used.
|
|
107
|
+
const candidates: string[] = [];
|
|
108
|
+
if (componentName) candidates.push(`${componentName}Props`);
|
|
109
|
+
candidates.push('Props');
|
|
110
|
+
|
|
111
|
+
let propertySignatures: PropertySignature[] = [];
|
|
112
|
+
for (const name of candidates) {
|
|
113
|
+
const iface = sf.getInterface(name);
|
|
114
|
+
if (iface) {
|
|
115
|
+
propertySignatures = collectLocalProperties(iface);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const alias = sf.getTypeAlias(name);
|
|
119
|
+
if (alias) {
|
|
120
|
+
propertySignatures = collectAliasProperties(alias);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (propertySignatures.length === 0) {
|
|
125
|
+
project.removeSourceFile(sf);
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const props: ParsedProp[] = [];
|
|
130
|
+
for (const prop of propertySignatures) {
|
|
131
|
+
const name = prop.getName();
|
|
132
|
+
// `getType()` on the PropertySignature node resolves at the
|
|
133
|
+
// declaration site — this is where `(typeof X)[number]` collapses
|
|
134
|
+
// to its literal union, generics expand, conditional types branch.
|
|
135
|
+
const type = prop.getType();
|
|
136
|
+
const required = !prop.hasQuestionToken();
|
|
137
|
+
props.push(parseType(name, type, required));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Clean up the virtual source file so successive calls in the
|
|
141
|
+
// same scan don't accumulate sources and bloat memory.
|
|
142
|
+
project.removeSourceFile(sf);
|
|
143
|
+
|
|
144
|
+
return props;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get ONLY the locally-declared properties on an interface, NOT
|
|
149
|
+
* properties inherited from `extends` clauses. This is the key choice
|
|
150
|
+
* that keeps the side panel sane for components like Starlight's
|
|
151
|
+
* `LinkCard` which declares `extends Omit<HTMLAttributes<'a'>, 'title'>`:
|
|
152
|
+
* the type-level `Type.getProperties()` would include every HTML
|
|
153
|
+
* attribute (~200 entries — `accesskey`, `aria-*`, `on*`, etc), making
|
|
154
|
+
* the panel useless. The declaration-level `iface.getProperties()`
|
|
155
|
+
* returns just the props the author explicitly wrote inside the
|
|
156
|
+
* braces, which is the editor's intent.
|
|
157
|
+
*
|
|
158
|
+
* Trade-off: a property the author "overrides" via re-declaration
|
|
159
|
+
* (eg LinkCard's local `title: string` overriding the inherited
|
|
160
|
+
* `title?: string`) appears — good. A property the author NEVER
|
|
161
|
+
* declared locally but the inherited interface defines (eg `href`
|
|
162
|
+
* inherited from HTMLAttributes) does NOT appear — also good, the
|
|
163
|
+
* panel stays focused on what the author wanted to expose. Hosts
|
|
164
|
+
* who want a specific inherited prop surfaced can re-declare it
|
|
165
|
+
* locally or use the sidecar `cmsConfig.props` override.
|
|
166
|
+
*/
|
|
167
|
+
function collectLocalProperties(iface: InterfaceDeclaration): PropertySignature[] {
|
|
168
|
+
// PropertySignature[] — only what's between this interface's own
|
|
169
|
+
// braces. Inherited properties from `extends` aren't included.
|
|
170
|
+
return iface.getProperties();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Type-alias variant. For `type Props = { ... }`, the declaration
|
|
175
|
+
* node is a TypeLiteralNode and we read its own member list. For
|
|
176
|
+
* intersections (`type Props = A & { ... }`) or imported aliases,
|
|
177
|
+
* we get an empty list rather than walking into the constituent
|
|
178
|
+
* types — same author-intent rationale as the interface case.
|
|
179
|
+
*/
|
|
180
|
+
function collectAliasProperties(alias: TypeAliasDeclaration): PropertySignature[] {
|
|
181
|
+
const node = alias.getTypeNode();
|
|
182
|
+
// ts-morph's `asKind(SyntaxKind.TypeLiteral)` would narrow this
|
|
183
|
+
// cleanly, but we only need the duck-typed check that the node
|
|
184
|
+
// exposes `getMembers()`. A type literal does; an intersection or
|
|
185
|
+
// imported reference doesn't — those return an empty list and the
|
|
186
|
+
// alias is skipped by the caller.
|
|
187
|
+
const members = (node as TypeLiteralNode | undefined)?.getMembers?.();
|
|
188
|
+
if (!members) return [];
|
|
189
|
+
return members.filter((m): m is PropertySignature => m.getKindName() === 'PropertySignature');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Map a resolved `Type` to a `ParsedProp`. Mirrors the kind of
|
|
194
|
+
* branching the old regex did, but on real type information.
|
|
195
|
+
*/
|
|
196
|
+
function parseType(name: string, type: Type, required: boolean): ParsedProp {
|
|
197
|
+
if (type.isString()) return { name, type: 'string', required };
|
|
198
|
+
if (type.isNumber()) return { name, type: 'number', required };
|
|
199
|
+
if (type.isBoolean()) return { name, type: 'boolean', required };
|
|
200
|
+
|
|
201
|
+
if (type.isUnion()) {
|
|
202
|
+
const members = type.getUnionTypes();
|
|
203
|
+
// Filter out `undefined` (added by the compiler for `?` props
|
|
204
|
+
// under strictNullChecks). The remaining members tell us what
|
|
205
|
+
// the prop actually accepts.
|
|
206
|
+
const nonUndefined = members.filter((m) => !m.isUndefined());
|
|
207
|
+
|
|
208
|
+
// All-boolean-literal union (`true | false`, or even `true` alone,
|
|
209
|
+
// or `false` alone) → boolean. Under strict mode, `boolean` is
|
|
210
|
+
// canonicalised by the checker into the union `true | false`, so
|
|
211
|
+
// `isBoolean()` on the original type returns false — we have to
|
|
212
|
+
// detect the expanded form. This is the path that catches eg
|
|
213
|
+
// CardGrid's `stagger?: boolean` (resolved as `true | false |
|
|
214
|
+
// undefined`).
|
|
215
|
+
if (nonUndefined.length > 0 && nonUndefined.every((m) => m.isBooleanLiteral() || m.isBoolean())) {
|
|
216
|
+
return { name, type: 'boolean', required };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// String-literal union → string prop with `options`. Even when
|
|
220
|
+
// the union also includes a non-literal `string`, surface the
|
|
221
|
+
// literals as picker suggestions.
|
|
222
|
+
const stringLiterals = nonUndefined
|
|
223
|
+
.filter((m) => m.isStringLiteral())
|
|
224
|
+
.map((m) => m.getLiteralValue())
|
|
225
|
+
.filter((v): v is string => typeof v === 'string');
|
|
226
|
+
if (stringLiterals.length > 0) {
|
|
227
|
+
return { name, type: 'string', required, options: stringLiterals };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Single non-undefined primitive after stripping the optional
|
|
231
|
+
// undefined — eg `string | undefined` collapses to `string`.
|
|
232
|
+
if (nonUndefined.length === 1) {
|
|
233
|
+
const only = nonUndefined[0];
|
|
234
|
+
if (only.isString()) return { name, type: 'string', required };
|
|
235
|
+
if (only.isNumber()) return { name, type: 'number', required };
|
|
236
|
+
if (only.isBoolean()) return { name, type: 'boolean', required };
|
|
237
|
+
if (only.isStringLiteral()) {
|
|
238
|
+
const v = only.getLiteralValue();
|
|
239
|
+
return { name, type: 'string', required, options: typeof v === 'string' ? [v] : undefined };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (type.isStringLiteral()) {
|
|
245
|
+
const v = type.getLiteralValue();
|
|
246
|
+
return { name, type: 'string', required, options: typeof v === 'string' ? [v] : undefined };
|
|
247
|
+
}
|
|
248
|
+
if (type.isBooleanLiteral()) {
|
|
249
|
+
return { name, type: 'boolean', required };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Anything else — function types, object types, branded types,
|
|
253
|
+
// arrays, Records — render as a free-form expression input.
|
|
254
|
+
return { name, type: 'expression', required };
|
|
255
|
+
}
|