@bian-womp/spark-workbench 0.2.80 → 0.2.82

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.
Files changed (37) hide show
  1. package/lib/cjs/index.cjs +81 -10
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/cjs/src/index.d.ts +2 -0
  4. package/lib/cjs/src/index.d.ts.map +1 -1
  5. package/lib/cjs/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
  6. package/lib/cjs/src/misc/load.d.ts.map +1 -1
  7. package/lib/cjs/src/misc/merge-utils.d.ts +7 -0
  8. package/lib/cjs/src/misc/merge-utils.d.ts.map +1 -0
  9. package/lib/cjs/src/misc/types.d.ts +14 -0
  10. package/lib/cjs/src/misc/types.d.ts.map +1 -0
  11. package/lib/cjs/src/runtime/AbstractGraphRunner.d.ts +1 -0
  12. package/lib/cjs/src/runtime/AbstractGraphRunner.d.ts.map +1 -1
  13. package/lib/cjs/src/runtime/IGraphRunner.d.ts +1 -1
  14. package/lib/cjs/src/runtime/IGraphRunner.d.ts.map +1 -1
  15. package/lib/cjs/src/runtime/LocalGraphRunner.d.ts +1 -0
  16. package/lib/cjs/src/runtime/LocalGraphRunner.d.ts.map +1 -1
  17. package/lib/cjs/src/runtime/RemoteGraphRunner.d.ts +5 -2
  18. package/lib/cjs/src/runtime/RemoteGraphRunner.d.ts.map +1 -1
  19. package/lib/esm/index.js +81 -11
  20. package/lib/esm/index.js.map +1 -1
  21. package/lib/esm/src/index.d.ts +2 -0
  22. package/lib/esm/src/index.d.ts.map +1 -1
  23. package/lib/esm/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
  24. package/lib/esm/src/misc/load.d.ts.map +1 -1
  25. package/lib/esm/src/misc/merge-utils.d.ts +7 -0
  26. package/lib/esm/src/misc/merge-utils.d.ts.map +1 -0
  27. package/lib/esm/src/misc/types.d.ts +14 -0
  28. package/lib/esm/src/misc/types.d.ts.map +1 -0
  29. package/lib/esm/src/runtime/AbstractGraphRunner.d.ts +1 -0
  30. package/lib/esm/src/runtime/AbstractGraphRunner.d.ts.map +1 -1
  31. package/lib/esm/src/runtime/IGraphRunner.d.ts +1 -1
  32. package/lib/esm/src/runtime/IGraphRunner.d.ts.map +1 -1
  33. package/lib/esm/src/runtime/LocalGraphRunner.d.ts +1 -0
  34. package/lib/esm/src/runtime/LocalGraphRunner.d.ts.map +1 -1
  35. package/lib/esm/src/runtime/RemoteGraphRunner.d.ts +5 -2
  36. package/lib/esm/src/runtime/RemoteGraphRunner.d.ts.map +1 -1
  37. package/package.json +4 -4
package/lib/cjs/index.cjs CHANGED
@@ -1174,9 +1174,9 @@ class LocalGraphRunner extends AbstractGraphRunner {
1174
1174
  this.build(payload.def);
1175
1175
  }
1176
1176
  this.setEnvironment?.(payload.environment || {}, { merge: false });
1177
- this.hydrate(payload);
1177
+ this.hydrate(payload, { dry: options?.dry });
1178
1178
  }
1179
- hydrate(snapshot) {
1179
+ hydrate(snapshot, opts) {
1180
1180
  // Hydrate via runtime for exact restore (this emits events on runtime emitter)
1181
1181
  this.runtime?.hydrate({
1182
1182
  inputs: snapshot.inputs || {},
@@ -1185,12 +1185,24 @@ class LocalGraphRunner extends AbstractGraphRunner {
1185
1185
  // Also emit directly from runner to ensure UI gets events even if engine isn't running
1186
1186
  for (const [nodeId, map] of Object.entries(snapshot.inputs || {})) {
1187
1187
  for (const [handle, value] of Object.entries(map || {})) {
1188
- this.emit("value", { nodeId, handle, value, io: "input" });
1188
+ this.emit("value", {
1189
+ nodeId,
1190
+ handle,
1191
+ value,
1192
+ io: "input",
1193
+ dry: opts?.dry,
1194
+ });
1189
1195
  }
1190
1196
  }
1191
1197
  for (const [nodeId, map] of Object.entries(snapshot.outputs || {})) {
1192
1198
  for (const [handle, value] of Object.entries(map || {})) {
1193
- this.emit("value", { nodeId, handle, value, io: "output" });
1199
+ this.emit("value", {
1200
+ nodeId,
1201
+ handle,
1202
+ value,
1203
+ io: "output",
1204
+ dry: opts?.dry,
1205
+ });
1194
1206
  }
1195
1207
  }
1196
1208
  }
@@ -1744,17 +1756,17 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1744
1756
  }
1745
1757
  async applySnapshotFull(payload, options) {
1746
1758
  // Hydrate local cache first so UI can display values immediately
1747
- this.hydrateValueCache(payload);
1759
+ this.hydrateValueCache(payload, { dry: options?.dry });
1748
1760
  // Then sync with backend
1749
1761
  const client = await this.ensureClient();
1750
- await client.applySnapshotFull(payload, options);
1762
+ await client.applySnapshotFull(payload, { skipBuild: options?.skipBuild });
1751
1763
  }
1752
1764
  /**
1753
1765
  * Hydrates the local valueCache from a snapshot and emits value events.
1754
1766
  * This ensures the UI can display inputs/outputs immediately without waiting
1755
1767
  * for value events from the remote backend.
1756
1768
  */
1757
- hydrateValueCache(snapshot) {
1769
+ hydrateValueCache(snapshot, opts) {
1758
1770
  // Hydrate inputs
1759
1771
  for (const [nodeId, map] of Object.entries(snapshot.inputs || {})) {
1760
1772
  for (const [handle, value] of Object.entries(map || {})) {
@@ -1762,7 +1774,13 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1762
1774
  io: "input",
1763
1775
  value,
1764
1776
  });
1765
- this.emit("value", { nodeId, handle, value, io: "input" });
1777
+ this.emit("value", {
1778
+ nodeId,
1779
+ handle,
1780
+ value,
1781
+ io: "input",
1782
+ dry: opts?.dry,
1783
+ });
1766
1784
  }
1767
1785
  }
1768
1786
  // Hydrate outputs
@@ -1772,7 +1790,13 @@ class RemoteGraphRunner extends AbstractGraphRunner {
1772
1790
  io: "output",
1773
1791
  value,
1774
1792
  });
1775
- this.emit("value", { nodeId, handle, value, io: "output" });
1793
+ this.emit("value", {
1794
+ nodeId,
1795
+ handle,
1796
+ value,
1797
+ io: "output",
1798
+ dry: opts?.dry,
1799
+ });
1776
1800
  }
1777
1801
  }
1778
1802
  }
@@ -2772,6 +2796,50 @@ async function upload(parsed, wb, runner) {
2772
2796
  }
2773
2797
  }
2774
2798
 
2799
+ /**
2800
+ * Merge UI state from source into target, remapping node IDs using nodeIdMap.
2801
+ * Preserves target state and adds/updates source state with remapped IDs.
2802
+ */
2803
+ function mergeUIState(targetUI, sourceUI, nodeIdMap) {
2804
+ const result = {
2805
+ ...targetUI,
2806
+ };
2807
+ if (!sourceUI)
2808
+ return result;
2809
+ // Merge positions (already handled by mergeSnapshotData, but included for completeness)
2810
+ if (sourceUI.positions) {
2811
+ result.positions = {
2812
+ ...(targetUI?.positions || {}),
2813
+ ...Object.fromEntries(Object.entries(sourceUI.positions).map(([oldId, pos]) => [
2814
+ nodeIdMap[oldId] || oldId,
2815
+ pos,
2816
+ ])),
2817
+ };
2818
+ }
2819
+ // Merge selection: remap node IDs and edge IDs
2820
+ if (sourceUI.selection) {
2821
+ const remappedNodes = (sourceUI.selection.nodes || [])
2822
+ .map((id) => nodeIdMap[id] || id)
2823
+ .filter((id) => id); // Filter out invalid mappings
2824
+ const remappedEdges = sourceUI.selection.edges || []; // Edge IDs don't need remapping typically
2825
+ result.selection = {
2826
+ nodes: [...(targetUI?.selection?.nodes || []), ...remappedNodes],
2827
+ edges: [...(targetUI?.selection?.edges || []), ...remappedEdges],
2828
+ };
2829
+ }
2830
+ // Merge nodeNames: remap node IDs
2831
+ if (sourceUI.nodeNames) {
2832
+ result.nodeNames = {
2833
+ ...(targetUI?.nodeNames || {}),
2834
+ ...Object.fromEntries(Object.entries(sourceUI.nodeNames).map(([oldId, name]) => [
2835
+ nodeIdMap[oldId] || oldId,
2836
+ name,
2837
+ ])),
2838
+ };
2839
+ }
2840
+ return result;
2841
+ }
2842
+
2775
2843
  const WorkbenchContext = React.createContext(null);
2776
2844
  function useWorkbenchContext() {
2777
2845
  const ctx = React.useContext(WorkbenchContext);
@@ -3060,6 +3128,8 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, overrides, uiVer
3060
3128
  wb.refreshValidation();
3061
3129
  };
3062
3130
  const offRunnerValue = runner.on("value", (e) => {
3131
+ if (e?.dry)
3132
+ return;
3063
3133
  const now = Date.now();
3064
3134
  if (e?.io === "input") {
3065
3135
  const nodeId = e.nodeId;
@@ -4293,7 +4363,7 @@ function DefaultNodeHeader({ id, typeId, title, validation, right, showId, onInv
4293
4363
  const [editValue, setEditValue] = React.useState("");
4294
4364
  const inputRef = React.useRef(null);
4295
4365
  // Use getNodeDisplayName if typeId is provided, otherwise use title prop
4296
- const displayName = typeId ? ctx.getNodeDisplayName(id) : (title ?? id);
4366
+ const displayName = typeId ? ctx.getNodeDisplayName(id) : title ?? id;
4297
4367
  const effectiveTypeId = typeId ?? title ?? id;
4298
4368
  // Get the default display name (without custom name) for comparison
4299
4369
  const getDefaultDisplayName = React.useCallback(() => {
@@ -5871,6 +5941,7 @@ exports.getHandleLayoutY = getHandleLayoutY;
5871
5941
  exports.getNodeBorderClassNames = getNodeBorderClassNames;
5872
5942
  exports.isValidViewport = isValidViewport;
5873
5943
  exports.layoutNode = layoutNode;
5944
+ exports.mergeUIState = mergeUIState;
5874
5945
  exports.preformatValueForDisplay = preformatValueForDisplay;
5875
5946
  exports.prettyHandle = prettyHandle;
5876
5947
  exports.resolveOutputDisplay = resolveOutputDisplay;