@bian-womp/spark-workbench 0.1.19 → 0.1.20

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
@@ -1960,7 +1960,7 @@ const WorkbenchCanvas = React.forwardRef(({ showValues, toString, toElement }, r
1960
1960
  return (jsxRuntime.jsx("div", { className: "w-full h-full", onContextMenu: onContextMenu, children: jsxRuntime.jsxs(ReactFlow, { nodes: nodes, edges: edges, nodeTypes: nodeTypes, selectionOnDrag: true, onConnect: onConnect, onEdgesChange: onEdgesChange, onEdgesDelete: onEdgesDelete, onNodesDelete: onNodesDelete, onNodesChange: onNodesChange, onSelectionChange: onSelectionChange, deleteKeyCode: ["Backspace", "Delete"], fitView: true, onInit: (inst) => (rfInstanceRef.current = inst), children: [jsxRuntime.jsx(ReactFlow.Background, {}), jsxRuntime.jsx(ReactFlow.MiniMap, {}), jsxRuntime.jsx(ReactFlow.Controls, {}), jsxRuntime.jsx(DefaultContextMenu, { open: menuOpen, clientPos: menuPos, onAdd: addNodeAt, onClose: () => setMenuOpen(false) }), jsxRuntime.jsx(NodeContextMenu, { open: nodeMenuOpen, clientPos: nodeMenuPos, nodeId: nodeAtMenu, onClose: () => setNodeMenuOpen(false) })] }) }));
1961
1961
  });
1962
1962
 
1963
- function WorkbenchStudioCanvas({ setRegistry, autoScroll, onAutoScrollChange, example, onExampleChange, engine, onEngineChange, backendKind, onBackendKindChange, httpBaseUrl, onHttpBaseUrlChange, wsUrl, onWsUrlChange, debug, onDebugChange, showValues, onShowValuesChange, hideWorkbench, onHideWorkbenchChange, overrides, }) {
1963
+ function WorkbenchStudioCanvas({ setRegistry, autoScroll, onAutoScrollChange, example, onExampleChange, engine, onEngineChange, backendKind, onBackendKindChange, httpBaseUrl, onHttpBaseUrlChange, wsUrl, onWsUrlChange, debug, onDebugChange, showValues, onShowValuesChange, hideWorkbench, onHideWorkbenchChange, overrides, onInit, onChange, }) {
1964
1964
  const { wb, runner, registry, def, selectedNodeId, runAutoLayout } = useWorkbenchContext();
1965
1965
  const selectedNode = def.nodes.find((n) => n.nodeId === selectedNodeId);
1966
1966
  const selectedDesc = selectedNode
@@ -2009,6 +2009,54 @@ function WorkbenchStudioCanvas({ setRegistry, autoScroll, onAutoScrollChange, ex
2009
2009
  const lastAutoLaunched = React.useRef(undefined);
2010
2010
  const autoLayoutRan = React.useRef(false);
2011
2011
  const canvasRef = React.useRef(null);
2012
+ // Expose init callback with setInitialGraph helper
2013
+ const initCalled = React.useRef(false);
2014
+ React.useEffect(() => {
2015
+ if (initCalled.current)
2016
+ return;
2017
+ initCalled.current = true;
2018
+ if (!onInit)
2019
+ return;
2020
+ const setInitialGraph = async (d, inputs) => {
2021
+ await wb.load(d);
2022
+ try {
2023
+ runner.build(wb.export());
2024
+ }
2025
+ catch { }
2026
+ if (inputs) {
2027
+ for (const [nodeId, map] of Object.entries(inputs)) {
2028
+ runner.setInputs(nodeId, map);
2029
+ }
2030
+ }
2031
+ runAutoLayout();
2032
+ };
2033
+ onInit({ wb, runner, setInitialGraph });
2034
+ }, [onInit, wb, runner, runAutoLayout]);
2035
+ // Expose change callback on graph/value changes
2036
+ React.useEffect(() => {
2037
+ if (!onChange)
2038
+ return;
2039
+ const off1 = wb.on("graphChanged", () => {
2040
+ try {
2041
+ const cur = wb.export();
2042
+ const inputs = runner.getInputs(cur);
2043
+ onChange({ def: cur, inputs });
2044
+ }
2045
+ catch { }
2046
+ });
2047
+ const off2 = runner.on("value", () => {
2048
+ try {
2049
+ const cur = wb.export();
2050
+ const inputs = runner.getInputs(cur);
2051
+ onChange({ def: cur, inputs });
2052
+ }
2053
+ catch { }
2054
+ });
2055
+ return () => {
2056
+ off1();
2057
+ off2();
2058
+ };
2059
+ }, [wb, runner, onChange]);
2012
2060
  const applyExample = React.useCallback(async (key) => {
2013
2061
  if (runner.isRunning()) {
2014
2062
  alert(`Stop engine before switching example.`);
@@ -2352,7 +2400,7 @@ function WorkbenchStudioCanvas({ setRegistry, autoScroll, onAutoScrollChange, ex
2352
2400
  }
2353
2401
  }, disabled: !engine, children: "Start" })), jsxRuntime.jsx("button", { className: "border border-gray-300 rounded px-2 py-1.5", onClick: runAutoLayout, children: "Auto Layout" }), jsxRuntime.jsx("button", { className: "ml-2 border border-gray-300 rounded px-2 py-1.5", onClick: () => canvasRef.current?.fitView?.(), title: "Fit View", children: "Fit View" }), jsxRuntime.jsx("button", { className: "ml-2 border border-gray-300 rounded px-2 py-1.5", onClick: downloadGraph, children: "Download Graph" }), jsxRuntime.jsxs("label", { className: "ml-2 flex items-center gap-1", children: [jsxRuntime.jsx("input", { type: "checkbox", checked: debug, onChange: (e) => onDebugChange(e.target.checked) }), jsxRuntime.jsx("span", { children: "Debug events" })] }), jsxRuntime.jsxs("label", { className: "ml-2 flex items-center gap-1", children: [jsxRuntime.jsx("input", { type: "checkbox", checked: showValues, onChange: (e) => onShowValuesChange(e.target.checked) }), jsxRuntime.jsx("span", { children: "Show values in nodes" })] })] }), jsxRuntime.jsxs("div", { className: "flex flex-1 min-h-0", children: [jsxRuntime.jsx("div", { className: "flex-1 min-w-0", children: jsxRuntime.jsx(WorkbenchCanvas, { ref: canvasRef, showValues: showValues, toString: toString, toElement: toElement }) }), jsxRuntime.jsx(Inspector, { setInput: setInput, debug: debug, autoScroll: autoScroll, hideWorkbench: hideWorkbench, onAutoScrollChange: onAutoScrollChange, onHideWorkbenchChange: onHideWorkbenchChange, toString: toString, toElement: toElement })] })] }));
2354
2402
  }
2355
- function WorkbenchStudio({ engine, onEngineChange, example, onExampleChange, backendKind, onBackendKindChange, httpBaseUrl, onHttpBaseUrlChange, wsUrl, onWsUrlChange, debug, onDebugChange, showValues, onShowValuesChange, hideWorkbench, onHideWorkbenchChange, autoScroll, onAutoScrollChange, overrides, }) {
2403
+ function WorkbenchStudio({ engine, onEngineChange, example, onExampleChange, backendKind, onBackendKindChange, httpBaseUrl, onHttpBaseUrlChange, wsUrl, onWsUrlChange, debug, onDebugChange, showValues, onShowValuesChange, hideWorkbench, onHideWorkbenchChange, autoScroll, onAutoScrollChange, overrides, onInit, onChange, }) {
2356
2404
  const [registry, setRegistry] = React.useState(sparkGraph.createSimpleGraphRegistry());
2357
2405
  const [wb] = React.useState(() => new InMemoryWorkbench({ ui: new DefaultUIExtensionRegistry() }));
2358
2406
  const runner = React.useMemo(() => {
@@ -2373,7 +2421,7 @@ function WorkbenchStudio({ engine, onEngineChange, example, onExampleChange, bac
2373
2421
  if (runner.isRunning())
2374
2422
  runner.dispose();
2375
2423
  onBackendKindChange(v);
2376
- }, httpBaseUrl: httpBaseUrl, onHttpBaseUrlChange: onHttpBaseUrlChange, wsUrl: wsUrl, onWsUrlChange: onWsUrlChange, debug: debug, onDebugChange: onDebugChange, showValues: showValues, onShowValuesChange: onShowValuesChange, hideWorkbench: hideWorkbench, onHideWorkbenchChange: onHideWorkbenchChange, overrides: overrides }) }));
2424
+ }, httpBaseUrl: httpBaseUrl, onHttpBaseUrlChange: onHttpBaseUrlChange, wsUrl: wsUrl, onWsUrlChange: onWsUrlChange, debug: debug, onDebugChange: onDebugChange, showValues: showValues, onShowValuesChange: onShowValuesChange, hideWorkbench: hideWorkbench, onHideWorkbenchChange: onHideWorkbenchChange, overrides: overrides, onInit: onInit, onChange: onChange }) }));
2377
2425
  }
2378
2426
 
2379
2427
  exports.AbstractWorkbench = AbstractWorkbench;