@tpitre/story-ui 3.3.0 → 3.4.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/dist/cli/index.js +0 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cloudflare-edge/src/mcp-session.js +462 -0
- package/dist/cloudflare-edge/src/types.js +4 -0
- package/dist/cloudflare-edge/src/worker.js +106 -0
- package/dist/cloudflare-pages/vite.config.js +14 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/index.js.map +1 -0
- package/dist/mcp-server/mcp-stdio-server.js.map +1 -0
- package/dist/mcp-server/routes/claude.js.map +1 -0
- package/dist/mcp-server/routes/components.js.map +1 -0
- package/dist/mcp-server/routes/generateStory.js.map +1 -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 +216 -0
- package/dist/mcp-server/routes/hybridStories.js.map +1 -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 +158 -0
- package/dist/mcp-server/routes/memoryStories.js.map +1 -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/storySync.js +147 -0
- package/dist/mcp-server/routes/storySync.js.map +1 -0
- package/dist/mcp-server/routes/updateStory.js +246 -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/mcp-server/sessionManager.js.map +1 -0
- package/dist/playground/components/AIAssistant/AIAssistant.d.ts +6 -0
- package/dist/playground/components/AIAssistant/AIAssistant.d.ts.map +1 -0
- package/dist/playground/components/AIAssistant/AIAssistant.js +109 -0
- package/dist/playground/components/AIAssistant/AIAssistant.js.map +1 -0
- package/dist/playground/components/AIAssistant/AIAssistant.module.css +166 -0
- package/dist/playground/components/Canvas/Canvas.d.ts +9 -0
- package/dist/playground/components/Canvas/Canvas.d.ts.map +1 -0
- package/dist/playground/components/Canvas/Canvas.js +58 -0
- package/dist/playground/components/Canvas/Canvas.js.map +1 -0
- package/dist/playground/components/Canvas/Canvas.module.css +189 -0
- package/dist/playground/components/Canvas/CanvasWithDnd.d.ts +9 -0
- package/dist/playground/components/Canvas/CanvasWithDnd.d.ts.map +1 -0
- package/dist/playground/components/Canvas/CanvasWithDnd.js +158 -0
- package/dist/playground/components/Canvas/CanvasWithDnd.js.map +1 -0
- package/dist/playground/components/Canvas/ComponentRenderer.d.ts +15 -0
- package/dist/playground/components/Canvas/ComponentRenderer.d.ts.map +1 -0
- package/dist/playground/components/Canvas/ComponentRenderer.js +177 -0
- package/dist/playground/components/Canvas/ComponentRenderer.js.map +1 -0
- package/dist/playground/components/Canvas/DraggableComponent.d.ts +15 -0
- package/dist/playground/components/Canvas/DraggableComponent.d.ts.map +1 -0
- package/dist/playground/components/Canvas/DraggableComponent.js +49 -0
- package/dist/playground/components/Canvas/DraggableComponent.js.map +1 -0
- package/dist/playground/components/Canvas/index.d.ts +9 -0
- package/dist/playground/components/Canvas/index.d.ts.map +1 -0
- package/dist/playground/components/Canvas/index.js +5 -0
- package/dist/playground/components/Canvas/index.js.map +1 -0
- package/dist/playground/components/CodeView/CodeView.d.ts +12 -0
- package/dist/playground/components/CodeView/CodeView.d.ts.map +1 -0
- package/dist/playground/components/CodeView/CodeView.js +77 -0
- package/dist/playground/components/CodeView/CodeView.js.map +1 -0
- package/dist/playground/components/CodeView/CodeView.module.css +178 -0
- package/dist/playground/components/ComponentPalette/ComponentPalette.d.ts +17 -0
- package/dist/playground/components/ComponentPalette/ComponentPalette.d.ts.map +1 -0
- package/dist/playground/components/ComponentPalette/ComponentPalette.js +138 -0
- package/dist/playground/components/ComponentPalette/ComponentPalette.js.map +1 -0
- package/dist/playground/components/ComponentPalette/ComponentPalette.module.css +217 -0
- package/dist/playground/components/ComponentPalette/index.d.ts +3 -0
- package/dist/playground/components/ComponentPalette/index.d.ts.map +1 -0
- package/dist/playground/components/ComponentPalette/index.js +2 -0
- package/dist/playground/components/ComponentPalette/index.js.map +1 -0
- package/dist/playground/components/DropZone/DropZone.d.ts +17 -0
- package/dist/playground/components/DropZone/DropZone.d.ts.map +1 -0
- package/dist/playground/components/DropZone/DropZone.js +73 -0
- package/dist/playground/components/DropZone/DropZone.js.map +1 -0
- package/dist/playground/components/DropZone/DropZone.module.css +86 -0
- package/dist/playground/components/ExportDialog/ExportDialog.d.ts +10 -0
- package/dist/playground/components/ExportDialog/ExportDialog.d.ts.map +1 -0
- package/dist/playground/components/ExportDialog/ExportDialog.js +57 -0
- package/dist/playground/components/ExportDialog/ExportDialog.js.map +1 -0
- package/dist/playground/components/ExportDialog/ExportDialog.module.css +328 -0
- package/dist/playground/components/LayoutHelpers/LayoutHelpers.d.ts +134 -0
- package/dist/playground/components/LayoutHelpers/LayoutHelpers.d.ts.map +1 -0
- package/dist/playground/components/LayoutHelpers/LayoutHelpers.js +254 -0
- package/dist/playground/components/LayoutHelpers/LayoutHelpers.js.map +1 -0
- package/dist/playground/components/LayoutHelpers/index.d.ts +3 -0
- package/dist/playground/components/LayoutHelpers/index.d.ts.map +1 -0
- package/dist/playground/components/LayoutHelpers/index.js +2 -0
- package/dist/playground/components/LayoutHelpers/index.js.map +1 -0
- package/dist/playground/components/Playground/Playground.d.ts +10 -0
- package/dist/playground/components/Playground/Playground.d.ts.map +1 -0
- package/dist/playground/components/Playground/Playground.js +128 -0
- package/dist/playground/components/Playground/Playground.js.map +1 -0
- package/dist/playground/components/Playground/Playground.module.css +308 -0
- package/dist/playground/components/PropertiesPanel/PropertiesPanel.d.ts +10 -0
- package/dist/playground/components/PropertiesPanel/PropertiesPanel.d.ts.map +1 -0
- package/dist/playground/components/PropertiesPanel/PropertiesPanel.js +150 -0
- package/dist/playground/components/PropertiesPanel/PropertiesPanel.js.map +1 -0
- package/dist/playground/components/PropertiesPanel/PropertiesPanel.module.css +155 -0
- package/dist/playground/components/PropertiesPanel/index.d.ts +3 -0
- package/dist/playground/components/PropertiesPanel/index.d.ts.map +1 -0
- package/dist/playground/components/PropertiesPanel/index.js +2 -0
- package/dist/playground/components/PropertiesPanel/index.js.map +1 -0
- package/dist/playground/components/PropertyEditors/BooleanEditor.d.ts +12 -0
- package/dist/playground/components/PropertyEditors/BooleanEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/BooleanEditor.js +14 -0
- package/dist/playground/components/PropertyEditors/BooleanEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/ColorEditor.d.ts +12 -0
- package/dist/playground/components/PropertyEditors/ColorEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/ColorEditor.js +62 -0
- package/dist/playground/components/PropertyEditors/ColorEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/IconEditor.d.ts +12 -0
- package/dist/playground/components/PropertyEditors/IconEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/IconEditor.js +123 -0
- package/dist/playground/components/PropertyEditors/IconEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/NumberEditor.d.ts +15 -0
- package/dist/playground/components/PropertyEditors/NumberEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/NumberEditor.js +46 -0
- package/dist/playground/components/PropertyEditors/NumberEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/PropertyEditors.module.css +432 -0
- package/dist/playground/components/PropertyEditors/SelectEditor.d.ts +19 -0
- package/dist/playground/components/PropertyEditors/SelectEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/SelectEditor.js +17 -0
- package/dist/playground/components/PropertyEditors/SelectEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/SpacingEditor.d.ts +19 -0
- package/dist/playground/components/PropertyEditors/SpacingEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/SpacingEditor.js +162 -0
- package/dist/playground/components/PropertyEditors/SpacingEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/SpacingEditor.module.css +214 -0
- package/dist/playground/components/PropertyEditors/TextEditor.d.ts +14 -0
- package/dist/playground/components/PropertyEditors/TextEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/TextEditor.js +38 -0
- package/dist/playground/components/PropertyEditors/TextEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/TokenEditor.d.ts +23 -0
- package/dist/playground/components/PropertyEditors/TokenEditor.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/TokenEditor.js +50 -0
- package/dist/playground/components/PropertyEditors/TokenEditor.js.map +1 -0
- package/dist/playground/components/PropertyEditors/index.d.ts +20 -0
- package/dist/playground/components/PropertyEditors/index.d.ts.map +1 -0
- package/dist/playground/components/PropertyEditors/index.js +12 -0
- package/dist/playground/components/PropertyEditors/index.js.map +1 -0
- package/dist/playground/components/TreeView/TreeView.d.ts +10 -0
- package/dist/playground/components/TreeView/TreeView.d.ts.map +1 -0
- package/dist/playground/components/TreeView/TreeView.js +146 -0
- package/dist/playground/components/TreeView/TreeView.js.map +1 -0
- package/dist/playground/components/TreeView/TreeView.module.css +214 -0
- package/dist/playground/components/TreeView/index.d.ts +3 -0
- package/dist/playground/components/TreeView/index.d.ts.map +1 -0
- package/dist/playground/components/TreeView/index.js +2 -0
- package/dist/playground/components/TreeView/index.js.map +1 -0
- package/dist/playground/config/propertyDefinitions.d.ts +73 -0
- package/dist/playground/config/propertyDefinitions.d.ts.map +1 -0
- package/dist/playground/config/propertyDefinitions.js +809 -0
- package/dist/playground/config/propertyDefinitions.js.map +1 -0
- package/dist/playground/hooks/useKeyboardShortcuts.d.ts +38 -0
- package/dist/playground/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/playground/hooks/useKeyboardShortcuts.js +191 -0
- package/dist/playground/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/playground/index.d.ts +21 -0
- package/dist/playground/index.d.ts.map +1 -0
- package/dist/playground/index.js +23 -0
- package/dist/playground/index.js.map +1 -0
- package/dist/playground/services/CodeGenerator.d.ts +73 -0
- package/dist/playground/services/CodeGenerator.d.ts.map +1 -0
- package/dist/playground/services/CodeGenerator.js +359 -0
- package/dist/playground/services/CodeGenerator.js.map +1 -0
- package/dist/playground/services/DragDropManager.d.ts +95 -0
- package/dist/playground/services/DragDropManager.d.ts.map +1 -0
- package/dist/playground/services/DragDropManager.js +408 -0
- package/dist/playground/services/DragDropManager.js.map +1 -0
- package/dist/playground/services/StoryParser.d.ts +73 -0
- package/dist/playground/services/StoryParser.d.ts.map +1 -0
- package/dist/playground/services/StoryParser.js +419 -0
- package/dist/playground/services/StoryParser.js.map +1 -0
- package/dist/playground/store/playgroundStore.d.ts +86 -0
- package/dist/playground/store/playgroundStore.d.ts.map +1 -0
- package/dist/playground/store/playgroundStore.js +337 -0
- package/dist/playground/store/playgroundStore.js.map +1 -0
- package/dist/playground/stories/PlaygroundDragDrop.stories.d.ts +13 -0
- package/dist/playground/stories/PlaygroundDragDrop.stories.d.ts.map +1 -0
- package/dist/playground/stories/PlaygroundDragDrop.stories.js +227 -0
- package/dist/playground/stories/PlaygroundDragDrop.stories.js.map +1 -0
- package/dist/playground/stories/PlaygroundPhase4.stories.d.ts +13 -0
- package/dist/playground/stories/PlaygroundPhase4.stories.d.ts.map +1 -0
- package/dist/playground/stories/PlaygroundPhase4.stories.js +334 -0
- package/dist/playground/stories/PlaygroundPhase4.stories.js.map +1 -0
- package/dist/playground/stories/PlaygroundPhase5.stories.d.ts +14 -0
- package/dist/playground/stories/PlaygroundPhase5.stories.d.ts.map +1 -0
- package/dist/playground/stories/PlaygroundPhase5.stories.js +512 -0
- package/dist/playground/stories/PlaygroundPhase5.stories.js.map +1 -0
- package/dist/playground/stories/PlaygroundProperties.stories.d.ts +13 -0
- package/dist/playground/stories/PlaygroundProperties.stories.d.ts.map +1 -0
- package/dist/playground/stories/PlaygroundProperties.stories.js +342 -0
- package/dist/playground/stories/PlaygroundProperties.stories.js.map +1 -0
- package/dist/playground/types/index.d.ts +251 -0
- package/dist/playground/types/index.d.ts.map +1 -0
- package/dist/playground/types/index.js +5 -0
- package/dist/playground/types/index.js.map +1 -0
- package/dist/scripts/verify-framework-adapters.js +105 -0
- package/dist/story-generator/componentBlacklist.js.map +1 -0
- package/dist/story-generator/componentDiscovery.js.map +1 -0
- package/dist/story-generator/configLoader.js.map +1 -0
- package/dist/story-generator/considerationsLoader.js.map +1 -0
- package/dist/story-generator/documentation-sources.js.map +1 -0
- package/dist/story-generator/documentationLoader.js.map +1 -0
- package/dist/story-generator/dynamicPackageDiscovery.js.map +1 -0
- package/dist/story-generator/enhancedComponentDiscovery.js.map +1 -0
- package/dist/story-generator/generateStory.js.map +1 -0
- package/dist/story-generator/gitignoreManager.js.map +1 -0
- package/dist/story-generator/inMemoryStoryService.d.ts +89 -0
- package/dist/story-generator/inMemoryStoryService.d.ts.map +1 -0
- package/dist/story-generator/inMemoryStoryService.js +128 -0
- package/dist/story-generator/inMemoryStoryService.js.map +1 -0
- package/dist/story-generator/logger.js.map +1 -0
- package/dist/story-generator/postProcessStory.js.map +1 -0
- package/dist/story-generator/postgresStoryService.d.ts +56 -0
- package/dist/story-generator/postgresStoryService.d.ts.map +1 -0
- package/dist/story-generator/postgresStoryService.js +240 -0
- 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 +340 -0
- package/dist/story-generator/productionGitignoreManager.js.map +1 -0
- package/dist/story-generator/promptGenerator.js.map +1 -0
- package/dist/story-generator/providerPresets.d.ts +54 -0
- package/dist/story-generator/providerPresets.d.ts.map +1 -0
- package/dist/story-generator/providerPresets.js +214 -0
- package/dist/story-generator/storyHistory.js.map +1 -0
- package/dist/story-generator/storyServiceFactory.d.ts +22 -0
- package/dist/story-generator/storyServiceFactory.d.ts.map +1 -0
- package/dist/story-generator/storyServiceFactory.js +97 -0
- package/dist/story-generator/storyServiceInterface.d.ts +85 -0
- package/dist/story-generator/storyServiceInterface.d.ts.map +1 -0
- package/dist/story-generator/storyServiceInterface.js +5 -0
- package/dist/story-generator/storySync.d.ts +68 -0
- package/dist/story-generator/storySync.d.ts.map +1 -0
- package/dist/story-generator/storySync.js +201 -0
- package/dist/story-generator/storySync.js.map +1 -0
- package/dist/story-generator/storyTracker.js.map +1 -0
- package/dist/story-generator/storyValidator.js.map +1 -0
- package/dist/story-generator/test_validation.d.ts +2 -0
- package/dist/story-generator/test_validation.d.ts.map +1 -0
- package/dist/story-generator/test_validation.js +51 -0
- package/dist/story-generator/universalDesignSystemAdapter.js.map +1 -0
- package/dist/story-generator/urlRedirectService.js.map +1 -0
- package/dist/story-generator/validateStory.js.map +1 -0
- package/dist/story-ui.config.js.map +1 -0
- package/dist/story-ui.config.loader.d.ts +36 -0
- package/dist/story-ui.config.loader.d.ts.map +1 -0
- package/dist/story-ui.config.loader.js +205 -0
- package/dist/story-ui.config.loader.js.map +1 -0
- package/dist/temp/package/templates/StoryUI/StoryUIPanel.js +807 -0
- package/dist/temp/package/templates/StoryUI/StoryUIPanel.stories.js +37 -0
- package/dist/temp/package/templates/StoryUI/index.js +2 -0
- package/dist/templates/StoryUI/StoryUIPanel.js.map +1 -0
- package/dist/templates/StoryUI/StoryUIPanel.stories.js.map +1 -0
- package/dist/templates/StoryUI/index.js.map +1 -0
- package/dist/templates/StoryUI/manager.d.ts +14 -0
- package/dist/templates/StoryUI/manager.d.ts.map +1 -0
- package/dist/templates/production-app/src/App.d.ts +10 -0
- package/dist/templates/production-app/src/App.d.ts.map +1 -0
- package/dist/templates/production-app/src/App.js +653 -0
- package/dist/templates/production-app/src/LivePreviewRenderer.d.ts +24 -0
- package/dist/templates/production-app/src/LivePreviewRenderer.d.ts.map +1 -0
- package/dist/templates/production-app/src/LivePreviewRenderer.js +199 -0
- package/dist/templates/production-app/src/componentRegistry.d.ts +20 -0
- package/dist/templates/production-app/src/componentRegistry.d.ts.map +1 -0
- package/dist/templates/production-app/src/componentRegistry.js +316 -0
- package/dist/templates/production-app/src/main.d.ts +9 -0
- package/dist/templates/production-app/src/main.d.ts.map +1 -0
- package/dist/templates/production-app/src/main.js +18 -0
- package/dist/templates/production-app/vite.config.d.ts +3 -0
- package/dist/templates/production-app/vite.config.d.ts.map +1 -0
- package/dist/templates/production-app/vite.config.js +71 -0
- package/dist/test-storybooks/angular-material-storybook/src/main.js +66 -0
- package/dist/test-storybooks/chakra-storybook/vite.config.js +6 -0
- package/dist/test-storybooks/mantine-storybook/vite.config.js +93 -0
- package/dist/test-storybooks/web-components-shoelace/vite.config.js +9 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* AIAssistant - Connects to existing Story UI generation and enables visual editing
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useCallback, useRef } from 'react';
|
|
6
|
+
import { usePlaygroundStore } from '../../store/playgroundStore';
|
|
7
|
+
import { StoryParser } from '../../services/StoryParser';
|
|
8
|
+
import styles from './AIAssistant.module.css';
|
|
9
|
+
// Get the MCP API port (same as StoryUIPanel)
|
|
10
|
+
const getApiPort = () => {
|
|
11
|
+
const vitePort = import.meta.env?.VITE_STORY_UI_PORT;
|
|
12
|
+
if (vitePort)
|
|
13
|
+
return String(vitePort);
|
|
14
|
+
const windowOverride = window.__STORY_UI_PORT__;
|
|
15
|
+
if (windowOverride)
|
|
16
|
+
return String(windowOverride);
|
|
17
|
+
const mcpOverride = window.STORY_UI_MCP_PORT;
|
|
18
|
+
if (mcpOverride)
|
|
19
|
+
return String(mcpOverride);
|
|
20
|
+
return '4001';
|
|
21
|
+
};
|
|
22
|
+
const MCP_API = `http://localhost:${getApiPort()}/story-ui/generate`;
|
|
23
|
+
export const AIAssistant = () => {
|
|
24
|
+
const [prompt, setPrompt] = useState('');
|
|
25
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
26
|
+
const [error, setError] = useState(null);
|
|
27
|
+
const [hasGenerated, setHasGenerated] = useState(false);
|
|
28
|
+
const textareaRef = useRef(null);
|
|
29
|
+
const { setGeneratedStoryCode, setIsParsingStory, setParseError, loadComponentsFromStory, setMode } = usePlaygroundStore();
|
|
30
|
+
const parser = useRef(new StoryParser());
|
|
31
|
+
// Generate layout using existing Story UI API
|
|
32
|
+
const handleGenerate = useCallback(async () => {
|
|
33
|
+
if (!prompt.trim() || isGenerating)
|
|
34
|
+
return;
|
|
35
|
+
setIsGenerating(true);
|
|
36
|
+
setError(null);
|
|
37
|
+
try {
|
|
38
|
+
// Call existing Story UI generation API
|
|
39
|
+
const response = await fetch(MCP_API, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
prompt,
|
|
44
|
+
// Add hint for playground-optimized generation
|
|
45
|
+
conversation: [{
|
|
46
|
+
role: 'system',
|
|
47
|
+
content: 'Generate a layout with clear component structure suitable for visual editing.'
|
|
48
|
+
}, {
|
|
49
|
+
role: 'user',
|
|
50
|
+
content: prompt
|
|
51
|
+
}]
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`Generation failed: ${response.statusText}`);
|
|
56
|
+
}
|
|
57
|
+
const data = await response.json();
|
|
58
|
+
if (!data.success) {
|
|
59
|
+
throw new Error(data.error || 'Story generation failed');
|
|
60
|
+
}
|
|
61
|
+
// Store the generated code
|
|
62
|
+
setGeneratedStoryCode(data.code || data.story);
|
|
63
|
+
// Parse the generated story into playground components
|
|
64
|
+
setIsParsingStory(true);
|
|
65
|
+
const parseResult = await parser.current.parseStoryToComponents(data.code || data.story);
|
|
66
|
+
if (parseResult.success) {
|
|
67
|
+
loadComponentsFromStory(parseResult.components);
|
|
68
|
+
setHasGenerated(true);
|
|
69
|
+
// Show any warnings
|
|
70
|
+
if (parseResult.warnings && parseResult.warnings.length > 0) {
|
|
71
|
+
console.warn('Parse warnings:', parseResult.warnings);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error(parseResult.error || 'Failed to parse story');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
80
|
+
setError(errorMessage);
|
|
81
|
+
setParseError(errorMessage);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setIsGenerating(false);
|
|
85
|
+
setIsParsingStory(false);
|
|
86
|
+
}
|
|
87
|
+
}, [
|
|
88
|
+
prompt,
|
|
89
|
+
isGenerating,
|
|
90
|
+
setGeneratedStoryCode,
|
|
91
|
+
setIsParsingStory,
|
|
92
|
+
setParseError,
|
|
93
|
+
loadComponentsFromStory
|
|
94
|
+
]);
|
|
95
|
+
// Switch to edit mode
|
|
96
|
+
const handleEditLayout = useCallback(() => {
|
|
97
|
+
setMode('edit');
|
|
98
|
+
// Additional edit mode setup could go here
|
|
99
|
+
}, [setMode]);
|
|
100
|
+
// Handle Enter key
|
|
101
|
+
const handleKeyDown = useCallback((e) => {
|
|
102
|
+
if (e.key === 'Enter' && e.metaKey) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
handleGenerate();
|
|
105
|
+
}
|
|
106
|
+
}, [handleGenerate]);
|
|
107
|
+
return (_jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.section, children: [_jsx("label", { className: styles.label, children: "Describe your layout" }), _jsx("textarea", { ref: textareaRef, className: styles.textarea, value: prompt, onChange: (e) => setPrompt(e.target.value), onKeyDown: handleKeyDown, placeholder: "Create a dashboard with a header, sidebar navigation, and main content area with cards...", rows: 4, disabled: isGenerating }), _jsxs("div", { className: styles.buttonGroup, children: [_jsx("button", { className: `${styles.button} ${styles.primaryButton}`, onClick: handleGenerate, disabled: !prompt.trim() || isGenerating, children: isGenerating ? (_jsxs(_Fragment, { children: [_jsx("span", { className: styles.spinner }), "Generating..."] })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: styles.icon, children: "\u2728" }), "Generate Layout"] })) }), hasGenerated && (_jsxs("button", { className: `${styles.button} ${styles.secondaryButton}`, onClick: handleEditLayout, children: [_jsx("span", { className: styles.icon, children: "\u270F\uFE0F" }), "Edit Layout"] }))] }), error && (_jsxs("div", { className: styles.error, children: [_jsx("span", { className: styles.errorIcon, children: "\u26A0\uFE0F" }), error] }))] }), _jsxs("div", { className: styles.section, children: [_jsx("h3", { className: styles.sectionTitle, children: "Suggestions" }), _jsxs("div", { className: styles.suggestions, children: [_jsx("button", { className: styles.suggestion, onClick: () => setPrompt('Create a blog post layout with header, content, and sidebar'), children: "Blog Layout" }), _jsx("button", { className: styles.suggestion, onClick: () => setPrompt('Build a product card grid with filters'), children: "Product Grid" }), _jsx("button", { className: styles.suggestion, onClick: () => setPrompt('Design a user profile page with stats and activity feed'), children: "Profile Page" }), _jsx("button", { className: styles.suggestion, onClick: () => setPrompt('Create a dashboard with charts and metrics'), children: "Dashboard" })] })] }), _jsxs("div", { className: styles.section, children: [_jsx("h3", { className: styles.sectionTitle, children: "Tips" }), _jsxs("ul", { className: styles.tips, children: [_jsx("li", { children: "Be specific about layout structure and components" }), _jsx("li", { children: "Mention spacing and alignment preferences" }), _jsx("li", { children: "After generation, click \"Edit Layout\" to refine visually" }), _jsx("li", { children: "Use Cmd+Enter to generate quickly" })] })] })] }));
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=AIAssistant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIAssistant.js","sourceRoot":"","sources":["../../../../playground/components/AIAssist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om: 24px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.label {
|
|
14
|
+
display: block;
|
|
15
|
+
font-size: 14px;
|
|
16
|
+
font-weight: 500;
|
|
17
|
+
color: #374151;
|
|
18
|
+
margin-bottom: 8px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.textarea {
|
|
22
|
+
width: 100%;
|
|
23
|
+
padding: 12px;
|
|
24
|
+
border: 1px solid #d1d5db;
|
|
25
|
+
border-radius: 8px;
|
|
26
|
+
font-size: 14px;
|
|
27
|
+
font-family: inherit;
|
|
28
|
+
resize: vertical;
|
|
29
|
+
transition: border-color 0.2s;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.textarea:focus {
|
|
34
|
+
outline: none;
|
|
35
|
+
border-color: #3b82f6;
|
|
36
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.textarea:disabled {
|
|
40
|
+
background: #f3f4f6;
|
|
41
|
+
cursor: not-allowed;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.buttonGroup {
|
|
45
|
+
display: flex;
|
|
46
|
+
gap: 8px;
|
|
47
|
+
margin-top: 12px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.button {
|
|
51
|
+
flex: 1;
|
|
52
|
+
padding: 10px 16px;
|
|
53
|
+
border-radius: 8px;
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
font-weight: 500;
|
|
56
|
+
font-family: inherit;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
transition: all 0.2s;
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
gap: 8px;
|
|
63
|
+
border: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.button:disabled {
|
|
67
|
+
opacity: 0.5;
|
|
68
|
+
cursor: not-allowed;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.primaryButton {
|
|
72
|
+
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
|
73
|
+
color: white;
|
|
74
|
+
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.primaryButton:hover:not(:disabled) {
|
|
78
|
+
transform: translateY(-1px);
|
|
79
|
+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.secondaryButton {
|
|
83
|
+
background: white;
|
|
84
|
+
color: #3b82f6;
|
|
85
|
+
border: 1px solid #3b82f6;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.secondaryButton:hover:not(:disabled) {
|
|
89
|
+
background: #eff6ff;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.icon {
|
|
93
|
+
font-size: 16px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.spinner {
|
|
97
|
+
width: 14px;
|
|
98
|
+
height: 14px;
|
|
99
|
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
100
|
+
border-top-color: white;
|
|
101
|
+
border-radius: 50%;
|
|
102
|
+
animation: spin 0.6s linear infinite;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@keyframes spin {
|
|
106
|
+
to { transform: rotate(360deg); }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.error {
|
|
110
|
+
margin-top: 12px;
|
|
111
|
+
padding: 12px;
|
|
112
|
+
background: #fee2e2;
|
|
113
|
+
border: 1px solid #fecaca;
|
|
114
|
+
border-radius: 8px;
|
|
115
|
+
color: #dc2626;
|
|
116
|
+
font-size: 14px;
|
|
117
|
+
display: flex;
|
|
118
|
+
align-items: flex-start;
|
|
119
|
+
gap: 8px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.errorIcon {
|
|
123
|
+
flex-shrink: 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.sectionTitle {
|
|
127
|
+
font-size: 14px;
|
|
128
|
+
font-weight: 600;
|
|
129
|
+
color: #1f2937;
|
|
130
|
+
margin: 0 0 12px 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.suggestions {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-wrap: wrap;
|
|
136
|
+
gap: 8px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.suggestion {
|
|
140
|
+
padding: 6px 12px;
|
|
141
|
+
background: #f3f4f6;
|
|
142
|
+
border: 1px solid #e5e7eb;
|
|
143
|
+
border-radius: 6px;
|
|
144
|
+
font-size: 13px;
|
|
145
|
+
color: #4b5563;
|
|
146
|
+
cursor: pointer;
|
|
147
|
+
transition: all 0.2s;
|
|
148
|
+
font-family: inherit;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.suggestion:hover {
|
|
152
|
+
background: #e5e7eb;
|
|
153
|
+
color: #1f2937;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.tips {
|
|
157
|
+
margin: 0;
|
|
158
|
+
padding-left: 20px;
|
|
159
|
+
color: #6b7280;
|
|
160
|
+
font-size: 13px;
|
|
161
|
+
line-height: 1.6;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.tips li {
|
|
165
|
+
margin-bottom: 6px;
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../../playground/components/Canvas/Canvas.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAyC,MAAM,OAAO,CAAC;AAO9D,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CA6HxC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Canvas - Main rendering surface for visual components
|
|
4
|
+
*/
|
|
5
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
6
|
+
import { usePlaygroundStore } from '../../store/playgroundStore';
|
|
7
|
+
import { DropZone } from '../DropZone/DropZone';
|
|
8
|
+
import { DraggableComponent } from './DraggableComponent';
|
|
9
|
+
import styles from './Canvas.module.css';
|
|
10
|
+
export const Canvas = ({ onReady }) => {
|
|
11
|
+
const canvasRef = useRef(null);
|
|
12
|
+
const { components, rootId, selectedIds, hoveredId, canvasZoom, canvasOffset, showGrid, gridSize, mode, selectComponent, deselectAll, setHoveredComponent } = usePlaygroundStore();
|
|
13
|
+
// Notify when canvas is ready
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
onReady?.();
|
|
16
|
+
}, [onReady]);
|
|
17
|
+
// Handle canvas click for deselection
|
|
18
|
+
const handleCanvasClick = useCallback((e) => {
|
|
19
|
+
// Only deselect if clicking directly on canvas
|
|
20
|
+
if (e.target === e.currentTarget) {
|
|
21
|
+
deselectAll();
|
|
22
|
+
}
|
|
23
|
+
}, [deselectAll]);
|
|
24
|
+
// Handle keyboard shortcuts
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const handleKeyDown = (e) => {
|
|
27
|
+
// Delete selected components
|
|
28
|
+
if ((e.key === 'Delete' || e.key === 'Backspace') && selectedIds.size > 0) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
// Implementation would go here
|
|
31
|
+
}
|
|
32
|
+
// Select all
|
|
33
|
+
if (e.metaKey && e.key === 'a') {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
// Implementation would go here
|
|
36
|
+
}
|
|
37
|
+
// Deselect all
|
|
38
|
+
if (e.key === 'Escape') {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
deselectAll();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
44
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
45
|
+
}, [selectedIds, deselectAll]);
|
|
46
|
+
// Get root component
|
|
47
|
+
const rootComponent = components.get(rootId);
|
|
48
|
+
if (!rootComponent) {
|
|
49
|
+
return (_jsx("div", { className: styles.canvas, children: _jsxs("div", { className: styles.emptyState, children: [_jsx("p", { children: "No components to display" }), _jsx("p", { className: styles.hint, children: "Use the AI Assistant to generate a layout or drag components from the palette" })] }) }));
|
|
50
|
+
}
|
|
51
|
+
return (_jsx("div", { ref: canvasRef, className: styles.canvas, onClick: handleCanvasClick, "data-mode": mode, "data-canvas": true, children: _jsxs("div", { className: styles.viewport, style: {
|
|
52
|
+
transform: `scale(${canvasZoom}) translate(${canvasOffset.x}px, ${canvasOffset.y}px)`,
|
|
53
|
+
transformOrigin: 'top left'
|
|
54
|
+
}, children: [showGrid && (_jsx("div", { className: styles.grid, style: {
|
|
55
|
+
backgroundSize: `${gridSize}px ${gridSize}px`
|
|
56
|
+
} })), _jsx("div", { className: styles.componentContainer, children: _jsx(DropZone, { id: "root-drop-zone", componentId: rootId, accepts: ['all'], showIndicator: mode === 'edit', children: _jsx(DraggableComponent, { component: rootComponent, isRoot: true, isSelected: selectedIds.has(rootId), isHovered: hoveredId === rootId, onSelect: (id) => selectComponent(id), onHover: (id) => setHoveredComponent(id) }) }) }), selectedIds.size > 0 && (_jsx("div", { className: styles.selectionOverlay }))] }) }));
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=Canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../../../../playground/components/Canvas/Canvas.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,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M,EACnB,OAAO,EAAE,CAAC,KAAK,CAAC,EAChB,aAAa,EAAE,IAAI,KAAK,MAAM,YAE9B,KAAC,kBAAkB,IACjB,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,IAAI,EACZ,UAAU,EAAE,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EACnC,SAAS,EAAE,SAAS,KAAK,MAAM,EAC/B,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,EACrC,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,mBAAmB,CAAC,EAAE,CAAC,GACxC,GACO,GACP,EAGL,WAAW,CAAC,IAAI,GAAG,CAAC,IAAI,CACvB,cAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,GAEjC,CACP,IACG,GACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/* Canvas styles */
|
|
2
|
+
|
|
3
|
+
.canvas {
|
|
4
|
+
flex: 1;
|
|
5
|
+
position: relative;
|
|
6
|
+
background: #fafafa;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
height: 100%;
|
|
9
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.viewport {
|
|
13
|
+
width: 100%;
|
|
14
|
+
height: 100%;
|
|
15
|
+
position: relative;
|
|
16
|
+
transition: transform 0.2s ease-out;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.grid {
|
|
20
|
+
position: absolute;
|
|
21
|
+
top: 0;
|
|
22
|
+
left: 0;
|
|
23
|
+
right: 0;
|
|
24
|
+
bottom: 0;
|
|
25
|
+
background-image:
|
|
26
|
+
linear-gradient(0deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
|
|
27
|
+
linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
|
|
28
|
+
background-size: 8px 8px;
|
|
29
|
+
pointer-events: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.componentContainer {
|
|
33
|
+
position: relative;
|
|
34
|
+
width: 100%;
|
|
35
|
+
min-height: 100vh;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.component {
|
|
39
|
+
position: relative;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
transition: outline 0.2s ease;
|
|
42
|
+
font-family: inherit;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.component:hover {
|
|
46
|
+
outline: 1px solid #93c5fd;
|
|
47
|
+
outline-offset: 2px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.component.selected {
|
|
51
|
+
outline: 2px solid #3b82f6;
|
|
52
|
+
outline-offset: 2px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.component.hovered {
|
|
56
|
+
outline: 1px dashed #60a5fa;
|
|
57
|
+
outline-offset: 2px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.component.root {
|
|
61
|
+
cursor: default;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.emptyState {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
height: 100%;
|
|
70
|
+
color: #6b7280;
|
|
71
|
+
text-align: center;
|
|
72
|
+
padding: 32px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.emptyState p {
|
|
76
|
+
margin: 8px 0;
|
|
77
|
+
font-size: 16px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.emptyState .hint {
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
color: #9ca3af;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.selectionOverlay {
|
|
86
|
+
position: absolute;
|
|
87
|
+
top: 0;
|
|
88
|
+
left: 0;
|
|
89
|
+
right: 0;
|
|
90
|
+
bottom: 0;
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Mode-specific styles */
|
|
95
|
+
.canvas[data-mode="view"] .component {
|
|
96
|
+
cursor: default;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.canvas[data-mode="view"] .component:hover {
|
|
100
|
+
outline: none;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Helper component indicators */
|
|
104
|
+
[data-helper] {
|
|
105
|
+
position: relative;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[data-helper]::before {
|
|
109
|
+
content: attr(data-helper);
|
|
110
|
+
position: absolute;
|
|
111
|
+
top: 2px;
|
|
112
|
+
right: 2px;
|
|
113
|
+
font-size: 10px;
|
|
114
|
+
color: #9ca3af;
|
|
115
|
+
background: rgba(255, 255, 255, 0.9);
|
|
116
|
+
padding: 2px 4px;
|
|
117
|
+
border-radius: 2px;
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
z-index: 1;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Draggable Component */
|
|
123
|
+
.draggableComponent {
|
|
124
|
+
position: relative;
|
|
125
|
+
cursor: move;
|
|
126
|
+
transition: opacity 0.2s;
|
|
127
|
+
font-family: inherit;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.draggableComponent.root {
|
|
131
|
+
cursor: default;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.draggableComponent.dragging {
|
|
135
|
+
opacity: 0.5;
|
|
136
|
+
cursor: grabbing;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.draggableComponent.selected {
|
|
140
|
+
outline: 2px solid #3b82f6;
|
|
141
|
+
outline-offset: 2px;
|
|
142
|
+
position: relative;
|
|
143
|
+
z-index: 10;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.draggableComponent.hovered {
|
|
147
|
+
outline: 1px dashed #93c5fd;
|
|
148
|
+
outline-offset: 2px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.componentChildren {
|
|
152
|
+
position: relative;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.childWrapper {
|
|
156
|
+
position: relative;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* Insertion zones for drag and drop */
|
|
160
|
+
.insertionZone {
|
|
161
|
+
min-height: 4px;
|
|
162
|
+
transition: all 0.2s;
|
|
163
|
+
position: relative;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.insertionZone.active {
|
|
167
|
+
min-height: 24px;
|
|
168
|
+
background: rgba(59, 130, 246, 0.1);
|
|
169
|
+
border: 2px dashed #3b82f6;
|
|
170
|
+
border-radius: 4px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Drag ghost */
|
|
174
|
+
.dragGhost {
|
|
175
|
+
pointer-events: none;
|
|
176
|
+
opacity: 0.8;
|
|
177
|
+
transform: scale(1.05);
|
|
178
|
+
filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.newComponentGhost {
|
|
182
|
+
padding: 12px 24px;
|
|
183
|
+
background: white;
|
|
184
|
+
border: 2px solid #3b82f6;
|
|
185
|
+
border-radius: 8px;
|
|
186
|
+
font-weight: 500;
|
|
187
|
+
color: #3b82f6;
|
|
188
|
+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
|
|
189
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CanvasWithDnd - Canvas with drag and drop support
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export interface CanvasWithDndProps {
|
|
6
|
+
onReady?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const CanvasWithDnd: React.FC<CanvasWithDndProps>;
|
|
9
|
+
//# sourceMappingURL=CanvasWithDnd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasWithDnd.d.ts","sourceRoot":"","sources":["../../../../playground/components/Canvas/CanvasWithDnd.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAkD,MAAM,OAAO,CAAC;AAyBvE,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsQtD,CAAC"}
|