-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from yojeek/2.0-subgraph-interface-nodes-posi…
…tioning Subgraph Interface Nodes positioning
- Loading branch information
Showing
3 changed files
with
125 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 67 additions & 26 deletions
93
packages/renderer-vue/src/graph/subgraphInterfaceNodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,80 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { defineNode, NodeInstanceOf, NodeInterface } from "@baklavajs/core"; | ||
import { INodeState, NodeInstanceOf, NodeInterface, Node } from "@baklavajs/core"; | ||
import { TextInputInterface } from "../nodeinterfaces"; | ||
|
||
export const SUBGRAPH_INPUT_NODE_TYPE = "__baklava_SubgraphInputNode"; | ||
export const SUBGRAPH_OUTPUT_NODE_TYPE = "__baklava_SubgraphOutputNode"; | ||
|
||
export interface ISubgraphInterfaceState<I, O> extends INodeState<I, O> { | ||
graphInterfaceId: string; | ||
} | ||
|
||
abstract class SubgraphInterfaceNode<I, O> extends Node<I, O> implements ISubgraphInterfaceNode { | ||
public graphInterfaceId: string; | ||
|
||
constructor() { | ||
super(); | ||
this.graphInterfaceId = uuidv4(); | ||
} | ||
|
||
onPlaced() { | ||
super.onPlaced(); | ||
|
||
this.initializeIo(); | ||
} | ||
|
||
save(): ISubgraphInterfaceState<I, O> { | ||
return { | ||
...super.save(), | ||
graphInterfaceId: this.graphInterfaceId, | ||
}; | ||
} | ||
|
||
load(state: ISubgraphInterfaceState<I, O>) { | ||
super.load(state as INodeState<I, O>); | ||
this.graphInterfaceId = state.graphInterfaceId; | ||
} | ||
} | ||
|
||
export interface ISubgraphInterfaceNode { | ||
graphInterfaceId: string; | ||
} | ||
|
||
export const SubgraphInputNode = defineNode({ | ||
type: SUBGRAPH_INPUT_NODE_TYPE, | ||
title: "Subgraph Input", | ||
inputs: { | ||
name: () => new TextInputInterface("Name", "Input").setPort(false), | ||
}, | ||
outputs: { | ||
placeholder: () => new NodeInterface("Connection", undefined), | ||
}, | ||
onCreate() { | ||
(this as unknown as ISubgraphInterfaceNode).graphInterfaceId = uuidv4(); | ||
}, | ||
}); | ||
|
||
export const SubgraphOutputNode = defineNode({ | ||
type: SUBGRAPH_OUTPUT_NODE_TYPE, | ||
title: "Subgraph Output", | ||
inputs: { | ||
name: () => new TextInputInterface("Name", "Output").setPort(false), | ||
placeholder: () => new NodeInterface("Connection", undefined), | ||
}, | ||
onCreate() { | ||
(this as unknown as ISubgraphInterfaceNode).graphInterfaceId = uuidv4(); | ||
}, | ||
}); | ||
interface SubgraphInputNodeInputs { | ||
name: string; | ||
} | ||
|
||
interface SubgraphInputNodeOutputs { | ||
placeholder: string; | ||
} | ||
|
||
export class SubgraphInputNode extends SubgraphInterfaceNode<SubgraphInputNodeInputs, SubgraphInputNodeOutputs> implements ISubgraphInterfaceNode{ | ||
public readonly type = SUBGRAPH_INPUT_NODE_TYPE; | ||
_title = "Subgraph Input"; | ||
public inputs = { | ||
name: new TextInputInterface("Name", "Input").setPort(false), | ||
}; | ||
public outputs = { | ||
placeholder: new NodeInterface("Connection", ''), | ||
}; | ||
} | ||
|
||
interface SubgraphOutputNodeInputs { | ||
name: string; | ||
placeholder: string; | ||
} | ||
|
||
interface SubgraphOutputNodeOutputs {} | ||
|
||
export class SubgraphOutputNode extends SubgraphInterfaceNode<SubgraphOutputNodeInputs, SubgraphOutputNodeOutputs> implements ISubgraphInterfaceNode{ | ||
public readonly type = SUBGRAPH_OUTPUT_NODE_TYPE; | ||
_title = "Subgraph Output"; | ||
public inputs = { | ||
name: new TextInputInterface("Name", "Output").setPort(false), | ||
placeholder: new NodeInterface("Connection", ''), | ||
}; | ||
public outputs = {}; | ||
} | ||
|
||
export type InputNode = NodeInstanceOf<typeof SubgraphInputNode> & ISubgraphInterfaceNode; | ||
export type OutputNode = NodeInstanceOf<typeof SubgraphOutputNode> & ISubgraphInterfaceNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters