@lace-cloud/canvas 0.10.0 → 0.11.0

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/README.md CHANGED
@@ -47,6 +47,30 @@ createRoot(document.getElementById('root')!).render(
47
47
  );
48
48
  ```
49
49
 
50
+ `App` fills the viewport by default with `height="100vh"`. An embedded
51
+ canvas should live in a parent with an explicit height and opt into that
52
+ containing block with `height="100%"`:
53
+
54
+ ```tsx
55
+ <div style={{ height: 460 }}>
56
+ <App engine={engine} hostBridge={browserHostBridge} height="100%" />
57
+ </div>
58
+ ```
59
+
60
+ ### Viewport fitting
61
+
62
+ Three things fit the whole graph, and all three use the same options
63
+ (`padding: 0.2`, `duration: 300`):
64
+
65
+ - the first frame an engine delivers — including after the host swaps in
66
+ a new engine, so navigating between snapshots re-frames the graph
67
+ without remounting the canvas;
68
+ - xyflow's native **Fit View** control in the bottom-right cluster;
69
+ - a `fit-all` viewport intent that doesn't override padding or duration.
70
+
71
+ A `focus-node` intent frames one node instead (`padding: 1.2`), and any
72
+ intent may override padding and duration per dispatch.
73
+
50
74
  ## Read-only mode
51
75
 
52
76
  ```tsx
@@ -1,17 +1,16 @@
1
1
  /*
2
2
  * Canvas.css — xyflow (@xyflow/react) customisations for the Lace canvas.
3
3
  *
4
- * Colocated with Canvas.tsx (imported there) so both the VS Code webview
5
- * bundle and the Storybook canvas-stories build pick these rules up via
6
- * the React import chain. There is no separate global stylesheet for the
7
- * canvas — that was the source of the webview↔Storybook divergence.
4
+ * Colocated with Canvas.tsx (imported there) so every consumer — the VS
5
+ * Code webview bundle, the portal SPA, Storybook — picks these rules up
6
+ * via the React import chain. There is no separate global stylesheet for
7
+ * the canvas; a consumer that has to remember to import one gets a canvas
8
+ * that silently renders wrong.
8
9
  *
9
- * Layer ordering note:
10
- * xyflow ships its own stylesheet under @layer components. Our rules
11
- * below are unlayered, so they beat @layer rules without needing
12
- * !important. Only the rules that explicitly need to live inside
13
- * @layer components (e.g. the edge stroke override that competes with
14
- * the xyflow default) are placed there.
10
+ * Ordering note:
11
+ * Canvas.tsx imports xyflow's own stylesheet immediately before this
12
+ * one, and neither is layered, so at equal specificity these rules win
13
+ * on source order — no !important needed.
15
14
  */
16
15
 
17
16
  /* ── Pin handles (Blender-style typed I/O) ──
package/dist/index.cjs CHANGED
@@ -72,7 +72,8 @@ var import_react34 = require("@xyflow/react");
72
72
  var import_react35 = require("react");
73
73
 
74
74
  // src/Canvas.tsx
75
- var import_Canvas = require("./Canvas-IXCFWQNP.css");
75
+ var import_style = require("@xyflow/react/dist/style.css");
76
+ var import_Canvas = require("./Canvas-J6F7YHEK.css");
76
77
  var import_feedback = require("@lace-cloud/ui/feedback");
77
78
  var import_react30 = require("@xyflow/react");
78
79
  var import_react31 = require("react");
@@ -4148,6 +4149,7 @@ var nodeTypes = {
4148
4149
  moduleNode: ModuleNode_default,
4149
4150
  groupNode: GroupNode_default
4150
4151
  };
4152
+ var FIT_VIEW_OPTIONS = { padding: 0.2, duration: 300 };
4151
4153
  function CompositeEditor({
4152
4154
  view,
4153
4155
  readOnly,
@@ -4181,11 +4183,6 @@ function CompositeEditor({
4181
4183
  const nodesInitialized = xyflowInitialized || view.nodes.length === 0;
4182
4184
  const selectedIdsRef = (0, import_react31.useRef)([]);
4183
4185
  const pendingSelectIdsRef = (0, import_react31.useRef)(null);
4184
- (0, import_react31.useEffect)(() => {
4185
- if (view.nodes.length > 0) {
4186
- requestAnimationFrame(() => fitView({ padding: 0.2, duration: 300 }));
4187
- }
4188
- }, []);
4189
4186
  (0, import_react31.useEffect)(() => {
4190
4187
  registerGoToNode((nodeId) => {
4191
4188
  const n = getNode(nodeId);
@@ -4210,8 +4207,8 @@ function CompositeEditor({
4210
4207
  if (viewportIntent.kind === "fit-all") {
4211
4208
  if (view.nodes.length > 0) {
4212
4209
  fitView({
4213
- padding: viewportIntent.padding ?? 0.2,
4214
- duration: viewportIntent.duration ?? 300
4210
+ padding: viewportIntent.padding ?? FIT_VIEW_OPTIONS.padding,
4211
+ duration: viewportIntent.duration ?? FIT_VIEW_OPTIONS.duration
4215
4212
  });
4216
4213
  }
4217
4214
  return;
@@ -4231,7 +4228,7 @@ function CompositeEditor({
4231
4228
  }
4232
4229
  );
4233
4230
  });
4234
- }, [fitBounds, fitView, getNode, view.nodes.length, viewportIntent, viewportIntentSeq]);
4231
+ }, [viewportIntentSeq]);
4235
4232
  const groupLogic = useGroupLogic(view.nodes, view.edges, view.groups, newNodeIds, erroredNodeIds);
4236
4233
  const rfEdgesFromView = groupLogic.rfEdges;
4237
4234
  const [rfEdges, setRfEdges] = (0, import_react31.useState)(rfEdgesFromView);
@@ -4387,7 +4384,15 @@ function CompositeEditor({
4387
4384
  nodeColor: "var(--lace-color-accent)"
4388
4385
  }
4389
4386
  ) : null,
4390
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react30.Controls, { position: "bottom-right", showInteractive: false, style: { bottom: 20, right: 20 } }),
4387
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4388
+ import_react30.Controls,
4389
+ {
4390
+ position: "bottom-right",
4391
+ showInteractive: false,
4392
+ fitViewOptions: FIT_VIEW_OPTIONS,
4393
+ style: { bottom: 20, right: 20 }
4394
+ }
4395
+ ),
4391
4396
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4392
4397
  ActionBar,
4393
4398
  {
@@ -4414,7 +4419,7 @@ function CompositeEditor({
4414
4419
  }
4415
4420
  );
4416
4421
  }
4417
- function Canvas({ registryBaseUrl, apiToken } = {}) {
4422
+ function Canvas({ height, registryBaseUrl, apiToken }) {
4418
4423
  const { state, readOnly, localGroupCollapseOverrides } = useCanvas();
4419
4424
  const engine = useEngine();
4420
4425
  const viewRef = (0, import_react31.useRef)(state.view);
@@ -4624,7 +4629,7 @@ function Canvas({ registryBaseUrl, apiToken } = {}) {
4624
4629
  "div",
4625
4630
  {
4626
4631
  style: {
4627
- height: "100vh",
4632
+ height,
4628
4633
  display: "flex",
4629
4634
  alignItems: "center",
4630
4635
  justifyContent: "center",
@@ -4640,118 +4645,112 @@ function Canvas({ registryBaseUrl, apiToken } = {}) {
4640
4645
  localGroupCollapseOverrides,
4641
4646
  readOnly
4642
4647
  );
4643
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
4644
- "div",
4645
- {
4646
- style: { position: "relative", display: "flex", flexDirection: "column", height: "100vh" },
4647
- children: [
4648
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_feedback.Toast, { toast }),
4649
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4650
- ContextMenu,
4651
- {
4652
- contextMenu,
4653
- onCopy,
4654
- onCut,
4655
- onPaste,
4656
- onGroupSelected,
4657
- onUngroup,
4658
- onDismiss: dismissContextMenu
4659
- }
4660
- ),
4661
- !errorBannerDismissed && validationErrors.length > 0 && !toast && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4662
- ValidationErrorBanner,
4663
- {
4664
- diagnostics: validationErrors,
4665
- nodeIds: erroredNodeIds,
4666
- onGoToNode: (nodeId) => goToNodeRef.current?.(nodeId),
4667
- onOpenFile: (relativePath, line, column) => window.dispatchEvent(
4668
- new CustomEvent(CANVAS_EVENTS.OPEN_FILE, { detail: { relativePath, line, column } })
4669
- ),
4670
- onDismiss: dismissErrorBanner
4671
- }
4648
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: { position: "relative", display: "flex", flexDirection: "column", height }, children: [
4649
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_feedback.Toast, { toast }),
4650
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4651
+ ContextMenu,
4652
+ {
4653
+ contextMenu,
4654
+ onCopy,
4655
+ onCut,
4656
+ onPaste,
4657
+ onGroupSelected,
4658
+ onUngroup,
4659
+ onDismiss: dismissContextMenu
4660
+ }
4661
+ ),
4662
+ !errorBannerDismissed && validationErrors.length > 0 && !toast && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4663
+ ValidationErrorBanner,
4664
+ {
4665
+ diagnostics: validationErrors,
4666
+ nodeIds: erroredNodeIds,
4667
+ onGoToNode: (nodeId) => goToNodeRef.current?.(nodeId),
4668
+ onOpenFile: (relativePath, line, column) => window.dispatchEvent(
4669
+ new CustomEvent(CANVAS_EVENTS.OPEN_FILE, { detail: { relativePath, line, column } })
4672
4670
  ),
4673
- /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: { position: "relative", flex: "1 1 auto", minHeight: 0 }, children: [
4674
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4675
- CompositeEditor,
4676
- {
4677
- view,
4678
- readOnly,
4679
- isGenerating: generating,
4680
- erroredNodeIds,
4681
- newNodeIds,
4682
- forcePositionsRef,
4683
- onDragStop,
4684
- onConnect,
4685
- onEdgeClick,
4686
- onEdgesDelete,
4687
- onNodesDelete,
4688
- onSave,
4689
- onUndo,
4690
- onRedo,
4691
- onClearGraph,
4692
- onGenerate,
4693
- onOpenSettings,
4694
- onOpenPolicy: readOnly ? void 0 : onOpenPolicy,
4695
- onOpenRegistry: canBrowseRegistry ? openRegistry : void 0,
4696
- showMiniMap,
4697
- onToggleMiniMap: toggleMiniMap,
4698
- registerGoToNode,
4699
- registerGetSelectedIds,
4700
- registerSelectNodes,
4701
- viewportIntent: state.viewportIntent,
4702
- viewportIntentSeq: state.viewportIntentSeq
4703
- }
4704
- ),
4705
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: !!configTarget, children: configTarget && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4706
- ModuleConfigPanel,
4707
- {
4708
- instance_id: configTarget,
4709
- engine,
4710
- onClose: () => setConfigTarget(null),
4711
- onModified: clearNew
4712
- }
4713
- ) }),
4714
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: !!selectedEdge, zIndex: 40, children: selectedEdge && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4715
- EdgeInspectorPanel,
4716
- {
4717
- source: selectedEdge.source,
4718
- target: selectedEdge.target,
4719
- sourceOutput: selectedEdge.sourceOutput,
4720
- targetInput: selectedEdge.targetInput,
4721
- onDelete: onDeleteSelectedEdge,
4722
- onClose: clearSelectedEdge
4723
- }
4724
- ) }),
4725
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: settingsOpen, children: settingsOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4726
- UnifiedSettingsPanel,
4727
- {
4728
- engine,
4729
- onClose: () => setSettingsOpen(false),
4730
- onSaved: () => showToast("Settings saved", "success")
4731
- }
4732
- ) }),
4733
- !readOnly && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: policyOpen, children: policyOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4734
- PolicySidebar,
4735
- {
4736
- resolution: policyResolution,
4737
- onPreview: previewPolicy,
4738
- onClose: () => setPolicyOpen(false)
4739
- }
4740
- ) }),
4741
- canBrowseRegistry && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: registryOpen, children: registryOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4742
- RegistryBrowser,
4743
- {
4744
- engine,
4745
- registryBaseUrl,
4746
- apiToken,
4747
- showToast,
4748
- onClose: closeRegistry
4749
- }
4750
- ) })
4751
- ] })
4752
- ]
4753
- }
4754
- );
4671
+ onDismiss: dismissErrorBanner
4672
+ }
4673
+ ),
4674
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { style: { position: "relative", flex: "1 1 auto", minHeight: 0 }, children: [
4675
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4676
+ CompositeEditor,
4677
+ {
4678
+ view,
4679
+ readOnly,
4680
+ isGenerating: generating,
4681
+ erroredNodeIds,
4682
+ newNodeIds,
4683
+ forcePositionsRef,
4684
+ onDragStop,
4685
+ onConnect,
4686
+ onEdgeClick,
4687
+ onEdgesDelete,
4688
+ onNodesDelete,
4689
+ onSave,
4690
+ onUndo,
4691
+ onRedo,
4692
+ onClearGraph,
4693
+ onGenerate,
4694
+ onOpenSettings,
4695
+ onOpenPolicy: readOnly ? void 0 : onOpenPolicy,
4696
+ onOpenRegistry: canBrowseRegistry ? openRegistry : void 0,
4697
+ showMiniMap,
4698
+ onToggleMiniMap: toggleMiniMap,
4699
+ registerGoToNode,
4700
+ registerGetSelectedIds,
4701
+ registerSelectNodes,
4702
+ viewportIntent: state.viewportIntent,
4703
+ viewportIntentSeq: state.viewportIntentSeq
4704
+ }
4705
+ ),
4706
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: !!configTarget, children: configTarget && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4707
+ ModuleConfigPanel,
4708
+ {
4709
+ instance_id: configTarget,
4710
+ engine,
4711
+ onClose: () => setConfigTarget(null),
4712
+ onModified: clearNew
4713
+ }
4714
+ ) }),
4715
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: !!selectedEdge, zIndex: 40, children: selectedEdge && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4716
+ EdgeInspectorPanel,
4717
+ {
4718
+ source: selectedEdge.source,
4719
+ target: selectedEdge.target,
4720
+ sourceOutput: selectedEdge.sourceOutput,
4721
+ targetInput: selectedEdge.targetInput,
4722
+ onDelete: onDeleteSelectedEdge,
4723
+ onClose: clearSelectedEdge
4724
+ }
4725
+ ) }),
4726
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: settingsOpen, children: settingsOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4727
+ UnifiedSettingsPanel,
4728
+ {
4729
+ engine,
4730
+ onClose: () => setSettingsOpen(false),
4731
+ onSaved: () => showToast("Settings saved", "success")
4732
+ }
4733
+ ) }),
4734
+ !readOnly && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: policyOpen, children: policyOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4735
+ PolicySidebar,
4736
+ {
4737
+ resolution: policyResolution,
4738
+ onPreview: previewPolicy,
4739
+ onClose: () => setPolicyOpen(false)
4740
+ }
4741
+ ) }),
4742
+ canBrowseRegistry && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SlidePanel, { open: registryOpen, children: registryOpen && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4743
+ RegistryBrowser,
4744
+ {
4745
+ engine,
4746
+ registryBaseUrl,
4747
+ apiToken,
4748
+ showToast,
4749
+ onClose: closeRegistry
4750
+ }
4751
+ ) })
4752
+ ] })
4753
+ ] });
4755
4754
  }
4756
4755
 
4757
4756
  // src/components/ErrorBoundary.tsx
@@ -4807,9 +4806,11 @@ function useWindowEvent(eventName, handler, options) {
4807
4806
 
4808
4807
  // src/App.tsx
4809
4808
  var import_jsx_runtime22 = require("react/jsx-runtime");
4809
+ var FIT_ALL_INTENT = { kind: "fit-all" };
4810
4810
  function App({
4811
4811
  engine,
4812
4812
  hostBridge,
4813
+ height = "100vh",
4813
4814
  readOnly = false,
4814
4815
  registryBaseUrl,
4815
4816
  apiToken
@@ -4825,15 +4826,20 @@ function App({
4825
4826
  const toggleLocalGroupCollapse = (0, import_react35.useCallback)((groupId, currentCollapsed) => {
4826
4827
  setLocalGroupCollapseOverrides((prev) => ({ ...prev, [groupId]: !currentCollapsed }));
4827
4828
  }, []);
4829
+ const refitOnNextStateRef = (0, import_react35.useRef)(true);
4828
4830
  (0, import_react35.useEffect)(() => {
4831
+ refitOnNextStateRef.current = true;
4829
4832
  return engine.onEvent((event) => {
4830
4833
  if (event.type === "stateUpdated") {
4834
+ const refit = refitOnNextStateRef.current;
4835
+ refitOnNextStateRef.current = false;
4836
+ const viewportIntent = event.viewportIntent ?? (refit ? FIT_ALL_INTENT : null);
4831
4837
  setState((prev) => ({
4832
4838
  view: event.view,
4833
4839
  loading: false,
4834
4840
  generation: prev.generation + 1,
4835
- viewportIntent: event.viewportIntent ?? null,
4836
- viewportIntentSeq: prev.viewportIntentSeq + (event.viewportIntent ? 1 : 0)
4841
+ viewportIntent,
4842
+ viewportIntentSeq: prev.viewportIntentSeq + (viewportIntent ? 1 : 0)
4837
4843
  }));
4838
4844
  }
4839
4845
  });
@@ -4865,7 +4871,7 @@ function App({
4865
4871
  localGroupCollapseOverrides,
4866
4872
  toggleLocalGroupCollapse
4867
4873
  },
4868
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react34.ReactFlowProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Canvas, { registryBaseUrl, apiToken }) })
4874
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react34.ReactFlowProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Canvas, { height, registryBaseUrl, apiToken }) })
4869
4875
  }
4870
4876
  ) });
4871
4877
  }