@likec4/diagram 1.20.1 → 1.20.2

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 (129) hide show
  1. package/dist/LikeC4Diagram.css.d.ts +1 -0
  2. package/dist/LikeC4Diagram.css.js +3 -1
  3. package/dist/base/BaseXYFlow.js +15 -14
  4. package/dist/base/Link.css.d.ts +3 -0
  5. package/dist/base/Link.css.js +9 -0
  6. package/dist/base/Link.d.ts +5 -0
  7. package/dist/base/Link.js +58 -0
  8. package/dist/base/const.d.ts +1 -0
  9. package/dist/base/const.js +2 -1
  10. package/dist/base/example/custom.d.ts +1 -1
  11. package/dist/base/index.d.ts +1 -0
  12. package/dist/base/primitives/compound/CompoundActionButton.js +2 -1
  13. package/dist/base/primitives/compound/CompoundDetailsButton.js +2 -1
  14. package/dist/base/primitives/compound/CompoundNodeContainer.css.d.ts +0 -1
  15. package/dist/base/primitives/compound/CompoundNodeContainer.css.js +4 -6
  16. package/dist/base/primitives/compound/CompoundNodeContainer.js +2 -2
  17. package/dist/base/primitives/customEdge.d.ts +1 -1
  18. package/dist/base/primitives/customEdge.js +1 -1
  19. package/dist/base/primitives/customNode.js +1 -1
  20. package/dist/base/primitives/edge/EdgeLabel.js +3 -1
  21. package/dist/base/primitives/edge/EdgePath.d.ts +2 -1
  22. package/dist/base/primitives/edge/EdgePath.js +2 -0
  23. package/dist/base/primitives/element/ElementActionButtons.js +2 -1
  24. package/dist/base/primitives/element/ElementDetailsButton.js +2 -1
  25. package/dist/base/primitives/element/ElementNodeContainer.css.d.ts +0 -1
  26. package/dist/base/primitives/element/ElementNodeContainer.css.js +1 -3
  27. package/dist/base/primitives/element/ElementNodeContainer.js +2 -3
  28. package/dist/base/primitives/element/ElementShape.js +4 -2
  29. package/dist/base/primitives/element/ElementTitle.js +2 -1
  30. package/dist/base/updateEdges.js +3 -3
  31. package/dist/base/updateNodes.js +2 -2
  32. package/dist/context/FramerMotionConfig.js +1 -1
  33. package/dist/hooks/useDiagram.d.ts +313 -90
  34. package/dist/hooks/useDiagramActor.d.ts +2 -2
  35. package/dist/hooks/useDiagramContext.d.ts +1 -1
  36. package/dist/hooks/useXYFlow.d.ts +2 -1
  37. package/dist/hooks/useXYFlow.js +5 -0
  38. package/dist/likec4diagram/XYFlow.js +12 -10
  39. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +1 -1
  40. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +2 -2
  41. package/dist/likec4diagram/custom/index.d.ts +1 -1
  42. package/dist/likec4diagram/custom/nodes/nodeTypes.js +2 -2
  43. package/dist/likec4diagram/state/actorContext.d.ts +1438 -364
  44. package/dist/likec4diagram/state/assign.js +2 -2
  45. package/dist/likec4diagram/state/machine.d.ts +321 -93
  46. package/dist/likec4diagram/state/syncManualLayoutActor.d.ts +1 -1
  47. package/dist/likec4diagram/types.d.ts +1 -0
  48. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +4 -3
  49. package/dist/likec4diagram/useViewToNodesEdges.js +3 -1
  50. package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +0 -1
  51. package/dist/overlays/element-details/ElementDetailsCard.css.js +1 -3
  52. package/dist/overlays/element-details/ElementDetailsCard.js +5 -30
  53. package/dist/overlays/relationship-details/RelationshipDetails.js +4 -4
  54. package/dist/overlays/relationship-details/custom/ElementActions.js +1 -3
  55. package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +1 -1
  56. package/dist/overlays/relationship-details/hooks.d.ts +2 -2
  57. package/dist/overlays/relationship-details/hooks.js +7 -7
  58. package/dist/overlays/relationship-details/useLayoutedDetails.js +7 -10
  59. package/dist/overlays/relationships-browser/-useRelationshipsView.d.ts +4 -1
  60. package/dist/overlays/relationships-browser/-useRelationshipsView.js +12 -11
  61. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +81 -66
  62. package/dist/overlays/relationships-browser/_types.d.ts +2 -1
  63. package/dist/overlays/relationships-browser/actor.d.ts +15 -2
  64. package/dist/overlays/relationships-browser/actor.js +262 -65
  65. package/dist/overlays/relationships-browser/const.d.ts +1 -0
  66. package/dist/overlays/relationships-browser/const.js +4 -0
  67. package/dist/overlays/relationships-browser/custom/ElementActions.js +1 -1
  68. package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +3 -2
  69. package/dist/overlays/relationships-browser/custom/edgeTypes.js +24 -6
  70. package/dist/overlays/relationships-browser/custom/nodeTypes.js +3 -2
  71. package/dist/overlays/relationships-browser/hooks.d.ts +6 -3
  72. package/dist/overlays/relationships-browser/hooks.js +4 -2
  73. package/dist/overlays/relationships-browser/useViewToNodesEdges.js +7 -2
  74. package/dist/style.css +1 -1
  75. package/dist/utils/xyflow.js +9 -1
  76. package/package.json +8 -8
  77. package/src/LikeC4Diagram.css.ts +8 -0
  78. package/src/base/BaseXYFlow.tsx +23 -14
  79. package/src/base/Link.css.ts +49 -0
  80. package/src/base/Link.tsx +66 -0
  81. package/src/base/const.ts +1 -0
  82. package/src/base/index.ts +2 -0
  83. package/src/base/primitives/compound/CompoundActionButton.tsx +2 -1
  84. package/src/base/primitives/compound/CompoundDetailsButton.tsx +2 -1
  85. package/src/base/primitives/compound/CompoundNodeContainer.css.ts +16 -10
  86. package/src/base/primitives/compound/CompoundNodeContainer.tsx +1 -1
  87. package/src/base/primitives/customEdge.ts +2 -0
  88. package/src/base/primitives/customNode.ts +3 -0
  89. package/src/base/primitives/edge/EdgeLabel.tsx +3 -1
  90. package/src/base/primitives/edge/EdgePath.tsx +3 -0
  91. package/src/base/primitives/element/ElementActionButtons.tsx +2 -1
  92. package/src/base/primitives/element/ElementDetailsButton.tsx +2 -1
  93. package/src/base/primitives/element/ElementNodeContainer.css.ts +9 -4
  94. package/src/base/primitives/element/ElementNodeContainer.tsx +1 -2
  95. package/src/base/primitives/element/ElementShape.tsx +4 -3
  96. package/src/base/primitives/element/ElementTitle.tsx +2 -1
  97. package/src/base/updateEdges.ts +3 -2
  98. package/src/base/updateNodes.ts +3 -2
  99. package/src/context/DiagramFeatures.tsx +1 -0
  100. package/src/context/FramerMotionConfig.tsx +1 -1
  101. package/src/hooks/useDiagramActor.ts +7 -5
  102. package/src/hooks/useDiagramContext.ts +4 -1
  103. package/src/hooks/useXYFlow.ts +6 -1
  104. package/src/likec4diagram/XYFlow.tsx +20 -9
  105. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +2 -2
  106. package/src/likec4diagram/custom/nodes/nodeTypes.tsx +2 -2
  107. package/src/likec4diagram/types.ts +1 -0
  108. package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +4 -3
  109. package/src/likec4diagram/useViewToNodesEdges.ts +1 -0
  110. package/src/overlays/element-details/ElementDetailsCard.css.ts +0 -28
  111. package/src/overlays/element-details/ElementDetailsCard.tsx +2 -50
  112. package/src/overlays/relationship-details/RelationshipDetails.tsx +4 -4
  113. package/src/overlays/relationship-details/custom/ElementActions.tsx +1 -2
  114. package/src/overlays/relationship-details/custom/edgeTypes.tsx +0 -5
  115. package/src/overlays/relationship-details/hooks.ts +6 -6
  116. package/src/overlays/relationship-details/useLayoutedDetails.ts +7 -10
  117. package/src/overlays/relationships-browser/-useRelationshipsView.ts +16 -12
  118. package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +105 -68
  119. package/src/overlays/relationships-browser/_types.ts +2 -1
  120. package/src/overlays/relationships-browser/actor.ts +321 -62
  121. package/src/overlays/relationships-browser/const.ts +1 -0
  122. package/src/overlays/relationships-browser/custom/ElementActions.tsx +1 -1
  123. package/src/overlays/relationships-browser/custom/edgeTypes.tsx +25 -6
  124. package/src/overlays/relationships-browser/custom/nodeTypes.tsx +3 -2
  125. package/src/overlays/relationships-browser/hooks.ts +3 -1
  126. package/src/overlays/relationships-browser/useViewToNodesEdges.ts +8 -2
  127. package/dist/likec4diagram/ui/diagram-title/Link.js +0 -36
  128. package/dist/ui/Link.d.ts +0 -4
  129. package/src/ui/Link.tsx +0 -40
@@ -1,5 +1,5 @@
1
1
  import { LikeC4ViewActorRef, MachineSnapshot } from '../likec4diagram/state/machine';
2
2
  import { SyncLayoutActorSnapshot } from '../likec4diagram/state/syncManualLayoutActor';
3
3
  export declare function useDiagramActor(): LikeC4ViewActorRef;
4
- export declare function useDiagramActorState<T>(selector: (state: MachineSnapshot) => T, compare?: <A, B>(a: A, b: B) => boolean): T;
5
- export declare function useDiagramSyncLayoutState<T>(selector: (state: SyncLayoutActorSnapshot) => T, compare?: <A, B>(a: A, b: B) => boolean): T;
4
+ export declare function useDiagramActorState<T = unknown>(selector: (state: MachineSnapshot) => T, compare?: (a: NoInfer<T>, b: NoInfer<T>) => boolean): T;
5
+ export declare function useDiagramSyncLayoutState<T = unknown>(selector: (state: SyncLayoutActorSnapshot) => T, compare?: (a: NoInfer<T>, b: NoInfer<T>) => boolean): T;
@@ -1,3 +1,3 @@
1
1
  import { DiagramContext } from '../likec4diagram/state/machine';
2
- export declare function useDiagramContext<T>(selector: (state: DiagramContext) => T, compare?: <A, B>(a: A, b: B) => boolean): T;
2
+ export declare function useDiagramContext<T = unknown>(selector: (state: DiagramContext) => T, compare?: (a: NoInfer<T>, b: NoInfer<T>) => boolean): T;
3
3
  export { DiagramContext } from '../likec4diagram/state/machine';
@@ -50,7 +50,7 @@ export declare const useXYFlow: () => ReactFlowInstance<Types.Node, {
50
50
  dimmed?: import("../base").Base.Dimmed;
51
51
  };
52
52
  }>;
53
- export declare function useXYStore<StateSlice = unknown>(selector: (state: ReactFlowState<Types.Node, Types.Edge>) => StateSlice, equalityFn?: (a: StateSlice, b: StateSlice) => boolean): StateSlice;
53
+ export declare function useXYStore<StateSlice = unknown>(selector: (state: ReactFlowState<Types.Node, Types.Edge>) => StateSlice, equalityFn?: (a: NoInfer<StateSlice>, b: NoInfer<StateSlice>) => boolean): StateSlice;
54
54
  export declare const useXYStoreApi: () => {
55
55
  getState: () => ReactFlowState<Types.Node, {
56
56
  id: string;
@@ -426,3 +426,4 @@ export declare const useXYStoreApi: () => {
426
426
  };
427
427
  export type XYStoreApi = ReturnType<typeof useXYStoreApi>;
428
428
  export declare const useXYInternalNode: (id: string) => InternalNode<Types.Node> | undefined;
429
+ export declare function useIsZoomTooSmall(): boolean;
@@ -10,7 +10,12 @@ function useXYStore(selector, equalityFn) {
10
10
  }
11
11
  const useXYStoreApi = useStoreApi;
12
12
  const useXYInternalNode = useInternalNode;
13
+ const selectZoom = (state) => state.transform[2] < 0.2;
14
+ function useIsZoomTooSmall() {
15
+ return useStore(selectZoom);
16
+ }
13
17
  export {
18
+ useIsZoomTooSmall,
14
19
  useXYFlow,
15
20
  useXYInternalNode,
16
21
  useXYStore,
@@ -2,12 +2,12 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { nonNullable } from "@likec4/core";
3
3
  import { useCallbackRef } from "@mantine/hooks";
4
4
  import clsx from "clsx";
5
+ import { shallowEqual } from "fast-equals";
5
6
  import { useDiagram } from "../hooks/useDiagram.js";
6
7
  import { useDiagramContext } from "../hooks/useDiagramContext.js";
7
8
  import { edgeTypes } from "./custom/index.js";
8
9
  import { useLayoutConstraints } from "./useLayoutConstraints.js";
9
10
  import { useDiagramEventHandlers } from "../context/DiagramEventHandlers.js";
10
- import { useEnabledFeature } from "../context/DiagramFeatures.js";
11
11
  import { BaseXYFlow } from "../base/BaseXYFlow.js";
12
12
  import { nodeTypes } from "./custom/nodes/nodeTypes.js";
13
13
  const selectXYProps = (ctx) => ({
@@ -16,16 +16,21 @@ const selectXYProps = (ctx) => ({
16
16
  edges: ctx.xyedges,
17
17
  pannable: ctx.pannable,
18
18
  zoomable: ctx.zoomable,
19
- fitViewPadding: ctx.fitViewPadding
19
+ fitViewPadding: ctx.fitViewPadding,
20
+ enableFitView: ctx.features.enableFitView,
21
+ enableReadOnly: ctx.features.enableReadOnly
20
22
  });
23
+ 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);
21
24
  const LikeC4DiagramXYFlow = ({ background, ...rest }) => {
22
25
  const diagram = useDiagram();
23
26
  const {
24
27
  initialized,
25
28
  nodes,
26
29
  edges,
30
+ enableReadOnly,
31
+ enableFitView,
27
32
  ...props
28
- } = useDiagramContext(selectXYProps);
33
+ } = useDiagramContext(selectXYProps, equalsXYProps);
29
34
  const {
30
35
  onNodeContextMenu,
31
36
  onCanvasContextMenu,
@@ -35,12 +40,11 @@ const LikeC4DiagramXYFlow = ({ background, ...rest }) => {
35
40
  onCanvasClick,
36
41
  onCanvasDblClick
37
42
  } = useDiagramEventHandlers();
38
- const {
39
- enableFitView,
40
- enableReadOnly
41
- } = useEnabledFeature("ReadOnly", "FitView");
42
43
  const notReadOnly = !enableReadOnly;
43
44
  const layoutConstraints = useLayoutConstraints();
45
+ const onViewportResize = useCallbackRef(() => {
46
+ diagram.send({ type: "xyflow.resized" });
47
+ });
44
48
  return /* @__PURE__ */ jsx(
45
49
  BaseXYFlow,
46
50
  {
@@ -107,9 +111,7 @@ const LikeC4DiagramXYFlow = ({ background, ...rest }) => {
107
111
  })
108
112
  },
109
113
  ...enableFitView && {
110
- onViewportResize: () => {
111
- diagram.send({ type: "xyflow.resized" });
112
- }
114
+ onViewportResize
113
115
  },
114
116
  ...notReadOnly && rest.nodesDraggable && layoutConstraints,
115
117
  ...props,
@@ -7,9 +7,9 @@ export declare const RelationshipEdge: NamedExoticComponent<{
7
7
  target: string;
8
8
  style?: CSSProperties;
9
9
  id: string;
10
- selected?: boolean;
11
10
  selectable?: boolean;
12
11
  deletable?: boolean;
12
+ selected?: boolean;
13
13
  animated?: boolean;
14
14
  sourceX: number;
15
15
  sourceY: number;
@@ -7,13 +7,13 @@ import { useCallback, forwardRef, Fragment as Fragment$1 } from "react";
7
7
  import { pipe, map, filter, isTruthy, partition } from "remeda";
8
8
  import { useDiagram } from "../../../hooks/useDiagram.js";
9
9
  import { useDiagramContext } from "../../../hooks/useDiagramContext.js";
10
- import { Link } from "../../ui/diagram-title/Link.js";
11
10
  import { menuDropdown, menuItemRelationship, endpoint, title } from "./RelationshipsDropdownMenu.css.js";
12
11
  import { DiagramContext } from "../../state/machine.js";
13
12
  import { useLikeC4Model } from "../../../likec4model/useLikeC4Model.js";
14
13
  import { useMantinePortalProps } from "../../../hooks/useMantinePortalProps.js";
15
14
  import { useEnabledFeature, IfEnabled } from "../../../context/DiagramFeatures.js";
16
15
  import { useDiagramEventHandlers } from "../../../context/DiagramEventHandlers.js";
16
+ import { Link } from "../../../base/Link.js";
17
17
  const stopPropagation = (e) => e.stopPropagation();
18
18
  const Tooltip = Tooltip$1.withProps({
19
19
  color: "gray",
@@ -194,7 +194,7 @@ const Relationship = forwardRef(({
194
194
  gap: 3,
195
195
  justify: "stretch",
196
196
  align: "stretch",
197
- children: links.map((link) => /* @__PURE__ */ jsx(Link, { link }, link.url))
197
+ children: links.map((link) => /* @__PURE__ */ jsx(Link, { size: "sm", value: link }, link.url))
198
198
  }
199
199
  )
200
200
  ] });
@@ -8,9 +8,9 @@ export declare const edgeTypes: {
8
8
  target: string;
9
9
  style?: CSSProperties;
10
10
  id: string;
11
- selected?: boolean;
12
11
  selectable?: boolean;
13
12
  deletable?: boolean;
13
+ selected?: boolean;
14
14
  animated?: boolean;
15
15
  sourceX: number;
16
16
  sourceY: number;
@@ -32,7 +32,7 @@ const ElementDetailsButtonWithHandler = ({ fqn, ...props }) => {
32
32
  };
33
33
  const nodeTypes = {
34
34
  element: customNode((props) => /* @__PURE__ */ jsxs(ElementNodeContainer, { nodeProps: props, children: [
35
- /* @__PURE__ */ jsx(ElementShape, { ...props }),
35
+ /* @__PURE__ */ jsx(ElementShape, { ...props, isMultiple: props.data.isMultiple }),
36
36
  /* @__PURE__ */ jsx(ElementTitle, { ...props }),
37
37
  /* @__PURE__ */ jsx(ElementActions, { ...props }),
38
38
  /* @__PURE__ */ jsx(
@@ -46,7 +46,7 @@ const nodeTypes = {
46
46
  /* @__PURE__ */ jsx(DefaultHandles, {})
47
47
  ] })),
48
48
  deployment: customNode((props) => /* @__PURE__ */ jsxs(ElementNodeContainer, { nodeProps: props, children: [
49
- /* @__PURE__ */ jsx(ElementShape, { ...props }),
49
+ /* @__PURE__ */ jsx(ElementShape, { ...props, isMultiple: props.data.isMultiple }),
50
50
  /* @__PURE__ */ jsx(ElementTitle, { ...props }),
51
51
  /* @__PURE__ */ jsx(DeploymentElementActions, { ...props }),
52
52
  !!props.data.modelFqn && /* @__PURE__ */ jsx(