Skip to content
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

request node and window bar #1424

Open
wants to merge 3 commits into
base: behave-graph
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,8 @@ export const Composer = ({ tab, theme, spellId }) => {
setApi(event.api)
}

useEffect(() => {
if (!api) return

const unsubscribe = subscribe(events.$CREATE_TEXT_EDITOR(tab.id), () => {
const windowBarMap = {
[events.$CREATE_TEXT_EDITOR(tab.id)]: () => {
api.addPanel({
id: 'Text Editor',
component: 'TextEditor',
Expand All @@ -232,18 +230,63 @@ export const Composer = ({ tab, theme, spellId }) => {
tab,
spellId
},
position: { referencePanel: 'Composer', direction: 'left' },
})
},
[events.$CREATE_INSPECTOR(tab.id)]: () => {
api.addPanel({
id: 'Inspector',
component: 'Inspector',
params: {
title: 'Inspector',
tab,
spellId
},
position: { referencePanel: 'Composer', direction: 'left' },
})
},
[events.$CREATE_PLAYTEST(tab.id)]: () => {
api.addPanel({
id: 'Playtest',
component: 'Playtest',
params: {
title: 'Playtest',
tab,
spellId
},
position: { referencePanel: 'Composer', direction: 'below' },
})
},
[events.$CREATE_CONSOLE(tab.id)]: () => {
api.addPanel({
id: 'Console',
component: 'Console',
params: {
title: 'Console',
tab,
spellId
},
position: { referencePanel: 'Composer', direction: 'below' },
})
},
}

useEffect(() => {
if (!api) return

const windowBarSubscriptions = Object.entries(windowBarMap).map(([event, handler]) => {
return subscribe(event, handler)
})

console.log('Setting up layout change listener')
api.onDidLayoutChange(() => {
const layout = api.toJSON()

saveLayoutToLocalStorage(spellId, layout)
})

return () => {
unsubscribe()
windowBarSubscriptions.forEach(unsubscribe => {
unsubscribe()
})
}
}, [api])

Expand Down
77 changes: 52 additions & 25 deletions packages/client/editor/src/components/workspaces/composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,61 @@ import { Tab, useDockviewTheme } from 'client/state';
import { usePubSub } from '@magickml/providers';
import { Composer } from './composer';

const DraggableElement = (props) => (
<p
tabIndex={-1}
onDragStart={(event) => {
if (event.dataTransfer) {
event.dataTransfer.effectAllowed = 'move';
const DraggableElement = (props) => {
const { tab } = props.params
const { publish, events } = usePubSub()
const windows = {
'Console': () => {
publish(events.$CREATE_CONSOLE(tab.id))
},
'TextEditor': () => {
publish(events.$CREATE_TEXT_EDITOR(tab.id))
},
'Inspector': () => {
publish(events.$CREATE_INSPECTOR(tab.id))
},
'Playtest': () => {
publish(events.$CREATE_PLAYTEST(tab.id))
}
}

event.dataTransfer.setData('text/plain', 'nothing');
event.dataTransfer.setData('component', props.window)
event.dataTransfer.setData('title', props.title)
}
}}
style={{
padding: '8px',
color: 'white',
cursor: 'pointer',
}}
draggable={true}
>
{props.window}
</p>
);
const handleClick = () => {
windows[props.window]()
}

return (
<p
tabIndex={-1}
onDragStart={(event) => {
if (event.dataTransfer) {
event.dataTransfer.effectAllowed = 'move';

event.dataTransfer.setData('text/plain', 'nothing');
event.dataTransfer.setData('component', props.window)
event.dataTransfer.setData('title', props.title)
}
}}
style={{
padding: '8px',
color: 'white',
cursor: 'pointer',
}}
draggable={true}
onClick={handleClick}
>
{props.window}
</p>
)
};

const composerLayoutComponents = {
WindowBar: (props: IGridviewPanelProps<{ title: string }>) => {
return (
<div style={{ width: '100%', display: 'inline-flex', justifyContent: 'flex-end', flexDirection: 'row', gap: '8px', padding: "0 16px" }}>
<DraggableElement window="Console" />
<DraggableElement window="TextEditor" title="Text Editor" />
<DraggableElement window="Inspector" />
<DraggableElement window="Playtest" />
<DraggableElement window="Console" {...props} />
<DraggableElement window="TextEditor" title="Text Editor" {...props} />
<DraggableElement window="Inspector" {...props} />
<DraggableElement window="Playtest" {...props} />
</div>
)
},
Expand All @@ -53,6 +77,9 @@ const ComposerContainer = (props: IGridviewPanelProps<{ tab: Tab; theme: string,
component: 'WindowBar',
maximumHeight: 30,
minimumHeight: 30,
params: {
...props.params
}
})

event.api.addPanel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ export const Composer = ({ tab, theme, spellId }) => {
setApi(event.api)
}

useEffect(() => {
if (!api) return

const unsubscribe = subscribe(events.$CREATE_TEXT_EDITOR(tab.id), () => {
const windowBarMap = {
[events.$CREATE_TEXT_EDITOR(tab.id)]: () => {
api.addPanel({
id: 'Text Editor',
component: 'TextEditor',
Expand All @@ -169,7 +167,52 @@ export const Composer = ({ tab, theme, spellId }) => {
tab,
spellId
},
position: { referencePanel: 'Graph', direction: 'left' },
})
},
[events.$CREATE_INSPECTOR(tab.id)]: () => {
api.addPanel({
id: 'Inspector',
component: 'Inspector',
params: {
title: 'Inspector',
tab,
spellId
},
position: { referencePanel: 'Graph', direction: 'left' },
})
},
[events.$CREATE_PLAYTEST(tab.id)]: () => {
api.addPanel({
id: 'Chat',
component: 'Chat',
params: {
title: 'Chat',
tab,
spellId
},
position: { referencePanel: 'Graph', direction: 'below' },
})
},
[events.$CREATE_CONSOLE(tab.id)]: () => {
api.addPanel({
id: 'Console',
component: 'Console',
params: {
title: 'Console',
tab,
spellId
},
position: { referencePanel: 'Graph', direction: 'below' },
})
},
}

useEffect(() => {
if (!api) return

const windowBarSubscriptions = Object.entries(windowBarMap).map(([event, handler]) => {
return subscribe(event, handler)
})

api.onDidLayoutChange(() => {
Expand All @@ -179,7 +222,9 @@ export const Composer = ({ tab, theme, spellId }) => {
})

return () => {
unsubscribe()
windowBarSubscriptions.forEach(unsubscribe => {
unsubscribe()
})
}
}, [api])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
import { GridviewReact, IGridviewPanelProps, Orientation } from 'dockview';
import WorkspaceProvider from '../../../contexts/WorkspaceProvider'
import { Tab, createStore, injectReducer, tabReducer, useDockviewTheme } from 'client/state';
import { Tab, useDockviewTheme } from 'client/state';
import { usePubSub } from '@magickml/providers';
import { Composer } from './composer';
import { useEffect } from 'react';

const DraggableElement = (props) => (
<p
tabIndex={-1}
onDragStart={(event) => {
if (event.dataTransfer) {
event.dataTransfer.effectAllowed = 'move';

event.dataTransfer.setData('text/plain', 'nothing');
event.dataTransfer.setData('component', props.window)
event.dataTransfer.setData('title', props.title)
}
}}
style={{
padding: '8px',
color: 'white',
cursor: 'pointer',
}}
draggable={true}
>
{props.window}
</p>
);
const DraggableElement = (props) => {
const { tab } = props.params
const { publish, events } = usePubSub()
const windows = {
'Console': () => {
publish(events.$CREATE_CONSOLE(tab.id))
},
'TextEditor': () => {
publish(events.$CREATE_TEXT_EDITOR(tab.id))
},
'Inspector': () => {
publish(events.$CREATE_INSPECTOR(tab.id))
},
'Playtest': () => {
publish(events.$CREATE_PLAYTEST(tab.id))
}
}

const handleClick = () => {
windows[props.window]()
}

return (
<p
tabIndex={-1}
onDragStart={(event) => {
if (event.dataTransfer) {
event.dataTransfer.effectAllowed = 'move';

event.dataTransfer.setData('text/plain', 'nothing');
event.dataTransfer.setData('component', props.window)
event.dataTransfer.setData('title', props.title)
}
}}
onClick={handleClick}
style={{
padding: '8px',
color: 'white',
cursor: 'pointer',
}}
draggable={true}
>
{props.window}
</p>
)
};

const composerLayoutComponents = {
WindowBar: (props: IGridviewPanelProps<{ title: string }>) => {
return (
<div>
<div style={{ width: '100%', display: 'inline-flex', justifyContent: 'flex-end', flexDirection: 'row', gap: '8px', padding: "0 16px" }}>
<p style={{ padding: 8, color: 'grey', marginRight: 50 }}>Composer V2</p>
<DraggableElement window="Console" />
<DraggableElement window="TextEditor" title="Text Editor" />
<DraggableElement window="Inspector" />
<DraggableElement window="Playtest" />
<DraggableElement window="Console" {...props} />
<DraggableElement window="TextEditor" title="Text Editor" {...props} />
<DraggableElement window="Inspector" {...props} />
<DraggableElement window="Playtest" {...props} />
</div>
</div >
)
Expand All @@ -48,7 +72,6 @@ const composerLayoutComponents = {
}

const ComposerContainer = (props: IGridviewPanelProps<{ tab: Tab; theme: string, spellId: string }>) => {
const { tab } = props.params
const { theme } = useDockviewTheme()
const pubSub = usePubSub()

Expand All @@ -58,6 +81,9 @@ const ComposerContainer = (props: IGridviewPanelProps<{ tab: Tab; theme: string,
component: 'WindowBar',
maximumHeight: 30,
minimumHeight: 30,
params: {
...props.params
}
})

event.api.addPanel({
Expand Down
Loading
Loading