Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(outline-pane): export OutlinePaneContext, add null option to setPluginContext and hideFilter option to Pane #1953

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class TreeMaster {
const { workspace } = this.pluginContext;
this.initEvent();
if (pluginContext.registerLevel === IPublicEnumPluginRegisterLevel.Workspace) {
this.setPluginContext(workspace.window?.currentEditorView);
workspace.onWindowRendererReady(() => {
this.setPluginContext(workspace.window?.currentEditorView);
let dispose: IPublicTypeDisposable | undefined;
Expand All @@ -60,7 +61,7 @@ export class TreeMaster {
}
}

private setPluginContext(pluginContext: IPublicModelPluginContext | undefined) {
private setPluginContext(pluginContext: IPublicModelPluginContext | undefined | null) {
if (!pluginContext) {
return;
}
Expand Down
61 changes: 35 additions & 26 deletions packages/plugin-outline-pane/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ import { TreeMaster } from './controllers/tree-master';
import { PaneController } from './controllers/pane-controller';
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) => {
const { skeleton, config, canvas, project } = ctx;

Expand All @@ -19,7 +47,6 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
backupPane: false,
};
const treeMaster = new TreeMaster(ctx, options);
let backupPaneController: PaneController | null = null;
return {
async init() {
skeleton.add({
Expand All @@ -33,22 +60,7 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
icon: IconOutline,
description: treeMaster.pluginContext.intlNode('Outline Tree'),
},
content: function Context(props: any) {
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}
/>
);
},
content: OutlinePaneContext,
},
panelProps: {
area: isInFloatArea ? 'leftFloatArea' : 'leftFixedArea',
Expand All @@ -57,6 +69,8 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
},
contentProps: {
treeTitleExtra: config.get('treeTitleExtra'),
treeMaster,
paneName: MasterPaneName,
},
});

Expand All @@ -67,15 +81,10 @@ export const OutlinePlugin = (ctx: IPublicModelPluginContext, options: any) => {
props: {
hiddenWhenInit: true,
},
content: (props: any) => {
backupPaneController = new PaneController(BackupPaneName, treeMaster);
return (
<Pane
treeMaster={treeMaster}
controller={backupPaneController}
{...props}
/>
);
content: OutlinePaneContext,
contentProps: {
paneName: BackupPaneName,
treeMaster,
},
});

Expand Down
5 changes: 0 additions & 5 deletions packages/plugin-outline-pane/src/views/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default class Filter extends PureComponent<{

return (
<div className="lc-outline-filter">
{/* @ts-ignore */}
<Search
hasClear
shape="simple"
Expand All @@ -60,7 +59,6 @@ export default class Filter extends PureComponent<{
value={keywords}
onChange={this.handleSearchChange}
/>
{/* @ts-ignore */}
<Balloon
v2
align="br"
Expand All @@ -72,17 +70,14 @@ export default class Filter extends PureComponent<{
</div>
)}
>
{/* @ts-ignore */}
<Checkbox
checked={checkAll}
indeterminate={indeterminate}
onChange={this.handleCheckAll}
>
{this.props.tree.pluginContext.intlNode('Check All')}
</Checkbox>
{/* @ts-ignore */}
<Divider />
{/* @ts-ignore */}
<Checkbox.Group
value={filterOps}
direction="ver"
Expand Down
20 changes: 8 additions & 12 deletions packages/plugin-outline-pane/src/views/pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Tree } from '../controllers/tree';
import { IPublicTypeDisposable } from '@alilc/lowcode-types';

export class Pane extends PureComponent<{
config: any;
treeMaster: TreeMaster;
controller: PaneController;
hideFilter?: boolean;
}, {
tree: Tree | null;
}> {
Expand All @@ -26,29 +26,25 @@ export class Pane extends PureComponent<{
this.state = {
tree: treeMaster.currentTree,
};
this.dispose = this.props.treeMaster.pluginContext?.project?.onSimulatorRendererReady(() => {
this.setState({
tree: this.props.treeMaster.currentTree,
});
});
}

componentWillUnmount() {
this.controller.purge();
this.dispose && this.dispose();
}

componentDidMount() {
this.dispose = this.props.treeMaster.pluginContext.project.onSimulatorRendererReady(() => {
this.setState({
tree: this.props.treeMaster.currentTree,
});
});
}

render() {
const tree = this.state.tree;

if (!tree) {
return (
<div className="lc-outline-pane">
<p className="lc-outline-notice">
{/* @ts-ignore */}
<Loading
style={{
display: 'block',
Expand All @@ -63,8 +59,8 @@ export class Pane extends PureComponent<{

return (
<div className="lc-outline-pane">
<Filter tree={tree} />
<div ref={(shell) => this.controller.mount(shell)} className="lc-outline-tree-container">
{ !this.props.hideFilter && <Filter tree={tree} /> }
<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} />
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-outline-pane/src/views/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
overflow: auto;
}

> .lc-outline-tree-container.lc-hidden-outline-filter {
top: 0;
}

> .lc-outline-filter {
padding: 12px 16px;
display: flex;
align-items: center;
align-items: stretch;
justify-content: right;

.lc-outline-filter-search-input {
Expand All @@ -27,7 +31,6 @@
.lc-outline-filter-icon {
background: #ebecf0;
border: 1px solid #c4c6cf;
height: 28px;
display: flex;
align-items: center;
border-radius: 0 2px 2px 0;
Expand Down
7 changes: 0 additions & 7 deletions packages/renderer-core/tests/hoc/leaf.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ beforeEach(() => {
});

component = renderer.create(
// @ts-ignore
<Div _leaf={DivNode}>
<Text _leaf={TextNode} content="content"></Text>
</Div>
Expand Down Expand Up @@ -238,7 +237,6 @@ describe('mini unit render', () => {
nodeMap.set(textSchema.id, TextNode);

component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv>
Expand Down Expand Up @@ -285,7 +283,6 @@ describe('mini unit render', () => {
nodeMap.set(textSchema.id, TextNode);

renderer.create(
// @ts-ignore
<div>
<Text _leaf={TextNode} content="content"></Text>
</div>
Expand All @@ -309,7 +306,6 @@ describe('mini unit render', () => {
});

renderer.create(
// @ts-ignore
<div>
<Text _leaf={TextNode} content="content"></Text>
</div>
Expand Down Expand Up @@ -388,7 +384,6 @@ describe('mini unit render', () => {
};

const component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv>
Expand Down Expand Up @@ -428,7 +423,6 @@ describe('mini unit render', () => {
nodeMap.set(miniRenderSchema.id, MiniRenderDivNode);

component = renderer.create(
// @ts-ignore
<MiniRenderDiv _leaf={MiniRenderDivNode}>
<Text _leaf={TextNode} content="content"></Text>
</MiniRenderDiv>
Expand Down Expand Up @@ -491,7 +485,6 @@ describe('onVisibleChange', () => {
describe('children', () => {
it('this.props.children is array', () => {
const component = renderer.create(
// @ts-ignore
<Div _leaf={DivNode}>
<Text _leaf={TextNode} content="content"></Text>
<Text _leaf={TextNode} content="content"></Text>
Expand Down
1 change: 0 additions & 1 deletion packages/renderer-core/tests/renderer/base.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('Base Render methods', () => {
// const originalUtils = jest.requireActual('../../src/utils');
// mockParseExpression.mockImplementation(originalUtils.parseExpression);
const component = TestRenderer.create(
// @ts-ignore
<RendererClass
__schema={mockSchema}
components={components as any}
Expand Down
2 changes: 0 additions & 2 deletions packages/renderer-core/tests/renderer/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function getComp(schema, comp = null, others = {}): Promise<{
}> {
return new Promise((resolve, reject) => {
const component = renderer.create(
// @ts-ignore
<Renderer
schema={schema}
components={components as any}
Expand Down Expand Up @@ -48,7 +47,6 @@ afterEach(() => {
describe('Base Render', () => {
it('renderComp', () => {
const content = (
// @ts-ignore
<Renderer
schema={schema as any}
components={components as any}
Expand Down
Loading