-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-user-to-context
Signed-off-by: Jan Potoms <[email protected]>
- Loading branch information
Showing
32 changed files
with
647 additions
and
231 deletions.
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
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
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { styled } from '@mui/material'; | ||
import { StyledComponent } from '@emotion/styled'; | ||
import { styled, BoxProps } from '@mui/material'; | ||
|
||
export default styled('div')({ flex: 1 }); | ||
const FlexFill: StyledComponent<BoxProps> = styled('div')({ flex: 1 }); | ||
|
||
export default FlexFill; |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { styled } from '@mui/material'; | ||
import { StyledComponent } from '@emotion/styled'; | ||
import { styled, BoxProps } from '@mui/material'; | ||
|
||
export default styled('pre')({ | ||
const Pre: StyledComponent<BoxProps> = styled('pre')({ | ||
margin: 0, | ||
fontFamily: 'Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace', | ||
}); | ||
|
||
export default Pre; |
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 |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import { styled } from '@mui/material'; | ||
import { PanelResizeHandle as PanelResizeHandleOrig } from 'react-resizable-panels'; | ||
import { | ||
PanelResizeHandle as PanelResizeHandleOrig, | ||
PanelResizeHandleProps, | ||
} from 'react-resizable-panels'; | ||
|
||
export * from 'react-resizable-panels'; | ||
|
||
const RESIZE_HANDLE_OFFSET = 3; | ||
|
||
export const PanelResizeHandle = styled(PanelResizeHandleOrig)(({ theme }) => ({ | ||
backgroundClip: 'padding-box', | ||
zIndex: 1, | ||
display: 'flex', | ||
backgroundColor: theme.palette.divider, | ||
borderStyle: 'solid', | ||
borderColor: 'rgba(255, 255, 255, 0)', | ||
'&:hover': { | ||
borderColor: theme.palette.divider, | ||
}, | ||
transition: 'all 250ms ease', | ||
'&[data-panel-group-direction="horizontal"]': { | ||
width: 2 * RESIZE_HANDLE_OFFSET + 1, | ||
marginLeft: -RESIZE_HANDLE_OFFSET, | ||
marginRight: -RESIZE_HANDLE_OFFSET, | ||
borderLeftWidth: RESIZE_HANDLE_OFFSET, | ||
borderRightWidth: RESIZE_HANDLE_OFFSET, | ||
}, | ||
'&[data-panel-group-direction="vertical"]': { | ||
height: 2 * RESIZE_HANDLE_OFFSET + 1, | ||
marginTop: -RESIZE_HANDLE_OFFSET, | ||
marginBottom: -RESIZE_HANDLE_OFFSET, | ||
borderTopWidth: RESIZE_HANDLE_OFFSET, | ||
borderBottomWidth: RESIZE_HANDLE_OFFSET, | ||
}, | ||
})); | ||
export const PanelResizeHandle: React.FC<PanelResizeHandleProps> = styled(PanelResizeHandleOrig)( | ||
({ theme }) => ({ | ||
backgroundClip: 'padding-box', | ||
zIndex: 1, | ||
display: 'flex', | ||
backgroundColor: theme.palette.divider, | ||
borderStyle: 'solid', | ||
borderColor: 'rgba(255, 255, 255, 0)', | ||
'&:hover': { | ||
borderColor: theme.palette.divider, | ||
}, | ||
transition: 'all 250ms ease', | ||
'&[data-panel-group-direction="horizontal"]': { | ||
width: 2 * RESIZE_HANDLE_OFFSET + 1, | ||
marginLeft: -RESIZE_HANDLE_OFFSET, | ||
marginRight: -RESIZE_HANDLE_OFFSET, | ||
borderLeftWidth: RESIZE_HANDLE_OFFSET, | ||
borderRightWidth: RESIZE_HANDLE_OFFSET, | ||
}, | ||
'&[data-panel-group-direction="vertical"]': { | ||
height: 2 * RESIZE_HANDLE_OFFSET + 1, | ||
marginTop: -RESIZE_HANDLE_OFFSET, | ||
marginBottom: -RESIZE_HANDLE_OFFSET, | ||
borderTopWidth: RESIZE_HANDLE_OFFSET, | ||
borderBottomWidth: RESIZE_HANDLE_OFFSET, | ||
}, | ||
}), | ||
); |
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,82 @@ | ||
import Button from '@mui/material/Button'; | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/client'; | ||
import { ToolpadComponents } from '@mui/toolpad-core'; | ||
import createCache from '@emotion/cache'; | ||
import { CacheProvider } from '@emotion/react'; | ||
import { Box } from '@mui/material'; | ||
import { RuntimeState } from './runtime/types'; | ||
import { | ||
AppHost, | ||
AppHostContext, | ||
ToolpadApp as RuntimeToolpadApp, | ||
ToolpadAppProps, | ||
componentsStore, | ||
pageComponentsStore, | ||
} from './runtime'; | ||
|
||
const IS_PREVIEW = process.env.NODE_ENV !== 'production'; | ||
const IS_CUSTOM_SERVER = process.env.TOOLPAD_CUSTOM_SERVER === 'true'; | ||
|
||
const cache = createCache({ | ||
key: 'css', | ||
prepend: true, | ||
}); | ||
|
||
// See https://github.com/emotion-js/emotion/issues/1105#issuecomment-1058225197 | ||
cache.compat = true; | ||
|
||
/** | ||
* This allows us to hot update the components when a file is added/removed | ||
*/ | ||
export function setComponents( | ||
newComponents: ToolpadComponents, | ||
pageComponents: Record<string, React.ComponentType>, | ||
) { | ||
componentsStore.setState(newComponents); | ||
pageComponentsStore.setState(pageComponents); | ||
} | ||
|
||
interface RootProps { | ||
initialState: RuntimeState; | ||
base: string; | ||
ToolpadApp: React.ComponentType<ToolpadAppProps>; | ||
} | ||
|
||
const IS_RENDERED_IN_CANVAS = | ||
typeof window === 'undefined' | ||
? false | ||
: !!(window.frameElement as HTMLIFrameElement)?.dataset?.toolpadCanvas; | ||
|
||
const appHost: AppHost = { | ||
isPreview: IS_PREVIEW, | ||
isCustomServer: IS_CUSTOM_SERVER, | ||
isCanvas: IS_RENDERED_IN_CANVAS, | ||
}; | ||
|
||
function Root({ ToolpadApp, initialState, base }: RootProps) { | ||
return ( | ||
<React.StrictMode> | ||
<CacheProvider value={cache}> | ||
{/* For some reason this helps with https://github.com/vitejs/vite/issues/12423 */} | ||
<Button sx={{ display: 'none' }} /> | ||
<AppHostContext.Provider value={appHost}> | ||
<ToolpadApp basename={base} state={initialState} /> | ||
</AppHostContext.Provider> | ||
<Box data-testid="page-ready-marker" sx={{ display: 'none' }} /> | ||
</CacheProvider> | ||
</React.StrictMode> | ||
); | ||
} | ||
|
||
export interface InitParams { | ||
initialState: RuntimeState; | ||
base: string; | ||
ToolpadApp?: React.ComponentType<ToolpadAppProps>; | ||
} | ||
|
||
export function init({ ToolpadApp = RuntimeToolpadApp, initialState, base }: InitParams) { | ||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<Root base={base} ToolpadApp={ToolpadApp} initialState={initialState} />, | ||
); | ||
} |
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,6 @@ | ||
import * as React from 'react'; | ||
import ToolpadEditor from '../toolpad/Toolpad'; | ||
|
||
export default function ToolpadEditorVite({ basename }: { basename: string }) { | ||
return <ToolpadEditor basename={`${basename}/editor`} appUrl={basename} />; | ||
} |
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 @@ | ||
export * from '../entrypoint'; |
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
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.