feat: init
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import type { NodeInstance, Socket } from "@nodarium/types";
|
import type { NodeInstance, Socket } from "@nodarium/types";
|
||||||
import { getContext, setContext } from "svelte";
|
import { getContext, setContext } from "svelte";
|
||||||
import { SvelteSet } from "svelte/reactivity";
|
import { SvelteMap, SvelteSet } from "svelte/reactivity";
|
||||||
import type { GraphManager } from "./graph-manager.svelte";
|
import type { GraphManager } from "./graph-manager.svelte";
|
||||||
import type { OrthographicCamera } from "three";
|
import type { Mesh, OrthographicCamera, Vector3 } from "three";
|
||||||
|
|
||||||
|
|
||||||
const graphStateKey = Symbol("graph-state");
|
const graphStateKey = Symbol("graph-state");
|
||||||
@@ -46,6 +46,8 @@ export class GraphState {
|
|||||||
width = $state(100);
|
width = $state(100);
|
||||||
height = $state(100);
|
height = $state(100);
|
||||||
|
|
||||||
|
edgeGeometries = new SvelteMap<string, { geo: Mesh, points: Vector3[] }>();
|
||||||
|
|
||||||
wrapper = $state<HTMLDivElement>(null!);
|
wrapper = $state<HTMLDivElement>(null!);
|
||||||
rect: DOMRect = $derived(
|
rect: DOMRect = $derived(
|
||||||
(this.wrapper && this.width && this.height) ? this.wrapper.getBoundingClientRect() : new DOMRect(0, 0, 0, 0),
|
(this.wrapper && this.width && this.height) ? this.wrapper.getBoundingClientRect() : new DOMRect(0, 0, 0, 0),
|
||||||
@@ -97,6 +99,14 @@ export class GraphState {
|
|||||||
|
|
||||||
isBodyFocused = () => document?.activeElement?.nodeName !== "INPUT";
|
isBodyFocused = () => document?.activeElement?.nodeName !== "INPUT";
|
||||||
|
|
||||||
|
setEdgeGeometry(edgeId: string, edgeGeometry: { geo: Mesh, points: Vector3[] }) {
|
||||||
|
this.edgeGeometries.set(edgeId, edgeGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeEdgeGeometry(edgeId: string) {
|
||||||
|
this.edgeGeometries.delete(edgeId);
|
||||||
|
}
|
||||||
|
|
||||||
updateNodePosition(node: NodeInstance) {
|
updateNodePosition(node: NodeInstance) {
|
||||||
if (
|
if (
|
||||||
node.state.x === node.position[0] &&
|
node.state.x === node.position[0] &&
|
||||||
|
|||||||
@@ -112,16 +112,38 @@ export class FileDropEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EdgeInteractionManager {
|
||||||
|
constructor(
|
||||||
|
private graph: GraphManager,
|
||||||
|
private state: GraphState) { };
|
||||||
|
|
||||||
|
handleMouseDown() {
|
||||||
|
const edges = this.graph.edges;
|
||||||
|
console.log(edges)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseMove() {
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseUp() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export class MouseEventManager {
|
export class MouseEventManager {
|
||||||
|
|
||||||
|
edgeInteractionManager: EdgeInteractionManager
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private graph: GraphManager,
|
private graph: GraphManager,
|
||||||
private state: GraphState
|
private state: GraphState
|
||||||
) { }
|
) {
|
||||||
|
|
||||||
|
this.edgeInteractionManager = new EdgeInteractionManager(graph, state);
|
||||||
|
}
|
||||||
|
|
||||||
handleMouseUp(event: MouseEvent) {
|
handleMouseUp(event: MouseEvent) {
|
||||||
|
this.edgeInteractionManager.handleMouseUp();
|
||||||
this.state.isPanning = false;
|
this.state.isPanning = false;
|
||||||
if (!this.state.mouseDown) return;
|
if (!this.state.mouseDown) return;
|
||||||
|
|
||||||
@@ -312,6 +334,7 @@ export class MouseEventManager {
|
|||||||
this.state.activeNodeId = clickedNodeId;
|
this.state.activeNodeId = clickedNodeId;
|
||||||
this.state.clearSelection();
|
this.state.clearSelection();
|
||||||
}
|
}
|
||||||
|
this.edgeInteractionManager.handleMouseDown();
|
||||||
} else if (event.ctrlKey) {
|
} else if (event.ctrlKey) {
|
||||||
this.state.boxSelection = true;
|
this.state.boxSelection = true;
|
||||||
}
|
}
|
||||||
@@ -397,6 +420,7 @@ export class MouseEventManager {
|
|||||||
|
|
||||||
// here we are handling dragging of nodes
|
// here we are handling dragging of nodes
|
||||||
if (this.state.activeNodeId !== -1 && this.state.mouseDownNodeId !== -1) {
|
if (this.state.activeNodeId !== -1 && this.state.mouseDownNodeId !== -1) {
|
||||||
|
this.edgeInteractionManager.handleMouseMove();
|
||||||
const node = this.graph.getNode(this.state.activeNodeId);
|
const node = this.graph.getNode(this.state.activeNodeId);
|
||||||
if (!node || event.buttons !== 1) return;
|
if (!node || event.buttons !== 1) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user