-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Showing
78 changed files
with
2,298 additions
and
1,815 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
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,51 @@ | ||
import { type Plugin, type IBoostsService } from '@alilc/lowcode-renderer-core'; | ||
import { type ComponentType, type PropsWithChildren } from 'react'; | ||
|
||
export type WrapperComponent = ComponentType<PropsWithChildren<any>>; | ||
|
||
export interface OutletProps { | ||
[key: string]: any; | ||
} | ||
|
||
export type Outlet = ComponentType<OutletProps>; | ||
|
||
export interface ReactRendererExtensionApi { | ||
addAppWrapper(appWrapper: WrapperComponent): void; | ||
|
||
setOutlet(outlet: Outlet): void; | ||
} | ||
|
||
class ReactRendererExtension { | ||
private wrappers: WrapperComponent[] = []; | ||
|
||
private outlet: Outlet | null = null; | ||
|
||
getAppWrappers() { | ||
return this.wrappers; | ||
} | ||
|
||
getOutlet() { | ||
return this.outlet; | ||
} | ||
|
||
toExpose(): ReactRendererExtensionApi { | ||
return { | ||
addAppWrapper: (appWrapper) => { | ||
if (appWrapper) this.wrappers.push(appWrapper); | ||
}, | ||
setOutlet: (outletComponent) => { | ||
if (outletComponent) this.outlet = outletComponent; | ||
}, | ||
}; | ||
} | ||
|
||
install(boostsService: IBoostsService) { | ||
boostsService.extend(this.toExpose()); | ||
} | ||
} | ||
|
||
export const extension = new ReactRendererExtension(); | ||
|
||
export function defineRendererPlugin(plugin: Plugin<ReactRendererExtensionApi>) { | ||
return plugin; | ||
} |
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,3 @@ | ||
export * from './context'; | ||
export * from './extension'; | ||
export * from './view'; |
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,34 @@ | ||
import { useRenderContext } from './context'; | ||
import { getComponentByName } from '../runtime/component'; | ||
import { extension } from './extension'; | ||
|
||
export function ApplicationView() { | ||
const renderContext = useRenderContext(); | ||
const { schema } = renderContext; | ||
const appWrappers = extension.getAppWrappers(); | ||
const Outlet = extension.getOutlet(); | ||
|
||
if (!Outlet) return null; | ||
|
||
let element = <Outlet />; | ||
|
||
const layoutConfig = schema.get('config')?.layout; | ||
|
||
if (layoutConfig) { | ||
const componentName = layoutConfig.componentName; | ||
const Layout = getComponentByName(componentName, renderContext); | ||
|
||
if (Layout) { | ||
const layoutProps: any = layoutConfig.props ?? {}; | ||
element = <Layout {...layoutProps}>{element}</Layout>; | ||
} | ||
} | ||
|
||
if (appWrappers.length > 0) { | ||
element = appWrappers.reduce((preElement, CurrentWrapper) => { | ||
return <CurrentWrapper>{preElement}</CurrentWrapper>; | ||
}, element); | ||
} | ||
|
||
return element; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.