@conloca/astro-cms 0.1.15 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -247
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/ts/src/cms-handler.d.ts +18 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/ts/src/cms-handler.js +245 -0
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +160 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +170 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.js +22 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts +21 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.js +39 -0
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js +25 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js +232 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/ts/src/discovery/merge-registry.js +333 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/ts/src/discovery/scan-components.d.ts +94 -0
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-components.js +397 -0
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.js +113 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.js +34 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts +4 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/ts/src/hydration.js +5 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +41 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.js +136 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-script.js +89 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-utils.js +84 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/ts/src/lib/route-utils.d.ts +61 -0
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/route-utils.js +96 -0
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/ts/src/lib/routing-config.d.ts +38 -0
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/ts/src/lib/routing-config.js +106 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts +6 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/ts/src/lib/serialize-props.js +8 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts +33 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/ts/src/lib/withHydration.js +50 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/ts/src/loader.js +118 -0
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts +61 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/ts/src/locales-helpers.js +50 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts +3 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/ts/src/mime-types.js +20 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts +8 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/ts/src/path-validation.js +13 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/ts/src/plugin-spa.d.ts +182 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/ts/src/plugin-spa.js +1165 -0
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts +13 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/ts/src/safe-json-stringify.js +7 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js +264 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +15 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +67 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/ts/src/types.d.ts +543 -0
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +74 -0
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +198 -56
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +10 -0
- package/src/cms-handler.ts +280 -0
- package/src/collections.ts +262 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +48 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/src/lib/withHydration.ts +71 -0
- package/src/loader.ts +145 -0
- package/src/locales-helpers.ts +68 -0
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1480 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +84 -0
- package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections.d.mts +0 -36
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -65
- package/dist/collections.mjs.map +0 -1
- package/dist/components.d.mts +0 -46
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -226
- package/dist/components.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -3
- package/dist/index.d.mts +0 -139
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -66
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -26
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -267
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -85
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -19
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.mjs +0 -4
- package/dist/node/index.d.mts +0 -52
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.mjs +0 -753
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
- package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
- package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
- package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content';
|
|
2
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
3
|
+
import { dataMetaSchema, fragmentMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ALL_FRAGMENTS_COLLECTION } from './handlers/page-render-core.js';
|
|
6
|
+
import { declareConlocaCollection, withDeclarationCheck } from './internal/declared-collections.js';
|
|
7
|
+
import { buildPageCollectionSchema, hostFieldsFromPageSchemas } from './internal/page-collection-schema.js';
|
|
8
|
+
import { conlocaLoader } from './loader.js';
|
|
9
|
+
export { ALL_FRAGMENTS_COLLECTION };
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Declare collections explicitly with {@link conlocaPages},
|
|
12
|
+
* {@link conlocaData} and {@link conlocaFragments} — they keep the entry
|
|
13
|
+
* types Astro's generated `getCollection` needs, and undeclared content
|
|
14
|
+
* fails the build instead of silently not building. This wrapper still
|
|
15
|
+
* works but returns untyped entries.
|
|
16
|
+
*
|
|
17
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
18
|
+
* Uses content-api to find collections that have content.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // src/content.config.ts
|
|
23
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
24
|
+
* import { pageSchemas } from './page-schemas';
|
|
25
|
+
*
|
|
26
|
+
* export const { collections } = await createConlocaCollections({ pageSchemas });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export async function createConlocaCollections(options = {}) {
|
|
30
|
+
// Default comes from the conlocaCMS integration, which publishes its raw
|
|
31
|
+
// contentRoot option to process.env before the content config loads — one
|
|
32
|
+
// contentRoot in astro.config covers both. (A missing directory is the
|
|
33
|
+
// integration's job to report; it warns in dev and fails the build.)
|
|
34
|
+
const { contentRoot = process.env.CONLOCA_CONTENT_ROOT ?? './content', site = 'default', pageSchemas } = options;
|
|
35
|
+
const api = await createContentAPI({ contentRoot });
|
|
36
|
+
const collections = {};
|
|
37
|
+
collections[ALL_FRAGMENTS_COLLECTION] = defineCollection({
|
|
38
|
+
loader: conlocaLoader({ contentRoot, site, kind: 'fragment' }),
|
|
39
|
+
schema: fragmentMetaSchema.loose(),
|
|
40
|
+
});
|
|
41
|
+
for (const name of api.fragments.collections) {
|
|
42
|
+
collections[name] = defineCollection({
|
|
43
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment' }),
|
|
44
|
+
schema: fragmentMetaSchema.loose(),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const name of api.data.collections) {
|
|
48
|
+
collections[name] = defineCollection({
|
|
49
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
|
|
50
|
+
schema: dataMetaSchema.loose(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const hostFields = pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : undefined;
|
|
54
|
+
const pageSchema = hostFields && Object.keys(hostFields.shape).length > 0
|
|
55
|
+
? buildPageCollectionSchema(hostFields)
|
|
56
|
+
: pageMetaSchema.loose();
|
|
57
|
+
const siteCollections = api.getSite(site)?.collections ?? new Set();
|
|
58
|
+
for (const name of siteCollections) {
|
|
59
|
+
collections[name] = defineCollection({
|
|
60
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
|
|
61
|
+
schema: pageSchema,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return { collections };
|
|
65
|
+
}
|
|
66
|
+
const defaultContentRoot = () => process.env.CONLOCA_CONTENT_ROOT ?? './content';
|
|
67
|
+
// What each conlocaPages call was handed, keyed weakly by the collection it
|
|
68
|
+
// returned: fresh objects per config evaluation, so a stale evaluation can
|
|
69
|
+
// never answer for a new one, and nothing is kept alive for it.
|
|
70
|
+
const pageSchemasByCollection = new WeakMap();
|
|
71
|
+
/**
|
|
72
|
+
* The exact pageSchemas object a conlocaPages collection was declared with,
|
|
73
|
+
* or undefined for anything else. Lets a site test assert the identity the
|
|
74
|
+
* pageSchemas option demands — against the real factory, with no module mock.
|
|
75
|
+
*/
|
|
76
|
+
export function pageSchemasOf(collection) {
|
|
77
|
+
return pageSchemasByCollection.get(collection);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* One typed Astro collection for Conloca pages — the explicit,
|
|
81
|
+
* Starlight-shaped declaration:
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* export const collections = { pages: conlocaPages({ pageSchemas }) };
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Entry data is typed as {@link ConlocaPageEntry}; `getCollection('pages')`
|
|
88
|
+
* carries pathname/title/dates and the host's declared meta fields.
|
|
89
|
+
*/
|
|
90
|
+
export function conlocaPages(options = {}) {
|
|
91
|
+
const { contentRoot = defaultContentRoot(), site = 'default', collection = 'pages', pageSchemas } = options;
|
|
92
|
+
declareConlocaCollection('page', collection);
|
|
93
|
+
const defined = defineCollection({
|
|
94
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'page' }), {
|
|
95
|
+
contentRoot,
|
|
96
|
+
site,
|
|
97
|
+
}),
|
|
98
|
+
schema: buildPageCollectionSchema(pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : z.object({})),
|
|
99
|
+
});
|
|
100
|
+
if (pageSchemas)
|
|
101
|
+
pageSchemasByCollection.set(defined, pageSchemas);
|
|
102
|
+
return defined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
|
|
106
|
+
* requiredness preserved, no rewrite guard — because the site owns it whole
|
|
107
|
+
* for exactly one collection, unlike host page fields folded into the shared
|
|
108
|
+
* pages schema. The flip side, accepted for now: a .transform or .default in
|
|
109
|
+
* a dataSchema runs at build time but not in the editor form, so the two can
|
|
110
|
+
* diverge.
|
|
111
|
+
*/
|
|
112
|
+
function conlocaDataCollection(name, payload, contentRoot, site) {
|
|
113
|
+
return defineCollection({
|
|
114
|
+
loader: withDeclarationCheck(conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }), {
|
|
115
|
+
contentRoot,
|
|
116
|
+
site,
|
|
117
|
+
}),
|
|
118
|
+
// Base meta plus this collection's payload under `data`. `data` stays
|
|
119
|
+
// optional: an entry saved before any payload exists is not an error.
|
|
120
|
+
schema: z.looseObject({ ...dataMetaSchema.shape, data: payload.optional() }),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Typed Astro collections for Conloca data, one per `dataSchemas` key:
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* export const collections = { ...conlocaData({ dataSchemas }) };
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* `getCollection('testimonials')` entries carry `data` typed by that key's
|
|
131
|
+
* schema, and a stored entry that fails its schema fails the build instead
|
|
132
|
+
* of rendering blank.
|
|
133
|
+
*/
|
|
134
|
+
export function conlocaData(options) {
|
|
135
|
+
const { dataSchemas, contentRoot = defaultContentRoot(), site = 'default' } = options;
|
|
136
|
+
const entries = Object.entries(dataSchemas).map(([name, payload]) => {
|
|
137
|
+
declareConlocaCollection('data', name);
|
|
138
|
+
return [name, conlocaDataCollection(name, payload, contentRoot, site)];
|
|
139
|
+
});
|
|
140
|
+
// Object.fromEntries erases per-key types; the assertion restores exactly
|
|
141
|
+
// what the loop built — one collection per dataSchemas key.
|
|
142
|
+
return Object.fromEntries(entries);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The fragments aggregate (always) plus one collection per named fragment
|
|
146
|
+
* folder: `...conlocaFragments('general')`. No arguments declares only the
|
|
147
|
+
* aggregate the render pipeline reads. There are no per-call options:
|
|
148
|
+
* contentRoot comes from conlocaCMS()'s contentRoot (via
|
|
149
|
+
* CONLOCA_CONTENT_ROOT) and the site is always 'default'.
|
|
150
|
+
*/
|
|
151
|
+
export function conlocaFragments(...names) {
|
|
152
|
+
const contentRoot = defaultContentRoot();
|
|
153
|
+
const site = 'default';
|
|
154
|
+
const fragmentCollection = (collection) => defineCollection({
|
|
155
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment' }), {
|
|
156
|
+
contentRoot,
|
|
157
|
+
site,
|
|
158
|
+
}),
|
|
159
|
+
schema: fragmentMetaSchema.loose(),
|
|
160
|
+
});
|
|
161
|
+
const named = Object.fromEntries(names.map((name) => {
|
|
162
|
+
declareConlocaCollection('fragment', name);
|
|
163
|
+
return [name, fragmentCollection(name)];
|
|
164
|
+
}));
|
|
165
|
+
// The computed key and Object.fromEntries both erase literal keys; the
|
|
166
|
+
// assertion restores exactly what was built — the aggregate plus one
|
|
167
|
+
// collection per name.
|
|
168
|
+
return { [ALL_FRAGMENTS_COLLECTION]: fragmentCollection(), ...named };
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAC5G,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAkCpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CA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wB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACvC,OAAO,CAAC,IAAI,EAAE,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAU,CAAC;IAClF,CAAC,CAAC,CAAC;IACH,0EAA0E;IAC1E,4DAA4D;IAC5D,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAyE,CAAC;AAC7G,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAoC,GAAG,KAAQ;IAC7E,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC;IACvB,MAAM,kBAAkB,GAAG,CAAC,UAAmB,EAAE,EAAE,CACjD,gBAAgB,CAAC;QACf,MAAM,EAAE,oBAAoB,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE;YAC/F,WAAW;YACX,IAAI;SACL,CAAC;QACF,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE;KACnC,CAAC,CAAC;IACL,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,wBAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAU,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;IACF,uEAAuE;IACvE,qEAAqE;IACrE,uBAAuB;IACvB,OAAO,EAAE,CAAC,wBAAwB,CAAC,EAAE,kBAAkB,EAAE,EAAE,GAAG,KAAK,EAEJ,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { HydrationStrategy } from '../types.js';
|
|
3
|
+
interface HydrationWrapperProps {
|
|
4
|
+
componentName: string;
|
|
5
|
+
strategy: HydrationStrategy;
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Wraps hydratable components with data attributes for browser hydration.
|
|
11
|
+
*
|
|
12
|
+
* When strategy is 'none', renders children directly without wrapper overhead.
|
|
13
|
+
* Otherwise, wraps in a div with data-hydrate attributes that the browser
|
|
14
|
+
* hydration script uses to find and hydrate components.
|
|
15
|
+
*/
|
|
16
|
+
export declare function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=HydrationWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationWrapper.d.ts","sourceRoot":"","sources":["../../../../src/components/HydrationWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,UAAU,qBAAqB;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAsBnG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { serializeProps } from '../lib/serialize-props.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps hydratable components with data attributes for browser hydration.
|
|
5
|
+
*
|
|
6
|
+
* When strategy is 'none', renders children directly without wrapper overhead.
|
|
7
|
+
* Otherwise, wraps in a div with data-hydrate attributes that the browser
|
|
8
|
+
* hydration script uses to find and hydrate components.
|
|
9
|
+
*/
|
|
10
|
+
export function HydrationWrapper({ componentName, strategy, props, children }) {
|
|
11
|
+
// No hydration needed - render children directly without wrapper
|
|
12
|
+
if (strategy === 'none') {
|
|
13
|
+
return _jsx(_Fragment, { children: children });
|
|
14
|
+
}
|
|
15
|
+
// Strip Puck-internal props that aren't needed for hydration.
|
|
16
|
+
// `puck` contains functions (renderDropZone) that can't survive JSON serialization
|
|
17
|
+
// and would crash on hydration if a component called them.
|
|
18
|
+
const { puck: _puck, ...hydrateProps } = props;
|
|
19
|
+
// Wrap with hydration markers for the browser script to find
|
|
20
|
+
return (_jsx("div", { style: { display: 'contents' }, "data-hydrate": componentName, "data-hydrate-strategy": strategy, "data-props": serializeProps(hydrateProps), children: children }));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=HydrationWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationWrapper.js","sourceRoot":"","sources":["../../../../src/components/HydrationWrapper.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAU3D;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAyB;IAClG,iEAAiE;IACjE,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxB,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACzB,CAAC;IAED,8DAA8D;IAC9D,mFAAmF;IACnF,2DAA2D;IAC3D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,YAAY,EAAE,GAAG,KAAqD,CAAC;IAE/F,6DAA6D;IAC7D,OAAO,CACL,cACE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,kBAChB,aAAa,2BACJ,QAAQ,gBACnB,cAAc,CAAC,YAAY,CAAC,YAEvC,QAAQ,GACL,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MDXHeading } from '@conloca/content-api';
|
|
2
|
+
import type { MDXFragmentEvaluationResult } from '@conloca/mdx/node';
|
|
3
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
4
|
+
import type { ComponentType } from 'react';
|
|
5
|
+
import type { DataContext } from '../types.js';
|
|
6
|
+
interface MDXComponent {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
Component: ComponentType;
|
|
10
|
+
outline: readonly MDXHeading[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Factory function to create a PageRenderer with MDX components baked in via closure.
|
|
14
|
+
*
|
|
15
|
+
* This approach avoids dangerouslySetInnerHTML by keeping React components as components
|
|
16
|
+
* throughout the rendering pipeline. Components are captured in the closure and don't
|
|
17
|
+
* need to be passed as props (which Astro can't serialize).
|
|
18
|
+
*
|
|
19
|
+
* @param config - The Puck configuration with component definitions
|
|
20
|
+
* @param data - Puck page data containing component tree
|
|
21
|
+
* @param mdxComponents - Array of evaluated MDX fragment results
|
|
22
|
+
* @param metadata - The page's data context, handed to every block's render as `puck.metadata`
|
|
23
|
+
* @returns A PageRenderer component with no props needed (components in closure)
|
|
24
|
+
*/
|
|
25
|
+
export declare function createPageRendererWithFragments(config: Config, data: Data, mdxComponents: (MDXFragmentEvaluationResult | MDXComponent)[], metadata: DataContext): ComponentType;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=RenderWithFragments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderWithFragments.d.ts","sourceRoot":"","sources":["../../../../src/components/RenderWithFragments.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAmB,MAAM,EAAE,IAAI,EAAiB,MAAM,kBAAkB,CAAC;AAErF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,aAAa,CAAC;AAG5E,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CAChC;AAoKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,CAAC,2BAA2B,GAAG,YAAY,CAAC,EAAE,EAC7D,QAAQ,EAAE,WAAW,GACpB,aAAa,CAOf"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Render } from '@puckeditor/core/rsc';
|
|
3
|
+
import { hasHydratableComponents } from '../lib/hydration-utils.js';
|
|
4
|
+
import { RenderWithHydration } from './RenderWithHydration.js';
|
|
5
|
+
function isRenderableFragment(fragment) {
|
|
6
|
+
return 'Component' in fragment && !('ok' in fragment);
|
|
7
|
+
}
|
|
8
|
+
function createFailedFragmentComponent(fragment) {
|
|
9
|
+
return function FailedFragmentComponent() {
|
|
10
|
+
return (_jsxs("div", { className: "p-4 bg-red-50 border border-red-200 rounded text-red-600", children: [_jsx("p", { className: "font-semibold mb-2", children: "MDX Fragment Error" }), _jsxs("p", { className: "text-sm", children: ["Fragment: ", fragment.id] }), _jsx("p", { className: "text-xs mt-2", children: fragment.error.message })] }));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function resolveRenderableFragments(fragments) {
|
|
14
|
+
return fragments.map((fragment) => {
|
|
15
|
+
if (isRenderableFragment(fragment)) {
|
|
16
|
+
return fragment;
|
|
17
|
+
}
|
|
18
|
+
if (fragment.ok) {
|
|
19
|
+
return fragment;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
id: fragment.id,
|
|
23
|
+
title: fragment.title,
|
|
24
|
+
Component: createFailedFragmentComponent(fragment),
|
|
25
|
+
outline: [],
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a host block's own render so it receives the resolved fragment as a
|
|
31
|
+
* prop. The platform owns resolution, the site owns the markup around it: the
|
|
32
|
+
* marker attribute makes the style scanner's content-root detection exact
|
|
33
|
+
* instead of heuristic.
|
|
34
|
+
*/
|
|
35
|
+
function withResolvedFragment(hostRender, fragmentComponentMap) {
|
|
36
|
+
// Rendered, never called: a site may ship its block as memo(...) or
|
|
37
|
+
// forwardRef(...), and those are objects React renders but nothing invokes.
|
|
38
|
+
const HostBlock = hostRender;
|
|
39
|
+
return (props) => {
|
|
40
|
+
const selected = fragmentComponentMap.get(props.fragmentId);
|
|
41
|
+
const SelectedFragmentComponent = selected?.Component;
|
|
42
|
+
return (_jsx(HostBlock, { ...props, fragmentOutline: selected?.outline ?? [], fragment: SelectedFragmentComponent ? (_jsx("div", { className: "mdx-content conloca-prose", "data-conloca-content-root": "", children: _jsx(SelectedFragmentComponent, {}) })) : undefined }));
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// ── Main Component ──────────────────────────────────────────────────────────
|
|
46
|
+
/**
|
|
47
|
+
* Internal component for rendering Puck pages with MDX fragments.
|
|
48
|
+
*
|
|
49
|
+
* Enhances the Puck config by:
|
|
50
|
+
* 1. Registering each MDX fragment as a dynamic Puck component (`Fragment_{id}`)
|
|
51
|
+
* 2. Wrapping the host's `ContentFragmentSection` render so it receives the
|
|
52
|
+
* resolved fragment as a `fragment` prop
|
|
53
|
+
*
|
|
54
|
+
* MDX fragments are passed as React components (not HTML strings), which:
|
|
55
|
+
* - Avoids dangerouslySetInnerHTML security risks
|
|
56
|
+
* - More efficient (no HTML conversion round-trip)
|
|
57
|
+
* - Type-safe with proper React component types
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
function RenderWithFragments({ config, data, mdxComponents, metadata }) {
|
|
62
|
+
// Build enhanced config with MDX fragments
|
|
63
|
+
const fragmentComponents = {};
|
|
64
|
+
const fragmentCategoryList = [];
|
|
65
|
+
const fragmentComponentMap = new Map(mdxComponents.map((fragment) => [fragment.id, fragment]));
|
|
66
|
+
// Create component configs for each fragment
|
|
67
|
+
mdxComponents.forEach((fragment) => {
|
|
68
|
+
const componentKey = `Fragment_${fragment.id}`;
|
|
69
|
+
// Capture component in closure - Puck doesn't persist defaultProps reliably
|
|
70
|
+
const FragmentComponent = fragment.Component;
|
|
71
|
+
fragmentComponents[componentKey] = {
|
|
72
|
+
label: fragment.title,
|
|
73
|
+
fields: {},
|
|
74
|
+
defaultProps: {},
|
|
75
|
+
render: () => (_jsx("div", { className: "mdx-content conloca-prose", "data-conloca-content-root": "", children: _jsx(FragmentComponent, {}) })),
|
|
76
|
+
};
|
|
77
|
+
fragmentCategoryList.push(componentKey);
|
|
78
|
+
});
|
|
79
|
+
// Merge with existing config
|
|
80
|
+
const existingCategories = config.categories || {};
|
|
81
|
+
const existingComponents = config.components || {};
|
|
82
|
+
const contentFragmentSection = existingComponents.ContentFragmentSection;
|
|
83
|
+
const enhancedContentFragmentSection = contentFragmentSection
|
|
84
|
+
? {
|
|
85
|
+
...contentFragmentSection,
|
|
86
|
+
render: withResolvedFragment(contentFragmentSection.render, fragmentComponentMap),
|
|
87
|
+
}
|
|
88
|
+
: undefined;
|
|
89
|
+
// Merge fragment components with existing config components
|
|
90
|
+
const mergedComponents = {
|
|
91
|
+
...existingComponents,
|
|
92
|
+
...(enhancedContentFragmentSection && { ContentFragmentSection: enhancedContentFragmentSection }),
|
|
93
|
+
...fragmentComponents,
|
|
94
|
+
};
|
|
95
|
+
const enhancedConfig = {
|
|
96
|
+
...config,
|
|
97
|
+
categories: {
|
|
98
|
+
...existingCategories,
|
|
99
|
+
fragments: {
|
|
100
|
+
title: 'Content Fragments',
|
|
101
|
+
components: fragmentCategoryList,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
components: mergedComponents,
|
|
105
|
+
};
|
|
106
|
+
// Check if page has hydratable components
|
|
107
|
+
const needsHydration = hasHydratableComponents(data, enhancedConfig);
|
|
108
|
+
if (needsHydration) {
|
|
109
|
+
return _jsx(RenderWithHydration, { config: enhancedConfig, data: data, metadata: metadata });
|
|
110
|
+
}
|
|
111
|
+
return _jsx(Render, { config: enhancedConfig, data: data, metadata: metadata });
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Factory function to create a PageRenderer with MDX components baked in via closure.
|
|
115
|
+
*
|
|
116
|
+
* This approach avoids dangerouslySetInnerHTML by keeping React components as components
|
|
117
|
+
* throughout the rendering pipeline. Components are captured in the closure and don't
|
|
118
|
+
* need to be passed as props (which Astro can't serialize).
|
|
119
|
+
*
|
|
120
|
+
* @param config - The Puck configuration with component definitions
|
|
121
|
+
* @param data - Puck page data containing component tree
|
|
122
|
+
* @param mdxComponents - Array of evaluated MDX fragment results
|
|
123
|
+
* @param metadata - The page's data context, handed to every block's render as `puck.metadata`
|
|
124
|
+
* @returns A PageRenderer component with no props needed (components in closure)
|
|
125
|
+
*/
|
|
126
|
+
export function createPageRendererWithFragments(config, data, mdxComponents, metadata) {
|
|
127
|
+
const renderableFragments = resolveRenderableFragments(mdxComponents);
|
|
128
|
+
// Capture components in closure - no need to pass as props
|
|
129
|
+
return function PageRendererWithFragments() {
|
|
130
|
+
return _jsx(RenderWithFragments, { config: config, data: data, mdxComponents: renderableFragments, metadata: metadata });
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=RenderWithFragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderWithFragments.js","sourceRoot":"","sources":["../../../../src/components/RenderWithFragments.tsx"],"names":[],"mappings":";AAGA,OAA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;;;;;GAYG;AACH,MAAM,UAAU,+BAA+B,CAC7C,MAAc,EACd,IAAU,EACV,aAA6D,EAC7D,QAAqB;IAErB,MAAM,mBAAmB,GAAG,0BAA0B,CAAC,aAAa,CAAC,CAAC;IAEtE,2DAA2D;IAC3D,OAAO,SAAS,yBAAyB;QACvC,OAAO,KAAC,mBAAmB,IAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAC;IACrH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
2
|
+
import type { DataContext } from '../types.js';
|
|
3
|
+
interface RenderWithHydrationProps {
|
|
4
|
+
config: Config;
|
|
5
|
+
data: Data;
|
|
6
|
+
metadata: DataContext;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper around Puck's Render component that adds hydration support.
|
|
10
|
+
*
|
|
11
|
+
* For each component with a hydration strategy configured, wraps the
|
|
12
|
+
* component's render output with HydrationWrapper to add data-hydrate
|
|
13
|
+
* attributes for browser-side hydration.
|
|
14
|
+
*
|
|
15
|
+
* Non-hydratable components render without any wrapper overhead. Every block
|
|
16
|
+
* renders with the page's data context as `puck.metadata` on the server; a
|
|
17
|
+
* hydrated block does not get `puck` in the browser.
|
|
18
|
+
*/
|
|
19
|
+
export declare function RenderWithHydration({ config, data, metadata }: RenderWithHydrationProps): import("react").JSX.Element;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=RenderWithHydration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderWithHydration.d.ts","sourceRoot":"","sources":["../../../../src/components/RenderWithHydration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,wBAAwB,+BA+BvF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Render } from '@puckeditor/core/rsc';
|
|
3
|
+
import { isHydratable } from '../lib/hydration-utils.js';
|
|
4
|
+
import { HydrationWrapper } from './HydrationWrapper.js';
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper around Puck's Render component that adds hydration support.
|
|
7
|
+
*
|
|
8
|
+
* For each component with a hydration strategy configured, wraps the
|
|
9
|
+
* component's render output with HydrationWrapper to add data-hydrate
|
|
10
|
+
* attributes for browser-side hydration.
|
|
11
|
+
*
|
|
12
|
+
* Non-hydratable components render without any wrapper overhead. Every block
|
|
13
|
+
* renders with the page's data context as `puck.metadata` on the server; a
|
|
14
|
+
* hydrated block does not get `puck` in the browser.
|
|
15
|
+
*/
|
|
16
|
+
export function RenderWithHydration({ config, data, metadata }) {
|
|
17
|
+
// Create wrapped config with hydration-aware render functions
|
|
18
|
+
const wrappedConfig = {
|
|
19
|
+
...config,
|
|
20
|
+
components: Object.fromEntries(Object.entries(config.components).map(([name, componentConfig]) => {
|
|
21
|
+
const strategy = isHydratable(name, config);
|
|
22
|
+
if (strategy === 'none') {
|
|
23
|
+
// No wrapping needed - component stays static
|
|
24
|
+
return [name, componentConfig];
|
|
25
|
+
}
|
|
26
|
+
// Wrap the render function so its output becomes HydrationWrapper children
|
|
27
|
+
const originalRender = componentConfig.render;
|
|
28
|
+
return [
|
|
29
|
+
name,
|
|
30
|
+
{
|
|
31
|
+
...componentConfig,
|
|
32
|
+
render: (props) => (_jsx(HydrationWrapper, { componentName: name, strategy: strategy, props: props, children: originalRender(props) })),
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
})),
|
|
36
|
+
};
|
|
37
|
+
return _jsx(Render, { config: wrappedConfig, data: data, metadata: metadata });
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=RenderWithHydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderWithHydration.js","sourceRoot":"","sources":["../../../../src/components/RenderWithHydration.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAA4B;IACtF,8DAA8D;IAC9D,MAAM,aAAa,GAAW;QAC5B,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,EAAE;YAChE,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAE5C,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACxB,8CAA8C;gBAC9C,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;YACjC,CAAC;YAED,2EAA2E;YAC3E,MAAM,cAAc,GAAG,eAAe,CAAC,MAAM,CAAC;YAC9C,OAAO;gBACL,IAAI;gBACJ;oBACE,GAAG,eAAe;oBAClB,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CACjB,KAAC,gBAAgB,IAAC,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,YACpE,cAAc,CAAC,KAAK,CAAC,GACL,CACpB;iBACF;aACF,CAAC;QACJ,CAAC,CAAC,CACH;KACF,CAAC;IAEF,OAAO,KAAC,MAAM,IAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 declare function extractAstroFrontmatter(content: string): string | null;
|
|
18
|
+
//# sourceMappingURL=astro-frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-frontmatter.d.ts","sourceRoot":"","sources":["../../../../src/discovery/astro-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOtE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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) {
|
|
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
|
+
}
|
|
25
|
+
//# sourceMappingURL=astro-frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-frontmatter.js","sourceRoot":"","sources":["../../../../src/discovery/astro-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,sDAAsD;IACtD,gEAAgE;IAChE,8DAA8D;IAC9D,kEAAkE;IAClE,MAAM,KAAK,GAAG,2CAA2C,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type DiscoveredComponent } from './merge-registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs for the MDX component registry scan. Resolved ONCE by the
|
|
4
|
+
* integration so the dev endpoint and a build-time integration cannot drift.
|
|
5
|
+
*/
|
|
6
|
+
export interface MdxRegistryScanOptions {
|
|
7
|
+
/** Absolute or project-relative path to the MDX content directory. */
|
|
8
|
+
contentRoot: string;
|
|
9
|
+
/** Project-relative paths to scan for local components. */
|
|
10
|
+
componentFolders: string[];
|
|
11
|
+
/** Project-relative folder of `*.cms.json` sidecar override files,
|
|
12
|
+
* keyed by component basename (`Card.cms.json` → overrides `Card`).
|
|
13
|
+
* Defaults to `src/cms-overrides` — hosts can omit it when they
|
|
14
|
+
* don't need any overrides yet. */
|
|
15
|
+
overridesFolder?: string;
|
|
16
|
+
/** Base for resolving the paths above. Defaults to `process.cwd()`. */
|
|
17
|
+
projectRoot?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The three-stage auto-discovery pipeline behind the editor's MDX
|
|
21
|
+
* component registry (scan-mdx + scan-components + merge-registry).
|
|
22
|
+
*
|
|
23
|
+
* Free of any dev-server dependency on purpose: dev serves the result
|
|
24
|
+
* from `/__cms/api/registry`, and a build-time caller, where no dev server
|
|
25
|
+
* runs, calls this same function. One scan implementation is the only way
|
|
26
|
+
* both can agree.
|
|
27
|
+
*/
|
|
28
|
+
export declare function discoverMdxComponents(options: MdxRegistryScanOptions): Promise<DiscoveredComponent[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Rewrites absolute local-component import specifiers to project-relative
|
|
31
|
+
* ones (`/src/components/mdx/Aside.tsx`), and `aliases` keys — absolute MDX
|
|
32
|
+
* file paths of the scanning machine — the same way.
|
|
33
|
+
*
|
|
34
|
+
* The scanner records a local component's `import.from` as its absolute file
|
|
35
|
+
* path, which is what the dev render endpoint hands to `ssrLoadModule`. That
|
|
36
|
+
* path is machine-specific: descriptors that outlive the scan (saved with the
|
|
37
|
+
* site's MDX files, say) would carry the scanning machine's prefix into the
|
|
38
|
+
* repository and break the next build elsewhere. Callers whose descriptors
|
|
39
|
+
* outlive the scan apply it; the dev endpoint keeps the paths its loader
|
|
40
|
+
* expects. npm specifiers and paths outside the project are left untouched.
|
|
41
|
+
*/
|
|
42
|
+
export declare function toPortableImports(components: DiscoveredComponent[], projectRoot: string): DiscoveredComponent[];
|
|
43
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../../../src/discovery/discover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,mBAAmB,EAAiB,MAAM,qBAAqB,CAAC;AAK9E;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B;;;uCAGmC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAsB3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,mBAAmB,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAqB/G"}
|