@conloca/astro-cms 0.1.16 → 0.2.1
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 +254 -301
- 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/{src → ts/src}/cms-handler.d.ts +0 -1
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/{src → ts/src}/cms-handler.js +11 -131
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +161 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +178 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
- 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/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
- 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.map +1 -0
- package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -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.map +1 -0
- package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.js +1 -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/{src → ts/src}/discovery/scan-components.d.ts +3 -7
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -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.map +1 -0
- package/dist/{src → ts/src}/hydration.js +1 -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 +13 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +45 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-utils.js +1 -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/{src → ts/src}/lib/route-utils.d.ts +26 -6
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.js +33 -15
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.js +13 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/serialize-props.js +1 -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/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
- 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/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/withHydration.js +1 -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/{src → ts/src}/loader.js +33 -4
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/{src → ts/src}/locales-helpers.js +1 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/{src → ts/src}/mime-types.js +1 -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.map +1 -0
- package/dist/{src → ts/src}/path-validation.js +1 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.js +301 -88
- 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.map +1 -0
- package/dist/{src → ts/src}/safe-json-stringify.js +1 -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/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
- 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 +16 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +117 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/{src → ts/src}/types.d.ts +26 -110
- 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 +12 -93
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +161 -73
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +11 -0
- package/src/cms-handler.ts +281 -0
- package/src/collections.ts +271 -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 +53 -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/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
- package/src/loader.ts +145 -0
- package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
- 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 +1496 -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 +134 -0
- package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections-Bd7EME4b.mjs +0 -129
- package/dist/collections-Bd7EME4b.mjs.map +0 -1
- package/dist/collections.d.mts +0 -35
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -2
- package/dist/components.d.mts +0 -41
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -223
- package/dist/components.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -2
- package/dist/index.d.mts +0 -108
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -67
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -25
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -314
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts +0 -30
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -84
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
- package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
- package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -18
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.d.ts +0 -3
- package/dist/node/content.d.ts.map +0 -1
- package/dist/node/content.js +0 -2
- package/dist/node/content.mjs +0 -2
- package/dist/node/index.d.mts +0 -200
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts +0 -4
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.mjs +0 -2513
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-BHoNpzH6.mjs +0 -72
- package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
- package/dist/src/cms-handler.d.ts.map +0 -1
- package/dist/src/collections.d.ts +0 -32
- package/dist/src/collections.d.ts.map +0 -1
- package/dist/src/collections.js +0 -50
- package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.js +0 -129
- package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
- package/dist/src/components.d.ts +0 -4
- package/dist/src/components.d.ts.map +0 -1
- package/dist/src/components.js +0 -3
- package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
- package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
- package/dist/src/discovery/merge-registry.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.d.ts +0 -42
- package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.js +0 -81
- package/dist/src/discovery/scan-components.d.ts.map +0 -1
- package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
- package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
- package/dist/src/hydration.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -25
- package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
- package/dist/src/lib/hydration-script.d.ts.map +0 -1
- package/dist/src/lib/hydration-utils.d.ts.map +0 -1
- package/dist/src/lib/page-api.d.ts +0 -77
- package/dist/src/lib/page-api.d.ts.map +0 -1
- package/dist/src/lib/page-api.js +0 -121
- package/dist/src/lib/route-utils.d.ts.map +0 -1
- package/dist/src/lib/routing-config.d.ts.map +0 -1
- package/dist/src/lib/serialize-props.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.js +0 -263
- package/dist/src/lib/withHydration.d.ts.map +0 -1
- package/dist/src/loader.d.ts +0 -14
- package/dist/src/loader.d.ts.map +0 -1
- package/dist/src/locales-helpers.d.ts.map +0 -1
- package/dist/src/mime-types.d.ts.map +0 -1
- package/dist/src/path-validation.d.ts.map +0 -1
- package/dist/src/plugin-spa.d.ts.map +0 -1
- package/dist/src/safe-json-stringify.d.ts.map +0 -1
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -1
- package/dist/types-CS9neadI.d.mts.map +0 -1
- package/dist/withHydration-C256ox_6.mjs +0 -49
- package/dist/withHydration-C256ox_6.mjs.map +0 -1
- package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
- /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
- /package/dist/{src → ts/src}/hydration.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
- /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
- /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
- /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
- /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { experimental_AstroContainer } from 'astro/container';
|
|
2
|
+
import type { Connect } from 'vite';
|
|
3
|
+
|
|
4
|
+
interface ViteModuleLoader {
|
|
5
|
+
ssrLoadModule(url: string): Promise<unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Vite middleware that renders an MDX JSX subtree to HTML on demand.
|
|
10
|
+
*
|
|
11
|
+
* Container components (CardGrid, Tabs, …) have JSX children that on
|
|
12
|
+
* the published page render as direct DOM children of the parent —
|
|
13
|
+
* positional CSS (`:nth-child` colour cycling on Card grids, CSS-grid
|
|
14
|
+
* placement) depends on that DOM shape. Per-block isolated rendering
|
|
15
|
+
* breaks both: each child gets its own wrapper, and the parent's only
|
|
16
|
+
* direct child is a slot marker.
|
|
17
|
+
*
|
|
18
|
+
* This endpoint renders a recursive tree: each node provides its
|
|
19
|
+
* component name + source + props, optionally with its own `children`
|
|
20
|
+
* tree. The server renders leaves first and assembles parents by
|
|
21
|
+
* passing rendered children HTML as the parent's default slot, so the
|
|
22
|
+
* final markup matches what Astro would emit for the same MDX
|
|
23
|
+
* source — same DOM, same CSS context.
|
|
24
|
+
*
|
|
25
|
+
* Request shape (JSON body):
|
|
26
|
+
* {
|
|
27
|
+
* tree: {
|
|
28
|
+
* component: string,
|
|
29
|
+
* source: string,
|
|
30
|
+
* defaultExport?: boolean,
|
|
31
|
+
* props?: Record<string, unknown>,
|
|
32
|
+
* slotId: string,
|
|
33
|
+
* children?: RenderTreeNode[]
|
|
34
|
+
* },
|
|
35
|
+
* documentIndex?: number // wraps top-level output to fix
|
|
36
|
+
* // sibling-position CSS for root-level
|
|
37
|
+
* // blocks (see phantom-sibling fix).
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* Legacy shape (kept for backward compatibility):
|
|
41
|
+
* { component, source, defaultExport?, props?, documentIndex? }
|
|
42
|
+
*
|
|
43
|
+
* For each node, the rendered slot content is either:
|
|
44
|
+
* - The concatenated HTML of recursively-rendered children, if any.
|
|
45
|
+
* - `<conloca-slot data-slot-id="<id>"></conloca-slot>` placeholder
|
|
46
|
+
* otherwise (the SPA portals a Lexical editor into it).
|
|
47
|
+
*
|
|
48
|
+
* Returns 200 with `Content-Type: text/html` on success; 4xx with a
|
|
49
|
+
* plain-text error otherwise.
|
|
50
|
+
*/
|
|
51
|
+
export function createRenderEndpoint(
|
|
52
|
+
server: ViteModuleLoader,
|
|
53
|
+
getAllowedSources: () => Promise<Set<string>>,
|
|
54
|
+
): Connect.NextHandleFunction {
|
|
55
|
+
let containerPromise: Promise<experimental_AstroContainer> | null = null;
|
|
56
|
+
const getContainer = () => {
|
|
57
|
+
if (!containerPromise) containerPromise = experimental_AstroContainer.create();
|
|
58
|
+
return containerPromise;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return async (req, res, _next) => {
|
|
62
|
+
if (req.method !== 'POST') {
|
|
63
|
+
res.statusCode = 405;
|
|
64
|
+
res.setHeader('content-type', 'text/plain');
|
|
65
|
+
res.end('Method not allowed');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const body = (await readJson(req)) as RequestBody;
|
|
71
|
+
|
|
72
|
+
// Normalize: accept either { tree } or the legacy flat shape.
|
|
73
|
+
const tree: RenderTreeNode = body.tree ?? {
|
|
74
|
+
component: body.component ?? '',
|
|
75
|
+
source: body.source ?? '',
|
|
76
|
+
defaultExport: body.defaultExport,
|
|
77
|
+
props: body.props,
|
|
78
|
+
slotId: 'root',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (!tree.component || !tree.source) {
|
|
82
|
+
res.statusCode = 400;
|
|
83
|
+
res.setHeader('content-type', 'text/plain');
|
|
84
|
+
res.end('Missing required fields: tree.component, tree.source');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Allowlist check. `source` flows into `server.ssrLoadModule`,
|
|
89
|
+
// which will load and execute ANY file Vite can resolve — so
|
|
90
|
+
// accepting arbitrary strings here would let any localhost POST
|
|
91
|
+
// (eg from a malicious tab visited during `bun dev`) run any
|
|
92
|
+
// JS file on the developer's machine. The registry already knows
|
|
93
|
+
// every legal component source; reject anything outside it.
|
|
94
|
+
const allowed = await getAllowedSources();
|
|
95
|
+
const disallowed = collectDisallowedSources(tree, allowed);
|
|
96
|
+
if (disallowed.length > 0) {
|
|
97
|
+
res.statusCode = 400;
|
|
98
|
+
res.setHeader('content-type', 'text/plain');
|
|
99
|
+
res.end(`source not in registry: ${disallowed.join(', ')}`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const container = await getContainer();
|
|
104
|
+
// Even the top-level render is wrapped: a hard failure here would
|
|
105
|
+
// 500 the whole response and leave the editor with no usable
|
|
106
|
+
// HTML to portal a body editor into. The stub keeps the surface
|
|
107
|
+
// editable so the author can fix the broken prop in place.
|
|
108
|
+
let rendered: string;
|
|
109
|
+
try {
|
|
110
|
+
rendered = await renderTree(tree, container, server);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.warn(`[conloca:render] <${tree.component}> failed:`, err instanceof Error ? err.message : err);
|
|
113
|
+
rendered = renderErrorStub(tree, err);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Wrap top-level output in a host-marker parent (`.sl-markdown-content`)
|
|
117
|
+
// with `(documentIndex - 1)` hidden phantom siblings so root-level
|
|
118
|
+
// components match the live page's `:nth-child(N)` position. See
|
|
119
|
+
// earlier commit for the rationale (Starlight Card cycle).
|
|
120
|
+
//
|
|
121
|
+
// Inline (text-kind) requests skip the wrapper entirely: the
|
|
122
|
+
// rendered HTML is destined for inline text flow (eg an Icon's
|
|
123
|
+
// `<svg>` inside a paragraph), where a block wrapper would force
|
|
124
|
+
// a line break and phantom siblings make no sense (the node
|
|
125
|
+
// isn't a root flow child).
|
|
126
|
+
let html: string;
|
|
127
|
+
if (body.inline) {
|
|
128
|
+
html = rendered;
|
|
129
|
+
} else {
|
|
130
|
+
const documentIndex = body.documentIndex;
|
|
131
|
+
const phantomCount = typeof documentIndex === 'number' && documentIndex > 0 ? documentIndex - 1 : 0;
|
|
132
|
+
const phantoms = phantomCount > 0 ? '<span hidden aria-hidden="true"></span>'.repeat(phantomCount) : '';
|
|
133
|
+
html = `<div class="sl-markdown-content">${phantoms}${rendered}</div>`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
res.statusCode = 200;
|
|
137
|
+
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
138
|
+
res.setHeader('cache-control', 'no-store');
|
|
139
|
+
res.end(html);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
res.statusCode = 500;
|
|
142
|
+
res.setHeader('content-type', 'text/plain');
|
|
143
|
+
res.end(`Render failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface RenderTreeNode {
|
|
149
|
+
component: string;
|
|
150
|
+
source: string;
|
|
151
|
+
defaultExport?: boolean;
|
|
152
|
+
props?: Record<string, unknown>;
|
|
153
|
+
slotId: string;
|
|
154
|
+
/** HTML-escaped text fallback for leaf body. Shown when no editor
|
|
155
|
+
* is portaled into the slot (eg inside container-rendered children
|
|
156
|
+
* before Phase 3 inline editing lands). */
|
|
157
|
+
body?: string;
|
|
158
|
+
/** Raw HTML that REPLACES the conloca-slot wrapper. Used for
|
|
159
|
+
* components whose Astro implementation validates the slot element
|
|
160
|
+
* type (Starlight's `<Steps>` requires `<ol>`, `<FileTree>` requires
|
|
161
|
+
* `<ul>`) — wrapping in `<conloca-slot>` makes the Container API
|
|
162
|
+
* render call throw. With `bodyHtml`, the validator sees the real
|
|
163
|
+
* element. No inline editing possible until per-position slot
|
|
164
|
+
* markers are added inside the rendered list. */
|
|
165
|
+
bodyHtml?: string;
|
|
166
|
+
children?: RenderTreeNode[];
|
|
167
|
+
/** Named-slot HTML keyed by slot name. Passed as additional slots
|
|
168
|
+
* to `container.renderToString`. Source MDX uses
|
|
169
|
+
* `<Fragment slot="...">…</Fragment>` to declare them. */
|
|
170
|
+
namedSlots?: Record<string, string>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface RequestBody {
|
|
174
|
+
// New shape
|
|
175
|
+
tree?: RenderTreeNode;
|
|
176
|
+
// Legacy shape (one component, no children)
|
|
177
|
+
component?: string;
|
|
178
|
+
source?: string;
|
|
179
|
+
defaultExport?: boolean;
|
|
180
|
+
props?: Record<string, unknown>;
|
|
181
|
+
// Top-level wrapping
|
|
182
|
+
documentIndex?: number;
|
|
183
|
+
/** When true, suppress the `<div class="sl-markdown-content">` wrapper
|
|
184
|
+
* and phantom siblings — the rendered HTML is destined for inline
|
|
185
|
+
* text flow (eg `<Icon>`), where a block wrapper would force a line
|
|
186
|
+
* break and phantom siblings make no sense (the node isn't a root
|
|
187
|
+
* flow child). */
|
|
188
|
+
inline?: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function renderTree(
|
|
192
|
+
node: RenderTreeNode,
|
|
193
|
+
container: experimental_AstroContainer,
|
|
194
|
+
server: ViteModuleLoader,
|
|
195
|
+
): Promise<string> {
|
|
196
|
+
const module = (await server.ssrLoadModule(node.source)) as Record<string, unknown>;
|
|
197
|
+
const exportKey = node.defaultExport ? 'default' : node.component;
|
|
198
|
+
const factory = module[exportKey];
|
|
199
|
+
|
|
200
|
+
if (typeof factory !== 'function') {
|
|
201
|
+
throw new Error(`Component '${node.component}' not found at '${node.source}' (export '${exportKey}')`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Slot content priority:
|
|
205
|
+
// 1. `children` (recursive tree) — pure-JSX container case.
|
|
206
|
+
// 2. `bodyHtml` — raw HTML emitted as-is, no
|
|
207
|
+
// conloca-slot wrapper. For
|
|
208
|
+
// components whose Astro
|
|
209
|
+
// implementation validates the
|
|
210
|
+
// slot's element type.
|
|
211
|
+
// 3. `<conloca-slot data-slot-id>{body}</conloca-slot>`
|
|
212
|
+
// — default path for everything
|
|
213
|
+
// else. The slot marker is the
|
|
214
|
+
// portal target; `body` is the
|
|
215
|
+
// static text fallback shown
|
|
216
|
+
// when no portal is mounted.
|
|
217
|
+
let slotContent: string;
|
|
218
|
+
if (node.children && node.children.length > 0) {
|
|
219
|
+
// Per-child error isolation: one broken `<Card>` no longer blanks
|
|
220
|
+
// its sibling Cards. A failure to render any specific child
|
|
221
|
+
// becomes an inline error stub (carrying that child's slot id so
|
|
222
|
+
// the body editor still portals into it), and the parent goes on
|
|
223
|
+
// to render with the stub HTML in that child's position.
|
|
224
|
+
const renderedChildren = await Promise.all(
|
|
225
|
+
node.children.map(async (child) => {
|
|
226
|
+
try {
|
|
227
|
+
return await renderTree(child, container, server);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
// Log to the dev console so the failure isn't entirely
|
|
230
|
+
// invisible — the inline stub is the author's surface, but
|
|
231
|
+
// a dev tailing the terminal still wants the stack trace.
|
|
232
|
+
console.warn(`[conloca:render] <${child.component}> failed:`, err instanceof Error ? err.message : err);
|
|
233
|
+
return renderErrorStub(child, err);
|
|
234
|
+
}
|
|
235
|
+
}),
|
|
236
|
+
);
|
|
237
|
+
slotContent = renderedChildren.join('');
|
|
238
|
+
} else if (node.bodyHtml) {
|
|
239
|
+
slotContent = node.bodyHtml;
|
|
240
|
+
} else {
|
|
241
|
+
const fallback = node.body ?? '';
|
|
242
|
+
slotContent = `<conloca-slot data-slot-id="${escapeHtml(node.slotId)}">${fallback}</conloca-slot>`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Named slots (Astro's `<Fragment slot="header">` pattern) are
|
|
246
|
+
// passed alongside `default`. The client extracts them from mdast
|
|
247
|
+
// and ships each as an HTML string keyed by slot name.
|
|
248
|
+
const slots: Record<string, string> = { default: slotContent, ...(node.namedSlots ?? {}) };
|
|
249
|
+
|
|
250
|
+
return container.renderToString(factory as Parameters<experimental_AstroContainer['renderToString']>[0], {
|
|
251
|
+
props: node.props,
|
|
252
|
+
slots,
|
|
253
|
+
// Frameworks (Starlight, others) read content via `Astro.locals.t(...)`
|
|
254
|
+
// set by their middleware. The bare container has none, so we
|
|
255
|
+
// pass a fallback: strip namespace, capitalize the leaf
|
|
256
|
+
// ('asides.note' → 'Note'). Real titles/body come from props.
|
|
257
|
+
locals: { t: defaultI18nFallback } as App.Locals,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Build a self-contained, editable error stub for one render failure.
|
|
263
|
+
*
|
|
264
|
+
* Three jobs:
|
|
265
|
+
* 1. Surface the error inline so the author sees *exactly* which
|
|
266
|
+
* component blew up and why, right where it sits in the document.
|
|
267
|
+
* No console-spelunking required.
|
|
268
|
+
* 2. Keep the slot id intact so GenericBlock's portal-discovery loop
|
|
269
|
+
* (`querySelectorAll('conloca-slot[data-slot-id]')`) still finds a
|
|
270
|
+
* mount point inside the stub. The body editor mounts as normal;
|
|
271
|
+
* the author can edit the children even though the parent
|
|
272
|
+
* component's own render failed — typically that's enough to fix
|
|
273
|
+
* whatever the validator was upset about.
|
|
274
|
+
* 3. Stay structurally innocuous. A `<div>` wrapper renders cleanly
|
|
275
|
+
* inside any parent slot that accepts arbitrary HTML, and a
|
|
276
|
+
* data-attribute on the wrapper lets host CSS style it however
|
|
277
|
+
* they like (yellow background, red border, whatever).
|
|
278
|
+
*
|
|
279
|
+
* Note: if the parent component itself has a strict-slot validator
|
|
280
|
+
* (eg `<Tabs>` rejects non-TabItem children), the stub will fail the
|
|
281
|
+
* parent's render too — but the recursion at the parent level then
|
|
282
|
+
* catches THAT failure and emits its own stub one level up. The
|
|
283
|
+
* worst case bubbles all the way to the top-level wrap in the
|
|
284
|
+
* endpoint handler. Errors never escape as 500s.
|
|
285
|
+
*/
|
|
286
|
+
function renderErrorStub(node: RenderTreeNode, err: unknown): string {
|
|
287
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
288
|
+
const name = node.component || 'unknown';
|
|
289
|
+
return (
|
|
290
|
+
`<div class="conloca-render-error" data-component="${escapeHtml(name)}" data-slot-id="${escapeHtml(node.slotId)}" role="alert">` +
|
|
291
|
+
`<div class="conloca-render-error__label"><${escapeHtml(name)}> failed to render: ${escapeHtml(message)}</div>` +
|
|
292
|
+
`<conloca-slot data-slot-id="${escapeHtml(node.slotId)}"></conloca-slot>` +
|
|
293
|
+
'</div>'
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function collectDisallowedSources(node: RenderTreeNode, allowed: Set<string>): string[] {
|
|
298
|
+
const bad: string[] = [];
|
|
299
|
+
if (!allowed.has(node.source)) bad.push(node.source);
|
|
300
|
+
if (node.children) {
|
|
301
|
+
for (const child of node.children) bad.push(...collectDisallowedSources(child, allowed));
|
|
302
|
+
}
|
|
303
|
+
return bad;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function escapeHtml(s: string): string {
|
|
307
|
+
return s.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function defaultI18nFallback(key: string): string {
|
|
311
|
+
const leaf = key.split('.').pop() ?? key;
|
|
312
|
+
return leaf.charAt(0).toUpperCase() + leaf.slice(1);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async function readJson(req: Connect.IncomingMessage): Promise<unknown> {
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
let raw = '';
|
|
318
|
+
req.setEncoding('utf8');
|
|
319
|
+
req.on('data', (chunk) => {
|
|
320
|
+
raw += chunk;
|
|
321
|
+
});
|
|
322
|
+
req.on('end', () => {
|
|
323
|
+
try {
|
|
324
|
+
resolve(raw ? JSON.parse(raw) : {});
|
|
325
|
+
} catch (err) {
|
|
326
|
+
reject(err instanceof Error ? err : new Error('Invalid JSON'));
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
req.on('error', reject);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { Connect } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite middleware that returns the concatenated CSS for a route URL.
|
|
5
|
+
*
|
|
6
|
+
* Used by the CMS editor SPA to fetch the styles that apply to the page
|
|
7
|
+
* being edited so the editor renders content with the same CSS as the
|
|
8
|
+
* published page.
|
|
9
|
+
*
|
|
10
|
+
* Mechanism (host-agnostic):
|
|
11
|
+
*
|
|
12
|
+
* 1. HTTP-fetch the live HTML at the route URL from the running dev
|
|
13
|
+
* server. This is the same HTML a browser would receive — it lists
|
|
14
|
+
* every stylesheet the page actually loads.
|
|
15
|
+
* 2. Pull the content of every `<style>...</style>` block (where dev-
|
|
16
|
+
* mode Astro inlines its component / Tailwind / user CSS).
|
|
17
|
+
* 3. Pull every `<link rel="stylesheet" href="…">` (excluding
|
|
18
|
+
* `media="print"`) and fetch each one with `?direct` so the dev
|
|
19
|
+
* server returns the raw CSS instead of the HMR JS wrapper.
|
|
20
|
+
* 4. Concatenate in source order and return as `text/css`.
|
|
21
|
+
*
|
|
22
|
+
* Why this instead of Astro's `devCSSMap`:
|
|
23
|
+
*
|
|
24
|
+
* - `devCSSMap` is an Astro-internal virtual module. It only surfaces
|
|
25
|
+
* CSS that flows through Astro's `.astro` component graph. Anything
|
|
26
|
+
* emitted by an Astro integration as a STANDALONE asset (the
|
|
27
|
+
* canonical example is expressive-code's `/_astro/ec.*.css`) sits
|
|
28
|
+
* outside that graph and never reaches the editor through devCSSMap.
|
|
29
|
+
* - Scraping the live HTML reads what the published page actually
|
|
30
|
+
* paints with — the same stylesheets the user will see in the
|
|
31
|
+
* browser. No dependency on a specific framework's internal API.
|
|
32
|
+
*
|
|
33
|
+
* Known limitations (rare on Astro sites):
|
|
34
|
+
*
|
|
35
|
+
* - CSS injected by JavaScript at runtime (`document.head.appendChild`)
|
|
36
|
+
* isn't in the initial HTML, so we don't see it. Affects view-
|
|
37
|
+
* transition handlers and third-party widget snippets.
|
|
38
|
+
* - CSS-in-JS libraries (styled-components, emotion) generate styles
|
|
39
|
+
* during client render and have the same blind spot.
|
|
40
|
+
* - Cross-origin stylesheets the dev server can't reach get logged
|
|
41
|
+
* and skipped (graceful degradation, not silent failure).
|
|
42
|
+
*/
|
|
43
|
+
export function createStylesEndpoint(): Connect.NextHandleFunction {
|
|
44
|
+
return async (req, res, _next) => {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = new URL(req.url ?? '', 'http://localhost');
|
|
47
|
+
const routeUrl = parsed.searchParams.get('url');
|
|
48
|
+
|
|
49
|
+
if (!routeUrl) {
|
|
50
|
+
res.statusCode = 400;
|
|
51
|
+
res.setHeader('content-type', 'text/plain');
|
|
52
|
+
res.end('Missing required query parameter: url');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const host = req.headers.host ?? 'localhost:4321';
|
|
57
|
+
const protocol = (req.headers['x-forwarded-proto'] as string) ?? 'http';
|
|
58
|
+
const origin = `${protocol}://${host}`;
|
|
59
|
+
const cookie = req.headers.cookie;
|
|
60
|
+
|
|
61
|
+
const liveResponse = await fetch(`${origin}${routeUrl}`, {
|
|
62
|
+
headers: cookie ? { cookie } : undefined,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Propagate upstream non-200 status (eg 404 for unknown routes)
|
|
66
|
+
// so the editor doesn't accidentally render a 404 page's CSS.
|
|
67
|
+
if (!liveResponse.ok) {
|
|
68
|
+
res.statusCode = liveResponse.status;
|
|
69
|
+
res.setHeader('content-type', 'text/plain');
|
|
70
|
+
res.end(`Upstream route returned ${liveResponse.status}: ${routeUrl}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const html = await liveResponse.text();
|
|
75
|
+
const styles = await collectStylesFromHtml(html, origin, cookie);
|
|
76
|
+
const body = styles.map((s) => `/* ${s.url} */\n${s.css}`).join('\n\n');
|
|
77
|
+
|
|
78
|
+
res.statusCode = 200;
|
|
79
|
+
res.setHeader('content-type', 'text/css; charset=utf-8');
|
|
80
|
+
// No-cache: dev HMR rewrites stylesheet contents in place; the
|
|
81
|
+
// editor refetches on page switch, so cache invalidation is the
|
|
82
|
+
// client's job, not the server's.
|
|
83
|
+
res.setHeader('cache-control', 'no-store');
|
|
84
|
+
res.end(body);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
res.statusCode = 500;
|
|
87
|
+
res.setHeader('content-type', 'text/plain');
|
|
88
|
+
res.end(`Styles discovery failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface DiscoveredStyle {
|
|
94
|
+
/** Diagnostic label — either an inline `<style>` marker or the link href. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** Raw CSS text. */
|
|
97
|
+
css: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Read every `<style>` block and `<link rel="stylesheet">` from the
|
|
102
|
+
* HTML in their original source order. Inline `<style>` blocks are
|
|
103
|
+
* captured verbatim; link tags are fetched separately (raw CSS via
|
|
104
|
+
* `?direct`). Print-media stylesheets are skipped.
|
|
105
|
+
*
|
|
106
|
+
* Exported for unit testing.
|
|
107
|
+
*/
|
|
108
|
+
export async function collectStylesFromHtml(
|
|
109
|
+
html: string,
|
|
110
|
+
origin: string,
|
|
111
|
+
cookie: string | undefined,
|
|
112
|
+
): Promise<DiscoveredStyle[]> {
|
|
113
|
+
// Strip comments first so opening-tag-shaped strings inside them
|
|
114
|
+
// don't pollute the regex walk.
|
|
115
|
+
const cleaned = html.replace(/<!--[\s\S]*?-->/g, '');
|
|
116
|
+
|
|
117
|
+
// Iterate every <style> and <link> tag in source order. The naive
|
|
118
|
+
// approach — scan once with a unified regex — is fragile for nested
|
|
119
|
+
// attribute quoting. Two passes with positions, then merge sorted by
|
|
120
|
+
// index, keeps the parsing simple AND preserves cascade order.
|
|
121
|
+
type Entry = { index: number; fetch: () => Promise<DiscoveredStyle | null> };
|
|
122
|
+
const entries: Entry[] = [];
|
|
123
|
+
|
|
124
|
+
const styleRe = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
125
|
+
for (const match of cleaned.matchAll(styleRe)) {
|
|
126
|
+
const attrs = match[1];
|
|
127
|
+
if (/media\s*=\s*["']?print/i.test(attrs)) continue;
|
|
128
|
+
const css = match[2];
|
|
129
|
+
const idAttr = attrs.match(/data-vite-dev-id="([^"]+)"/);
|
|
130
|
+
const label = idAttr ? idAttr[1] : `<style#${match.index}>`;
|
|
131
|
+
const captured = { url: label, css };
|
|
132
|
+
entries.push({ index: match.index, fetch: () => Promise.resolve(captured) });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const linkRe = /<link\b([^>]*)\/?>/gi;
|
|
136
|
+
for (const match of cleaned.matchAll(linkRe)) {
|
|
137
|
+
const attrs = match[1];
|
|
138
|
+
if (!/rel\s*=\s*["']?stylesheet["']?/i.test(attrs)) continue;
|
|
139
|
+
if (/media\s*=\s*["']?print/i.test(attrs)) continue;
|
|
140
|
+
const hrefMatch = attrs.match(/href\s*=\s*"([^"]+)"|href\s*=\s*'([^']+)'/);
|
|
141
|
+
if (!hrefMatch) continue;
|
|
142
|
+
const href = hrefMatch[1] ?? hrefMatch[2];
|
|
143
|
+
const index = match.index;
|
|
144
|
+
entries.push({ index, fetch: () => fetchStylesheet(href, origin, cookie) });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Source-order sort (style blocks and link tags interleave in HTML).
|
|
148
|
+
entries.sort((a, b) => a.index - b.index);
|
|
149
|
+
|
|
150
|
+
const results = await Promise.all(entries.map((e) => e.fetch()));
|
|
151
|
+
return results.filter((r): r is DiscoveredStyle => r !== null);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Fetch a stylesheet by href and return its raw CSS. Vite serves CSS
|
|
156
|
+
* files as JS HMR wrappers by default; `?direct` flips that to raw CSS
|
|
157
|
+
* output. Absolute URLs are fetched as-is; root-relative paths are
|
|
158
|
+
* resolved against the dev server origin so cross-page link tags work.
|
|
159
|
+
*/
|
|
160
|
+
async function fetchStylesheet(
|
|
161
|
+
href: string,
|
|
162
|
+
origin: string,
|
|
163
|
+
cookie: string | undefined,
|
|
164
|
+
): Promise<DiscoveredStyle | null> {
|
|
165
|
+
// Absolute URL (`https://…`) or relative — both need `?direct` only
|
|
166
|
+
// when targeting our own dev server. External CDNs serve raw CSS
|
|
167
|
+
// already; appending `?direct` would 404 there.
|
|
168
|
+
const isLocal = !/^https?:\/\//i.test(href) || href.startsWith(origin);
|
|
169
|
+
const target = isLocal
|
|
170
|
+
? `${origin}${href.startsWith('/') ? href : `/${href}`}${href.includes('?') ? '&direct' : '?direct'}`
|
|
171
|
+
: href;
|
|
172
|
+
try {
|
|
173
|
+
const res = await fetch(target, { headers: cookie ? { cookie } : undefined });
|
|
174
|
+
if (!res.ok) {
|
|
175
|
+
console.warn(`[conloca:css] link fetch returned ${res.status} for ${href}`);
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const css = await res.text();
|
|
179
|
+
return { url: href, css };
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.warn(`[conloca:css] link fetch failed for ${href}:`, err);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { isContentPublished, pageTimestampsOf } from '@conloca/content-api';
|
|
2
|
+
import { readSitesConfig } from '@conloca/content-api/node';
|
|
3
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
4
|
+
import type { AstroUserConfig } from 'astro';
|
|
5
|
+
import { resolveLocale } from './lib/resolve-locale.js';
|
|
6
|
+
import { resolveSiteName } from './lib/resolve-site-name.js';
|
|
7
|
+
import { normalizeRoutingConfig, resolveRouteConfig } from './lib/routing-config.js';
|
|
8
|
+
import type { ConlocaCMSOptions } from './plugin-spa.js';
|
|
9
|
+
|
|
10
|
+
/** The Astro settings that decide a page's address: pass the same values defineConfig() gets. */
|
|
11
|
+
export type AstroUrlSettings = Required<Pick<AstroUserConfig, 'site'>> &
|
|
12
|
+
Pick<AstroUserConfig, 'base' | 'trailingSlash' | 'build'>;
|
|
13
|
+
|
|
14
|
+
/** The part of @astrojs/sitemap's options that lists the CMS's pages. */
|
|
15
|
+
export interface ConlocaSitemapOptions {
|
|
16
|
+
/** Full address of every published page the CMS routes serve. */
|
|
17
|
+
customPages: string[];
|
|
18
|
+
/** Dates a CMS page by its last edit; any other entry passes through unchanged. */
|
|
19
|
+
serialize<Item extends { url: string; lastmod?: string }>(item: Item): Item;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* CMS pages rendered on demand have no file a sitemap can discover, so this
|
|
24
|
+
* hands @astrojs/sitemap the ones the routes serve right now: their full
|
|
25
|
+
* addresses and each one's last-edit date.
|
|
26
|
+
*/
|
|
27
|
+
export async function conlocaSitemapOptions(
|
|
28
|
+
cmsOptions: Pick<ConlocaCMSOptions, 'contentRoot' | 'routing' | 'layout' | 'locales'>,
|
|
29
|
+
urls: AstroUrlSettings,
|
|
30
|
+
): Promise<ConlocaSitemapOptions> {
|
|
31
|
+
// Config files are plain JavaScript, so nothing typechecks this call; without
|
|
32
|
+
// `site` the addresses below would fail with a bare "Invalid URL".
|
|
33
|
+
if (!urls.site) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"[Conloca] conlocaSitemapOptions needs Astro's `site` setting to build full addresses: pass the same settings you give defineConfig().",
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const lastEdits = new Map<string, string>();
|
|
40
|
+
const addresses = new Set<string>();
|
|
41
|
+
for (const { pathname, lastEdit } of await servedPages(cmsOptions)) {
|
|
42
|
+
const address = pageAddress(pathname, urls);
|
|
43
|
+
addresses.add(address);
|
|
44
|
+
if (lastEdit) lastEdits.set(address, lastEdit.toISOString());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const customPages = [...addresses];
|
|
48
|
+
// oxlint-disable-next-line unicorn/no-array-sort -- the target lib predates toSorted; this sorts a fresh local copy.
|
|
49
|
+
customPages.sort();
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
customPages,
|
|
53
|
+
serialize(item) {
|
|
54
|
+
const lastmod = lastEdits.get(item.url);
|
|
55
|
+
return lastmod ? { ...item, lastmod } : item;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The published pages the CMS routes serve, each with its last-edit date when that can be read. */
|
|
61
|
+
async function servedPages(
|
|
62
|
+
options: Pick<ConlocaCMSOptions, 'contentRoot' | 'routing' | 'layout' | 'locales'>,
|
|
63
|
+
): Promise<{ pathname: string; lastEdit: Date | undefined }[]> {
|
|
64
|
+
const routing = normalizeRoutingConfig(options.routing, options.layout);
|
|
65
|
+
if (!routing || routing.enabled === false) return [];
|
|
66
|
+
|
|
67
|
+
// The site and language the integration resolves its routes to.
|
|
68
|
+
const sitesConfig = await readSitesConfig(options.contentRoot);
|
|
69
|
+
const site = resolveSiteName(routing.siteName, sitesConfig.sites);
|
|
70
|
+
const locale = resolveLocale(routing.locale, options.locales?.defaultLocale, site, sitesConfig);
|
|
71
|
+
|
|
72
|
+
const collections = new Set(Object.values(routing.routes ?? {}).map((route) => resolveRouteConfig(route).collection));
|
|
73
|
+
const api = await createContentAPI({ contentRoot: options.contentRoot });
|
|
74
|
+
const pages: { pathname: string; lastEdit: Date | undefined }[] = [];
|
|
75
|
+
for (const collection of collections) {
|
|
76
|
+
for (const manifest of api.listAllContent({ collection, kind: 'page', site })) {
|
|
77
|
+
// Another renderer owns MDX pages; the CMS page route skips them.
|
|
78
|
+
if (manifest.type === 'mdx') continue;
|
|
79
|
+
const version = manifest.locales[locale];
|
|
80
|
+
if (version?.pathname !== undefined && isContentPublished(version)) {
|
|
81
|
+
pages.push({ pathname: version.pathname, lastEdit: pageTimestampsOf(version).modified });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return pages;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The base as Astro normalises it (core/config/schemas/relative.js): a leading
|
|
90
|
+
* slash, and a trailing one per trailingSlash, kept as written under 'ignore'.
|
|
91
|
+
*/
|
|
92
|
+
function astroBase({ base = '/', trailingSlash = 'ignore' }: AstroUrlSettings): string {
|
|
93
|
+
const leading = `/${base.replace(/^\/+/, '')}`;
|
|
94
|
+
if (trailingSlash === 'never') return `/${leading.replace(/^\/+|\/+$/g, '')}`;
|
|
95
|
+
if (trailingSlash === 'always') return leading.endsWith('/') ? leading : `${leading}/`;
|
|
96
|
+
return leading;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Whether Astro names a built page with a trailing slash (core/build/util.js shouldAppendForwardSlash). */
|
|
100
|
+
function endsInSlash({ trailingSlash = 'ignore', build }: AstroUrlSettings): boolean {
|
|
101
|
+
if (trailingSlash !== 'ignore') return trailingSlash === 'always';
|
|
102
|
+
return (build?.format ?? 'directory') === 'directory';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The address Astro serves a page at, so a CMS page Astro prerenders after all
|
|
107
|
+
* is the same string in the sitemap's own list and merges instead of doubling.
|
|
108
|
+
*/
|
|
109
|
+
function pageAddress(pathname: string, urls: AstroUrlSettings): string {
|
|
110
|
+
const base = astroBase(urls);
|
|
111
|
+
const page = pathname.replace(/^\/+|\/+$/g, '');
|
|
112
|
+
if (page === '') return new URL(base, urls.site).href;
|
|
113
|
+
const dir = base.endsWith('/') ? base : `${base}/`;
|
|
114
|
+
return new URL(`${dir}${page}${endsInSlash(urls) ? '/' : ''}`, urls.site).href;
|
|
115
|
+
}
|