@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
package/README.md
CHANGED
|
@@ -5,6 +5,61 @@ managing content using Puck's drag-and-drop editor, allowing developers to creat
|
|
|
5
5
|
maintaining full control over their content structure. The CMS integrates seamlessly into your Astro development
|
|
6
6
|
workflow, accessible at `/__cms` routes without requiring authentication or complex setup.
|
|
7
7
|
|
|
8
|
+
## MDX component registry
|
|
9
|
+
|
|
10
|
+
Hosts can register JSX components (their own, or third-party ones like Starlight's `<Steps>`, `<Tabs>`, `<Card>`) with
|
|
11
|
+
the MDX editor so authors get typed insert affordances and optional auto-import injection. The registry is wired through
|
|
12
|
+
the same `schemasPath` option that already loads `pageSchemas` — add an `mdxComponents` export to the file and the CMS
|
|
13
|
+
picks it up at boot (and on HMR).
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// src/schemas.ts
|
|
17
|
+
import { defineMdxComponents } from '@conloca/astro-cms';
|
|
18
|
+
|
|
19
|
+
export const pageSchemas = {
|
|
20
|
+
/* existing entries */
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const mdxComponents = defineMdxComponents([
|
|
24
|
+
{
|
|
25
|
+
name: 'Steps',
|
|
26
|
+
kind: 'flow',
|
|
27
|
+
hasChildren: true,
|
|
28
|
+
insert: { label: 'Steps', description: 'Numbered step-by-step list', icon: 'list-ordered' },
|
|
29
|
+
defaults: { children: '1. First step\n2. Second step\n3. Third step' },
|
|
30
|
+
import: { from: '@astrojs/starlight/components' },
|
|
31
|
+
},
|
|
32
|
+
// …other components your site uses
|
|
33
|
+
]);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Starlight components are declared the same way as any other component — the CMS does not ship Starlight descriptors.
|
|
37
|
+
Copy the props you need from each component's source (e.g.
|
|
38
|
+
`node_modules/@astrojs/starlight/user-components/<Component>.astro`).
|
|
39
|
+
|
|
40
|
+
In the editor, registered components appear in two places:
|
|
41
|
+
|
|
42
|
+
- A slash menu, opened by typing `/` in the body. Filter by name, label, description, or keywords.
|
|
43
|
+
- A toolbar dropdown next to the admonition button, listing block-level (`kind: 'flow'`) components.
|
|
44
|
+
|
|
45
|
+
### Auto-import injection (and its pruning caveat)
|
|
46
|
+
|
|
47
|
+
Setting `import: { from: '<module>' }` on a descriptor opts the component into automatic import injection: whenever the
|
|
48
|
+
component appears in the document, the CMS save serializer emits the matching `import { Name } from '<module>'` line at
|
|
49
|
+
the top of the file (after frontmatter).
|
|
50
|
+
|
|
51
|
+
**Important: the editor rebuilds the import block on every save from components actually referenced in the tree.**
|
|
52
|
+
Imports for unused components are dropped. So are non-JSX imports — type imports, side-effect imports
|
|
53
|
+
(`import './styles.css'`), and helper-function imports — because the editor does not consider them "referred to" by a
|
|
54
|
+
JSX node. This is a hard constraint of the underlying `@mdxeditor/editor` export pipeline
|
|
55
|
+
([`exportMarkdownFromLexical.js:98-148`](../../node_modules/@mdxeditor/editor/dist/exportMarkdownFromLexical.js)), not a
|
|
56
|
+
policy choice.
|
|
57
|
+
|
|
58
|
+
For Starlight-flavored docs (where MDX only imports Starlight components from `@astrojs/starlight/components`) the
|
|
59
|
+
behavior matches authorial intent — imports follow usage. For richer MDX that relies on type or side-effect imports,
|
|
60
|
+
edit those files in your IDE rather than the CMS, or omit `import.from` from your descriptors so the editor does not
|
|
61
|
+
claim ownership of the import line.
|
|
62
|
+
|
|
8
63
|
## How Astro Integrations Are Built
|
|
9
64
|
|
|
10
65
|
Based on research of official Astro integrations:
|
|
@@ -131,12 +186,14 @@ React:
|
|
|
131
186
|
|
|
132
187
|
### How .astro Components Work
|
|
133
188
|
|
|
134
|
-
1. **Compilation Process**
|
|
189
|
+
1. **Compilation Process**
|
|
190
|
+
([astro/packages/astro/src/vite-plugin-astro/compile.ts](https://github.com/withastro/astro/blob/main/packages/astro/src/vite-plugin-astro/compile.ts)):
|
|
135
191
|
- .astro files are transformed by `@astrojs/compiler` into TypeScript/JavaScript
|
|
136
192
|
- The output is an `AstroComponentFactory` function, not a React component
|
|
137
193
|
- Components include metadata for hydration, slots, and server-side rendering
|
|
138
194
|
|
|
139
|
-
2. **Component Factory Structure**
|
|
195
|
+
2. **Component Factory Structure**
|
|
196
|
+
([astro/packages/astro/src/runtime/server/render/astro/factory.ts](https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/server/render/astro/factory.ts)):
|
|
140
197
|
|
|
141
198
|
```typescript
|
|
142
199
|
interface AstroComponentFactory {
|
|
@@ -147,7 +204,8 @@ React:
|
|
|
147
204
|
}
|
|
148
205
|
```
|
|
149
206
|
|
|
150
|
-
3. **Container API**
|
|
207
|
+
3. **Container API**
|
|
208
|
+
([astro/packages/astro/src/container/index.ts](https://github.com/withastro/astro/blob/main/packages/astro/src/container/index.ts)):
|
|
151
209
|
- Provides `experimental_AstroContainer` for programmatic rendering
|
|
152
210
|
- Can render .astro components to HTML strings via `renderToString()`
|
|
153
211
|
- Server-side only - returns static HTML, not React components
|
|
@@ -243,12 +301,14 @@ which can also be used in Astro pages via the React integration.
|
|
|
243
301
|
|
|
244
302
|
Based on analysis of the Astro source code:
|
|
245
303
|
|
|
246
|
-
1. **Compilation Pipeline**
|
|
304
|
+
1. **Compilation Pipeline**
|
|
305
|
+
([astro/packages/astro/src/vite-plugin-astro/index.ts](https://github.com/withastro/astro/blob/main/packages/astro/src/vite-plugin-astro/index.ts)):
|
|
247
306
|
- `@astrojs/compiler` transforms .astro files into JavaScript
|
|
248
307
|
- `vite-plugin-astro` orchestrates this compilation
|
|
249
308
|
- The plugin integrates with Vite's module system
|
|
250
309
|
|
|
251
|
-
2. **HMR Implementation**
|
|
310
|
+
2. **HMR Implementation**
|
|
311
|
+
([astro/packages/astro/src/vite-plugin-astro/hmr.ts](https://github.com/withastro/astro/blob/main/packages/astro/src/vite-plugin-astro/hmr.ts)):
|
|
252
312
|
- Vite watches for file changes and triggers `handleHotUpdate`
|
|
253
313
|
- Astro optimizes HMR for specific change types:
|
|
254
314
|
- Style-only changes: Only CSS virtual modules are invalidated
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { blockMetaSchema, dataMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
2
|
+
import { defineCollection } from "astro:content";
|
|
3
|
+
import { createContentAPI } from "@conloca/content-api/reader";
|
|
4
|
+
//#region src/loader.ts
|
|
5
|
+
/**
|
|
6
|
+
* Custom Astro content loader for Conloca CMS.
|
|
7
|
+
* Loads content from the Conloca content directory into Astro collections.
|
|
8
|
+
*/
|
|
9
|
+
function conlocaLoader(options) {
|
|
10
|
+
return {
|
|
11
|
+
name: "conloca-loader",
|
|
12
|
+
async load(context) {
|
|
13
|
+
const { store, parseData, generateDigest, logger } = context;
|
|
14
|
+
const api = await createContentAPI({ contentRoot: options.contentRoot });
|
|
15
|
+
const kind = options.kind ?? (options.collection === "blocks" ? "block" : "page");
|
|
16
|
+
const content = Array.from(api.listAllContent({
|
|
17
|
+
collection: options.collection,
|
|
18
|
+
kind,
|
|
19
|
+
site: kind === "page" ? options.site : void 0
|
|
20
|
+
}));
|
|
21
|
+
store.clear();
|
|
22
|
+
for (const manifest of content) {
|
|
23
|
+
if (kind === "page" && manifest.type === "mdx") continue;
|
|
24
|
+
for (const [locale, localeVersion] of Object.entries(manifest.locales)) {
|
|
25
|
+
if (!localeVersion) continue;
|
|
26
|
+
const entryId = `${manifest.id}/${locale}`;
|
|
27
|
+
let dataContent;
|
|
28
|
+
let mdxContent;
|
|
29
|
+
let puckData;
|
|
30
|
+
if (kind === "data") {
|
|
31
|
+
const fullContent = await api.getLocalized(manifest.id, locale);
|
|
32
|
+
if (fullContent?.localized.content?.data) dataContent = fullContent.localized.content.data;
|
|
33
|
+
} else if (kind === "block") {
|
|
34
|
+
const fullContent = await api.getLocalized(manifest.id, locale);
|
|
35
|
+
if (fullContent?.localized.content?.mdx) mdxContent = fullContent.localized.content.mdx;
|
|
36
|
+
} else if (kind === "page") {
|
|
37
|
+
const fullContent = await api.getLocalized(manifest.id, locale);
|
|
38
|
+
if (fullContent?.localized.content?.puckData) puckData = fullContent.localized.content.puckData;
|
|
39
|
+
}
|
|
40
|
+
const data = {
|
|
41
|
+
id: manifest.id,
|
|
42
|
+
locale,
|
|
43
|
+
...localeVersion.pathname && { pathname: localeVersion.pathname },
|
|
44
|
+
...localeVersion.name && { name: localeVersion.name },
|
|
45
|
+
...localeVersion.meta,
|
|
46
|
+
created: localeVersion.created,
|
|
47
|
+
modified: localeVersion.modified,
|
|
48
|
+
publishAt: localeVersion.publishAt,
|
|
49
|
+
unpublishAt: localeVersion.unpublishAt,
|
|
50
|
+
...dataContent && { data: dataContent }
|
|
51
|
+
};
|
|
52
|
+
if (mdxContent !== void 0) data.mdx = mdxContent;
|
|
53
|
+
if (puckData !== void 0) data.puckData = puckData;
|
|
54
|
+
const parsedData = await parseData({
|
|
55
|
+
id: entryId,
|
|
56
|
+
data
|
|
57
|
+
});
|
|
58
|
+
store.set({
|
|
59
|
+
id: entryId,
|
|
60
|
+
data: parsedData,
|
|
61
|
+
digest: generateDigest(localeVersion.etag)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
logger.info(`Loaded ${store.keys().length} entries from ${options.collection || `${kind} content`}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/collections.ts
|
|
71
|
+
const ALL_BLOCKS_COLLECTION = "__conloca_blocks";
|
|
72
|
+
/**
|
|
73
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
74
|
+
* Uses content-api to find collections that have content.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // src/content.config.ts
|
|
79
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
80
|
+
*
|
|
81
|
+
* export const { collections } = await createConlocaCollections();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async function createConlocaCollections(options = {}) {
|
|
85
|
+
const { contentRoot = "./content", site = "default" } = options;
|
|
86
|
+
const api = await createContentAPI({ contentRoot });
|
|
87
|
+
const collections = {};
|
|
88
|
+
collections[ALL_BLOCKS_COLLECTION] = defineCollection({
|
|
89
|
+
loader: conlocaLoader({
|
|
90
|
+
contentRoot,
|
|
91
|
+
site,
|
|
92
|
+
kind: "block"
|
|
93
|
+
}),
|
|
94
|
+
schema: blockMetaSchema.passthrough()
|
|
95
|
+
});
|
|
96
|
+
for (const name of api.blocks.collections) collections[name] = defineCollection({
|
|
97
|
+
loader: conlocaLoader({
|
|
98
|
+
collection: name,
|
|
99
|
+
contentRoot,
|
|
100
|
+
site,
|
|
101
|
+
kind: "block"
|
|
102
|
+
}),
|
|
103
|
+
schema: blockMetaSchema.passthrough()
|
|
104
|
+
});
|
|
105
|
+
for (const name of api.data.collections) collections[name] = defineCollection({
|
|
106
|
+
loader: conlocaLoader({
|
|
107
|
+
collection: name,
|
|
108
|
+
contentRoot,
|
|
109
|
+
site,
|
|
110
|
+
kind: "data"
|
|
111
|
+
}),
|
|
112
|
+
schema: dataMetaSchema.passthrough()
|
|
113
|
+
});
|
|
114
|
+
const siteCollections = api.getSite(site)?.collections ?? /* @__PURE__ */ new Set();
|
|
115
|
+
for (const name of siteCollections) collections[name] = defineCollection({
|
|
116
|
+
loader: conlocaLoader({
|
|
117
|
+
collection: name,
|
|
118
|
+
contentRoot,
|
|
119
|
+
site,
|
|
120
|
+
kind: "page"
|
|
121
|
+
}),
|
|
122
|
+
schema: pageMetaSchema.passthrough()
|
|
123
|
+
});
|
|
124
|
+
return { collections };
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { createConlocaCollections as n, conlocaLoader as r, ALL_BLOCKS_COLLECTION as t };
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=collections-Bd7EME4b.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-Bd7EME4b.mjs","names":[],"sources":["../src/loader.ts","../src/collections.ts"],"sourcesContent":["import { createContentAPI } from '@conloca/content-api/reader';\nimport type { Loader, LoaderContext } from 'astro/loaders';\n\nexport interface ConlocaLoaderOptions {\n collection?: string;\n contentRoot: string;\n site?: string;\n /** Collection kind. If not provided, defaults to 'block' for 'blocks' collection, 'page' otherwise. */\n kind?: 'page' | 'block' | 'data';\n}\n\n/**\n * Custom Astro content loader for Conloca CMS.\n * Loads content from the Conloca content directory into Astro collections.\n */\nexport function conlocaLoader(options: ConlocaLoaderOptions): Loader {\n return {\n name: 'conloca-loader',\n async load(context: LoaderContext): Promise<void> {\n const { store, parseData, generateDigest, logger } = context;\n\n // Create content API instance\n const api = await createContentAPI({ contentRoot: options.contentRoot });\n\n // Use provided kind, or fall back to inferring from collection name\n const kind = options.kind ?? (options.collection === 'blocks' ? 'block' : 'page');\n\n // List all content for this collection\n // Note: blocks and data don't have a site, so only pass site for pages\n const content = Array.from(\n api.listAllContent({\n collection: options.collection,\n kind,\n site: kind === 'page' ? options.site : undefined,\n }),\n );\n\n store.clear();\n\n for (const manifest of content) {\n // Skip type:'mdx' pages — they're owned by an external renderer\n // (any Astro loader reading from a site's `mdxPages` path in\n // sites.json, such as Starlight's stock docsLoader) and would\n // otherwise collide with the puck-page route handler.\n if (kind === 'page' && manifest.type === 'mdx') continue;\n\n for (const [locale, localeVersion] of Object.entries(manifest.locales)) {\n if (!localeVersion) continue;\n\n const entryId = `${manifest.id}/${locale}`;\n\n // For data and page collections, fetch full content to get the actual content fields\n let dataContent: Record<string, unknown> | undefined;\n let mdxContent: string | undefined;\n let puckData: unknown | undefined;\n\n if (kind === 'data') {\n const fullContent = await api.getLocalized(manifest.id, locale);\n if (fullContent?.localized.content?.data) {\n dataContent = fullContent.localized.content.data;\n }\n } else if (kind === 'block') {\n const fullContent = await api.getLocalized(manifest.id, locale);\n if (fullContent?.localized.content?.mdx) {\n mdxContent = fullContent.localized.content.mdx;\n }\n } else if (kind === 'page') {\n // For page collections, fetch full content to get puckData\n // This enables getCollection('pages') to return entries with puckData included\n const fullContent = await api.getLocalized(manifest.id, locale);\n if (fullContent?.localized.content?.puckData) {\n puckData = fullContent.localized.content.puckData;\n }\n }\n\n const data: Record<string, unknown> = {\n id: manifest.id,\n locale,\n ...(localeVersion.pathname && { pathname: localeVersion.pathname }),\n ...(localeVersion.name && { name: localeVersion.name }),\n ...localeVersion.meta,\n created: localeVersion.created,\n modified: localeVersion.modified,\n publishAt: localeVersion.publishAt,\n unpublishAt: localeVersion.unpublishAt,\n // Include the data content for data collections\n ...(dataContent && { data: dataContent }),\n };\n\n if (mdxContent !== undefined) {\n data.mdx = mdxContent;\n }\n\n // Include puckData for page collections (added separately to avoid spread type issues)\n if (puckData !== undefined) {\n data.puckData = puckData;\n }\n\n const parsedData = await parseData({ id: entryId, data });\n\n store.set({\n id: entryId,\n data: parsedData,\n digest: generateDigest(localeVersion.etag),\n });\n }\n }\n\n logger.info(`Loaded ${store.keys().length} entries from ${options.collection || `${kind} content`}`);\n },\n };\n}\n","import { defineCollection } from 'astro:content';\nimport { createContentAPI } from '@conloca/content-api/reader';\nimport { blockMetaSchema, dataMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';\nimport { conlocaLoader } from './loader';\n\nexport const ALL_BLOCKS_COLLECTION = '__conloca_blocks';\n\n/**\n * Options for createConlocaCollections().\n */\nexport interface CreateConlocaCollectionsOptions {\n /** Path to content root directory. @default './content' */\n contentRoot?: string;\n /** Site name for multi-site setups. @default 'default' */\n site?: string;\n}\n\n/**\n * Return type of createConlocaCollections().\n */\nexport interface ConlocaCollectionsResult {\n /** Astro Content Collections definitions - export this as `collections` */\n collections: Record<string, ReturnType<typeof defineCollection>>;\n}\n\n/**\n * Creates Astro Content Collections by discovering from indexed content.\n * Uses content-api to find collections that have content.\n *\n * @example\n * ```typescript\n * // src/content.config.ts\n * import { createConlocaCollections } from '@conloca/astro-cms/node/content';\n *\n * export const { collections } = await createConlocaCollections();\n * ```\n */\nexport async function createConlocaCollections(\n options: CreateConlocaCollectionsOptions = {},\n): Promise<ConlocaCollectionsResult> {\n const { contentRoot = './content', site = 'default' } = options;\n\n const api = await createContentAPI({ contentRoot });\n const collections: Record<string, ReturnType<typeof defineCollection>> = {};\n\n collections[ALL_BLOCKS_COLLECTION] = defineCollection({\n loader: conlocaLoader({ contentRoot, site, kind: 'block' }),\n schema: blockMetaSchema.passthrough() as never,\n });\n\n // Add block collections\n for (const name of api.blocks.collections) {\n collections[name] = defineCollection({\n loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'block' }),\n // Cast needed: Astro uses Zod v3 BaseSchema types, our schemas are Zod v4\n schema: blockMetaSchema.passthrough() as never,\n });\n }\n\n // Add data collections\n for (const name of api.data.collections) {\n collections[name] = defineCollection({\n loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),\n schema: dataMetaSchema.passthrough() as never,\n });\n }\n\n // Add page collections for this site\n const siteCollections = api.getSite(site)?.collections ?? new Set<string>();\n for (const name of siteCollections) {\n collections[name] = defineCollection({\n loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),\n schema: pageMetaSchema.passthrough() as never,\n });\n }\n\n return { collections };\n}\n"],"mappings":"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"}
|
package/dist/collections.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCollection } from "astro:content";
|
|
2
|
-
|
|
3
2
|
//#region src/collections.d.ts
|
|
3
|
+
declare const ALL_BLOCKS_COLLECTION = "__conloca_blocks";
|
|
4
4
|
/**
|
|
5
5
|
* Options for createConlocaCollections().
|
|
6
6
|
*/
|
|
@@ -24,12 +24,12 @@ interface ConlocaCollectionsResult {
|
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
26
|
* // src/content.config.ts
|
|
27
|
-
* import { createConlocaCollections } from '@conloca/astro-cms/
|
|
27
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
28
28
|
*
|
|
29
29
|
* export const { collections } = await createConlocaCollections();
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
declare function createConlocaCollections(options?: CreateConlocaCollectionsOptions): Promise<ConlocaCollectionsResult>;
|
|
33
33
|
//#endregion
|
|
34
|
-
export { ConlocaCollectionsResult, CreateConlocaCollectionsOptions, createConlocaCollections };
|
|
34
|
+
export { ALL_BLOCKS_COLLECTION, ConlocaCollectionsResult, CreateConlocaCollectionsOptions, createConlocaCollections };
|
|
35
35
|
//# sourceMappingURL=collections.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.mts","names":[],"sources":["../src/collections.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"collections.d.mts","names":[],"sources":["../src/collections.ts"],"mappings":";;cAKa;;;;UAKI;;EAEf;;EAEA;;;;;UAMe;;EAEf,aAAa,eAAe,kBAAkB;;;;;;;;;;;;;;iBAe1B,yBACpB,UAAS,kCACR,QAAQ"}
|
package/dist/collections.mjs
CHANGED
|
@@ -1,56 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { createContentAPI } from "@conloca/content-api/node";
|
|
4
|
-
import { defineCollection } from "astro:content";
|
|
5
|
-
|
|
6
|
-
//#region src/collections.ts
|
|
7
|
-
/**
|
|
8
|
-
* Creates Astro Content Collections by discovering from indexed content.
|
|
9
|
-
* Uses content-api to find collections that have content.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // src/content.config.ts
|
|
14
|
-
* import { createConlocaCollections } from '@conloca/astro-cms/collections';
|
|
15
|
-
*
|
|
16
|
-
* export const { collections } = await createConlocaCollections();
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
async function createConlocaCollections(options = {}) {
|
|
20
|
-
const { contentRoot = "./content", site = "default" } = options;
|
|
21
|
-
const api = await createContentAPI({ contentRoot });
|
|
22
|
-
const collections = {};
|
|
23
|
-
for (const name of api.blocks.collections) collections[name] = defineCollection({
|
|
24
|
-
loader: conlocaLoader({
|
|
25
|
-
collection: name,
|
|
26
|
-
contentRoot,
|
|
27
|
-
site,
|
|
28
|
-
kind: "block"
|
|
29
|
-
}),
|
|
30
|
-
schema: blockMetaSchema
|
|
31
|
-
});
|
|
32
|
-
for (const name of api.data.collections) collections[name] = defineCollection({
|
|
33
|
-
loader: conlocaLoader({
|
|
34
|
-
collection: name,
|
|
35
|
-
contentRoot,
|
|
36
|
-
site,
|
|
37
|
-
kind: "data"
|
|
38
|
-
}),
|
|
39
|
-
schema: dataMetaSchema
|
|
40
|
-
});
|
|
41
|
-
const siteCollections = api.getSite(site)?.collections ?? /* @__PURE__ */ new Set();
|
|
42
|
-
for (const name of siteCollections) collections[name] = defineCollection({
|
|
43
|
-
loader: conlocaLoader({
|
|
44
|
-
collection: name,
|
|
45
|
-
contentRoot,
|
|
46
|
-
site,
|
|
47
|
-
kind: "page"
|
|
48
|
-
}),
|
|
49
|
-
schema: pageMetaSchema.passthrough()
|
|
50
|
-
});
|
|
51
|
-
return { collections };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
export { createConlocaCollections };
|
|
56
|
-
//# sourceMappingURL=collections.mjs.map
|
|
1
|
+
import { n as createConlocaCollections, t as ALL_BLOCKS_COLLECTION } from "./collections-Bd7EME4b.mjs";
|
|
2
|
+
export { ALL_BLOCKS_COLLECTION, createConlocaCollections };
|
package/dist/components.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
1
|
+
import { MDXBlockEvaluationResult, evaluateMDXBlocks } from "@conloca/mdx/node";
|
|
3
2
|
import { ComponentType } from "react";
|
|
4
|
-
|
|
3
|
+
import { Config, Data } from "@puckeditor/core";
|
|
5
4
|
//#region src/components/RenderWithBlocks.d.ts
|
|
6
5
|
interface MDXComponent {
|
|
7
6
|
id: string;
|
|
@@ -17,31 +16,10 @@ interface MDXComponent {
|
|
|
17
16
|
*
|
|
18
17
|
* @param config - The Puck configuration with component definitions
|
|
19
18
|
* @param data - Puck page data containing component tree
|
|
20
|
-
* @param mdxComponents - Array of evaluated MDX
|
|
19
|
+
* @param mdxComponents - Array of evaluated MDX block results
|
|
21
20
|
* @returns A PageRenderer component with no props needed (components in closure)
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```astro
|
|
25
|
-
* ---
|
|
26
|
-
* import { createPageRendererWithBlocks } from '@conloca/astro-cms/components';
|
|
27
|
-
* import { evaluateMDXBlocks } from '@conloca/mdx/node';
|
|
28
|
-
* import { createContentAPI } from '@conloca/content-api/node';
|
|
29
|
-
* import config from '../puck.config';
|
|
30
|
-
*
|
|
31
|
-
* const api = await createContentAPI({ contentRoot: './content' });
|
|
32
|
-
* const mdxComponents = await evaluateMDXBlocks(api, 'en');
|
|
33
|
-
* const PageRenderer = createPageRendererWithBlocks(config, puckData, mdxComponents);
|
|
34
|
-
* ---
|
|
35
|
-
* <PageRenderer />
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* Benefits:
|
|
39
|
-
* - No dangerouslySetInnerHTML (safer, no XSS risk from HTML strings)
|
|
40
|
-
* - No string conversion round-trip (more efficient)
|
|
41
|
-
* - Type safe React components throughout
|
|
42
|
-
* - Normal React rendering with proper escaping
|
|
43
21
|
*/
|
|
44
|
-
declare function createPageRendererWithBlocks(config: Config, data: Data, mdxComponents: MDXComponent[]): ComponentType;
|
|
22
|
+
declare function createPageRendererWithBlocks(config: Config, data: Data, mdxComponents: (MDXBlockEvaluationResult | MDXComponent)[]): ComponentType;
|
|
45
23
|
//#endregion
|
|
46
24
|
//#region src/components/RenderWithHydration.d.ts
|
|
47
25
|
interface RenderWithHydrationProps {
|
|
@@ -57,10 +35,7 @@ interface RenderWithHydrationProps {
|
|
|
57
35
|
*
|
|
58
36
|
* Non-hydratable components render without any wrapper overhead.
|
|
59
37
|
*/
|
|
60
|
-
declare function RenderWithHydration({
|
|
61
|
-
config,
|
|
62
|
-
data
|
|
63
|
-
}: RenderWithHydrationProps): react_jsx_runtime0.JSX.Element;
|
|
38
|
+
declare function RenderWithHydration({ config, data }: RenderWithHydrationProps): import("react/jsx-runtime").JSX.Element;
|
|
64
39
|
//#endregion
|
|
65
|
-
export { RenderWithHydration, createPageRendererWithBlocks };
|
|
40
|
+
export { RenderWithHydration, createPageRendererWithBlocks, evaluateMDXBlocks };
|
|
66
41
|
//# sourceMappingURL=components.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.mts","names":[],"sources":["../src/components/RenderWithBlocks.tsx","../src/components/RenderWithHydration.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"components.d.mts","names":[],"sources":["../src/components/RenderWithBlocks.tsx","../src/components/RenderWithHydration.tsx"],"mappings":";;;;UAQU;EACR;EACA;EACA,WAAW;;;;;;;;;;;;;;iBAsMG,6BACd,QAAQ,QACR,MAAM,MACN,gBAAgB,2BAA2B,kBAC1C;;;UChNO;EACR,QAAQ;EACR,MAAM;;;;;;;;;;;iBAYQ,sBAAsB,QAAQ,QAAQ,uDAAwB,IAAA"}
|
package/dist/components.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { i as isHydratable, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { i as isHydratable, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-BHoNpzH6.mjs";
|
|
2
|
+
import { evaluateMDXBlocks } from "@conloca/mdx/node";
|
|
3
|
+
import { Render } from "@puckeditor/core/rsc";
|
|
4
|
+
import cn from "clsx";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
//#region src/components/HydrationWrapper.tsx
|
|
6
7
|
/**
|
|
7
8
|
* Wraps hydratable components with data attributes for browser hydration.
|
|
@@ -12,15 +13,15 @@ import { Fragment, jsx } from "react/jsx-runtime";
|
|
|
12
13
|
*/
|
|
13
14
|
function HydrationWrapper({ componentName, strategy, props, children }) {
|
|
14
15
|
if (strategy === "none") return /* @__PURE__ */ jsx(Fragment, { children });
|
|
16
|
+
const { puck: _puck, ...hydrateProps } = props;
|
|
15
17
|
return /* @__PURE__ */ jsx("div", {
|
|
16
18
|
style: { display: "contents" },
|
|
17
19
|
"data-hydrate": componentName,
|
|
18
20
|
"data-hydrate-strategy": strategy,
|
|
19
|
-
"data-props": serializeProps(
|
|
21
|
+
"data-props": serializeProps(hydrateProps),
|
|
20
22
|
children
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
//#endregion
|
|
25
26
|
//#region src/components/RenderWithHydration.tsx
|
|
26
27
|
/**
|
|
@@ -54,32 +55,69 @@ function RenderWithHydration({ config, data }) {
|
|
|
54
55
|
data
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
|
-
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/components/RenderWithBlocks.tsx
|
|
60
|
+
function isRenderableBlock(block) {
|
|
61
|
+
return "Component" in block && !("ok" in block);
|
|
62
|
+
}
|
|
63
|
+
const contentBlockWidthClasses = {
|
|
64
|
+
narrow: "max-w-3xl",
|
|
65
|
+
default: "max-w-4xl"
|
|
66
|
+
};
|
|
67
|
+
const contentBlockToneClasses = {
|
|
68
|
+
transparent: "",
|
|
69
|
+
subtle: "rounded-3xl border border-surface-200/80 bg-surface-100/70 p-6 sm:p-8 dark:border-surface-800/60 dark:bg-surface-900/50"
|
|
70
|
+
};
|
|
71
|
+
function createFailedBlockComponent(block) {
|
|
72
|
+
return function FailedBlockComponent() {
|
|
73
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: "p-4 bg-red-50 border border-red-200 rounded text-red-600",
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsx("p", {
|
|
77
|
+
className: "font-semibold mb-2",
|
|
78
|
+
children: "MDX Block Error"
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ jsxs("p", {
|
|
81
|
+
className: "text-sm",
|
|
82
|
+
children: ["Block: ", block.id]
|
|
83
|
+
}),
|
|
84
|
+
/* @__PURE__ */ jsx("p", {
|
|
85
|
+
className: "text-xs mt-2",
|
|
86
|
+
children: block.error.message
|
|
87
|
+
})
|
|
88
|
+
]
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function resolveRenderableBlocks(blocks) {
|
|
93
|
+
return blocks.map((block) => {
|
|
94
|
+
if (isRenderableBlock(block)) return block;
|
|
95
|
+
if (block.ok) return block;
|
|
96
|
+
return {
|
|
97
|
+
id: block.id,
|
|
98
|
+
title: block.title,
|
|
99
|
+
Component: createFailedBlockComponent(block)
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
60
103
|
/**
|
|
61
104
|
* Internal component for rendering Puck pages with MDX blocks.
|
|
62
105
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
106
|
+
* Enhances the Puck config by:
|
|
107
|
+
* 1. Registering each MDX block as a dynamic Puck component (`Block_{id}`)
|
|
108
|
+
* 2. Overriding ContentBlockSection's render to resolve blockId → actual MDX content
|
|
65
109
|
*
|
|
66
110
|
* MDX blocks are passed as React components (not HTML strings), which:
|
|
67
111
|
* - Avoids dangerouslySetInnerHTML security risks
|
|
68
112
|
* - More efficient (no HTML conversion round-trip)
|
|
69
113
|
* - Type-safe with proper React component types
|
|
70
114
|
*
|
|
71
|
-
* **Note:** This function is internal. Use `createPageRendererWithBlocks` instead,
|
|
72
|
-
* which provides a factory pattern to handle the closure correctly.
|
|
73
|
-
*
|
|
74
115
|
* @internal
|
|
75
|
-
* @param props - Component props
|
|
76
|
-
* @param props.config - Base Puck configuration
|
|
77
|
-
* @param props.data - Puck page data containing component tree
|
|
78
|
-
* @param props.mdxComponents - Array of evaluated MDX React components
|
|
79
116
|
*/
|
|
80
117
|
function RenderWithBlocks({ config, data, mdxComponents }) {
|
|
81
118
|
const blockComponents = {};
|
|
82
119
|
const blockCategoryList = [];
|
|
120
|
+
const blockComponentMap = new Map(mdxComponents.map((block) => [block.id, block]));
|
|
83
121
|
mdxComponents.forEach((block) => {
|
|
84
122
|
const componentKey = `Block_${block.id}`;
|
|
85
123
|
const BlockComponent = block.Component;
|
|
@@ -89,7 +127,7 @@ function RenderWithBlocks({ config, data, mdxComponents }) {
|
|
|
89
127
|
defaultProps: {},
|
|
90
128
|
render: () => {
|
|
91
129
|
return /* @__PURE__ */ jsx("div", {
|
|
92
|
-
className: "mdx-content prose
|
|
130
|
+
className: "mdx-content conloca-prose max-w-none",
|
|
93
131
|
children: /* @__PURE__ */ jsx(BlockComponent, {})
|
|
94
132
|
});
|
|
95
133
|
}
|
|
@@ -97,8 +135,44 @@ function RenderWithBlocks({ config, data, mdxComponents }) {
|
|
|
97
135
|
blockCategoryList.push(componentKey);
|
|
98
136
|
});
|
|
99
137
|
const existingCategories = config.categories || {};
|
|
138
|
+
const existingComponents = config.components || {};
|
|
139
|
+
const contentBlockSection = existingComponents.ContentBlockSection;
|
|
140
|
+
const enhancedContentBlockSection = contentBlockSection ? {
|
|
141
|
+
...contentBlockSection,
|
|
142
|
+
render: ({ blockId, label, title, subtitle, tone = "transparent", width = "default" }) => {
|
|
143
|
+
const SelectedBlockComponent = blockComponentMap.get(blockId)?.Component;
|
|
144
|
+
return /* @__PURE__ */ jsx("section", {
|
|
145
|
+
className: "pb-16 sm:pb-20",
|
|
146
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
147
|
+
className: cn("mx-auto px-4 sm:px-6 lg:px-8", contentBlockWidthClasses[width]),
|
|
148
|
+
children: [
|
|
149
|
+
label ? /* @__PURE__ */ jsx("p", {
|
|
150
|
+
className: "mb-4 text-sm font-medium uppercase tracking-[0.18em] text-brand-700 dark:text-brand-300",
|
|
151
|
+
children: label
|
|
152
|
+
}) : null,
|
|
153
|
+
title && /* @__PURE__ */ jsx("h2", {
|
|
154
|
+
className: "text-2xl sm:text-3xl font-bold text-surface-900 dark:text-white mb-4",
|
|
155
|
+
children: title
|
|
156
|
+
}),
|
|
157
|
+
subtitle && /* @__PURE__ */ jsx("p", {
|
|
158
|
+
className: "text-surface-500 dark:text-surface-400 text-sm leading-relaxed mb-6",
|
|
159
|
+
children: subtitle
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ jsx("div", {
|
|
162
|
+
className: cn(contentBlockToneClasses[tone]),
|
|
163
|
+
children: SelectedBlockComponent && /* @__PURE__ */ jsx("div", {
|
|
164
|
+
className: "mdx-content conloca-prose max-w-none",
|
|
165
|
+
children: /* @__PURE__ */ jsx(SelectedBlockComponent, {})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
} : void 0;
|
|
100
173
|
const mergedComponents = {
|
|
101
|
-
...
|
|
174
|
+
...existingComponents,
|
|
175
|
+
...enhancedContentBlockSection && { ContentBlockSection: enhancedContentBlockSection },
|
|
102
176
|
...blockComponents
|
|
103
177
|
};
|
|
104
178
|
const enhancedConfig = {
|
|
@@ -112,10 +186,11 @@ function RenderWithBlocks({ config, data, mdxComponents }) {
|
|
|
112
186
|
},
|
|
113
187
|
components: mergedComponents
|
|
114
188
|
};
|
|
115
|
-
|
|
189
|
+
if (hasHydratableComponents(data, enhancedConfig)) return /* @__PURE__ */ jsx(RenderWithHydration, {
|
|
116
190
|
config: enhancedConfig,
|
|
117
191
|
data
|
|
118
|
-
})
|
|
192
|
+
});
|
|
193
|
+
return /* @__PURE__ */ jsx(Render, {
|
|
119
194
|
config: enhancedConfig,
|
|
120
195
|
data
|
|
121
196
|
});
|
|
@@ -129,40 +204,20 @@ function RenderWithBlocks({ config, data, mdxComponents }) {
|
|
|
129
204
|
*
|
|
130
205
|
* @param config - The Puck configuration with component definitions
|
|
131
206
|
* @param data - Puck page data containing component tree
|
|
132
|
-
* @param mdxComponents - Array of evaluated MDX
|
|
207
|
+
* @param mdxComponents - Array of evaluated MDX block results
|
|
133
208
|
* @returns A PageRenderer component with no props needed (components in closure)
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```astro
|
|
137
|
-
* ---
|
|
138
|
-
* import { createPageRendererWithBlocks } from '@conloca/astro-cms/components';
|
|
139
|
-
* import { evaluateMDXBlocks } from '@conloca/mdx/node';
|
|
140
|
-
* import { createContentAPI } from '@conloca/content-api/node';
|
|
141
|
-
* import config from '../puck.config';
|
|
142
|
-
*
|
|
143
|
-
* const api = await createContentAPI({ contentRoot: './content' });
|
|
144
|
-
* const mdxComponents = await evaluateMDXBlocks(api, 'en');
|
|
145
|
-
* const PageRenderer = createPageRendererWithBlocks(config, puckData, mdxComponents);
|
|
146
|
-
* ---
|
|
147
|
-
* <PageRenderer />
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* Benefits:
|
|
151
|
-
* - No dangerouslySetInnerHTML (safer, no XSS risk from HTML strings)
|
|
152
|
-
* - No string conversion round-trip (more efficient)
|
|
153
|
-
* - Type safe React components throughout
|
|
154
|
-
* - Normal React rendering with proper escaping
|
|
155
209
|
*/
|
|
156
210
|
function createPageRendererWithBlocks(config, data, mdxComponents) {
|
|
211
|
+
const renderableBlocks = resolveRenderableBlocks(mdxComponents);
|
|
157
212
|
return function PageRendererWithBlocks() {
|
|
158
213
|
return /* @__PURE__ */ jsx(RenderWithBlocks, {
|
|
159
214
|
config,
|
|
160
215
|
data,
|
|
161
|
-
mdxComponents
|
|
216
|
+
mdxComponents: renderableBlocks
|
|
162
217
|
});
|
|
163
218
|
};
|
|
164
219
|
}
|
|
165
|
-
|
|
166
220
|
//#endregion
|
|
167
|
-
export { RenderWithHydration, createPageRendererWithBlocks };
|
|
221
|
+
export { RenderWithHydration, createPageRendererWithBlocks, evaluateMDXBlocks };
|
|
222
|
+
|
|
168
223
|
//# sourceMappingURL=components.mjs.map
|