@likec4/diagram 1.22.0 → 1.22.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.
@@ -1,7 +1,7 @@
1
1
  import { ExclusiveUnion, NonEmptyArray } from '@likec4/core';
2
2
  import { PropsWithChildren } from 'react';
3
3
  declare const FeatureNames: readonly ["Controls", "ReadOnly", "FocusMode", "NavigateTo", "ElementDetails", "RelationshipDetails", "RelationshipBrowser", "Search", "NavigationButtons", "Notations", "DynamicViewWalkthrough", "EdgeEditing", "ViewTitle", "FitView", "LikeC4Model", "Vscode"];
4
- type FeatureName = typeof FeatureNames[number];
4
+ export type FeatureName = typeof FeatureNames[number];
5
5
  export type EnabledFeatures = {
6
6
  [P in `enable${FeatureName}`]: boolean;
7
7
  };
@@ -1,5 +1,6 @@
1
1
  import { EdgeId, Fqn, NodeId, ViewId, DiagramView, ViewChange, RelationId, Color, RelationshipLineType, NonEmptyArray, Point, RelationshipArrowType, BBox, XYPoint, DiagramNode, DiagramEdge } from '@likec4/core';
2
2
  import { PartialDeep } from 'type-fest';
3
+ import { FeatureName } from '../context/DiagramFeatures';
3
4
  import { OpenSourceParams } from '../LikeC4Diagram.props';
4
5
  import { AlignmentMode } from '../likec4diagram/state/aligners';
5
6
  import { DiagramContext, Events, Input, ActionArg } from '../likec4diagram/state/machine';
@@ -14,7 +15,6 @@ import { ReactNode, CSSProperties } from 'react';
14
15
  import { Input, XYStoreApi, Events } from '../overlays/relationships-browser/actor';
15
16
  import { LayoutRelationshipsViewResult } from '../overlays/relationships-browser/-useRelationshipsView';
16
17
  import { focusedBounds } from '../likec4diagram/state/utils';
17
- import { EnabledFeatures } from '../context';
18
18
  export declare function useDiagram(): {
19
19
  send: (event: Events) => void;
20
20
  navigateTo: (viewId: ViewId, fromNode?: NodeId) => void;
@@ -1028,6 +1028,9 @@ export declare function useDiagram(): {
1028
1028
  enableLikeC4Model: boolean;
1029
1029
  enableVscode: boolean;
1030
1030
  };
1031
+ toggledFeatures: {
1032
+ enableReadOnly: true;
1033
+ };
1031
1034
  initialized: false;
1032
1035
  viewportChangedManually: false;
1033
1036
  lastOnNavigate: null;
@@ -1787,6 +1790,10 @@ export declare function useDiagram(): {
1787
1790
  toPosition: XYPoint;
1788
1791
  };
1789
1792
  };
1793
+ updateFeatures: {
1794
+ type: "updateFeatures";
1795
+ params: NonReducibleUnknown;
1796
+ };
1790
1797
  }>, Values<{
1791
1798
  "enabled: FitView": {
1792
1799
  type: "enabled: FitView";
@@ -4487,6 +4494,10 @@ export declare function useDiagram(): {
4487
4494
  toPosition: XYPoint;
4488
4495
  };
4489
4496
  };
4497
+ updateFeatures: {
4498
+ type: "updateFeatures";
4499
+ params: NonReducibleUnknown;
4500
+ };
4490
4501
  }>, Values<{
4491
4502
  "enabled: FitView": {
4492
4503
  type: "enabled: FitView";
@@ -5731,6 +5742,10 @@ export declare function useDiagram(): {
5731
5742
  toPosition: XYPoint;
5732
5743
  };
5733
5744
  };
5745
+ updateFeatures: {
5746
+ type: "updateFeatures";
5747
+ params: NonReducibleUnknown;
5748
+ };
5734
5749
  }>, Values<{
5735
5750
  "enabled: FitView": {
5736
5751
  type: "enabled: FitView";
@@ -6036,6 +6051,10 @@ export declare function useDiagram(): {
6036
6051
  toPosition: XYPoint;
6037
6052
  };
6038
6053
  };
6054
+ updateFeatures: {
6055
+ type: "updateFeatures";
6056
+ params: NonReducibleUnknown;
6057
+ };
6039
6058
  }>, Values<{
6040
6059
  "enabled: FitView": {
6041
6060
  type: "enabled: FitView";
@@ -7202,6 +7221,10 @@ export declare function useDiagram(): {
7202
7221
  toPosition: XYPoint;
7203
7222
  };
7204
7223
  };
7224
+ updateFeatures: {
7225
+ type: "updateFeatures";
7226
+ params: NonReducibleUnknown;
7227
+ };
7205
7228
  }>, Values<{
7206
7229
  "enabled: FitView": {
7207
7230
  type: "enabled: FitView";
@@ -7515,6 +7538,10 @@ export declare function useDiagram(): {
7515
7538
  toPosition: XYPoint;
7516
7539
  };
7517
7540
  };
7541
+ updateFeatures: {
7542
+ type: "updateFeatures";
7543
+ params: NonReducibleUnknown;
7544
+ };
7518
7545
  }>, Values<{
7519
7546
  "enabled: FitView": {
7520
7547
  type: "enabled: FitView";
@@ -9341,6 +9368,10 @@ export declare function useDiagram(): {
9341
9368
  toPosition: XYPoint;
9342
9369
  };
9343
9370
  };
9371
+ updateFeatures: {
9372
+ type: "updateFeatures";
9373
+ params: NonReducibleUnknown;
9374
+ };
9344
9375
  }>, Values<{
9345
9376
  "enabled: FitView": {
9346
9377
  type: "enabled: FitView";
@@ -9596,10 +9627,10 @@ export declare function useDiagram(): {
9596
9627
  }>, never, never, never, never>;
9597
9628
  };
9598
9629
  readonly 'update.features': {
9599
- readonly actions: ActionFunction<DiagramContext, {
9600
- type: "update.features";
9601
- features: EnabledFeatures;
9602
- }, Events, undefined, Values<{
9630
+ readonly actions: "updateFeatures";
9631
+ };
9632
+ readonly 'update.nodeData': {
9633
+ readonly actions: ActionFunction<DiagramContext, Events, Events, undefined, Values<{
9603
9634
  hotkeyActor: {
9604
9635
  src: "hotkeyActor";
9605
9636
  logic: CallbackActorLogic<AnyEventObject, NonReducibleUnknown, HotKeyEvent>;
@@ -9810,7 +9841,7 @@ export declare function useDiagram(): {
9810
9841
  };
9811
9842
  }>, never, never, never, never>;
9812
9843
  };
9813
- readonly 'update.nodeData': {
9844
+ readonly 'update.edgeData': {
9814
9845
  readonly actions: ActionFunction<DiagramContext, Events, Events, undefined, Values<{
9815
9846
  hotkeyActor: {
9816
9847
  src: "hotkeyActor";
@@ -10022,8 +10053,27 @@ export declare function useDiagram(): {
10022
10053
  };
10023
10054
  }>, never, never, never, never>;
10024
10055
  };
10025
- readonly 'update.edgeData': {
10026
- readonly actions: ActionFunction<DiagramContext, Events, Events, undefined, Values<{
10056
+ readonly 'layout.align': {
10057
+ readonly guard: "not readonly";
10058
+ readonly actions: readonly [{
10059
+ readonly type: "layout.align";
10060
+ readonly params: ({ event }: {
10061
+ context: DiagramContext;
10062
+ event: {
10063
+ type: "layout.align";
10064
+ mode: AlignmentMode;
10065
+ };
10066
+ }) => {
10067
+ mode: AlignmentMode;
10068
+ };
10069
+ }, ActionFunction<DiagramContext, {
10070
+ type: "layout.align";
10071
+ mode: AlignmentMode;
10072
+ }, Events, undefined, never, never, never, never, never>];
10073
+ };
10074
+ readonly 'layout.resetEdgeControlPoints': {
10075
+ readonly guard: "not readonly";
10076
+ readonly actions: readonly [ ActionFunction<DiagramContext, Events, Events, undefined, Values<{
10027
10077
  hotkeyActor: {
10028
10078
  src: "hotkeyActor";
10029
10079
  logic: CallbackActorLogic<AnyEventObject, NonReducibleUnknown, HotKeyEvent>;
@@ -10232,29 +10282,26 @@ export declare function useDiagram(): {
10232
10282
  }, "active", any, any, any>, Events, Input, any, any>;
10233
10283
  id: "relationshipsBrowser";
10234
10284
  };
10235
- }>, never, never, never, never>;
10285
+ }>, never, never, never, never>, ActionFunction<DiagramContext, {
10286
+ type: "layout.resetEdgeControlPoints";
10287
+ }, Events, undefined, never, never, never, never, never>];
10236
10288
  };
10237
- readonly 'layout.align': {
10238
- readonly guard: "not readonly";
10239
- readonly actions: readonly [{
10240
- readonly type: "layout.align";
10241
- readonly params: ({ event }: {
10242
- context: DiagramContext;
10243
- event: {
10244
- type: "layout.align";
10245
- mode: AlignmentMode;
10246
- };
10247
- }) => {
10248
- mode: AlignmentMode;
10249
- };
10250
- }, ActionFunction<DiagramContext, {
10251
- type: "layout.align";
10252
- mode: AlignmentMode;
10289
+ readonly 'xyflow.resized': {
10290
+ readonly guard: ({ context }: {
10291
+ context: DiagramContext;
10292
+ }) => boolean;
10293
+ readonly actions: readonly [ CancelAction<DiagramContext, {
10294
+ type: "xyflow.resized";
10295
+ }, undefined, Events>, ActionFunction<DiagramContext, {
10296
+ type: "xyflow.resized";
10253
10297
  }, Events, undefined, never, never, never, never, never>];
10254
10298
  };
10255
- readonly 'layout.resetEdgeControlPoints': {
10256
- readonly guard: "not readonly";
10257
- readonly actions: readonly [ ActionFunction<DiagramContext, Events, Events, undefined, Values<{
10299
+ readonly 'open.elementDetails': {
10300
+ readonly actions: ActionFunction<DiagramContext, {
10301
+ type: "open.elementDetails";
10302
+ fqn: Fqn;
10303
+ fromNode?: NodeId | undefined;
10304
+ }, Events, undefined, Values<{
10258
10305
  hotkeyActor: {
10259
10306
  src: "hotkeyActor";
10260
10307
  logic: CallbackActorLogic<AnyEventObject, NonReducibleUnknown, HotKeyEvent>;
@@ -10463,25 +10510,37 @@ export declare function useDiagram(): {
10463
10510
  }, "active", any, any, any>, Events, Input, any, any>;
10464
10511
  id: "relationshipsBrowser";
10465
10512
  };
10466
- }>, never, never, never, never>, ActionFunction<DiagramContext, {
10467
- type: "layout.resetEdgeControlPoints";
10468
- }, Events, undefined, never, never, never, never, never>];
10513
+ }>, never, never, never, never>;
10514
+ readonly target: ".overlay.elementDetails";
10469
10515
  };
10470
- readonly 'xyflow.resized': {
10471
- readonly guard: ({ context }: {
10472
- context: DiagramContext;
10473
- }) => boolean;
10474
- readonly actions: readonly [ CancelAction<DiagramContext, {
10475
- type: "xyflow.resized";
10476
- }, undefined, Events>, ActionFunction<DiagramContext, {
10477
- type: "xyflow.resized";
10478
- }, Events, undefined, never, never, never, never, never>];
10516
+ readonly 'open.relationshipDetails': {
10517
+ readonly target: ".overlay.relationshipDetails";
10479
10518
  };
10480
- readonly 'open.elementDetails': {
10519
+ readonly 'open.relationshipsBrowser': {
10520
+ readonly target: ".overlay.relationshipsBrowser";
10521
+ };
10522
+ readonly 'open.source': {
10523
+ readonly actions: {
10524
+ readonly type: "trigger:OpenSource";
10525
+ readonly params: (data: {
10526
+ context: DiagramContext;
10527
+ event: {
10528
+ type: "open.source";
10529
+ } & OpenSourceParams;
10530
+ }) => {
10531
+ type: "open.source";
10532
+ } & OpenSourceParams;
10533
+ };
10534
+ };
10535
+ readonly 'walkthrough.start': {
10536
+ readonly guard: "is dynamic view";
10537
+ readonly target: ".walkthrough";
10538
+ };
10539
+ readonly 'toggle.feature': {
10481
10540
  readonly actions: ActionFunction<DiagramContext, {
10482
- type: "open.elementDetails";
10483
- fqn: Fqn;
10484
- fromNode?: NodeId | undefined;
10541
+ type: "toggle.feature";
10542
+ feature: FeatureName;
10543
+ forceValue?: boolean;
10485
10544
  }, Events, undefined, Values<{
10486
10545
  hotkeyActor: {
10487
10546
  src: "hotkeyActor";
@@ -10692,30 +10751,6 @@ export declare function useDiagram(): {
10692
10751
  id: "relationshipsBrowser";
10693
10752
  };
10694
10753
  }>, never, never, never, never>;
10695
- readonly target: ".overlay.elementDetails";
10696
- };
10697
- readonly 'open.relationshipDetails': {
10698
- readonly target: ".overlay.relationshipDetails";
10699
- };
10700
- readonly 'open.relationshipsBrowser': {
10701
- readonly target: ".overlay.relationshipsBrowser";
10702
- };
10703
- readonly 'open.source': {
10704
- readonly actions: {
10705
- readonly type: "trigger:OpenSource";
10706
- readonly params: (data: {
10707
- context: DiagramContext;
10708
- event: {
10709
- type: "open.source";
10710
- } & OpenSourceParams;
10711
- }) => {
10712
- type: "open.source";
10713
- } & OpenSourceParams;
10714
- };
10715
- };
10716
- readonly 'walkthrough.start': {
10717
- readonly guard: "is dynamic view";
10718
- readonly target: ".walkthrough";
10719
10754
  };
10720
10755
  };
10721
10756
  readonly exit: readonly [ StopAction<DiagramContext, Events, undefined, Events>, StopAction<DiagramContext, Events, undefined, Events>, ActionFunction<DiagramContext, Events, Events, undefined, Values<{
@@ -10944,4 +10979,5 @@ export declare function useDiagram(): {
10944
10979
  startWalkthrough: () => void;
10945
10980
  walkthroughStep: (direction?: "next" | "previous") => void;
10946
10981
  stopWalkthrough: () => void;
10982
+ toggleFeature: (feature: FeatureName, forceValue?: boolean) => void;
10947
10983
  };
@@ -111,6 +111,9 @@ function useDiagram() {
111
111
  },
112
112
  stopWalkthrough: () => {
113
113
  actor.send({ type: "walkthrough.end" });
114
+ },
115
+ toggleFeature: (feature, forceValue) => {
116
+ actor.send({ type: "toggle.feature", feature, ...forceValue !== void 0 && { forceValue } });
114
117
  }
115
118
  }), [actor]);
116
119
  }
@@ -5,10 +5,11 @@ import { useEffect } from "react";
5
5
  import { useDiagramActor } from "../hooks/useDiagramActor.js";
6
6
  import { useUpdateEffect } from "../hooks/useUpdateEffect.js";
7
7
  import { LikeC4ViewMachineContextProvider } from "./state/actorContext.js";
8
+ import { useDiagramContext } from "../hooks/useDiagramContext.js";
8
9
  import { diagramMachine } from "./state/machine.js";
9
10
  import { syncManualLayoutActor } from "./state/syncManualLayoutActor.js";
10
11
  import { useDiagramEventHandlers } from "../context/DiagramEventHandlers.js";
11
- import { useEnabledFeatures } from "../context/DiagramFeatures.js";
12
+ import { useEnabledFeatures, DiagramFeatures } from "../context/DiagramFeatures.js";
12
13
  function DiagramActor({ input, children }) {
13
14
  const { onNavigateTo, onOpenSource, onChange } = useDiagramEventHandlers();
14
15
  const xystore = useStoreApi();
@@ -47,7 +48,7 @@ function DiagramActor({ input, children }) {
47
48
  },
48
49
  children: [
49
50
  /* @__PURE__ */ jsx(SyncStore, { input }),
50
- children
51
+ /* @__PURE__ */ jsx(DiagramActorToggledFeatures, { children })
51
52
  ]
52
53
  }
53
54
  );
@@ -66,6 +67,16 @@ const SyncStore = ({ input: { view, xyedges, xynodes, ...inputs } }) => {
66
67
  }, [send, view, xyedges, xynodes]);
67
68
  return null;
68
69
  };
70
+ function DiagramActorToggledFeatures({ children }) {
71
+ const toggledFeatures = useDiagramContext((s) => s.toggledFeatures);
72
+ return /* @__PURE__ */ jsx(
73
+ DiagramFeatures,
74
+ {
75
+ overrides: toggledFeatures,
76
+ children
77
+ }
78
+ );
79
+ }
69
80
  export {
70
81
  DiagramActor
71
82
  };
@@ -20,9 +20,16 @@ const selectXYProps = (ctx) => ({
20
20
  zoomable: ctx.zoomable,
21
21
  fitViewPadding: ctx.fitViewPadding,
22
22
  enableFitView: ctx.features.enableFitView,
23
- enableReadOnly: ctx.features.enableReadOnly
23
+ enableReadOnly: ctx.features.enableReadOnly,
24
+ ...!ctx.features.enableFitView && {
25
+ viewport: {
26
+ x: -Math.min(ctx.view.bounds.x, 0),
27
+ y: -Math.min(ctx.view.bounds.y, 0),
28
+ zoom: 1
29
+ }
30
+ }
24
31
  });
25
- const equalsXYProps = (a, b) => a.initialized === b.initialized && a.pannable === b.pannable && a.zoomable === b.zoomable && a.fitViewPadding === b.fitViewPadding && a.enableFitView === b.enableFitView && a.enableReadOnly === b.enableReadOnly && shallowEqual(a.nodes, b.nodes) && shallowEqual(a.edges, b.edges);
32
+ const equalsXYProps = (a, b) => a.initialized === b.initialized && a.pannable === b.pannable && a.zoomable === b.zoomable && a.fitViewPadding === b.fitViewPadding && a.enableFitView === b.enableFitView && a.enableReadOnly === b.enableReadOnly && shallowEqual(a.nodes, b.nodes) && shallowEqual(a.edges, b.edges) && shallowEqual(a.viewport, b.viewport);
26
33
  const LikeC4DiagramXYFlow = memo(({ background, nodesDraggable, nodesSelectable }) => {
27
34
  const diagram = useDiagram();
28
35
  const {