add interfaces for bounds mutations

This commit is contained in:
bymyself
2025-09-09 17:07:49 -07:00
parent d39bf36ce0
commit ea93135dbb
3 changed files with 21 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ import type {
LayoutOperation,
MoveNodeOperation,
MoveRerouteOperation,
NodeBoundsUpdate,
ResizeNodeOperation,
SetNodeZIndexOperation
} from '@/renderer/core/layout/types'
@@ -1429,9 +1430,7 @@ class LayoutStoreImpl implements LayoutStore {
/**
* Batch update node bounds using Yjs transaction for atomicity.
*/
batchUpdateNodeBounds(
updates: Array<{ nodeId: NodeId; bounds: Bounds }>
): void {
batchUpdateNodeBounds(updates: NodeBoundsUpdate[]): void {
if (updates.length === 0) return
// Set source to Vue for these DOM-driven updates

View File

@@ -31,6 +31,11 @@ export interface Bounds {
height: number
}
export interface NodeBoundsUpdate {
nodeId: NodeId
bounds: Bounds
}
export type NodeId = string
export type LinkId = number
export type RerouteId = number

View File

@@ -10,9 +10,20 @@
*/
import { getCurrentInstance, onMounted, onUnmounted } from 'vue'
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
import type { Bounds, NodeId } from '@/renderer/core/layout/types'
/**
* Generic update item for element bounds tracking
*/
interface ElementBoundsUpdate {
/** Element identifier (could be nodeId, widgetId, slotId, etc.) */
id: string
/** Updated bounds */
bounds: Bounds
}
/**
* Configuration for different types of tracked elements
*/
@@ -20,7 +31,7 @@ interface ElementTrackingConfig {
/** Data attribute name (e.g., 'nodeId') */
dataAttribute: string
/** Handler for processing bounds updates */
updateHandler: (updates: Array<{ id: string; bounds: Bounds }>) => void
updateHandler: (updates: ElementBoundsUpdate[]) => void
}
/**
@@ -45,7 +56,7 @@ const trackingConfigs: Map<string, ElementTrackingConfig> = new Map([
// Single ResizeObserver instance for all Vue elements
const resizeObserver = new ResizeObserver((entries) => {
// Group updates by element type
const updatesByType = new Map<string, Array<{ id: string; bounds: Bounds }>>()
const updatesByType = new Map<string, ElementBoundsUpdate[]>()
for (const entry of entries) {
if (!(entry.target instanceof HTMLElement)) continue
@@ -73,7 +84,7 @@ const resizeObserver = new ResizeObserver((entries) => {
x: rect.left,
y: rect.top,
width,
height: height-LiteGraph.NODE_TITLE_HEIGHT
height: height - LiteGraph.NODE_TITLE_HEIGHT
}
if (!updatesByType.has(elementType)) {