@likec4/diagram 1.39.5 → 1.41.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.
Files changed (140) hide show
  1. package/bundle/{chunk-CW_KClZe.js → chunk-FGcODVxo.js} +1059 -1023
  2. package/bundle/custom.js +61 -60
  3. package/bundle/index.js +2932 -764
  4. package/dist/LikeC4Diagram.d.ts +1 -1
  5. package/dist/LikeC4Diagram.js +7 -4
  6. package/dist/LikeC4Diagram.props.d.ts +6 -1
  7. package/dist/base/const.d.ts +9 -0
  8. package/dist/base/const.js +10 -1
  9. package/dist/base/index.d.ts +1 -0
  10. package/dist/base/primitives/MarkdownBlock.js +2 -0
  11. package/dist/base/primitives/edge/EdgeLabel.js +2 -1
  12. package/dist/base/primitives/edge/EdgeLabelContainer.js +10 -4
  13. package/dist/base/primitives/edge/EdgePath.js +17 -8
  14. package/dist/base/primitives/edge/edge.css.d.ts +0 -1
  15. package/dist/base/primitives/edge/edge.css.js +6 -14
  16. package/dist/base/primitives/element/ElementActionButtons.js +1 -3
  17. package/dist/base/primitives/element/ElementNodeContainer.d.ts +0 -6
  18. package/dist/base/primitives/element/ElementNodeContainer.js +3 -26
  19. package/dist/base/primitives/element/ElementTitle.js +2 -2
  20. package/dist/base/types.d.ts +3 -3
  21. package/dist/bundle/LikeC4View.js +4 -12
  22. package/dist/bundle/LikeC4View.props.d.ts +12 -3
  23. package/dist/bundle/custom.js +1 -1
  24. package/dist/components/Link.js +28 -20
  25. package/dist/custom/customNodes.d.ts +6 -0
  26. package/dist/custom/customNodes.js +2 -1
  27. package/dist/custom/index.js +1 -1
  28. package/dist/hooks/useDiagram.d.ts +5 -1
  29. package/dist/hooks/useDiagram.js +3 -0
  30. package/dist/hooks/useXYFlow.d.ts +4 -439
  31. package/dist/likec4diagram/DiagramUI.js +1 -1
  32. package/dist/likec4diagram/DiagramXYFlow.js +8 -4
  33. package/dist/likec4diagram/convert-to-xyflow.d.ts +14 -0
  34. package/dist/likec4diagram/convert-to-xyflow.js +29 -0
  35. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +4 -4
  36. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +0 -1
  37. package/dist/likec4diagram/custom/edges/SequenceStepEdge.d.ts +3 -0
  38. package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +71 -0
  39. package/dist/likec4diagram/custom/index.js +7 -2
  40. package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +2 -1
  41. package/dist/likec4diagram/custom/nodes/SequenceActorNode.d.ts +4 -0
  42. package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +157 -0
  43. package/dist/likec4diagram/custom/nodes/index.d.ts +1 -0
  44. package/dist/likec4diagram/custom/nodes/nodes.d.ts +1 -2
  45. package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +31 -27
  46. package/dist/likec4diagram/types.d.ts +41 -7
  47. package/dist/likec4diagram/xyflow-diagram/diagram-view.d.ts +11 -0
  48. package/dist/likec4diagram/{useViewToNodesEdges.js → xyflow-diagram/diagram-view.js} +4 -13
  49. package/dist/likec4diagram/xyflow-sequence/_types.d.ts +41 -0
  50. package/dist/likec4diagram/xyflow-sequence/const.d.ts +17 -0
  51. package/dist/likec4diagram/xyflow-sequence/const.js +16 -0
  52. package/dist/likec4diagram/xyflow-sequence/layouter.d.ts +46 -0
  53. package/dist/likec4diagram/xyflow-sequence/layouter.js +408 -0
  54. package/dist/likec4diagram/xyflow-sequence/sequence-view.d.ts +7 -0
  55. package/dist/likec4diagram/xyflow-sequence/sequence-view.js +273 -0
  56. package/dist/likec4diagram/xyflow-sequence/utils.d.ts +14 -0
  57. package/dist/likec4diagram/xyflow-sequence/utils.js +92 -0
  58. package/dist/navigationpanel/NavigationPanelControls.js +2 -2
  59. package/dist/navigationpanel/controls/ViewDetailsCard.js +27 -12
  60. package/dist/navigationpanel/dropdown/ProjectsMenu.js +53 -44
  61. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.d.ts +1 -2
  62. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +10 -41
  63. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +292 -0
  64. package/dist/navigationpanel/walkthrough/DynamicViewControls.js +119 -0
  65. package/dist/navigationpanel/walkthrough/index.d.ts +2 -1
  66. package/dist/overlays/element-details/ElementDetailsCard.css.js +7 -1
  67. package/dist/overlays/element-details/ElementDetailsCard.js +17 -19
  68. package/dist/overlays/relationship-details/RelationshipDetails.js +4 -1
  69. package/dist/overlays/relationship-details/layout.d.ts +3 -2
  70. package/dist/overlays/relationship-details/layout.js +1 -2
  71. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +2 -1
  72. package/dist/overlays/relationships-browser/layout.js +1 -1
  73. package/dist/search/components/ElementsColumn.js +1 -1
  74. package/dist/state/DiagramActorProvider.d.ts +3 -2
  75. package/dist/state/DiagramActorProvider.js +40 -41
  76. package/dist/state/assign.js +11 -4
  77. package/dist/state/diagram-machine.d.ts +224 -194
  78. package/dist/state/diagram-machine.js +170 -63
  79. package/dist/state/utils.d.ts +7 -1
  80. package/dist/state/utils.js +67 -7
  81. package/dist/styles-min.css +1 -1
  82. package/dist/styles.css +1 -1
  83. package/dist/styles.css2.js +1 -1
  84. package/package.json +8 -7
  85. package/panda.buildinfo.json +45 -24
  86. package/src/LikeC4Diagram.props.ts +14 -1
  87. package/src/LikeC4Diagram.tsx +7 -4
  88. package/src/base/const.ts +12 -0
  89. package/src/base/index.ts +2 -0
  90. package/src/base/primitives/MarkdownBlock.tsx +2 -0
  91. package/src/base/primitives/edge/EdgeLabel.tsx +23 -19
  92. package/src/base/primitives/edge/EdgeLabelContainer.tsx +12 -7
  93. package/src/base/primitives/edge/EdgePath.tsx +25 -14
  94. package/src/base/primitives/edge/edge.css.ts +5 -14
  95. package/src/base/primitives/element/ElementActionButtons.tsx +1 -3
  96. package/src/base/primitives/element/ElementNodeContainer.tsx +3 -30
  97. package/src/base/primitives/element/ElementTitle.tsx +2 -3
  98. package/src/base/types.ts +7 -5
  99. package/src/bundle/LikeC4View.props.ts +14 -3
  100. package/src/bundle/LikeC4View.tsx +4 -14
  101. package/src/bundle/ReactLikeC4.tsx +1 -2
  102. package/src/components/Link.tsx +21 -18
  103. package/src/custom/customNodes.ts +7 -0
  104. package/src/hooks/useDiagram.ts +10 -0
  105. package/src/likec4diagram/DiagramUI.tsx +1 -1
  106. package/src/likec4diagram/DiagramXYFlow.tsx +10 -5
  107. package/src/likec4diagram/convert-to-xyflow.ts +45 -0
  108. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +0 -1
  109. package/src/likec4diagram/custom/edges/SequenceStepEdge.tsx +65 -0
  110. package/src/likec4diagram/custom/index.ts +7 -1
  111. package/src/likec4diagram/custom/nodes/ElementActions.tsx +4 -2
  112. package/src/likec4diagram/custom/nodes/SequenceActorNode.tsx +175 -0
  113. package/src/likec4diagram/custom/nodes/index.ts +1 -0
  114. package/src/likec4diagram/custom/nodes/nodes.tsx +1 -1
  115. package/src/likec4diagram/relationship-popover/RelationshipPopover.tsx +36 -30
  116. package/src/likec4diagram/types.ts +96 -13
  117. package/src/likec4diagram/{useViewToNodesEdges.ts → xyflow-diagram/diagram-view.ts} +7 -28
  118. package/src/likec4diagram/xyflow-sequence/_types.ts +45 -0
  119. package/src/likec4diagram/xyflow-sequence/const.ts +37 -0
  120. package/src/likec4diagram/xyflow-sequence/layouter.ts +567 -0
  121. package/src/likec4diagram/xyflow-sequence/sequence-view.ts +337 -0
  122. package/src/likec4diagram/xyflow-sequence/utils.ts +112 -0
  123. package/src/navigationpanel/NavigationPanelControls.tsx +2 -2
  124. package/src/navigationpanel/controls/ViewDetailsCard.tsx +29 -12
  125. package/src/navigationpanel/dropdown/ProjectsMenu.tsx +5 -1
  126. package/src/navigationpanel/walkthrough/ActiveWalkthroughControls.tsx +5 -40
  127. package/src/navigationpanel/walkthrough/DynamicViewControls.tsx +125 -0
  128. package/src/navigationpanel/walkthrough/index.tsx +2 -1
  129. package/src/overlays/element-details/ElementDetailsCard.css.ts +7 -1
  130. package/src/overlays/element-details/ElementDetailsCard.tsx +24 -25
  131. package/src/overlays/relationship-details/RelationshipDetails.tsx +5 -2
  132. package/src/overlays/relationship-details/layout.ts +4 -3
  133. package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +2 -1
  134. package/src/overlays/relationships-browser/layout.ts +1 -1
  135. package/src/search/components/ElementsColumn.tsx +1 -1
  136. package/src/state/DiagramActorProvider.tsx +46 -51
  137. package/src/state/assign.ts +18 -5
  138. package/src/state/diagram-machine.ts +207 -75
  139. package/src/state/utils.ts +81 -7
  140. package/dist/likec4diagram/useViewToNodesEdges.d.ts +0 -12
@@ -1,11 +1,12 @@
1
- import { DiagramView, WhereOperator } from '@likec4/core/types';
1
+ import { DiagramView, DynamicViewDisplayVariant, WhereOperator } from '@likec4/core/types';
2
2
  import { PropsWithChildren } from 'react';
3
3
  import { ViewPadding } from '../LikeC4Diagram.props';
4
- export declare function DiagramActorProvider({ view, zoomable, pannable, fitViewPadding, nodesSelectable, where, children, }: PropsWithChildren<{
4
+ export declare function DiagramActorProvider({ view, zoomable, pannable, fitViewPadding, nodesSelectable, where, children, dynamicViewVariant: _defaultVariant, }: PropsWithChildren<{
5
5
  view: DiagramView;
6
6
  zoomable: boolean;
7
7
  pannable: boolean;
8
8
  fitViewPadding: ViewPadding;
9
9
  nodesSelectable: boolean;
10
10
  where: WhereOperator | null;
11
+ dynamicViewVariant: DynamicViewDisplayVariant | undefined;
11
12
  }>): import("react/jsx-runtime").JSX.Element;
@@ -1,29 +1,22 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useCustomCompareEffect } from '@react-hookz/web';
2
+ import { useCustomCompareEffect, useRafEffect } from '@react-hookz/web';
3
3
  import { useActorRef, useSelector } from '@xstate/react';
4
4
  import { useStoreApi } from '@xyflow/react';
5
5
  import { shallowEqual, deepEqual } from 'fast-equals';
6
- import { useRef, useEffect } from 'react';
6
+ import { useRef, useMemo } from 'react';
7
7
  import { ErrorBoundary } from '../components/ErrorFallback.js';
8
8
  import { useDiagramEventHandlers } from '../context/DiagramEventHandlers.js';
9
9
  import { useEnabledFeatures, DiagramFeatures } from '../context/DiagramFeatures.js';
10
10
  import { DiagramActorContextProvider } from '../hooks/safeContext.js';
11
- import { useCurrentViewId } from '../hooks/useCurrentViewId.js';
12
- import { useViewToNodesEdges } from '../likec4diagram/useViewToNodesEdges.js';
11
+ import { convertToXYFlow } from '../likec4diagram/convert-to-xyflow.js';
13
12
  import { CurrentViewModelContext } from '../likec4model/LikeC4ModelContext.js';
14
13
  import { useLikeC4Model } from '../likec4model/useLikeC4Model.js';
15
14
  import { diagramMachine } from './diagram-machine.js';
16
15
  import { syncManualLayoutActorLogic } from './syncManualLayoutActor.js';
17
16
  import { useOnDiagramEvent } from '../hooks/useDiagram.js';
18
17
 
19
- const selectToggledFeatures = (state) => {
20
- if (state.context.features.enableReadOnly || state.context.activeWalkthrough) {
21
- return {
22
- ...state.context.toggledFeatures,
23
- enableReadOnly: true
24
- };
25
- }
26
- return state.context.toggledFeatures;
18
+ const selectDynamicViewVariant = (state) => {
19
+ return state.context.dynamicViewVariant;
27
20
  };
28
21
  function DiagramActorProvider({
29
22
  view,
@@ -32,7 +25,8 @@ function DiagramActorProvider({
32
25
  fitViewPadding,
33
26
  nodesSelectable,
34
27
  where,
35
- children
28
+ children,
29
+ dynamicViewVariant: _defaultVariant
36
30
  }) {
37
31
  const { handlersRef } = useDiagramEventHandlers();
38
32
  const xystore = useStoreApi();
@@ -62,7 +56,8 @@ function DiagramActorProvider({
62
56
  zoomable,
63
57
  pannable,
64
58
  fitViewPadding,
65
- nodesSelectable
59
+ nodesSelectable,
60
+ dynamicViewVariant: _defaultVariant
66
61
  }
67
62
  }
68
63
  );
@@ -81,25 +76,42 @@ function DiagramActorProvider({
81
76
  [zoomable, pannable, fitViewPadding, nodesSelectable],
82
77
  deepEqual
83
78
  );
84
- const { xyedges, xynodes } = useViewToNodesEdges({
85
- view,
86
- where,
87
- nodesSelectable
88
- });
89
- useEffect(() => {
90
- actorRef.send({ type: "update.view", view, xyedges, xynodes });
91
- }, [view, xyedges, xynodes]);
92
- const toggledFeatures = useSelector(actorRef, selectToggledFeatures, shallowEqual);
79
+ const dynamicViewVariant = useSelector(actorRef, selectDynamicViewVariant);
80
+ const update = useMemo(
81
+ () => convertToXYFlow({ view, where, nodesSelectable, dynamicViewVariant }),
82
+ [view, where, nodesSelectable, dynamicViewVariant]
83
+ );
84
+ useRafEffect(() => {
85
+ actorRef.send({
86
+ type: "update.view",
87
+ ...update
88
+ });
89
+ }, [actorRef, update]);
93
90
  return /* @__PURE__ */ jsxs(DiagramActorContextProvider, { value: actorRef, children: [
94
- /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(CurrentViewModelProvider, { children }) }) }),
91
+ /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(CurrentViewModelProvider, { actorRef, children }) }),
95
92
  /* @__PURE__ */ jsx(DiagramActorEventListener, { actorRef })
96
93
  ] });
97
94
  }
98
- function CurrentViewModelProvider({ children }) {
99
- const viewId = useCurrentViewId();
95
+ const selectViewIdAndToggledFeatures = (state) => {
96
+ if (state.context.features.enableReadOnly || state.context.activeWalkthrough) {
97
+ return {
98
+ viewId: state.context.view.id,
99
+ toggledFeatures: {
100
+ ...state.context.toggledFeatures,
101
+ enableReadOnly: true
102
+ }
103
+ };
104
+ }
105
+ return {
106
+ viewId: state.context.view.id,
107
+ toggledFeatures: state.context.toggledFeatures
108
+ };
109
+ };
110
+ function CurrentViewModelProvider({ children, actorRef }) {
111
+ const { viewId, toggledFeatures } = useSelector(actorRef, selectViewIdAndToggledFeatures, deepEqual);
100
112
  const likec4model = useLikeC4Model();
101
113
  const viewmodel = likec4model.findView(viewId);
102
- return /* @__PURE__ */ jsx(CurrentViewModelContext.Provider, { value: viewmodel, children });
114
+ return /* @__PURE__ */ jsx(CurrentViewModelContext.Provider, { value: viewmodel, children: /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children }) });
103
115
  }
104
116
  function DiagramActorEventListener({ actorRef }) {
105
117
  const {
@@ -107,20 +119,7 @@ function DiagramActorEventListener({ actorRef }) {
107
119
  onOpenSource
108
120
  } = useDiagramEventHandlers();
109
121
  useOnDiagramEvent("openSource", ({ params }) => onOpenSource?.(params));
110
- useEffect(() => {
111
- if (!onNavigateTo) return;
112
- let frame;
113
- const subscription = actorRef.on("navigateTo", ({ viewId }) => {
114
- cancelAnimationFrame(frame);
115
- frame = requestAnimationFrame(() => {
116
- onNavigateTo(viewId);
117
- });
118
- });
119
- return () => {
120
- cancelAnimationFrame(frame);
121
- subscription.unsubscribe();
122
- };
123
- }, [actorRef, onNavigateTo]);
122
+ useOnDiagramEvent("navigateTo", ({ viewId }) => onNavigateTo?.(viewId));
124
123
  return null;
125
124
  }
126
125
 
@@ -4,6 +4,7 @@ import { deepEqual } from 'fast-equals';
4
4
  import { omit, mergeDeep, isEmpty } from 'remeda';
5
5
  import { assertEvent } from 'xstate';
6
6
  import { Base } from '../base/types.js';
7
+ import { SeqParallelAreaColor } from '../likec4diagram/xyflow-sequence/const.js';
7
8
  import { VectorImpl, vector } from '../utils/vector.js';
8
9
 
9
10
  function lastClickedNode(params) {
@@ -52,12 +53,12 @@ function mergeXYNodesEdges({ context, event }) {
52
53
  const currentEdges = context.xyedges;
53
54
  xyedges = event.xyedges.map((update) => {
54
55
  const existing = currentEdges.find((n) => n.id === update.id);
55
- if (existing) {
56
- if (deepEqual(existing.hidden ?? false, update.hidden ?? false) && deepEqual(existing.data, update.data)) {
56
+ if (existing && existing.type === update.type) {
57
+ if (deepEqual(existing.hidden ?? false, update.hidden ?? false) && deepEqual(existing.data, update.data) && deepEqual(existing.source, update.source) && deepEqual(existing.target, update.target) && deepEqual(existing.sourceHandle, update.sourceHandle) && deepEqual(existing.targetHandle, update.targetHandle)) {
57
58
  return existing;
58
59
  }
59
60
  return {
60
- ...existing,
61
+ ...omit(existing, ["sourceHandle", "targetHandle"]),
61
62
  ...update,
62
63
  data: {
63
64
  ...existing.data,
@@ -338,11 +339,17 @@ function updateActiveWalkthrough({ context }) {
338
339
  const active = stepId === edge.id || !!parallelPrefix && edge.id.startsWith(parallelPrefix);
339
340
  return Base.setData(edge, {
340
341
  active,
341
- dimmed: !active
342
+ dimmed: stepId !== edge.id
342
343
  });
343
344
  }),
344
345
  xynodes: context.xynodes.map((node) => {
345
346
  const dimmed = step.source !== node.id && step.target !== node.id;
347
+ if (node.type === "seq-parallel") {
348
+ return Base.setData(node, {
349
+ color: parallelPrefix === node.data.parallelPrefix ? SeqParallelAreaColor.active : SeqParallelAreaColor.default,
350
+ dimmed
351
+ });
352
+ }
346
353
  return Base.setDimmed(node, dimmed);
347
354
  })
348
355
  };