From bff77742161bba1487ede4ce5c5482f9fc1a60ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 07:21:16 +0000 Subject: [PATCH 1/3] Initial plan From b5870923853ae84d3184d18dc4a7f669bb7d8bd0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 07:29:59 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=92=A4=E9=94=80=E9=87=8D=E5=81=9A?= =?UTF-8?q?=E6=97=B6=E8=A1=A5=E5=8F=91=E8=8A=82=E7=82=B9=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: CraneReturn <127602190+CraneReturn@users.noreply.github.com> --- packages/core/__tests__/logicflow.test.ts | 41 ++++++++++++++++++++++- packages/core/src/LogicFlow.tsx | 30 ++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/packages/core/__tests__/logicflow.test.ts b/packages/core/__tests__/logicflow.test.ts index 66c3e557a..b1b762c44 100644 --- a/packages/core/__tests__/logicflow.test.ts +++ b/packages/core/__tests__/logicflow.test.ts @@ -1,4 +1,4 @@ -import { BaseNode, BaseNodeModel, Keyboard } from '../src' +import { BaseNode, BaseNodeModel, EventType, Keyboard } from '../src' import LogicFlow from '../src/LogicFlow' // import Tool from '../src/tool' /** @@ -464,6 +464,45 @@ describe('logicflow/apis', () => { }) }) + test('emit node properties change when undo/redo', async () => { + const dom = document.createElement('div') + dom.id = 'history-graph' + document.body.appendChild(dom) + const historyLf = new LogicFlow({ + container: dom, + }) + historyLf.renderRawData(rawData) + historyLf.history.waitTime = 0 + + const propertiesChangeHandler = jest.fn() + historyLf.on(EventType.NODE_PROPERTIES_CHANGE, propertiesChangeHandler) + historyLf.setProperties('node1', { + width: 160, + height: 80, + }) + await new Promise((resolve) => setTimeout(resolve, 20)) + + propertiesChangeHandler.mockClear() + historyLf.undo() + expect(propertiesChangeHandler).toBeCalledWith( + expect.objectContaining({ + id: 'node1', + preProperties: { width: 160, height: 80 }, + properties: {}, + }), + ) + + propertiesChangeHandler.mockClear() + historyLf.redo() + expect(propertiesChangeHandler).toBeCalledWith( + expect.objectContaining({ + id: 'node1', + preProperties: {}, + properties: { width: 160, height: 80 }, + }), + ) + }) + test('delete properties', () => { lf.renderRawData(rawData) lf.deleteProperty('node1', 'a') diff --git a/packages/core/src/LogicFlow.tsx b/packages/core/src/LogicFlow.tsx index fb6257acc..96fd95ee8 100644 --- a/packages/core/src/LogicFlow.tsx +++ b/packages/core/src/LogicFlow.tsx @@ -1,5 +1,5 @@ import { ComponentType, createElement as h, render } from 'preact/compat' -import { cloneDeep, forEach, indexOf, isNil } from 'lodash-es' +import { cloneDeep, forEach, indexOf, isEqual, isNil } from 'lodash-es' import { observer } from '.' import { Options as LFOptions } from './options' import * as _Model from './model' @@ -1160,16 +1160,42 @@ export class LogicFlow { /********************************************************* * History/Resize 相关方法 ********************************************************/ + private emitNodePropertiesChange( + preGraphData: GraphData, + curGraphData: GraphData, + ) { + const preNodeMap = new Map(preGraphData.nodes.map((node) => [node.id, node])) + forEach(curGraphData.nodes, (node) => { + const preNode = preNodeMap.get(node.id) + if (!preNode) return + const preProperties = (preNode.properties ?? {}) as Record + const properties = (node.properties ?? {}) as Record + if (isEqual(preProperties, properties)) return + const keys = Object.keys({ + ...preProperties, + ...properties, + }).filter((key) => !isEqual(preProperties[key], properties[key])) + this.graphModel.eventCenter.emit(EventType.NODE_PROPERTIES_CHANGE, { + id: node.id, + keys, + preProperties, + properties, + }) + }) + } + /** * 历史记录操作 * 返回上一步 */ undo() { if (!this.history.undoAble()) return + const preGraphData = this.graphModel.modelToGraphData() // formatData兼容vue数据 const graphData = formatData(this.history.undo()!) this.clearSelectElements() this.graphModel.graphDataToModel(graphData) + this.emitNodePropertiesChange(preGraphData, graphData) } /** @@ -1178,10 +1204,12 @@ export class LogicFlow { */ redo() { if (!this.history.redoAble()) return + const preGraphData = this.graphModel.modelToGraphData() // formatData兼容vue数据 const graphData = formatData(this.history.redo()!) this.clearSelectElements() this.graphModel.graphDataToModel(graphData) + this.emitNodePropertiesChange(preGraphData, graphData) } /** From 1a06d8112a64574d3cb6efa9fc88bb515ec134ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 07:32:30 +0000 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=E4=BC=98=E5=8C=96=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=8F=98=E6=9B=B4=20keys=20=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: CraneReturn <127602190+CraneReturn@users.noreply.github.com> --- packages/core/src/LogicFlow.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/LogicFlow.tsx b/packages/core/src/LogicFlow.tsx index 96fd95ee8..3a8eaa059 100644 --- a/packages/core/src/LogicFlow.tsx +++ b/packages/core/src/LogicFlow.tsx @@ -1171,10 +1171,9 @@ export class LogicFlow { const preProperties = (preNode.properties ?? {}) as Record const properties = (node.properties ?? {}) as Record if (isEqual(preProperties, properties)) return - const keys = Object.keys({ - ...preProperties, - ...properties, - }).filter((key) => !isEqual(preProperties[key], properties[key])) + const keys = Array.from( + new Set([...Object.keys(preProperties), ...Object.keys(properties)]), + ).filter((key) => !isEqual(preProperties[key], properties[key])) this.graphModel.eventCenter.emit(EventType.NODE_PROPERTIES_CHANGE, { id: node.id, keys,