Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.
Open

Demo #41

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
95 changes: 90 additions & 5 deletions demo/src/components/FlowDetailForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import * as React from "react";
import { withPropsApi } from "../../../src/index";
import { ICanvasData } from "../../../src/types/flow";
import { IPropsAPI } from "../../../src/types/propsAPI";
import { IPropsAPI, IEdgeModel } from "../../../src/types/propsAPI";

interface IProps {
propsAPI: IPropsAPI;
name: string;
}

import * as Fabric from "office-ui-fabric-react";
import { StackItem } from "office-ui-fabric-react";

import { IMxCell } from "../../../src/types/mxGraph";

const {
TextField,
Stack,
StackItem,
Label,
Text,
} = Fabric;

export class DetailForm extends React.PureComponent<IProps, { value: string }> {
Expand All @@ -31,14 +35,95 @@ export class DetailForm extends React.PureComponent<IProps, { value: string }> {
this._isEditing = false;
}
public render(): React.ReactNode {
console.log("render");
const { name } = this.props;
return (
<Stack >
<StackItem>
{name === "node" && this.renderNodeDetail()}
{name === "edge" && this.renderEdgeDetail()}
{name === "port" && this.renderPortDetail()}
{name === "canvas" && this.renderCanvasDetail()}
</Stack >
);
}

public renderNodeDetail = () => {
const { propsAPI } = this.props;
const model = propsAPI.getCellModel(this.cell);
console.log(model);
return [
(
<StackItem key="1">
<TextField label="label" type="text" placeholder="placeholder" value={this._getInputValue()} onFocus={this.startEditing} onChange={this._onChange} onBlur={this.stopEditing} />
</StackItem>
</Stack >
),
(
<StackItem key="2">
<Label>id</Label>
<Text>{model.id}</Text>
</StackItem>
)
];
}

public renderEdgeDetail = () => {
const { propsAPI } = this.props;
const model = propsAPI.getCellModel(this.cell);
console.log(model);
return [
(
<StackItem key="1">
<TextField label="label" type="text" placeholder="placeholder" value={this._getInputValue()} onFocus={this.startEditing} onChange={this._onChange} onBlur={this.stopEditing} />
</StackItem>
),
(
<StackItem key="2">
<Label>id</Label>
<Text>{model.id}</Text>
<Label>source id</Label>
<Text> {(model as IEdgeModel).source}</Text>
<Label>target id</Label>
<Text> {(model as IEdgeModel).target}</Text>
<Label>source port id</Label>
<Text> {(model as IEdgeModel).sourcePort}</Text>
<Label>target port id</Label>
<Text> {(model as IEdgeModel).targetPort}</Text>
</StackItem>
)
];
}

public renderPortDetail = () => {
const { propsAPI } = this.props;
const model = propsAPI.getCellModel(this.cell);
console.log(model);
console.log(propsAPI.graph.getTerminalForPort(this.cell, false));
console.log(propsAPI.graph.getTerminalForPort(this.cell, true));
return [
(
<StackItem key="1">
<TextField label="label" type="text" placeholder="placeholder" value={this._getInputValue()} onFocus={this.startEditing} onChange={this._onChange} onBlur={this.stopEditing} />
</StackItem>
),
(
<StackItem key="2">
<Label>id</Label>
<Text>{model.id}</Text>
</StackItem>
)
];
}

public renderCanvasDetail = () => {
const { propsAPI } = this.props;
console.log(propsAPI);
return (
<StackItem>
{"canvas"}
</StackItem>
);
}

private readonly _onChange = (event) => {
this.setState({ value: event.target.value });
}
Expand All @@ -54,7 +139,7 @@ export class DetailForm extends React.PureComponent<IProps, { value: string }> {
if (!cell) {
throw new Error("no cell to get value");
}
update(cell, {label: this.state.value});
update(cell, { label: this.state.value });
this._isEditing = false;
}
private readonly _getCellValue = () => {
Expand Down
7 changes: 3 additions & 4 deletions demo/src/components/FlowDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EdgePanel,
NodePanel,
PortPanel,
TextEditor,
} from "../../../src/index";

import {
Expand All @@ -15,13 +14,13 @@ export const FlowDetailPanel = () => {
return (
<DetailPanel >
<NodePanel >
<FlowDetailForm />
<FlowDetailForm name="node"/>
</NodePanel>
<EdgePanel >
<FlowDetailForm />
<FlowDetailForm name="edge"/>
</EdgePanel>
<PortPanel>
<FlowDetailForm />
<FlowDetailForm name="port"/>
</PortPanel>
</DetailPanel>
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"dependencies": {
"@storybook/react": "^5.1.9",
"eslint": "^6.0.1",
"mxgraph-js": "^1.0.1"
"mxgraph": "^4.0.4",
"office-ui-fabric-react": "^7.28.1"
}
}
3 changes: 0 additions & 3 deletions src/components/Command.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as React from "react";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";

import {
IMenuItemContext,
MenuItemContext,
Expand Down
6 changes: 2 additions & 4 deletions src/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @ts-ignore
import * as mxGraphJs from "mxgraph-js";
import * as React from "react";

const {
import {
mxEvent,
mxUtils,
} = mxGraphJs;
} from "../mxgraph";

import {
IMxGraphContext,
Expand Down
29 changes: 21 additions & 8 deletions src/components/DetailPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as React from "react";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";

const {
import {
mxEvent
} = mxGraphJs;
} from "../mxgraph";

import {
IMxGraphContext,
Expand All @@ -28,6 +25,22 @@ export class DetailPanel extends React.PureComponent<{}, { cells?: IMxCell[] }>

}

// public shouldComponentUpdate(_nextProps: {}, nextState: { cells?: IMxCell[]}): boolean {
// if (this.state.cells && nextState.cells) {
// if (this.state.cells.length === nextState.cells.length) {
// for (let i = 0; i < this.state.cells.length; i += 1) {
// if (this.state.cells[i] !== nextState.cells[i]) {
// return true;
// }
// }
// return false;
// }
// else { return true; }
// } else {
// return this.state.cells !== nextState.cells;
// }
// }

public render(): React.ReactNode {
// console.log("render");
return (
Expand All @@ -40,7 +53,9 @@ export class DetailPanel extends React.PureComponent<{}, { cells?: IMxCell[] }>
this._setListener(graph);
this._first = false;
}
const name = this._getName(graph, this.state.cells);
const name = this._getName(graph, graph.getSelectionCells());
// console.log("render root")
// console.log(this.state.cells);
return (
<PanelContext.Provider value={{ name, cells: this.state.cells }}>
<div>
Expand All @@ -58,8 +73,6 @@ export class DetailPanel extends React.PureComponent<{}, { cells?: IMxCell[] }>

graph.getSelectionModel()
.addListener(mxEvent.CHANGE, (_sender, _evt) => {
// console.log(_sender, _evt);
// console.log(graph.getSelectionCells()[0], graph.getDefaultParent());
this.setState({ cells: graph.getSelectionCells() });
});
}
Expand Down
9 changes: 2 additions & 7 deletions src/components/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
ICanvasData,
} from "../types/flow";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";
import { mxGraph } from "../mxgraph";

import {
IMxGraphContext,
Expand All @@ -22,10 +21,6 @@ interface IFlowState {
graph?: IMxGraph;
}

const {
mxGraph,
} = mxGraphJs;

export class Flow extends React.PureComponent<IFlowProps, IFlowState> {
private readonly _containerRef = React.createRef<HTMLDivElement>();
private _setGraph?: (graph: IMxGraph) => void;
Expand All @@ -49,7 +44,7 @@ export class Flow extends React.PureComponent<IFlowProps, IFlowState> {
if (graph) {
readData(graph, this.props.data);
}
// const Background = require("../../images/grid.gif");

return (
<div style={{width: "100%", height: "100%", overflow: "scroll"}} className="flow-container" ref={this._containerRef} />
);
Expand Down
11 changes: 4 additions & 7 deletions src/components/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as React from "react";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";

const {
mxUtils,
} = mxGraphJs;
import {
mxUtils
} from "../mxgraph";

import {
IMxGraphContext,
Expand Down Expand Up @@ -74,7 +71,7 @@ export class Item extends React.PureComponent<IItemProps>{

private readonly insertNode = (graph: IMxGraph, _evt: PointerEvent, target: IMxCell, x: number, y: number): void => {
const label = this.props.model && this.props.model.label ? this.props.model.label : "none";
// tslint:disable-next-line: newline-per-chained-call

const shape = this.props.shape;
const tmp = this.props.size ? this.props.size.split("*")
.map((s) => parseInt(s, 10)) : [100, 70];
Expand Down
3 changes: 0 additions & 3 deletions src/components/ItemPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as React from "react";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";

export class ItemPanel extends React.PureComponent {
public render(): React.ReactNode {

Expand Down
6 changes: 2 additions & 4 deletions src/components/Minimap.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as React from "react";

// @ts-ignore
import * as mxGraphJs from "mxgraph-js";
import {
IMxGraphContext,
MxGraphContext,
} from "../context/MxGraphContext";
import { IMxGraph } from "../types/mxGraph";

const {
import {
mxOutline,
} = mxGraphJs;
} from "../mxgraph";

interface IMinimapProps {
width?: string;
Expand Down
Loading