@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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
/**
|
|
5
|
+
* Read every `*.cms.json` file under `folder` (recursive) and return
|
|
6
|
+
* the parsed overrides keyed by basename (`Card.cms.json` → `Card`).
|
|
7
|
+
*
|
|
8
|
+
* Failures are skipped with a warning — a broken JSON file shouldn't
|
|
9
|
+
* take down the rest of the registry build. The folder being empty
|
|
10
|
+
* (or not existing) returns an empty map silently; that's the
|
|
11
|
+
* common zero-config case where the host hasn't added any
|
|
12
|
+
* overrides yet.
|
|
13
|
+
*/
|
|
14
|
+
export async function loadCmsOverrides(folder, projectRoot) {
|
|
15
|
+
const out = new Map();
|
|
16
|
+
if (!folder)
|
|
17
|
+
return out;
|
|
18
|
+
const pattern = `${folder.replace(/\/+$/, '')}/**/*.cms.json`;
|
|
19
|
+
const files = await fg(pattern, { cwd: projectRoot, absolute: true, dot: false });
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
try {
|
|
22
|
+
const content = await readFile(file, 'utf8');
|
|
23
|
+
const parsed = JSON.parse(content);
|
|
24
|
+
const base = basename(file);
|
|
25
|
+
const name = base.slice(0, -'.cms.json'.length);
|
|
26
|
+
out.set(name, parsed);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.warn(`[conloca:discovery] failed to load override ${file}:`, err instanceof Error ? err.message : err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../../src/hydration.ts"],"names":[],"mappings":"AAIA,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvG,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { defineMdxComponents, type MdxComponentDescriptor, type MdxComponentInsertHint, type MdxComponentProp, type MdxComponents, type MdxJsxComponentDescriptor, type MdxSnippetDescriptor, readStringAttribute, writeStringAttribute, } from '@conloca/cms-spa/mdx-components';
|
|
2
|
+
export { type CoreFieldsMode, definePageSchema, type FieldHint, type FieldHintCommon, type FieldHints, type FieldHintVariant, type PageSchemaDescriptor, type PageSchemaEntry, type PageSchemaGroup, type PageSchemas, } from '@conloca/cms-spa/page-schemas';
|
|
3
|
+
export { type BlockMeta, blockMetaSchema, type PageMeta, pageMetaSchema, } from '@conloca/content-api/schemas';
|
|
4
|
+
export type { ComponentRegistry } from './lib/hydration-script.js';
|
|
5
|
+
export { findHydratableComponents, type HydratableComponent, type HydratableComponentConfig, hasHydratableComponents, isHydratable, } from './lib/hydration-utils.js';
|
|
6
|
+
export { extractSlugFromPathname, isPublished, pathnameFromSlug, toDate } from './lib/route-utils.js';
|
|
7
|
+
export { serializeProps } from './lib/serialize-props.js';
|
|
8
|
+
export { type HydrationMeta, type WithHydrationStrategy, withHydration } from './lib/withHydration.js';
|
|
9
|
+
export { type ConlocaLocales, localesFromAstroI18n, localesFromStarlight } from './locales-helpers.js';
|
|
10
|
+
export type { DataCollectionEntry, HydrationStrategy, LayoutProps, PageData, PageReference, ResolvedRoutingConfig, TemplateConfig, } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,EACnB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EACL,KAAK,cAAc,EACnB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,KAAK,SAAS,EACd,eAAe,EACf,KAAK,QAAQ,EACb,cAAc,GACf,MAAM,8BAA8B,CAAC;AAMtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,wBAAwB,EACxB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,uBAAuB,EACvB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtG,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvG,OAAO,EAAE,KAAK,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIvG,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Astro integration for Conloca CMS
|
|
2
|
+
// MDX component registry plugin API — hosts use these to register JSX
|
|
3
|
+
// components (e.g. Starlight's Steps/Tabs/Card) with typed insert editors
|
|
4
|
+
// and opt-in auto-import injection. Runtime registry also wires through
|
|
5
|
+
// the schemasPath option; hosts export `mdxComponents` from the same file.
|
|
6
|
+
//
|
|
7
|
+
// `readStringAttribute` / `writeStringAttribute` are mdast-level helpers
|
|
8
|
+
// for hosts writing their own typed `Editor` components — controlled
|
|
9
|
+
// inputs against a string prop. Re-exported here so a host's editor file
|
|
10
|
+
// can pull everything it needs from one place.
|
|
11
|
+
export { defineMdxComponents, readStringAttribute, writeStringAttribute, } from '@conloca/cms-spa/mdx-components';
|
|
12
|
+
// Page-schema plugin API — hosts use these to declare frontmatter form UI
|
|
13
|
+
// for the CMS page-settings dialog. Runtime registry lives in @conloca/cms-spa
|
|
14
|
+
// and is wired by the schemasPath option (see ConlocaCMSOptions).
|
|
15
|
+
export { definePageSchema, } from '@conloca/cms-spa/page-schemas';
|
|
16
|
+
// Re-export Zod schemas and types for convenience
|
|
17
|
+
export { blockMetaSchema, pageMetaSchema, } from '@conloca/content-api/schemas';
|
|
18
|
+
export { findHydratableComponents, hasHydratableComponents, isHydratable, } from './lib/hydration-utils.js';
|
|
19
|
+
export { extractSlugFromPathname, isPublished, pathnameFromSlug, toDate } from './lib/route-utils.js';
|
|
20
|
+
export { serializeProps } from './lib/serialize-props.js';
|
|
21
|
+
// New hydration API: withHydration wrapper and build-time scanner
|
|
22
|
+
export { withHydration } from './lib/withHydration.js';
|
|
23
|
+
// Locale plumbing helpers — translate framework-native i18n configs
|
|
24
|
+
// into Conloca's locale shape. See locales-helpers.ts for the contract.
|
|
25
|
+
export { localesFromAstroI18n, localesFromStarlight } from './locales-helpers.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of scanning a component file for withHydration usage.
|
|
3
|
+
*/
|
|
4
|
+
export interface HydrationDiscovery {
|
|
5
|
+
/** Component name derived from filename (PascalCase) */
|
|
6
|
+
componentName: string;
|
|
7
|
+
/** Absolute path to the component file */
|
|
8
|
+
filePath: string;
|
|
9
|
+
/** Hydration strategy extracted from withHydration call */
|
|
10
|
+
strategy: 'load' | 'visible' | 'idle';
|
|
11
|
+
}
|
|
12
|
+
export declare const HYDRATION_IMPORT_PATTERN: RegExp;
|
|
13
|
+
export declare const HYDRATION_PATTERN: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* Derives component scan paths from puckConfigPath.
|
|
16
|
+
*
|
|
17
|
+
* Convention: puckConfigPath directory + '/components/puck'
|
|
18
|
+
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
19
|
+
*
|
|
20
|
+
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
21
|
+
*
|
|
22
|
+
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
23
|
+
* @param explicitPaths - Optional additional paths to scan
|
|
24
|
+
* @returns Array of paths to scan for hydratable components
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveComponentPaths(puckConfigPath: string, explicitPaths?: string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Scans component directories for files using withHydration wrapper.
|
|
29
|
+
*
|
|
30
|
+
* This function performs static analysis to discover components marked
|
|
31
|
+
* for hydration, without executing any component code.
|
|
32
|
+
*
|
|
33
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
34
|
+
* @param projectRoot - Absolute path to the project root
|
|
35
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const discoveries = await scanForHydratableComponents(
|
|
40
|
+
* ['src/components/puck'],
|
|
41
|
+
* '/path/to/project'
|
|
42
|
+
* )
|
|
43
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function scanForHydratableComponents(componentPaths: string[], projectRoot: string): Promise<HydrationDiscovery[]>;
|
|
47
|
+
//# sourceMappingURL=hydration-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-scanner.d.ts","sourceRoot":"","sources":["../../../src/lib/hydration-scanner.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;CACvC;AAID,eAAO,MAAM,wBAAwB,QACwD,CAAC;AAI9F,eAAO,MAAM,iBAAiB,QAAuD,CAAC;AAKtF;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQ/F;AA4BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,2BAA2B,CAC/C,cAAc,EAAE,MAAM,EAAE,EACxB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA6E/B"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
// Regex to check if file imports withHydration from @conloca/astro-cms or @conloca/astro-cms/hydration
|
|
5
|
+
// This is faster than es-module-lexer for JSX files and avoids parse errors
|
|
6
|
+
export const HYDRATION_IMPORT_PATTERN = /import\s+\{[^}]*withHydration[^}]*\}\s+from\s+['"]@conloca\/astro-cms(?:\/hydration)?['"]/;
|
|
7
|
+
// Regex to find withHydration calls and extract strategy
|
|
8
|
+
// Matches: withHydration(ComponentName, 'strategy') or withHydration(ComponentName, "strategy")
|
|
9
|
+
export const HYDRATION_PATTERN = /withHydration\s*\(\s*\w+\s*,\s*['"](\w+)['"]\s*\)/g;
|
|
10
|
+
// Valid hydration strategies
|
|
11
|
+
const VALID_STRATEGIES = new Set(['load', 'visible', 'idle']);
|
|
12
|
+
/**
|
|
13
|
+
* Derives component scan paths from puckConfigPath.
|
|
14
|
+
*
|
|
15
|
+
* Convention: puckConfigPath directory + '/components/puck'
|
|
16
|
+
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
17
|
+
*
|
|
18
|
+
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
19
|
+
*
|
|
20
|
+
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
21
|
+
* @param explicitPaths - Optional additional paths to scan
|
|
22
|
+
* @returns Array of paths to scan for hydratable components
|
|
23
|
+
*/
|
|
24
|
+
export function deriveComponentPaths(puckConfigPath, explicitPaths) {
|
|
25
|
+
const puckDir = dirname(puckConfigPath);
|
|
26
|
+
const defaultScanPath = join(puckDir, 'components', 'puck');
|
|
27
|
+
if (explicitPaths && explicitPaths.length > 0) {
|
|
28
|
+
return [defaultScanPath, ...explicitPaths];
|
|
29
|
+
}
|
|
30
|
+
return [defaultScanPath];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derives a PascalCase component name from a file path.
|
|
34
|
+
*
|
|
35
|
+
* @param filePath - Absolute path to the component file
|
|
36
|
+
* @returns Component name in PascalCase
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* deriveComponentName('/src/components/puck/TestimonialGrid.tsx')
|
|
40
|
+
* // => 'TestimonialGrid'
|
|
41
|
+
*
|
|
42
|
+
* deriveComponentName('/src/components/puck/blog-post-grid.tsx')
|
|
43
|
+
* // => 'BlogPostGrid'
|
|
44
|
+
*/
|
|
45
|
+
function deriveComponentName(filePath) {
|
|
46
|
+
const filename = basename(filePath, extname(filePath));
|
|
47
|
+
// Convert kebab-case to PascalCase if needed
|
|
48
|
+
if (filename.includes('-')) {
|
|
49
|
+
return filename
|
|
50
|
+
.split('-')
|
|
51
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
52
|
+
.join('');
|
|
53
|
+
}
|
|
54
|
+
// Ensure first letter is uppercase
|
|
55
|
+
return filename.charAt(0).toUpperCase() + filename.slice(1);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scans component directories for files using withHydration wrapper.
|
|
59
|
+
*
|
|
60
|
+
* This function performs static analysis to discover components marked
|
|
61
|
+
* for hydration, without executing any component code.
|
|
62
|
+
*
|
|
63
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
64
|
+
* @param projectRoot - Absolute path to the project root
|
|
65
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const discoveries = await scanForHydratableComponents(
|
|
70
|
+
* ['src/components/puck'],
|
|
71
|
+
* '/path/to/project'
|
|
72
|
+
* )
|
|
73
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export async function scanForHydratableComponents(componentPaths, projectRoot) {
|
|
77
|
+
const discoveries = [];
|
|
78
|
+
const seenNames = new Map(); // componentName -> first filePath
|
|
79
|
+
for (const scanPath of componentPaths) {
|
|
80
|
+
const absolutePath = resolve(projectRoot, scanPath);
|
|
81
|
+
// Find all .tsx files in the directory and subdirectories
|
|
82
|
+
const files = await fg('**/*.tsx', {
|
|
83
|
+
cwd: absolutePath,
|
|
84
|
+
absolute: true,
|
|
85
|
+
onlyFiles: true,
|
|
86
|
+
});
|
|
87
|
+
for (const filePath of files) {
|
|
88
|
+
try {
|
|
89
|
+
const content = await readFile(filePath, 'utf-8');
|
|
90
|
+
// Fast path: check if file imports withHydration from @conloca/astro-cms
|
|
91
|
+
// Using simple regex instead of es-module-lexer to avoid JSX parse errors
|
|
92
|
+
if (!HYDRATION_IMPORT_PATTERN.test(content)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Find withHydration calls with regex
|
|
96
|
+
const matches = [...content.matchAll(HYDRATION_PATTERN)];
|
|
97
|
+
if (matches.length === 0) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (matches.length > 1) {
|
|
101
|
+
console.warn(`[Conloca Hydration] Multiple withHydration calls in ${filePath}. ` +
|
|
102
|
+
'Consider splitting into separate component files. Using first call.');
|
|
103
|
+
}
|
|
104
|
+
const match = matches[0];
|
|
105
|
+
const rawStrategy = match[1];
|
|
106
|
+
// Validate strategy
|
|
107
|
+
if (!VALID_STRATEGIES.has(rawStrategy)) {
|
|
108
|
+
console.warn(`[Conloca Hydration] Invalid strategy '${rawStrategy}' in ${filePath}. ` +
|
|
109
|
+
`Valid options: ${[...VALID_STRATEGIES].join(', ')}. Skipping component.`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const strategy = rawStrategy;
|
|
113
|
+
const componentName = deriveComponentName(filePath);
|
|
114
|
+
// Check for naming conflicts
|
|
115
|
+
const existingPath = seenNames.get(componentName);
|
|
116
|
+
if (existingPath) {
|
|
117
|
+
console.warn(`[Conloca Hydration] Duplicate component name '${componentName}'. ` +
|
|
118
|
+
`Found in: ${existingPath} and ${filePath}. Using first occurrence.`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
seenNames.set(componentName, filePath);
|
|
122
|
+
discoveries.push({
|
|
123
|
+
componentName,
|
|
124
|
+
filePath,
|
|
125
|
+
strategy,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
// Log error but continue scanning other files
|
|
130
|
+
console.warn(`[Conloca Hydration] Error reading ${filePath}:`, err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return discoveries;
|
|
135
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HydrationStrategy } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Async loader that returns a React component.
|
|
4
|
+
* The registry generator handles extraction from ComponentConfig at build time.
|
|
5
|
+
*/
|
|
6
|
+
type ComponentLoader = () => Promise<React.ComponentType<unknown>>;
|
|
7
|
+
/**
|
|
8
|
+
* Registry entry with loader and strategy.
|
|
9
|
+
* Generated by the scanner from withHydration metadata.
|
|
10
|
+
*/
|
|
11
|
+
interface ComponentRegistryEntry {
|
|
12
|
+
loader: ComponentLoader;
|
|
13
|
+
strategy: HydrationStrategy;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registry mapping component names to their loaders and strategies.
|
|
17
|
+
* Generated by virtual:conloca-hydration-registry at build time.
|
|
18
|
+
*/
|
|
19
|
+
export type ComponentRegistry = Record<string, ComponentRegistryEntry>;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize hydration for all marked components on the page.
|
|
22
|
+
*
|
|
23
|
+
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
24
|
+
* according to their strategy from the registry.
|
|
25
|
+
*/
|
|
26
|
+
export declare function initHydration(registry: ComponentRegistry): void;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=hydration-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-script.d.ts","sourceRoot":"","sources":["../../../src/lib/hydration-script.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,UAAU,sBAAsB;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAiEvE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CA8B/D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
3
|
+
/**
|
|
4
|
+
* Hydrate a single element with its corresponding React component.
|
|
5
|
+
*/
|
|
6
|
+
async function hydrateElement(element, entry) {
|
|
7
|
+
const componentName = element.dataset.hydrate;
|
|
8
|
+
const propsJson = element.dataset.props || '{}';
|
|
9
|
+
if (!componentName) {
|
|
10
|
+
console.warn('[Conloca Hydration] Element missing data-hydrate attribute');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const props = JSON.parse(propsJson);
|
|
15
|
+
const Component = await entry.loader();
|
|
16
|
+
hydrateRoot(element, createElement(Component, props));
|
|
17
|
+
// Clean up data attributes after successful hydration
|
|
18
|
+
delete element.dataset.hydrate;
|
|
19
|
+
delete element.dataset.hydrateStrategy;
|
|
20
|
+
delete element.dataset.props;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error(`[Conloca Hydration] Failed to hydrate ${componentName}:`, error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Hydrate immediately on page load.
|
|
28
|
+
*/
|
|
29
|
+
function hydrateOnLoad(element, entry) {
|
|
30
|
+
hydrateElement(element, entry);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hydrate when element becomes visible in viewport.
|
|
34
|
+
*/
|
|
35
|
+
function hydrateOnVisible(element, entry) {
|
|
36
|
+
const observer = new IntersectionObserver((entries, obs) => {
|
|
37
|
+
for (const ioEntry of entries) {
|
|
38
|
+
if (ioEntry.isIntersecting) {
|
|
39
|
+
obs.unobserve(ioEntry.target);
|
|
40
|
+
hydrateElement(ioEntry.target, entry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, { rootMargin: '50px' });
|
|
44
|
+
observer.observe(element);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hydrate when browser is idle.
|
|
48
|
+
* Uses requestIdleCallback with setTimeout fallback for Safari.
|
|
49
|
+
*/
|
|
50
|
+
function hydrateOnIdle(element, entry) {
|
|
51
|
+
const scheduleIdle = window.requestIdleCallback ??
|
|
52
|
+
((cb) => window.setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 50 }), 1));
|
|
53
|
+
scheduleIdle(() => hydrateElement(element, entry), { timeout: 2000 });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Initialize hydration for all marked components on the page.
|
|
57
|
+
*
|
|
58
|
+
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
59
|
+
* according to their strategy from the registry.
|
|
60
|
+
*/
|
|
61
|
+
export function initHydration(registry) {
|
|
62
|
+
const elements = document.querySelectorAll('[data-hydrate]');
|
|
63
|
+
for (const element of elements) {
|
|
64
|
+
const componentName = element.dataset.hydrate;
|
|
65
|
+
if (!componentName)
|
|
66
|
+
continue;
|
|
67
|
+
const entry = registry[componentName];
|
|
68
|
+
if (!entry) {
|
|
69
|
+
console.warn(`[Conloca Hydration] Unknown component: ${componentName}`);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Use strategy from registry (set at build time via withHydration)
|
|
73
|
+
const strategy = entry.strategy;
|
|
74
|
+
switch (strategy) {
|
|
75
|
+
case 'load':
|
|
76
|
+
hydrateOnLoad(element, entry);
|
|
77
|
+
break;
|
|
78
|
+
case 'visible':
|
|
79
|
+
hydrateOnVisible(element, entry);
|
|
80
|
+
break;
|
|
81
|
+
case 'idle':
|
|
82
|
+
hydrateOnIdle(element, entry);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
hydrateOnLoad(element, entry);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Config, Data } from '@puckeditor/core';
|
|
2
|
+
import type { HydrationStrategy } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extended ComponentConfig with hydration support.
|
|
5
|
+
* @deprecated Use withHydration() wrapper instead of hydration property.
|
|
6
|
+
*/
|
|
7
|
+
export interface HydratableComponentConfig {
|
|
8
|
+
/** @deprecated Use withHydration() wrapper on render function instead */
|
|
9
|
+
hydration?: HydrationStrategy;
|
|
10
|
+
render?: (props: unknown) => unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Component instance requiring hydration.
|
|
14
|
+
* Contains the component name, props, and hydration strategy.
|
|
15
|
+
*/
|
|
16
|
+
export interface HydratableComponent {
|
|
17
|
+
/** Component type name from Puck config */
|
|
18
|
+
type: string;
|
|
19
|
+
/** Props to pass to the component */
|
|
20
|
+
props: Record<string, unknown>;
|
|
21
|
+
/** Hydration strategy from ComponentConfig */
|
|
22
|
+
strategy: Exclude<HydrationStrategy, 'none'>;
|
|
23
|
+
/** Unique ID from Puck data (for keying) */
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if a component type has hydration enabled.
|
|
28
|
+
*
|
|
29
|
+
* First checks for __hydration metadata on the render function (new withHydration API),
|
|
30
|
+
* then falls back to hydration property on ComponentConfig (deprecated).
|
|
31
|
+
*
|
|
32
|
+
* @param componentType - The component type name from Puck data
|
|
33
|
+
* @param config - The Puck config with component definitions
|
|
34
|
+
* @returns The hydration strategy ('none', 'load', 'visible', 'idle')
|
|
35
|
+
*/
|
|
36
|
+
export declare function isHydratable(componentType: string, config: Config): HydrationStrategy;
|
|
37
|
+
/**
|
|
38
|
+
* Find all components in a Puck data tree that require hydration.
|
|
39
|
+
* Walks the content array and zones recursively.
|
|
40
|
+
*
|
|
41
|
+
* @param data - Puck data object containing content tree
|
|
42
|
+
* @param config - Puck config with component definitions
|
|
43
|
+
* @returns Array of components that need hydration
|
|
44
|
+
*/
|
|
45
|
+
export declare function findHydratableComponents(data: Data, config: Config): HydratableComponent[];
|
|
46
|
+
/**
|
|
47
|
+
* Check if Puck data contains any hydratable components.
|
|
48
|
+
* Quick check before more expensive operations.
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasHydratableComponents(data: Data, config: Config): boolean;
|
|
51
|
+
//# sourceMappingURL=hydration-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydration-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/hydration-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC7C,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAYrF;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAoC1F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgB3E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a component type has hydration enabled.
|
|
3
|
+
*
|
|
4
|
+
* First checks for __hydration metadata on the render function (new withHydration API),
|
|
5
|
+
* then falls back to hydration property on ComponentConfig (deprecated).
|
|
6
|
+
*
|
|
7
|
+
* @param componentType - The component type name from Puck data
|
|
8
|
+
* @param config - The Puck config with component definitions
|
|
9
|
+
* @returns The hydration strategy ('none', 'load', 'visible', 'idle')
|
|
10
|
+
*/
|
|
11
|
+
export function isHydratable(componentType, config) {
|
|
12
|
+
const componentConfig = config.components[componentType];
|
|
13
|
+
if (!componentConfig?.render)
|
|
14
|
+
return 'none';
|
|
15
|
+
// New API: Check for __hydration metadata attached by withHydration()
|
|
16
|
+
const render = componentConfig.render;
|
|
17
|
+
if (render.__hydration?.__isHydratable) {
|
|
18
|
+
return render.__hydration.strategy;
|
|
19
|
+
}
|
|
20
|
+
// Deprecated: Check hydration property on ComponentConfig
|
|
21
|
+
return componentConfig?.hydration ?? 'none';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Find all components in a Puck data tree that require hydration.
|
|
25
|
+
* Walks the content array and zones recursively.
|
|
26
|
+
*
|
|
27
|
+
* @param data - Puck data object containing content tree
|
|
28
|
+
* @param config - Puck config with component definitions
|
|
29
|
+
* @returns Array of components that need hydration
|
|
30
|
+
*/
|
|
31
|
+
export function findHydratableComponents(data, config) {
|
|
32
|
+
const hydratable = [];
|
|
33
|
+
// Walk content array
|
|
34
|
+
if (data.content) {
|
|
35
|
+
for (const item of data.content) {
|
|
36
|
+
const strategy = isHydratable(item.type, config);
|
|
37
|
+
if (strategy !== 'none') {
|
|
38
|
+
hydratable.push({
|
|
39
|
+
type: item.type,
|
|
40
|
+
props: item.props ?? {},
|
|
41
|
+
strategy,
|
|
42
|
+
id: item.props?.id ?? item.type,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Walk zones (named drop zones with nested content)
|
|
48
|
+
if (data.zones) {
|
|
49
|
+
for (const [zoneName, zoneContent] of Object.entries(data.zones)) {
|
|
50
|
+
for (const item of zoneContent) {
|
|
51
|
+
const strategy = isHydratable(item.type, config);
|
|
52
|
+
if (strategy !== 'none') {
|
|
53
|
+
hydratable.push({
|
|
54
|
+
type: item.type,
|
|
55
|
+
props: item.props ?? {},
|
|
56
|
+
strategy,
|
|
57
|
+
id: item.props?.id ?? `${zoneName}-${item.type}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return hydratable;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if Puck data contains any hydratable components.
|
|
67
|
+
* Quick check before more expensive operations.
|
|
68
|
+
*/
|
|
69
|
+
export function hasHydratableComponents(data, config) {
|
|
70
|
+
// Check content
|
|
71
|
+
if (data.content?.some((item) => isHydratable(item.type, config) !== 'none')) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
// Check zones
|
|
75
|
+
if (data.zones) {
|
|
76
|
+
for (const zoneContent of Object.values(data.zones)) {
|
|
77
|
+
if (zoneContent.some((item) => isHydratable(item.type, config) !== 'none')) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { PageData, PageReference } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a PageAPI instance.
|
|
4
|
+
*/
|
|
5
|
+
export interface PageApiOptions {
|
|
6
|
+
contentRoot: string;
|
|
7
|
+
canvasDir: string;
|
|
8
|
+
/** Site name to use for pages (defaults to 'default') */
|
|
9
|
+
siteName?: string;
|
|
10
|
+
/** Default locale for content (defaults to 'en') */
|
|
11
|
+
locale?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Page loading API interface.
|
|
15
|
+
*
|
|
16
|
+
* Provides a clean interface for page-handler.astro to:
|
|
17
|
+
* - Get all pages for getStaticPaths()
|
|
18
|
+
* - Load individual page data for rendering
|
|
19
|
+
* - Check if pages exist for 404 handling
|
|
20
|
+
*/
|
|
21
|
+
export interface PageAPI {
|
|
22
|
+
/**
|
|
23
|
+
* Get all pages for static path generation.
|
|
24
|
+
*
|
|
25
|
+
* @param collection - Optional collection filter (defaults to all)
|
|
26
|
+
* @returns Array of page references with minimal data
|
|
27
|
+
*/
|
|
28
|
+
getAllPages(collection?: string): Promise<PageReference[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Load full page data for rendering.
|
|
31
|
+
*
|
|
32
|
+
* @param pathname - URL pathname (e.g., '/about', '/blog/post-1')
|
|
33
|
+
* @param collection - Optional collection filter
|
|
34
|
+
* @returns Full page data including Puck content
|
|
35
|
+
* @throws Error with code 'PAGE_NOT_FOUND' if page doesn't exist
|
|
36
|
+
*/
|
|
37
|
+
getPage(pathname: string, collection?: string): Promise<PageData>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a page exists without loading full data.
|
|
40
|
+
*
|
|
41
|
+
* Useful for 404 detection without the overhead of full page load.
|
|
42
|
+
*
|
|
43
|
+
* @param pathname - URL pathname
|
|
44
|
+
* @param collection - Optional collection filter
|
|
45
|
+
* @returns True if page exists, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
pageExists(pathname: string, collection?: string): Promise<boolean>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Error class for page not found scenarios.
|
|
51
|
+
*/
|
|
52
|
+
export declare class PageNotFoundError extends Error {
|
|
53
|
+
readonly code: 'PAGE_NOT_FOUND';
|
|
54
|
+
constructor(pathname: string);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a PageAPI instance for loading page data.
|
|
58
|
+
*
|
|
59
|
+
* Wraps ContentAPI with a cleaner interface focused on
|
|
60
|
+
* page rendering needs.
|
|
61
|
+
*
|
|
62
|
+
* @param options - Configuration for ContentAPI initialization
|
|
63
|
+
* @returns PageAPI instance
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const api = await createPageAPI({
|
|
68
|
+
* contentRoot: '../content',
|
|
69
|
+
* canvasDir: './canvas',
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const pages = await api.getAllPages('pages');
|
|
73
|
+
* const page = await api.getPage('/about');
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function createPageAPI(options: PageApiOptions): Promise<PageAPI>;
|
|
77
|
+
//# sourceMappingURL=page-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-api.d.ts","sourceRoot":"","sources":["../../../src/lib/page-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;OAKG;IACH,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE3D;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAElE;;;;;;;;OAQG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAG,gBAAgB,CAAU;IAE1C,YAAY,QAAQ,EAAE,MAAM,EAG3B;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyG7E"}
|