@conloca/astro-cms 0.1.14 → 0.1.16
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 +65 -5
- package/dist/collections-Bd7EME4b.mjs +129 -0
- package/dist/collections-Bd7EME4b.mjs.map +1 -0
- package/dist/collections.d.mts +3 -3
- package/dist/collections.d.mts.map +1 -1
- package/dist/collections.mjs +2 -56
- package/dist/components.d.mts +6 -31
- package/dist/components.d.mts.map +1 -1
- package/dist/components.mjs +100 -45
- package/dist/components.mjs.map +1 -1
- package/dist/hydration.d.mts +2 -2
- package/dist/hydration.mjs +2 -3
- package/dist/index.d.mts +12 -88
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +19 -797
- package/dist/index.mjs.map +1 -1
- package/dist/internal/acorn-default.mjs +29 -0
- package/dist/{cms-handler.d.mts → internal/cms-handler.d.mts} +0 -1
- package/dist/internal/cms-handler.d.mts.map +1 -0
- package/dist/{cms-handler.mjs → internal/cms-handler.mjs} +57 -8
- package/dist/internal/cms-handler.mjs.map +1 -0
- package/dist/internal/page-handler.astro +541 -0
- package/dist/lib/hydration-script.d.mts +1 -2
- package/dist/lib/hydration-script.d.mts.map +1 -1
- package/dist/lib/hydration-script.mjs +1 -2
- package/dist/lib/hydration-script.mjs.map +1 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts +64 -0
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +1 -0
- package/dist/locales-helpers-qiwh7nxS.mjs +54 -0
- package/dist/locales-helpers-qiwh7nxS.mjs.map +1 -0
- package/dist/node/content.d.mts +18 -0
- package/dist/node/content.d.mts.map +1 -0
- package/dist/node/content.d.ts +3 -0
- package/dist/node/content.d.ts.map +1 -0
- package/dist/node/content.js +2 -0
- package/dist/node/content.mjs +2 -0
- package/dist/node/index.d.mts +200 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +3 -0
- package/dist/node/index.mjs +2513 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/{serialize-props-DqfDQeFl.mjs → serialize-props-BHoNpzH6.mjs} +4 -5
- package/dist/{serialize-props-DqfDQeFl.mjs.map → serialize-props-BHoNpzH6.mjs.map} +1 -1
- package/dist/src/cms-handler.d.ts +19 -0
- package/dist/src/cms-handler.d.ts.map +1 -0
- package/dist/src/cms-handler.js +366 -0
- package/dist/src/collections.d.ts +32 -0
- package/dist/src/collections.d.ts.map +1 -0
- package/dist/src/collections.js +50 -0
- package/dist/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/src/components/HydrationWrapper.js +21 -0
- package/dist/src/components/RenderWithBlocks.d.ts +23 -0
- package/dist/src/components/RenderWithBlocks.d.ts.map +1 -0
- package/dist/src/components/RenderWithBlocks.js +129 -0
- package/dist/src/components/RenderWithHydration.d.ts +17 -0
- package/dist/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/src/components/RenderWithHydration.js +36 -0
- package/dist/src/components.d.ts +4 -0
- package/dist/src/components.d.ts.map +1 -0
- package/dist/src/components.js +3 -0
- package/dist/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/src/discovery/astro-frontmatter.js +24 -0
- package/dist/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/src/discovery/extract-props-ts.js +231 -0
- package/dist/src/discovery/merge-registry.d.ts +58 -0
- package/dist/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/src/discovery/merge-registry.js +332 -0
- package/dist/src/discovery/registry-endpoint.d.ts +42 -0
- package/dist/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/src/discovery/registry-endpoint.js +81 -0
- package/dist/src/discovery/scan-components.d.ts +98 -0
- package/dist/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/src/discovery/scan-components.js +399 -0
- package/dist/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/src/discovery/scan-mdx.js +112 -0
- package/dist/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/src/discovery/scan-overrides.js +33 -0
- package/dist/src/hydration.d.ts +4 -0
- package/dist/src/hydration.d.ts.map +1 -0
- package/dist/src/hydration.js +4 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/src/lib/hydration-scanner.js +135 -0
- package/dist/src/lib/hydration-script.d.ts +28 -0
- package/dist/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/src/lib/hydration-script.js +88 -0
- package/dist/src/lib/hydration-utils.d.ts +51 -0
- package/dist/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/src/lib/hydration-utils.js +83 -0
- package/dist/src/lib/page-api.d.ts +77 -0
- package/dist/src/lib/page-api.d.ts.map +1 -0
- package/dist/src/lib/page-api.js +121 -0
- package/dist/src/lib/route-utils.d.ts +41 -0
- package/dist/src/lib/route-utils.d.ts.map +1 -0
- package/dist/src/lib/route-utils.js +78 -0
- package/dist/src/lib/routing-config.d.ts +32 -0
- package/dist/src/lib/routing-config.d.ts.map +1 -0
- package/dist/src/lib/routing-config.js +93 -0
- package/dist/src/lib/serialize-props.d.ts +6 -0
- package/dist/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/src/lib/serialize-props.js +7 -0
- package/dist/src/lib/virtual-module-generators.d.ts +57 -0
- package/dist/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/src/lib/virtual-module-generators.js +263 -0
- package/dist/src/lib/withHydration.d.ts +51 -0
- package/dist/src/lib/withHydration.d.ts.map +1 -0
- package/dist/src/lib/withHydration.js +49 -0
- package/dist/src/loader.d.ts +14 -0
- package/dist/src/loader.d.ts.map +1 -0
- package/dist/src/loader.js +89 -0
- package/dist/src/locales-helpers.d.ts +61 -0
- package/dist/src/locales-helpers.d.ts.map +1 -0
- package/dist/src/locales-helpers.js +49 -0
- package/dist/src/mime-types.d.ts +3 -0
- package/dist/src/mime-types.d.ts.map +1 -0
- package/dist/src/mime-types.js +19 -0
- package/dist/src/path-validation.d.ts +8 -0
- package/dist/src/path-validation.d.ts.map +1 -0
- package/dist/src/path-validation.js +12 -0
- package/dist/src/plugin-spa.d.ts +164 -0
- package/dist/src/plugin-spa.d.ts.map +1 -0
- package/dist/src/plugin-spa.js +972 -0
- package/dist/src/safe-json-stringify.d.ts +13 -0
- package/dist/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/src/safe-json-stringify.js +6 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts +76 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/content-wrapper-endpoint.js +227 -0
- package/dist/src/site-styles/render-endpoint.d.ts +55 -0
- package/dist/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/render-endpoint.js +263 -0
- package/dist/src/site-styles/styles-endpoint.d.ts +61 -0
- package/dist/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/styles-endpoint.js +158 -0
- package/dist/src/types.d.ts +627 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/{types-Bsd_qENn.d.mts → types-CS9neadI.d.mts} +193 -3
- package/dist/types-CS9neadI.d.mts.map +1 -0
- package/dist/virtual-modules.d.ts +155 -0
- package/dist/{withHydration-692fMySA.mjs → withHydration-C256ox_6.mjs} +6 -2
- package/dist/withHydration-C256ox_6.mjs.map +1 -0
- package/dist/{withHydration-BGgQDE-H.d.mts → withHydration-DkKpkmzJ.d.mts} +5 -2
- package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
- package/package.json +106 -40
- package/dist/cms-handler.d.mts.map +0 -1
- package/dist/cms-handler.mjs.map +0 -1
- package/dist/collections.mjs.map +0 -1
- package/dist/handlers/page-handler.astro +0 -299
- package/dist/loader-W3i9kf3p.mjs +0 -61
- package/dist/loader-W3i9kf3p.mjs.map +0 -1
- package/dist/types-Bsd_qENn.d.mts.map +0 -1
- package/dist/withHydration-692fMySA.mjs.map +0 -1
- package/dist/withHydration-BGgQDE-H.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-props-
|
|
1
|
+
{"version":3,"file":"serialize-props-BHoNpzH6.mjs","names":[],"sources":["../src/lib/hydration-utils.ts","../src/lib/serialize-props.ts"],"sourcesContent":["import type { Config, Data } from '@puckeditor/core';\nimport type { HydrationStrategy } from '../types.js';\nimport type { HydrationMeta } from './withHydration.js';\n\n/**\n * Extended ComponentConfig with hydration support.\n * @deprecated Use withHydration() wrapper instead of hydration property.\n */\nexport interface HydratableComponentConfig {\n /** @deprecated Use withHydration() wrapper on render function instead */\n hydration?: HydrationStrategy;\n render?: (props: unknown) => unknown;\n}\n\n/**\n * Component instance requiring hydration.\n * Contains the component name, props, and hydration strategy.\n */\nexport interface HydratableComponent {\n /** Component type name from Puck config */\n type: string;\n /** Props to pass to the component */\n props: Record<string, unknown>;\n /** Hydration strategy from ComponentConfig */\n strategy: Exclude<HydrationStrategy, 'none'>;\n /** Unique ID from Puck data (for keying) */\n id: string;\n}\n\n/**\n * Check if a component type has hydration enabled.\n *\n * First checks for __hydration metadata on the render function (new withHydration API),\n * then falls back to hydration property on ComponentConfig (deprecated).\n *\n * @param componentType - The component type name from Puck data\n * @param config - The Puck config with component definitions\n * @returns The hydration strategy ('none', 'load', 'visible', 'idle')\n */\nexport function isHydratable(componentType: string, config: Config): HydrationStrategy {\n const componentConfig = config.components[componentType] as HydratableComponentConfig | undefined;\n if (!componentConfig?.render) return 'none';\n\n // New API: Check for __hydration metadata attached by withHydration()\n const render = componentConfig.render as { __hydration?: HydrationMeta };\n if (render.__hydration?.__isHydratable) {\n return render.__hydration.strategy;\n }\n\n // Deprecated: Check hydration property on ComponentConfig\n return componentConfig?.hydration ?? 'none';\n}\n\n/**\n * Find all components in a Puck data tree that require hydration.\n * Walks the content array and zones recursively.\n *\n * @param data - Puck data object containing content tree\n * @param config - Puck config with component definitions\n * @returns Array of components that need hydration\n */\nexport function findHydratableComponents(data: Data, config: Config): HydratableComponent[] {\n const hydratable: HydratableComponent[] = [];\n\n // Walk content array\n if (data.content) {\n for (const item of data.content) {\n const strategy = isHydratable(item.type, config);\n if (strategy !== 'none') {\n hydratable.push({\n type: item.type,\n props: item.props ?? {},\n strategy,\n id: item.props?.id ?? item.type,\n });\n }\n }\n }\n\n // Walk zones (named drop zones with nested content)\n if (data.zones) {\n for (const [zoneName, zoneContent] of Object.entries(data.zones)) {\n for (const item of zoneContent) {\n const strategy = isHydratable(item.type, config);\n if (strategy !== 'none') {\n hydratable.push({\n type: item.type,\n props: item.props ?? {},\n strategy,\n id: item.props?.id ?? `${zoneName}-${item.type}`,\n });\n }\n }\n }\n }\n\n return hydratable;\n}\n\n/**\n * Check if Puck data contains any hydratable components.\n * Quick check before more expensive operations.\n */\nexport function hasHydratableComponents(data: Data, config: Config): boolean {\n // Check content\n if (data.content?.some((item) => isHydratable(item.type, config) !== 'none')) {\n return true;\n }\n\n // Check zones\n if (data.zones) {\n for (const zoneContent of Object.values(data.zones)) {\n if (zoneContent.some((item) => isHydratable(item.type, config) !== 'none')) {\n return true;\n }\n }\n }\n\n return false;\n}\n","/**\n * Safely serialize props for embedding in HTML data attributes.\n * Escapes < to prevent XSS when JSON is parsed in browser.\n */\nexport function serializeProps(props: Record<string, unknown>): string {\n return JSON.stringify(props).replace(/</g, '\\\\u003c');\n}\n"],"mappings":";;;;;;;;;;;AAuCA,SAAgB,aAAa,eAAuB,QAAmC;CACrF,MAAM,kBAAkB,OAAO,WAAW;CAC1C,IAAI,CAAC,iBAAiB,QAAQ,OAAO;CAGrC,MAAM,SAAS,gBAAgB;CAC/B,IAAI,OAAO,aAAa,gBACtB,OAAO,OAAO,YAAY;CAI5B,OAAO,iBAAiB,aAAa;AACvC;;;;;;;;;AAUA,SAAgB,yBAAyB,MAAY,QAAuC;CAC1F,MAAM,aAAoC,CAAC;CAG3C,IAAI,KAAK,SACP,KAAK,MAAM,QAAQ,KAAK,SAAS;EAC/B,MAAM,WAAW,aAAa,KAAK,MAAM,MAAM;EAC/C,IAAI,aAAa,QACf,WAAW,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK,SAAS,CAAC;GACtB;GACA,IAAI,KAAK,OAAO,MAAM,KAAK;EAC7B,CAAC;CAEL;CAIF,IAAI,KAAK,OACP,KAAK,MAAM,CAAC,UAAU,gBAAgB,OAAO,QAAQ,KAAK,KAAK,GAC7D,KAAK,MAAM,QAAQ,aAAa;EAC9B,MAAM,WAAW,aAAa,KAAK,MAAM,MAAM;EAC/C,IAAI,aAAa,QACf,WAAW,KAAK;GACd,MAAM,KAAK;GACX,OAAO,KAAK,SAAS,CAAC;GACtB;GACA,IAAI,KAAK,OAAO,MAAM,GAAG,SAAS,GAAG,KAAK;EAC5C,CAAC;CAEL;CAIJ,OAAO;AACT;;;;;AAMA,SAAgB,wBAAwB,MAAY,QAAyB;CAE3E,IAAI,KAAK,SAAS,MAAM,SAAS,aAAa,KAAK,MAAM,MAAM,MAAM,MAAM,GACzE,OAAO;CAIT,IAAI,KAAK,OACF;OAAA,MAAM,eAAe,OAAO,OAAO,KAAK,KAAK,GAChD,IAAI,YAAY,MAAM,SAAS,aAAa,KAAK,MAAM,MAAM,MAAM,MAAM,GACvE,OAAO;CAAA;CAKb,OAAO;AACT;;;;;;;ACnHA,SAAgB,eAAe,OAAwC;CACrE,OAAO,KAAK,UAAU,KAAK,CAAC,CAAC,QAAQ,MAAM,SAAS;AACtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
export { SPA_MIME_TYPES } from './mime-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Unified CMS handler - single entry point for all CMS routes.
|
|
5
|
+
*
|
|
6
|
+
* This handler:
|
|
7
|
+
* 1. Validates CF Access authentication ONCE at the top
|
|
8
|
+
* 2. Routes to appropriate sub-handler based on path:
|
|
9
|
+
* - /api/data-context -> handleDataContext()
|
|
10
|
+
* - /api/* -> handleContentApi()
|
|
11
|
+
* - /* -> handleSpa()
|
|
12
|
+
*
|
|
13
|
+
* Benefits:
|
|
14
|
+
* - Single authentication check prevents security gaps
|
|
15
|
+
* - New routes automatically inherit auth protection
|
|
16
|
+
* - Easier to audit security
|
|
17
|
+
*/
|
|
18
|
+
export declare const ALL: APIRoute;
|
|
19
|
+
//# sourceMappingURL=cms-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-handler.d.ts","sourceRoot":"","sources":["../../src/cms-handler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAMtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA2BjD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,GAAG,EAAE,QAwBjB,CAAC"}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import spaConfig from 'virtual:conloca-config';
|
|
5
|
+
import { contentOptions, getDataCollection, getPagesByPrefix } from 'virtual:conloca-page-api';
|
|
6
|
+
import routingConfig from 'virtual:conloca-routing-config';
|
|
7
|
+
import { createContentAPI, createContentAPIRouter, ErrorCodes, FileSystemContentAPI, validateCFAccessRequest, } from '@conloca/content-api/node';
|
|
8
|
+
import { compileMDX } from '@conloca/mdx/node';
|
|
9
|
+
import { SPA_MIME_TYPES } from './mime-types.js';
|
|
10
|
+
import { isPathWithinBase } from './path-validation.js';
|
|
11
|
+
import { safeJsonStringify } from './safe-json-stringify.js';
|
|
12
|
+
export { SPA_MIME_TYPES } from './mime-types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Read the top-level locales options from build-time env vars.
|
|
15
|
+
* `CONLOCA_LOCALES` is inlined as a JS array (or `null`) by Vite's
|
|
16
|
+
* `define`; `CONLOCA_DEFAULT_LOCALE` is a string (or `''`). When neither
|
|
17
|
+
* is set, returns an empty object so the spread is a no-op and the
|
|
18
|
+
* content-api falls back to sites.json (the existing behavior).
|
|
19
|
+
*/
|
|
20
|
+
function localesFromEnv() {
|
|
21
|
+
const list = import.meta.env.CONLOCA_LOCALES;
|
|
22
|
+
const defaultLocale = import.meta.env.CONLOCA_DEFAULT_LOCALE;
|
|
23
|
+
return {
|
|
24
|
+
...(Array.isArray(list) && list.length > 0 ? { availableLocales: list } : {}),
|
|
25
|
+
...(typeof defaultLocale === 'string' && defaultLocale ? { defaultLocale } : {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// mdxPages config (root / site / defaultLocale) is no longer passed as
|
|
29
|
+
// env vars — the content-api reads sites.json directly from disk under
|
|
30
|
+
// `contentRoot`, so handlers below don't need to spread mdx-options at
|
|
31
|
+
// all. See `readSitesConfig()` in @conloca/content-api/node.
|
|
32
|
+
// Get the path to the cms-spa package by resolving its package.json
|
|
33
|
+
const require = createRequire(import.meta.url);
|
|
34
|
+
const cmsSpaPath = dirname(require.resolve('@conloca/cms-spa/package.json'));
|
|
35
|
+
/**
|
|
36
|
+
* Unified CMS handler - single entry point for all CMS routes.
|
|
37
|
+
*
|
|
38
|
+
* This handler:
|
|
39
|
+
* 1. Validates CF Access authentication ONCE at the top
|
|
40
|
+
* 2. Routes to appropriate sub-handler based on path:
|
|
41
|
+
* - /api/data-context -> handleDataContext()
|
|
42
|
+
* - /api/* -> handleContentApi()
|
|
43
|
+
* - /* -> handleSpa()
|
|
44
|
+
*
|
|
45
|
+
* Benefits:
|
|
46
|
+
* - Single authentication check prevents security gaps
|
|
47
|
+
* - New routes automatically inherit auth protection
|
|
48
|
+
* - Easier to audit security
|
|
49
|
+
*/
|
|
50
|
+
export const ALL = async ({ params, request }) => {
|
|
51
|
+
// Step 1: Validate CF Access ONCE
|
|
52
|
+
const cfResult = await validateCFAccessRequest(request);
|
|
53
|
+
if (!cfResult.valid && cfResult.required) {
|
|
54
|
+
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
|
55
|
+
status: 401,
|
|
56
|
+
headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Step 2: Route based on path
|
|
60
|
+
const pathArray = params.path;
|
|
61
|
+
const path = Array.isArray(pathArray) ? pathArray.join('/') : pathArray || '';
|
|
62
|
+
// Route to appropriate handler
|
|
63
|
+
if (path.startsWith('api/data-context')) {
|
|
64
|
+
return handleDataContext(request);
|
|
65
|
+
}
|
|
66
|
+
if (path.startsWith('api/')) {
|
|
67
|
+
return handleContentApi(request, cfResult);
|
|
68
|
+
}
|
|
69
|
+
return handleSpa(params, request);
|
|
70
|
+
};
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// SPA Handler (from spa-handler.ts)
|
|
73
|
+
// ============================================================================
|
|
74
|
+
/**
|
|
75
|
+
* Generate HTML for dev mode that loads cms-spa source through Vite.
|
|
76
|
+
* This ensures React is resolved from Vite's pre-bundled deps, not from the cms-spa bundle.
|
|
77
|
+
*/
|
|
78
|
+
function generateDevHtml(config) {
|
|
79
|
+
return `<!DOCTYPE html>
|
|
80
|
+
<html lang="en">
|
|
81
|
+
<head>
|
|
82
|
+
<meta charset="UTF-8" />
|
|
83
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
84
|
+
<title>Conloca CMS</title>
|
|
85
|
+
<link rel="stylesheet" href="${config.basename}/main.css" />
|
|
86
|
+
<script type="module" src="${config.basename}/site-styles.js"></script>
|
|
87
|
+
<script type="module" src="${config.basename}/editor-styles.js"></script>
|
|
88
|
+
<script>
|
|
89
|
+
// Configure UI with plugin options
|
|
90
|
+
window.__UI_CONFIG__ = ${safeJsonStringify(config)};
|
|
91
|
+
</script>
|
|
92
|
+
<script type="module" src="${config.basename}/schemas-entry.js"></script>
|
|
93
|
+
<script type="module" src="${config.basename}/puck-entry.js"></script>
|
|
94
|
+
<script type="module" src="${config.basename}/content-listener.js"></script>
|
|
95
|
+
</head>
|
|
96
|
+
<body>
|
|
97
|
+
<div id="root"></div>
|
|
98
|
+
<script type="module" src="${config.basename}/cms-spa-entry.js"></script>
|
|
99
|
+
</body>
|
|
100
|
+
</html>`;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Load the HTML at runtime (production only)
|
|
104
|
+
*/
|
|
105
|
+
async function loadIndexHtml() {
|
|
106
|
+
const spaDir = join(cmsSpaPath, 'dist/spa');
|
|
107
|
+
const { readdir } = await import('node:fs/promises');
|
|
108
|
+
const files = await readdir(spaDir);
|
|
109
|
+
const htmlFile = files.find((f) => f.startsWith('index.') && f.endsWith('.html'));
|
|
110
|
+
if (!htmlFile) {
|
|
111
|
+
throw new Error('No index.html found in @conloca/cms-spa dist/spa');
|
|
112
|
+
}
|
|
113
|
+
const htmlPath = join(spaDir, htmlFile);
|
|
114
|
+
const html = await readFile(htmlPath, 'utf-8');
|
|
115
|
+
return html;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handle SPA requests - serve CMS admin interface
|
|
119
|
+
*/
|
|
120
|
+
async function handleSpa(params, request) {
|
|
121
|
+
// The path parameter is an array for [...path] routes
|
|
122
|
+
const pathArray = params.path;
|
|
123
|
+
const path = Array.isArray(pathArray) ? pathArray.join('/') : pathArray || '';
|
|
124
|
+
// For the root path or any path without an extension, serve the HTML
|
|
125
|
+
if (!path || !path.includes('.')) {
|
|
126
|
+
try {
|
|
127
|
+
let html;
|
|
128
|
+
// In dev mode, generate HTML that loads source through Vite
|
|
129
|
+
// In production, load the pre-built HTML from cms-spa dist
|
|
130
|
+
if (import.meta.env.DEV) {
|
|
131
|
+
html = generateDevHtml(spaConfig);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
html = await loadIndexHtml();
|
|
135
|
+
// Inject CMS configuration and load virtual modules
|
|
136
|
+
const configScript = `
|
|
137
|
+
<script>
|
|
138
|
+
// Configure UI with plugin options
|
|
139
|
+
window.__UI_CONFIG__ = ${safeJsonStringify(spaConfig)};
|
|
140
|
+
</script>
|
|
141
|
+
<script type="module" src="${spaConfig.basename}/site-styles.js"></script>
|
|
142
|
+
<script type="module" src="${spaConfig.basename}/editor-styles.js"></script>
|
|
143
|
+
<script type="module" src="${spaConfig.basename}/schemas-entry.js"></script>
|
|
144
|
+
<script type="module" src="${spaConfig.basename}/puck-entry.js"></script>
|
|
145
|
+
<script type="module" src="${spaConfig.basename}/content-listener.js"></script>
|
|
146
|
+
`;
|
|
147
|
+
// Inject the script at the top to ensure config is available first
|
|
148
|
+
html = html.replace('<head>', `<head>${configScript}`);
|
|
149
|
+
}
|
|
150
|
+
return new Response(html, {
|
|
151
|
+
headers: {
|
|
152
|
+
'Content-Type': 'text/html',
|
|
153
|
+
'Cache-Control': 'no-store, must-revalidate',
|
|
154
|
+
'X-HMR': 'spa-page',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('Error loading CMS HTML:', error);
|
|
160
|
+
return new Response('CMS build not found. Run nx build @conloca/astro-cms', {
|
|
161
|
+
status: 500,
|
|
162
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// For asset requests, serve them from the cms-spa dist/spa directory
|
|
167
|
+
try {
|
|
168
|
+
const spaBase = join(cmsSpaPath, 'dist/spa');
|
|
169
|
+
const assetPath = join(spaBase, path);
|
|
170
|
+
if (!isPathWithinBase(spaBase, assetPath)) {
|
|
171
|
+
console.warn('[security] Path traversal attempt blocked:', path);
|
|
172
|
+
return new Response('Forbidden', { status: 403 });
|
|
173
|
+
}
|
|
174
|
+
const content = await readFile(assetPath);
|
|
175
|
+
// Determine content type from extension map with octet-stream fallback
|
|
176
|
+
const ext = path.substring(path.lastIndexOf('.'));
|
|
177
|
+
const contentType = SPA_MIME_TYPES[ext] ?? 'application/octet-stream';
|
|
178
|
+
return new Response(content, {
|
|
179
|
+
headers: {
|
|
180
|
+
'Content-Type': contentType,
|
|
181
|
+
'Cache-Control': import.meta.env.DEV ? 'no-store, must-revalidate' : 'public, max-age=31536000',
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return new Response('Not found', { status: 404 });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// ============================================================================
|
|
190
|
+
// Data Context Handler (from data-context-handler.ts)
|
|
191
|
+
// ============================================================================
|
|
192
|
+
/**
|
|
193
|
+
* Handle DataContext API requests - returns data bindings for CMS editor
|
|
194
|
+
*/
|
|
195
|
+
async function handleDataContext(request) {
|
|
196
|
+
try {
|
|
197
|
+
const url = new URL(request.url);
|
|
198
|
+
const pageId = url.searchParams.get('pageId');
|
|
199
|
+
if (!pageId) {
|
|
200
|
+
return jsonResponse({});
|
|
201
|
+
}
|
|
202
|
+
const config = routingConfig;
|
|
203
|
+
if (!config.enabled) {
|
|
204
|
+
return jsonResponse({});
|
|
205
|
+
}
|
|
206
|
+
// Find which route this page belongs to by loading the page manifest
|
|
207
|
+
// and matching its collection against route configs
|
|
208
|
+
const contentApi = await createContentAPI({
|
|
209
|
+
contentRoot: contentOptions.contentRoot,
|
|
210
|
+
canvasDir: contentOptions.canvasDir,
|
|
211
|
+
...localesFromEnv(),
|
|
212
|
+
});
|
|
213
|
+
const locale = contentOptions.locale;
|
|
214
|
+
// Get the page manifest to determine its collection
|
|
215
|
+
const content = await contentApi.getContent(pageId);
|
|
216
|
+
if (!content) {
|
|
217
|
+
return jsonResponse({});
|
|
218
|
+
}
|
|
219
|
+
const pageCollection = content.collection || 'pages';
|
|
220
|
+
// Find the route whose collection matches this page
|
|
221
|
+
const routeEntry = Object.entries(config.routes).find(([, routeConfig]) => routeConfig.collection === pageCollection);
|
|
222
|
+
if (!routeEntry) {
|
|
223
|
+
return jsonResponse({});
|
|
224
|
+
}
|
|
225
|
+
const [, routeConfig] = routeEntry;
|
|
226
|
+
const hasCollections = routeConfig.dataBindings?.collections?.length;
|
|
227
|
+
const hasPages = routeConfig.dataBindings?.pages?.prefix;
|
|
228
|
+
if (!hasCollections && !hasPages) {
|
|
229
|
+
return jsonResponse({});
|
|
230
|
+
}
|
|
231
|
+
// Build DataContext using the same logic as page-handler.astro
|
|
232
|
+
const collections = {};
|
|
233
|
+
let pages;
|
|
234
|
+
if (hasCollections && routeConfig.dataBindings?.collections) {
|
|
235
|
+
for (const collectionName of routeConfig.dataBindings.collections) {
|
|
236
|
+
try {
|
|
237
|
+
const bindingLocale = routeConfig.dataBindings.locale ?? locale;
|
|
238
|
+
collections[collectionName] = await getDataCollection(collectionName, bindingLocale);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
collections[collectionName] = [];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (hasPages && routeConfig.dataBindings?.pages) {
|
|
246
|
+
try {
|
|
247
|
+
const pagesConfig = routeConfig.dataBindings.pages;
|
|
248
|
+
pages = await getPagesByPrefix(pagesConfig.prefix, {
|
|
249
|
+
sort: pagesConfig.sort,
|
|
250
|
+
limit: pagesConfig.limit,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
pages = [];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const dataContext = {
|
|
258
|
+
collections,
|
|
259
|
+
pages,
|
|
260
|
+
locale: routeConfig.dataBindings.locale ?? locale,
|
|
261
|
+
siteName: contentOptions.siteName,
|
|
262
|
+
};
|
|
263
|
+
return jsonResponse({ dataContext });
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return jsonResponse({});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function jsonResponse(data) {
|
|
270
|
+
return new Response(JSON.stringify(data), {
|
|
271
|
+
status: 200,
|
|
272
|
+
headers: { 'Content-Type': 'application/json' },
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// Content API Handler (from content-api-handler.ts)
|
|
277
|
+
// ============================================================================
|
|
278
|
+
/**
|
|
279
|
+
* Handle Content API requests - delegates to Hono router
|
|
280
|
+
*/
|
|
281
|
+
async function handleContentApi(request, cfResult) {
|
|
282
|
+
const contentRoot = import.meta.env.CONLOCA_CONTENT_ROOT || './content';
|
|
283
|
+
const canvasDir = import.meta.env.CONLOCA_CANVAS_DIR || './canvas';
|
|
284
|
+
// FileSystemContentAPI.create() handles caching internally.
|
|
285
|
+
// mdxPages is read from sites.json by the content-api itself.
|
|
286
|
+
const contentApi = await FileSystemContentAPI.create({
|
|
287
|
+
contentRoot,
|
|
288
|
+
canvasDir,
|
|
289
|
+
...localesFromEnv(),
|
|
290
|
+
});
|
|
291
|
+
// Create the Hono router with assets and content root for git operations
|
|
292
|
+
const assetsPath = import.meta.env.CONLOCA_ASSETS_PATH || '';
|
|
293
|
+
const app = createContentAPIRouter(contentApi, {
|
|
294
|
+
...(assetsPath && { assetsPath }),
|
|
295
|
+
contentRoot,
|
|
296
|
+
});
|
|
297
|
+
// POST /mdx/compile — server-side MDX compilation for the browser preview.
|
|
298
|
+
// The route lives here (not in @conloca/content-api) because compileMDX is
|
|
299
|
+
// a renderer concern; content-api is purely storage. The browser sends raw
|
|
300
|
+
// MDX, we return a JavaScript function body that @mdx-js/mdx's run() can
|
|
301
|
+
// execute.
|
|
302
|
+
app.post('/mdx/compile', async (c) => {
|
|
303
|
+
let body;
|
|
304
|
+
try {
|
|
305
|
+
body = await c.req.json();
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return c.json({ error: { code: ErrorCodes.INVALID_REQUEST, message: 'Invalid JSON body' } }, 400);
|
|
309
|
+
}
|
|
310
|
+
const mdxContent = typeof body === 'object' && body !== null ? body.mdxContent : null;
|
|
311
|
+
if (!mdxContent || typeof mdxContent !== 'string') {
|
|
312
|
+
return c.json({
|
|
313
|
+
error: {
|
|
314
|
+
code: ErrorCodes.MISSING_REQUIRED_FIELD,
|
|
315
|
+
message: 'mdxContent string required',
|
|
316
|
+
details: { field: 'mdxContent' },
|
|
317
|
+
},
|
|
318
|
+
}, 400);
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const { code, metadata } = await compileMDX(mdxContent);
|
|
322
|
+
return c.json({ code, metadata });
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
const message = error instanceof Error ? error.message : 'Failed to compile MDX';
|
|
326
|
+
console.error('[CMS] /mdx/compile failed:', error);
|
|
327
|
+
return c.json({ error: { code: ErrorCodes.MDX_COMPILE_FAILED, message } }, 422);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
// Extract the path after the API base
|
|
331
|
+
const url = new URL(request.url);
|
|
332
|
+
// Find where /api/ appears in the pathname
|
|
333
|
+
const apiIndex = url.pathname.indexOf('/api/');
|
|
334
|
+
if (apiIndex === -1) {
|
|
335
|
+
return new Response('Invalid API path', { status: 400 });
|
|
336
|
+
}
|
|
337
|
+
const basePath = url.pathname.substring(0, apiIndex + 4); // Include '/api'
|
|
338
|
+
const path = url.pathname.substring(basePath.length) || '/';
|
|
339
|
+
// Pass user to Hono via headers for downstream use (needed for git commit attribution)
|
|
340
|
+
const headers = new Headers(request.headers);
|
|
341
|
+
if (cfResult.user) {
|
|
342
|
+
if (cfResult.user.email) {
|
|
343
|
+
headers.set('X-CF-User-Email', cfResult.user.email);
|
|
344
|
+
}
|
|
345
|
+
if (cfResult.user.sub) {
|
|
346
|
+
headers.set('X-CF-User-Sub', cfResult.user.sub);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// Create a new request with the correct path for Hono
|
|
350
|
+
// Note: duplex option is required for Node.js fetch when sending a body
|
|
351
|
+
// but not in the TypeScript RequestInit type
|
|
352
|
+
const honoRequest = new Request(new URL(path + url.search, 'http://localhost').href, {
|
|
353
|
+
method: request.method,
|
|
354
|
+
headers,
|
|
355
|
+
body: request.body,
|
|
356
|
+
...(request.body && { duplex: 'half' }),
|
|
357
|
+
});
|
|
358
|
+
// Let Hono handle the request
|
|
359
|
+
const response = await app.fetch(honoRequest);
|
|
360
|
+
// Return the Hono response
|
|
361
|
+
return new Response(response.body, {
|
|
362
|
+
status: response.status,
|
|
363
|
+
statusText: response.statusText,
|
|
364
|
+
headers: response.headers,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content';
|
|
2
|
+
export declare const ALL_BLOCKS_COLLECTION = "__conloca_blocks";
|
|
3
|
+
/**
|
|
4
|
+
* Options for createConlocaCollections().
|
|
5
|
+
*/
|
|
6
|
+
export interface CreateConlocaCollectionsOptions {
|
|
7
|
+
/** Path to content root directory. @default './content' */
|
|
8
|
+
contentRoot?: string;
|
|
9
|
+
/** Site name for multi-site setups. @default 'default' */
|
|
10
|
+
site?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Return type of createConlocaCollections().
|
|
14
|
+
*/
|
|
15
|
+
export interface ConlocaCollectionsResult {
|
|
16
|
+
/** Astro Content Collections definitions - export this as `collections` */
|
|
17
|
+
collections: Record<string, ReturnType<typeof defineCollection>>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
21
|
+
* Uses content-api to find collections that have content.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // src/content.config.ts
|
|
26
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
27
|
+
*
|
|
28
|
+
* export const { collections } = await createConlocaCollections();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createConlocaCollections(options?: CreateConlocaCollectionsOptions): Promise<ConlocaCollectionsResult>;
|
|
32
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKjD,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;CAClE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAsCnC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content';
|
|
2
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
3
|
+
import { blockMetaSchema, dataMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';
|
|
4
|
+
import { conlocaLoader } from './loader';
|
|
5
|
+
export const ALL_BLOCKS_COLLECTION = '__conloca_blocks';
|
|
6
|
+
/**
|
|
7
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
8
|
+
* Uses content-api to find collections that have content.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // src/content.config.ts
|
|
13
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
14
|
+
*
|
|
15
|
+
* export const { collections } = await createConlocaCollections();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export async function createConlocaCollections(options = {}) {
|
|
19
|
+
const { contentRoot = './content', site = 'default' } = options;
|
|
20
|
+
const api = await createContentAPI({ contentRoot });
|
|
21
|
+
const collections = {};
|
|
22
|
+
collections[ALL_BLOCKS_COLLECTION] = defineCollection({
|
|
23
|
+
loader: conlocaLoader({ contentRoot, site, kind: 'block' }),
|
|
24
|
+
schema: blockMetaSchema.passthrough(),
|
|
25
|
+
});
|
|
26
|
+
// Add block collections
|
|
27
|
+
for (const name of api.blocks.collections) {
|
|
28
|
+
collections[name] = defineCollection({
|
|
29
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'block' }),
|
|
30
|
+
// Cast needed: Astro uses Zod v3 BaseSchema types, our schemas are Zod v4
|
|
31
|
+
schema: blockMetaSchema.passthrough(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Add data collections
|
|
35
|
+
for (const name of api.data.collections) {
|
|
36
|
+
collections[name] = defineCollection({
|
|
37
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
|
|
38
|
+
schema: dataMetaSchema.passthrough(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Add page collections for this site
|
|
42
|
+
const siteCollections = api.getSite(site)?.collections ?? new Set();
|
|
43
|
+
for (const name of siteCollections) {
|
|
44
|
+
collections[name] = defineCollection({
|
|
45
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
|
|
46
|
+
schema: pageMetaSchema.passthrough(),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return { collections };
|
|
50
|
+
}
|
|
@@ -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-runtime").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,2CAsBnG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MDXBlockEvaluationResult } from '@conloca/mdx/node';
|
|
2
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
3
|
+
import type { ComponentType } from 'react';
|
|
4
|
+
interface MDXComponent {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
Component: ComponentType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Factory function to create a PageRenderer with MDX components baked in via closure.
|
|
11
|
+
*
|
|
12
|
+
* This approach avoids dangerouslySetInnerHTML by keeping React components as components
|
|
13
|
+
* throughout the rendering pipeline. Components are captured in the closure and don't
|
|
14
|
+
* need to be passed as props (which Astro can't serialize).
|
|
15
|
+
*
|
|
16
|
+
* @param config - The Puck configuration with component definitions
|
|
17
|
+
* @param data - Puck page data containing component tree
|
|
18
|
+
* @param mdxComponents - Array of evaluated MDX block results
|
|
19
|
+
* @returns A PageRenderer component with no props needed (components in closure)
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPageRendererWithBlocks(config: Config, data: Data, mdxComponents: (MDXBlockEvaluationResult | MDXComponent)[]): ComponentType;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=RenderWithBlocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderWithBlocks.d.ts","sourceRoot":"","sources":["../../../src/components/RenderWithBlocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAmB,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;CAC1B;AAyLD;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,CAAC,wBAAwB,GAAG,YAAY,CAAC,EAAE,GACzD,aAAa,CAOf"}
|