import type { Meta, StoryObj } from '@storybook/react'; import { useState } from 'react'; import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; import { WorkspaceFactory } from '@adaptive-desktop/adaptive-workspace'; import { WorkspaceView } from './WorkspaceView'; import { Panel } from '..'; import { loadDesktopSnapshot } from '@adaptive-desktop/adaptive-workspace'; import { idGenerator } from '../../utils'; const meta: Meta = { title: 'Components/WorkspaceView', component: WorkspaceView, parameters: { layout: 'fullscreen', }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { workspace: (() => { const snapshot = loadDesktopSnapshot(); const context = snapshot.workspaceContexts[0]; const factory = new WorkspaceFactory(idGenerator); return factory.fromSnapshot(snapshot, context.maxScreenBounds); })(), style: { backgroundColor: '#808080', }, }, }; // Interactive story that demonstrates updateScreenPosition const DynamicWorkspaceDemo = () => { const [workspace] = useState(() => { const snapshot = loadDesktopSnapshot(); // Use the 'laptop' context for a smaller workspace const context = snapshot.workspaceContexts.find(ctx => ctx.id === 'laptop') || snapshot.workspaceContexts[0]; const factory = new WorkspaceFactory(idGenerator); return factory.fromSnapshot(snapshot, context.maxScreenBounds); }); const [, forceUpdate] = useState({}); const updatePosition = ( x: number, y: number, width: number, height: number ) => { workspace.setScreenBounds({ x, y, width, height }); forceUpdate({}); // Force re-render to show changes }; return ( Workspace Position Demo updatePosition(50, 50, 600, 400)} > Top Left updatePosition(200, 50, 600, 400)} > Top Right updatePosition(50, 200, 600, 400)} > Bottom Left updatePosition(100, 100, 400, 300)} > Bottom Right updatePosition(25, 25, 750, 500)} > Large Workspace ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f0f0f0', padding: 20, }, controls: { backgroundColor: '#ffffff', padding: 15, borderRadius: 8, marginBottom: 20, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 3, }, title: { fontSize: 18, fontWeight: 'bold', marginBottom: 15, textAlign: 'center', }, buttonRow: { flexDirection: 'row', justifyContent: 'space-around', marginBottom: 10, }, button: { backgroundColor: '#007ACC', paddingHorizontal: 15, paddingVertical: 10, borderRadius: 5, minWidth: 100, }, largeButton: { alignSelf: 'center', minWidth: 150, }, buttonText: { color: '#ffffff', textAlign: 'center', fontWeight: '600', }, workspace: { backgroundColor: '#808080', }, }); export const HalfWorkspace: Story = { render: () => { const snapshot = loadDesktopSnapshot(); const context = snapshot.workspaceContexts[0]; const factory = new WorkspaceFactory(idGenerator); const workspace = factory.fromSnapshot(snapshot, context.maxScreenBounds); // Use the first viewport from the snapshot const viewport = workspace.viewports.values().next().value; if (!viewport) { return ( No viewport found in snapshot. ); } return ( Half Workspace Demo Workspace (gray) with viewport (blue) taking up left half workspace.removeViewport(viewport.id)} onSplit={dir => workspace.splitViewport(viewport.id, dir)} > Panel Content ID: {viewport.id.slice(-6)} Size: {viewport.screenBounds.width} ×{' '} {viewport.screenBounds.height} 50% of workspace width ); }, }; const halfWorkspaceStyles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f0f0f0', padding: 20, }, title: { fontSize: 20, fontWeight: 'bold', marginBottom: 8, textAlign: 'center', color: '#333', }, description: { fontSize: 14, color: '#666', textAlign: 'center', marginBottom: 20, }, workspaceContainer: { width: 800, height: 600, backgroundColor: '#808080', // Gray workspace background borderWidth: 2, borderColor: '#666', position: 'relative', alignSelf: 'center', }, viewport: { position: 'absolute', backgroundColor: '#3b82f6', // Blue viewport background borderWidth: 2, borderColor: '#1d4ed8', borderRadius: 4, }, viewportContent: { flex: 1, padding: 16, justifyContent: 'center', alignItems: 'center', }, viewportTitle: { color: '#ffffff', fontSize: 18, fontWeight: 'bold', marginBottom: 8, textAlign: 'center', }, viewportText: { color: '#e5e7eb', fontSize: 12, textAlign: 'center', marginBottom: 2, }, }); export const DynamicPosition: Story = { render: () => , };