@conloca/astro-cms 0.1.13 → 0.1.15

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.
Files changed (47) hide show
  1. package/dist/collections.d.mts +3 -2
  2. package/dist/collections.d.mts.map +1 -1
  3. package/dist/collections.mjs +15 -6
  4. package/dist/collections.mjs.map +1 -1
  5. package/dist/components.d.mts +4 -24
  6. package/dist/components.d.mts.map +1 -1
  7. package/dist/components.mjs +99 -40
  8. package/dist/components.mjs.map +1 -1
  9. package/dist/hydration-scanner-B0NjYkZ_.mjs +109 -0
  10. package/dist/hydration-scanner-B0NjYkZ_.mjs.map +1 -0
  11. package/dist/hydration.d.mts +2 -2
  12. package/dist/hydration.mjs +1 -1
  13. package/dist/index.d.mts +9 -54
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +17 -778
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/internal/acorn-default.mjs +29 -0
  18. package/dist/{cms-handler.d.mts → internal/cms-handler.d.mts} +5 -1
  19. package/dist/internal/cms-handler.d.mts.map +1 -0
  20. package/dist/{cms-handler.mjs → internal/cms-handler.mjs} +63 -20
  21. package/dist/internal/cms-handler.mjs.map +1 -0
  22. package/dist/internal/page-handler.astro +541 -0
  23. package/dist/lib/hydration-script.d.mts +1 -1
  24. package/dist/{loader-W3i9kf3p.mjs → loader-By-AQWHc.mjs} +10 -3
  25. package/dist/loader-By-AQWHc.mjs.map +1 -0
  26. package/dist/node/content.d.mts +19 -0
  27. package/dist/node/content.d.mts.map +1 -0
  28. package/dist/node/content.mjs +4 -0
  29. package/dist/node/index.d.mts +52 -0
  30. package/dist/node/index.d.mts.map +1 -0
  31. package/dist/node/index.mjs +753 -0
  32. package/dist/node/index.mjs.map +1 -0
  33. package/dist/{serialize-props-DqfDQeFl.mjs → serialize-props-Dhv_MnkY.mjs} +3 -3
  34. package/dist/{serialize-props-DqfDQeFl.mjs.map → serialize-props-Dhv_MnkY.mjs.map} +1 -1
  35. package/dist/{types-Bsd_qENn.d.mts → types-CVQNmPxF.d.mts} +1 -1
  36. package/dist/{types-Bsd_qENn.d.mts.map → types-CVQNmPxF.d.mts.map} +1 -1
  37. package/dist/{withHydration-692fMySA.mjs → withHydration-EzyzBQ-Y.mjs} +5 -1
  38. package/dist/withHydration-EzyzBQ-Y.mjs.map +1 -0
  39. package/dist/{withHydration-BGgQDE-H.d.mts → withHydration-HIvO9ysY.d.mts} +5 -1
  40. package/dist/withHydration-HIvO9ysY.d.mts.map +1 -0
  41. package/package.json +37 -27
  42. package/dist/cms-handler.d.mts.map +0 -1
  43. package/dist/cms-handler.mjs.map +0 -1
  44. package/dist/handlers/page-handler.astro +0 -294
  45. package/dist/loader-W3i9kf3p.mjs.map +0 -1
  46. package/dist/withHydration-692fMySA.mjs.map +0 -1
  47. package/dist/withHydration-BGgQDE-H.d.mts.map +0 -1
@@ -0,0 +1,541 @@
1
+ ---
2
+ /**
3
+ * Page Handler Component
4
+ *
5
+ * This Astro component is injected via injectRoute() to handle content pages.
6
+ * It implements getStaticPaths() for static page generation and renders
7
+ * content using the Puck Render component with an optional Layout wrapper.
8
+ *
9
+ * MDX blocks are evaluated at build time and rendered as React components.
10
+ */
11
+
12
+ import { getCollection } from 'astro:content'
13
+ import type { GetStaticPaths } from 'astro'
14
+ import { Render, resolveAllData, type Data } from '@puckeditor/core'
15
+ import React from 'react'
16
+ import type { ComponentType } from 'react'
17
+
18
+ import { createPageRendererWithBlocks, RenderWithHydration } from '@conloca/astro-cms/components'
19
+ import { hasHydratableComponents, extractSlugFromPathname, isPublished, toDate } from '@conloca/astro-cms'
20
+ import type { DataCollectionEntry, DataContext, PageData, PageReference, ResolvedRoutingConfig } from '@conloca/astro-cms'
21
+ import { ALL_BLOCKS_COLLECTION } from '@conloca/astro-cms/node/content'
22
+
23
+ import routingConfig from 'virtual:conloca-routing-config'
24
+ import Layout from 'virtual:conloca-layout'
25
+ import puckConfig from 'virtual:conloca-puck-config'
26
+
27
+ // prerender is controlled by injectRoute({ prerender }) in plugin-spa.ts
28
+ // Do not hardcode here — it overrides the route-level config
29
+
30
+ type AstroCollectionEntry = Awaited<ReturnType<typeof getCollection>>[number]
31
+
32
+ interface BaseEntryData {
33
+ id: string
34
+ locale: string
35
+ title?: string
36
+ description?: string
37
+ created?: string | Date
38
+ modified?: string | Date
39
+ publishAt?: string | Date | null
40
+ unpublishAt?: string | Date | null
41
+ }
42
+
43
+ interface PageEntryData extends BaseEntryData {
44
+ pathname?: string
45
+ puckData?: Data
46
+ }
47
+
48
+ interface BlockEntryData extends BaseEntryData {
49
+ name?: string
50
+ mdx?: string
51
+ }
52
+
53
+ interface DataEntryData extends BaseEntryData {
54
+ name?: string
55
+ data?: Record<string, unknown>
56
+ }
57
+
58
+ /**
59
+ * Merge component defaultProps with stored sparse props.
60
+ *
61
+ * Mirrors the editor's mergeDefaultProps in PageEditorWrapper.tsx.
62
+ * Without this, new top-level fields added to a component after content was saved
63
+ * would render as undefined in production (Puck's Render doesn't apply defaultProps).
64
+ */
65
+ function mergeDefaultProps(data: Data, config: typeof puckConfig): Data {
66
+ if (!data?.content || !config?.components) return data
67
+
68
+ const mergeComponentProps = (item: Data['content'][0]): Data['content'][0] => {
69
+ const componentConfig = config.components[item.type]
70
+ if (!componentConfig?.defaultProps) return item
71
+
72
+ return {
73
+ ...item,
74
+ props: {
75
+ ...componentConfig.defaultProps,
76
+ ...item.props,
77
+ },
78
+ }
79
+ }
80
+
81
+ const mergedContent = data.content.map(mergeComponentProps)
82
+
83
+ let mergedZones = data.zones
84
+ if (data.zones) {
85
+ mergedZones = {}
86
+ for (const [zoneKey, zoneContent] of Object.entries(data.zones)) {
87
+ mergedZones[zoneKey] = zoneContent.map(mergeComponentProps)
88
+ }
89
+ }
90
+
91
+ return {
92
+ ...data,
93
+ content: mergedContent,
94
+ ...(mergedZones && { zones: mergedZones }),
95
+ }
96
+ }
97
+
98
+ const collectionCache = new Map<string, Promise<AstroCollectionEntry[]>>()
99
+ let evaluateMDXToComponentPromise: Promise<typeof import('@conloca/mdx/node').evaluateMDXToComponent> | undefined
100
+
101
+ async function loadEvaluateMDXToComponent() {
102
+ evaluateMDXToComponentPromise ??= import('@conloca/mdx/node').then((module) => module.evaluateMDXToComponent)
103
+
104
+ return evaluateMDXToComponentPromise
105
+ }
106
+
107
+ async function getCollectionEntries(collectionName: string) {
108
+ return (getCollection(collectionName as never) as Promise<AstroCollectionEntry[]>).catch((error) => {
109
+ if (error instanceof Error && error.message.includes(`The collection "${collectionName}" does not exist or is empty`)) {
110
+ return []
111
+ }
112
+
113
+ throw error
114
+ })
115
+ }
116
+
117
+ async function loadCollectionEntries(collectionName: string) {
118
+ if (import.meta.env.DEV) {
119
+ return getCollectionEntries(collectionName)
120
+ }
121
+
122
+ let entriesPromise = collectionCache.get(collectionName)
123
+
124
+ if (!entriesPromise) {
125
+ entriesPromise = getCollectionEntries(collectionName)
126
+ collectionCache.set(collectionName, entriesPromise)
127
+ }
128
+
129
+ return entriesPromise
130
+ }
131
+
132
+ async function getPageEntries(collectionName: string, locale: string) {
133
+ const entries = await loadCollectionEntries(collectionName)
134
+
135
+ return entries
136
+ .map((entry) => ({ entry, data: entry.data as Partial<PageEntryData> }))
137
+ .filter(({ data }) => data.locale === locale && typeof data.pathname === 'string' && isPublished(data as BaseEntryData))
138
+ }
139
+
140
+ function toPageReference(data: PageEntryData, collection: string): PageReference {
141
+ return {
142
+ id: data.id,
143
+ pathname: data.pathname || '/',
144
+ title: data.title,
145
+ collection,
146
+ meta: {
147
+ title: data.title,
148
+ description: data.description,
149
+ },
150
+ timestamps: {
151
+ created: toDate(data.created),
152
+ modified: toDate(data.modified),
153
+ },
154
+ }
155
+ }
156
+
157
+ async function getPagesByPrefix(prefix: string, locale: string, config: ResolvedRoutingConfig, options?: { sort?: 'date-desc' | 'date-asc' | 'title'; limit?: number }) {
158
+ const pageCollections = Array.from(new Set(Object.values(config.routes).map((route) => route.collection)))
159
+ const pages = (
160
+ await Promise.all(
161
+ pageCollections.map(async (collectionName) => {
162
+ const entries = await getPageEntries(collectionName, locale)
163
+
164
+ return entries.map(({ data }) => toPageReference(data as PageEntryData, collectionName))
165
+ }),
166
+ )
167
+ ).flat()
168
+
169
+ let filtered = pages.filter((page) => page.pathname.startsWith(prefix) && page.pathname !== prefix && page.pathname !== prefix.slice(0, -1))
170
+
171
+ if (options?.sort === 'date-asc') {
172
+ filtered.sort((a, b) => (a.timestamps?.modified || a.timestamps?.created || new Date(0)).getTime() - (b.timestamps?.modified || b.timestamps?.created || new Date(0)).getTime())
173
+ } else if (options?.sort === 'title') {
174
+ filtered.sort((a, b) => (a.title || '').localeCompare(b.title || ''))
175
+ } else {
176
+ filtered.sort((a, b) => (b.timestamps?.modified || b.timestamps?.created || new Date(0)).getTime() - (a.timestamps?.modified || a.timestamps?.created || new Date(0)).getTime())
177
+ }
178
+
179
+ if (options?.limit && options.limit > 0) {
180
+ filtered = filtered.slice(0, options.limit)
181
+ }
182
+
183
+ return filtered
184
+ }
185
+
186
+ async function getDataCollectionEntries(collectionName: string, locale: string) {
187
+ const entries = await loadCollectionEntries(collectionName)
188
+
189
+ return entries
190
+ .map((entry) => ({ entry, data: entry.data as Partial<DataEntryData> }))
191
+ .filter(({ data }) => data.locale === locale && typeof data.name === 'string' && isPublished(data as BaseEntryData))
192
+ .map(({ data }) => ({
193
+ id: data.id || '',
194
+ name: data.name || '',
195
+ data: data.data || {},
196
+ meta: {
197
+ title: data.title,
198
+ description: data.description,
199
+ },
200
+ })) satisfies DataCollectionEntry[]
201
+ }
202
+
203
+ async function loadMdxComponents(locale: string) {
204
+ const evaluateMDXToComponent = await loadEvaluateMDXToComponent()
205
+ const entries = (await loadCollectionEntries(ALL_BLOCKS_COLLECTION)).map((entry) => ({ entry, data: entry.data as Partial<BlockEntryData> }))
206
+
207
+ return Promise.all(
208
+ entries
209
+ .filter(({ data }) => data.locale === locale && typeof data.id === 'string' && isPublished(data as BaseEntryData))
210
+ .map(async ({ data }) => {
211
+ const title = data.title || data.name || data.id
212
+ const mdx = data.mdx
213
+
214
+ if (!mdx) {
215
+ if (import.meta.env.DEV) {
216
+ console.warn(`[Conloca] No MDX content found for block: ${title}`)
217
+ }
218
+ return {
219
+ id: data.id || title,
220
+ title,
221
+ Component: () => null,
222
+ }
223
+ }
224
+
225
+ const { Component, error } = await evaluateMDXToComponent(mdx)
226
+
227
+ if (!Component || error) {
228
+ const errorMessage = error?.message || 'MDX evaluation failed'
229
+ console.error(`[Conloca] MDX compilation error in block "${title}": ${errorMessage}`)
230
+
231
+ return {
232
+ id: data.id || title,
233
+ title,
234
+ Component: import.meta.env.DEV
235
+ ? () =>
236
+ React.createElement(
237
+ 'div',
238
+ { className: 'p-4 bg-red-50 border border-red-200 rounded text-red-600' },
239
+ React.createElement('p', { className: 'font-semibold mb-2' }, 'MDX Compilation Error'),
240
+ React.createElement('p', { className: 'text-sm' }, `Block: ${title}`),
241
+ React.createElement('p', { className: 'text-xs mt-2' }, errorMessage),
242
+ )
243
+ : () => null,
244
+ }
245
+ }
246
+
247
+ return {
248
+ id: data.id || title,
249
+ title,
250
+ Component,
251
+ }
252
+ }),
253
+ )
254
+ }
255
+
256
+ export const getStaticPaths: GetStaticPaths = async () => {
257
+ const config = routingConfig as ResolvedRoutingConfig
258
+ const paths: {
259
+ params: { slug: string | undefined }
260
+ props: { routeName: string; collection: string; pathname: string }
261
+ }[] = []
262
+
263
+ if (!config.enabled) {
264
+ return paths
265
+ }
266
+
267
+ for (const [routeName, routeConfig] of Object.entries(config.routes)) {
268
+ try {
269
+ const pages = (await getCollection(routeConfig.collection as never) as AstroCollectionEntry[])
270
+ .map((entry) => entry.data as Partial<PageEntryData>)
271
+ .filter((data) => {
272
+ if (data.locale !== config.locale || typeof data.pathname !== 'string') {
273
+ return false
274
+ }
275
+
276
+ return isPublished(data as BaseEntryData)
277
+ })
278
+
279
+ for (const data of pages) {
280
+ const pathname = data.pathname || '/'
281
+ const slug = extractSlugFromPathname(pathname, routeConfig.pattern)
282
+
283
+ paths.push({
284
+ params: { slug },
285
+ props: {
286
+ routeName,
287
+ collection: routeConfig.collection,
288
+ pathname,
289
+ },
290
+ })
291
+ }
292
+ } catch (error) {
293
+ console.error(`[Conloca] Error loading pages for route '${routeName}':`, error)
294
+ }
295
+ }
296
+
297
+ if (import.meta.env.DEV) {
298
+ if (paths.length === 0) {
299
+ console.warn(
300
+ '[Conloca] getStaticPaths returned 0 pages. '
301
+ + 'Check that content collections are populated and pages have locale/pathname fields.',
302
+ )
303
+ } else {
304
+ console.debug(`[Conloca] getStaticPaths: ${paths.length} page(s)`)
305
+ }
306
+ }
307
+
308
+ return paths
309
+ }
310
+
311
+ interface Props {
312
+ routeName: string
313
+ collection: string
314
+ pathname: string
315
+ }
316
+
317
+ const config = routingConfig as ResolvedRoutingConfig
318
+
319
+ // In prerender mode, props come from getStaticPaths().
320
+ // In SSR mode (prerender: false), derive from the request URL.
321
+ const propsFromStaticPaths = Astro.props as Partial<Props>
322
+ let routeName = propsFromStaticPaths.routeName
323
+ let collection = propsFromStaticPaths.collection
324
+ let pathname = propsFromStaticPaths.pathname
325
+
326
+ if (!routeName || !collection || !pathname) {
327
+ // SSR fallback: match URL against configured routes
328
+ const requestPath = Astro.url.pathname
329
+ for (const [name, routeConfig] of Object.entries(config.routes)) {
330
+ const prefix = routeConfig.pattern.replace(/\[.*$/, '').replace(/\/$/, '')
331
+ if (requestPath === prefix || requestPath.startsWith(prefix + '/') || prefix === '') {
332
+ routeName = name
333
+ collection = routeConfig.collection
334
+ pathname = requestPath
335
+ break
336
+ }
337
+ }
338
+ }
339
+
340
+ let page: PageData | undefined
341
+ let loadError: Error | undefined
342
+
343
+ try {
344
+ const entries = await getPageEntries(collection, config.locale)
345
+ const matchedPage = entries.find(({ data }) => data.pathname === pathname)
346
+
347
+ if (!matchedPage) {
348
+ const error = new Error(`Page not found: ${pathname}`) as Error & { code?: string }
349
+ error.code = 'PAGE_NOT_FOUND'
350
+ throw error
351
+ }
352
+
353
+ const data = matchedPage.data as PageEntryData
354
+ const routeConfig = config.routes[routeName]
355
+
356
+ page = {
357
+ id: data.id,
358
+ title: data.title || data.id,
359
+ description: data.description,
360
+ pathname,
361
+ puckData: data.puckData as Data,
362
+ collection,
363
+ route: {
364
+ name: routeName,
365
+ pattern: routeConfig.pattern,
366
+ meta: routeConfig.meta,
367
+ },
368
+ meta: {
369
+ title: data.title,
370
+ description: data.description,
371
+ },
372
+ timestamps: {
373
+ created: toDate(data.created),
374
+ modified: toDate(data.modified),
375
+ published: toDate(data.publishAt),
376
+ },
377
+ }
378
+ } catch (error) {
379
+ loadError = error as Error
380
+
381
+ if ((error as { code?: string }).code === 'PAGE_NOT_FOUND') {
382
+ if (config.fallback === 'passthrough') {
383
+ return Astro.redirect('/404', 307)
384
+ }
385
+
386
+ return new Response('Page not found', { status: 404 })
387
+ }
388
+
389
+ throw error
390
+ }
391
+
392
+ let dataContext: DataContext | undefined
393
+
394
+ const routeConfig = config.routes[routeName]
395
+ const hasCollections = routeConfig?.dataBindings?.collections?.length
396
+ const hasPages = routeConfig?.dataBindings?.pages?.prefix
397
+
398
+ if (hasCollections || hasPages) {
399
+ const collections: Record<string, DataCollectionEntry[]> = {}
400
+ let pages: PageReference[] | undefined
401
+
402
+ if (hasCollections) {
403
+ for (const collectionName of routeConfig.dataBindings.collections) {
404
+ try {
405
+ const locale = routeConfig.dataBindings.locale ?? config.locale
406
+ collections[collectionName] = await getDataCollectionEntries(collectionName, locale)
407
+ } catch (error) {
408
+ console.error(`[Conloca] Failed to fetch collection '${collectionName}':`, error)
409
+ collections[collectionName] = []
410
+ }
411
+ }
412
+ }
413
+
414
+ if (hasPages) {
415
+ try {
416
+ const pagesConfig = routeConfig.dataBindings.pages
417
+ pages = await getPagesByPrefix(pagesConfig.prefix, routeConfig.dataBindings.locale ?? config.locale, config, {
418
+ sort: pagesConfig.sort,
419
+ limit: pagesConfig.limit,
420
+ })
421
+ } catch (error) {
422
+ console.error(`[Conloca] Failed to fetch pages with prefix '${routeConfig.dataBindings.pages.prefix}':`, error)
423
+ pages = []
424
+ }
425
+ }
426
+
427
+ dataContext = {
428
+ collections,
429
+ pages,
430
+ locale: routeConfig.dataBindings.locale ?? config.locale,
431
+ siteName: config.siteName,
432
+ }
433
+ }
434
+
435
+ const hasPuckData = !!page?.puckData && Object.keys(page.puckData).length > 0
436
+ let resolvedPuckData = page?.puckData
437
+
438
+ if (hasPuckData && page) {
439
+ const mergedData = mergeDefaultProps(page.puckData, puckConfig)
440
+ try {
441
+ resolvedPuckData = await resolveAllData(
442
+ mergedData,
443
+ puckConfig,
444
+ dataContext ? { metadata: dataContext } : undefined,
445
+ )
446
+ } catch (error) {
447
+ console.error('[Conloca] resolveAllData failed:', error)
448
+ resolvedPuckData = mergedData
449
+ }
450
+ }
451
+
452
+ const needsHydration = hasPuckData && resolvedPuckData && hasHydratableComponents(resolvedPuckData, puckConfig)
453
+
454
+ let PageRenderer: ComponentType | undefined
455
+
456
+ if (hasPuckData && page && resolvedPuckData) {
457
+ try {
458
+ const mdxComponents = await loadMdxComponents(config.locale)
459
+ PageRenderer = createPageRendererWithBlocks(puckConfig, resolvedPuckData, mdxComponents)
460
+ } catch (error) {
461
+ console.error('[Conloca] MDX evaluation failed, falling back to plain render:', error)
462
+ PageRenderer = undefined
463
+ }
464
+ }
465
+
466
+ ---
467
+
468
+ {Layout && page ? (
469
+ <Layout title={page.title ?? 'Page'} description={page.description}>
470
+ {hasPuckData && PageRenderer ? (
471
+ <PageRenderer />
472
+ ) : hasPuckData && resolvedPuckData ? (
473
+ needsHydration ? (
474
+ <RenderWithHydration config={puckConfig} data={resolvedPuckData} />
475
+ ) : (
476
+ <Render config={puckConfig} data={resolvedPuckData} />
477
+ )
478
+ ) : (
479
+ <div class="conloca-empty-page">
480
+ <p>This page has no content yet.</p>
481
+ </div>
482
+ )}
483
+ </Layout>
484
+ ) : page ? (
485
+ <html lang={config.locale || 'en'}>
486
+ <head>
487
+ <meta charset="UTF-8" />
488
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
489
+ <title>{page.title || 'Untitled'}</title>
490
+ {page.description && <meta name="description" content={page.description} />}
491
+ {needsHydration && <script>import 'virtual:conloca-hydration-entry'</script>}
492
+ </head>
493
+ <body>
494
+ {hasPuckData && PageRenderer ? (
495
+ <PageRenderer />
496
+ ) : hasPuckData && resolvedPuckData ? (
497
+ needsHydration ? (
498
+ <RenderWithHydration config={puckConfig} data={resolvedPuckData} />
499
+ ) : (
500
+ <Render config={puckConfig} data={resolvedPuckData} />
501
+ )
502
+ ) : (
503
+ <div class="conloca-empty-page">
504
+ <p>This page has no content yet.</p>
505
+ </div>
506
+ )}
507
+ </body>
508
+ </html>
509
+ ) : (
510
+ <html lang="en">
511
+ <head>
512
+ <meta charset="UTF-8" />
513
+ <title>Error</title>
514
+ </head>
515
+ <body>
516
+ <div class="conloca-error">
517
+ <h1>Error Loading Page</h1>
518
+ <p>{import.meta.env.DEV ? (loadError?.message || 'An unknown error occurred.') : 'An error occurred while loading this page.'}</p>
519
+ </div>
520
+ </body>
521
+ </html>
522
+ )}
523
+
524
+ {Layout && needsHydration && <script>import 'virtual:conloca-hydration-entry'</script>}
525
+
526
+ <style>
527
+ .conloca-empty-page {
528
+ padding: 2rem;
529
+ text-align: center;
530
+ color: #666;
531
+ }
532
+
533
+ .conloca-error {
534
+ padding: 2rem;
535
+ text-align: center;
536
+ }
537
+
538
+ .conloca-error h1 {
539
+ color: #c00;
540
+ }
541
+ </style>
@@ -1,4 +1,4 @@
1
- import { t as HydrationStrategy } from "../types-Bsd_qENn.mjs";
1
+ import { t as HydrationStrategy } from "../types-CVQNmPxF.mjs";
2
2
 
3
3
  //#region src/lib/hydration-script.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { createContentAPI } from "@conloca/content-api/node";
1
+ import { createContentAPI } from "@conloca/content-api/reader";
2
2
 
3
3
  //#region src/loader.ts
4
4
  /**
@@ -22,10 +22,14 @@ function conlocaLoader(options) {
22
22
  if (!localeVersion) continue;
23
23
  const entryId = `${manifest.id}/${locale}`;
24
24
  let dataContent;
25
+ let mdxContent;
25
26
  let puckData;
26
27
  if (kind === "data") {
27
28
  const fullContent = await api.getLocalized(manifest.id, locale);
28
29
  if (fullContent?.localized.content?.data) dataContent = fullContent.localized.content.data;
30
+ } else if (kind === "block") {
31
+ const fullContent = await api.getLocalized(manifest.id, locale);
32
+ if (fullContent?.localized.content?.mdx) mdxContent = fullContent.localized.content.mdx;
29
33
  } else if (kind === "page") {
30
34
  const fullContent = await api.getLocalized(manifest.id, locale);
31
35
  if (fullContent?.localized.content?.puckData) puckData = fullContent.localized.content.puckData;
@@ -36,10 +40,13 @@ function conlocaLoader(options) {
36
40
  ...localeVersion.pathname && { pathname: localeVersion.pathname },
37
41
  ...localeVersion.name && { name: localeVersion.name },
38
42
  ...localeVersion.meta,
43
+ created: localeVersion.created,
44
+ modified: localeVersion.modified,
39
45
  publishAt: localeVersion.publishAt,
40
46
  unpublishAt: localeVersion.unpublishAt,
41
47
  ...dataContent && { data: dataContent }
42
48
  };
49
+ if (mdxContent !== void 0) data.mdx = mdxContent;
43
50
  if (puckData !== void 0) data.puckData = puckData;
44
51
  const parsedData = await parseData({
45
52
  id: entryId,
@@ -51,11 +58,11 @@ function conlocaLoader(options) {
51
58
  digest: generateDigest(localeVersion.etag)
52
59
  });
53
60
  }
54
- logger.info(`Loaded ${store.keys().length} entries from ${options.collection}`);
61
+ logger.info(`Loaded ${store.keys().length} entries from ${options.collection || `${kind} content`}`);
55
62
  }
56
63
  };
57
64
  }
58
65
 
59
66
  //#endregion
60
67
  export { conlocaLoader as t };
61
- //# sourceMappingURL=loader-W3i9kf3p.mjs.map
68
+ //# sourceMappingURL=loader-By-AQWHc.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader-By-AQWHc.mjs","names":[],"sources":["../src/loader.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 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"],"mappings":";;;;;;;AAeA,SAAgB,cAAc,SAAuC;AACnE,QAAO;EACL,MAAM;EACN,MAAM,KAAK,SAAuC;GAChD,MAAM,EAAE,OAAO,WAAW,gBAAgB,WAAW;GAGrD,MAAM,MAAM,MAAM,iBAAiB,EAAE,aAAa,QAAQ,aAAa,CAAC;GAGxE,MAAM,OAAO,QAAQ,SAAS,QAAQ,eAAe,WAAW,UAAU;GAI1E,MAAM,UAAU,MAAM,KACpB,IAAI,eAAe;IACjB,YAAY,QAAQ;IACpB;IACA,MAAM,SAAS,SAAS,QAAQ,OAAO;IACxC,CAAC,CACH;AAED,SAAM,OAAO;AAEb,QAAK,MAAM,YAAY,QACrB,MAAK,MAAM,CAAC,QAAQ,kBAAkB,OAAO,QAAQ,SAAS,QAAQ,EAAE;AACtE,QAAI,CAAC,cAAe;IAEpB,MAAM,UAAU,GAAG,SAAS,GAAG,GAAG;IAGlC,IAAI;IACJ,IAAI;IACJ,IAAI;AAEJ,QAAI,SAAS,QAAQ;KACnB,MAAM,cAAc,MAAM,IAAI,aAAa,SAAS,IAAI,OAAO;AAC/D,SAAI,aAAa,UAAU,SAAS,KAClC,eAAc,YAAY,UAAU,QAAQ;eAErC,SAAS,SAAS;KAC3B,MAAM,cAAc,MAAM,IAAI,aAAa,SAAS,IAAI,OAAO;AAC/D,SAAI,aAAa,UAAU,SAAS,IAClC,cAAa,YAAY,UAAU,QAAQ;eAEpC,SAAS,QAAQ;KAG1B,MAAM,cAAc,MAAM,IAAI,aAAa,SAAS,IAAI,OAAO;AAC/D,SAAI,aAAa,UAAU,SAAS,SAClC,YAAW,YAAY,UAAU,QAAQ;;IAI7C,MAAM,OAAgC;KACpC,IAAI,SAAS;KACb;KACA,GAAI,cAAc,YAAY,EAAE,UAAU,cAAc,UAAU;KAClE,GAAI,cAAc,QAAQ,EAAE,MAAM,cAAc,MAAM;KACtD,GAAG,cAAc;KACjB,SAAS,cAAc;KACvB,UAAU,cAAc;KACxB,WAAW,cAAc;KACzB,aAAa,cAAc;KAE3B,GAAI,eAAe,EAAE,MAAM,aAAa;KACzC;AAED,QAAI,eAAe,OACjB,MAAK,MAAM;AAIb,QAAI,aAAa,OACf,MAAK,WAAW;IAGlB,MAAM,aAAa,MAAM,UAAU;KAAE,IAAI;KAAS;KAAM,CAAC;AAEzD,UAAM,IAAI;KACR,IAAI;KACJ,MAAM;KACN,QAAQ,eAAe,cAAc,KAAK;KAC3C,CAAC;;AAIN,UAAO,KAAK,UAAU,MAAM,MAAM,CAAC,OAAO,gBAAgB,QAAQ,cAAc,GAAG,KAAK,YAAY;;EAEvG"}
@@ -0,0 +1,19 @@
1
+ import { ALL_BLOCKS_COLLECTION, ConlocaCollectionsResult, CreateConlocaCollectionsOptions, createConlocaCollections } from "../collections.mjs";
2
+ import { Loader } from "astro/loaders";
3
+
4
+ //#region src/loader.d.ts
5
+ interface ConlocaLoaderOptions {
6
+ collection?: string;
7
+ contentRoot: string;
8
+ site?: string;
9
+ /** Collection kind. If not provided, defaults to 'block' for 'blocks' collection, 'page' otherwise. */
10
+ kind?: 'page' | 'block' | 'data';
11
+ }
12
+ /**
13
+ * Custom Astro content loader for Conloca CMS.
14
+ * Loads content from the Conloca content directory into Astro collections.
15
+ */
16
+ declare function conlocaLoader(options: ConlocaLoaderOptions): Loader;
17
+ //#endregion
18
+ export { ALL_BLOCKS_COLLECTION, type ConlocaCollectionsResult, type ConlocaLoaderOptions, type CreateConlocaCollectionsOptions, conlocaLoader, createConlocaCollections };
19
+ //# sourceMappingURL=content.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.mts","names":[],"sources":["../../src/loader.ts"],"mappings":";;;;UAGiB,oBAAA;EACf,UAAA;EACA,WAAA;EACA,IAAA;EAHmC;EAKnC,IAAA;AAAA;;;;;iBAOc,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,MAAA"}
@@ -0,0 +1,4 @@
1
+ import { t as conlocaLoader } from "../loader-By-AQWHc.mjs";
2
+ import { ALL_BLOCKS_COLLECTION, createConlocaCollections } from "../collections.mjs";
3
+
4
+ export { ALL_BLOCKS_COLLECTION, conlocaLoader, createConlocaCollections };
@@ -0,0 +1,52 @@
1
+ import { n as RoutingConfigInput, r as TemplateConfig } from "../types-CVQNmPxF.mjs";
2
+ import { UIConfig } from "@conloca/cms-spa";
3
+ import { AstroIntegration } from "astro";
4
+
5
+ //#region src/plugin-spa.d.ts
6
+ interface ConlocaCMSOptions extends Omit<UIConfig, 'basename'> {
7
+ contentRoot: string;
8
+ canvasDir?: string;
9
+ route?: string;
10
+ puckConfigPath: string;
11
+ schemasPath?: string;
12
+ /**
13
+ * Default layout for content pages.
14
+ * When provided without routing config, enables routing with catch-all pattern.
15
+ * For multi-route setups, use routing.routes.{name}.layout instead.
16
+ *
17
+ * @example './src/layouts/Layout.astro'
18
+ */
19
+ layout?: string;
20
+ routing?: RoutingConfigInput;
21
+ templates?: Record<string, TemplateConfig>;
22
+ /**
23
+ * Paths to scan for hydratable components.
24
+ * Components using withHydration() in these directories are auto-discovered.
25
+ *
26
+ * @example ['src/components/puck']
27
+ */
28
+ componentPaths?: string[];
29
+ /**
30
+ * Path to the assets directory for image uploads.
31
+ * When provided, enables the Media Library and asset upload API routes.
32
+ *
33
+ * @example 'src/assets/uploads'
34
+ */
35
+ assetsPath?: string;
36
+ /**
37
+ * CSS files to load in the CMS editor for component preview styling.
38
+ *
39
+ * Each file is processed by Vite (Tailwind, PostCSS, etc.) and injected
40
+ * directly into Puck's preview iframe `<head>`. Site CSS never enters the
41
+ * CMS admin's parent document, so host-site styles cannot bleed into the
42
+ * CMS chrome (drawer, sidebar, etc.).
43
+ *
44
+ * @example './src/styles/global.css'
45
+ * @example ['./src/styles/global.css', './src/styles/theme.css']
46
+ */
47
+ siteStyles?: string | string[];
48
+ }
49
+ declare function conlocaCMS(options: ConlocaCMSOptions): AstroIntegration;
50
+ //#endregion
51
+ export { type ConlocaCMSOptions, conlocaCMS };
52
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/plugin-spa.ts"],"mappings":";;;;;UAsEiB,iBAAA,SAA0B,IAAA,CAAK,QAAA;EAC9C,WAAA;EACA,SAAA;EACA,KAAA;EACA,cAAA;EACA,WAAA;EAWU;;;;;;;EAFV,MAAA;EAEA,OAAA,GAAU,kBAAA;EACV,SAAA,GAAY,MAAA,SAAe,cAAA;EAd3B;;;;;;EAsBA,cAAA;EARY;;;;;;EAgBZ,UAAA;EAgIc;;;;;;;;;;;EAnHd,UAAA;AAAA;AAAA,iBAmHc,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAoB,gBAAA"}