@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.
Files changed (160) hide show
  1. package/README.md +65 -5
  2. package/dist/collections-Bd7EME4b.mjs +129 -0
  3. package/dist/collections-Bd7EME4b.mjs.map +1 -0
  4. package/dist/collections.d.mts +0 -1
  5. package/dist/collections.d.mts.map +1 -1
  6. package/dist/collections.mjs +1 -64
  7. package/dist/components.d.mts +2 -7
  8. package/dist/components.d.mts.map +1 -1
  9. package/dist/components.mjs +3 -6
  10. package/dist/components.mjs.map +1 -1
  11. package/dist/hydration.d.mts +2 -2
  12. package/dist/hydration.mjs +2 -3
  13. package/dist/index.d.mts +6 -37
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +7 -6
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/internal/cms-handler.d.mts +0 -1
  18. package/dist/internal/cms-handler.d.mts.map +1 -1
  19. package/dist/internal/cms-handler.mjs +55 -8
  20. package/dist/internal/cms-handler.mjs.map +1 -1
  21. package/dist/lib/hydration-script.d.mts +1 -2
  22. package/dist/lib/hydration-script.d.mts.map +1 -1
  23. package/dist/lib/hydration-script.mjs +1 -2
  24. package/dist/lib/hydration-script.mjs.map +1 -1
  25. package/dist/locales-helpers-BvYYqnJ5.d.mts +64 -0
  26. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +1 -0
  27. package/dist/locales-helpers-qiwh7nxS.mjs +54 -0
  28. package/dist/locales-helpers-qiwh7nxS.mjs.map +1 -0
  29. package/dist/node/content.d.mts +0 -1
  30. package/dist/node/content.d.mts.map +1 -1
  31. package/dist/node/content.d.ts +3 -0
  32. package/dist/node/content.d.ts.map +1 -0
  33. package/dist/node/content.js +2 -0
  34. package/dist/node/content.mjs +2 -4
  35. package/dist/node/index.d.mts +151 -3
  36. package/dist/node/index.d.mts.map +1 -1
  37. package/dist/node/index.d.ts +4 -0
  38. package/dist/node/index.d.ts.map +1 -0
  39. package/dist/node/index.js +3 -0
  40. package/dist/node/index.mjs +1857 -97
  41. package/dist/node/index.mjs.map +1 -1
  42. package/dist/{serialize-props-Dhv_MnkY.mjs → serialize-props-BHoNpzH6.mjs} +2 -3
  43. package/dist/{serialize-props-Dhv_MnkY.mjs.map → serialize-props-BHoNpzH6.mjs.map} +1 -1
  44. package/dist/src/cms-handler.d.ts +19 -0
  45. package/dist/src/cms-handler.d.ts.map +1 -0
  46. package/dist/src/cms-handler.js +366 -0
  47. package/dist/src/collections.d.ts +32 -0
  48. package/dist/src/collections.d.ts.map +1 -0
  49. package/dist/src/collections.js +50 -0
  50. package/dist/src/components/HydrationWrapper.d.ts +18 -0
  51. package/dist/src/components/HydrationWrapper.d.ts.map +1 -0
  52. package/dist/src/components/HydrationWrapper.js +21 -0
  53. package/dist/src/components/RenderWithBlocks.d.ts +23 -0
  54. package/dist/src/components/RenderWithBlocks.d.ts.map +1 -0
  55. package/dist/src/components/RenderWithBlocks.js +129 -0
  56. package/dist/src/components/RenderWithHydration.d.ts +17 -0
  57. package/dist/src/components/RenderWithHydration.d.ts.map +1 -0
  58. package/dist/src/components/RenderWithHydration.js +36 -0
  59. package/dist/src/components.d.ts +4 -0
  60. package/dist/src/components.d.ts.map +1 -0
  61. package/dist/src/components.js +3 -0
  62. package/dist/src/discovery/astro-frontmatter.d.ts +18 -0
  63. package/dist/src/discovery/astro-frontmatter.d.ts.map +1 -0
  64. package/dist/src/discovery/astro-frontmatter.js +24 -0
  65. package/dist/src/discovery/extract-props-ts.d.ts +41 -0
  66. package/dist/src/discovery/extract-props-ts.d.ts.map +1 -0
  67. package/dist/src/discovery/extract-props-ts.js +231 -0
  68. package/dist/src/discovery/merge-registry.d.ts +58 -0
  69. package/dist/src/discovery/merge-registry.d.ts.map +1 -0
  70. package/dist/src/discovery/merge-registry.js +332 -0
  71. package/dist/src/discovery/registry-endpoint.d.ts +42 -0
  72. package/dist/src/discovery/registry-endpoint.d.ts.map +1 -0
  73. package/dist/src/discovery/registry-endpoint.js +81 -0
  74. package/dist/src/discovery/scan-components.d.ts +98 -0
  75. package/dist/src/discovery/scan-components.d.ts.map +1 -0
  76. package/dist/src/discovery/scan-components.js +399 -0
  77. package/dist/src/discovery/scan-mdx.d.ts +63 -0
  78. package/dist/src/discovery/scan-mdx.d.ts.map +1 -0
  79. package/dist/src/discovery/scan-mdx.js +112 -0
  80. package/dist/src/discovery/scan-overrides.d.ts +71 -0
  81. package/dist/src/discovery/scan-overrides.d.ts.map +1 -0
  82. package/dist/src/discovery/scan-overrides.js +33 -0
  83. package/dist/src/hydration.d.ts +4 -0
  84. package/dist/src/hydration.d.ts.map +1 -0
  85. package/dist/src/hydration.js +4 -0
  86. package/dist/src/index.d.ts +11 -0
  87. package/dist/src/index.d.ts.map +1 -0
  88. package/dist/src/index.js +25 -0
  89. package/dist/src/lib/hydration-scanner.d.ts +47 -0
  90. package/dist/src/lib/hydration-scanner.d.ts.map +1 -0
  91. package/dist/src/lib/hydration-scanner.js +135 -0
  92. package/dist/src/lib/hydration-script.d.ts +28 -0
  93. package/dist/src/lib/hydration-script.d.ts.map +1 -0
  94. package/dist/src/lib/hydration-script.js +88 -0
  95. package/dist/src/lib/hydration-utils.d.ts +51 -0
  96. package/dist/src/lib/hydration-utils.d.ts.map +1 -0
  97. package/dist/src/lib/hydration-utils.js +83 -0
  98. package/dist/src/lib/page-api.d.ts +77 -0
  99. package/dist/src/lib/page-api.d.ts.map +1 -0
  100. package/dist/src/lib/page-api.js +121 -0
  101. package/dist/src/lib/route-utils.d.ts +41 -0
  102. package/dist/src/lib/route-utils.d.ts.map +1 -0
  103. package/dist/src/lib/route-utils.js +78 -0
  104. package/dist/src/lib/routing-config.d.ts +32 -0
  105. package/dist/src/lib/routing-config.d.ts.map +1 -0
  106. package/dist/src/lib/routing-config.js +93 -0
  107. package/dist/src/lib/serialize-props.d.ts +6 -0
  108. package/dist/src/lib/serialize-props.d.ts.map +1 -0
  109. package/dist/src/lib/serialize-props.js +7 -0
  110. package/dist/src/lib/virtual-module-generators.d.ts +57 -0
  111. package/dist/src/lib/virtual-module-generators.d.ts.map +1 -0
  112. package/dist/src/lib/virtual-module-generators.js +263 -0
  113. package/dist/src/lib/withHydration.d.ts +51 -0
  114. package/dist/src/lib/withHydration.d.ts.map +1 -0
  115. package/dist/src/lib/withHydration.js +49 -0
  116. package/dist/src/loader.d.ts +14 -0
  117. package/dist/src/loader.d.ts.map +1 -0
  118. package/dist/src/loader.js +89 -0
  119. package/dist/src/locales-helpers.d.ts +61 -0
  120. package/dist/src/locales-helpers.d.ts.map +1 -0
  121. package/dist/src/locales-helpers.js +49 -0
  122. package/dist/src/mime-types.d.ts +3 -0
  123. package/dist/src/mime-types.d.ts.map +1 -0
  124. package/dist/src/mime-types.js +19 -0
  125. package/dist/src/path-validation.d.ts +8 -0
  126. package/dist/src/path-validation.d.ts.map +1 -0
  127. package/dist/src/path-validation.js +12 -0
  128. package/dist/src/plugin-spa.d.ts +164 -0
  129. package/dist/src/plugin-spa.d.ts.map +1 -0
  130. package/dist/src/plugin-spa.js +972 -0
  131. package/dist/src/safe-json-stringify.d.ts +13 -0
  132. package/dist/src/safe-json-stringify.d.ts.map +1 -0
  133. package/dist/src/safe-json-stringify.js +6 -0
  134. package/dist/src/site-styles/content-wrapper-endpoint.d.ts +76 -0
  135. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  136. package/dist/src/site-styles/content-wrapper-endpoint.js +227 -0
  137. package/dist/src/site-styles/render-endpoint.d.ts +55 -0
  138. package/dist/src/site-styles/render-endpoint.d.ts.map +1 -0
  139. package/dist/src/site-styles/render-endpoint.js +263 -0
  140. package/dist/src/site-styles/styles-endpoint.d.ts +61 -0
  141. package/dist/src/site-styles/styles-endpoint.d.ts.map +1 -0
  142. package/dist/src/site-styles/styles-endpoint.js +158 -0
  143. package/dist/src/types.d.ts +627 -0
  144. package/dist/src/types.d.ts.map +1 -0
  145. package/dist/src/types.js +1 -0
  146. package/dist/{types-CVQNmPxF.d.mts → types-CS9neadI.d.mts} +193 -3
  147. package/dist/types-CS9neadI.d.mts.map +1 -0
  148. package/dist/virtual-modules.d.ts +155 -0
  149. package/dist/{withHydration-EzyzBQ-Y.mjs → withHydration-C256ox_6.mjs} +2 -2
  150. package/dist/{withHydration-EzyzBQ-Y.mjs.map → withHydration-C256ox_6.mjs.map} +1 -1
  151. package/dist/{withHydration-HIvO9ysY.d.mts → withHydration-DkKpkmzJ.d.mts} +1 -2
  152. package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
  153. package/package.json +82 -26
  154. package/dist/collections.mjs.map +0 -1
  155. package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
  156. package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
  157. package/dist/loader-By-AQWHc.mjs +0 -68
  158. package/dist/loader-By-AQWHc.mjs.map +0 -1
  159. package/dist/types-CVQNmPxF.d.mts.map +0 -1
  160. package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
@@ -0,0 +1,129 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Render } from '@puckeditor/core/rsc';
3
+ import cn from 'clsx';
4
+ import { hasHydratableComponents } from '../lib/hydration-utils.js';
5
+ import { RenderWithHydration } from './RenderWithHydration.js';
6
+ function isRenderableBlock(block) {
7
+ return 'Component' in block && !('ok' in block);
8
+ }
9
+ const contentBlockWidthClasses = {
10
+ narrow: 'max-w-3xl',
11
+ default: 'max-w-4xl',
12
+ };
13
+ const contentBlockToneClasses = {
14
+ transparent: '',
15
+ subtle: 'rounded-3xl border border-surface-200/80 bg-surface-100/70 p-6 sm:p-8 dark:border-surface-800/60 dark:bg-surface-900/50',
16
+ };
17
+ function createFailedBlockComponent(block) {
18
+ return function FailedBlockComponent() {
19
+ return (_jsxs("div", { className: "p-4 bg-red-50 border border-red-200 rounded text-red-600", children: [_jsx("p", { className: "font-semibold mb-2", children: "MDX Block Error" }), _jsxs("p", { className: "text-sm", children: ["Block: ", block.id] }), _jsx("p", { className: "text-xs mt-2", children: block.error.message })] }));
20
+ };
21
+ }
22
+ function resolveRenderableBlocks(blocks) {
23
+ return blocks.map((block) => {
24
+ if (isRenderableBlock(block)) {
25
+ return block;
26
+ }
27
+ if (block.ok) {
28
+ return block;
29
+ }
30
+ return {
31
+ id: block.id,
32
+ title: block.title,
33
+ Component: createFailedBlockComponent(block),
34
+ };
35
+ });
36
+ }
37
+ // ── Main Component ──────────────────────────────────────────────────────────
38
+ /**
39
+ * Internal component for rendering Puck pages with MDX blocks.
40
+ *
41
+ * Enhances the Puck config by:
42
+ * 1. Registering each MDX block as a dynamic Puck component (`Block_{id}`)
43
+ * 2. Overriding ContentBlockSection's render to resolve blockId → actual MDX content
44
+ *
45
+ * MDX blocks are passed as React components (not HTML strings), which:
46
+ * - Avoids dangerouslySetInnerHTML security risks
47
+ * - More efficient (no HTML conversion round-trip)
48
+ * - Type-safe with proper React component types
49
+ *
50
+ * @internal
51
+ */
52
+ function RenderWithBlocks({ config, data, mdxComponents }) {
53
+ // Build enhanced config with MDX blocks
54
+ const blockComponents = {};
55
+ const blockCategoryList = [];
56
+ const blockComponentMap = new Map(mdxComponents.map((block) => [block.id, block]));
57
+ // Create component configs for each block
58
+ mdxComponents.forEach((block) => {
59
+ const componentKey = `Block_${block.id}`;
60
+ // Capture component in closure - Puck doesn't persist defaultProps reliably
61
+ const BlockComponent = block.Component;
62
+ blockComponents[componentKey] = {
63
+ label: block.title,
64
+ fields: {},
65
+ defaultProps: {},
66
+ render: () => {
67
+ // Use blockId and BlockComponent from closure - no prop dependency
68
+ return (_jsx("div", { className: "mdx-content conloca-prose max-w-none", children: _jsx(BlockComponent, {}) }));
69
+ },
70
+ };
71
+ blockCategoryList.push(componentKey);
72
+ });
73
+ // Merge with existing config
74
+ const existingCategories = config.categories || {};
75
+ const existingComponents = config.components || {};
76
+ const contentBlockSection = existingComponents.ContentBlockSection;
77
+ const enhancedContentBlockSection = contentBlockSection
78
+ ? {
79
+ ...contentBlockSection,
80
+ render: ({ blockId, label, title, subtitle, tone = 'transparent', width = 'default', }) => {
81
+ const selectedBlock = blockComponentMap.get(blockId);
82
+ const SelectedBlockComponent = selectedBlock?.Component;
83
+ return (_jsx("section", { className: "pb-16 sm:pb-20", children: _jsxs("div", { className: cn('mx-auto px-4 sm:px-6 lg:px-8', contentBlockWidthClasses[width]), children: [label ? (_jsx("p", { className: "mb-4 text-sm font-medium uppercase tracking-[0.18em] text-brand-700 dark:text-brand-300", children: label })) : null, title && (_jsx("h2", { className: "text-2xl sm:text-3xl font-bold text-surface-900 dark:text-white mb-4", children: title })), subtitle && (_jsx("p", { className: "text-surface-500 dark:text-surface-400 text-sm leading-relaxed mb-6", children: subtitle })), _jsx("div", { className: cn(contentBlockToneClasses[tone]), children: SelectedBlockComponent && (_jsx("div", { className: "mdx-content conloca-prose max-w-none", children: _jsx(SelectedBlockComponent, {}) })) })] }) }));
84
+ },
85
+ }
86
+ : undefined;
87
+ // Merge block components with existing config components
88
+ const mergedComponents = {
89
+ ...existingComponents,
90
+ ...(enhancedContentBlockSection && { ContentBlockSection: enhancedContentBlockSection }),
91
+ ...blockComponents,
92
+ };
93
+ const enhancedConfig = {
94
+ ...config,
95
+ categories: {
96
+ ...existingCategories,
97
+ blocks: {
98
+ title: 'Content Blocks',
99
+ components: blockCategoryList,
100
+ },
101
+ },
102
+ components: mergedComponents,
103
+ };
104
+ // Check if page has hydratable components
105
+ const needsHydration = hasHydratableComponents(data, enhancedConfig);
106
+ if (needsHydration) {
107
+ return _jsx(RenderWithHydration, { config: enhancedConfig, data: data });
108
+ }
109
+ return _jsx(Render, { config: enhancedConfig, data: data });
110
+ }
111
+ /**
112
+ * Factory function to create a PageRenderer with MDX components baked in via closure.
113
+ *
114
+ * This approach avoids dangerouslySetInnerHTML by keeping React components as components
115
+ * throughout the rendering pipeline. Components are captured in the closure and don't
116
+ * need to be passed as props (which Astro can't serialize).
117
+ *
118
+ * @param config - The Puck configuration with component definitions
119
+ * @param data - Puck page data containing component tree
120
+ * @param mdxComponents - Array of evaluated MDX block results
121
+ * @returns A PageRenderer component with no props needed (components in closure)
122
+ */
123
+ export function createPageRendererWithBlocks(config, data, mdxComponents) {
124
+ const renderableBlocks = resolveRenderableBlocks(mdxComponents);
125
+ // Capture components in closure - no need to pass as props
126
+ return function PageRendererWithBlocks() {
127
+ return _jsx(RenderWithBlocks, { config: config, data: data, mdxComponents: renderableBlocks });
128
+ };
129
+ }
@@ -0,0 +1,17 @@
1
+ import type { Config, Data } from '@puckeditor/core';
2
+ interface RenderWithHydrationProps {
3
+ config: Config;
4
+ data: Data;
5
+ }
6
+ /**
7
+ * Wrapper around Puck's Render component that adds hydration support.
8
+ *
9
+ * For each component with a hydration strategy configured, wraps the
10
+ * component's render output with HydrationWrapper to add data-hydrate
11
+ * attributes for browser-side hydration.
12
+ *
13
+ * Non-hydratable components render without any wrapper overhead.
14
+ */
15
+ export declare function RenderWithHydration({ config, data }: RenderWithHydrationProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
17
+ //# sourceMappingURL=RenderWithHydration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderWithHydration.d.ts","sourceRoot":"","sources":["../../../src/components/RenderWithHydration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAKrD,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;CACZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,wBAAwB,2CA+B7E"}
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Render } from '@puckeditor/core/rsc';
3
+ import { isHydratable } from '../lib/hydration-utils.js';
4
+ import { HydrationWrapper } from './HydrationWrapper.js';
5
+ /**
6
+ * Wrapper around Puck's Render component that adds hydration support.
7
+ *
8
+ * For each component with a hydration strategy configured, wraps the
9
+ * component's render output with HydrationWrapper to add data-hydrate
10
+ * attributes for browser-side hydration.
11
+ *
12
+ * Non-hydratable components render without any wrapper overhead.
13
+ */
14
+ export function RenderWithHydration({ config, data }) {
15
+ // Create wrapped config with hydration-aware render functions
16
+ const wrappedConfig = {
17
+ ...config,
18
+ components: Object.fromEntries(Object.entries(config.components).map(([name, componentConfig]) => {
19
+ const strategy = isHydratable(name, config);
20
+ if (strategy === 'none') {
21
+ // No wrapping needed - component stays static
22
+ return [name, componentConfig];
23
+ }
24
+ // Wrap the render function so its output becomes HydrationWrapper children
25
+ const originalRender = componentConfig.render;
26
+ return [
27
+ name,
28
+ {
29
+ ...componentConfig,
30
+ render: (props) => (_jsx(HydrationWrapper, { componentName: name, strategy: strategy, props: props, children: originalRender(props) })),
31
+ },
32
+ ];
33
+ })),
34
+ };
35
+ return _jsx(Render, { config: wrappedConfig, data: data });
36
+ }
@@ -0,0 +1,4 @@
1
+ export { evaluateMDXBlocks } from '@conloca/mdx/node';
2
+ export { createPageRendererWithBlocks } from './components/RenderWithBlocks';
3
+ export { RenderWithHydration } from './components/RenderWithHydration';
4
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { evaluateMDXBlocks } from '@conloca/mdx/node';
2
+ export { createPageRendererWithBlocks } from './components/RenderWithBlocks';
3
+ export { RenderWithHydration } from './components/RenderWithHydration';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Extract the frontmatter (the `---`-fenced TypeScript block) from
3
+ * an `.astro` source file. Returns the inner text, or `null` if no
4
+ * frontmatter is present (a valid Astro file shape — props-less
5
+ * components without `<script>` of any kind).
6
+ *
7
+ * Astro's official compiler (`@astrojs/compiler`) exposes a full
8
+ * parser, but for the props-extraction use case all we need is the
9
+ * text between the opening and closing fences. A regex is sufficient
10
+ * and keeps this synchronous (no WASM init cost, no async).
11
+ *
12
+ * The fence rule is simple: the file must start with `---\n` and
13
+ * close with `\n---` followed by either a newline or end-of-file.
14
+ * Whitespace before the opening fence is rejected — Astro itself
15
+ * requires the fence at column 0.
16
+ */
17
+ export declare function extractAstroFrontmatter(content: string): string | null;
18
+ //# sourceMappingURL=astro-frontmatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-frontmatter.d.ts","sourceRoot":"","sources":["../../../src/discovery/astro-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOtE"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Extract the frontmatter (the `---`-fenced TypeScript block) from
3
+ * an `.astro` source file. Returns the inner text, or `null` if no
4
+ * frontmatter is present (a valid Astro file shape — props-less
5
+ * components without `<script>` of any kind).
6
+ *
7
+ * Astro's official compiler (`@astrojs/compiler`) exposes a full
8
+ * parser, but for the props-extraction use case all we need is the
9
+ * text between the opening and closing fences. A regex is sufficient
10
+ * and keeps this synchronous (no WASM init cost, no async).
11
+ *
12
+ * The fence rule is simple: the file must start with `---\n` and
13
+ * close with `\n---` followed by either a newline or end-of-file.
14
+ * Whitespace before the opening fence is rejected — Astro itself
15
+ * requires the fence at column 0.
16
+ */
17
+ export function extractAstroFrontmatter(content) {
18
+ // `^---\r?\n` opens; `\r?\n---\s*(?:\r?\n|$)` closes.
19
+ // Capturing the inner content lazily so a body containing `---`
20
+ // (eg a horizontal rule string inside a default-prop) doesn't
21
+ // truncate. Astro itself uses the same "first ---/--- pair" rule.
22
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n|$)/.exec(content);
23
+ return match ? match[1] : null;
24
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * TypeScript-aware extraction of a component's `Props` interface,
3
+ * replacing the regex-based path in `scan-components.ts`. Uses
4
+ * `ts-morph` (a thin wrapper over the TypeScript compiler API) so
5
+ * derived types — `(typeof asideVariants)[number]`, mapped types,
6
+ * imported aliases, conditional types — resolve to their concrete
7
+ * literal-union values. The regex scanner couldn't follow any
8
+ * indirection and silently dropped options for those props (Aside's
9
+ * `type` being the canonical example).
10
+ *
11
+ * The output shape is identical to the regex path (`ParsedProp[]`)
12
+ * so the rest of the discovery pipeline doesn't change.
13
+ *
14
+ * Astro files are handled by extracting the frontmatter block and
15
+ * feeding it to the Project as a virtual `.ts` source — see
16
+ * `extractAstroFrontmatter` in `astro-frontmatter.ts`.
17
+ */
18
+ import { Project } from 'ts-morph';
19
+ import type { ParsedProp } from './scan-components.js';
20
+ /**
21
+ * One Project per scan run, reused across `extractPropsViaTs` calls
22
+ * within the same scan. Building the Project loads `lib.dom.d.ts`
23
+ * etc. which dominates cold-start cost (~500ms-2s); sharing across
24
+ * files in a scan amortises that. A fresh Project is built per scan
25
+ * run so file changes are picked up — ts-morph's `addSourceFile`
26
+ * caches by path and wouldn't see external edits otherwise.
27
+ */
28
+ export declare function createScanProject(tsConfigFilePath?: string): Project;
29
+ /**
30
+ * Extract the Props interface from a source string and return the
31
+ * parsed prop list. `filepath` is used as the virtual file's path
32
+ * inside the Project so error messages and source-map debugging
33
+ * point back at the right file; the actual content comes from
34
+ * `sourceText`. `.astro` callers pass the extracted frontmatter as
35
+ * `sourceText` and `${filepath}.virtual.ts` as `filepath`.
36
+ *
37
+ * Returns `[]` when no Props interface is found — same contract as
38
+ * the regex path so callers don't need a special-case branch.
39
+ */
40
+ export declare function extractPropsViaTs(project: Project, filepath: string, sourceText: string, componentName?: string): ParsedProp[];
41
+ //# sourceMappingURL=extract-props-ts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-props-ts.d.ts","sourceRoot":"","sources":["../../../src/discovery/extract-props-ts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAIL,OAAO,EAOR,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CA8BpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,GACrB,UAAU,EAAE,CAwDd"}
@@ -0,0 +1,231 @@
1
+ /**
2
+ * TypeScript-aware extraction of a component's `Props` interface,
3
+ * replacing the regex-based path in `scan-components.ts`. Uses
4
+ * `ts-morph` (a thin wrapper over the TypeScript compiler API) so
5
+ * derived types — `(typeof asideVariants)[number]`, mapped types,
6
+ * imported aliases, conditional types — resolve to their concrete
7
+ * literal-union values. The regex scanner couldn't follow any
8
+ * indirection and silently dropped options for those props (Aside's
9
+ * `type` being the canonical example).
10
+ *
11
+ * The output shape is identical to the regex path (`ParsedProp[]`)
12
+ * so the rest of the discovery pipeline doesn't change.
13
+ *
14
+ * Astro files are handled by extracting the frontmatter block and
15
+ * feeding it to the Project as a virtual `.ts` source — see
16
+ * `extractAstroFrontmatter` in `astro-frontmatter.ts`.
17
+ */
18
+ import { ModuleKind, ModuleResolutionKind, Project, ScriptTarget, } from 'ts-morph';
19
+ /**
20
+ * One Project per scan run, reused across `extractPropsViaTs` calls
21
+ * within the same scan. Building the Project loads `lib.dom.d.ts`
22
+ * etc. which dominates cold-start cost (~500ms-2s); sharing across
23
+ * files in a scan amortises that. A fresh Project is built per scan
24
+ * run so file changes are picked up — ts-morph's `addSourceFile`
25
+ * caches by path and wouldn't see external edits otherwise.
26
+ */
27
+ export function createScanProject(tsConfigFilePath) {
28
+ // When the host has a tsconfig, use it — that's how cross-file
29
+ // `typeof` refs and path mappings (`@/foo`) resolve. Without one,
30
+ // fall back to permissive defaults that still handle the common
31
+ // shapes (literal unions inside a single file, simple imports).
32
+ if (tsConfigFilePath) {
33
+ try {
34
+ return new Project({
35
+ tsConfigFilePath,
36
+ // Add files explicitly per scan; don't auto-load every file
37
+ // referenced by tsconfig.include — that would slow scans on
38
+ // big projects.
39
+ skipAddingFilesFromTsConfig: true,
40
+ });
41
+ }
42
+ catch {
43
+ // tsconfig parse failure — fall through to defaults
44
+ }
45
+ }
46
+ return new Project({
47
+ compilerOptions: {
48
+ target: ScriptTarget.ES2022,
49
+ module: ModuleKind.ESNext,
50
+ moduleResolution: ModuleResolutionKind.Bundler,
51
+ allowJs: true,
52
+ esModuleInterop: true,
53
+ skipLibCheck: true,
54
+ strict: false,
55
+ },
56
+ skipAddingFilesFromTsConfig: true,
57
+ });
58
+ }
59
+ /**
60
+ * Extract the Props interface from a source string and return the
61
+ * parsed prop list. `filepath` is used as the virtual file's path
62
+ * inside the Project so error messages and source-map debugging
63
+ * point back at the right file; the actual content comes from
64
+ * `sourceText`. `.astro` callers pass the extracted frontmatter as
65
+ * `sourceText` and `${filepath}.virtual.ts` as `filepath`.
66
+ *
67
+ * Returns `[]` when no Props interface is found — same contract as
68
+ * the regex path so callers don't need a special-case branch.
69
+ */
70
+ export function extractPropsViaTs(project, filepath, sourceText, componentName) {
71
+ let sf;
72
+ try {
73
+ sf = project.createSourceFile(filepath, sourceText, { overwrite: true });
74
+ }
75
+ catch (err) {
76
+ // Source parse failure — eg the .astro frontmatter contained
77
+ // syntax the TS compiler rejected (rare; most front-matter is
78
+ // valid TS). Return empty so the merge layer can still surface
79
+ // the component, just without prop schema.
80
+ console.warn(`[conloca:ts-morph] parse failed for ${filepath}:`, err instanceof Error ? err.message : err);
81
+ return [];
82
+ }
83
+ // Try `${ComponentName}Props` first (matches the convention
84
+ // `interface CardProps {...}` used by some libraries), then the
85
+ // bare `Props` name (Astro components and most React components).
86
+ // Try interface declarations first, then type aliases — same
87
+ // priority the regex scanner used.
88
+ const candidates = [];
89
+ if (componentName)
90
+ candidates.push(`${componentName}Props`);
91
+ candidates.push('Props');
92
+ let propertySignatures = [];
93
+ for (const name of candidates) {
94
+ const iface = sf.getInterface(name);
95
+ if (iface) {
96
+ propertySignatures = collectLocalProperties(iface);
97
+ break;
98
+ }
99
+ const alias = sf.getTypeAlias(name);
100
+ if (alias) {
101
+ propertySignatures = collectAliasProperties(alias);
102
+ break;
103
+ }
104
+ }
105
+ if (propertySignatures.length === 0) {
106
+ project.removeSourceFile(sf);
107
+ return [];
108
+ }
109
+ const props = [];
110
+ for (const prop of propertySignatures) {
111
+ const name = prop.getName();
112
+ // `getType()` on the PropertySignature node resolves at the
113
+ // declaration site — this is where `(typeof X)[number]` collapses
114
+ // to its literal union, generics expand, conditional types branch.
115
+ const type = prop.getType();
116
+ const required = !prop.hasQuestionToken();
117
+ props.push(parseType(name, type, required));
118
+ }
119
+ // Clean up the virtual source file so successive calls in the
120
+ // same scan don't accumulate sources and bloat memory.
121
+ project.removeSourceFile(sf);
122
+ return props;
123
+ }
124
+ /**
125
+ * Get ONLY the locally-declared properties on an interface, NOT
126
+ * properties inherited from `extends` clauses. This is the key choice
127
+ * that keeps the side panel sane for components like Starlight's
128
+ * `LinkCard` which declares `extends Omit<HTMLAttributes<'a'>, 'title'>`:
129
+ * the type-level `Type.getProperties()` would include every HTML
130
+ * attribute (~200 entries — `accesskey`, `aria-*`, `on*`, etc), making
131
+ * the panel useless. The declaration-level `iface.getProperties()`
132
+ * returns just the props the author explicitly wrote inside the
133
+ * braces, which is the editor's intent.
134
+ *
135
+ * Trade-off: a property the author "overrides" via re-declaration
136
+ * (eg LinkCard's local `title: string` overriding the inherited
137
+ * `title?: string`) appears — good. A property the author NEVER
138
+ * declared locally but the inherited interface defines (eg `href`
139
+ * inherited from HTMLAttributes) does NOT appear — also good, the
140
+ * panel stays focused on what the author wanted to expose. Hosts
141
+ * who want a specific inherited prop surfaced can re-declare it
142
+ * locally or use the sidecar `cmsConfig.props` override.
143
+ */
144
+ function collectLocalProperties(iface) {
145
+ // PropertySignature[] — only what's between this interface's own
146
+ // braces. Inherited properties from `extends` aren't included.
147
+ return iface.getProperties();
148
+ }
149
+ /**
150
+ * Type-alias variant. For `type Props = { ... }`, the declaration
151
+ * node is a TypeLiteralNode and we read its own member list. For
152
+ * intersections (`type Props = A & { ... }`) or imported aliases,
153
+ * we get an empty list rather than walking into the constituent
154
+ * types — same author-intent rationale as the interface case.
155
+ */
156
+ function collectAliasProperties(alias) {
157
+ const node = alias.getTypeNode();
158
+ // ts-morph's `asKind(SyntaxKind.TypeLiteral)` would narrow this
159
+ // cleanly, but we only need the duck-typed check that the node
160
+ // exposes `getMembers()`. A type literal does; an intersection or
161
+ // imported reference doesn't — those return an empty list and the
162
+ // alias is skipped by the caller.
163
+ const members = node?.getMembers?.();
164
+ if (!members)
165
+ return [];
166
+ return members.filter((m) => m.getKindName() === 'PropertySignature');
167
+ }
168
+ /**
169
+ * Map a resolved `Type` to a `ParsedProp`. Mirrors the kind of
170
+ * branching the old regex did, but on real type information.
171
+ */
172
+ function parseType(name, type, required) {
173
+ if (type.isString())
174
+ return { name, type: 'string', required };
175
+ if (type.isNumber())
176
+ return { name, type: 'number', required };
177
+ if (type.isBoolean())
178
+ return { name, type: 'boolean', required };
179
+ if (type.isUnion()) {
180
+ const members = type.getUnionTypes();
181
+ // Filter out `undefined` (added by the compiler for `?` props
182
+ // under strictNullChecks). The remaining members tell us what
183
+ // the prop actually accepts.
184
+ const nonUndefined = members.filter((m) => !m.isUndefined());
185
+ // All-boolean-literal union (`true | false`, or even `true` alone,
186
+ // or `false` alone) → boolean. Under strict mode, `boolean` is
187
+ // canonicalised by the checker into the union `true | false`, so
188
+ // `isBoolean()` on the original type returns false — we have to
189
+ // detect the expanded form. This is the path that catches eg
190
+ // CardGrid's `stagger?: boolean` (resolved as `true | false |
191
+ // undefined`).
192
+ if (nonUndefined.length > 0 && nonUndefined.every((m) => m.isBooleanLiteral() || m.isBoolean())) {
193
+ return { name, type: 'boolean', required };
194
+ }
195
+ // String-literal union → string prop with `options`. Even when
196
+ // the union also includes a non-literal `string`, surface the
197
+ // literals as picker suggestions.
198
+ const stringLiterals = nonUndefined
199
+ .filter((m) => m.isStringLiteral())
200
+ .map((m) => m.getLiteralValue())
201
+ .filter((v) => typeof v === 'string');
202
+ if (stringLiterals.length > 0) {
203
+ return { name, type: 'string', required, options: stringLiterals };
204
+ }
205
+ // Single non-undefined primitive after stripping the optional
206
+ // undefined — eg `string | undefined` collapses to `string`.
207
+ if (nonUndefined.length === 1) {
208
+ const only = nonUndefined[0];
209
+ if (only.isString())
210
+ return { name, type: 'string', required };
211
+ if (only.isNumber())
212
+ return { name, type: 'number', required };
213
+ if (only.isBoolean())
214
+ return { name, type: 'boolean', required };
215
+ if (only.isStringLiteral()) {
216
+ const v = only.getLiteralValue();
217
+ return { name, type: 'string', required, options: typeof v === 'string' ? [v] : undefined };
218
+ }
219
+ }
220
+ }
221
+ if (type.isStringLiteral()) {
222
+ const v = type.getLiteralValue();
223
+ return { name, type: 'string', required, options: typeof v === 'string' ? [v] : undefined };
224
+ }
225
+ if (type.isBooleanLiteral()) {
226
+ return { name, type: 'boolean', required };
227
+ }
228
+ // Anything else — function types, object types, branded types,
229
+ // arrays, Records — render as a free-form expression input.
230
+ return { name, type: 'expression', required };
231
+ }
@@ -0,0 +1,58 @@
1
+ import type { MdxJsxComponentDescriptor } from '@conloca/cms-spa/mdx-components';
2
+ import type { LocalComponentScanResult } from './scan-components';
3
+ import type { MdxScanResult } from './scan-mdx';
4
+ import type { CmsOverride } from './scan-overrides';
5
+ /**
6
+ * Combine the MDX usage scan with the local-component folder scan
7
+ * into the final flat list of component descriptors the editor
8
+ * registry consumes.
9
+ *
10
+ * Rules (chosen to match the decisions locked in earlier this
11
+ * session — usage-only inference for npm, full interface schema
12
+ * for local, per-file context wins on name collisions, aliases
13
+ * preserved per file):
14
+ *
15
+ * 1. Every component referenced by an `import` in any MDX file
16
+ * becomes a descriptor. The `name` is the canonical export
17
+ * name (`Aside`, not `Callout`), the `source` is the import
18
+ * path. This catches npm packages we can't statically scan.
19
+ *
20
+ * 2. Every component found by the local folder scan is also a
21
+ * descriptor. Its props come from the parsed `Props` interface.
22
+ * If the same canonical (name, source) was also seen in MDX,
23
+ * we merge — interface props win on the schema, usage-observed
24
+ * string values enrich `options`.
25
+ *
26
+ * 3. Components seen in MDX but never declared in any import
27
+ * (raw HTML tags like `<div>` or unresolved names) are dropped —
28
+ * `GenericBlock` already has its own HTML-passthrough path.
29
+ *
30
+ * 4. Across all usages, observed string values per attribute are
31
+ * collected. When ≤5 distinct values are seen (and the prop
32
+ * doesn't already have explicit options from the interface),
33
+ * they're added as dropdown choices.
34
+ *
35
+ * 5. Aliases (file-local imports renaming the canonical export,
36
+ * eg `import { Aside as Callout }`) are tracked on the
37
+ * descriptor's `aliases` map keyed by file path. The save
38
+ * serializer reads this to preserve the alias when writing
39
+ * the file back out.
40
+ *
41
+ * 6. Name collisions across different sources (local `<Card>` vs
42
+ * Starlight `<Card>`) — the higher-usage source wins; ties
43
+ * break in favor of the source whose props came from an
44
+ * interface schema. The dropped alternative isn't lost from
45
+ * the merge itself — it just doesn't surface in the registry
46
+ * until per-file disambiguation exists in the insert flow.
47
+ */
48
+ /** Same shape as `MdxJsxComponentDescriptor` from cms-spa, extended
49
+ * with `aliases` so save serialization can preserve `import { X as Y }`
50
+ * per file. Cms-spa's runtime type doesn't need to know about
51
+ * aliases — they're picked up server-side at save time. */
52
+ export interface DiscoveredComponent extends MdxJsxComponentDescriptor {
53
+ /** Per-file local alias (when the file uses `import { X as Y }`).
54
+ * Map key is the absolute MDX file path. */
55
+ aliases?: Record<string, string>;
56
+ }
57
+ export declare function mergeRegistry(mdxScans: MdxScanResult[], localComponents: LocalComponentScanResult[], overrides?: Map<string, CmsOverride>): DiscoveredComponent[];
58
+ //# sourceMappingURL=merge-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-registry.d.ts","sourceRoot":"","sources":["../../../src/discovery/merge-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,KAAK,EAAE,wBAAwB,EAAc,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAa,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH;;;2DAG2D;AAC3D,MAAM,WAAW,mBAAoB,SAAQ,yBAAyB;IACpE;gDAC4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,aAAa,EAAE,EACzB,eAAe,EAAE,wBAAwB,EAAE,EAC3C,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GACnC,mBAAmB,EAAE,CAwEvB"}