|
| 1 | +import React from 'react'; |
| 2 | +import type { Meta, StoryObj } from '@storybook/react'; |
| 3 | +import WorkspaceView from '../components/WorkspaceView'; |
| 4 | +import WorkspaceManager from '../../model/model'; |
| 5 | + |
| 6 | +import { |
| 7 | + createSimpleBrick, |
| 8 | + createExpressionBrick, |
| 9 | + createCompoundBrick, |
| 10 | + resetFactoryCounter, |
| 11 | +} from '../../../brick/utils/brickFactory'; |
| 12 | + |
| 13 | +const meta: Meta<typeof WorkspaceView> = { |
| 14 | + title: 'Workspace/Fixed', |
| 15 | + component: WorkspaceView, |
| 16 | +}; |
| 17 | +export default meta; |
| 18 | + |
| 19 | +type Story = StoryObj<typeof WorkspaceView>; |
| 20 | + |
| 21 | +// === Workspace Story 1: Single Tower (adapted from tree SingleBrick) === |
| 22 | +export const SingleTower: Story = { |
| 23 | + render: () => { |
| 24 | + resetFactoryCounter(); |
| 25 | + const manager = new WorkspaceManager(); |
| 26 | + const brick = createSimpleBrick(); |
| 27 | + manager.createTower(brick, { x: 100, y: 100 }); |
| 28 | + return <WorkspaceView manager={manager} />; |
| 29 | + }, |
| 30 | +}; |
| 31 | + |
| 32 | +// === Workspace Story 2: Multiple Separate Towers (adapted from tree concept) === |
| 33 | +export const MultipleTowers: Story = { |
| 34 | + render: () => { |
| 35 | + resetFactoryCounter(); |
| 36 | + const manager = new WorkspaceManager(); |
| 37 | + |
| 38 | + // Tower 1: Simple stack (like tree StackedBricks) |
| 39 | + const root1 = createSimpleBrick(); |
| 40 | + const child1 = createSimpleBrick(); |
| 41 | + const child2 = createSimpleBrick(); |
| 42 | + const tower1 = manager.createTower(root1, { x: 100, y: 100 }); |
| 43 | + tower1.addBrick(root1.uuid, child1, { x: 100, y: 130 }); |
| 44 | + tower1.addBrick(child1.uuid, child2, { x: 100, y: 160 }); |
| 45 | + |
| 46 | + // Tower 2: Arguments (like tree ArgumentBricks) |
| 47 | + const root2 = createSimpleBrick({ |
| 48 | + label: 'My Simple', |
| 49 | + bboxArgs: [ |
| 50 | + { w: 60, h: 40 }, |
| 51 | + { w: 60, h: 20 }, |
| 52 | + ], |
| 53 | + }); |
| 54 | + const arg1 = createExpressionBrick({ label: 'Expr A', bboxArgs: [{ w: 60, h: 40 }] }); |
| 55 | + const arg2 = createExpressionBrick({ label: 'Expr B', bboxArgs: [{ w: 60, h: 20 }] }); |
| 56 | + const tower2 = manager.createTower(root2, { x: 400, y: 100 }); |
| 57 | + tower2.addArgumentBrick(root2.uuid, arg1, { x: 0, y: 0 }, 0); |
| 58 | + tower2.addArgumentBrick(root2.uuid, arg2, { x: 0, y: 0 }, 1); |
| 59 | + |
| 60 | + // Tower 3: Compound with nested (like tree CompoundWithNested) |
| 61 | + const compound = createCompoundBrick({ |
| 62 | + label: 'Compound with Nested', |
| 63 | + bboxArgs: [{ w: 80, h: 40 }], |
| 64 | + }); |
| 65 | + const nested1 = createSimpleBrick(); |
| 66 | + const nested2 = createSimpleBrick(); |
| 67 | + const tower3 = manager.createTower(compound, { x: 700, y: 100 }); |
| 68 | + tower3.addNestedBrick(compound.uuid, nested1, { x: 0, y: 0 }); |
| 69 | + tower3.addNestedBrick(compound.uuid, nested2, { x: 0, y: 0 }); |
| 70 | + |
| 71 | + return <WorkspaceView manager={manager} />; |
| 72 | + }, |
| 73 | +}; |
| 74 | + |
| 75 | +// === Workspace Story 3: Full Composite Workspace (adapted from tree FullCompositeTree) === |
| 76 | +export const FullCompositeWorkspace: Story = { |
| 77 | + render: () => { |
| 78 | + resetFactoryCounter(); |
| 79 | + const manager = new WorkspaceManager(); |
| 80 | + |
| 81 | + // Tower 1: Full composite (like tree FullCompositeTree) |
| 82 | + const compound1 = createCompoundBrick({ |
| 83 | + label: 'Full Composite box with args', |
| 84 | + bboxArgs: [ |
| 85 | + { w: 100, h: 50 }, |
| 86 | + { w: 120, h: 70 }, |
| 87 | + ], |
| 88 | + }); |
| 89 | + const arg1 = createExpressionBrick({ label: 'Expr 1', bboxArgs: [{ w: 100, h: 50 }] }); |
| 90 | + const arg2 = createExpressionBrick({ label: 'Expr 2', bboxArgs: [{ w: 120, h: 70 }] }); |
| 91 | + const nested = createSimpleBrick(); |
| 92 | + const stacked = createSimpleBrick(); |
| 93 | + const tower1 = manager.createTower(compound1, { x: 100, y: 100 }); |
| 94 | + tower1.addArgumentBrick(compound1.uuid, arg1, { x: 0, y: 0 }, 0); |
| 95 | + tower1.addArgumentBrick(compound1.uuid, arg2, { x: 0, y: 0 }, 1); |
| 96 | + tower1.addNestedBrick(compound1.uuid, nested, { x: 0, y: 0 }); |
| 97 | + tower1.addBrick(compound1.uuid, stacked, { x: 100, y: 160 }); |
| 98 | + |
| 99 | + // Tower 2: Another compound |
| 100 | + const compound2 = createCompoundBrick({ |
| 101 | + label: 'Second Compound', |
| 102 | + bboxArgs: [{ w: 80, h: 40 }], |
| 103 | + }); |
| 104 | + const tower2 = manager.createTower(compound2, { x: 500, y: 200 }); |
| 105 | + tower2.addNestedBrick(compound2.uuid, createSimpleBrick(), { x: 0, y: 0 }); |
| 106 | + |
| 107 | + return <WorkspaceView manager={manager} />; |
| 108 | + }, |
| 109 | +}; |
| 110 | + |
| 111 | +// === Workspace Story 4: Argument Positioning Test (adapted from tree TestArgumentPositioning) === |
| 112 | +export const TestArgumentPositioning: Story = { |
| 113 | + render: () => { |
| 114 | + resetFactoryCounter(); |
| 115 | + const manager = new WorkspaceManager(); |
| 116 | + |
| 117 | + // Test with different label lengths |
| 118 | + const shortLabel = createCompoundBrick({ |
| 119 | + label: 'Short', |
| 120 | + bboxArgs: Array(3).fill({ w: 60, h: 20 }), |
| 121 | + }); |
| 122 | + const longLabel = createCompoundBrick({ |
| 123 | + label: 'Very Long Label That Should Push Args Further Right', |
| 124 | + bboxArgs: Array(3).fill({ w: 60, h: 20 }), |
| 125 | + }); |
| 126 | + |
| 127 | + const tower1 = manager.createTower(shortLabel, { x: 100, y: 50 }); |
| 128 | + const tower2 = manager.createTower(longLabel, { x: 100, y: 200 }); |
| 129 | + |
| 130 | + // Add argument bricks to both |
| 131 | + for (let i = 0; i < 3; i++) { |
| 132 | + const expr1 = createExpressionBrick({ label: `Arg ${i + 1}` }); |
| 133 | + const expr2 = createExpressionBrick({ label: `Arg ${i + 1}` }); |
| 134 | + tower1.addArgumentBrick(shortLabel.uuid, expr1, { x: 0, y: 0 }, i); |
| 135 | + tower2.addArgumentBrick(longLabel.uuid, expr2, { x: 0, y: 0 }, i); |
| 136 | + } |
| 137 | + |
| 138 | + return <WorkspaceView manager={manager} />; |
| 139 | + }, |
| 140 | +}; |
0 commit comments