fix node in panel sync

This commit is contained in:
hjlarry 2026-01-19 18:01:43 +08:00
parent 995d5ccf66
commit 805bb7c468
1 changed files with 36 additions and 1 deletions

View File

@ -890,13 +890,48 @@ export class CollaborationManager {
this.pendingGraphImportEmit = true
requestAnimationFrame(() => {
this.pendingGraphImportEmit = false
const mergedNodes = this.mergeLocalNodeState(this.getNodes())
this.eventEmitter.emit('graphImport', {
nodes: this.getNodes(),
nodes: mergedNodes,
edges: this.getEdges(),
})
})
}
private mergeLocalNodeState(nodes: Node[]): Node[] {
const reactFlowStore = this.reactFlowStore
const state = reactFlowStore?.getState()
const localNodes = state?.getNodes() || []
if (localNodes.length === 0)
return nodes
const localNodesMap = new Map(localNodes.map(node => [node.id, node]))
return nodes.map((node) => {
const localNode = localNodesMap.get(node.id)
if (!localNode)
return node
const nextNode = cloneDeep(node)
const nextData = { ...(nextNode.data || {}) } as Node['data']
const nextDataRecord = nextData as Record<string, unknown>
const localData = localNode.data as Record<string, unknown> | undefined
if (localData) {
Object.entries(localData).forEach(([key, value]) => {
if (key === 'selected' || key.startsWith('_'))
nextDataRecord[key] = value
})
}
if (!Object.prototype.hasOwnProperty.call(nextDataRecord, 'selected') && localNode.selected !== undefined)
nextDataRecord.selected = localNode.selected
nextNode.data = nextData
return nextNode
})
}
private setupSocketEventListeners(socket: Socket): void {
socket.on('collaboration_update', (update: CollaborationUpdate) => {
if (update.type === 'mouse_move') {