@bian-womp/spark-workbench 0.2.71 → 0.2.72

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.
package/lib/cjs/index.cjs CHANGED
@@ -381,6 +381,7 @@ class InMemoryWorkbench extends AbstractWorkbench {
381
381
  }
382
382
  setHistory(history) {
383
383
  this.historyState = history;
384
+ this.emit("historyChanged", { history });
384
385
  }
385
386
  getNodeRuntimeMetadata(nodeId) {
386
387
  return this.runtimeState?.nodes[nodeId];
@@ -4383,6 +4384,7 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
4383
4384
  const nodeValidation = validationByNode;
4384
4385
  const edgeValidation = validationByEdge.errors;
4385
4386
  const [registryVersion, setRegistryVersion] = React.useState(0);
4387
+ const [historyState, setHistoryState] = React.useState(wb.getHistory());
4386
4388
  const prevNodesRef = React.useRef([]);
4387
4389
  const prevEdgesRef = React.useRef([]);
4388
4390
  function retainStabilityById(prev, next, isSame) {
@@ -4728,6 +4730,12 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
4728
4730
  });
4729
4731
  return () => off();
4730
4732
  }, [runner]);
4733
+ React.useEffect(() => {
4734
+ const off = wb.on("historyChanged", (event) => {
4735
+ setHistoryState(event.history);
4736
+ });
4737
+ return () => off();
4738
+ }, [wb]);
4731
4739
  const nodeIds = React.useMemo(() => Array.from(registry.nodes.keys()), [registry, registryVersion]);
4732
4740
  const defaultContextMenuHandlers = React.useMemo(() => {
4733
4741
  // Get storage from override or use workbench's internal storage
@@ -4743,12 +4751,12 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement, get
4743
4751
  return;
4744
4752
  wb.pasteCopiedData(data, position, { commit: true, reason: "paste" });
4745
4753
  onCloseMenu();
4746
- }, runner, () => storage.get(), () => storage.set(null), wb.getHistory());
4754
+ }, runner, () => storage.get(), () => storage.set(null), historyState);
4747
4755
  if (overrides?.getDefaultContextMenuHandlers) {
4748
4756
  return overrides.getDefaultContextMenuHandlers(wb, baseHandlers);
4749
4757
  }
4750
4758
  return baseHandlers;
4751
- }, [addNodeAt, onCloseMenu, overrides, wb, runner]);
4759
+ }, [addNodeAt, onCloseMenu, overrides, wb, runner, historyState]);
4752
4760
  const selectionContextMenuHandlers = React.useMemo(() => {
4753
4761
  // Get storage from override or use workbench's internal storage
4754
4762
  const storage = overrides?.getCopiedDataStorage