|
1 | 1 | import Box from '@mui/material/Box' |
| 2 | +import SIDEAppBar from 'browser/components/AppBar' |
| 3 | +import SIDEDrawer from 'browser/components/Drawer' |
| 4 | +import Main from 'browser/components/Main' |
| 5 | +import { context } from 'browser/contexts/show-drawer' |
| 6 | +import { PROJECT_TAB, TAB } from 'browser/enums/tab' |
| 7 | +import { usePanelGroup } from 'browser/hooks/usePanelGroup' |
2 | 8 | import React, { useContext } from 'react' |
3 | 9 | import { DndProvider } from 'react-dnd' |
4 | 10 | import { HTML5Backend } from 'react-dnd-html5-backend' |
5 | | -import Main from '../Main' |
6 | | -import { SIDEMainProps } from '../types' |
7 | | -import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels' |
8 | | -import SIDEDrawer from '../Drawer' |
9 | | -import { usePanelGroup } from 'browser/hooks/usePanelGroup' |
10 | | -import SIDEAppBar from '../AppBar' |
11 | | -import { context } from 'browser/contexts/show-drawer' |
| 11 | +import { Panel, PanelGroup } from 'react-resizable-panels' |
| 12 | +import ResizeHandle from '../ResizeHandle' |
12 | 13 |
|
13 | | -const ProjectEditor: React.FC<Pick<SIDEMainProps, 'setTab' | 'tab'>> = ({ |
14 | | - setTab, |
15 | | - tab, |
16 | | -}) => { |
| 14 | +export type PluginWindow = { |
| 15 | + name: string |
| 16 | + url: string |
| 17 | +} |
| 18 | + |
| 19 | +const ProjectEditor: React.FC = () => { |
| 20 | + const [tab, setTab] = React.useState<TAB>(PROJECT_TAB) |
17 | 21 | const showDrawer = useContext(context) |
| 22 | + const [pluginWindows, setPluginWindows] = React.useState<PluginWindow[]>([]) |
| 23 | + React.useEffect(() => { |
| 24 | + const handler = (name: string, url: string) => { |
| 25 | + setPluginWindows((prev) => prev.concat({ name, url })) |
| 26 | + } |
| 27 | + window.sideAPI.plugins.onRequestCustomEditorPanel.addListener(handler) |
| 28 | + return () => { |
| 29 | + window.sideAPI.plugins.onRequestCustomEditorPanel.removeListener(handler) |
| 30 | + } |
| 31 | + }, []) |
18 | 32 | return ( |
19 | 33 | <DndProvider backend={HTML5Backend}> |
20 | | - <div className="flex flex-col height-100 pb-1 ps-1 pt-5 window-drag"> |
| 34 | + <div className="flex flex-col height-100 pb-1 ps-1 pt-6 window-drag"> |
21 | 35 | <div className="flex-initial no-window-drag"> |
22 | 36 | <SIDEAppBar setTab={setTab} tab={tab} /> |
23 | 37 | </div> |
24 | | - <div className="flex-1 no-window-drag"> |
25 | | - <PanelGroup |
26 | | - direction="horizontal" |
27 | | - id="drawer-editor" |
28 | | - {...usePanelGroup('drawer-editor', !showDrawer)} |
29 | | - > |
30 | | - {showDrawer && ( |
31 | | - <> |
32 | | - <Panel |
33 | | - collapsible |
34 | | - id="editor-drawer" |
35 | | - defaultSize={25} |
36 | | - order={1} |
37 | | - > |
38 | | - <SIDEDrawer tab={tab} /> |
| 38 | + <PanelGroup direction="vertical" id="plugin-windows"> |
| 39 | + <Panel defaultSize={100} id="plugin-windows-panel"> |
| 40 | + <div className="flex-col flex-1 height-100 no-window-drag"> |
| 41 | + <PanelGroup |
| 42 | + direction="horizontal" |
| 43 | + id="drawer-editor" |
| 44 | + {...usePanelGroup('drawer-editor', !showDrawer)} |
| 45 | + > |
| 46 | + {showDrawer && ( |
| 47 | + <> |
| 48 | + <Panel |
| 49 | + collapsible |
| 50 | + id="editor-drawer" |
| 51 | + defaultSize={25} |
| 52 | + order={1} |
| 53 | + > |
| 54 | + <SIDEDrawer tab={tab} /> |
| 55 | + </Panel> |
| 56 | + <ResizeHandle id="h-resize-1" y /> |
| 57 | + </> |
| 58 | + )} |
| 59 | + <Panel defaultSize={75} id="editor-panel" order={2}> |
| 60 | + <Box className="fill flex flex-col"> |
| 61 | + <Main setTab={setTab} tab={tab} /> |
| 62 | + </Box> |
39 | 63 | </Panel> |
40 | | - <PanelResizeHandle className="resize-bar" id="h-resize-1" /> |
41 | | - </> |
42 | | - )} |
43 | | - <Panel defaultSize={75} id="editor-panel" order={2}> |
44 | | - <Box className="fill flex flex-col"> |
45 | | - <Main setTab={setTab} tab={tab} /> |
46 | | - </Box> |
47 | | - </Panel> |
48 | | - </PanelGroup> |
49 | | - </div> |
| 64 | + </PanelGroup> |
| 65 | + </div> |
| 66 | + </Panel> |
| 67 | + {pluginWindows.map((pluginWindow, index) => ( |
| 68 | + <React.Fragment key={index}> |
| 69 | + <ResizeHandle id={`v-resize-${index}`} x /> |
| 70 | + <Panel key={index} id={pluginWindow.name}> |
| 71 | + <iframe |
| 72 | + className="fill" |
| 73 | + src={pluginWindow.url} |
| 74 | + title={pluginWindow.name} |
| 75 | + /> |
| 76 | + </Panel> |
| 77 | + </React.Fragment> |
| 78 | + ))} |
| 79 | + </PanelGroup> |
50 | 80 | </div> |
51 | 81 | </DndProvider> |
52 | 82 | ) |
|
0 commit comments