-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2111d2c
commit d8225b7
Showing
9 changed files
with
56 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
src/react/components/PageShell/PageShell.tsx → src/react/components/WebModule/WebModule.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import './PageShell.module.css'; | ||
import './WebModule.module.css'; | ||
import { ConfigProvider } from 'antd'; | ||
|
||
export function PageShell(props: PropsWithChildren) { | ||
export function WebModule(props: PropsWithChildren) { | ||
return ( | ||
<ConfigProvider> | ||
{ props.children } | ||
</ConfigProvider> | ||
); | ||
} | ||
|
||
export default PageShell; | ||
export default WebModule; |
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,2 @@ | ||
export * from "./WebModule"; | ||
export { default } from "./WebModule"; |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
import React, { ComponentType, ReactElement } from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { WebModuleFactoryContext, startWebModule } from "../utils/webModule"; | ||
import WebModule from './components/WebModule'; | ||
|
||
type LazyReactElementFactory = (context?: WebModuleFactoryContext) => Promise<ReactElement> | ||
|
||
interface WebModuleOpts { | ||
wrapper?: ComponentType | ||
view?: ReactElement | LazyReactElementFactory | ||
} | ||
|
||
export function startup(opts: WebModuleOpts) { | ||
startWebModule(async (context) => { | ||
let webModuleContent: ReactElement = <></>; | ||
if (React.isValidElement(opts.view)) { | ||
webModuleContent = opts.view; | ||
} else if (typeof opts.view === "function") { | ||
webModuleContent = await opts.view(context); | ||
} | ||
|
||
const Wrapper = opts.wrapper ?? React.Fragment; | ||
const render = ReactDOM.createRoot(context?.container ?? document.getElementById('root') ?? document.body); | ||
render.render( | ||
<WebModule> | ||
<Wrapper> | ||
{ webModuleContent } | ||
</Wrapper> | ||
</WebModule> | ||
); | ||
|
||
return () => { | ||
render.unmount(); | ||
} | ||
}) | ||
} | ||
|
||
|
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