@conloca/astro-cms 0.1.16 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -298
- 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 +9 -130
- 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/{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 +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.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 +280 -87
- 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 +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/{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 +159 -73
- 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/{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 +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-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,262 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content';
|
|
2
|
+
import type { DataSchemas, PageSchemas } from '@conloca/cms-spa/page-schema-define';
|
|
3
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
4
|
+
import { dataMetaSchema, fragmentMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ALL_FRAGMENTS_COLLECTION } from './handlers/page-render-core.js';
|
|
7
|
+
import { declareConlocaCollection, withDeclarationCheck } from './internal/declared-collections.js';
|
|
8
|
+
import { buildPageCollectionSchema, hostFieldsFromPageSchemas } from './internal/page-collection-schema.js';
|
|
9
|
+
import { conlocaLoader } from './loader.js';
|
|
10
|
+
|
|
11
|
+
export { ALL_FRAGMENTS_COLLECTION };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for createConlocaCollections().
|
|
15
|
+
*/
|
|
16
|
+
export interface CreateConlocaCollectionsOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Path to content root directory. Defaults to the contentRoot configured on
|
|
19
|
+
* conlocaCMS() in astro.config, falling back to './content'.
|
|
20
|
+
*/
|
|
21
|
+
contentRoot?: string;
|
|
22
|
+
/** Site name for multi-site setups. @default 'default' */
|
|
23
|
+
site?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The same `pageSchemas` object the editor loads. Host meta fields are
|
|
26
|
+
* validated on every page collection at build time (made optional, because
|
|
27
|
+
* the editor scopes a descriptor to a prefix while Astro validates the
|
|
28
|
+
* whole pile). Pass the object itself — not a hand-copied field list — so
|
|
29
|
+
* the form and the build cannot drift. Listing types come from augmenting
|
|
30
|
+
* `HostPageMeta`, not from Astro `entry.data`.
|
|
31
|
+
* The {@link pageSchemasOf} read-back is a {@link conlocaPages} contract
|
|
32
|
+
* and does not cover this deprecated wrapper.
|
|
33
|
+
*/
|
|
34
|
+
pageSchemas?: PageSchemas;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Return type of createConlocaCollections().
|
|
39
|
+
*/
|
|
40
|
+
export interface ConlocaCollectionsResult {
|
|
41
|
+
/** Astro Content Collections definitions - export this as `collections` */
|
|
42
|
+
collections: Record<string, ReturnType<typeof defineCollection>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Declare collections explicitly with {@link conlocaPages},
|
|
47
|
+
* {@link conlocaData} and {@link conlocaFragments} — they keep the entry
|
|
48
|
+
* types Astro's generated `getCollection` needs, and undeclared content
|
|
49
|
+
* fails the build instead of silently not building. This wrapper still
|
|
50
|
+
* works but returns untyped entries.
|
|
51
|
+
*
|
|
52
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
53
|
+
* Uses content-api to find collections that have content.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // src/content.config.ts
|
|
58
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
59
|
+
* import { pageSchemas } from './page-schemas';
|
|
60
|
+
*
|
|
61
|
+
* export const { collections } = await createConlocaCollections({ pageSchemas });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export async function createConlocaCollections(
|
|
65
|
+
options: CreateConlocaCollectionsOptions = {},
|
|
66
|
+
): Promise<ConlocaCollectionsResult> {
|
|
67
|
+
// Default comes from the conlocaCMS integration, which publishes its raw
|
|
68
|
+
// contentRoot option to process.env before the content config loads — one
|
|
69
|
+
// contentRoot in astro.config covers both. (A missing directory is the
|
|
70
|
+
// integration's job to report; it warns in dev and fails the build.)
|
|
71
|
+
const { contentRoot = process.env.CONLOCA_CONTENT_ROOT ?? './content', site = 'default', pageSchemas } = options;
|
|
72
|
+
|
|
73
|
+
const api = await createContentAPI({ contentRoot });
|
|
74
|
+
const collections: Record<string, ReturnType<typeof defineCollection>> = {};
|
|
75
|
+
|
|
76
|
+
collections[ALL_FRAGMENTS_COLLECTION] = defineCollection({
|
|
77
|
+
loader: conlocaLoader({ contentRoot, site, kind: 'fragment' }),
|
|
78
|
+
schema: fragmentMetaSchema.loose(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
for (const name of api.fragments.collections) {
|
|
82
|
+
collections[name] = defineCollection({
|
|
83
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment' }),
|
|
84
|
+
schema: fragmentMetaSchema.loose(),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const name of api.data.collections) {
|
|
89
|
+
collections[name] = defineCollection({
|
|
90
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
|
|
91
|
+
schema: dataMetaSchema.loose(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const hostFields = pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : undefined;
|
|
96
|
+
const pageSchema =
|
|
97
|
+
hostFields && Object.keys(hostFields.shape).length > 0
|
|
98
|
+
? buildPageCollectionSchema(hostFields)
|
|
99
|
+
: pageMetaSchema.loose();
|
|
100
|
+
|
|
101
|
+
const siteCollections = api.getSite(site)?.collections ?? new Set<string>();
|
|
102
|
+
for (const name of siteCollections) {
|
|
103
|
+
collections[name] = defineCollection({
|
|
104
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
|
|
105
|
+
schema: pageSchema,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { collections };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const defaultContentRoot = () => process.env.CONLOCA_CONTENT_ROOT ?? './content';
|
|
113
|
+
|
|
114
|
+
/** Options for conlocaPages(). */
|
|
115
|
+
export interface ConlocaPagesOptions {
|
|
116
|
+
/**
|
|
117
|
+
* The same `pageSchemas` object the editor loads. Host meta fields are
|
|
118
|
+
* validated on every page at build time and typed via the HostPageMeta
|
|
119
|
+
* augmentation. Pass the object itself — not a hand-copied field list;
|
|
120
|
+
* {@link pageSchemasOf} reads it back off the returned collection so a
|
|
121
|
+
* site test can assert exactly that.
|
|
122
|
+
*/
|
|
123
|
+
pageSchemas?: PageSchemas;
|
|
124
|
+
/** @default 'pages' — must equal the content.config key this is assigned to. */
|
|
125
|
+
collection?: string;
|
|
126
|
+
/** @default 'default' */
|
|
127
|
+
site?: string;
|
|
128
|
+
/** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
|
|
129
|
+
contentRoot?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// What each conlocaPages call was handed, keyed weakly by the collection it
|
|
133
|
+
// returned: fresh objects per config evaluation, so a stale evaluation can
|
|
134
|
+
// never answer for a new one, and nothing is kept alive for it.
|
|
135
|
+
const pageSchemasByCollection = new WeakMap<object, PageSchemas>();
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The exact pageSchemas object a conlocaPages collection was declared with,
|
|
139
|
+
* or undefined for anything else. Lets a site test assert the identity the
|
|
140
|
+
* pageSchemas option demands — against the real factory, with no module mock.
|
|
141
|
+
*/
|
|
142
|
+
export function pageSchemasOf(collection: object): PageSchemas | undefined {
|
|
143
|
+
return pageSchemasByCollection.get(collection);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* One typed Astro collection for Conloca pages — the explicit,
|
|
148
|
+
* Starlight-shaped declaration:
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* export const collections = { pages: conlocaPages({ pageSchemas }) };
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* Entry data is typed as {@link ConlocaPageEntry}; `getCollection('pages')`
|
|
155
|
+
* carries pathname/title/dates and the host's declared meta fields.
|
|
156
|
+
*/
|
|
157
|
+
export function conlocaPages(options: ConlocaPagesOptions = {}) {
|
|
158
|
+
const { contentRoot = defaultContentRoot(), site = 'default', collection = 'pages', pageSchemas } = options;
|
|
159
|
+
declareConlocaCollection('page', collection);
|
|
160
|
+
const defined = defineCollection({
|
|
161
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'page' }), {
|
|
162
|
+
contentRoot,
|
|
163
|
+
site,
|
|
164
|
+
}),
|
|
165
|
+
schema: buildPageCollectionSchema(pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : z.object({})),
|
|
166
|
+
});
|
|
167
|
+
if (pageSchemas) pageSchemasByCollection.set(defined, pageSchemas);
|
|
168
|
+
return defined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Options for conlocaData(). */
|
|
172
|
+
export interface ConlocaDataOptions<DS extends DataSchemas> {
|
|
173
|
+
/**
|
|
174
|
+
* The same `dataSchemas` object the editor renders entry forms from. Its
|
|
175
|
+
* keys ARE the data collections — nothing is named twice. Each entry's
|
|
176
|
+
* payload is validated against its schema at build time.
|
|
177
|
+
*/
|
|
178
|
+
dataSchemas: DS;
|
|
179
|
+
/** @default 'default' */
|
|
180
|
+
site?: string;
|
|
181
|
+
/** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
|
|
182
|
+
contentRoot?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
|
|
187
|
+
* requiredness preserved, no rewrite guard — because the site owns it whole
|
|
188
|
+
* for exactly one collection, unlike host page fields folded into the shared
|
|
189
|
+
* pages schema. The flip side, accepted for now: a .transform or .default in
|
|
190
|
+
* a dataSchema runs at build time but not in the editor form, so the two can
|
|
191
|
+
* diverge.
|
|
192
|
+
*/
|
|
193
|
+
function conlocaDataCollection<T extends z.ZodObject<z.ZodRawShape>>(
|
|
194
|
+
name: string,
|
|
195
|
+
payload: T,
|
|
196
|
+
contentRoot: string,
|
|
197
|
+
site: string,
|
|
198
|
+
) {
|
|
199
|
+
return defineCollection({
|
|
200
|
+
loader: withDeclarationCheck(conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }), {
|
|
201
|
+
contentRoot,
|
|
202
|
+
site,
|
|
203
|
+
}),
|
|
204
|
+
// Base meta plus this collection's payload under `data`. `data` stays
|
|
205
|
+
// optional: an entry saved before any payload exists is not an error.
|
|
206
|
+
schema: z.looseObject({ ...dataMetaSchema.shape, data: payload.optional() }),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Typed Astro collections for Conloca data, one per `dataSchemas` key:
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* export const collections = { ...conlocaData({ dataSchemas }) };
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* `getCollection('testimonials')` entries carry `data` typed by that key's
|
|
218
|
+
* schema, and a stored entry that fails its schema fails the build instead
|
|
219
|
+
* of rendering blank.
|
|
220
|
+
*/
|
|
221
|
+
export function conlocaData<DS extends DataSchemas>(options: ConlocaDataOptions<DS>) {
|
|
222
|
+
const { dataSchemas, contentRoot = defaultContentRoot(), site = 'default' } = options;
|
|
223
|
+
const entries = Object.entries(dataSchemas).map(([name, payload]) => {
|
|
224
|
+
declareConlocaCollection('data', name);
|
|
225
|
+
return [name, conlocaDataCollection(name, payload, contentRoot, site)] as const;
|
|
226
|
+
});
|
|
227
|
+
// Object.fromEntries erases per-key types; the assertion restores exactly
|
|
228
|
+
// what the loop built — one collection per dataSchemas key.
|
|
229
|
+
return Object.fromEntries(entries) as { [K in keyof DS]: ReturnType<typeof conlocaDataCollection<DS[K]>> };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The fragments aggregate (always) plus one collection per named fragment
|
|
234
|
+
* folder: `...conlocaFragments('general')`. No arguments declares only the
|
|
235
|
+
* aggregate the render pipeline reads. There are no per-call options:
|
|
236
|
+
* contentRoot comes from conlocaCMS()'s contentRoot (via
|
|
237
|
+
* CONLOCA_CONTENT_ROOT) and the site is always 'default'.
|
|
238
|
+
*/
|
|
239
|
+
export function conlocaFragments<const N extends readonly string[]>(...names: N) {
|
|
240
|
+
const contentRoot = defaultContentRoot();
|
|
241
|
+
const site = 'default';
|
|
242
|
+
const fragmentCollection = (collection?: string) =>
|
|
243
|
+
defineCollection({
|
|
244
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment' }), {
|
|
245
|
+
contentRoot,
|
|
246
|
+
site,
|
|
247
|
+
}),
|
|
248
|
+
schema: fragmentMetaSchema.loose(),
|
|
249
|
+
});
|
|
250
|
+
const named = Object.fromEntries(
|
|
251
|
+
names.map((name) => {
|
|
252
|
+
declareConlocaCollection('fragment', name);
|
|
253
|
+
return [name, fragmentCollection(name)] as const;
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
// The computed key and Object.fromEntries both erase literal keys; the
|
|
257
|
+
// assertion restores exactly what was built — the aggregate plus one
|
|
258
|
+
// collection per name.
|
|
259
|
+
return { [ALL_FRAGMENTS_COLLECTION]: fragmentCollection(), ...named } as {
|
|
260
|
+
[ALL_FRAGMENTS_COLLECTION]: ReturnType<typeof fragmentCollection>;
|
|
261
|
+
} & { [K in N[number]]: ReturnType<typeof fragmentCollection> };
|
|
262
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { serializeProps } from '../lib/serialize-props.js';
|
|
3
|
+
import type { HydrationStrategy } from '../types.js';
|
|
4
|
+
|
|
5
|
+
interface HydrationWrapperProps {
|
|
6
|
+
componentName: string;
|
|
7
|
+
strategy: HydrationStrategy;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wraps hydratable components with data attributes for browser hydration.
|
|
14
|
+
*
|
|
15
|
+
* When strategy is 'none', renders children directly without wrapper overhead.
|
|
16
|
+
* Otherwise, wraps in a div with data-hydrate attributes that the browser
|
|
17
|
+
* hydration script uses to find and hydrate components.
|
|
18
|
+
*/
|
|
19
|
+
export function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps) {
|
|
20
|
+
// No hydration needed - render children directly without wrapper
|
|
21
|
+
if (strategy === 'none') {
|
|
22
|
+
return <>{children}</>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Strip Puck-internal props that aren't needed for hydration.
|
|
26
|
+
// `puck` contains functions (renderDropZone) that can't survive JSON serialization
|
|
27
|
+
// and would crash on hydration if a component called them.
|
|
28
|
+
const { puck: _puck, ...hydrateProps } = props as Record<string, unknown> & { puck?: unknown };
|
|
29
|
+
|
|
30
|
+
// Wrap with hydration markers for the browser script to find
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
style={{ display: 'contents' }}
|
|
34
|
+
data-hydrate={componentName}
|
|
35
|
+
data-hydrate-strategy={strategy}
|
|
36
|
+
data-props={serializeProps(hydrateProps)}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -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
|
+
}
|