|
@@ -49,49 +49,57 @@ export class EditableGraph extends React.Component<EditableGraphProps, EditableG
|
|
|
readonly compositeLvl: CompositeLevel = new CompositeLevel();
|
|
|
readonly versionRegistry: VersionRegistry = new VersionRegistry();
|
|
|
|
|
|
- mouseDownHandler = (event, {x,y}, node: NodeType | undefined) => {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state = {showCrossHair: false};
|
|
|
+ }
|
|
|
+
|
|
|
+ mouseDownHandler = (event, {x,y}, mouseDownNode: NodeType | undefined) => {
|
|
|
event.stopPropagation();
|
|
|
- if (node) {
|
|
|
- this.mouseDownNode = node;
|
|
|
+ if (mouseDownNode) {
|
|
|
+ this.mouseDownNode = mouseDownNode;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- mouseUpHandler = (event, {x,y}, node: NodeType | undefined) => {
|
|
|
+ mouseUpHandler = (event, {x,y}, mouseUpNode: NodeType | undefined) => {
|
|
|
event.stopPropagation();
|
|
|
|
|
|
// Construct the delta(s) that capture the user's change:
|
|
|
const deltas: PrimitiveDelta[] = (() => {
|
|
|
if (event.button === 2) { // right mouse button
|
|
|
- if (this.mouseDownNode !== null && node !== undefined) {
|
|
|
- // right mouse button was dragged from one node to another -> create/update edge from one node to the other
|
|
|
- const label = prompt("Edge label (ESC to cancel):", "label");
|
|
|
- if (label !== null) {
|
|
|
- return this.mouseDownNode.obj.getDeltasForSetEdge(label, node.obj);
|
|
|
+ if (this.mouseDownNode !== null && this.mouseDownNode.obj instanceof NodeState) {
|
|
|
+ // create outgoing edge...
|
|
|
+ if (mouseUpNode !== undefined) {
|
|
|
+ // right mouse button was dragged from one node to another -> create/update edge from one node to the other
|
|
|
+ const label = prompt("Edge label (ESC to cancel):", "label");
|
|
|
+ if (label !== null) {
|
|
|
+ return this.mouseDownNode.obj.getDeltasForSetEdge(label, mouseUpNode.obj);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else if (this.mouseDownNode !== null && node === undefined) {
|
|
|
- // right mouse button was dragged from a node to empty space -> create/update edge from node to a value
|
|
|
- const label = prompt("Edge label (ESC to cancel):", "label");
|
|
|
- if (label !== null) {
|
|
|
- let enteredValue: string|null = "\"42\"";
|
|
|
- while (true) {
|
|
|
- enteredValue = prompt("Target value (enter a JSON-parsable(!) string (with quotes), number or boolean):\n(ESC to cancel)", enteredValue);
|
|
|
- if (enteredValue === null) {
|
|
|
- break;
|
|
|
+ else {
|
|
|
+ // right mouse button was dragged from a node to empty space -> create/update edge from node to a value
|
|
|
+ const label = prompt("Edge label (ESC to cancel):", "label");
|
|
|
+ if (label !== null) {
|
|
|
+ let enteredValue: string|null = "\"42\"";
|
|
|
+ while (true) {
|
|
|
+ enteredValue = prompt("Target value (enter a JSON-parsable(!) string (with quotes), number or boolean):\n(ESC to cancel)", enteredValue);
|
|
|
+ if (enteredValue === null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ let parsedValue;
|
|
|
+ try {
|
|
|
+ parsedValue = JSON.parse(enteredValue);
|
|
|
+ } catch (err) {
|
|
|
+ alert("Invalid JSON!");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const typeofParsedValue = typeof parsedValue;
|
|
|
+ if (typeofParsedValue !== "string" && typeofParsedValue !== "number" && typeofParsedValue !== "boolean") {
|
|
|
+ alert("Expected string, number or boolean. Got: " + typeofParsedValue);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return this.mouseDownNode.obj.getDeltasForSetEdge(label, this.props.graphDeltaExecutor.getValueState(parsedValue));
|
|
|
}
|
|
|
- let parsedValue;
|
|
|
- try {
|
|
|
- parsedValue = JSON.parse(enteredValue);
|
|
|
- } catch (err) {
|
|
|
- alert("Invalid JSON!");
|
|
|
- continue;
|
|
|
- }
|
|
|
- const typeofParsedValue = typeof parsedValue;
|
|
|
- if (typeofParsedValue !== "string" && typeofParsedValue !== "number" && typeofParsedValue !== "boolean") {
|
|
|
- alert("Expected string, number or boolean. Got: " + typeofParsedValue);
|
|
|
- continue;
|
|
|
- }
|
|
|
- return this.mouseDownNode.obj.getDeltasForSetEdge(label, this.props.graphDeltaExecutor.getValueState(parsedValue));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -103,9 +111,9 @@ export class EditableGraph extends React.Component<EditableGraphProps, EditableG
|
|
|
}
|
|
|
}
|
|
|
else if (event.button === 1) { // middle mouse button
|
|
|
- if (node !== undefined) {
|
|
|
+ if (mouseUpNode !== undefined) {
|
|
|
// middle mouse button click on node -> delete node (and incoming/outgoing edges)
|
|
|
- return node.obj.getDeltasForDelete();
|
|
|
+ return mouseUpNode.obj.getDeltasForDelete();
|
|
|
}
|
|
|
}
|
|
|
return [];
|
|
@@ -128,14 +136,13 @@ export class EditableGraph extends React.Component<EditableGraphProps, EditableG
|
|
|
|
|
|
render() {
|
|
|
return (
|
|
|
- <>
|
|
|
- <Graph
|
|
|
- graph={this.props.graph}
|
|
|
- forces={this.props.forces}
|
|
|
- mouseDownHandler={this.mouseDownHandler}
|
|
|
- mouseUpHandler={this.mouseUpHandler}
|
|
|
- />
|
|
|
- </>
|
|
|
+ <Graph
|
|
|
+ graph={this.props.graph}
|
|
|
+ forces={this.props.forces}
|
|
|
+
|
|
|
+ mouseDownHandler={this.mouseDownHandler}
|
|
|
+ mouseUpHandler={this.mouseUpHandler}
|
|
|
+ />
|
|
|
);
|
|
|
}
|
|
|
|