Skip to content

Commit

Permalink
chore(release): bump ver to 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-zhang committed Mar 25, 2023
1 parent 2111d2c commit d8225b7
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 65 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@x-poppy/web-sdk",
"version": "0.0.6",
"version": "0.0.7",
"description": "",
"main": "./dist/main.js",
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions src/react/components/PageShell/index.ts

This file was deleted.

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;
2 changes: 2 additions & 0 deletions src/react/components/WebModule/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./WebModule";
export { default } from "./WebModule";
48 changes: 0 additions & 48 deletions src/react/startPageModule.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions src/react/webModule.tsx
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();
}
})
}


19 changes: 10 additions & 9 deletions src/utils/webModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,26 @@ async function loadWebModule(webModuleUrl: string) {
}
}

function get(webModuleUrlOrName: string) {
const webModuleName = webModuleAliasMap[webModuleUrlOrName] ?? webModuleUrlOrName;
return webModuleMap[webModuleName] ?? undefined;
export function get(webModuleUrlOrName: string) {
const webModuleUrl = webModuleAliasMap[webModuleUrlOrName] ?? webModuleUrlOrName;
return webModuleMap[webModuleUrl] ?? undefined;
}

export async function importWebModule(webModuleUrl: string, webModuleName?: string): Promise<WebModule> {
export function alias(webModuleUrl: string, alias: string) {
webModuleAliasMap[alias] = webModuleUrl;
}

export async function importWebModule(webModuleUrlOrName: string): Promise<WebModule> {
const webModuleUrl = webModuleAliasMap[webModuleUrlOrName] ?? webModuleUrlOrName;
if (webModuleLoadedMap[webModuleUrl]) {
await webModuleLoadedMap[webModuleUrl];
return get(webModuleUrl);
}

if (webModuleName) {
webModuleAliasMap[webModuleName] = webModuleUrl;
}

const publicPath = baseURL(webModuleUrl);

const webModule = {
moduleName: webModuleName ?? webModuleUrl,
moduleName: webModuleUrl,
publicPath,
factory: null,
};
Expand Down

0 comments on commit d8225b7

Please sign in to comment.