@conloca/astro-cms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -0
- package/dist/cms-handler.d.mts +23 -0
- package/dist/cms-handler.d.mts.map +1 -0
- package/dist/cms-handler.mjs +221 -0
- package/dist/cms-handler.mjs.map +1 -0
- package/dist/collections.d.mts +36 -0
- package/dist/collections.d.mts.map +1 -0
- package/dist/collections.mjs +56 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/components.d.mts +46 -0
- package/dist/components.d.mts.map +1 -0
- package/dist/components.mjs +167 -0
- package/dist/components.mjs.map +1 -0
- package/dist/hydration-script-CKamSyIx.d.mts +461 -0
- package/dist/hydration-script-CKamSyIx.d.mts.map +1 -0
- package/dist/hydration.d.mts +3 -0
- package/dist/hydration.mjs +3 -0
- package/dist/index.d.mts +148 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +770 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/hydration-script.d.mts +2 -0
- package/dist/lib/hydration-script.mjs +85 -0
- package/dist/lib/hydration-script.mjs.map +1 -0
- package/dist/loader-C6JF2toW.mjs +61 -0
- package/dist/loader-C6JF2toW.mjs.map +1 -0
- package/dist/serialize-props-BryTdVgJ.mjs +73 -0
- package/dist/serialize-props-BryTdVgJ.mjs.map +1 -0
- package/dist/withHydration-C6l6XnF2.d.mts +52 -0
- package/dist/withHydration-C6l6XnF2.d.mts.map +1 -0
- package/dist/withHydration-DAkXCF9z.mjs +45 -0
- package/dist/withHydration-DAkXCF9z.mjs.map +1 -0
- package/package.json +102 -0
- package/src/handlers/page-handler.astro +298 -0
- package/src/virtual-modules.d.ts +144 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { Data } from "@measured/puck";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hydration strategy for Puck components in production.
|
|
7
|
+
*
|
|
8
|
+
* Determines when a component's React code loads and hydrates on the client.
|
|
9
|
+
* Only components with explicit hydration strategy will ship JavaScript.
|
|
10
|
+
*
|
|
11
|
+
* @example In puck.config.tsx
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const FilteredGrid: ComponentConfig<Props> & { hydration?: HydrationStrategy } = {
|
|
14
|
+
* hydration: 'visible', // Hydrate when scrolled into view
|
|
15
|
+
* fields: { ... },
|
|
16
|
+
* render: (props) => <FilteredGridComponent {...props} />,
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Strategies:
|
|
21
|
+
* - 'none': No hydration, pure static HTML (default, current behavior)
|
|
22
|
+
* - 'load': Hydrate immediately on page load (client:load)
|
|
23
|
+
* - 'visible': Hydrate when component enters viewport (client:visible)
|
|
24
|
+
* - 'idle': Hydrate when browser is idle (client:idle)
|
|
25
|
+
*/
|
|
26
|
+
type HydrationStrategy = 'none' | 'load' | 'visible' | 'idle';
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for Conloca's content page routing system.
|
|
29
|
+
*
|
|
30
|
+
* The routing system allows sites to declare which URL patterns
|
|
31
|
+
* map to which content collections, eliminating the need for
|
|
32
|
+
* manual [...slug].astro files.
|
|
33
|
+
*
|
|
34
|
+
* @example Minimal configuration (uses all defaults)
|
|
35
|
+
* ```typescript
|
|
36
|
+
* conlocaCMS({
|
|
37
|
+
* contentRoot: '../content',
|
|
38
|
+
* puckConfigPath: './src/puck.config.tsx',
|
|
39
|
+
* routing: true, // Enable with all defaults
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Full configuration
|
|
44
|
+
* ```typescript
|
|
45
|
+
* conlocaCMS({
|
|
46
|
+
* contentRoot: '../content',
|
|
47
|
+
* puckConfigPath: './src/puck.config.tsx',
|
|
48
|
+
* routing: {
|
|
49
|
+
* enabled: true,
|
|
50
|
+
* routes: {
|
|
51
|
+
* pages: {
|
|
52
|
+
* pattern: '/[...slug]',
|
|
53
|
+
* collection: 'pages',
|
|
54
|
+
* layout: './src/layouts/Layout.astro',
|
|
55
|
+
* prerender: true,
|
|
56
|
+
* },
|
|
57
|
+
* blog: {
|
|
58
|
+
* pattern: '/blog/[slug]',
|
|
59
|
+
* collection: 'posts',
|
|
60
|
+
* layout: './src/layouts/BlogLayout.astro',
|
|
61
|
+
* },
|
|
62
|
+
* },
|
|
63
|
+
* fallback: '404',
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
interface RoutingConfig {
|
|
69
|
+
/**
|
|
70
|
+
* Whether routing is enabled.
|
|
71
|
+
*
|
|
72
|
+
* When false, no content routes are injected and sites must
|
|
73
|
+
* handle routing manually (backward-compatible mode).
|
|
74
|
+
*
|
|
75
|
+
* @default true (when routing config object is provided)
|
|
76
|
+
*/
|
|
77
|
+
enabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Route definitions mapping URL patterns to content collections.
|
|
80
|
+
*
|
|
81
|
+
* Each key is a route identifier (for debugging/logging).
|
|
82
|
+
* The value defines how that route behaves.
|
|
83
|
+
*
|
|
84
|
+
* If not provided, a default 'pages' route is created:
|
|
85
|
+
* - pattern: '/[...slug]'
|
|
86
|
+
* - collection: 'pages' (auto-discovered from content)
|
|
87
|
+
* - layout: undefined (uses default Astro layout behavior)
|
|
88
|
+
* - prerender: true
|
|
89
|
+
*
|
|
90
|
+
* @default { pages: { pattern: '/[...slug]', collection: 'pages', prerender: true } }
|
|
91
|
+
*/
|
|
92
|
+
routes?: Record<string, RouteConfig>;
|
|
93
|
+
/**
|
|
94
|
+
* Behavior when a route pattern matches but no content exists.
|
|
95
|
+
*
|
|
96
|
+
* - '404': Return a 404 response (standard behavior)
|
|
97
|
+
* - 'passthrough': Let Astro continue to the next route handler
|
|
98
|
+
*
|
|
99
|
+
* 'passthrough' is useful when you have both CMS-managed pages
|
|
100
|
+
* and file-based pages coexisting during migration.
|
|
101
|
+
*
|
|
102
|
+
* @default '404'
|
|
103
|
+
*/
|
|
104
|
+
fallback?: '404' | 'passthrough';
|
|
105
|
+
/**
|
|
106
|
+
* What to do when an injected route conflicts with an existing file-based route.
|
|
107
|
+
*
|
|
108
|
+
* - 'warn': Log a warning but proceed (injected route takes precedence)
|
|
109
|
+
* - 'error': Fail the build with an error
|
|
110
|
+
* - 'silent': No message (injected route takes precedence)
|
|
111
|
+
*
|
|
112
|
+
* Conflicts are detected during the 'astro:routes:resolved' hook.
|
|
113
|
+
*
|
|
114
|
+
* @default 'warn'
|
|
115
|
+
*/
|
|
116
|
+
onConflict?: 'warn' | 'error' | 'silent';
|
|
117
|
+
/**
|
|
118
|
+
* Site name for content resolution.
|
|
119
|
+
*
|
|
120
|
+
* Used by PageAPI to call contentApi.getSite(siteName).
|
|
121
|
+
* Allows multi-site content directories with a single configuration.
|
|
122
|
+
*
|
|
123
|
+
* @example Multi-site setup with different content directories
|
|
124
|
+
* ```typescript
|
|
125
|
+
* conlocaCMS({
|
|
126
|
+
* contentRoot: '../content',
|
|
127
|
+
* routing: {
|
|
128
|
+
* enabled: true,
|
|
129
|
+
* siteName: 'marketing', // Load content from 'marketing' site
|
|
130
|
+
* },
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @default 'default'
|
|
135
|
+
*/
|
|
136
|
+
siteName?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Default locale for content resolution.
|
|
139
|
+
*
|
|
140
|
+
* Used by PageAPI for listPages(locale) and getByPathname(pathname, locale).
|
|
141
|
+
* Can be extended later for multi-locale routing.
|
|
142
|
+
*
|
|
143
|
+
* @example Non-English content site
|
|
144
|
+
* ```typescript
|
|
145
|
+
* conlocaCMS({
|
|
146
|
+
* contentRoot: '../content',
|
|
147
|
+
* routing: {
|
|
148
|
+
* enabled: true,
|
|
149
|
+
* locale: 'de', // German content
|
|
150
|
+
* },
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @default 'en'
|
|
155
|
+
*/
|
|
156
|
+
locale?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Shorthand for enabling routing with all defaults.
|
|
160
|
+
*
|
|
161
|
+
* When `routing: true` is passed, it's equivalent to:
|
|
162
|
+
* ```typescript
|
|
163
|
+
* routing: {
|
|
164
|
+
* enabled: true,
|
|
165
|
+
* routes: { pages: { pattern: '/[...slug]', collection: 'pages', prerender: true } },
|
|
166
|
+
* fallback: '404',
|
|
167
|
+
* onConflict: 'warn',
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
type RoutingConfigInput = boolean | RoutingConfig;
|
|
172
|
+
/**
|
|
173
|
+
* Configuration for a single route mapping.
|
|
174
|
+
*
|
|
175
|
+
* Defines how a URL pattern maps to content from a collection,
|
|
176
|
+
* which layout to use, and rendering behavior.
|
|
177
|
+
*
|
|
178
|
+
* @example Catch-all pages route
|
|
179
|
+
* ```typescript
|
|
180
|
+
* {
|
|
181
|
+
* pattern: '/[...slug]',
|
|
182
|
+
* collection: 'pages',
|
|
183
|
+
* layout: './src/layouts/Layout.astro',
|
|
184
|
+
* prerender: true,
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example Blog route with specific prefix
|
|
189
|
+
* ```typescript
|
|
190
|
+
* {
|
|
191
|
+
* pattern: '/blog/[slug]',
|
|
192
|
+
* collection: 'posts',
|
|
193
|
+
* layout: './src/layouts/BlogLayout.astro',
|
|
194
|
+
* prerender: true,
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example SSR route (no static generation)
|
|
199
|
+
* ```typescript
|
|
200
|
+
* {
|
|
201
|
+
* pattern: '/preview/[...slug]',
|
|
202
|
+
* collection: 'pages',
|
|
203
|
+
* prerender: false,
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
interface RouteConfig {
|
|
208
|
+
/**
|
|
209
|
+
* Astro route pattern for URL matching.
|
|
210
|
+
*
|
|
211
|
+
* Must be a valid Astro route pattern:
|
|
212
|
+
* - '/about' - Exact match
|
|
213
|
+
* - '/blog/[slug]' - Single dynamic segment
|
|
214
|
+
* - '/[...slug]' - Catch-all (rest parameter)
|
|
215
|
+
* - '/docs/[...path]' - Catch-all with prefix
|
|
216
|
+
*
|
|
217
|
+
* The pattern is passed directly to Astro's injectRoute() API.
|
|
218
|
+
*
|
|
219
|
+
* IMPORTANT: Pattern must start with '/'
|
|
220
|
+
* IMPORTANT: Catch-all patterns ([...param]) capture everything after the prefix
|
|
221
|
+
*/
|
|
222
|
+
pattern: string;
|
|
223
|
+
/**
|
|
224
|
+
* Content collection to use for this route.
|
|
225
|
+
*
|
|
226
|
+
* Must match a collection in the content directory.
|
|
227
|
+
* Typically 'pages' for general content or a specific
|
|
228
|
+
* collection like 'posts' for blog content.
|
|
229
|
+
*
|
|
230
|
+
* If not specified, defaults to 'pages'.
|
|
231
|
+
*
|
|
232
|
+
* The collection is used to:
|
|
233
|
+
* 1. Discover available paths for getStaticPaths()
|
|
234
|
+
* 2. Load page data for the matched route
|
|
235
|
+
*
|
|
236
|
+
* @default 'pages'
|
|
237
|
+
*/
|
|
238
|
+
collection?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Path to the Astro layout component.
|
|
241
|
+
*
|
|
242
|
+
* The layout wraps the Puck-rendered content. It receives
|
|
243
|
+
* LayoutProps with page metadata and children.
|
|
244
|
+
*
|
|
245
|
+
* Path resolution:
|
|
246
|
+
* - Relative paths (./src/...) resolve from project root
|
|
247
|
+
* - Can be an Astro component (.astro) or React component (.tsx)
|
|
248
|
+
*
|
|
249
|
+
* If not specified, the page handler renders content without
|
|
250
|
+
* a layout wrapper (Puck content only).
|
|
251
|
+
*
|
|
252
|
+
* @example './src/layouts/Layout.astro'
|
|
253
|
+
* @example './src/layouts/BlogLayout.tsx'
|
|
254
|
+
*/
|
|
255
|
+
layout?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Whether to statically generate pages at build time.
|
|
258
|
+
*
|
|
259
|
+
* - true: Generate static HTML at build time (SSG)
|
|
260
|
+
* - false: Render on each request (SSR)
|
|
261
|
+
*
|
|
262
|
+
* SSG (true) is recommended for most content sites:
|
|
263
|
+
* - Faster page loads
|
|
264
|
+
* - Lower hosting costs
|
|
265
|
+
* - Works with static hosting
|
|
266
|
+
*
|
|
267
|
+
* SSR (false) is useful for:
|
|
268
|
+
* - Preview routes
|
|
269
|
+
* - Personalized content
|
|
270
|
+
* - Frequently updated content
|
|
271
|
+
*
|
|
272
|
+
* @default true
|
|
273
|
+
*/
|
|
274
|
+
prerender?: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Additional route metadata passed to the page handler.
|
|
277
|
+
*
|
|
278
|
+
* This allows route-specific customization that the
|
|
279
|
+
* layout or page handler can access.
|
|
280
|
+
*
|
|
281
|
+
* @example { showSidebar: true, theme: 'dark' }
|
|
282
|
+
*/
|
|
283
|
+
meta?: Record<string, unknown>;
|
|
284
|
+
/**
|
|
285
|
+
* Data binding configuration for this route.
|
|
286
|
+
*
|
|
287
|
+
* Specifies which data collections should be fetched and
|
|
288
|
+
* injected into Puck component resolvers via metadata.
|
|
289
|
+
*
|
|
290
|
+
* @example Inject team and testimonials data
|
|
291
|
+
* ```typescript
|
|
292
|
+
* {
|
|
293
|
+
* pattern: '/[...slug]',
|
|
294
|
+
* dataBindings: {
|
|
295
|
+
* collections: ['team', 'testimonials'],
|
|
296
|
+
* },
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
dataBindings?: DataBindingConfig;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Configuration for automatic data collection injection into Puck components.
|
|
304
|
+
*
|
|
305
|
+
* Allows components to declare data dependencies on Conloca data collections,
|
|
306
|
+
* which are automatically fetched and injected via Puck's metadata system.
|
|
307
|
+
*
|
|
308
|
+
* @example Route with data bindings
|
|
309
|
+
* ```typescript
|
|
310
|
+
* conlocaCMS({
|
|
311
|
+
* routing: {
|
|
312
|
+
* routes: {
|
|
313
|
+
* pages: {
|
|
314
|
+
* pattern: '/[...slug]',
|
|
315
|
+
* dataBindings: {
|
|
316
|
+
* collections: ['team', 'testimonials'],
|
|
317
|
+
* },
|
|
318
|
+
* },
|
|
319
|
+
* },
|
|
320
|
+
* },
|
|
321
|
+
* });
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
interface DataBindingConfig {
|
|
325
|
+
/**
|
|
326
|
+
* Collections to fetch and inject into component resolvers.
|
|
327
|
+
*
|
|
328
|
+
* Each collection name must match a data collection in the content directory.
|
|
329
|
+
* The fetched data will be available in `metadata.collections[collectionName]`
|
|
330
|
+
* within Puck component resolvers.
|
|
331
|
+
*
|
|
332
|
+
* @example ['team', 'testimonials', 'products']
|
|
333
|
+
*/
|
|
334
|
+
collections?: string[];
|
|
335
|
+
/**
|
|
336
|
+
* Locale override for data fetching.
|
|
337
|
+
*
|
|
338
|
+
* Defaults to the route's locale setting (from routing.locale).
|
|
339
|
+
* Use this to fetch data in a specific locale regardless of route config.
|
|
340
|
+
*/
|
|
341
|
+
locale?: string;
|
|
342
|
+
/**
|
|
343
|
+
* Page discovery configuration for listing pages by path prefix.
|
|
344
|
+
*
|
|
345
|
+
* Enables components to access lists of pages matching a URL pattern,
|
|
346
|
+
* useful for blog listings, category pages, and site navigation.
|
|
347
|
+
*
|
|
348
|
+
* @example Blog listing page
|
|
349
|
+
* ```typescript
|
|
350
|
+
* {
|
|
351
|
+
* pattern: '/blog',
|
|
352
|
+
* dataBindings: {
|
|
353
|
+
* pages: {
|
|
354
|
+
* prefix: '/blog/',
|
|
355
|
+
* sort: 'date-desc',
|
|
356
|
+
* limit: 10,
|
|
357
|
+
* },
|
|
358
|
+
* },
|
|
359
|
+
* }
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
pages?: {
|
|
363
|
+
/**
|
|
364
|
+
* Path prefix to filter pages.
|
|
365
|
+
*
|
|
366
|
+
* Only pages whose pathname starts with this prefix are included.
|
|
367
|
+
* The listing page itself is excluded.
|
|
368
|
+
*
|
|
369
|
+
* @example '/blog/' matches '/blog/post-1', '/blog/post-2'
|
|
370
|
+
*/
|
|
371
|
+
prefix: string;
|
|
372
|
+
/**
|
|
373
|
+
* Maximum number of pages to return.
|
|
374
|
+
*
|
|
375
|
+
* Useful for showing "latest N posts" on a homepage or sidebar.
|
|
376
|
+
*/
|
|
377
|
+
limit?: number;
|
|
378
|
+
/**
|
|
379
|
+
* Sort order for returned pages.
|
|
380
|
+
*
|
|
381
|
+
* - 'date-desc': Newest first (by modified/created date)
|
|
382
|
+
* - 'date-asc': Oldest first
|
|
383
|
+
* - 'title': Alphabetical by title
|
|
384
|
+
*
|
|
385
|
+
* @default 'date-desc'
|
|
386
|
+
*/
|
|
387
|
+
sort?: 'date-desc' | 'date-asc' | 'title';
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Configuration for a page creation template.
|
|
392
|
+
*
|
|
393
|
+
* Templates allow sites to define pre-built page structures
|
|
394
|
+
* that users can select when creating new pages in the CMS.
|
|
395
|
+
*
|
|
396
|
+
* @example Blog template configuration
|
|
397
|
+
* ```typescript
|
|
398
|
+
* conlocaCMS({
|
|
399
|
+
* templates: {
|
|
400
|
+
* blog: {
|
|
401
|
+
* label: 'Blog Post',
|
|
402
|
+
* component: 'BlogPostTemplate',
|
|
403
|
+
* pathPrefix: '/blog/',
|
|
404
|
+
* },
|
|
405
|
+
* },
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
interface TemplateConfig {
|
|
410
|
+
/**
|
|
411
|
+
* Display label shown in the template dropdown.
|
|
412
|
+
* @example 'Blog Post', 'Landing Page', 'Documentation'
|
|
413
|
+
*/
|
|
414
|
+
label: string;
|
|
415
|
+
/**
|
|
416
|
+
* Puck component name to pre-drop into the page.
|
|
417
|
+
* Must match a component registered in the site's puck.config.
|
|
418
|
+
* @example 'BlogPostTemplate', 'LandingPageTemplate'
|
|
419
|
+
*/
|
|
420
|
+
component: string;
|
|
421
|
+
/**
|
|
422
|
+
* Optional path prefix to auto-apply when this template is selected.
|
|
423
|
+
* If the user's path doesn't start with this prefix, it's added.
|
|
424
|
+
* @example '/blog/' will turn '/my-post' into '/blog/my-post'
|
|
425
|
+
*/
|
|
426
|
+
pathPrefix?: string;
|
|
427
|
+
/**
|
|
428
|
+
* Optional description shown in the dropdown.
|
|
429
|
+
*/
|
|
430
|
+
description?: string;
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/lib/hydration-script.d.ts
|
|
434
|
+
/**
|
|
435
|
+
* Async loader that returns a React component.
|
|
436
|
+
* The registry generator handles extraction from ComponentConfig at build time.
|
|
437
|
+
*/
|
|
438
|
+
type ComponentLoader = () => Promise<React.ComponentType<unknown>>;
|
|
439
|
+
/**
|
|
440
|
+
* Registry entry with loader and strategy.
|
|
441
|
+
* Generated by the scanner from withHydration metadata.
|
|
442
|
+
*/
|
|
443
|
+
interface ComponentRegistryEntry {
|
|
444
|
+
loader: ComponentLoader;
|
|
445
|
+
strategy: HydrationStrategy;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Registry mapping component names to their loaders and strategies.
|
|
449
|
+
* Generated by virtual:conloca-hydration-registry at build time.
|
|
450
|
+
*/
|
|
451
|
+
type ComponentRegistry = Record<string, ComponentRegistryEntry>;
|
|
452
|
+
/**
|
|
453
|
+
* Initialize hydration for all marked components on the page.
|
|
454
|
+
*
|
|
455
|
+
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
456
|
+
* according to their strategy from the registry.
|
|
457
|
+
*/
|
|
458
|
+
declare function initHydration(registry: ComponentRegistry): void;
|
|
459
|
+
//#endregion
|
|
460
|
+
export { TemplateConfig as a, RoutingConfigInput as i, initHydration as n, HydrationStrategy as r, ComponentRegistry as t };
|
|
461
|
+
//# sourceMappingURL=hydration-script-CKamSyIx.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-script-CKamSyIx.d.mts","names":[],"sources":["../src/types.ts","../src/lib/hydration-script.ts"],"sourcesContent":[],"mappings":";;;;;;AAuBA;AA2CA;AA6GA;AAqCA;AA6YA;AAgLA;;;;AC9wBoD;AAMhB;AAepC;AA0EA;;;;;;;KD3EY,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA2CK,aAAA;;;;;;;;;;;;;;;;;;;;;;;;WAyBN,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoFd,kBAAA,aAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqC1B,WAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAgFR;;;;;;;;;;;;;;;;;iBAkBQ;;;;;;;;;;;;;;;;;;;;;;;;UA2SA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAgLA,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA1vBjB;AA2CA;AA6GA,KCtKK,eAAA,GDsKO,GAAkB,GCtKD,ODsKC,CCtKO,KAAA,CAAM,aDsKa,CAAA,OAAA,CAAA,CAAA;AAqCxD;AA6YA;AAgLA;;UClwBU,sBAAA;UACA;EAPL,QAAA,EAQO,iBARQ;AAAgB;AAepC;AA0EA;;;KA1EY,iBAAA,GAAoB,eAAe;;;;;;;iBA0E/B,aAAA,WAAwB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { r as HydrationStrategy, t as ComponentRegistry } from "./hydration-script-CKamSyIx.mjs";
|
|
2
|
+
import { n as WithHydrationStrategy, r as withHydration, t as HydrationMeta } from "./withHydration-C6l6XnF2.mjs";
|
|
3
|
+
export { type ComponentRegistry, type HydrationMeta, type HydrationStrategy, type WithHydrationStrategy, withHydration };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { a as TemplateConfig, i as RoutingConfigInput, r as HydrationStrategy, t as ComponentRegistry } from "./hydration-script-CKamSyIx.mjs";
|
|
2
|
+
import { n as WithHydrationStrategy, r as withHydration, t as HydrationMeta } from "./withHydration-C6l6XnF2.mjs";
|
|
3
|
+
import { BlockMeta, PageMeta, blockMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
4
|
+
import { Config, Data } from "@measured/puck";
|
|
5
|
+
import { AstroIntegration } from "astro";
|
|
6
|
+
import { Loader } from "astro/loaders";
|
|
7
|
+
import { UIConfig } from "@conloca/cms-spa";
|
|
8
|
+
|
|
9
|
+
//#region src/loader.d.ts
|
|
10
|
+
interface ConlocaLoaderOptions {
|
|
11
|
+
collection: string;
|
|
12
|
+
contentRoot: string;
|
|
13
|
+
site?: string;
|
|
14
|
+
/** Collection kind. If not provided, defaults to 'block' for 'blocks' collection, 'page' otherwise. */
|
|
15
|
+
kind?: 'page' | 'block' | 'data';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Custom Astro content loader for Conloca CMS.
|
|
19
|
+
* Loads content from the Conloca content directory into Astro collections.
|
|
20
|
+
*/
|
|
21
|
+
declare function conlocaLoader(options: ConlocaLoaderOptions): Loader;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/plugin-spa.d.ts
|
|
24
|
+
interface ConlocaCMSOptions extends Omit<UIConfig, 'basename'> {
|
|
25
|
+
contentRoot: string;
|
|
26
|
+
canvasDir?: string;
|
|
27
|
+
route?: string;
|
|
28
|
+
puckConfigPath: string;
|
|
29
|
+
schemasPath?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Default layout for content pages.
|
|
32
|
+
* When provided without routing config, enables routing with catch-all pattern.
|
|
33
|
+
* For multi-route setups, use routing.routes.{name}.layout instead.
|
|
34
|
+
*
|
|
35
|
+
* @example './src/layouts/Layout.astro'
|
|
36
|
+
*/
|
|
37
|
+
layout?: string;
|
|
38
|
+
routing?: RoutingConfigInput;
|
|
39
|
+
templates?: Record<string, TemplateConfig>;
|
|
40
|
+
/**
|
|
41
|
+
* Paths to scan for hydratable components.
|
|
42
|
+
* Components using withHydration() in these directories are auto-discovered.
|
|
43
|
+
*
|
|
44
|
+
* @example ['src/components/puck']
|
|
45
|
+
*/
|
|
46
|
+
componentPaths?: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Path to the assets directory for image uploads.
|
|
49
|
+
* When provided, enables the Media Library and asset upload API routes.
|
|
50
|
+
*
|
|
51
|
+
* @example 'src/assets/uploads'
|
|
52
|
+
*/
|
|
53
|
+
assetsPath?: string;
|
|
54
|
+
}
|
|
55
|
+
declare function conlocaCMS(options: ConlocaCMSOptions): AstroIntegration;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/lib/hydration-utils.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* Extended ComponentConfig with hydration support.
|
|
60
|
+
* @deprecated Use withHydration() wrapper instead of hydration property.
|
|
61
|
+
*/
|
|
62
|
+
interface HydratableComponentConfig {
|
|
63
|
+
/** @deprecated Use withHydration() wrapper on render function instead */
|
|
64
|
+
hydration?: HydrationStrategy;
|
|
65
|
+
render?: (props: unknown) => unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Component instance requiring hydration.
|
|
69
|
+
* Contains the component name, props, and hydration strategy.
|
|
70
|
+
*/
|
|
71
|
+
interface HydratableComponent {
|
|
72
|
+
/** Component type name from Puck config */
|
|
73
|
+
type: string;
|
|
74
|
+
/** Props to pass to the component */
|
|
75
|
+
props: Record<string, unknown>;
|
|
76
|
+
/** Hydration strategy from ComponentConfig */
|
|
77
|
+
strategy: Exclude<HydrationStrategy, 'none'>;
|
|
78
|
+
/** Unique ID from Puck data (for keying) */
|
|
79
|
+
id: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if a component type has hydration enabled.
|
|
83
|
+
*
|
|
84
|
+
* First checks for __hydration metadata on the render function (new withHydration API),
|
|
85
|
+
* then falls back to hydration property on ComponentConfig (deprecated).
|
|
86
|
+
*
|
|
87
|
+
* @param componentType - The component type name from Puck data
|
|
88
|
+
* @param config - The Puck config with component definitions
|
|
89
|
+
* @returns The hydration strategy ('none', 'load', 'visible', 'idle')
|
|
90
|
+
*/
|
|
91
|
+
declare function isHydratable(componentType: string, config: Config): HydrationStrategy;
|
|
92
|
+
/**
|
|
93
|
+
* Find all components in a Puck data tree that require hydration.
|
|
94
|
+
* Walks the content array and zones recursively.
|
|
95
|
+
*
|
|
96
|
+
* @param data - Puck data object containing content tree
|
|
97
|
+
* @param config - Puck config with component definitions
|
|
98
|
+
* @returns Array of components that need hydration
|
|
99
|
+
*/
|
|
100
|
+
declare function findHydratableComponents(data: Data, config: Config): HydratableComponent[];
|
|
101
|
+
/**
|
|
102
|
+
* Check if Puck data contains any hydratable components.
|
|
103
|
+
* Quick check before more expensive operations.
|
|
104
|
+
*/
|
|
105
|
+
declare function hasHydratableComponents(data: Data, config: Config): boolean;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/lib/serialize-props.d.ts
|
|
108
|
+
/**
|
|
109
|
+
* Safely serialize props for embedding in HTML data attributes.
|
|
110
|
+
* Escapes < to prevent XSS when JSON is parsed in browser.
|
|
111
|
+
*/
|
|
112
|
+
declare function serializeProps(props: Record<string, unknown>): string;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/lib/hydration-scanner.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* Result of scanning a component file for withHydration usage.
|
|
117
|
+
*/
|
|
118
|
+
interface HydrationDiscovery {
|
|
119
|
+
/** Component name derived from filename (PascalCase) */
|
|
120
|
+
componentName: string;
|
|
121
|
+
/** Absolute path to the component file */
|
|
122
|
+
filePath: string;
|
|
123
|
+
/** Hydration strategy extracted from withHydration call */
|
|
124
|
+
strategy: 'load' | 'visible' | 'idle';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Scans component directories for files using withHydration wrapper.
|
|
128
|
+
*
|
|
129
|
+
* This function performs static analysis to discover components marked
|
|
130
|
+
* for hydration, without executing any component code.
|
|
131
|
+
*
|
|
132
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
133
|
+
* @param projectRoot - Absolute path to the project root
|
|
134
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const discoveries = await scanForHydratableComponents(
|
|
139
|
+
* ['src/components/puck'],
|
|
140
|
+
* '/path/to/project'
|
|
141
|
+
* )
|
|
142
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare function scanForHydratableComponents(componentPaths: string[], projectRoot: string): Promise<HydrationDiscovery[]>;
|
|
146
|
+
//#endregion
|
|
147
|
+
export { type BlockMeta, type ComponentRegistry, type ConlocaCMSOptions, type ConlocaLoaderOptions, type HydratableComponent, type HydratableComponentConfig, type HydrationDiscovery, type HydrationMeta, type HydrationStrategy, type PageMeta, type TemplateConfig, type WithHydrationStrategy, blockMetaSchema, conlocaCMS, conlocaLoader, findHydratableComponents, hasHydratableComponents, isHydratable, pageMetaSchema, scanForHydratableComponents, serializeProps, withHydration };
|
|
148
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/loader.ts","../src/plugin-spa.ts","../src/lib/hydration-utils.ts","../src/lib/serialize-props.ts","../src/lib/hydration-scanner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UAGiB,oBAAA;;;;;;;;AAAjB;AAYA;;iBAAgB,aAAA,UAAuB,uBAAuB;;;UCuC7C,iBAAA,SAA0B,KAAK;;;;;;EDnD/B;AAYjB;;;;ACuCA;;EAgBY,MAAA,CAAA,EAAA,MAAA;EACiB,OAAA,CAAA,EADjB,kBACiB;EAAf,SAAA,CAAA,EAAA,MAAA,CAAA,MAAA,EAAe,cAAf,CAAA;EAjB6B;;AAwH3C;;;;ECtKiB,cAAA,CAAA,EAAA,MAAA,EAAA;EAUA;;;;;AAqBjB;EAyBgB,UAAA,CAAA,EAAA,MAAA;;AAEN,iBD4GM,UAAA,CC5GN,OAAA,ED4G0B,iBC5G1B,CAAA,ED4G8C,gBC5G9C;;;;;;;UA1DO,yBAAA;;cAEH;EFPG,MAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAoB,EAAA,GAAA,OAAA;AAYrC;;;;ACuCA;AAAgD,UCpC/B,mBAAA,CDoC+B;EAgBpC;EACiB,IAAA,EAAA,MAAA;EAAf;EAjB6B,KAAA,EChClC,MDgCkC,CAAA,MAAA,EAAA,OAAA,CAAA;EAAI;EAwH/B,QAAA,ECtJJ,ODsJc,CCtJN,iBDsJgB,EAAA,MAAA,CAAoB;;;;ACtKxD;AAUA;;;;;AAqBA;AAyBA;;;AAGG,iBA5Ba,YAAA,CA4Bb,aAAA,EAAA,MAAA,EAAA,MAAA,EA1BO,MA0BP,CAAA,EAzBA,iBAyBA;;AA0CH;;;;ACzGA;;;iBD4DgB,wBAAA,OACR,cACE,SACP;AE5DH;AA0FA;;;iBFYgB,uBAAA,OAA8B,cAAc;;;;;;;iBCzG5C,cAAA,QAAsB;;;;;;UCGrB,kBAAA;;;;;;EJJA,QAAA,EAAA,MAAA,GAAA,SAAoB,GAAA,MAAA;AAYrC;;AEPA;AAUA;;;;;AAqBA;AAyBA;;;;;AA6CA;;;;ACzGA;;iBC6FsB,2BAAA,iDAGnB,QAAQ"}
|