@conloca/astro-cms 0.1.15 → 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 +0 -1
- package/dist/collections.d.mts.map +1 -1
- package/dist/collections.mjs +1 -64
- package/dist/components.d.mts +2 -7
- package/dist/components.d.mts.map +1 -1
- package/dist/components.mjs +3 -6
- 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 +6 -37
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/cms-handler.d.mts +0 -1
- package/dist/internal/cms-handler.d.mts.map +1 -1
- package/dist/internal/cms-handler.mjs +55 -8
- package/dist/internal/cms-handler.mjs.map +1 -1
- 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 +0 -1
- package/dist/node/content.d.mts.map +1 -1
- 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 -4
- package/dist/node/index.d.mts +151 -3
- package/dist/node/index.d.mts.map +1 -1
- 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 +1857 -97
- package/dist/node/index.mjs.map +1 -1
- package/dist/{serialize-props-Dhv_MnkY.mjs → serialize-props-BHoNpzH6.mjs} +2 -3
- package/dist/{serialize-props-Dhv_MnkY.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-CVQNmPxF.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-EzyzBQ-Y.mjs → withHydration-C256ox_6.mjs} +2 -2
- package/dist/{withHydration-EzyzBQ-Y.mjs.map → withHydration-C256ox_6.mjs.map} +1 -1
- package/dist/{withHydration-HIvO9ysY.d.mts → withHydration-DkKpkmzJ.d.mts} +1 -2
- package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
- package/package.json +82 -26
- package/dist/collections.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-HIvO9ysY.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 +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,65 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { blockMetaSchema, dataMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
3
|
-
import { defineCollection } from "astro:content";
|
|
4
|
-
import { createContentAPI } from "@conloca/content-api/reader";
|
|
5
|
-
|
|
6
|
-
//#region src/collections.ts
|
|
7
|
-
const ALL_BLOCKS_COLLECTION = "__conloca_blocks";
|
|
8
|
-
/**
|
|
9
|
-
* Creates Astro Content Collections by discovering from indexed content.
|
|
10
|
-
* Uses content-api to find collections that have content.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // src/content.config.ts
|
|
15
|
-
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
16
|
-
*
|
|
17
|
-
* export const { collections } = await createConlocaCollections();
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
async function createConlocaCollections(options = {}) {
|
|
21
|
-
const { contentRoot = "./content", site = "default" } = options;
|
|
22
|
-
const api = await createContentAPI({ contentRoot });
|
|
23
|
-
const collections = {};
|
|
24
|
-
collections[ALL_BLOCKS_COLLECTION] = defineCollection({
|
|
25
|
-
loader: conlocaLoader({
|
|
26
|
-
contentRoot,
|
|
27
|
-
site,
|
|
28
|
-
kind: "block"
|
|
29
|
-
}),
|
|
30
|
-
schema: blockMetaSchema.passthrough()
|
|
31
|
-
});
|
|
32
|
-
for (const name of api.blocks.collections) collections[name] = defineCollection({
|
|
33
|
-
loader: conlocaLoader({
|
|
34
|
-
collection: name,
|
|
35
|
-
contentRoot,
|
|
36
|
-
site,
|
|
37
|
-
kind: "block"
|
|
38
|
-
}),
|
|
39
|
-
schema: blockMetaSchema.passthrough()
|
|
40
|
-
});
|
|
41
|
-
for (const name of api.data.collections) collections[name] = defineCollection({
|
|
42
|
-
loader: conlocaLoader({
|
|
43
|
-
collection: name,
|
|
44
|
-
contentRoot,
|
|
45
|
-
site,
|
|
46
|
-
kind: "data"
|
|
47
|
-
}),
|
|
48
|
-
schema: dataMetaSchema.passthrough()
|
|
49
|
-
});
|
|
50
|
-
const siteCollections = api.getSite(site)?.collections ?? /* @__PURE__ */ new Set();
|
|
51
|
-
for (const name of siteCollections) collections[name] = defineCollection({
|
|
52
|
-
loader: conlocaLoader({
|
|
53
|
-
collection: name,
|
|
54
|
-
contentRoot,
|
|
55
|
-
site,
|
|
56
|
-
kind: "page"
|
|
57
|
-
}),
|
|
58
|
-
schema: pageMetaSchema.passthrough()
|
|
59
|
-
});
|
|
60
|
-
return { collections };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
1
|
+
import { n as createConlocaCollections, t as ALL_BLOCKS_COLLECTION } from "./collections-Bd7EME4b.mjs";
|
|
64
2
|
export { ALL_BLOCKS_COLLECTION, createConlocaCollections };
|
|
65
|
-
//# sourceMappingURL=collections.mjs.map
|
package/dist/components.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { MDXBlockEvaluationResult, evaluateMDXBlocks } from "@conloca/mdx/node";
|
|
2
|
-
import { Config, Data } from "@puckeditor/core";
|
|
3
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
2
|
import { ComponentType } from "react";
|
|
5
|
-
|
|
3
|
+
import { Config, Data } from "@puckeditor/core";
|
|
6
4
|
//#region src/components/RenderWithBlocks.d.ts
|
|
7
5
|
interface MDXComponent {
|
|
8
6
|
id: string;
|
|
@@ -37,10 +35,7 @@ interface RenderWithHydrationProps {
|
|
|
37
35
|
*
|
|
38
36
|
* Non-hydratable components render without any wrapper overhead.
|
|
39
37
|
*/
|
|
40
|
-
declare function RenderWithHydration({
|
|
41
|
-
config,
|
|
42
|
-
data
|
|
43
|
-
}: RenderWithHydrationProps): react_jsx_runtime0.JSX.Element;
|
|
38
|
+
declare function RenderWithHydration({ config, data }: RenderWithHydrationProps): import("react/jsx-runtime").JSX.Element;
|
|
44
39
|
//#endregion
|
|
45
40
|
export { RenderWithHydration, createPageRendererWithBlocks, evaluateMDXBlocks };
|
|
46
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,9 +1,8 @@
|
|
|
1
|
-
import { i as isHydratable, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-
|
|
1
|
+
import { i as isHydratable, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-BHoNpzH6.mjs";
|
|
2
2
|
import { evaluateMDXBlocks } from "@conloca/mdx/node";
|
|
3
|
-
import { Render } from "@puckeditor/core";
|
|
3
|
+
import { Render } from "@puckeditor/core/rsc";
|
|
4
4
|
import cn from "clsx";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
6
|
//#region src/components/HydrationWrapper.tsx
|
|
8
7
|
/**
|
|
9
8
|
* Wraps hydratable components with data attributes for browser hydration.
|
|
@@ -23,7 +22,6 @@ function HydrationWrapper({ componentName, strategy, props, children }) {
|
|
|
23
22
|
children
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
//#endregion
|
|
28
26
|
//#region src/components/RenderWithHydration.tsx
|
|
29
27
|
/**
|
|
@@ -57,7 +55,6 @@ function RenderWithHydration({ config, data }) {
|
|
|
57
55
|
data
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
//#endregion
|
|
62
59
|
//#region src/components/RenderWithBlocks.tsx
|
|
63
60
|
function isRenderableBlock(block) {
|
|
@@ -220,7 +217,7 @@ function createPageRendererWithBlocks(config, data, mdxComponents) {
|
|
|
220
217
|
});
|
|
221
218
|
};
|
|
222
219
|
}
|
|
223
|
-
|
|
224
220
|
//#endregion
|
|
225
221
|
export { RenderWithHydration, createPageRendererWithBlocks, evaluateMDXBlocks };
|
|
222
|
+
|
|
226
223
|
//# sourceMappingURL=components.mjs.map
|
package/dist/components.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","names":[],"sources":["../src/components/HydrationWrapper.tsx","../src/components/RenderWithHydration.tsx","../src/components/RenderWithBlocks.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { serializeProps } from '../lib/serialize-props.js';\nimport type { HydrationStrategy } from '../types.js';\n\ninterface HydrationWrapperProps {\n componentName: string;\n strategy: HydrationStrategy;\n props: Record<string, unknown>;\n children: ReactNode;\n}\n\n/**\n * Wraps hydratable components with data attributes for browser hydration.\n *\n * When strategy is 'none', renders children directly without wrapper overhead.\n * Otherwise, wraps in a div with data-hydrate attributes that the browser\n * hydration script uses to find and hydrate components.\n */\nexport function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps) {\n // No hydration needed - render children directly without wrapper\n if (strategy === 'none') {\n return <>{children}</>;\n }\n\n // Strip Puck-internal props that aren't needed for hydration.\n // `puck` contains functions (renderDropZone) that can't survive JSON serialization\n // and would crash on hydration if a component called them.\n const { puck: _puck, ...hydrateProps } = props as Record<string, unknown> & { puck?: unknown };\n\n // Wrap with hydration markers for the browser script to find\n return (\n <div\n style={{ display: 'contents' }}\n data-hydrate={componentName}\n data-hydrate-strategy={strategy}\n data-props={serializeProps(hydrateProps)}\n >\n {children}\n </div>\n );\n}\n","import type { Config, Data } from '@puckeditor/core';\nimport { Render } from '@puckeditor/core';\nimport { isHydratable } from '../lib/hydration-utils.js';\nimport { HydrationWrapper } from './HydrationWrapper.js';\n\ninterface RenderWithHydrationProps {\n config: Config;\n data: Data;\n}\n\n/**\n * Wrapper around Puck's Render component that adds hydration support.\n *\n * For each component with a hydration strategy configured, wraps the\n * component's render output with HydrationWrapper to add data-hydrate\n * attributes for browser-side hydration.\n *\n * Non-hydratable components render without any wrapper overhead.\n */\nexport function RenderWithHydration({ config, data }: RenderWithHydrationProps) {\n // Create wrapped config with hydration-aware render functions\n const wrappedConfig: Config = {\n ...config,\n components: Object.fromEntries(\n Object.entries(config.components).map(([name, componentConfig]) => {\n const strategy = isHydratable(name, config);\n\n if (strategy === 'none') {\n // No wrapping needed - component stays static\n return [name, componentConfig];\n }\n\n // Wrap the render function so its output becomes HydrationWrapper children\n const originalRender = componentConfig.render;\n return [\n name,\n {\n ...componentConfig,\n render: (props) => (\n <HydrationWrapper componentName={name} strategy={strategy} props={props}>\n {originalRender(props)}\n </HydrationWrapper>\n ),\n },\n ];\n }),\n ),\n };\n\n return <Render config={wrappedConfig} data={data} />;\n}\n","import type { MDXBlockEvaluationResult } from '@conloca/mdx/node';\nimport type { ComponentConfig, Config, Data } from '@puckeditor/core';\nimport { Render } from '@puckeditor/core';\nimport cn from 'clsx';\nimport type { ComponentType } from 'react';\nimport { hasHydratableComponents } from '../lib/hydration-utils.js';\nimport { RenderWithHydration } from './RenderWithHydration.js';\n\ninterface MDXComponent {\n id: string;\n title: string;\n Component: ComponentType;\n}\n\nfunction isRenderableBlock(block: MDXBlockEvaluationResult | MDXComponent): block is MDXComponent {\n return 'Component' in block && !('ok' in block);\n}\n\ninterface RenderWithBlocksProps {\n config: Config;\n data: Data;\n mdxComponents: MDXComponent[];\n}\n\ninterface ContentBlockSectionProps {\n title?: string;\n subtitle?: string;\n label?: string;\n blockId: string;\n width?: 'narrow' | 'default';\n tone?: 'transparent' | 'subtle';\n}\n\nconst contentBlockWidthClasses: Record<NonNullable<ContentBlockSectionProps['width']>, string> = {\n narrow: 'max-w-3xl',\n default: 'max-w-4xl',\n};\n\nconst contentBlockToneClasses: Record<NonNullable<ContentBlockSectionProps['tone']>, string> = {\n transparent: '',\n subtle:\n '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',\n};\n\nfunction createFailedBlockComponent(block: Extract<MDXBlockEvaluationResult, { ok: false }>): ComponentType {\n return function FailedBlockComponent() {\n return (\n <div className=\"p-4 bg-red-50 border border-red-200 rounded text-red-600\">\n <p className=\"font-semibold mb-2\">MDX Block Error</p>\n <p className=\"text-sm\">Block: {block.id}</p>\n <p className=\"text-xs mt-2\">{block.error.message}</p>\n </div>\n );\n };\n}\n\nfunction resolveRenderableBlocks(blocks: (MDXBlockEvaluationResult | MDXComponent)[]): MDXComponent[] {\n return blocks.map((block) => {\n if (isRenderableBlock(block)) {\n return block;\n }\n\n if (block.ok) {\n return block;\n }\n\n return {\n id: block.id,\n title: block.title,\n Component: createFailedBlockComponent(block),\n };\n });\n}\n\n// ── Main Component ──────────────────────────────────────────────────────────\n\n/**\n * Internal component for rendering Puck pages with MDX blocks.\n *\n * Enhances the Puck config by:\n * 1. Registering each MDX block as a dynamic Puck component (`Block_{id}`)\n * 2. Overriding ContentBlockSection's render to resolve blockId → actual MDX content\n *\n * MDX blocks are passed as React components (not HTML strings), which:\n * - Avoids dangerouslySetInnerHTML security risks\n * - More efficient (no HTML conversion round-trip)\n * - Type-safe with proper React component types\n *\n * @internal\n */\nfunction RenderWithBlocks({ config, data, mdxComponents }: RenderWithBlocksProps) {\n // Build enhanced config with MDX blocks\n const blockComponents: Record<string, ComponentConfig> = {};\n const blockCategoryList: string[] = [];\n const blockComponentMap = new Map(mdxComponents.map((block) => [block.id, block]));\n\n // Create component configs for each block\n mdxComponents.forEach((block) => {\n const componentKey = `Block_${block.id}`;\n\n // Capture component in closure - Puck doesn't persist defaultProps reliably\n const BlockComponent = block.Component;\n\n blockComponents[componentKey] = {\n label: block.title,\n fields: {},\n defaultProps: {},\n render: () => {\n // Use blockId and BlockComponent from closure - no prop dependency\n return (\n <div className=\"mdx-content conloca-prose max-w-none\">\n <BlockComponent />\n </div>\n );\n },\n };\n blockCategoryList.push(componentKey);\n });\n\n // Merge with existing config\n const existingCategories = config.categories || {};\n const existingComponents = config.components || {};\n const contentBlockSection = existingComponents.ContentBlockSection as\n | ComponentConfig<ContentBlockSectionProps>\n | undefined;\n\n const enhancedContentBlockSection = contentBlockSection\n ? {\n ...contentBlockSection,\n render: ({\n blockId,\n label,\n title,\n subtitle,\n tone = 'transparent',\n width = 'default',\n }: ContentBlockSectionProps) => {\n const selectedBlock = blockComponentMap.get(blockId);\n const SelectedBlockComponent = selectedBlock?.Component;\n\n return (\n <section className=\"pb-16 sm:pb-20\">\n <div className={cn('mx-auto px-4 sm:px-6 lg:px-8', contentBlockWidthClasses[width])}>\n {label ? (\n <p className=\"mb-4 text-sm font-medium uppercase tracking-[0.18em] text-brand-700 dark:text-brand-300\">\n {label}\n </p>\n ) : null}\n {title && (\n <h2 className=\"text-2xl sm:text-3xl font-bold text-surface-900 dark:text-white mb-4\">{title}</h2>\n )}\n {subtitle && (\n <p className=\"text-surface-500 dark:text-surface-400 text-sm leading-relaxed mb-6\">{subtitle}</p>\n )}\n <div className={cn(contentBlockToneClasses[tone])}>\n {SelectedBlockComponent && (\n <div className=\"mdx-content conloca-prose max-w-none\">\n <SelectedBlockComponent />\n </div>\n )}\n </div>\n </div>\n </section>\n );\n },\n }\n : undefined;\n\n // Merge block components with existing config components\n const mergedComponents = {\n ...existingComponents,\n ...(enhancedContentBlockSection && { ContentBlockSection: enhancedContentBlockSection }),\n ...blockComponents,\n } as Config['components'];\n\n const enhancedConfig: Config = {\n ...config,\n categories: {\n ...existingCategories,\n blocks: {\n title: 'Content Blocks',\n components: blockCategoryList,\n },\n },\n components: mergedComponents,\n };\n\n // Check if page has hydratable components\n const needsHydration = hasHydratableComponents(data, enhancedConfig);\n\n if (needsHydration) {\n return <RenderWithHydration config={enhancedConfig} data={data} />;\n }\n\n return <Render config={enhancedConfig} data={data} />;\n}\n\n/**\n * Factory function to create a PageRenderer with MDX components baked in via closure.\n *\n * This approach avoids dangerouslySetInnerHTML by keeping React components as components\n * throughout the rendering pipeline. Components are captured in the closure and don't\n * need to be passed as props (which Astro can't serialize).\n *\n * @param config - The Puck configuration with component definitions\n * @param data - Puck page data containing component tree\n * @param mdxComponents - Array of evaluated MDX block results\n * @returns A PageRenderer component with no props needed (components in closure)\n */\nexport function createPageRendererWithBlocks(\n config: Config,\n data: Data,\n mdxComponents: (MDXBlockEvaluationResult | MDXComponent)[],\n): ComponentType {\n const renderableBlocks = resolveRenderableBlocks(mdxComponents);\n\n // Capture components in closure - no need to pass as props\n return function PageRendererWithBlocks() {\n return <RenderWithBlocks config={config} data={data} mdxComponents={renderableBlocks} />;\n };\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"components.mjs","names":[],"sources":["../src/components/HydrationWrapper.tsx","../src/components/RenderWithHydration.tsx","../src/components/RenderWithBlocks.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { serializeProps } from '../lib/serialize-props.js';\nimport type { HydrationStrategy } from '../types.js';\n\ninterface HydrationWrapperProps {\n componentName: string;\n strategy: HydrationStrategy;\n props: Record<string, unknown>;\n children: ReactNode;\n}\n\n/**\n * Wraps hydratable components with data attributes for browser hydration.\n *\n * When strategy is 'none', renders children directly without wrapper overhead.\n * Otherwise, wraps in a div with data-hydrate attributes that the browser\n * hydration script uses to find and hydrate components.\n */\nexport function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps) {\n // No hydration needed - render children directly without wrapper\n if (strategy === 'none') {\n return <>{children}</>;\n }\n\n // Strip Puck-internal props that aren't needed for hydration.\n // `puck` contains functions (renderDropZone) that can't survive JSON serialization\n // and would crash on hydration if a component called them.\n const { puck: _puck, ...hydrateProps } = props as Record<string, unknown> & { puck?: unknown };\n\n // Wrap with hydration markers for the browser script to find\n return (\n <div\n style={{ display: 'contents' }}\n data-hydrate={componentName}\n data-hydrate-strategy={strategy}\n data-props={serializeProps(hydrateProps)}\n >\n {children}\n </div>\n );\n}\n","import type { Config, Data } from '@puckeditor/core';\nimport { Render } from '@puckeditor/core/rsc';\nimport { isHydratable } from '../lib/hydration-utils.js';\nimport { HydrationWrapper } from './HydrationWrapper.js';\n\ninterface RenderWithHydrationProps {\n config: Config;\n data: Data;\n}\n\n/**\n * Wrapper around Puck's Render component that adds hydration support.\n *\n * For each component with a hydration strategy configured, wraps the\n * component's render output with HydrationWrapper to add data-hydrate\n * attributes for browser-side hydration.\n *\n * Non-hydratable components render without any wrapper overhead.\n */\nexport function RenderWithHydration({ config, data }: RenderWithHydrationProps) {\n // Create wrapped config with hydration-aware render functions\n const wrappedConfig: Config = {\n ...config,\n components: Object.fromEntries(\n Object.entries(config.components).map(([name, componentConfig]) => {\n const strategy = isHydratable(name, config);\n\n if (strategy === 'none') {\n // No wrapping needed - component stays static\n return [name, componentConfig];\n }\n\n // Wrap the render function so its output becomes HydrationWrapper children\n const originalRender = componentConfig.render;\n return [\n name,\n {\n ...componentConfig,\n render: (props) => (\n <HydrationWrapper componentName={name} strategy={strategy} props={props}>\n {originalRender(props)}\n </HydrationWrapper>\n ),\n },\n ];\n }),\n ),\n };\n\n return <Render config={wrappedConfig} data={data} />;\n}\n","import type { MDXBlockEvaluationResult } from '@conloca/mdx/node';\nimport type { ComponentConfig, Config, Data } from '@puckeditor/core';\nimport { Render } from '@puckeditor/core/rsc';\nimport cn from 'clsx';\nimport type { ComponentType } from 'react';\nimport { hasHydratableComponents } from '../lib/hydration-utils.js';\nimport { RenderWithHydration } from './RenderWithHydration.js';\n\ninterface MDXComponent {\n id: string;\n title: string;\n Component: ComponentType;\n}\n\nfunction isRenderableBlock(block: MDXBlockEvaluationResult | MDXComponent): block is MDXComponent {\n return 'Component' in block && !('ok' in block);\n}\n\ninterface RenderWithBlocksProps {\n config: Config;\n data: Data;\n mdxComponents: MDXComponent[];\n}\n\ninterface ContentBlockSectionProps {\n title?: string;\n subtitle?: string;\n label?: string;\n blockId: string;\n width?: 'narrow' | 'default';\n tone?: 'transparent' | 'subtle';\n}\n\nconst contentBlockWidthClasses: Record<NonNullable<ContentBlockSectionProps['width']>, string> = {\n narrow: 'max-w-3xl',\n default: 'max-w-4xl',\n};\n\nconst contentBlockToneClasses: Record<NonNullable<ContentBlockSectionProps['tone']>, string> = {\n transparent: '',\n subtle:\n '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',\n};\n\nfunction createFailedBlockComponent(block: Extract<MDXBlockEvaluationResult, { ok: false }>): ComponentType {\n return function FailedBlockComponent() {\n return (\n <div className=\"p-4 bg-red-50 border border-red-200 rounded text-red-600\">\n <p className=\"font-semibold mb-2\">MDX Block Error</p>\n <p className=\"text-sm\">Block: {block.id}</p>\n <p className=\"text-xs mt-2\">{block.error.message}</p>\n </div>\n );\n };\n}\n\nfunction resolveRenderableBlocks(blocks: (MDXBlockEvaluationResult | MDXComponent)[]): MDXComponent[] {\n return blocks.map((block) => {\n if (isRenderableBlock(block)) {\n return block;\n }\n\n if (block.ok) {\n return block;\n }\n\n return {\n id: block.id,\n title: block.title,\n Component: createFailedBlockComponent(block),\n };\n });\n}\n\n// ── Main Component ──────────────────────────────────────────────────────────\n\n/**\n * Internal component for rendering Puck pages with MDX blocks.\n *\n * Enhances the Puck config by:\n * 1. Registering each MDX block as a dynamic Puck component (`Block_{id}`)\n * 2. Overriding ContentBlockSection's render to resolve blockId → actual MDX content\n *\n * MDX blocks are passed as React components (not HTML strings), which:\n * - Avoids dangerouslySetInnerHTML security risks\n * - More efficient (no HTML conversion round-trip)\n * - Type-safe with proper React component types\n *\n * @internal\n */\nfunction RenderWithBlocks({ config, data, mdxComponents }: RenderWithBlocksProps) {\n // Build enhanced config with MDX blocks\n const blockComponents: Record<string, ComponentConfig> = {};\n const blockCategoryList: string[] = [];\n const blockComponentMap = new Map(mdxComponents.map((block) => [block.id, block]));\n\n // Create component configs for each block\n mdxComponents.forEach((block) => {\n const componentKey = `Block_${block.id}`;\n\n // Capture component in closure - Puck doesn't persist defaultProps reliably\n const BlockComponent = block.Component;\n\n blockComponents[componentKey] = {\n label: block.title,\n fields: {},\n defaultProps: {},\n render: () => {\n // Use blockId and BlockComponent from closure - no prop dependency\n return (\n <div className=\"mdx-content conloca-prose max-w-none\">\n <BlockComponent />\n </div>\n );\n },\n };\n blockCategoryList.push(componentKey);\n });\n\n // Merge with existing config\n const existingCategories = config.categories || {};\n const existingComponents = config.components || {};\n const contentBlockSection = existingComponents.ContentBlockSection as\n | ComponentConfig<ContentBlockSectionProps>\n | undefined;\n\n const enhancedContentBlockSection = contentBlockSection\n ? {\n ...contentBlockSection,\n render: ({\n blockId,\n label,\n title,\n subtitle,\n tone = 'transparent',\n width = 'default',\n }: ContentBlockSectionProps) => {\n const selectedBlock = blockComponentMap.get(blockId);\n const SelectedBlockComponent = selectedBlock?.Component;\n\n return (\n <section className=\"pb-16 sm:pb-20\">\n <div className={cn('mx-auto px-4 sm:px-6 lg:px-8', contentBlockWidthClasses[width])}>\n {label ? (\n <p className=\"mb-4 text-sm font-medium uppercase tracking-[0.18em] text-brand-700 dark:text-brand-300\">\n {label}\n </p>\n ) : null}\n {title && (\n <h2 className=\"text-2xl sm:text-3xl font-bold text-surface-900 dark:text-white mb-4\">{title}</h2>\n )}\n {subtitle && (\n <p className=\"text-surface-500 dark:text-surface-400 text-sm leading-relaxed mb-6\">{subtitle}</p>\n )}\n <div className={cn(contentBlockToneClasses[tone])}>\n {SelectedBlockComponent && (\n <div className=\"mdx-content conloca-prose max-w-none\">\n <SelectedBlockComponent />\n </div>\n )}\n </div>\n </div>\n </section>\n );\n },\n }\n : undefined;\n\n // Merge block components with existing config components\n const mergedComponents = {\n ...existingComponents,\n ...(enhancedContentBlockSection && { ContentBlockSection: enhancedContentBlockSection }),\n ...blockComponents,\n } as Config['components'];\n\n const enhancedConfig: Config = {\n ...config,\n categories: {\n ...existingCategories,\n blocks: {\n title: 'Content Blocks',\n components: blockCategoryList,\n },\n },\n components: mergedComponents,\n };\n\n // Check if page has hydratable components\n const needsHydration = hasHydratableComponents(data, enhancedConfig);\n\n if (needsHydration) {\n return <RenderWithHydration config={enhancedConfig} data={data} />;\n }\n\n return <Render config={enhancedConfig} data={data} />;\n}\n\n/**\n * Factory function to create a PageRenderer with MDX components baked in via closure.\n *\n * This approach avoids dangerouslySetInnerHTML by keeping React components as components\n * throughout the rendering pipeline. Components are captured in the closure and don't\n * need to be passed as props (which Astro can't serialize).\n *\n * @param config - The Puck configuration with component definitions\n * @param data - Puck page data containing component tree\n * @param mdxComponents - Array of evaluated MDX block results\n * @returns A PageRenderer component with no props needed (components in closure)\n */\nexport function createPageRendererWithBlocks(\n config: Config,\n data: Data,\n mdxComponents: (MDXBlockEvaluationResult | MDXComponent)[],\n): ComponentType {\n const renderableBlocks = resolveRenderableBlocks(mdxComponents);\n\n // Capture components in closure - no need to pass as props\n return function PageRendererWithBlocks() {\n return <RenderWithBlocks config={config} data={data} mdxComponents={renderableBlocks} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,iBAAiB,EAAE,eAAe,UAAU,OAAO,YAAmC;CAEpG,IAAI,aAAa,QACf,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAMvB,MAAM,EAAE,MAAM,OAAO,GAAG,iBAAiB;CAGzC,OACE,oBAAC,OAAD;EACE,OAAO,EAAE,SAAS,WAAW;EAC7B,gBAAc;EACd,yBAAuB;EACvB,cAAY,eAAe,YAAY;EAEtC;CACE,CAAA;AAET;;;;;;;;;;;;ACrBA,SAAgB,oBAAoB,EAAE,QAAQ,QAAkC;CA8B9E,OAAO,oBAAC,QAAD;EAAQ,QAAQ;GA3BrB,GAAG;GACH,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,UAAU,CAAC,CAAC,KAAK,CAAC,MAAM,qBAAqB;IACjE,MAAM,WAAW,aAAa,MAAM,MAAM;IAE1C,IAAI,aAAa,QAEf,OAAO,CAAC,MAAM,eAAe;IAI/B,MAAM,iBAAiB,gBAAgB;IACvC,OAAO,CACL,MACA;KACE,GAAG;KACH,SAAS,UACP,oBAAC,kBAAD;MAAkB,eAAe;MAAgB;MAAiB;MAC/D,UAAA,eAAe,KAAK;KACL,CAAA;IAEtB,CACF;GACF,CAAC,CACH;EAGiC;EAAS;CAAO,CAAA;AACrD;;;ACpCA,SAAS,kBAAkB,OAAuE;CAChG,OAAO,eAAe,SAAS,EAAE,QAAQ;AAC3C;AAiBA,MAAM,2BAA2F;CAC/F,QAAQ;CACR,SAAS;AACX;AAEA,MAAM,0BAAyF;CAC7F,aAAa;CACb,QACE;AACJ;AAEA,SAAS,2BAA2B,OAAwE;CAC1G,OAAO,SAAS,uBAAuB;EACrC,OACE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,oBAAC,KAAD;KAAG,WAAU;KAAqB,UAAA;IAAkB,CAAA;IACpD,qBAAC,KAAD;KAAG,WAAU;KAAb,UAAA,CAAuB,WAAQ,MAAM,EAAM;;IAC3C,oBAAC,KAAD;KAAG,WAAU;KAAgB,UAAA,MAAM,MAAM;IAAW,CAAA;GACjD;;CAET;AACF;AAEA,SAAS,wBAAwB,QAAqE;CACpG,OAAO,OAAO,KAAK,UAAU;EAC3B,IAAI,kBAAkB,KAAK,GACzB,OAAO;EAGT,IAAI,MAAM,IACR,OAAO;EAGT,OAAO;GACL,IAAI,MAAM;GACV,OAAO,MAAM;GACb,WAAW,2BAA2B,KAAK;EAC7C;CACF,CAAC;AACH;;;;;;;;;;;;;;;AAkBA,SAAS,iBAAiB,EAAE,QAAQ,MAAM,iBAAwC;CAEhF,MAAM,kBAAmD,CAAC;CAC1D,MAAM,oBAA8B,CAAC;CACrC,MAAM,oBAAoB,IAAI,IAAI,cAAc,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;CAGjF,cAAc,SAAS,UAAU;EAC/B,MAAM,eAAe,SAAS,MAAM;EAGpC,MAAM,iBAAiB,MAAM;EAE7B,gBAAgB,gBAAgB;GAC9B,OAAO,MAAM;GACb,QAAQ,CAAC;GACT,cAAc,CAAC;GACf,cAAc;IAEZ,OACE,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,gBAAD,CAAiB,CAAA;IACd,CAAA;GAET;EACF;EACA,kBAAkB,KAAK,YAAY;CACrC,CAAC;CAGD,MAAM,qBAAqB,OAAO,cAAc,CAAC;CACjD,MAAM,qBAAqB,OAAO,cAAc,CAAC;CACjD,MAAM,sBAAsB,mBAAmB;CAI/C,MAAM,8BAA8B,sBAChC;EACE,GAAG;EACH,SAAS,EACP,SACA,OACA,OACA,UACA,OAAO,eACP,QAAQ,gBACsB;GAE9B,MAAM,yBADgB,kBAAkB,IAAI,OACD,CAAC,EAAE;GAE9C,OACE,oBAAC,WAAD;IAAS,WAAU;IACjB,UAAA,qBAAC,OAAD;KAAK,WAAW,GAAG,gCAAgC,yBAAyB,MAAM;KAAlF,UAAA;MACG,QACC,oBAAC,KAAD;OAAG,WAAU;OACV,UAAA;MACA,CAAA,IACD;MACH,SACC,oBAAC,MAAD;OAAI,WAAU;OAAwE,UAAA;MAAU,CAAA;MAEjG,YACC,oBAAC,KAAD;OAAG,WAAU;OAAuE,UAAA;MAAY,CAAA;MAElG,oBAAC,OAAD;OAAK,WAAW,GAAG,wBAAwB,KAAK;OAC7C,UAAA,0BACC,oBAAC,OAAD;QAAK,WAAU;QACb,UAAA,oBAAC,wBAAD,CAAyB,CAAA;OACtB,CAAA;MAEJ,CAAA;KACF;;GACE,CAAA;EAEb;CACF,IACA,KAAA;CAGJ,MAAM,mBAAmB;EACvB,GAAG;EACH,GAAI,+BAA+B,EAAE,qBAAqB,4BAA4B;EACtF,GAAG;CACL;CAEA,MAAM,iBAAyB;EAC7B,GAAG;EACH,YAAY;GACV,GAAG;GACH,QAAQ;IACN,OAAO;IACP,YAAY;GACd;EACF;EACA,YAAY;CACd;CAKA,IAFuB,wBAAwB,MAAM,cAEpC,GACf,OAAO,oBAAC,qBAAD;EAAqB,QAAQ;EAAsB;CAAO,CAAA;CAGnE,OAAO,oBAAC,QAAD;EAAQ,QAAQ;EAAsB;CAAO,CAAA;AACtD;;;;;;;;;;;;;AAcA,SAAgB,6BACd,QACA,MACA,eACe;CACf,MAAM,mBAAmB,wBAAwB,aAAa;CAG9D,OAAO,SAAS,yBAAyB;EACvC,OAAO,oBAAC,kBAAD;GAA0B;GAAc;GAAM,eAAe;EAAmB,CAAA;CACzF;AACF"}
|
package/dist/hydration.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as WithHydrationStrategy, r as withHydration, t as HydrationMeta } from "./withHydration-HIvO9ysY.mjs";
|
|
1
|
+
import { n as HydrationStrategy } from "./types-CS9neadI.mjs";
|
|
3
2
|
import { ComponentRegistry } from "./lib/hydration-script.mjs";
|
|
3
|
+
import { n as WithHydrationStrategy, r as withHydration, t as HydrationMeta } from "./withHydration-DkKpkmzJ.mjs";
|
|
4
4
|
export { type ComponentRegistry, type HydrationMeta, type HydrationStrategy, type WithHydrationStrategy, withHydration };
|
package/dist/hydration.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { t as withHydration } from "./withHydration-
|
|
2
|
-
|
|
3
|
-
export { withHydration };
|
|
1
|
+
import { t as withHydration } from "./withHydration-C256ox_6.mjs";
|
|
2
|
+
export { withHydration };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import { n as
|
|
1
|
+
import { n as localesFromAstroI18n, r as localesFromStarlight, t as ConlocaLocales } from "./locales-helpers-BvYYqnJ5.mjs";
|
|
2
|
+
import { a as PageReference, c as TemplateConfig, i as PageData, n as HydrationStrategy, o as ResolvedRoutingConfig, r as LayoutProps, t as DataCollectionEntry } from "./types-CS9neadI.mjs";
|
|
3
3
|
import { ComponentRegistry } from "./lib/hydration-script.mjs";
|
|
4
|
+
import { n as WithHydrationStrategy, r as withHydration, t as HydrationMeta } from "./withHydration-DkKpkmzJ.mjs";
|
|
5
|
+
import { MdxComponentDescriptor, MdxComponentInsertHint, MdxComponentProp, MdxComponents, MdxJsxComponentDescriptor, MdxSnippetDescriptor, defineMdxComponents, readStringAttribute, writeStringAttribute } from "@conloca/cms-spa/mdx-components";
|
|
6
|
+
import { CoreFieldsMode, FieldHint, FieldHintCommon, FieldHintVariant, FieldHints, PageSchemaDescriptor, PageSchemaEntry, PageSchemaGroup, PageSchemas, definePageSchema } from "@conloca/cms-spa/page-schemas";
|
|
4
7
|
import { BlockMeta, PageMeta, blockMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
5
8
|
import { Config, Data } from "@puckeditor/core";
|
|
6
|
-
|
|
7
|
-
//#region src/lib/hydration-scanner.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Result of scanning a component file for withHydration usage.
|
|
10
|
-
*/
|
|
11
|
-
interface HydrationDiscovery {
|
|
12
|
-
/** Component name derived from filename (PascalCase) */
|
|
13
|
-
componentName: string;
|
|
14
|
-
/** Absolute path to the component file */
|
|
15
|
-
filePath: string;
|
|
16
|
-
/** Hydration strategy extracted from withHydration call */
|
|
17
|
-
strategy: 'load' | 'visible' | 'idle';
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Scans component directories for files using withHydration wrapper.
|
|
21
|
-
*
|
|
22
|
-
* This function performs static analysis to discover components marked
|
|
23
|
-
* for hydration, without executing any component code.
|
|
24
|
-
*
|
|
25
|
-
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
26
|
-
* @param projectRoot - Absolute path to the project root
|
|
27
|
-
* @returns Array of discovered hydratable components with their strategies
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const discoveries = await scanForHydratableComponents(
|
|
32
|
-
* ['src/components/puck'],
|
|
33
|
-
* '/path/to/project'
|
|
34
|
-
* )
|
|
35
|
-
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
declare function scanForHydratableComponents(componentPaths: string[], projectRoot: string): Promise<HydrationDiscovery[]>;
|
|
39
|
-
//#endregion
|
|
40
9
|
//#region src/lib/hydration-utils.d.ts
|
|
41
10
|
/**
|
|
42
11
|
* Extended ComponentConfig with hydration support.
|
|
@@ -135,5 +104,5 @@ declare function pathnameFromSlug(slug: string | undefined, pattern: string): st
|
|
|
135
104
|
*/
|
|
136
105
|
declare function serializeProps(props: Record<string, unknown>): string;
|
|
137
106
|
//#endregion
|
|
138
|
-
export { type BlockMeta, type ComponentRegistry, type
|
|
107
|
+
export { type BlockMeta, type ComponentRegistry, type ConlocaLocales, type CoreFieldsMode, type DataCollectionEntry, type FieldHint, type FieldHintCommon, type FieldHintVariant, type FieldHints, type HydratableComponent, type HydratableComponentConfig, type HydrationMeta, type HydrationStrategy, type LayoutProps, type MdxComponentDescriptor, type MdxComponentInsertHint, type MdxComponentProp, type MdxComponents, type MdxJsxComponentDescriptor, type MdxSnippetDescriptor, type PageData, type PageMeta, type PageReference, type PageSchemaDescriptor, type PageSchemaEntry, type PageSchemaGroup, type PageSchemas, type ResolvedRoutingConfig, type TemplateConfig, type WithHydrationStrategy, blockMetaSchema, defineMdxComponents, definePageSchema, extractSlugFromPathname, findHydratableComponents, hasHydratableComponents, isHydratable, isPublished, localesFromAstroI18n, localesFromStarlight, pageMetaSchema, pathnameFromSlug, readStringAttribute, serializeProps, toDate, withHydration, writeStringAttribute };
|
|
139
108
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/hydration-
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/hydration-utils.ts","../src/lib/route-utils.ts","../src/lib/serialize-props.ts"],"mappings":";;;;;;;;;;;;;UAQiB;;EAEf,YAAY;EACZ,UAAU;;;;;;UAOK;;EAEf;;EAEA,OAAO;;EAEP,UAAU,QAAQ;;EAElB;;;;;;;;;;;;iBAac,aAAa,uBAAuB,QAAQ,SAAS;;;;;;;;;iBAsBrD,yBAAyB,MAAM,MAAM,QAAQ,SAAS;;;;;iBA0CtD,wBAAwB,MAAM,MAAM,QAAQ;;;iBCvG5C,OAAO,gBAAgB,0BAAuB;UAcpD;EACR,qBAAqB;EACrB,uBAAuB;;iBAGT,YAAY,MAAM;;;;;;;;;;;;;;;;;iBAgClB,wBAAwB,kBAAkB;;;;;;;;;;;;;;;;iBAkC1C,iBAAiB,0BAA0B;;;;;;;iBCjF3C,eAAe,OAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { i as isHydratable, n as findHydratableComponents, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-BHoNpzH6.mjs";
|
|
2
|
+
import { t as withHydration } from "./withHydration-C256ox_6.mjs";
|
|
3
|
+
import { n as localesFromStarlight, t as localesFromAstroI18n } from "./locales-helpers-qiwh7nxS.mjs";
|
|
4
|
+
import { defineMdxComponents, readStringAttribute, writeStringAttribute } from "@conloca/cms-spa/mdx-components";
|
|
5
|
+
import { definePageSchema } from "@conloca/cms-spa/page-schemas";
|
|
4
6
|
import { blockMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
5
|
-
|
|
6
7
|
//#region src/lib/route-utils.ts
|
|
7
8
|
function toDate(value) {
|
|
8
9
|
if (!value) return;
|
|
@@ -60,7 +61,7 @@ function pathnameFromSlug(slug, pattern) {
|
|
|
60
61
|
if (!slug) return prefix || "/";
|
|
61
62
|
return `${prefix}/${slug}`;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
64
|
//#endregion
|
|
65
|
-
export { blockMetaSchema, extractSlugFromPathname, findHydratableComponents, hasHydratableComponents, isHydratable, isPublished, pageMetaSchema, pathnameFromSlug,
|
|
65
|
+
export { blockMetaSchema, defineMdxComponents, definePageSchema, extractSlugFromPathname, findHydratableComponents, hasHydratableComponents, isHydratable, isPublished, localesFromAstroI18n, localesFromStarlight, pageMetaSchema, pathnameFromSlug, readStringAttribute, serializeProps, toDate, withHydration, writeStringAttribute };
|
|
66
|
+
|
|
66
67
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/lib/route-utils.ts"],"sourcesContent":["export function toDate(value: string | Date | null | undefined) {\n if (!value) {\n return undefined;\n }\n\n if (value instanceof Date) {\n return value;\n }\n\n const parsed = new Date(value);\n\n return Number.isNaN(parsed.getTime()) ? undefined : parsed;\n}\n\ninterface PublishSchedule {\n publishAt?: string | Date | null;\n unpublishAt?: string | Date | null;\n}\n\nexport function isPublished(data: PublishSchedule) {\n const now = new Date();\n const publishAt = toDate(data.publishAt);\n const unpublishAt = toDate(data.unpublishAt);\n\n if (publishAt && publishAt > now) {\n return false;\n }\n\n if (unpublishAt && unpublishAt <= now) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Extract slug from pathname given a route pattern.\n *\n * The slug is the portion of the pathname that comes after the\n * static prefix of the pattern.\n *\n * @param pathname - URL pathname (e.g., '/about', '/blog/post-1')\n * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')\n * @returns The extracted slug, or undefined for root paths\n *\n * @example\n * extractSlugFromPathname('/about', '/[...slug]') // 'about'\n * extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'\n * extractSlugFromPathname('/', '/[...slug]') // undefined\n * extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined\n */\nexport function extractSlugFromPathname(pathname: string, pattern: string): string | undefined {\n // Pattern: /[...slug] -> prefix: ''\n // Pattern: /blog/[...slug] -> prefix: '/blog'\n // Pattern: /docs/[...path] -> prefix: '/docs'\n\n const prefixMatch = pattern.match(/^(.*?)\\[/);\n const prefix = prefixMatch ? prefixMatch[1].replace(/\\/$/, '') : '';\n\n // Remove prefix from pathname\n const slugPart = pathname.slice(prefix.length);\n\n // Remove leading slash\n const slug = slugPart.replace(/^\\//, '');\n\n // Empty string means root page (e.g., /blog for /blog/[...slug])\n // Return undefined for root to match [...slug] behavior\n return slug || undefined;\n}\n\n/**\n * Convert a slug back to a pathname given a route pattern.\n *\n * The inverse of extractSlugFromPathname.\n *\n * @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root\n * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')\n * @returns Full URL pathname\n *\n * @example\n * pathnameFromSlug('about', '/[...slug]') // '/about'\n * pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'\n * pathnameFromSlug(undefined, '/[...slug]') // '/'\n * pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'\n */\nexport function pathnameFromSlug(slug: string | undefined, pattern: string): string {\n // Extract the static prefix before the dynamic segment\n const prefixMatch = pattern.match(/^(.*?)\\[/);\n const prefix = prefixMatch ? prefixMatch[1].replace(/\\/$/, '') : '';\n\n if (!slug) {\n // No slug means root of this pattern\n return prefix || '/';\n }\n\n // Combine prefix and slug\n return `${prefix}/${slug}`;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/lib/route-utils.ts"],"sourcesContent":["export function toDate(value: string | Date | null | undefined) {\n if (!value) {\n return undefined;\n }\n\n if (value instanceof Date) {\n return value;\n }\n\n const parsed = new Date(value);\n\n return Number.isNaN(parsed.getTime()) ? undefined : parsed;\n}\n\ninterface PublishSchedule {\n publishAt?: string | Date | null;\n unpublishAt?: string | Date | null;\n}\n\nexport function isPublished(data: PublishSchedule) {\n const now = new Date();\n const publishAt = toDate(data.publishAt);\n const unpublishAt = toDate(data.unpublishAt);\n\n if (publishAt && publishAt > now) {\n return false;\n }\n\n if (unpublishAt && unpublishAt <= now) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Extract slug from pathname given a route pattern.\n *\n * The slug is the portion of the pathname that comes after the\n * static prefix of the pattern.\n *\n * @param pathname - URL pathname (e.g., '/about', '/blog/post-1')\n * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')\n * @returns The extracted slug, or undefined for root paths\n *\n * @example\n * extractSlugFromPathname('/about', '/[...slug]') // 'about'\n * extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'\n * extractSlugFromPathname('/', '/[...slug]') // undefined\n * extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined\n */\nexport function extractSlugFromPathname(pathname: string, pattern: string): string | undefined {\n // Pattern: /[...slug] -> prefix: ''\n // Pattern: /blog/[...slug] -> prefix: '/blog'\n // Pattern: /docs/[...path] -> prefix: '/docs'\n\n const prefixMatch = pattern.match(/^(.*?)\\[/);\n const prefix = prefixMatch ? prefixMatch[1].replace(/\\/$/, '') : '';\n\n // Remove prefix from pathname\n const slugPart = pathname.slice(prefix.length);\n\n // Remove leading slash\n const slug = slugPart.replace(/^\\//, '');\n\n // Empty string means root page (e.g., /blog for /blog/[...slug])\n // Return undefined for root to match [...slug] behavior\n return slug || undefined;\n}\n\n/**\n * Convert a slug back to a pathname given a route pattern.\n *\n * The inverse of extractSlugFromPathname.\n *\n * @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root\n * @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')\n * @returns Full URL pathname\n *\n * @example\n * pathnameFromSlug('about', '/[...slug]') // '/about'\n * pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'\n * pathnameFromSlug(undefined, '/[...slug]') // '/'\n * pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'\n */\nexport function pathnameFromSlug(slug: string | undefined, pattern: string): string {\n // Extract the static prefix before the dynamic segment\n const prefixMatch = pattern.match(/^(.*?)\\[/);\n const prefix = prefixMatch ? prefixMatch[1].replace(/\\/$/, '') : '';\n\n if (!slug) {\n // No slug means root of this pattern\n return prefix || '/';\n }\n\n // Combine prefix and slug\n return `${prefix}/${slug}`;\n}\n"],"mappings":";;;;;;;AAAA,SAAgB,OAAO,OAAyC;CAC9D,IAAI,CAAC,OACH;CAGF,IAAI,iBAAiB,MACnB,OAAO;CAGT,MAAM,SAAS,IAAI,KAAK,KAAK;CAE7B,OAAO,OAAO,MAAM,OAAO,QAAQ,CAAC,IAAI,KAAA,IAAY;AACtD;AAOA,SAAgB,YAAY,MAAuB;CACjD,MAAM,sBAAM,IAAI,KAAK;CACrB,MAAM,YAAY,OAAO,KAAK,SAAS;CACvC,MAAM,cAAc,OAAO,KAAK,WAAW;CAE3C,IAAI,aAAa,YAAY,KAC3B,OAAO;CAGT,IAAI,eAAe,eAAe,KAChC,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;;;;;AAkBA,SAAgB,wBAAwB,UAAkB,SAAqC;CAK7F,MAAM,cAAc,QAAQ,MAAM,UAAU;CAC5C,MAAM,SAAS,cAAc,YAAY,EAAE,CAAC,QAAQ,OAAO,EAAE,IAAI;CAUjE,OAPiB,SAAS,MAAM,OAAO,MAGnB,CAAC,CAAC,QAAQ,OAAO,EAI3B,KAAK,KAAA;AACjB;;;;;;;;;;;;;;;;AAiBA,SAAgB,iBAAiB,MAA0B,SAAyB;CAElF,MAAM,cAAc,QAAQ,MAAM,UAAU;CAC5C,MAAM,SAAS,cAAc,YAAY,EAAE,CAAC,QAAQ,OAAO,EAAE,IAAI;CAEjE,IAAI,CAAC,MAEH,OAAO,UAAU;CAInB,OAAO,GAAG,OAAO,GAAG;AACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms-handler.d.mts","names":[],"sources":["../../src/mime-types.ts","../../src/cms-handler.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cms-handler.d.mts","names":[],"sources":["../../src/mime-types.ts","../../src/cms-handler.ts"],"mappings":";;;cACa,gBAAgB;;;;;;;;;;;;;;;;;;cC8DhB,KAAK"}
|