@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/dist/index.d.mts CHANGED
@@ -2,9 +2,9 @@ import { CanvasView, Diagnostic, NodeConfig, EdgeConfig, SettingsConfig, RenderE
2
2
  export { CanvasView, Diagnostic, EdgeConfig, GeneratePhase, HostToWebview, NodeConfig, NodePin, ProjectionMeta, RenderEdge, RenderError, RenderGroup, RenderInput, RenderNode, RenderOutput, SettingsConfig, ViewportIntent, projectCanvasView } from '@lace-cloud/proto';
3
3
  export { Toast } from '@lace-cloud/ui/feedback';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
- import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
6
5
  import * as React from 'react';
7
6
  import React__default from 'react';
7
+ import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
8
8
  import { NodeProps, Node } from '@xyflow/react';
9
9
 
10
10
  interface Bundle {
@@ -526,6 +526,11 @@ type HostBridge = {
526
526
  type AppProps = {
527
527
  engine: CanvasEngine;
528
528
  hostBridge: HostBridge;
529
+ /**
530
+ * Height of the canvas root. Defaults to `100vh`; embedded consumers can
531
+ * pass `100%` when their parent establishes an explicit height.
532
+ */
533
+ height?: React__default.CSSProperties['height'];
529
534
  /**
530
535
  * When true, the canvas renders in read-only mode: pan/zoom/drag/inspect
531
536
  * still work, but every IR-mutating affordance (save, delete, rename,
@@ -537,7 +542,7 @@ type AppProps = {
537
542
  /** API token for registry access. */
538
543
  apiToken?: string;
539
544
  };
540
- declare function App({ engine, hostBridge, readOnly, registryBaseUrl, apiToken, }: AppProps): react_jsx_runtime.JSX.Element;
545
+ declare function App({ engine, hostBridge, height, readOnly, registryBaseUrl, apiToken, }: AppProps): react_jsx_runtime.JSX.Element;
541
546
 
542
547
  type Props$a = {
543
548
  title: string;
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@ import { CanvasView, Diagnostic, NodeConfig, EdgeConfig, SettingsConfig, RenderE
2
2
  export { CanvasView, Diagnostic, EdgeConfig, GeneratePhase, HostToWebview, NodeConfig, NodePin, ProjectionMeta, RenderEdge, RenderError, RenderGroup, RenderInput, RenderNode, RenderOutput, SettingsConfig, ViewportIntent, projectCanvasView } from '@lace-cloud/proto';
3
3
  export { Toast } from '@lace-cloud/ui/feedback';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
- import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
6
5
  import * as React from 'react';
7
6
  import React__default from 'react';
7
+ import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
8
8
  import { NodeProps, Node } from '@xyflow/react';
9
9
 
10
10
  interface Bundle {
@@ -526,6 +526,11 @@ type HostBridge = {
526
526
  type AppProps = {
527
527
  engine: CanvasEngine;
528
528
  hostBridge: HostBridge;
529
+ /**
530
+ * Height of the canvas root. Defaults to `100vh`; embedded consumers can
531
+ * pass `100%` when their parent establishes an explicit height.
532
+ */
533
+ height?: React__default.CSSProperties['height'];
529
534
  /**
530
535
  * When true, the canvas renders in read-only mode: pan/zoom/drag/inspect
531
536
  * still work, but every IR-mutating affordance (save, delete, rename,
@@ -537,7 +542,7 @@ type AppProps = {
537
542
  /** API token for registry access. */
538
543
  apiToken?: string;
539
544
  };
540
- declare function App({ engine, hostBridge, readOnly, registryBaseUrl, apiToken, }: AppProps): react_jsx_runtime.JSX.Element;
545
+ declare function App({ engine, hostBridge, height, readOnly, registryBaseUrl, apiToken, }: AppProps): react_jsx_runtime.JSX.Element;
541
546
 
542
547
  type Props$a = {
543
548
  title: string;
package/dist/index.mjs CHANGED
@@ -4,10 +4,11 @@ import { Toast as Toast2 } from "@lace-cloud/ui/feedback";
4
4
 
5
5
  // src/App.tsx
6
6
  import { ReactFlowProvider } from "@xyflow/react";
7
- import { useCallback as useCallback21, useEffect as useEffect17, useState as useState24 } from "react";
7
+ import { useCallback as useCallback21, useEffect as useEffect17, useRef as useRef10, useState as useState24 } from "react";
8
8
 
9
9
  // src/Canvas.tsx
10
- import "./Canvas-IXCFWQNP.css";
10
+ import "@xyflow/react/dist/style.css";
11
+ import "./Canvas-J6F7YHEK.css";
11
12
  import { Toast } from "@lace-cloud/ui/feedback";
12
13
  import {
13
14
  applyEdgeChanges,
@@ -4092,6 +4093,7 @@ var nodeTypes = {
4092
4093
  moduleNode: ModuleNode_default,
4093
4094
  groupNode: GroupNode_default
4094
4095
  };
4096
+ var FIT_VIEW_OPTIONS = { padding: 0.2, duration: 300 };
4095
4097
  function CompositeEditor({
4096
4098
  view,
4097
4099
  readOnly,
@@ -4125,11 +4127,6 @@ function CompositeEditor({
4125
4127
  const nodesInitialized = xyflowInitialized || view.nodes.length === 0;
4126
4128
  const selectedIdsRef = useRef8([]);
4127
4129
  const pendingSelectIdsRef = useRef8(null);
4128
- useEffect15(() => {
4129
- if (view.nodes.length > 0) {
4130
- requestAnimationFrame(() => fitView({ padding: 0.2, duration: 300 }));
4131
- }
4132
- }, []);
4133
4130
  useEffect15(() => {
4134
4131
  registerGoToNode((nodeId) => {
4135
4132
  const n = getNode(nodeId);
@@ -4154,8 +4151,8 @@ function CompositeEditor({
4154
4151
  if (viewportIntent.kind === "fit-all") {
4155
4152
  if (view.nodes.length > 0) {
4156
4153
  fitView({
4157
- padding: viewportIntent.padding ?? 0.2,
4158
- duration: viewportIntent.duration ?? 300
4154
+ padding: viewportIntent.padding ?? FIT_VIEW_OPTIONS.padding,
4155
+ duration: viewportIntent.duration ?? FIT_VIEW_OPTIONS.duration
4159
4156
  });
4160
4157
  }
4161
4158
  return;
@@ -4175,7 +4172,7 @@ function CompositeEditor({
4175
4172
  }
4176
4173
  );
4177
4174
  });
4178
- }, [fitBounds, fitView, getNode, view.nodes.length, viewportIntent, viewportIntentSeq]);
4175
+ }, [viewportIntentSeq]);
4179
4176
  const groupLogic = useGroupLogic(view.nodes, view.edges, view.groups, newNodeIds, erroredNodeIds);
4180
4177
  const rfEdgesFromView = groupLogic.rfEdges;
4181
4178
  const [rfEdges, setRfEdges] = useState23(rfEdgesFromView);
@@ -4331,7 +4328,15 @@ function CompositeEditor({
4331
4328
  nodeColor: "var(--lace-color-accent)"
4332
4329
  }
4333
4330
  ) : null,
4334
- /* @__PURE__ */ jsx20(Controls, { position: "bottom-right", showInteractive: false, style: { bottom: 20, right: 20 } }),
4331
+ /* @__PURE__ */ jsx20(
4332
+ Controls,
4333
+ {
4334
+ position: "bottom-right",
4335
+ showInteractive: false,
4336
+ fitViewOptions: FIT_VIEW_OPTIONS,
4337
+ style: { bottom: 20, right: 20 }
4338
+ }
4339
+ ),
4335
4340
  /* @__PURE__ */ jsx20(
4336
4341
  ActionBar,
4337
4342
  {
@@ -4358,7 +4363,7 @@ function CompositeEditor({
4358
4363
  }
4359
4364
  );
4360
4365
  }
4361
- function Canvas({ registryBaseUrl, apiToken } = {}) {
4366
+ function Canvas({ height, registryBaseUrl, apiToken }) {
4362
4367
  const { state, readOnly, localGroupCollapseOverrides } = useCanvas();
4363
4368
  const engine = useEngine();
4364
4369
  const viewRef = useRef8(state.view);
@@ -4568,7 +4573,7 @@ function Canvas({ registryBaseUrl, apiToken } = {}) {
4568
4573
  "div",
4569
4574
  {
4570
4575
  style: {
4571
- height: "100vh",
4576
+ height,
4572
4577
  display: "flex",
4573
4578
  alignItems: "center",
4574
4579
  justifyContent: "center",
@@ -4584,118 +4589,112 @@ function Canvas({ registryBaseUrl, apiToken } = {}) {
4584
4589
  localGroupCollapseOverrides,
4585
4590
  readOnly
4586
4591
  );
4587
- return /* @__PURE__ */ jsxs18(
4588
- "div",
4589
- {
4590
- style: { position: "relative", display: "flex", flexDirection: "column", height: "100vh" },
4591
- children: [
4592
- /* @__PURE__ */ jsx20(Toast, { toast }),
4593
- /* @__PURE__ */ jsx20(
4594
- ContextMenu,
4595
- {
4596
- contextMenu,
4597
- onCopy,
4598
- onCut,
4599
- onPaste,
4600
- onGroupSelected,
4601
- onUngroup,
4602
- onDismiss: dismissContextMenu
4603
- }
4604
- ),
4605
- !errorBannerDismissed && validationErrors.length > 0 && !toast && /* @__PURE__ */ jsx20(
4606
- ValidationErrorBanner,
4607
- {
4608
- diagnostics: validationErrors,
4609
- nodeIds: erroredNodeIds,
4610
- onGoToNode: (nodeId) => goToNodeRef.current?.(nodeId),
4611
- onOpenFile: (relativePath, line, column) => window.dispatchEvent(
4612
- new CustomEvent(CANVAS_EVENTS.OPEN_FILE, { detail: { relativePath, line, column } })
4613
- ),
4614
- onDismiss: dismissErrorBanner
4615
- }
4592
+ return /* @__PURE__ */ jsxs18("div", { style: { position: "relative", display: "flex", flexDirection: "column", height }, children: [
4593
+ /* @__PURE__ */ jsx20(Toast, { toast }),
4594
+ /* @__PURE__ */ jsx20(
4595
+ ContextMenu,
4596
+ {
4597
+ contextMenu,
4598
+ onCopy,
4599
+ onCut,
4600
+ onPaste,
4601
+ onGroupSelected,
4602
+ onUngroup,
4603
+ onDismiss: dismissContextMenu
4604
+ }
4605
+ ),
4606
+ !errorBannerDismissed && validationErrors.length > 0 && !toast && /* @__PURE__ */ jsx20(
4607
+ ValidationErrorBanner,
4608
+ {
4609
+ diagnostics: validationErrors,
4610
+ nodeIds: erroredNodeIds,
4611
+ onGoToNode: (nodeId) => goToNodeRef.current?.(nodeId),
4612
+ onOpenFile: (relativePath, line, column) => window.dispatchEvent(
4613
+ new CustomEvent(CANVAS_EVENTS.OPEN_FILE, { detail: { relativePath, line, column } })
4616
4614
  ),
4617
- /* @__PURE__ */ jsxs18("div", { style: { position: "relative", flex: "1 1 auto", minHeight: 0 }, children: [
4618
- /* @__PURE__ */ jsx20(
4619
- CompositeEditor,
4620
- {
4621
- view,
4622
- readOnly,
4623
- isGenerating: generating,
4624
- erroredNodeIds,
4625
- newNodeIds,
4626
- forcePositionsRef,
4627
- onDragStop,
4628
- onConnect,
4629
- onEdgeClick,
4630
- onEdgesDelete,
4631
- onNodesDelete,
4632
- onSave,
4633
- onUndo,
4634
- onRedo,
4635
- onClearGraph,
4636
- onGenerate,
4637
- onOpenSettings,
4638
- onOpenPolicy: readOnly ? void 0 : onOpenPolicy,
4639
- onOpenRegistry: canBrowseRegistry ? openRegistry : void 0,
4640
- showMiniMap,
4641
- onToggleMiniMap: toggleMiniMap,
4642
- registerGoToNode,
4643
- registerGetSelectedIds,
4644
- registerSelectNodes,
4645
- viewportIntent: state.viewportIntent,
4646
- viewportIntentSeq: state.viewportIntentSeq
4647
- }
4648
- ),
4649
- /* @__PURE__ */ jsx20(SlidePanel, { open: !!configTarget, children: configTarget && /* @__PURE__ */ jsx20(
4650
- ModuleConfigPanel,
4651
- {
4652
- instance_id: configTarget,
4653
- engine,
4654
- onClose: () => setConfigTarget(null),
4655
- onModified: clearNew
4656
- }
4657
- ) }),
4658
- /* @__PURE__ */ jsx20(SlidePanel, { open: !!selectedEdge, zIndex: 40, children: selectedEdge && /* @__PURE__ */ jsx20(
4659
- EdgeInspectorPanel,
4660
- {
4661
- source: selectedEdge.source,
4662
- target: selectedEdge.target,
4663
- sourceOutput: selectedEdge.sourceOutput,
4664
- targetInput: selectedEdge.targetInput,
4665
- onDelete: onDeleteSelectedEdge,
4666
- onClose: clearSelectedEdge
4667
- }
4668
- ) }),
4669
- /* @__PURE__ */ jsx20(SlidePanel, { open: settingsOpen, children: settingsOpen && /* @__PURE__ */ jsx20(
4670
- UnifiedSettingsPanel,
4671
- {
4672
- engine,
4673
- onClose: () => setSettingsOpen(false),
4674
- onSaved: () => showToast("Settings saved", "success")
4675
- }
4676
- ) }),
4677
- !readOnly && /* @__PURE__ */ jsx20(SlidePanel, { open: policyOpen, children: policyOpen && /* @__PURE__ */ jsx20(
4678
- PolicySidebar,
4679
- {
4680
- resolution: policyResolution,
4681
- onPreview: previewPolicy,
4682
- onClose: () => setPolicyOpen(false)
4683
- }
4684
- ) }),
4685
- canBrowseRegistry && /* @__PURE__ */ jsx20(SlidePanel, { open: registryOpen, children: registryOpen && /* @__PURE__ */ jsx20(
4686
- RegistryBrowser,
4687
- {
4688
- engine,
4689
- registryBaseUrl,
4690
- apiToken,
4691
- showToast,
4692
- onClose: closeRegistry
4693
- }
4694
- ) })
4695
- ] })
4696
- ]
4697
- }
4698
- );
4615
+ onDismiss: dismissErrorBanner
4616
+ }
4617
+ ),
4618
+ /* @__PURE__ */ jsxs18("div", { style: { position: "relative", flex: "1 1 auto", minHeight: 0 }, children: [
4619
+ /* @__PURE__ */ jsx20(
4620
+ CompositeEditor,
4621
+ {
4622
+ view,
4623
+ readOnly,
4624
+ isGenerating: generating,
4625
+ erroredNodeIds,
4626
+ newNodeIds,
4627
+ forcePositionsRef,
4628
+ onDragStop,
4629
+ onConnect,
4630
+ onEdgeClick,
4631
+ onEdgesDelete,
4632
+ onNodesDelete,
4633
+ onSave,
4634
+ onUndo,
4635
+ onRedo,
4636
+ onClearGraph,
4637
+ onGenerate,
4638
+ onOpenSettings,
4639
+ onOpenPolicy: readOnly ? void 0 : onOpenPolicy,
4640
+ onOpenRegistry: canBrowseRegistry ? openRegistry : void 0,
4641
+ showMiniMap,
4642
+ onToggleMiniMap: toggleMiniMap,
4643
+ registerGoToNode,
4644
+ registerGetSelectedIds,
4645
+ registerSelectNodes,
4646
+ viewportIntent: state.viewportIntent,
4647
+ viewportIntentSeq: state.viewportIntentSeq
4648
+ }
4649
+ ),
4650
+ /* @__PURE__ */ jsx20(SlidePanel, { open: !!configTarget, children: configTarget && /* @__PURE__ */ jsx20(
4651
+ ModuleConfigPanel,
4652
+ {
4653
+ instance_id: configTarget,
4654
+ engine,
4655
+ onClose: () => setConfigTarget(null),
4656
+ onModified: clearNew
4657
+ }
4658
+ ) }),
4659
+ /* @__PURE__ */ jsx20(SlidePanel, { open: !!selectedEdge, zIndex: 40, children: selectedEdge && /* @__PURE__ */ jsx20(
4660
+ EdgeInspectorPanel,
4661
+ {
4662
+ source: selectedEdge.source,
4663
+ target: selectedEdge.target,
4664
+ sourceOutput: selectedEdge.sourceOutput,
4665
+ targetInput: selectedEdge.targetInput,
4666
+ onDelete: onDeleteSelectedEdge,
4667
+ onClose: clearSelectedEdge
4668
+ }
4669
+ ) }),
4670
+ /* @__PURE__ */ jsx20(SlidePanel, { open: settingsOpen, children: settingsOpen && /* @__PURE__ */ jsx20(
4671
+ UnifiedSettingsPanel,
4672
+ {
4673
+ engine,
4674
+ onClose: () => setSettingsOpen(false),
4675
+ onSaved: () => showToast("Settings saved", "success")
4676
+ }
4677
+ ) }),
4678
+ !readOnly && /* @__PURE__ */ jsx20(SlidePanel, { open: policyOpen, children: policyOpen && /* @__PURE__ */ jsx20(
4679
+ PolicySidebar,
4680
+ {
4681
+ resolution: policyResolution,
4682
+ onPreview: previewPolicy,
4683
+ onClose: () => setPolicyOpen(false)
4684
+ }
4685
+ ) }),
4686
+ canBrowseRegistry && /* @__PURE__ */ jsx20(SlidePanel, { open: registryOpen, children: registryOpen && /* @__PURE__ */ jsx20(
4687
+ RegistryBrowser,
4688
+ {
4689
+ engine,
4690
+ registryBaseUrl,
4691
+ apiToken,
4692
+ showToast,
4693
+ onClose: closeRegistry
4694
+ }
4695
+ ) })
4696
+ ] })
4697
+ ] });
4699
4698
  }
4700
4699
 
4701
4700
  // src/components/ErrorBoundary.tsx
@@ -4751,9 +4750,11 @@ function useWindowEvent(eventName, handler, options) {
4751
4750
 
4752
4751
  // src/App.tsx
4753
4752
  import { jsx as jsx22 } from "react/jsx-runtime";
4753
+ var FIT_ALL_INTENT = { kind: "fit-all" };
4754
4754
  function App({
4755
4755
  engine,
4756
4756
  hostBridge,
4757
+ height = "100vh",
4757
4758
  readOnly = false,
4758
4759
  registryBaseUrl,
4759
4760
  apiToken
@@ -4769,15 +4770,20 @@ function App({
4769
4770
  const toggleLocalGroupCollapse = useCallback21((groupId, currentCollapsed) => {
4770
4771
  setLocalGroupCollapseOverrides((prev) => ({ ...prev, [groupId]: !currentCollapsed }));
4771
4772
  }, []);
4773
+ const refitOnNextStateRef = useRef10(true);
4772
4774
  useEffect17(() => {
4775
+ refitOnNextStateRef.current = true;
4773
4776
  return engine.onEvent((event) => {
4774
4777
  if (event.type === "stateUpdated") {
4778
+ const refit = refitOnNextStateRef.current;
4779
+ refitOnNextStateRef.current = false;
4780
+ const viewportIntent = event.viewportIntent ?? (refit ? FIT_ALL_INTENT : null);
4775
4781
  setState((prev) => ({
4776
4782
  view: event.view,
4777
4783
  loading: false,
4778
4784
  generation: prev.generation + 1,
4779
- viewportIntent: event.viewportIntent ?? null,
4780
- viewportIntentSeq: prev.viewportIntentSeq + (event.viewportIntent ? 1 : 0)
4785
+ viewportIntent,
4786
+ viewportIntentSeq: prev.viewportIntentSeq + (viewportIntent ? 1 : 0)
4781
4787
  }));
4782
4788
  }
4783
4789
  });
@@ -4809,7 +4815,7 @@ function App({
4809
4815
  localGroupCollapseOverrides,
4810
4816
  toggleLocalGroupCollapse
4811
4817
  },
4812
- children: /* @__PURE__ */ jsx22(ReactFlowProvider, { children: /* @__PURE__ */ jsx22(Canvas, { registryBaseUrl, apiToken }) })
4818
+ children: /* @__PURE__ */ jsx22(ReactFlowProvider, { children: /* @__PURE__ */ jsx22(Canvas, { height, registryBaseUrl, apiToken }) })
4813
4819
  }
4814
4820
  ) });
4815
4821
  }