Skip to content

Commit

Permalink
feat: support online tree title extra
Browse files Browse the repository at this point in the history
  • Loading branch information
huoteng authored and liujuping committed Dec 13, 2022
1 parent d9e1203 commit 778ba32
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/engine/src/engine-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ engineConfig.set('isOpenSource', isOpenSource);
keepVisibleWhileDragging: true,
...engineConfig.get('defaultOutlinePaneProps'),
},
contentProps: {
treeTitleExtra: engineConfig.get('treeTitleExtra'),
},
});
skeleton.add({
area: 'rightArea',
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin-outline-pane/src/helper/tree-title-extra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { globalContext } from '@alilc/lowcode-editor-core';
import { ReactElement } from 'react';

const TREE_TITLE_EXTRA_KEY = 'TREE_TITLE_EXTRA_KEY';

export const registerTreeTitleExtra = (extra: ReactElement) => {
if (extra && !globalContext.has(TREE_TITLE_EXTRA_KEY)) {
globalContext.register(extra, TREE_TITLE_EXTRA_KEY);
}
};

export const getTreeTitleExtra = () => {
try {
return globalContext.get(TREE_TITLE_EXTRA_KEY);
} catch (e) {
// console.error('getTreeTitleExtra Error', e);
}

return null;
};
5 changes: 5 additions & 0 deletions packages/plugin-outline-pane/src/views/pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TreeView from './tree';
import './style.less';
import { IEditor } from '@alilc/lowcode-types';
import Filter from './filter';
import { registerTreeTitleExtra } from '../helper/tree-title-extra';

@observer
export class OutlinePane extends Component<{ config: any; editor: IEditor }> {
Expand All @@ -15,6 +16,10 @@ export class OutlinePane extends Component<{ config: any; editor: IEditor }> {
this.main.purge();
}

componentDidMount() {
registerTreeTitleExtra(this.props?.config?.contentProps?.treeTitleExtra);
}

render() {
const tree = this.main.currentTree;

Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-outline-pane/src/views/tree-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IconLoop } from '../icons/loop';
import { IconRadioActive } from '../icons/radio-active';
import { IconRadio } from '../icons/radio';
import { IconLock, IconUnlock } from '../icons';
import { getTreeTitleExtra } from '../helper/tree-title-extra';


function emitOutlineEvent(type: string, treeNode: TreeNode, rest?: Record<string, unknown>) {
Expand Down Expand Up @@ -97,6 +98,7 @@ export default class TreeTitle extends Component<{
};
}
const { filterWorking, matchSelf, keywords } = treeNode.filterReult;
const Extra = getTreeTitleExtra();

return (
<div
Expand Down Expand Up @@ -153,6 +155,7 @@ export default class TreeTitle extends Component<{
match={filterWorking && matchSelf}
keywords={keywords}
/>
{Extra && <Extra node={treeNode?.node} />}
{node.slotFor && (
<a className="tree-node-tag slot">
{/* todo: click redirect to prop */}
Expand Down

0 comments on commit 778ba32

Please sign in to comment.