-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(playground): dummy workspace inside playground #361
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
modules/code-builder/playground/pages/WorkSpace/data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
import { | ||
ModelBrickBlock, | ||
ModelBrickData, | ||
ModelBrickExpression, | ||
ModelBrickStatement, | ||
} from '@/brick'; | ||
import type { TBrickType, TBrickCoords, TBrickArgDataType } from '@/@types/brick'; | ||
|
||
type InstanceMap = { | ||
data: ModelBrickData; | ||
expression: ModelBrickExpression; | ||
statement: ModelBrickStatement; | ||
block: ModelBrickBlock; | ||
}; | ||
|
||
export type Brick = { | ||
id: string; | ||
type: TBrickType; | ||
instance: InstanceMap[TBrickType]; | ||
coords: TBrickCoords; | ||
children?: Brick[]; | ||
}; | ||
|
||
export const WORKSPACES_DATA: { id: string; data: Brick[] }[] = [ | ||
{ | ||
id: 'workspace1', | ||
data: [ | ||
{ | ||
id: '1', | ||
type: 'block', | ||
instance: new ModelBrickBlock({ | ||
label: 'Block', | ||
args: Object.fromEntries( | ||
[].map< | ||
[string, { label: string; dataType: TBrickArgDataType; meta: unknown }] | ||
>((name) => [name, { label: name, dataType: 'any', meta: undefined }]), | ||
), | ||
colorBg: 'yellow', | ||
colorFg: 'black', | ||
outline: 'red', | ||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
nestLengthY: 125, | ||
}), | ||
coords: { x: 50, y: 50 }, | ||
children: [ | ||
{ | ||
id: '2', | ||
type: 'statement', | ||
instance: new ModelBrickStatement({ | ||
label: 'Statement', | ||
args: Object.fromEntries( | ||
[].map< | ||
[ | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
}, | ||
] | ||
>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg: 'lightblue', | ||
colorFg: 'black', | ||
outline: 'blue', | ||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
}), | ||
coords: { x: 68, y: 92 }, | ||
}, | ||
{ | ||
id: '3', | ||
type: 'statement', | ||
instance: new ModelBrickStatement({ | ||
label: 'Statement', | ||
args: Object.fromEntries( | ||
[].map< | ||
[ | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
}, | ||
] | ||
>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg: 'lightgreen', | ||
colorFg: 'black', | ||
outline: 'green', | ||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
}), | ||
coords: { x: 68, y: 134 }, | ||
}, | ||
{ | ||
id: '4', | ||
type: 'block', | ||
instance: new ModelBrickBlock({ | ||
label: 'Block', | ||
args: Object.fromEntries( | ||
[].map< | ||
[ | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
}, | ||
] | ||
>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg: 'orange', | ||
colorFg: 'black', | ||
outline: 'grey', | ||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
nestLengthY: 17, | ||
}), | ||
coords: { x: 68, y: 176 }, | ||
children: [ | ||
{ | ||
id: '5', | ||
type: 'statement', | ||
instance: new ModelBrickStatement({ | ||
label: 'Statement', | ||
args: Object.fromEntries( | ||
[].map< | ||
[ | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
}, | ||
] | ||
>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg: 'lightpink', | ||
colorFg: 'black', | ||
outline: 'deeppink', | ||
|
||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
}), | ||
coords: { x: 86, y: 218 }, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '6', | ||
type: 'statement', | ||
instance: new ModelBrickStatement({ | ||
label: 'Statement', | ||
args: Object.fromEntries( | ||
[].map< | ||
[ | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
}, | ||
] | ||
>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg: 'lightgreen', | ||
colorFg: 'black', | ||
outline: 'green', | ||
scale: 2, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
}), | ||
coords: { x: 68, y: 302 }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
BrickBlock, | ||
BrickData, | ||
BrickExpression, | ||
BrickStatement, | ||
ModelBrickBlock, | ||
ModelBrickData, | ||
ModelBrickExpression, | ||
ModelBrickStatement, | ||
} from '@/brick'; | ||
import { WORKSPACES_DATA } from './data'; | ||
import type { TBrickCoords, TBrickType } from '@/@types/brick'; | ||
import type { Brick } from './data'; | ||
|
||
function getBrick( | ||
type: TBrickType, | ||
instance: ModelBrickBlock | ModelBrickData | ModelBrickExpression | ModelBrickStatement, | ||
coords: TBrickCoords, | ||
) { | ||
switch (type) { | ||
case 'data': | ||
return <BrickData instance={instance as ModelBrickData} coords={coords} />; | ||
case 'expression': | ||
return <BrickExpression instance={instance as ModelBrickExpression} coords={coords} />; | ||
case 'statement': | ||
return <BrickStatement instance={instance as ModelBrickStatement} coords={coords} />; | ||
case 'block': | ||
return <BrickBlock instance={instance as ModelBrickBlock} coords={coords} />; | ||
default: | ||
return <></>; | ||
} | ||
} | ||
|
||
function RenderBricks({ brickData }: { brickData: Brick }) { | ||
return ( | ||
<> | ||
{getBrick(brickData.type, brickData.instance, brickData.coords)} | ||
{brickData.children && | ||
brickData.children?.length > 0 && | ||
brickData.children.map((child) => <RenderBricks key={child.id} brickData={child} />)} | ||
</> | ||
); | ||
} | ||
|
||
function WorkSpace() { | ||
return ( | ||
<div> | ||
{WORKSPACES_DATA.map((workspace) => ( | ||
<svg | ||
version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
key={workspace.id} | ||
height="500px" | ||
width="500px" | ||
> | ||
{workspace.data.map((brick) => { | ||
return <RenderBricks key={brick.id} brickData={brick} />; | ||
})} | ||
</svg> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default WorkSpace; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
modules/code-builder/src/brick/design0/components/BrickBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
modules/code-builder/src/brick/design0/components/BrickData.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
modules/code-builder/src/brick/design0/components/BrickExpression.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious where the number 17 comes from?