mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
Removed old files
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
import { cn } from '@/lib/utils'
|
||||
import { CoordinateTransformer } from '@/app/w/lib/coordinates'
|
||||
import { useState, useCallback, useEffect } from 'react'
|
||||
|
||||
interface ConnectionPointProps {
|
||||
position: 'top' | 'bottom'
|
||||
}
|
||||
|
||||
interface ConnectionLine {
|
||||
start: { x: number; y: number }
|
||||
end: { x: number; y: number }
|
||||
}
|
||||
|
||||
export function ConnectionPoint({ position }: ConnectionPointProps) {
|
||||
const [isDrawing, setIsDrawing] = useState(false)
|
||||
const [line, setLine] = useState<ConnectionLine | null>(null)
|
||||
|
||||
const handleMouseDown = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
|
||||
e.stopPropagation()
|
||||
|
||||
const canvasElement = e.currentTarget.closest(
|
||||
'[style*="transform"]'
|
||||
) as HTMLElement
|
||||
if (!canvasElement) return
|
||||
|
||||
// Get raw client coordinates
|
||||
const startPoint = {
|
||||
x: e.clientX,
|
||||
y: e.clientY,
|
||||
}
|
||||
|
||||
// Use the same conversion pattern as drag and drop
|
||||
const canvasPoint = CoordinateTransformer.viewportToCanvas(
|
||||
CoordinateTransformer.clientToViewport(startPoint),
|
||||
canvasElement
|
||||
)
|
||||
|
||||
setIsDrawing(true)
|
||||
setLine({
|
||||
start: canvasPoint,
|
||||
end: canvasPoint,
|
||||
})
|
||||
}, [])
|
||||
|
||||
const handleMouseMove = useCallback(
|
||||
(e: MouseEvent) => {
|
||||
if (!isDrawing || !line) return
|
||||
|
||||
const canvasElement = document.querySelector(
|
||||
'[style*="transform"]'
|
||||
) as HTMLElement
|
||||
if (!canvasElement) return
|
||||
|
||||
// Convert current mouse position to canvas coordinates
|
||||
const currentPoint = CoordinateTransformer.viewportToCanvas(
|
||||
CoordinateTransformer.clientToViewport({
|
||||
x: e.clientX,
|
||||
y: e.clientY,
|
||||
}),
|
||||
canvasElement
|
||||
)
|
||||
|
||||
setLine((prev) =>
|
||||
prev
|
||||
? {
|
||||
...prev,
|
||||
end: currentPoint,
|
||||
}
|
||||
: null
|
||||
)
|
||||
},
|
||||
[isDrawing, line]
|
||||
)
|
||||
|
||||
const handleMouseUp = useCallback(() => {
|
||||
setIsDrawing(false)
|
||||
setLine(null)
|
||||
}, [])
|
||||
|
||||
// Add and remove global mouse event listeners
|
||||
useEffect(() => {
|
||||
if (isDrawing) {
|
||||
document.addEventListener('mousemove', handleMouseMove)
|
||||
document.addEventListener('mouseup', handleMouseUp)
|
||||
return () => {
|
||||
document.removeEventListener('mousemove', handleMouseMove)
|
||||
document.removeEventListener('mouseup', handleMouseUp)
|
||||
}
|
||||
}
|
||||
}, [isDrawing, handleMouseMove, handleMouseUp])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
data-connection-point
|
||||
onMouseDown={handleMouseDown}
|
||||
className={cn(
|
||||
'absolute left-1/2 -translate-x-1/2 w-3 h-3',
|
||||
'bg-white rounded-full border opacity-0 group-hover:opacity-100',
|
||||
'transition-opacity duration-200 cursor-crosshair hover:border-blue-500',
|
||||
'hover:scale-110 hover:shadow-sm',
|
||||
position === 'top'
|
||||
? '-translate-y-1/2 top-0'
|
||||
: 'translate-y-1/2 bottom-0'
|
||||
)}
|
||||
/>
|
||||
{line && (
|
||||
<svg
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
zIndex: 9999,
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
<line
|
||||
x1={line.start.x}
|
||||
y1={line.start.y}
|
||||
x2={line.end.x}
|
||||
y2={line.end.y}
|
||||
stroke="rgb(59 130 246)"
|
||||
strokeWidth="2"
|
||||
strokeDasharray="5,5"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { BlockConfig, SubBlockConfig } from '../../types/block'
|
||||
import { SubBlock } from './components/sub-block/sub-block'
|
||||
import { ConnectionPoint } from './components/connection/connection-point'
|
||||
import { SubBlock } from './sub-block/sub-block'
|
||||
import { Handle, Position } from 'reactflow'
|
||||
|
||||
interface WorkflowBlockProps {
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
* Represents a point in 2D space
|
||||
*/
|
||||
interface Point {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the current transform state of the canvas
|
||||
*/
|
||||
interface CanvasTransform {
|
||||
scale: number
|
||||
translateX: number
|
||||
translateY: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility class for handling coordinate transformations in the workflow
|
||||
*/
|
||||
export class CoordinateTransformer {
|
||||
private static readonly SIDEBAR_WIDTH = 344
|
||||
private static readonly HEADER_HEIGHT = 56
|
||||
|
||||
/**
|
||||
* Gets the current transform state from a canvas element
|
||||
*/
|
||||
static getCanvasTransform(element: HTMLElement): CanvasTransform {
|
||||
const matrix = new DOMMatrix(window.getComputedStyle(element).transform)
|
||||
return {
|
||||
scale: matrix.a,
|
||||
translateX: matrix.e,
|
||||
translateY: matrix.f,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts viewport coordinates to canvas coordinates
|
||||
*/
|
||||
static viewportToCanvas(point: Point, canvasElement: HTMLElement): Point {
|
||||
const matrix = new DOMMatrix(window.getComputedStyle(canvasElement).transform)
|
||||
const domPoint = new DOMPoint(point.x, point.y)
|
||||
const transformed = domPoint.matrixTransform(matrix.inverse())
|
||||
|
||||
return {
|
||||
x: transformed.x,
|
||||
y: transformed.y,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts canvas coordinates to viewport coordinates
|
||||
*/
|
||||
static canvasToViewport(point: Point, canvasElement: HTMLElement): Point {
|
||||
const matrix = new DOMMatrix(window.getComputedStyle(canvasElement).transform)
|
||||
const domPoint = new DOMPoint(point.x, point.y)
|
||||
const transformed = domPoint.matrixTransform(matrix)
|
||||
|
||||
return {
|
||||
x: transformed.x,
|
||||
y: transformed.y,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts client coordinates to viewport coordinates by removing sidebar and header offsets
|
||||
*/
|
||||
static clientToViewport(point: Point): Point {
|
||||
return {
|
||||
x: point.x - this.SIDEBAR_WIDTH,
|
||||
y: point.y - this.HEADER_HEIGHT,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the viewport dimensions
|
||||
*/
|
||||
static getViewportDimensions(): { width: number; height: number } {
|
||||
return {
|
||||
width: window.innerWidth - this.SIDEBAR_WIDTH,
|
||||
height: window.innerHeight - this.HEADER_HEIGHT,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relative position of an element within the canvas
|
||||
*/
|
||||
static getElementCanvasPosition(element: HTMLElement, canvasElement: HTMLElement): Point {
|
||||
const rect = element.getBoundingClientRect()
|
||||
const point = {
|
||||
x: rect.left,
|
||||
y: rect.top,
|
||||
}
|
||||
|
||||
return this.viewportToCanvas(this.clientToViewport(point), canvasElement)
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the distance between two points accounting for canvas transform
|
||||
*/
|
||||
static getTransformedDistance(point1: Point, point2: Point, canvasElement: HTMLElement): Point {
|
||||
const transform = this.getCanvasTransform(canvasElement)
|
||||
return {
|
||||
x: (point2.x - point1.x) / transform.scale,
|
||||
y: (point2.y - point1.y) / transform.scale,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user