feat(outline-pane): export OutlinePaneContext

This commit is contained in:
liujuping 2023-04-26 10:20:52 +08:00 committed by 林熠
parent ebc137d118
commit 5b1423068e
8 changed files with 50 additions and 56 deletions

View File

@ -40,6 +40,7 @@ export class TreeMaster {
const { workspace } = this.pluginContext; const { workspace } = this.pluginContext;
this.initEvent(); this.initEvent();
if (pluginContext.registerLevel === IPublicEnumPluginRegisterLevel.Workspace) { if (pluginContext.registerLevel === IPublicEnumPluginRegisterLevel.Workspace) {
this.setPluginContext(workspace.window?.currentEditorView);
workspace.onWindowRendererReady(() => { workspace.onWindowRendererReady(() => {
this.setPluginContext(workspace.window?.currentEditorView); this.setPluginContext(workspace.window?.currentEditorView);
let dispose: IPublicTypeDisposable | undefined; let dispose: IPublicTypeDisposable | undefined;
@ -60,7 +61,7 @@ export class TreeMaster {
} }
} }
private setPluginContext(pluginContext: IPublicModelPluginContext | undefined) { private setPluginContext(pluginContext: IPublicModelPluginContext | undefined | null) {
if (!pluginContext) { if (!pluginContext) {
return; return;
} }

View File

@ -6,6 +6,34 @@ import { TreeMaster } from './controllers/tree-master';
import { PaneController } from './controllers/pane-controller'; import { PaneController } from './controllers/pane-controller';
import { useState } from 'react'; import { useState } from 'react';
export function OutlinePaneContext(props: {
treeMaster?: TreeMaster;
pluginContext: IPublicModelPluginContext;
options: any;
paneName: string;
hideFilter?: boolean;
}) {
const treeMaster = props.treeMaster || new TreeMaster(props.pluginContext, props.options);
const [masterPaneController, setMasterPaneController] = useState(new PaneController(props.paneName || MasterPaneName, treeMaster));
treeMaster.onPluginContextChange(() => {
setMasterPaneController(new PaneController(props.paneName || MasterPaneName, treeMaster));
});
return (
<Pane
treeMaster={treeMaster}
controller={masterPaneController}
key={masterPaneController.id}
hideFilter={props.hideFilter}
{...props}
/>
);
}
export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => { export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
const { skeleton, config, canvas, project } = ctx; const { skeleton, config, canvas, project } = ctx;
@ -19,7 +47,6 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
backupPane: false, backupPane: false,
}; };
const treeMaster = new TreeMaster(ctx, options); const treeMaster = new TreeMaster(ctx, options);
let backupPaneController: PaneController | null = null;
return { return {
async init() { async init() {
skeleton.add({ skeleton.add({
@ -33,22 +60,7 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
icon: IconOutline, icon: IconOutline,
description: treeMaster.pluginContext.intlNode('Outline Tree'), description: treeMaster.pluginContext.intlNode('Outline Tree'),
}, },
content: function Context(props: any) { content: OutlinePaneContext,
const [masterPaneController, setMasterPaneController] = useState(new PaneController(MasterPaneName, treeMaster));
treeMaster.onPluginContextChange(() => {
setMasterPaneController(new PaneController(MasterPaneName, treeMaster));
});
return (
<Pane
config={config}
treeMaster={treeMaster}
controller={masterPaneController}
key={masterPaneController.id}
{...props}
/>
);
},
}, },
panelProps: { panelProps: {
area: isInFloatArea ? 'leftFloatArea' : 'leftFixedArea', area: isInFloatArea ? 'leftFloatArea' : 'leftFixedArea',
@ -57,6 +69,8 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
}, },
contentProps: { contentProps: {
treeTitleExtra: config.get('treeTitleExtra'), treeTitleExtra: config.get('treeTitleExtra'),
treeMaster,
paneName: MasterPaneName,
}, },
}); });
@ -67,15 +81,10 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
props: { props: {
hiddenWhenInit: true, hiddenWhenInit: true,
}, },
content: (props: any) => { content: OutlinePaneContext,
backupPaneController = new PaneController(BackupPaneName, treeMaster); contentProps: {
return ( paneName: BackupPaneName,
<Pane treeMaster,
treeMaster={treeMaster}
controller={backupPaneController}
{...props}
/>
);
}, },
}); });

View File

@ -51,7 +51,6 @@ export default class Filter extends PureComponent<{
return ( return (
<div className="lc-outline-filter"> <div className="lc-outline-filter">
{/* @ts-ignore */}
<Search <Search
hasClear hasClear
shape="simple" shape="simple"
@ -60,7 +59,6 @@ export default class Filter extends PureComponent<{
value={keywords} value={keywords}
onChange={this.handleSearchChange} onChange={this.handleSearchChange}
/> />
{/* @ts-ignore */}
<Balloon <Balloon
v2 v2
align="br" align="br"
@ -72,7 +70,6 @@ export default class Filter extends PureComponent<{
</div> </div>
)} )}
> >
{/* @ts-ignore */}
<Checkbox <Checkbox
checked={checkAll} checked={checkAll}
indeterminate={indeterminate} indeterminate={indeterminate}
@ -80,9 +77,7 @@ export default class Filter extends PureComponent<{
> >
{this.props.tree.pluginContext.intlNode('Check All')} {this.props.tree.pluginContext.intlNode('Check All')}
</Checkbox> </Checkbox>
{/* @ts-ignore */}
<Divider /> <Divider />
{/* @ts-ignore */}
<Checkbox.Group <Checkbox.Group
value={filterOps} value={filterOps}
direction="ver" direction="ver"

View File

@ -9,9 +9,9 @@ import { Tree } from '../controllers/tree';
import { IPublicTypeDisposable } from '@alilc/lowcode-types'; import { IPublicTypeDisposable } from '@alilc/lowcode-types';
export class Pane extends PureComponent<{ export class Pane extends PureComponent<{
config: any;
treeMaster: TreeMaster; treeMaster: TreeMaster;
controller: PaneController; controller: PaneController;
hideFilter?: boolean;
}, { }, {
tree: Tree | null; tree: Tree | null;
}> { }> {
@ -26,6 +26,11 @@ export class Pane extends PureComponent<{
this.state = { this.state = {
tree: treeMaster.currentTree, tree: treeMaster.currentTree,
}; };
this.dispose = this.props.treeMaster.pluginContext?.project?.onSimulatorRendererReady(() => {
this.setState({
tree: this.props.treeMaster.currentTree,
});
});
} }
componentWillUnmount() { componentWillUnmount() {
@ -33,14 +38,6 @@ export class Pane extends PureComponent<{
this.dispose && this.dispose(); this.dispose && this.dispose();
} }
componentDidMount() {
this.dispose = this.props.treeMaster.pluginContext.project.onSimulatorRendererReady(() => {
this.setState({
tree: this.props.treeMaster.currentTree,
});
});
}
render() { render() {
const tree = this.state.tree; const tree = this.state.tree;
@ -48,7 +45,6 @@ export class Pane extends PureComponent<{
return ( return (
<div className="lc-outline-pane"> <div className="lc-outline-pane">
<p className="lc-outline-notice"> <p className="lc-outline-notice">
{/* @ts-ignore */}
<Loading <Loading
style={{ style={{
display: 'block', display: 'block',
@ -63,8 +59,8 @@ export class Pane extends PureComponent<{
return ( return (
<div className="lc-outline-pane"> <div className="lc-outline-pane">
<Filter tree={tree} /> { !this.props.hideFilter && <Filter tree={tree} /> }
<div ref={(shell) => this.controller.mount(shell)} className="lc-outline-tree-container"> <div ref={(shell) => this.controller.mount(shell)} className={`lc-outline-tree-container ${ this.props.hideFilter ? 'lc-hidden-outline-filter' : '' }`}>
<TreeView key={tree.id} tree={tree} /> <TreeView key={tree.id} tree={tree} />
</div> </div>
</div> </div>

View File

@ -14,10 +14,14 @@
overflow: auto; overflow: auto;
} }
> .lc-outline-tree-container.lc-hidden-outline-filter {
top: 0;
}
> .lc-outline-filter { > .lc-outline-filter {
padding: 12px 16px; padding: 12px 16px;
display: flex; display: flex;
align-items: center; align-items: stretch;
justify-content: right; justify-content: right;
.lc-outline-filter-search-input { .lc-outline-filter-search-input {
@ -27,7 +31,6 @@
.lc-outline-filter-icon { .lc-outline-filter-icon {
background: #ebecf0; background: #ebecf0;
border: 1px solid #c4c6cf; border: 1px solid #c4c6cf;
height: 28px;
display: flex; display: flex;
align-items: center; align-items: center;
border-radius: 0 2px 2px 0; border-radius: 0 2px 2px 0;

View File

@ -83,7 +83,6 @@ beforeEach(() => {
}); });
component = renderer.create( component = renderer.create(
// @ts-ignore
<Div _leaf={DivNode}> <Div _leaf={DivNode}>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</Div> </Div>
@ -238,7 +237,6 @@ describe('mini unit render', () => {
nodeMap.set(textSchema.id, TextNode); nodeMap.set(textSchema.id, TextNode);
component = renderer.create( component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}> <MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv> </MiniRenderDiv>
@ -285,7 +283,6 @@ describe('mini unit render', () => {
nodeMap.set(textSchema.id, TextNode); nodeMap.set(textSchema.id, TextNode);
renderer.create( renderer.create(
// @ts-ignore
<div> <div>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</div> </div>
@ -309,7 +306,6 @@ describe('mini unit render', () => {
}); });
renderer.create( renderer.create(
// @ts-ignore
<div> <div>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</div> </div>
@ -388,7 +384,6 @@ describe('mini unit render', () => {
}; };
const component = renderer.create( const component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}> <MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv> </MiniRenderDiv>
@ -428,7 +423,6 @@ describe('mini unit render', () => {
nodeMap.set(miniRenderSchema.id, MiniRenderDivNode); nodeMap.set(miniRenderSchema.id, MiniRenderDivNode);
component = renderer.create( component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}> <MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv> </MiniRenderDiv>
@ -491,7 +485,6 @@ describe('onVisibleChange', () => {
describe('children', () => { describe('children', () => {
it('this.props.children is array', () => { it('this.props.children is array', () => {
const component = renderer.create( const component = renderer.create(
// @ts-ignore
<Div _leaf={DivNode}> <Div _leaf={DivNode}>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>
<Text _leaf={TextNode} content="content"></Text> <Text _leaf={TextNode} content="content"></Text>

View File

@ -79,7 +79,6 @@ describe('Base Render methods', () => {
// const originalUtils = jest.requireActual('../../src/utils'); // const originalUtils = jest.requireActual('../../src/utils');
// mockParseExpression.mockImplementation(originalUtils.parseExpression); // mockParseExpression.mockImplementation(originalUtils.parseExpression);
const component = TestRenderer.create( const component = TestRenderer.create(
// @ts-ignore
<RendererClass <RendererClass
__schema={mockSchema} __schema={mockSchema}
components={components as any} components={components as any}

View File

@ -13,7 +13,6 @@ function getComp(schema, comp = null, others = {}): Promise<{
}> { }> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const component = renderer.create( const component = renderer.create(
// @ts-ignore
<Renderer <Renderer
schema={schema} schema={schema}
components={components as any} components={components as any}
@ -48,7 +47,6 @@ afterEach(() => {
describe('Base Render', () => { describe('Base Render', () => {
it('renderComp', () => { it('renderComp', () => {
const content = ( const content = (
// @ts-ignore
<Renderer <Renderer
schema={schema as any} schema={schema as any}
components={components as any} components={components as any}