withEditorContext

This commit is contained in:
zhandouxiaojiji committed 2020-10-16 16:38:20 +08:00
1 parent 30a49ed5d6
commit 6fc77ad797
3 files changed
+54 -46

No files matched your search

+37 -7
View File
@@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import GGEditor, { Mind, RegisterNode } from 'gg-editor'; import GGEditor, { Mind, RegisterNode, setAnchorPointsState } from 'gg-editor';
import { MindData } from 'gg-editor/lib/common/interfaces'; import { MindData } from 'gg-editor/lib/common/interfaces';
const data: MindData = { const data: MindData = {
id: "1", id: "1",
@@ -20,14 +20,44 @@ const data: MindData = {
], ],
}; };
export default class BehaviorTree extends React.Component { interface BehaviorTreeProps{
}
class BehaviorTree extends React.Component <BehaviorTreeProps> {
componentDidMount() {
// const { graph } = this.props;
// graph.on('click', (ev: any) => {
// console.log("click", ev);
// });
// graph.on('dbclick', (ev: any) => {
// console.log("dbclick", ev);
// });
// graph.on('dragenter', (ev: any) => {
// console.log("dragenter", ev);
// });
}
render() { render() {
return ( return (
<Mind <Mind
style={{ width: "70vw", height: "100vh" }} style={{ width: "70vw", height: "100vh" }}
graphConfig= {{fitView: true, maxZoom:2, fitViewPadding:[20, 20, 20, 20]}} graphConfig={{
data={data} fitView: true,
/> maxZoom: 2,
fitViewPadding: [20, 20, 20, 20]
}}
data={data}
ref={component => {
if (component) {
console.log('graph:', component.graph);
}
}}
/>
); );
} }
} }
export default BehaviorTree;
+10 -27
View File
@@ -2,10 +2,9 @@ import React from 'react';
import { Card } from 'antd'; import { Card } from 'antd';
import { DetailPanel, withEditorContext } from 'gg-editor'; import { DetailPanel, withEditorContext } from 'gg-editor';
import { EditorContextProps } from 'gg-editor/lib/components/EditorContext'; import { EditorContextProps } from 'gg-editor/lib/components/EditorContext';
import { DetailPanelComponentProps } from 'gg-editor/lib/components/DetailPanel';
interface NodePanelProps extends EditorContextProps, DetailPanelComponentProps { interface NodePanelProps extends EditorContextProps {
} }
@@ -13,33 +12,17 @@ interface NodePanelState {
} }
class Panel extends React.Component<NodePanelProps, NodePanelState> { class Panel extends React.Component<NodePanelProps> {
render() { componentDidMount() {
const { nodes } = this.props; console.log(this.props);
console.log("NodePanel render", nodes); this.props.graph.on("click", (ev: any) => {
const node = nodes[0]; console.log("on click", ev);
if (node) { })
return (
<Card title="节点信息">
{node ? node.getModel().label : ''}
</Card>
)
} else {
return (
<Card title="节点信息">
未选中
</Card>
)
}
} }
}
export default class NodePanel extends React.Component {
render() { render() {
console.log("NodePanel render"); console.log("NodePanel render", this.props);
return ( return (
<Card title="节点信息" style = {{height:"100%"}}> <Card title="节点信息" style={{ height: "100%" }}>
未选中fefqwefqwefwewef 未选中fefqwefqwefwewef
</Card> </Card>
) )
@@ -47,4 +30,4 @@ export default class NodePanel extends React.Component {
} }
// export default DetailPanel.create<NodePanelProps>('node')(withEditorContext(Panel)); export default withEditorContext<NodePanelProps, Panel>(Panel);
+7 -12
View File
@@ -1,16 +1,20 @@
import * as React from 'react'; import * as React from 'react';
import GGEditor, { Mind, RegisterNode } from 'gg-editor'; import GGEditor, { Mind, RegisterNode, withEditorContext } from 'gg-editor';
import { MindData } from 'gg-editor/lib/common/interfaces';
import { Row, Col } from 'antd'; import { Row, Col } from 'antd';
import './Editor.css';
import NodePanel from './NodePanel'; import NodePanel from './NodePanel';
import BehaviorTree from './BehaviorTree'; import BehaviorTree from './BehaviorTree';
import './Editor.css';
export interface EditorProps { export interface EditorProps {
} }
export default class Editor extends React.Component<EditorProps> { export default class Editor extends React.Component<EditorProps> {
componentDidMount() {
console.log("props", this.props);
}
render() { render() {
return ( return (
<GGEditor className="editor"> <GGEditor className="editor">
@@ -22,16 +26,7 @@ export default class Editor extends React.Component<EditorProps> {
<NodePanel /> <NodePanel />
</Col> </Col>
</Row> </Row>
{/* <MindContextMenu />
<MindCopy />
<MindPaste />
<MindSave />
<RegisterBehaviour name="dblclickItemEditLabel" behaviour={() => { }} /> */}
</GGEditor> </GGEditor>
); );
} }
} }
function getExclamationMarks(numChars: number) {
return Array(numChars + 1).join('!');
}