@tpitre/story-ui 2.1.5 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.sample +82 -11
- package/README.md +130 -4
- 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 +55 -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 +138 -6
- 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 +638 -0
- 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 +274 -115
- 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/hybridStories.js +214 -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/memoryStories.js +13 -7
- 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/mcp-server/sessionManager.js +125 -0
- package/dist/story-generator/componentBlacklist.d.ts +21 -0
- package/dist/story-generator/componentBlacklist.d.ts.map +1 -0
- package/dist/story-generator/componentBlacklist.js +4 -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/configLoader.js +8 -1
- package/dist/story-generator/considerationsLoader.d.ts +32 -0
- package/dist/story-generator/considerationsLoader.d.ts.map +1 -0
- package/dist/story-generator/considerationsLoader.js +2 -1
- 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/documentationLoader.js +4 -3
- package/dist/story-generator/dynamicPackageDiscovery.d.ts +97 -0
- package/dist/story-generator/dynamicPackageDiscovery.d.ts.map +1 -0
- package/dist/story-generator/dynamicPackageDiscovery.js +31 -22
- 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 +162 -21
- 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/gitignoreManager.js +7 -6
- 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 +119 -0
- package/dist/story-generator/postProcessStory.d.ts +6 -0
- package/dist/story-generator/postProcessStory.d.ts.map +1 -0
- package/dist/story-generator/postProcessStory.js +8 -7
- package/dist/story-generator/productionGitignoreManager.d.ts +91 -0
- package/dist/story-generator/productionGitignoreManager.d.ts.map +1 -0
- package/dist/story-generator/productionGitignoreManager.js +11 -10
- 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/storyTracker.js +2 -1
- 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 +141 -3
- package/dist/story-generator/urlRedirectService.d.ts +21 -0
- package/dist/story-generator/urlRedirectService.d.ts.map +1 -0
- package/dist/story-generator/urlRedirectService.js +140 -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 +35 -4
- package/templates/StoryUI/StoryUIPanel.tsx +1973 -388
- package/templates/StoryUI/index.tsx +1 -1
- package/templates/StoryUI/manager.tsx +264 -0
- package/templates/mcp-config-claude.json +11 -0
- package/templates/mcp-example.md +76 -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 +1157 -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,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"}
|