@tpitre/story-ui 2.2.0 → 2.3.1
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/.env.sample +82 -11
- package/README.md +89 -0
- package/dist/cli/deploy.d.ts +17 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +696 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +26 -2
- package/dist/cli/setup.d.ts +11 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +437 -110
- package/dist/mcp-server/index.d.ts +2 -0
- package/dist/mcp-server/index.d.ts.map +1 -0
- package/dist/mcp-server/index.js +120 -2
- package/dist/mcp-server/mcp-stdio-server.d.ts +3 -0
- package/dist/mcp-server/mcp-stdio-server.d.ts.map +1 -0
- package/dist/mcp-server/mcp-stdio-server.js +8 -1
- package/dist/mcp-server/routes/claude.d.ts +3 -0
- package/dist/mcp-server/routes/claude.d.ts.map +1 -0
- package/dist/mcp-server/routes/claude.js +60 -23
- package/dist/mcp-server/routes/components.d.ts +4 -0
- package/dist/mcp-server/routes/components.d.ts.map +1 -0
- package/dist/mcp-server/routes/frameworks.d.ts +38 -0
- package/dist/mcp-server/routes/frameworks.d.ts.map +1 -0
- package/dist/mcp-server/routes/frameworks.js +183 -0
- package/dist/mcp-server/routes/generateStory.d.ts +3 -0
- package/dist/mcp-server/routes/generateStory.d.ts.map +1 -0
- package/dist/mcp-server/routes/generateStory.js +160 -76
- package/dist/mcp-server/routes/generateStoryStream.d.ts +12 -0
- package/dist/mcp-server/routes/generateStoryStream.d.ts.map +1 -0
- package/dist/mcp-server/routes/generateStoryStream.js +947 -0
- package/dist/mcp-server/routes/hybridStories.d.ts +18 -0
- package/dist/mcp-server/routes/hybridStories.d.ts.map +1 -0
- package/dist/mcp-server/routes/mcpRemote.d.ts +14 -0
- package/dist/mcp-server/routes/mcpRemote.d.ts.map +1 -0
- package/dist/mcp-server/routes/mcpRemote.js +489 -0
- package/dist/mcp-server/routes/memoryStories.d.ts +26 -0
- package/dist/mcp-server/routes/memoryStories.d.ts.map +1 -0
- package/dist/mcp-server/routes/providers.d.ts +89 -0
- package/dist/mcp-server/routes/providers.d.ts.map +1 -0
- package/dist/mcp-server/routes/providers.js +369 -0
- package/dist/mcp-server/routes/storySync.d.ts +26 -0
- package/dist/mcp-server/routes/storySync.d.ts.map +1 -0
- package/dist/mcp-server/routes/streamTypes.d.ts +110 -0
- package/dist/mcp-server/routes/streamTypes.d.ts.map +1 -0
- package/dist/mcp-server/routes/streamTypes.js +18 -0
- package/dist/mcp-server/sessionManager.d.ts +50 -0
- package/dist/mcp-server/sessionManager.d.ts.map +1 -0
- package/dist/story-generator/componentBlacklist.d.ts +21 -0
- package/dist/story-generator/componentBlacklist.d.ts.map +1 -0
- package/dist/story-generator/componentDiscovery.d.ts +28 -0
- package/dist/story-generator/componentDiscovery.d.ts.map +1 -0
- package/dist/story-generator/componentRegistryGenerator.d.ts +49 -0
- package/dist/story-generator/componentRegistryGenerator.d.ts.map +1 -0
- package/dist/story-generator/componentRegistryGenerator.js +205 -0
- package/dist/story-generator/configLoader.d.ts +33 -0
- package/dist/story-generator/configLoader.d.ts.map +1 -0
- package/dist/story-generator/considerationsLoader.d.ts +32 -0
- package/dist/story-generator/considerationsLoader.d.ts.map +1 -0
- package/dist/story-generator/documentation-sources.d.ts +28 -0
- package/dist/story-generator/documentation-sources.d.ts.map +1 -0
- package/dist/story-generator/documentationLoader.d.ts +64 -0
- package/dist/story-generator/documentationLoader.d.ts.map +1 -0
- package/dist/story-generator/dynamicPackageDiscovery.d.ts +97 -0
- package/dist/story-generator/dynamicPackageDiscovery.d.ts.map +1 -0
- package/dist/story-generator/enhancedComponentDiscovery.d.ts +125 -0
- package/dist/story-generator/enhancedComponentDiscovery.d.ts.map +1 -0
- package/dist/story-generator/enhancedComponentDiscovery.js +111 -11
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/angular-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/angular-adapter.js +427 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts +75 -0
- package/dist/story-generator/framework-adapters/base-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/base-adapter.js +147 -0
- package/dist/story-generator/framework-adapters/framework-detector.d.ts +55 -0
- package/dist/story-generator/framework-adapters/framework-detector.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/framework-detector.js +323 -0
- package/dist/story-generator/framework-adapters/index.d.ts +97 -0
- package/dist/story-generator/framework-adapters/index.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/index.js +198 -0
- package/dist/story-generator/framework-adapters/react-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/react-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/react-adapter.js +316 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts +40 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/svelte-adapter.js +372 -0
- package/dist/story-generator/framework-adapters/types.d.ts +182 -0
- package/dist/story-generator/framework-adapters/types.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/types.js +8 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts +36 -0
- package/dist/story-generator/framework-adapters/vue-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/vue-adapter.js +336 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts +54 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.d.ts.map +1 -0
- package/dist/story-generator/framework-adapters/web-components-adapter.js +387 -0
- package/dist/story-generator/generateStory.d.ts +7 -0
- package/dist/story-generator/generateStory.d.ts.map +1 -0
- package/dist/story-generator/gitignoreManager.d.ts +50 -0
- package/dist/story-generator/gitignoreManager.d.ts.map +1 -0
- package/dist/story-generator/imageProcessor.d.ts +80 -0
- package/dist/story-generator/imageProcessor.d.ts.map +1 -0
- package/dist/story-generator/imageProcessor.js +391 -0
- package/dist/story-generator/inMemoryStoryService.d.ts +89 -0
- package/dist/story-generator/inMemoryStoryService.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/base-provider.d.ts +36 -0
- package/dist/story-generator/llm-providers/base-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/base-provider.js +135 -0
- package/dist/story-generator/llm-providers/claude-provider.d.ts +23 -0
- package/dist/story-generator/llm-providers/claude-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/claude-provider.js +414 -0
- package/dist/story-generator/llm-providers/gemini-provider.d.ts +24 -0
- package/dist/story-generator/llm-providers/gemini-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/gemini-provider.js +406 -0
- package/dist/story-generator/llm-providers/index.d.ts +63 -0
- package/dist/story-generator/llm-providers/index.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/index.js +169 -0
- package/dist/story-generator/llm-providers/openai-provider.d.ts +24 -0
- package/dist/story-generator/llm-providers/openai-provider.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/openai-provider.js +458 -0
- package/dist/story-generator/llm-providers/settings-manager.d.ts +75 -0
- package/dist/story-generator/llm-providers/settings-manager.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/settings-manager.js +173 -0
- package/dist/story-generator/llm-providers/story-llm-service.d.ts +79 -0
- package/dist/story-generator/llm-providers/story-llm-service.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/story-llm-service.js +240 -0
- package/dist/story-generator/llm-providers/types.d.ts +153 -0
- package/dist/story-generator/llm-providers/types.d.ts.map +1 -0
- package/dist/story-generator/llm-providers/types.js +8 -0
- package/dist/story-generator/logger.d.ts +14 -0
- package/dist/story-generator/logger.d.ts.map +1 -0
- package/dist/story-generator/logger.js +96 -29
- package/dist/story-generator/postProcessStory.d.ts +6 -0
- package/dist/story-generator/postProcessStory.d.ts.map +1 -0
- package/dist/story-generator/productionGitignoreManager.d.ts +91 -0
- package/dist/story-generator/productionGitignoreManager.d.ts.map +1 -0
- package/dist/story-generator/promptGenerator.d.ts +48 -0
- package/dist/story-generator/promptGenerator.d.ts.map +1 -0
- package/dist/story-generator/promptGenerator.js +186 -1
- package/dist/story-generator/storyHistory.d.ts +44 -0
- package/dist/story-generator/storyHistory.d.ts.map +1 -0
- package/dist/story-generator/storySync.d.ts +68 -0
- package/dist/story-generator/storySync.d.ts.map +1 -0
- package/dist/story-generator/storyTracker.d.ts +48 -0
- package/dist/story-generator/storyTracker.d.ts.map +1 -0
- package/dist/story-generator/storyValidator.d.ts +6 -0
- package/dist/story-generator/storyValidator.d.ts.map +1 -0
- package/dist/story-generator/universalDesignSystemAdapter.d.ts +68 -0
- package/dist/story-generator/universalDesignSystemAdapter.d.ts.map +1 -0
- package/dist/story-generator/universalDesignSystemAdapter.js +138 -1
- package/dist/story-generator/urlRedirectService.d.ts +21 -0
- package/dist/story-generator/urlRedirectService.d.ts.map +1 -0
- package/dist/story-generator/validateStory.d.ts +19 -0
- package/dist/story-generator/validateStory.d.ts.map +1 -0
- package/dist/story-generator/validateStory.js +6 -2
- package/dist/story-generator/visionPrompts.d.ts +88 -0
- package/dist/story-generator/visionPrompts.d.ts.map +1 -0
- package/dist/story-generator/visionPrompts.js +462 -0
- package/dist/story-ui.config.d.ts +78 -0
- package/dist/story-ui.config.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.d.ts +4 -0
- package/dist/templates/StoryUI/StoryUIPanel.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.js +1874 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.d.ts +18 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.d.ts.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.js +37 -0
- package/dist/templates/StoryUI/index.d.ts +3 -0
- package/dist/templates/StoryUI/index.d.ts.map +1 -0
- package/dist/templates/StoryUI/index.js +2 -0
- package/package.json +17 -3
- package/templates/StoryUI/StoryUIPanel.tsx +1960 -384
- package/templates/StoryUI/index.tsx +1 -1
- package/templates/StoryUI/manager.tsx +264 -0
- package/templates/production-app/.env.example +11 -0
- package/templates/production-app/index.html +66 -0
- package/templates/production-app/package.json +30 -0
- package/templates/production-app/public/favicon.svg +5 -0
- package/templates/production-app/src/App.tsx +1560 -0
- package/templates/production-app/src/LivePreviewRenderer.tsx +420 -0
- package/templates/production-app/src/componentRegistry.ts +315 -0
- package/templates/production-app/src/considerations.ts +16 -0
- package/templates/production-app/src/index.css +284 -0
- package/templates/production-app/src/main.tsx +25 -0
- package/templates/production-app/tsconfig.json +32 -0
- package/templates/production-app/tsconfig.node.json +11 -0
- package/templates/production-app/vite.config.ts +83 -0
- package/templates/react-import-rule.json +2 -2
- package/dist/index.js +0 -12
- package/dist/story-ui.config.loader.js +0 -205
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework Adapters Module
|
|
3
|
+
*
|
|
4
|
+
* Exports framework detection, adapters, and the adapter registry.
|
|
5
|
+
*/
|
|
6
|
+
// Types
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
// Framework Detection
|
|
9
|
+
export { FrameworkDetector, detectFramework, getFrameworkDetector, } from './framework-detector.js';
|
|
10
|
+
// Base Adapter
|
|
11
|
+
export { BaseFrameworkAdapter } from './base-adapter.js';
|
|
12
|
+
// Framework Adapters
|
|
13
|
+
export { ReactAdapter, createReactAdapter } from './react-adapter.js';
|
|
14
|
+
export { WebComponentsAdapter, createWebComponentsAdapter } from './web-components-adapter.js';
|
|
15
|
+
export { VueAdapter, createVueAdapter } from './vue-adapter.js';
|
|
16
|
+
export { AngularAdapter, createAngularAdapter } from './angular-adapter.js';
|
|
17
|
+
export { SvelteAdapter, createSvelteAdapter } from './svelte-adapter.js';
|
|
18
|
+
import { ReactAdapter } from './react-adapter.js';
|
|
19
|
+
import { WebComponentsAdapter } from './web-components-adapter.js';
|
|
20
|
+
import { VueAdapter } from './vue-adapter.js';
|
|
21
|
+
import { AngularAdapter } from './angular-adapter.js';
|
|
22
|
+
import { SvelteAdapter } from './svelte-adapter.js';
|
|
23
|
+
import { detectFramework } from './framework-detector.js';
|
|
24
|
+
import { logger } from '../logger.js';
|
|
25
|
+
/**
|
|
26
|
+
* Framework Adapter Registry
|
|
27
|
+
*
|
|
28
|
+
* Manages available framework adapters and provides
|
|
29
|
+
* automatic framework detection and adapter selection.
|
|
30
|
+
*/
|
|
31
|
+
class AdapterRegistry {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.adapters = new Map();
|
|
34
|
+
this.detectedFramework = null;
|
|
35
|
+
// Register built-in adapters
|
|
36
|
+
this.registerBuiltInAdapters();
|
|
37
|
+
// Default to React
|
|
38
|
+
this.defaultAdapter = this.adapters.get('react');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Register built-in framework adapters
|
|
42
|
+
*/
|
|
43
|
+
registerBuiltInAdapters() {
|
|
44
|
+
this.register(new ReactAdapter());
|
|
45
|
+
this.register(new WebComponentsAdapter());
|
|
46
|
+
this.register(new VueAdapter());
|
|
47
|
+
this.register(new AngularAdapter());
|
|
48
|
+
this.register(new SvelteAdapter());
|
|
49
|
+
logger.debug('Registered framework adapters', {
|
|
50
|
+
adapters: Array.from(this.adapters.keys()),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Register a framework adapter
|
|
55
|
+
*/
|
|
56
|
+
register(adapter) {
|
|
57
|
+
this.adapters.set(adapter.type, adapter);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get adapter by framework type
|
|
61
|
+
*/
|
|
62
|
+
get(type) {
|
|
63
|
+
return this.adapters.get(type);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered adapters
|
|
67
|
+
*/
|
|
68
|
+
getAll() {
|
|
69
|
+
return Array.from(this.adapters.values());
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get available framework types
|
|
73
|
+
*/
|
|
74
|
+
getAvailableTypes() {
|
|
75
|
+
return Array.from(this.adapters.keys());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get available framework types (alias for getAvailableTypes)
|
|
79
|
+
*/
|
|
80
|
+
getAvailableFrameworks() {
|
|
81
|
+
return this.getAvailableTypes();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get adapter by framework type (alias for get with default fallback)
|
|
85
|
+
*/
|
|
86
|
+
getAdapter(type) {
|
|
87
|
+
return this.adapters.get(type) || this.defaultAdapter;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the default adapter
|
|
91
|
+
*/
|
|
92
|
+
getDefault() {
|
|
93
|
+
return this.defaultAdapter;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Set the default adapter
|
|
97
|
+
*/
|
|
98
|
+
setDefault(type) {
|
|
99
|
+
const adapter = this.adapters.get(type);
|
|
100
|
+
if (adapter) {
|
|
101
|
+
this.defaultAdapter = adapter;
|
|
102
|
+
logger.debug('Set default framework adapter', { type });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Auto-detect framework and return appropriate adapter
|
|
107
|
+
*/
|
|
108
|
+
async autoDetect(projectRoot) {
|
|
109
|
+
const result = await detectFramework(projectRoot);
|
|
110
|
+
this.detectedFramework = result.primary;
|
|
111
|
+
const adapter = this.adapters.get(result.primary.componentFramework);
|
|
112
|
+
if (adapter) {
|
|
113
|
+
logger.info('Auto-detected framework', {
|
|
114
|
+
framework: result.primary.componentFramework,
|
|
115
|
+
confidence: result.primary.confidence,
|
|
116
|
+
});
|
|
117
|
+
return adapter;
|
|
118
|
+
}
|
|
119
|
+
logger.warn('No adapter for detected framework, using default', {
|
|
120
|
+
detected: result.primary.componentFramework,
|
|
121
|
+
using: this.defaultAdapter.type,
|
|
122
|
+
});
|
|
123
|
+
return this.defaultAdapter;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the last detected framework info
|
|
127
|
+
*/
|
|
128
|
+
getDetectedFramework() {
|
|
129
|
+
return this.detectedFramework;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Generate prompt using the appropriate adapter
|
|
133
|
+
*/
|
|
134
|
+
async generatePrompt(config, components, options) {
|
|
135
|
+
// Determine which adapter to use
|
|
136
|
+
let adapter;
|
|
137
|
+
if (options?.framework) {
|
|
138
|
+
// Explicit framework specified
|
|
139
|
+
adapter = this.adapters.get(options.framework) || this.defaultAdapter;
|
|
140
|
+
}
|
|
141
|
+
else if (this.detectedFramework) {
|
|
142
|
+
// Use previously detected framework
|
|
143
|
+
adapter = this.adapters.get(this.detectedFramework.componentFramework) || this.defaultAdapter;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// Auto-detect
|
|
147
|
+
adapter = await this.autoDetect();
|
|
148
|
+
}
|
|
149
|
+
logger.debug('Generating prompt with adapter', { adapter: adapter.type });
|
|
150
|
+
return {
|
|
151
|
+
systemPrompt: adapter.generateSystemPrompt(config, options),
|
|
152
|
+
componentReference: adapter.generateComponentReference(components, config),
|
|
153
|
+
layoutInstructions: '', // TODO: Implement layout instructions
|
|
154
|
+
examples: adapter.generateExamples(config),
|
|
155
|
+
sampleStory: adapter.generateSampleStory(config, components),
|
|
156
|
+
framework: this.detectedFramework || {
|
|
157
|
+
componentFramework: adapter.type,
|
|
158
|
+
storyFramework: adapter.supportedStoryFrameworks[0],
|
|
159
|
+
confidence: 1,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Singleton registry instance
|
|
165
|
+
let registryInstance = null;
|
|
166
|
+
/**
|
|
167
|
+
* Get the global adapter registry instance
|
|
168
|
+
*/
|
|
169
|
+
export function getAdapterRegistry() {
|
|
170
|
+
if (!registryInstance) {
|
|
171
|
+
registryInstance = new AdapterRegistry();
|
|
172
|
+
}
|
|
173
|
+
return registryInstance;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get adapter for a specific framework
|
|
177
|
+
*/
|
|
178
|
+
export function getAdapter(type) {
|
|
179
|
+
return getAdapterRegistry().get(type);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get the default adapter
|
|
183
|
+
*/
|
|
184
|
+
export function getDefaultAdapter() {
|
|
185
|
+
return getAdapterRegistry().getDefault();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Auto-detect framework and get appropriate adapter
|
|
189
|
+
*/
|
|
190
|
+
export async function autoDetectAdapter(projectRoot) {
|
|
191
|
+
return getAdapterRegistry().autoDetect(projectRoot);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Generate framework-specific prompt
|
|
195
|
+
*/
|
|
196
|
+
export async function generateFrameworkPrompt(config, components, options) {
|
|
197
|
+
return getAdapterRegistry().generatePrompt(config, components, options);
|
|
198
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Framework Adapter
|
|
3
|
+
*
|
|
4
|
+
* Generates Storybook stories for React components.
|
|
5
|
+
* Supports CSF 3.0 format with TypeScript.
|
|
6
|
+
*/
|
|
7
|
+
import { FrameworkType, StoryFramework, StoryGenerationOptions } from './types.js';
|
|
8
|
+
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
9
|
+
import { StoryUIConfig } from '../../story-ui.config.js';
|
|
10
|
+
import { DiscoveredComponent } from '../componentDiscovery.js';
|
|
11
|
+
export declare class ReactAdapter extends BaseFrameworkAdapter {
|
|
12
|
+
readonly type: FrameworkType;
|
|
13
|
+
readonly name = "React";
|
|
14
|
+
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
|
+
readonly defaultExtension = ".stories.tsx";
|
|
16
|
+
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* FIX #2: Detect if the project uses Chakra UI v3
|
|
19
|
+
*/
|
|
20
|
+
private isChakraUIProject;
|
|
21
|
+
generateExamples(config: StoryUIConfig): string;
|
|
22
|
+
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
23
|
+
getStoryTemplate(options?: StoryGenerationOptions): string;
|
|
24
|
+
/**
|
|
25
|
+
* Post-process React stories
|
|
26
|
+
*/
|
|
27
|
+
postProcess(storyContent: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Validate React story
|
|
30
|
+
*/
|
|
31
|
+
validate(storyContent: string): {
|
|
32
|
+
valid: boolean;
|
|
33
|
+
errors: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Factory function
|
|
38
|
+
*/
|
|
39
|
+
export declare function createReactAdapter(): ReactAdapter;
|
|
40
|
+
//# sourceMappingURL=react-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/react-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,YAAa,SAAQ,oBAAoB;IACpD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAW;IACvC,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAIjD;IACF,QAAQ,CAAC,gBAAgB,kBAAkB;IAE3C,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IA+GT;;OAEG;IACH,OAAO,CAAC,iBAAiB;IASzB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAgE/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IA4CT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IA0B1D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IA4BzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;CA2BrE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Framework Adapter
|
|
3
|
+
*
|
|
4
|
+
* Generates Storybook stories for React components.
|
|
5
|
+
* Supports CSF 3.0 format with TypeScript.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
8
|
+
export class ReactAdapter extends BaseFrameworkAdapter {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.type = 'react';
|
|
12
|
+
this.name = 'React';
|
|
13
|
+
this.supportedStoryFrameworks = [
|
|
14
|
+
'storybook-react',
|
|
15
|
+
'ladle',
|
|
16
|
+
'chromatic',
|
|
17
|
+
];
|
|
18
|
+
this.defaultExtension = '.stories.tsx';
|
|
19
|
+
}
|
|
20
|
+
generateSystemPrompt(config, options) {
|
|
21
|
+
if (config.systemPrompt) {
|
|
22
|
+
return config.systemPrompt;
|
|
23
|
+
}
|
|
24
|
+
const componentSystemName = config.componentPrefix
|
|
25
|
+
? `${config.componentPrefix.replace(/^[A-Z]+/, '')} design system`
|
|
26
|
+
: 'component library';
|
|
27
|
+
const typescript = options?.typescript !== false;
|
|
28
|
+
// FIX #2: Auto-detect Chakra UI v3 for provider requirements
|
|
29
|
+
const isChakraUI = this.isChakraUIProject(config);
|
|
30
|
+
let chakraInstructions = '';
|
|
31
|
+
if (isChakraUI) {
|
|
32
|
+
chakraInstructions = `
|
|
33
|
+
|
|
34
|
+
CHAKRA UI v3 CONFIGURATION (CRITICAL):
|
|
35
|
+
Chakra UI v3 requires ChakraProvider for proper theming and styling.
|
|
36
|
+
|
|
37
|
+
OPTION 1 (Recommended): Configure in .storybook/preview.tsx (project-wide):
|
|
38
|
+
\`\`\`tsx
|
|
39
|
+
// .storybook/preview.tsx
|
|
40
|
+
import { ChakraProvider, defaultSystem } from '@chakra-ui/react';
|
|
41
|
+
|
|
42
|
+
export const decorators = [
|
|
43
|
+
(Story) => (
|
|
44
|
+
<ChakraProvider value={defaultSystem}>
|
|
45
|
+
<Story />
|
|
46
|
+
</ChakraProvider>
|
|
47
|
+
),
|
|
48
|
+
];
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
OPTION 2: Wrap individual stories (if preview.tsx not configured):
|
|
52
|
+
\`\`\`tsx
|
|
53
|
+
import { ChakraProvider, defaultSystem } from '@chakra-ui/react';
|
|
54
|
+
|
|
55
|
+
export const MyStory: Story = {
|
|
56
|
+
decorators: [
|
|
57
|
+
(Story) => (
|
|
58
|
+
<ChakraProvider value={defaultSystem}>
|
|
59
|
+
<Story />
|
|
60
|
+
</ChakraProvider>
|
|
61
|
+
),
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
IMPORTANT: Without ChakraProvider, you will see "useContext returned undefined" errors.
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
return `You are an expert React developer creating Storybook stories using CSF 3.0 format.
|
|
70
|
+
Use ONLY the React components from the ${componentSystemName} listed below.
|
|
71
|
+
|
|
72
|
+
MANDATORY IMPORTS - First lines of every story file:
|
|
73
|
+
1. import React from 'react';
|
|
74
|
+
2. import type { Meta, StoryObj } from '@storybook/react';
|
|
75
|
+
3. import { ComponentName } from '${config.importPath || 'your-library'}';
|
|
76
|
+
|
|
77
|
+
${typescript ? 'Use TypeScript with proper type annotations.' : 'Use JavaScript.'}
|
|
78
|
+
${chakraInstructions}
|
|
79
|
+
COMPONENT IMPORT RULES:
|
|
80
|
+
- ONLY import components listed in the "Available Components" section
|
|
81
|
+
- Use the EXACT import path shown after each component name
|
|
82
|
+
- Components not in the list DO NOT EXIST
|
|
83
|
+
|
|
84
|
+
STORY STRUCTURE (CSF 3.0):
|
|
85
|
+
- Use ES modules: export default meta; NOT module.exports
|
|
86
|
+
- Define Meta object with component, title, and parameters
|
|
87
|
+
- Export named stories as StoryObj<typeof ComponentName>
|
|
88
|
+
|
|
89
|
+
CRITICAL RULES:
|
|
90
|
+
- NEVER pass children through args - use render functions instead
|
|
91
|
+
- For layouts with multiple components, omit component from meta
|
|
92
|
+
- Use render: (args) => <Component {...args} /> for custom rendering
|
|
93
|
+
|
|
94
|
+
Example structure:
|
|
95
|
+
\`\`\`tsx
|
|
96
|
+
import React from 'react';
|
|
97
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
98
|
+
import { Button } from '${config.importPath || 'your-library'}';
|
|
99
|
+
|
|
100
|
+
const meta: Meta<typeof Button> = {
|
|
101
|
+
title: 'Components/Button',
|
|
102
|
+
component: Button,
|
|
103
|
+
parameters: { layout: 'centered' },
|
|
104
|
+
tags: ['autodocs'],
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default meta;
|
|
108
|
+
type Story = StoryObj<typeof meta>;
|
|
109
|
+
|
|
110
|
+
export const Primary: Story = {
|
|
111
|
+
args: { variant: 'primary', children: 'Click me' },
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const WithIcon: Story = {
|
|
115
|
+
render: () => (
|
|
116
|
+
<Button variant="primary">
|
|
117
|
+
<Icon /> Click me
|
|
118
|
+
</Button>
|
|
119
|
+
),
|
|
120
|
+
};
|
|
121
|
+
\`\`\`
|
|
122
|
+
|
|
123
|
+
${this.getCommonRules()}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* FIX #2: Detect if the project uses Chakra UI v3
|
|
127
|
+
*/
|
|
128
|
+
isChakraUIProject(config) {
|
|
129
|
+
const importPath = config.importPath || '';
|
|
130
|
+
return (importPath.includes('@chakra-ui') ||
|
|
131
|
+
importPath === 'chakra-ui' ||
|
|
132
|
+
config.componentPrefix === 'Chakra');
|
|
133
|
+
}
|
|
134
|
+
generateExamples(config) {
|
|
135
|
+
const lib = config.importPath || 'your-library';
|
|
136
|
+
return `
|
|
137
|
+
## Example Stories
|
|
138
|
+
|
|
139
|
+
### Single Component Story
|
|
140
|
+
\`\`\`tsx
|
|
141
|
+
import React from 'react';
|
|
142
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
143
|
+
import { Button } from '${lib}';
|
|
144
|
+
|
|
145
|
+
const meta: Meta<typeof Button> = {
|
|
146
|
+
title: 'Components/Button',
|
|
147
|
+
component: Button,
|
|
148
|
+
parameters: { layout: 'centered' },
|
|
149
|
+
argTypes: {
|
|
150
|
+
variant: {
|
|
151
|
+
control: 'select',
|
|
152
|
+
options: ['primary', 'secondary', 'ghost'],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export default meta;
|
|
158
|
+
type Story = StoryObj<typeof meta>;
|
|
159
|
+
|
|
160
|
+
export const Default: Story = {
|
|
161
|
+
args: { children: 'Button' },
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const Primary: Story = {
|
|
165
|
+
args: { variant: 'primary', children: 'Primary Button' },
|
|
166
|
+
};
|
|
167
|
+
\`\`\`
|
|
168
|
+
|
|
169
|
+
### Layout Story (Multiple Components)
|
|
170
|
+
\`\`\`tsx
|
|
171
|
+
import React from 'react';
|
|
172
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
173
|
+
import { Card, Button, Text } from '${lib}';
|
|
174
|
+
|
|
175
|
+
const meta: Meta = {
|
|
176
|
+
title: 'Examples/Card Layout',
|
|
177
|
+
parameters: { layout: 'padded' },
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export default meta;
|
|
181
|
+
type Story = StoryObj;
|
|
182
|
+
|
|
183
|
+
export const ProductCard: Story = {
|
|
184
|
+
render: () => (
|
|
185
|
+
<Card style={{ width: 300 }}>
|
|
186
|
+
<img src="https://picsum.photos/300/200" alt="Product" />
|
|
187
|
+
<Text variant="heading">Product Name</Text>
|
|
188
|
+
<Text>$99.00</Text>
|
|
189
|
+
<Button variant="primary">Add to Cart</Button>
|
|
190
|
+
</Card>
|
|
191
|
+
),
|
|
192
|
+
};
|
|
193
|
+
\`\`\`
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
generateSampleStory(config, components) {
|
|
197
|
+
const lib = config.importPath || 'your-library';
|
|
198
|
+
const firstComponent = components[0];
|
|
199
|
+
if (!firstComponent) {
|
|
200
|
+
return `
|
|
201
|
+
import React from 'react';
|
|
202
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
203
|
+
|
|
204
|
+
const meta: Meta = {
|
|
205
|
+
title: 'Examples/Sample',
|
|
206
|
+
parameters: { layout: 'centered' },
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default meta;
|
|
210
|
+
type Story = StoryObj;
|
|
211
|
+
|
|
212
|
+
export const Default: Story = {
|
|
213
|
+
render: () => <div>Sample story content</div>,
|
|
214
|
+
};
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
return `
|
|
218
|
+
import React from 'react';
|
|
219
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
220
|
+
import { ${firstComponent.name} } from '${lib}';
|
|
221
|
+
|
|
222
|
+
const meta: Meta<typeof ${firstComponent.name}> = {
|
|
223
|
+
title: 'Components/${firstComponent.name}',
|
|
224
|
+
component: ${firstComponent.name},
|
|
225
|
+
parameters: { layout: 'centered' },
|
|
226
|
+
tags: ['autodocs'],
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export default meta;
|
|
230
|
+
type Story = StoryObj<typeof meta>;
|
|
231
|
+
|
|
232
|
+
export const Default: Story = {
|
|
233
|
+
args: {},
|
|
234
|
+
};
|
|
235
|
+
`;
|
|
236
|
+
}
|
|
237
|
+
getStoryTemplate(options) {
|
|
238
|
+
const typescript = options?.typescript !== false;
|
|
239
|
+
const ext = typescript ? 'tsx' : 'jsx';
|
|
240
|
+
return `
|
|
241
|
+
// {{componentName}}.stories.${ext}
|
|
242
|
+
import React from 'react';
|
|
243
|
+
${typescript ? "import type { Meta, StoryObj } from '@storybook/react';" : ''}
|
|
244
|
+
import { {{componentName}} } from '{{importPath}}';
|
|
245
|
+
|
|
246
|
+
const meta${typescript ? ': Meta<typeof {{componentName}}>' : ''} = {
|
|
247
|
+
title: '{{category}}/{{componentName}}',
|
|
248
|
+
component: {{componentName}},
|
|
249
|
+
parameters: { layout: 'centered' },
|
|
250
|
+
tags: ['autodocs'],
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default meta;
|
|
254
|
+
${typescript ? 'type Story = StoryObj<typeof meta>;' : ''}
|
|
255
|
+
|
|
256
|
+
export const Default${typescript ? ': Story' : ''} = {
|
|
257
|
+
args: {},
|
|
258
|
+
};
|
|
259
|
+
`;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Post-process React stories
|
|
263
|
+
*/
|
|
264
|
+
postProcess(storyContent) {
|
|
265
|
+
let processed = super.postProcess(storyContent);
|
|
266
|
+
// Ensure React import is first
|
|
267
|
+
if (!processed.startsWith("import React from 'react'")) {
|
|
268
|
+
const lines = processed.split('\n');
|
|
269
|
+
const reactImportIndex = lines.findIndex(line => line.includes("import React from 'react'"));
|
|
270
|
+
if (reactImportIndex > 0) {
|
|
271
|
+
const reactImport = lines.splice(reactImportIndex, 1)[0];
|
|
272
|
+
lines.unshift(reactImport);
|
|
273
|
+
processed = lines.join('\n');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// Fix common issues
|
|
277
|
+
processed = processed
|
|
278
|
+
// Remove only EMPTY children in args (children: '' or children: "")
|
|
279
|
+
// The regex must require matching quotes to avoid removing valid children like children: 'Button'
|
|
280
|
+
.replace(/children:\s*['"]['"],?\s*/g, '')
|
|
281
|
+
// Fix double quotes in JSX
|
|
282
|
+
.replace(/class=/g, 'className=');
|
|
283
|
+
return processed;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Validate React story
|
|
287
|
+
*/
|
|
288
|
+
validate(storyContent) {
|
|
289
|
+
const baseValidation = super.validate(storyContent);
|
|
290
|
+
const errors = [...baseValidation.errors];
|
|
291
|
+
// React-specific validations
|
|
292
|
+
if (!storyContent.includes("import React from 'react'")) {
|
|
293
|
+
errors.push("Missing 'import React from 'react'' statement");
|
|
294
|
+
}
|
|
295
|
+
if (!storyContent.includes('export default')) {
|
|
296
|
+
errors.push('Missing default export');
|
|
297
|
+
}
|
|
298
|
+
if (storyContent.includes('module.exports')) {
|
|
299
|
+
errors.push('Using CommonJS exports instead of ES modules');
|
|
300
|
+
}
|
|
301
|
+
// Check for children in args (common mistake)
|
|
302
|
+
if (/args:\s*{[^}]*children:\s*</.test(storyContent)) {
|
|
303
|
+
errors.push('JSX children should not be in args - use render function instead');
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
valid: errors.length === 0,
|
|
307
|
+
errors,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Factory function
|
|
313
|
+
*/
|
|
314
|
+
export function createReactAdapter() {
|
|
315
|
+
return new ReactAdapter();
|
|
316
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte Framework Adapter
|
|
3
|
+
*
|
|
4
|
+
* Generates Storybook stories for Svelte components.
|
|
5
|
+
* Supports both Svelte 4 and Svelte 5 (runes).
|
|
6
|
+
*/
|
|
7
|
+
import { FrameworkType, StoryFramework, StoryGenerationOptions } from './types.js';
|
|
8
|
+
import { BaseFrameworkAdapter } from './base-adapter.js';
|
|
9
|
+
import { StoryUIConfig } from '../../story-ui.config.js';
|
|
10
|
+
import { DiscoveredComponent } from '../componentDiscovery.js';
|
|
11
|
+
export declare class SvelteAdapter extends BaseFrameworkAdapter {
|
|
12
|
+
readonly type: FrameworkType;
|
|
13
|
+
readonly name = "Svelte";
|
|
14
|
+
readonly supportedStoryFrameworks: StoryFramework[];
|
|
15
|
+
readonly defaultExtension = ".stories.ts";
|
|
16
|
+
generateSystemPrompt(config: StoryUIConfig, options?: StoryGenerationOptions): string;
|
|
17
|
+
generateExamples(config: StoryUIConfig): string;
|
|
18
|
+
generateSampleStory(config: StoryUIConfig, components: DiscoveredComponent[]): string;
|
|
19
|
+
getStoryTemplate(options?: StoryGenerationOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* Post-process Svelte stories
|
|
22
|
+
*/
|
|
23
|
+
postProcess(storyContent: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Validate Svelte story
|
|
26
|
+
*/
|
|
27
|
+
validate(storyContent: string): {
|
|
28
|
+
valid: boolean;
|
|
29
|
+
errors: string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generate imports for Svelte components
|
|
33
|
+
*/
|
|
34
|
+
generateImports(components: DiscoveredComponent[], config: StoryUIConfig): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Factory function
|
|
38
|
+
*/
|
|
39
|
+
export declare function createSvelteAdapter(): SvelteAdapter;
|
|
40
|
+
//# sourceMappingURL=svelte-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte-adapter.d.ts","sourceRoot":"","sources":["../../../story-generator/framework-adapters/svelte-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,aAAc,SAAQ,oBAAoB;IACrD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAY;IACxC,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,wBAAwB,EAAE,cAAc,EAAE,CAGjD;IACF,QAAQ,CAAC,gBAAgB,iBAAiB;IAE1C,oBAAoB,CAClB,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM;IAqGT,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IA0I/C,mBAAmB,CACjB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,mBAAmB,EAAE,GAChC,MAAM;IA4CT,gBAAgB,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM;IAsB1D;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAkBzC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAwBpE;;OAEG;IACH,eAAe,CACb,UAAU,EAAE,mBAAmB,EAAE,EACjC,MAAM,EAAE,aAAa,GACpB,MAAM;CAWV;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
|