@d34dman/flowdrop 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -72,16 +72,25 @@
|
|
|
72
72
|
// Track the workflow ID we're currently editing to detect workflow switches
|
|
73
73
|
let currentWorkflowId: string | null = null;
|
|
74
74
|
|
|
75
|
+
// Track the last store value written by this editor to distinguish
|
|
76
|
+
// external programmatic changes from our own echoed writes
|
|
77
|
+
let lastEditorStoreValue: Workflow | null = null;
|
|
78
|
+
|
|
75
79
|
// Initialize currentWorkflow from global store
|
|
76
|
-
//
|
|
80
|
+
// Sync on workflow ID change (new workflow loaded) or external programmatic changes
|
|
77
81
|
$effect(() => {
|
|
78
82
|
if ($workflowStore) {
|
|
79
83
|
const storeWorkflowId = $workflowStore.id;
|
|
80
84
|
|
|
81
|
-
// Sync on initial load or when a different workflow is loaded
|
|
82
85
|
if (currentWorkflowId !== storeWorkflowId) {
|
|
86
|
+
// New workflow loaded
|
|
83
87
|
currentWorkflow = $workflowStore;
|
|
84
88
|
currentWorkflowId = storeWorkflowId;
|
|
89
|
+
lastEditorStoreValue = null;
|
|
90
|
+
} else if ($workflowStore !== lastEditorStoreValue) {
|
|
91
|
+
// External programmatic change (e.g. addEdge, updateNode, updateEdges)
|
|
92
|
+
// The store value differs from what this editor last wrote, so sync it
|
|
93
|
+
currentWorkflow = $workflowStore;
|
|
85
94
|
}
|
|
86
95
|
} else if (currentWorkflow !== null) {
|
|
87
96
|
// Store was cleared
|
|
@@ -95,6 +104,8 @@
|
|
|
95
104
|
setOnRestoreCallback((restoredWorkflow: Workflow) => {
|
|
96
105
|
// Directly update local state (bypass store sync effect)
|
|
97
106
|
currentWorkflow = restoredWorkflow;
|
|
107
|
+
// Mark as our own write so sync effect doesn't re-process it
|
|
108
|
+
lastEditorStoreValue = restoredWorkflow;
|
|
98
109
|
// Also update the store without triggering history
|
|
99
110
|
workflowActions.restoreFromHistory(restoredWorkflow);
|
|
100
111
|
});
|
|
@@ -207,6 +218,7 @@
|
|
|
207
218
|
*/
|
|
208
219
|
const updateGlobalStore = throttle((): void => {
|
|
209
220
|
if (currentWorkflow) {
|
|
221
|
+
lastEditorStoreValue = currentWorkflow;
|
|
210
222
|
workflowActions.updateWorkflow(currentWorkflow);
|
|
211
223
|
}
|
|
212
224
|
}, 16);
|