@likec4/diagram 1.39.4 → 1.40.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 (123) hide show
  1. package/bundle/{chunk-CW_KClZe.js → chunk-CDr-4Ymp.js} +936 -903
  2. package/bundle/custom.js +61 -60
  3. package/bundle/index.js +2667 -539
  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/edge/EdgeLabel.js +2 -1
  11. package/dist/base/primitives/edge/EdgeLabelContainer.js +10 -4
  12. package/dist/base/primitives/edge/EdgePath.js +17 -8
  13. package/dist/base/primitives/edge/edge.css.d.ts +0 -1
  14. package/dist/base/primitives/edge/edge.css.js +6 -14
  15. package/dist/base/primitives/element/ElementActionButtons.js +1 -3
  16. package/dist/base/primitives/element/ElementNodeContainer.d.ts +0 -6
  17. package/dist/base/primitives/element/ElementNodeContainer.js +3 -26
  18. package/dist/base/primitives/element/ElementTitle.js +2 -2
  19. package/dist/base/types.d.ts +3 -3
  20. package/dist/bundle/LikeC4View.js +4 -12
  21. package/dist/bundle/LikeC4View.props.d.ts +12 -3
  22. package/dist/bundle/custom.js +1 -1
  23. package/dist/custom/customNodes.d.ts +6 -0
  24. package/dist/custom/customNodes.js +2 -1
  25. package/dist/custom/index.js +1 -1
  26. package/dist/hooks/useDiagram.d.ts +5 -1
  27. package/dist/hooks/useDiagram.js +3 -0
  28. package/dist/hooks/useXYFlow.d.ts +4 -439
  29. package/dist/likec4diagram/DiagramUI.js +1 -1
  30. package/dist/likec4diagram/DiagramXYFlow.js +8 -4
  31. package/dist/likec4diagram/convert-to-xyflow.d.ts +14 -0
  32. package/dist/likec4diagram/convert-to-xyflow.js +29 -0
  33. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +3 -3
  34. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +0 -1
  35. package/dist/likec4diagram/custom/edges/SequenceStepEdge.d.ts +3 -0
  36. package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +71 -0
  37. package/dist/likec4diagram/custom/index.js +7 -2
  38. package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +2 -1
  39. package/dist/likec4diagram/custom/nodes/SequenceActorNode.d.ts +4 -0
  40. package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +157 -0
  41. package/dist/likec4diagram/custom/nodes/index.d.ts +1 -0
  42. package/dist/likec4diagram/custom/nodes/nodes.d.ts +1 -2
  43. package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +31 -27
  44. package/dist/likec4diagram/types.d.ts +41 -7
  45. package/dist/likec4diagram/xyflow-diagram/diagram-view.d.ts +11 -0
  46. package/dist/likec4diagram/{useViewToNodesEdges.js → xyflow-diagram/diagram-view.js} +4 -13
  47. package/dist/likec4diagram/xyflow-sequence/_types.d.ts +41 -0
  48. package/dist/likec4diagram/xyflow-sequence/const.d.ts +17 -0
  49. package/dist/likec4diagram/xyflow-sequence/const.js +16 -0
  50. package/dist/likec4diagram/xyflow-sequence/layouter.d.ts +46 -0
  51. package/dist/likec4diagram/xyflow-sequence/layouter.js +408 -0
  52. package/dist/likec4diagram/xyflow-sequence/sequence-view.d.ts +7 -0
  53. package/dist/likec4diagram/xyflow-sequence/sequence-view.js +273 -0
  54. package/dist/likec4diagram/xyflow-sequence/utils.d.ts +14 -0
  55. package/dist/likec4diagram/xyflow-sequence/utils.js +92 -0
  56. package/dist/navigationpanel/NavigationPanelControls.js +2 -2
  57. package/dist/navigationpanel/controls/ViewDetailsCard.js +5 -2
  58. package/dist/navigationpanel/dropdown/ProjectsMenu.js +53 -44
  59. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.d.ts +1 -2
  60. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +10 -41
  61. package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +292 -0
  62. package/dist/navigationpanel/walkthrough/DynamicViewControls.js +119 -0
  63. package/dist/navigationpanel/walkthrough/index.d.ts +2 -1
  64. package/dist/overlays/relationship-details/RelationshipDetails.js +4 -1
  65. package/dist/state/DiagramActorProvider.d.ts +3 -2
  66. package/dist/state/DiagramActorProvider.js +19 -11
  67. package/dist/state/assign.js +11 -4
  68. package/dist/state/diagram-machine.d.ts +224 -194
  69. package/dist/state/diagram-machine.js +170 -63
  70. package/dist/state/utils.d.ts +7 -1
  71. package/dist/state/utils.js +67 -7
  72. package/dist/styles-min.css +1 -1
  73. package/dist/styles.css +1 -1
  74. package/dist/styles.css2.js +1 -1
  75. package/package.json +8 -7
  76. package/panda.buildinfo.json +30 -9
  77. package/src/LikeC4Diagram.props.ts +14 -1
  78. package/src/LikeC4Diagram.tsx +7 -4
  79. package/src/base/const.ts +12 -0
  80. package/src/base/index.ts +2 -0
  81. package/src/base/primitives/edge/EdgeLabel.tsx +23 -19
  82. package/src/base/primitives/edge/EdgeLabelContainer.tsx +12 -7
  83. package/src/base/primitives/edge/EdgePath.tsx +25 -14
  84. package/src/base/primitives/edge/edge.css.ts +5 -14
  85. package/src/base/primitives/element/ElementActionButtons.tsx +1 -3
  86. package/src/base/primitives/element/ElementNodeContainer.tsx +3 -30
  87. package/src/base/primitives/element/ElementTitle.tsx +2 -3
  88. package/src/base/types.ts +7 -5
  89. package/src/bundle/LikeC4View.props.ts +14 -3
  90. package/src/bundle/LikeC4View.tsx +4 -14
  91. package/src/bundle/ReactLikeC4.tsx +1 -2
  92. package/src/custom/customNodes.ts +7 -0
  93. package/src/hooks/useDiagram.ts +10 -0
  94. package/src/likec4diagram/DiagramUI.tsx +1 -1
  95. package/src/likec4diagram/DiagramXYFlow.tsx +10 -5
  96. package/src/likec4diagram/convert-to-xyflow.ts +45 -0
  97. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +0 -1
  98. package/src/likec4diagram/custom/edges/SequenceStepEdge.tsx +65 -0
  99. package/src/likec4diagram/custom/index.ts +7 -1
  100. package/src/likec4diagram/custom/nodes/ElementActions.tsx +4 -2
  101. package/src/likec4diagram/custom/nodes/SequenceActorNode.tsx +175 -0
  102. package/src/likec4diagram/custom/nodes/index.ts +1 -0
  103. package/src/likec4diagram/custom/nodes/nodes.tsx +1 -1
  104. package/src/likec4diagram/relationship-popover/RelationshipPopover.tsx +36 -30
  105. package/src/likec4diagram/types.ts +96 -13
  106. package/src/likec4diagram/{useViewToNodesEdges.ts → xyflow-diagram/diagram-view.ts} +7 -28
  107. package/src/likec4diagram/xyflow-sequence/_types.ts +45 -0
  108. package/src/likec4diagram/xyflow-sequence/const.ts +37 -0
  109. package/src/likec4diagram/xyflow-sequence/layouter.ts +567 -0
  110. package/src/likec4diagram/xyflow-sequence/sequence-view.ts +337 -0
  111. package/src/likec4diagram/xyflow-sequence/utils.ts +112 -0
  112. package/src/navigationpanel/NavigationPanelControls.tsx +2 -2
  113. package/src/navigationpanel/controls/ViewDetailsCard.tsx +5 -2
  114. package/src/navigationpanel/dropdown/ProjectsMenu.tsx +5 -1
  115. package/src/navigationpanel/walkthrough/ActiveWalkthroughControls.tsx +5 -40
  116. package/src/navigationpanel/walkthrough/DynamicViewControls.tsx +125 -0
  117. package/src/navigationpanel/walkthrough/index.tsx +2 -1
  118. package/src/overlays/relationship-details/RelationshipDetails.tsx +5 -2
  119. package/src/state/DiagramActorProvider.tsx +21 -10
  120. package/src/state/assign.ts +18 -5
  121. package/src/state/diagram-machine.ts +207 -75
  122. package/src/state/utils.ts +81 -7
  123. package/dist/likec4diagram/useViewToNodesEdges.d.ts +0 -12
@@ -0,0 +1,119 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { invariant } from '@likec4/core';
3
+ import { css } from '@likec4/styles/css';
4
+ import { Button, SegmentedControl } from '@mantine/core';
5
+ import * as m from 'motion/react-m';
6
+ import { forwardRef } from 'react';
7
+ import { useDiagramContext, useDiagram } from '../../hooks/useDiagram.js';
8
+ import { Tooltip } from '../_common.js';
9
+ import { useNavigationActor } from '../hooks.js';
10
+ import IconPlayerPlayFilled from '../../node_modules/.pnpm/@tabler_icons-react@3.34.1_react@19.1.1/node_modules/@tabler/icons-react/dist/esm/icons/IconPlayerPlayFilled.js';
11
+
12
+ const TriggerWalkthroughButton = forwardRef((props, ref) => /* @__PURE__ */ jsx(
13
+ Button,
14
+ {
15
+ variant: "filled",
16
+ size: "xs",
17
+ fw: "500",
18
+ ...props,
19
+ ref,
20
+ component: m.button,
21
+ layoutId: "trigger-dynamic-walkthrough",
22
+ className: css({
23
+ flexShrink: 0
24
+ })
25
+ }
26
+ ));
27
+ function StartWalkthroughButton({ onClick }) {
28
+ const diagram = useDiagram();
29
+ const actor = useNavigationActor();
30
+ return /* @__PURE__ */ jsx(Tooltip, { label: "Start Dynamic View Walkthrough", children: /* @__PURE__ */ jsx(
31
+ TriggerWalkthroughButton,
32
+ {
33
+ onClick: (e) => {
34
+ e.stopPropagation();
35
+ actor.closeDropdown();
36
+ diagram.startWalkthrough();
37
+ },
38
+ size: "compact-xs",
39
+ h: 26,
40
+ classNames: {
41
+ label: css({
42
+ display: {
43
+ base: "none",
44
+ "@/md": "[inherit]"
45
+ }
46
+ }),
47
+ section: css({
48
+ marginInlineStart: {
49
+ base: "0",
50
+ "@/md": "2"
51
+ }
52
+ })
53
+ },
54
+ rightSection: /* @__PURE__ */ jsx(IconPlayerPlayFilled, { size: 10 }),
55
+ children: "Start"
56
+ }
57
+ ) });
58
+ }
59
+ function DynamicViewModeSwitcher({
60
+ value,
61
+ onChange
62
+ }) {
63
+ return /* @__PURE__ */ jsx(m.div, { layout: "position", children: /* @__PURE__ */ jsx(
64
+ SegmentedControl,
65
+ {
66
+ size: "xs",
67
+ value,
68
+ component: m.div,
69
+ onChange: (variant) => {
70
+ invariant(variant === "diagram" || variant === "sequence", "Invalid dynamic view variant");
71
+ onChange(variant);
72
+ },
73
+ classNames: {
74
+ label: css({
75
+ fontSize: "xxs"
76
+ })
77
+ },
78
+ data: [
79
+ {
80
+ value: "diagram",
81
+ label: "Diagram"
82
+ },
83
+ {
84
+ value: "sequence",
85
+ label: "Sequence"
86
+ }
87
+ ]
88
+ }
89
+ ) });
90
+ }
91
+ function DynamicViewControls() {
92
+ const dynamicViewVariant = useDiagramContext((c) => c.dynamicViewVariant);
93
+ const diagram = useDiagram();
94
+ const actor = useNavigationActor();
95
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
96
+ /* @__PURE__ */ jsx(
97
+ DynamicViewModeSwitcher,
98
+ {
99
+ value: dynamicViewVariant,
100
+ onChange: (mode) => {
101
+ diagram.switchDynamicViewVariant(mode);
102
+ }
103
+ },
104
+ "dynamic-view-mode-switcher"
105
+ ),
106
+ /* @__PURE__ */ jsx(
107
+ StartWalkthroughButton,
108
+ {
109
+ onClick: () => {
110
+ actor.closeDropdown();
111
+ diagram.startWalkthrough();
112
+ }
113
+ },
114
+ "trigger-dynamic-walkthrough"
115
+ )
116
+ ] });
117
+ }
118
+
119
+ export { DynamicViewControls, TriggerWalkthroughButton };
@@ -1 +1,2 @@
1
- export { ActiveWalkthroughControls, StartWalkthroughButton } from './ActiveWalkthroughControls';
1
+ export { ActiveWalkthroughControls } from './ActiveWalkthroughControls';
2
+ export { DynamicViewControls } from './DynamicViewControls';
@@ -104,7 +104,10 @@ const RelationshipDetailsInner = memo(() => {
104
104
  id: browser.rootElementId,
105
105
  nodes,
106
106
  edges,
107
- className: cx(initialized ? "initialized" : "not-initialized"),
107
+ className: cx(
108
+ initialized ? "initialized" : "not-initialized",
109
+ "likec4-relationship-details"
110
+ ),
108
111
  nodeTypes,
109
112
  edgeTypes,
110
113
  onNodesChange: useCallbackRef((changes) => {
@@ -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;
@@ -3,13 +3,13 @@ import { useCustomCompareEffect } 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, useEffect } 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
11
  import { useCurrentViewId } from '../hooks/useCurrentViewId.js';
12
- import { useViewToNodesEdges } from '../likec4diagram/useViewToNodesEdges.js';
12
+ import { convertToXYFlow } from '../likec4diagram/convert-to-xyflow.js';
13
13
  import { CurrentViewModelContext } from '../likec4model/LikeC4ModelContext.js';
14
14
  import { useLikeC4Model } from '../likec4model/useLikeC4Model.js';
15
15
  import { diagramMachine } from './diagram-machine.js';
@@ -25,6 +25,9 @@ const selectToggledFeatures = (state) => {
25
25
  }
26
26
  return state.context.toggledFeatures;
27
27
  };
28
+ const selectDynamicViewVariant = (state) => {
29
+ return state.context.dynamicViewVariant;
30
+ };
28
31
  function DiagramActorProvider({
29
32
  view,
30
33
  zoomable,
@@ -32,7 +35,8 @@ function DiagramActorProvider({
32
35
  fitViewPadding,
33
36
  nodesSelectable,
34
37
  where,
35
- children
38
+ children,
39
+ dynamicViewVariant: _defaultVariant
36
40
  }) {
37
41
  const { handlersRef } = useDiagramEventHandlers();
38
42
  const xystore = useStoreApi();
@@ -62,7 +66,8 @@ function DiagramActorProvider({
62
66
  zoomable,
63
67
  pannable,
64
68
  fitViewPadding,
65
- nodesSelectable
69
+ nodesSelectable,
70
+ dynamicViewVariant: _defaultVariant
66
71
  }
67
72
  }
68
73
  );
@@ -81,14 +86,17 @@ function DiagramActorProvider({
81
86
  [zoomable, pannable, fitViewPadding, nodesSelectable],
82
87
  deepEqual
83
88
  );
84
- const { xyedges, xynodes } = useViewToNodesEdges({
85
- view,
86
- where,
87
- nodesSelectable
88
- });
89
+ const dynamicViewVariant = useSelector(actorRef, selectDynamicViewVariant);
90
+ const update = useMemo(
91
+ () => convertToXYFlow({ view, where, nodesSelectable, dynamicViewVariant }),
92
+ [view, where, nodesSelectable, dynamicViewVariant]
93
+ );
89
94
  useEffect(() => {
90
- actorRef.send({ type: "update.view", view, xyedges, xynodes });
91
- }, [view, xyedges, xynodes]);
95
+ actorRef.send({
96
+ type: "update.view",
97
+ ...update
98
+ });
99
+ }, [actorRef, update]);
92
100
  const toggledFeatures = useSelector(actorRef, selectToggledFeatures, shallowEqual);
93
101
  return /* @__PURE__ */ jsxs(DiagramActorContextProvider, { value: actorRef, children: [
94
102
  /* @__PURE__ */ jsx(DiagramFeatures, { overrides: toggledFeatures, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(CurrentViewModelProvider, { children }) }) }),
@@ -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
  };