@lace-cloud/canvas 0.14.0 → 0.15.1

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
@@ -1,5 +1,5 @@
1
- import { CanvasView, Diagnostic, NodeConfig, EdgeConfig, SettingsConfig, RenderError, ViewportIntent, GeneratePhase, RenderNode } from '@lace-cloud/proto';
2
- export { CanvasView, Diagnostic, EdgeConfig, GeneratePhase, HostToWebview, NodeConfig, NodePin, ProjectionMeta, RenderEdge, RenderError, RenderGroup, RenderInput, RenderNode, RenderOutput, SettingsConfig, ViewportIntent, projectCanvasView } from '@lace-cloud/proto';
1
+ import { CanvasView, Diagnostic, CanvasArrangement, NodeConfig, EdgeConfig, SettingsConfig, RenderError, ViewportIntent, GeneratePhase, RenderNode } from '@lace-cloud/proto';
2
+ export { CanvasArrangement, 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
5
  import * as React from 'react';
@@ -202,31 +202,6 @@ interface ProviderConfig {
202
202
  blocks: Block[];
203
203
  }
204
204
  declare const ProviderConfig: MessageFns<ProviderConfig>;
205
- interface GraphLayout {
206
- nodes: {
207
- [key: string]: NodeLayout;
208
- };
209
- groups: {
210
- [key: string]: NodeGroup;
211
- };
212
- }
213
- declare const GraphLayout: MessageFns<GraphLayout>;
214
- interface NodeGroup {
215
- id: string;
216
- label: string;
217
- node_ids: string[];
218
- collapsed: boolean;
219
- }
220
- declare const NodeGroup: MessageFns<NodeGroup>;
221
- interface NodeLayout {
222
- position: Position | undefined;
223
- }
224
- declare const NodeLayout: MessageFns<NodeLayout>;
225
- interface Position {
226
- x: number;
227
- y: number;
228
- }
229
- declare const Position: MessageFns<Position>;
230
205
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
231
206
  type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
232
207
  [K in keyof T]?: DeepPartial<T[K]>;
@@ -402,15 +377,30 @@ type GraphError = {
402
377
  inputName: string;
403
378
  message: string;
404
379
  };
380
+ /**
381
+ * Names one child created by a mutation (placement, group creation, copy).
382
+ * Mirrors the wire `CreatedRef` — clients key pending arrangement writes
383
+ * (position, group label/collapse) off these ids instead of diffing
384
+ * successive CanvasView frames to guess what changed.
385
+ */
386
+ type CreatedRef = {
387
+ scope: string;
388
+ id: string;
389
+ moduleKey: string;
390
+ sourceId: string;
391
+ };
405
392
  /**
406
393
  * Result of every mutation method. The CanvasView is NOT returned — it
407
394
  * arrives via the `stateUpdated` event after the server publishes the
408
395
  * new BundleState. Consumers that need the post-mutation view read it
409
- * from `engine.getCurrentView()` after awaiting the ApplyResult.
396
+ * from `engine.getCurrentView()` after awaiting the ApplyResult. `created`
397
+ * carries the server's attribution of any child/module ids the action
398
+ * minted (see `CreatedRef`); empty for actions that mint nothing.
410
399
  */
411
400
  type ApplyResult = {
412
401
  success: boolean;
413
402
  errors: GraphError[];
403
+ created: CreatedRef[];
414
404
  };
415
405
  interface CanvasEngine {
416
406
  sessionOpen(filePath: string, workspaceName: string): Promise<CanvasView>;
@@ -434,6 +424,23 @@ interface CanvasEngine {
434
424
  * awaited promise resolves.
435
425
  */
436
426
  getCurrentView(): CanvasView | null;
427
+ /**
428
+ * The Bundle backing the current view, or null before the first
429
+ * BundleState/snapshot has loaded. Consumers writing an arrangement
430
+ * entry (drag, collapse toggle, rename, group create/ungroup) need this
431
+ * to resolve a canvas-path id to the (scopeKey, localId) pair the write
432
+ * targets — arrangement is keyed by module key, the same key
433
+ * `projectScope` resolves via `resolveScopePath`, not by canvas path.
434
+ */
435
+ getCurrentBundle(): Bundle | null;
436
+ /**
437
+ * Replace the consumer-owned CanvasArrangement (node positions, group
438
+ * collapse/label) and immediately re-project + emit `stateUpdated`. The
439
+ * engine is the single projection site (`bundle-renders-on-canvas`); a
440
+ * consumer that mutates arrangement (drag, collapse toggle, rename)
441
+ * calls this instead of re-deriving a CanvasView itself.
442
+ */
443
+ setArrangement(arrangement: CanvasArrangement): void;
437
444
  connect(source: string, target: string, sourceOutput: string, targetInput: string): Promise<ApplyResult>;
438
445
  autoConnect(source: string, target: string): Promise<ApplyResult>;
439
446
  disconnect(target: string, inputName: string): Promise<ApplyResult>;
@@ -442,10 +449,6 @@ interface CanvasEngine {
442
449
  renameInstance(oldId: string, newId: string): Promise<ApplyResult>;
443
450
  deleteInstance(instanceId: string): Promise<ApplyResult>;
444
451
  copyInstances(instanceIds: string[]): Promise<ApplyResult>;
445
- syncLayout(positions: Record<string, {
446
- x: number;
447
- y: number;
448
- }>): Promise<ApplyResult>;
449
452
  setVariables(variables: VariableDef[]): Promise<ApplyResult>;
450
453
  setExports(outputs: OutputExportDef[], outputDefs: OutputDefEntry[]): Promise<ApplyResult>;
451
454
  setTerraform(requiredVersion?: string, requiredProviders?: ProviderDef[]): Promise<ApplyResult>;
@@ -464,25 +467,22 @@ interface CanvasEngine {
464
467
  /**
465
468
  * Place a module from the registry onto the canvas. The engine fetches
466
469
  * the module bundle from the registry, resolves its source, and drops
467
- * it into the workspace at the given (or auto-computed) position.
470
+ * it into the workspace. Placement position is consumer-owned
471
+ * arrangement state — the caller writes it from the mutation's
472
+ * `created` ref (see `CreatedRef`), not through this call.
468
473
  */
469
474
  placeModule(params: {
470
475
  name: string;
471
476
  system: string;
472
477
  version: string;
473
478
  organization?: string;
474
- position?: {
475
- x: number;
476
- y: number;
477
- };
478
- }): Promise<ApplyResult>;
479
- createGroup(label: string, nodeIds: string[]): Promise<ApplyResult>;
480
- updateGroup(groupId: string, updates: {
481
- label?: string;
482
- node_ids?: string[];
483
- collapsed?: boolean;
484
479
  }): Promise<ApplyResult>;
485
- deleteGroup(groupId: string): Promise<ApplyResult>;
480
+ createGroup(nodeIds: string[]): Promise<ApplyResult>;
481
+ /**
482
+ * Dissolves the group `groupId`: its Use is removed and the group
483
+ * module's children are promoted into the parent scope.
484
+ */
485
+ ungroup(groupId: string): Promise<ApplyResult>;
486
486
  queryNodeConfig(instanceId: string): Promise<NodeConfig>;
487
487
  queryEdgeConfig(source: string, target: string): Promise<EdgeConfig>;
488
488
  querySettings(): Promise<SettingsConfig>;
@@ -553,8 +553,22 @@ type AppProps = {
553
553
  registryBaseUrl?: string;
554
554
  /** API token for registry access. */
555
555
  apiToken?: string;
556
+ /**
557
+ * Initial CanvasArrangement (node positions, group collapse/label) —
558
+ * consumer-owned view state that never travels over the wire. Read once
559
+ * at mount (uncontrolled-with-initial-value); subsequent edits flow
560
+ * through `onArrangementChange`, not back in via this prop.
561
+ */
562
+ arrangement?: CanvasArrangement;
563
+ /**
564
+ * Fired whenever the arrangement changes (drag, collapse toggle, rename,
565
+ * group create/ungroup, copy/paste, placement) so a host that persists
566
+ * arrangement externally (localStorage, VS Code workspace state) can do
567
+ * so. Fires in both editable and read-only mode.
568
+ */
569
+ onArrangementChange?: (arrangement: CanvasArrangement) => void;
556
570
  };
557
- declare function App({ engine, hostBridge, height, readOnly, registryBaseUrl, apiToken, }: AppProps): react_jsx_runtime.JSX.Element;
571
+ declare function App({ engine, hostBridge, height, readOnly, registryBaseUrl, apiToken, arrangement: initialArrangement, onArrangementChange, }: AppProps): react_jsx_runtime.JSX.Element;
558
572
 
559
573
  type Props$a = {
560
574
  title: string;
@@ -639,6 +653,7 @@ type ExternalPin = {
639
653
  };
640
654
  type GroupNodeData = {
641
655
  groupId: string;
656
+ moduleKey: string;
642
657
  label: string;
643
658
  memberCount: number;
644
659
  collapsed: boolean;
@@ -809,7 +824,7 @@ declare class ConnectWebEngine implements CanvasEngine {
809
824
  private subscribeAbort;
810
825
  private readonly listeners;
811
826
  private currentBundle;
812
- private currentLayouts;
827
+ private currentArrangement;
813
828
  private currentCanUndo;
814
829
  private currentCanRedo;
815
830
  private currentIsDirty;
@@ -820,6 +835,13 @@ declare class ConnectWebEngine implements CanvasEngine {
820
835
  private emit;
821
836
  get sessionId(): string | null;
822
837
  getCurrentView(): CanvasView | null;
838
+ getCurrentBundle(): Bundle | null;
839
+ /**
840
+ * Replace the consumer-owned arrangement and re-project immediately —
841
+ * a local view refresh, not a mutation, so it never carries a viewport
842
+ * intent.
843
+ */
844
+ setArrangement(arrangement: CanvasArrangement): void;
823
845
  private requireSessionId;
824
846
  private unary;
825
847
  /** Replace local state from a BundleState snapshot and re-project. */
@@ -876,10 +898,6 @@ declare class ConnectWebEngine implements CanvasEngine {
876
898
  renameInstance(oldId: string, newId: string): Promise<ApplyResult>;
877
899
  deleteInstance(instanceId: string): Promise<ApplyResult>;
878
900
  copyInstances(instanceIds: string[]): Promise<ApplyResult>;
879
- syncLayout(positions: Record<string, {
880
- x: number;
881
- y: number;
882
- }>): Promise<ApplyResult>;
883
901
  setVariables(variables: VariableDef[]): Promise<ApplyResult>;
884
902
  setExports(outputs: OutputExportDef[], outputDefs: OutputDefEntry[]): Promise<ApplyResult>;
885
903
  setTerraform(requiredVersion?: string, requiredProviders?: ProviderDef[]): Promise<ApplyResult>;
@@ -890,13 +908,8 @@ declare class ConnectWebEngine implements CanvasEngine {
890
908
  setEnvironments(environments: Record<string, Record<string, unknown>>): Promise<ApplyResult>;
891
909
  undo(): Promise<ApplyResult>;
892
910
  redo(): Promise<ApplyResult>;
893
- createGroup(label: string, nodeIds: string[]): Promise<ApplyResult>;
894
- updateGroup(groupId: string, updates: {
895
- label?: string;
896
- node_ids?: string[];
897
- collapsed?: boolean;
898
- }): Promise<ApplyResult>;
899
- deleteGroup(groupId: string): Promise<ApplyResult>;
911
+ createGroup(nodeIds: string[]): Promise<ApplyResult>;
912
+ ungroup(groupId: string): Promise<ApplyResult>;
900
913
  queryNodeConfig(instanceId: string): Promise<NodeConfig>;
901
914
  queryEdgeConfig(source: string, target: string): Promise<EdgeConfig>;
902
915
  querySettings(): Promise<SettingsConfig>;
@@ -914,10 +927,6 @@ declare class ConnectWebEngine implements CanvasEngine {
914
927
  system: string;
915
928
  version: string;
916
929
  organization?: string;
917
- position?: {
918
- x: number;
919
- y: number;
920
- };
921
930
  }): Promise<ApplyResult>;
922
931
  /**
923
932
  * Starts a Subscribe stream for the active session. BundleStateEvents
@@ -949,7 +958,7 @@ declare class PostMessageEngine implements CanvasEngine {
949
958
  private readonly listeners;
950
959
  private readonly messageListener;
951
960
  private currentBundle;
952
- private currentLayouts;
961
+ private currentArrangement;
953
962
  private currentCanUndo;
954
963
  private currentCanRedo;
955
964
  private currentIsDirty;
@@ -960,7 +969,17 @@ declare class PostMessageEngine implements CanvasEngine {
960
969
  dispose(): void;
961
970
  onEvent(listener: EngineEventListener): () => void;
962
971
  getCurrentView(): CanvasView | null;
972
+ getCurrentBundle(): Bundle | null;
973
+ /**
974
+ * Replace the consumer-owned arrangement and re-project immediately —
975
+ * this is a local view refresh, not a mutation, so it never waits on a
976
+ * round-trip and never carries a viewport intent (the consumer's camera
977
+ * position is unaffected by a drag/collapse/rename it already applied
978
+ * optimistically).
979
+ */
980
+ setArrangement(arrangement: CanvasArrangement): void;
963
981
  private emit;
982
+ private reproject;
964
983
  private adoptState;
965
984
  private nextStateUpdate;
966
985
  private resolvePending;
@@ -987,10 +1006,6 @@ declare class PostMessageEngine implements CanvasEngine {
987
1006
  renameInstance(oldId: string, newId: string): Promise<ApplyResult>;
988
1007
  deleteInstance(instanceId: string): Promise<ApplyResult>;
989
1008
  copyInstances(instanceIds: string[]): Promise<ApplyResult>;
990
- syncLayout(positions: Record<string, {
991
- x: number;
992
- y: number;
993
- }>): Promise<ApplyResult>;
994
1009
  setVariables(variables: VariableDef[]): Promise<ApplyResult>;
995
1010
  setExports(outputs: OutputExportDef[], outputDefs: OutputDefEntry[]): Promise<ApplyResult>;
996
1011
  setTerraform(requiredVersion?: string, requiredProviders?: ProviderDef[]): Promise<ApplyResult>;
@@ -1006,18 +1021,9 @@ declare class PostMessageEngine implements CanvasEngine {
1006
1021
  system: string;
1007
1022
  version: string;
1008
1023
  organization?: string;
1009
- position?: {
1010
- x: number;
1011
- y: number;
1012
- };
1013
1024
  }): Promise<ApplyResult>;
1014
- createGroup(label: string, nodeIds: string[]): Promise<ApplyResult>;
1015
- updateGroup(groupId: string, updates: {
1016
- label?: string;
1017
- node_ids?: string[];
1018
- collapsed?: boolean;
1019
- }): Promise<ApplyResult>;
1020
- deleteGroup(groupId: string): Promise<ApplyResult>;
1025
+ createGroup(nodeIds: string[]): Promise<ApplyResult>;
1026
+ ungroup(groupId: string): Promise<ApplyResult>;
1021
1027
  queryNodeConfig(instanceId: string): Promise<NodeConfig>;
1022
1028
  queryEdgeConfig(source: string, target: string): Promise<EdgeConfig>;
1023
1029
  querySettings(): Promise<SettingsConfig>;
@@ -1049,20 +1055,18 @@ type SnapshotMeta = {
1049
1055
  };
1050
1056
  type SnapshotInProcess = {
1051
1057
  bundle: Bundle;
1052
- layouts?: {
1053
- [key: string]: GraphLayout;
1054
- };
1058
+ arrangement?: CanvasArrangement;
1055
1059
  meta?: SnapshotMeta;
1056
1060
  };
1057
1061
  type SnapshotUrls = {
1058
1062
  bundleUrl: string;
1059
- layoutsUrl: string;
1060
1063
  fetch?: typeof fetch;
1061
1064
  meta?: SnapshotMeta;
1065
+ arrangement?: CanvasArrangement;
1062
1066
  /**
1063
- * Extra request headers sent with the bundle + layouts GETs. Same-origin
1064
- * portal fetches carry the session cookie via `credentials: include`, but
1065
- * the API still resolves org/team scope from `x-org-slug`/`x-team-slug`
1067
+ * Extra request headers sent with the bundle GET. Same-origin portal
1068
+ * fetches carry the session cookie via `credentials: include`, but the
1069
+ * API still resolves org/team scope from `x-org-slug`/`x-team-slug`
1066
1070
  * headers — the caller must supply them here or the reads 400. Embed routes
1067
1071
  * authenticate via the token in the URL and omit this.
1068
1072
  */
@@ -1074,12 +1078,16 @@ declare class SnapshotCanvasEngine implements CanvasEngine {
1074
1078
  private readonly fetchImpl;
1075
1079
  private loadPromise;
1076
1080
  private view;
1081
+ private bundle;
1082
+ private readonly meta;
1083
+ private readonly listeners;
1077
1084
  constructor(input: SnapshotCanvasEngineInput);
1078
1085
  private projectInput;
1079
1086
  private loadView;
1080
1087
  private fetchBytes;
1081
- private fetchLayouts;
1082
1088
  getCurrentView(): CanvasView | null;
1089
+ getCurrentBundle(): Bundle | null;
1090
+ setArrangement(arrangement: CanvasArrangement): void;
1083
1091
  sessionOpen(): Promise<CanvasView>;
1084
1092
  sessionSave(): Promise<{
1085
1093
  saved: boolean;
@@ -1101,10 +1109,6 @@ declare class SnapshotCanvasEngine implements CanvasEngine {
1101
1109
  renameInstance(_oldId: string, _newId: string): Promise<ApplyResult>;
1102
1110
  deleteInstance(_instanceId: string): Promise<ApplyResult>;
1103
1111
  copyInstances(_instanceIds: string[]): Promise<ApplyResult>;
1104
- syncLayout(_positions: Record<string, {
1105
- x: number;
1106
- y: number;
1107
- }>): Promise<ApplyResult>;
1108
1112
  setVariables(_variables: VariableDef[]): Promise<ApplyResult>;
1109
1113
  setExports(_outputs: OutputExportDef[], _outputDefs: OutputDefEntry[]): Promise<ApplyResult>;
1110
1114
  setTerraform(_requiredVersion?: string, _requiredProviders?: ProviderDef[]): Promise<ApplyResult>;
@@ -1120,18 +1124,9 @@ declare class SnapshotCanvasEngine implements CanvasEngine {
1120
1124
  system: string;
1121
1125
  version: string;
1122
1126
  organization?: string;
1123
- position?: {
1124
- x: number;
1125
- y: number;
1126
- };
1127
- }): Promise<ApplyResult>;
1128
- createGroup(_label: string, _nodeIds: string[]): Promise<ApplyResult>;
1129
- updateGroup(_groupId: string, _updates: {
1130
- label?: string;
1131
- node_ids?: string[];
1132
- collapsed?: boolean;
1133
1127
  }): Promise<ApplyResult>;
1134
- deleteGroup(_groupId: string): Promise<ApplyResult>;
1128
+ createGroup(_nodeIds: string[]): Promise<ApplyResult>;
1129
+ ungroup(_groupId: string): Promise<ApplyResult>;
1135
1130
  queryNodeConfig(instanceId: string): Promise<NodeConfig>;
1136
1131
  queryEdgeConfig(source: string, target: string): Promise<EdgeConfig>;
1137
1132
  querySettings(): Promise<SettingsConfig>;
@@ -1162,8 +1157,8 @@ type CanvasContextValue = {
1162
1157
  state: CanvasState;
1163
1158
  engine: CanvasEngine | null;
1164
1159
  readOnly: boolean;
1165
- localGroupCollapseOverrides: Record<string, boolean>;
1166
- toggleLocalGroupCollapse: (groupId: string, currentCollapsed: boolean) => void;
1160
+ arrangement: CanvasArrangement;
1161
+ updateArrangement: (next: CanvasArrangement) => void;
1167
1162
  };
1168
1163
  declare const CanvasContext: React.Context<CanvasContextValue>;
1169
1164
  declare function useCanvas(): CanvasContextValue;