mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
fix node in panel sync
This commit is contained in:
@ -890,13 +890,48 @@ export class CollaborationManager {
|
|||||||
this.pendingGraphImportEmit = true
|
this.pendingGraphImportEmit = true
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
this.pendingGraphImportEmit = false
|
this.pendingGraphImportEmit = false
|
||||||
|
const mergedNodes = this.mergeLocalNodeState(this.getNodes())
|
||||||
this.eventEmitter.emit('graphImport', {
|
this.eventEmitter.emit('graphImport', {
|
||||||
nodes: this.getNodes(),
|
nodes: mergedNodes,
|
||||||
edges: this.getEdges(),
|
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 {
|
private setupSocketEventListeners(socket: Socket): void {
|
||||||
socket.on('collaboration_update', (update: CollaborationUpdate) => {
|
socket.on('collaboration_update', (update: CollaborationUpdate) => {
|
||||||
if (update.type === 'mouse_move') {
|
if (update.type === 'mouse_move') {
|
||||||
|
|||||||
Reference in New Issue
Block a user