@likec4/diagram 1.18.0 → 1.19.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.
Files changed (277) hide show
  1. package/LICENSE +1 -1
  2. package/dist/LikeC4CustomColors.d.ts +7 -0
  3. package/dist/LikeC4CustomColors.js +30 -0
  4. package/dist/LikeC4Diagram.css.d.ts +5 -0
  5. package/dist/LikeC4Diagram.css.js +13 -0
  6. package/dist/LikeC4Diagram.d.ts +6 -0
  7. package/dist/LikeC4Diagram.js +194 -0
  8. package/dist/LikeC4Diagram.props.d.ts +166 -0
  9. package/dist/LikeC4ModelProvider.d.ts +9 -0
  10. package/dist/LikeC4ModelProvider.js +12 -0
  11. package/dist/LikeC4Search.css.d.ts +1 -0
  12. package/dist/LikeC4Search.css.js +5 -0
  13. package/dist/LikeC4Search.d.ts +2 -0
  14. package/dist/LikeC4Search.js +96 -0
  15. package/dist/StaticLikeC4Diagram.d.ts +3 -0
  16. package/dist/StaticLikeC4Diagram.js +41 -0
  17. package/dist/_virtual/_commonjsHelpers.js +6 -0
  18. package/dist/controls/Text.d.ts +2 -0
  19. package/dist/controls/Text.js +7 -0
  20. package/dist/controls/action-button-bar/ActionButtonBar.css.d.ts +1 -0
  21. package/dist/controls/action-button-bar/ActionButtonBar.css.js +5 -0
  22. package/dist/controls/action-button-bar/ActionButtonBar.d.ts +9 -0
  23. package/dist/controls/action-button-bar/ActionButtonBar.js +100 -0
  24. package/dist/controls/action-button-bar/useActionButtonBarCtx.d.ts +10 -0
  25. package/dist/controls/action-button-bar/useActionButtonBarCtx.js +9 -0
  26. package/dist/controls/action-buttons/ActionButton.css.d.ts +1 -0
  27. package/dist/controls/action-buttons/ActionButton.css.js +5 -0
  28. package/dist/controls/action-buttons/ActionButton.d.ts +9 -0
  29. package/dist/controls/action-buttons/ActionButton.js +66 -0
  30. package/dist/controls/action-buttons/ActionButtons.d.ts +12 -0
  31. package/dist/controls/action-buttons/ActionButtons.js +99 -0
  32. package/dist/globals.css.d.ts +1 -0
  33. package/dist/globals.css.js +92 -0
  34. package/dist/hooks/index.d.ts +5 -0
  35. package/dist/hooks/useDiagramState.d.ts +6 -0
  36. package/dist/hooks/useDiagramState.js +27 -0
  37. package/dist/hooks/useMantinePortalProps.d.ts +9 -0
  38. package/dist/hooks/useMantinePortalProps.js +9 -0
  39. package/dist/hooks/useSetState.d.ts +2 -0
  40. package/dist/hooks/useSetState.js +19 -0
  41. package/dist/hooks/useUpdateEffect.d.ts +4 -0
  42. package/dist/hooks/useUpdateEffect.js +32 -0
  43. package/dist/hooks/useXYFlow.d.ts +270 -0
  44. package/dist/hooks/useXYFlow.js +20 -0
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.js +25 -0
  47. package/dist/likec4model/LikeC4ModelContext.d.ts +3 -0
  48. package/dist/likec4model/LikeC4ModelContext.js +5 -0
  49. package/dist/likec4model/index.d.ts +2 -0
  50. package/dist/likec4model/useLikeC4ElementsTree.d.ts +12 -0
  51. package/dist/likec4model/useLikeC4ElementsTree.js +25 -0
  52. package/dist/likec4model/useLikeC4Model.d.ts +20 -0
  53. package/dist/likec4model/useLikeC4Model.js +55 -0
  54. package/dist/overlays/OverlayContext.d.ts +10 -0
  55. package/dist/overlays/OverlayContext.js +9 -0
  56. package/dist/overlays/Overlays.css.d.ts +3 -0
  57. package/dist/overlays/Overlays.css.js +7 -0
  58. package/dist/overlays/Overlays.d.ts +2 -0
  59. package/dist/overlays/Overlays.js +137 -0
  60. package/dist/overlays/edge-details/EdgeDetailsXYFlow.d.ts +5 -0
  61. package/dist/overlays/edge-details/EdgeDetailsXYFlow.js +185 -0
  62. package/dist/overlays/edge-details/SelectEdge.css.d.ts +7 -0
  63. package/dist/overlays/edge-details/SelectEdge.css.js +17 -0
  64. package/dist/overlays/edge-details/SelectEdge.d.ts +5 -0
  65. package/dist/overlays/edge-details/SelectEdge.js +129 -0
  66. package/dist/overlays/edge-details/_types.d.ts +14 -0
  67. package/dist/overlays/edge-details/use-layouted-edge-details.d.ts +21 -0
  68. package/dist/overlays/edge-details/use-layouted-edge-details.js +270 -0
  69. package/dist/overlays/edge-details/xyflow/CompoundNode.d.ts +5 -0
  70. package/dist/overlays/edge-details/xyflow/CompoundNode.js +76 -0
  71. package/dist/overlays/edge-details/xyflow/ElementNode.d.ts +5 -0
  72. package/dist/overlays/edge-details/xyflow/ElementNode.js +159 -0
  73. package/dist/overlays/edge-details/xyflow/RelationshipEdge.d.ts +3 -0
  74. package/dist/overlays/edge-details/xyflow/RelationshipEdge.js +84 -0
  75. package/dist/overlays/edge-details/xyflow/styles.css.d.ts +9 -0
  76. package/dist/overlays/edge-details/xyflow/styles.css.js +21 -0
  77. package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +16 -0
  78. package/dist/overlays/element-details/ElementDetailsCard.css.js +33 -0
  79. package/dist/overlays/element-details/ElementDetailsCard.d.ts +7 -0
  80. package/dist/overlays/element-details/ElementDetailsCard.js +484 -0
  81. package/dist/overlays/element-details/TabPanelDeployments.css.d.ts +4 -0
  82. package/dist/overlays/element-details/TabPanelDeployments.css.js +11 -0
  83. package/dist/overlays/element-details/TabPanelDeployments.d.ts +7 -0
  84. package/dist/overlays/element-details/TabPanelDeployments.js +173 -0
  85. package/dist/overlays/element-details/TabPanelRelationships.css.d.ts +5 -0
  86. package/dist/overlays/element-details/TabPanelRelationships.css.js +11 -0
  87. package/dist/overlays/element-details/TabPanelRelationships.d.ts +8 -0
  88. package/dist/overlays/element-details/TabPanelRelationships.js +157 -0
  89. package/dist/overlays/element-details/TabPanelStructure.css.d.ts +2 -0
  90. package/dist/overlays/element-details/TabPanelStructure.css.js +7 -0
  91. package/dist/overlays/element-details/TabPanelStructure.d.ts +25 -0
  92. package/dist/overlays/element-details/TabPanelStructure.js +91 -0
  93. package/dist/overlays/index.d.ts +1 -0
  94. package/dist/overlays/relationships-of/RelationshipsOverlay.d.ts +5 -0
  95. package/dist/overlays/relationships-of/RelationshipsOverlay.js +193 -0
  96. package/dist/overlays/relationships-of/RelationshipsXYFlow.d.ts +19 -0
  97. package/dist/overlays/relationships-of/RelationshipsXYFlow.js +290 -0
  98. package/dist/overlays/relationships-of/SelectElement.css.d.ts +2 -0
  99. package/dist/overlays/relationships-of/SelectElement.css.js +7 -0
  100. package/dist/overlays/relationships-of/SelectElement.d.ts +7 -0
  101. package/dist/overlays/relationships-of/SelectElement.js +126 -0
  102. package/dist/overlays/relationships-of/_types.d.ts +28 -0
  103. package/dist/overlays/relationships-of/use-layouted-relationships.d.ts +22 -0
  104. package/dist/overlays/relationships-of/use-layouted-relationships.js +496 -0
  105. package/dist/overlays/relationships-of/xyflow/CompoundNode.d.ts +6 -0
  106. package/dist/overlays/relationships-of/xyflow/CompoundNode.js +120 -0
  107. package/dist/overlays/relationships-of/xyflow/ElementNode.d.ts +6 -0
  108. package/dist/overlays/relationships-of/xyflow/ElementNode.js +194 -0
  109. package/dist/overlays/relationships-of/xyflow/EmptyNode.d.ts +5 -0
  110. package/dist/overlays/relationships-of/xyflow/EmptyNode.js +18 -0
  111. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.d.ts +3 -0
  112. package/dist/overlays/relationships-of/xyflow/RelationshipEdge.js +123 -0
  113. package/dist/overlays/relationships-of/xyflow/styles.css.d.ts +14 -0
  114. package/dist/overlays/relationships-of/xyflow/styles.css.js +24 -0
  115. package/dist/overlays/shared/xyflow/RelationshipEdge.css.d.ts +4 -0
  116. package/dist/overlays/shared/xyflow/RelationshipEdge.css.js +12 -0
  117. package/dist/overlays/shared/xyflow/_types.d.ts +77 -0
  118. package/dist/state/DiagramContext.d.ts +1609 -0
  119. package/dist/state/DiagramContext.js +101 -0
  120. package/dist/state/aligners.d.ts +42 -0
  121. package/dist/state/aligners.js +349 -0
  122. package/dist/state/diagram-to-xyflow.d.ts +11 -0
  123. package/dist/state/diagram-to-xyflow.js +113 -0
  124. package/dist/state/diagramStore.d.ts +1705 -0
  125. package/dist/state/diagramStore.js +808 -0
  126. package/dist/state/diagramStore.layout.d.ts +4 -0
  127. package/dist/state/diagramStore.layout.js +56 -0
  128. package/dist/style.css +1 -0
  129. package/dist/theme-vars.css.d.ts +72 -0
  130. package/dist/theme-vars.css.js +6 -0
  131. package/dist/theme-vars.css.ts.vanilla.css.js +1 -0
  132. package/dist/theme-vars.d.ts +3 -0
  133. package/dist/theme-vars.js +5 -0
  134. package/dist/ui/DiagramTitlePanel.css.d.ts +4 -0
  135. package/dist/ui/DiagramTitlePanel.css.js +11 -0
  136. package/dist/ui/DiagramTitlePanel.d.ts +1 -0
  137. package/dist/ui/DiagramTitlePanel.js +159 -0
  138. package/dist/ui/DynamicViewWalkthrough.css.d.ts +4 -0
  139. package/dist/ui/DynamicViewWalkthrough.css.js +11 -0
  140. package/dist/ui/DynamicViewWalkthrough.d.ts +1 -0
  141. package/dist/ui/DynamicViewWalkthrough.js +156 -0
  142. package/dist/ui/EnsureMantine.d.ts +7 -0
  143. package/dist/ui/EnsureMantine.js +14 -0
  144. package/dist/ui/FramerMotionConfig.d.ts +2 -0
  145. package/dist/ui/FramerMotionConfig.js +14 -0
  146. package/dist/ui/Link.d.ts +4 -0
  147. package/dist/ui/Link.js +36 -0
  148. package/dist/ui/notation/NotationPanel.css.d.ts +6 -0
  149. package/dist/ui/notation/NotationPanel.css.js +16 -0
  150. package/dist/ui/notation/NotationPanel.d.ts +1 -0
  151. package/dist/ui/notation/NotationPanel.js +250 -0
  152. package/dist/ui/notation/index.d.ts +1 -0
  153. package/dist/ui/top-left/ChangeAutoLayoutButton.d.ts +2 -0
  154. package/dist/ui/top-left/ChangeAutoLayoutButton.js +159 -0
  155. package/dist/ui/top-left/ManualLayoutToolsButton.d.ts +2 -0
  156. package/dist/ui/top-left/ManualLayoutToolsButton.js +137 -0
  157. package/dist/ui/top-left/TopLeftPanel.d.ts +4 -0
  158. package/dist/ui/top-left/TopLeftPanel.js +211 -0
  159. package/dist/ui/top-left/_shared.d.ts +7 -0
  160. package/dist/ui/top-left/_shared.js +22 -0
  161. package/dist/ui/top-left/styles.css.d.ts +8 -0
  162. package/dist/ui/top-left/styles.css.js +17 -0
  163. package/dist/utils/types.d.ts +8 -0
  164. package/dist/utils/vector.d.ts +24 -0
  165. package/dist/utils/vector.js +55 -0
  166. package/dist/xyflow/EdgeMarkers.d.ts +12 -0
  167. package/dist/xyflow/EdgeMarkers.js +192 -0
  168. package/dist/xyflow/FitviewOnDiagramChange.d.ts +4 -0
  169. package/dist/xyflow/FitviewOnDiagramChange.js +72 -0
  170. package/dist/xyflow/SelectEdgesOnNodeFocus.d.ts +1 -0
  171. package/dist/xyflow/SelectEdgesOnNodeFocus.js +96 -0
  172. package/dist/xyflow/XYFlow.d.ts +8 -0
  173. package/dist/xyflow/XYFlow.js +145 -0
  174. package/dist/xyflow/XYFlowBackground.d.ts +10 -0
  175. package/dist/xyflow/XYFlowBackground.js +25 -0
  176. package/dist/xyflow/XYFlowInner.d.ts +8 -0
  177. package/dist/xyflow/XYFlowInner.js +41 -0
  178. package/dist/xyflow/const.d.ts +7 -0
  179. package/dist/xyflow/const.js +12 -0
  180. package/dist/xyflow/edges/EdgeLabel.d.ts +7 -0
  181. package/dist/xyflow/edges/EdgeLabel.js +160 -0
  182. package/dist/xyflow/edges/RelationshipEdge.d.ts +6 -0
  183. package/dist/xyflow/edges/RelationshipEdge.js +443 -0
  184. package/dist/xyflow/edges/RelationshipsDropdownMenu.css.d.ts +4 -0
  185. package/dist/xyflow/edges/RelationshipsDropdownMenu.css.js +11 -0
  186. package/dist/xyflow/edges/RelationshipsDropdownMenu.d.ts +13 -0
  187. package/dist/xyflow/edges/RelationshipsDropdownMenu.js +211 -0
  188. package/dist/xyflow/edges/edges.css.d.ts +17 -0
  189. package/dist/xyflow/edges/edges.css.js +37 -0
  190. package/dist/xyflow/edges/utils.d.ts +16 -0
  191. package/dist/xyflow/edges/utils.js +24 -0
  192. package/dist/xyflow/nodes/AnimateVariants.d.ts +1313 -0
  193. package/dist/xyflow/nodes/AnimateVariants.js +123 -0
  194. package/dist/xyflow/nodes/Node.css.d.ts +3 -0
  195. package/dist/xyflow/nodes/Node.css.js +9 -0
  196. package/dist/xyflow/nodes/compound/CompoundNode.css.d.ts +14 -0
  197. package/dist/xyflow/nodes/compound/CompoundNode.css.js +27 -0
  198. package/dist/xyflow/nodes/compound/CompoundNode.d.ts +6 -0
  199. package/dist/xyflow/nodes/compound/CompoundNode.js +216 -0
  200. package/dist/xyflow/nodes/compound/index.d.ts +1 -0
  201. package/dist/xyflow/nodes/element/ElementLink.css.d.ts +3 -0
  202. package/dist/xyflow/nodes/element/ElementLink.d.ts +6 -0
  203. package/dist/xyflow/nodes/element/ElementNode.d.ts +6 -0
  204. package/dist/xyflow/nodes/element/ElementNode.js +190 -0
  205. package/dist/xyflow/nodes/element/ElementShapeSvg.d.ts +17 -0
  206. package/dist/xyflow/nodes/element/ElementShapeSvg.js +175 -0
  207. package/dist/xyflow/nodes/element/element.css.d.ts +18 -0
  208. package/dist/xyflow/nodes/element/element.css.js +31 -0
  209. package/dist/xyflow/nodes/element/index.d.ts +1 -0
  210. package/dist/xyflow/nodes/shared/ElementIcon.d.ts +8 -0
  211. package/dist/xyflow/nodes/shared/ElementIcon.js +38 -0
  212. package/dist/xyflow/nodes/shared/Toolbar.d.ts +9 -0
  213. package/dist/xyflow/nodes/shared/Toolbar.js +436 -0
  214. package/dist/xyflow/types.d.ts +36 -0
  215. package/dist/xyflow/useLayoutConstraints.d.ts +42 -0
  216. package/dist/xyflow/useLayoutConstraints.js +226 -0
  217. package/dist/xyflow/useXYFlowEvents.d.ts +160 -0
  218. package/dist/xyflow/useXYFlowEvents.js +275 -0
  219. package/dist/xyflow/utils.d.ts +22 -0
  220. package/dist/xyflow/utils.js +72 -0
  221. package/package.json +34 -27
  222. package/src/LikeC4Diagram.tsx +4 -4
  223. package/src/LikeC4Search.css.ts +12 -0
  224. package/src/LikeC4Search.tsx +39 -90
  225. package/src/controls/Text.ts +5 -0
  226. package/src/controls/action-button-bar/ActionButtonBar.css.ts +13 -0
  227. package/src/controls/action-button-bar/ActionButtonBar.tsx +138 -0
  228. package/src/controls/action-button-bar/useActionButtonBarCtx.ts +13 -0
  229. package/src/controls/action-buttons/ActionButton.css.ts +29 -0
  230. package/src/controls/action-buttons/ActionButton.tsx +66 -0
  231. package/src/controls/action-buttons/ActionButtons.tsx +138 -0
  232. package/src/hooks/useXYFlow.ts +8 -8
  233. package/src/index.ts +12 -6
  234. package/src/likec4model/index.ts +12 -2
  235. package/src/overlays/edge-details/EdgeDetailsXYFlow.tsx +18 -12
  236. package/src/overlays/edge-details/_types.ts +13 -37
  237. package/src/overlays/edge-details/use-layouted-edge-details.ts +16 -14
  238. package/src/overlays/edge-details/xyflow/CompoundNode.tsx +3 -11
  239. package/src/overlays/edge-details/xyflow/ElementNode.tsx +4 -11
  240. package/src/overlays/edge-details/xyflow/RelationshipEdge.tsx +3 -3
  241. package/src/overlays/edge-details/xyflow/styles.css.ts +1 -59
  242. package/src/overlays/relationships-of/RelationshipsXYFlow.tsx +23 -23
  243. package/src/overlays/relationships-of/_types.ts +20 -58
  244. package/src/overlays/relationships-of/use-layouted-relationships.ts +36 -40
  245. package/src/overlays/relationships-of/xyflow/CompoundNode.tsx +9 -13
  246. package/src/overlays/relationships-of/xyflow/ElementNode.tsx +12 -15
  247. package/src/overlays/relationships-of/xyflow/EmptyNode.tsx +4 -7
  248. package/src/overlays/relationships-of/xyflow/RelationshipEdge.tsx +16 -14
  249. package/src/overlays/shared/xyflow/RelationshipEdge.css.ts +60 -0
  250. package/src/overlays/shared/xyflow/_types.ts +87 -0
  251. package/src/state/diagram-to-xyflow.ts +6 -7
  252. package/src/state/diagramStore.layout.ts +3 -4
  253. package/src/state/diagramStore.ts +35 -37
  254. package/src/theme-vars.css.ts +81 -0
  255. package/src/theme-vars.ts +8 -81
  256. package/src/ui/DiagramTitlePanel.tsx +6 -6
  257. package/src/utils/types.ts +6 -0
  258. package/src/xyflow/SelectEdgesOnNodeFocus.tsx +3 -3
  259. package/src/xyflow/XYFlow.tsx +2 -2
  260. package/src/xyflow/edges/EdgeLabel.tsx +25 -18
  261. package/src/xyflow/edges/RelationshipEdge.tsx +5 -3
  262. package/src/xyflow/edges/RelationshipsDropdownMenu.tsx +3 -3
  263. package/src/xyflow/edges/edges.css.ts +68 -74
  264. package/src/xyflow/edges/utils.ts +6 -6
  265. package/src/xyflow/nodes/AnimateVariants.ts +143 -0
  266. package/src/xyflow/nodes/Node.css.ts +44 -0
  267. package/src/xyflow/nodes/compound/CompoundNode.css.ts +1 -64
  268. package/src/xyflow/nodes/compound/CompoundNode.tsx +69 -182
  269. package/src/xyflow/nodes/element/ElementLink.tsx +2 -3
  270. package/src/xyflow/nodes/element/ElementNode.tsx +64 -266
  271. package/src/xyflow/nodes/element/element.css.ts +0 -57
  272. package/src/xyflow/nodes/shared/Toolbar.tsx +30 -30
  273. package/src/xyflow/types.ts +48 -51
  274. package/src/xyflow/useLayoutConstraints.ts +9 -9
  275. package/src/xyflow/useXYFlowEvents.ts +13 -30
  276. package/src/xyflow/utils.ts +2 -2
  277. package/src/xyflow/nodes/use-animate-variants.tsx +0 -64
@@ -0,0 +1,72 @@
1
+ import { invariant, hasAtLeast } from "@likec4/core";
2
+ import { getNodeDimensions } from "@xyflow/system";
3
+ import { Bezier } from "../node_modules/bezier-js/src/bezier.js";
4
+ import { isArray } from "remeda";
5
+ function toDomPrecision(v) {
6
+ if (v === null) {
7
+ return 0.01;
8
+ }
9
+ return Math.round(v * 100) / 100;
10
+ }
11
+ const nodeToRect = (nd) => ({
12
+ x: nd.internals.positionAbsolute.x,
13
+ y: nd.internals.positionAbsolute.y,
14
+ width: nd.measured.width ?? nd.width ?? nd.data.element.width,
15
+ height: nd.measured.height ?? nd.height ?? nd.data.element.height
16
+ });
17
+ const isInside = (test, target) => {
18
+ return test.x >= target.x && test.y >= target.y && test.x + test.width <= target.x + target.width && test.y + test.height <= target.y + target.height;
19
+ };
20
+ function bezierControlPoints(diagramEdge) {
21
+ let [start, ...bezierPoints] = diagramEdge.points;
22
+ invariant(start, "start should be defined");
23
+ const handles = [
24
+ // start
25
+ ];
26
+ while (hasAtLeast(bezierPoints, 3)) {
27
+ const [cp1, cp2, end, ...rest] = bezierPoints;
28
+ const bezier = new Bezier(start[0], start[1], cp1[0], cp1[1], cp2[0], cp2[1], end[0], end[1]);
29
+ const inflections = bezier.inflections();
30
+ if (inflections.length === 0) {
31
+ inflections.push(0.5);
32
+ }
33
+ inflections.forEach((t) => {
34
+ const { x, y } = bezier.get(t);
35
+ handles.push({
36
+ x: Math.round(x),
37
+ y: Math.round(y)
38
+ });
39
+ });
40
+ bezierPoints = rest;
41
+ start = end;
42
+ }
43
+ invariant(bezierPoints.length === 0, "all points should be consumed");
44
+ return handles;
45
+ }
46
+ const isClose = (a, b) => {
47
+ return Math.abs(a - b) < 3.1;
48
+ };
49
+ function isSamePoint(a, b) {
50
+ const [ax, ay] = isArray(a) ? a : [a.x, a.y];
51
+ const [bx, by] = isArray(b) ? b : [b.x, b.y];
52
+ return isClose(ax, bx) && isClose(ay, by);
53
+ }
54
+ function stopPropagation(e) {
55
+ return e.stopPropagation();
56
+ }
57
+ function centerXYInternalNode(nd) {
58
+ const { width, height } = getNodeDimensions(nd);
59
+ return {
60
+ x: nd.internals.positionAbsolute.x + width / 2,
61
+ y: nd.internals.positionAbsolute.y + height / 2
62
+ };
63
+ }
64
+ export {
65
+ bezierControlPoints,
66
+ centerXYInternalNode,
67
+ isInside,
68
+ isSamePoint,
69
+ nodeToRect,
70
+ stopPropagation,
71
+ toDomPrecision
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/diagram",
3
- "version": "1.18.0",
3
+ "version": "1.19.1",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -11,9 +11,7 @@
11
11
  "directory": "packages/diagram"
12
12
  },
13
13
  "files": [
14
- "package.json",
15
- "LICENSE",
16
- "README.md",
14
+ "dist",
17
15
  "src",
18
16
  "!**/*.spec.*",
19
17
  "!**/*.d.ts.map"
@@ -21,28 +19,32 @@
21
19
  "sideEffects": false,
22
20
  "type": "module",
23
21
  "exports": {
24
- ".": "./src/index.ts"
22
+ ".": {
23
+ "sources": "./src/index.ts",
24
+ "default": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "./style.css": "./dist/style.css"
25
31
  },
26
32
  "packageManager": "yarn@4.5.3",
27
33
  "scripts": {
28
34
  "typecheck": "tsc --noEmit",
29
- "build": "",
35
+ "build": "vite build",
30
36
  "lint": "run -T eslint src/ --fix",
31
37
  "clean": "rm -r -f -g 'dist/*' .tsbuildinfo",
32
38
  "test": "vitest run --no-isolate"
33
39
  },
34
40
  "dependencies": {
35
- "@dagrejs/dagre": "^1.1.4",
36
- "@likec4/core": "1.18.0",
37
- "@mantine/vanilla-extract": "7.15.1",
41
+ "@dagrejs/dagre": "1.1.4",
42
+ "@likec4/core": "1.19.1",
43
+ "@mantine/vanilla-extract": "7.15.2",
38
44
  "@react-hookz/web": "^24.0.4",
39
45
  "@tabler/icons-react": "3.17.0",
40
- "@vanilla-extract/css": "^1.16.1",
41
- "@vanilla-extract/css-utils": "^0.1.4",
42
- "@vanilla-extract/dynamic": "^2.1.2",
43
- "@xyflow/react": "12.3.5",
44
- "@xyflow/system": "0.0.46",
45
- "bezier-js": "^6.1.4",
46
+ "@xyflow/react": "12.3.6",
47
+ "@xyflow/system": "0.0.47",
46
48
  "clsx": "^2.1.1",
47
49
  "d3-shape": "^3.2.0",
48
50
  "esm-env": "^1.2.1",
@@ -55,25 +57,30 @@
55
57
  "zustand": "^4.5.5"
56
58
  },
57
59
  "peerDependencies": {
58
- "@mantine/core": "^7.15.1",
59
- "@mantine/hooks": "^7.15.1",
60
- "@mantine/spotlight": "^7.15.1",
60
+ "@mantine/core": "^7.15.2",
61
+ "@mantine/hooks": "^7.15.2",
62
+ "@mantine/spotlight": "^7.15.2",
61
63
  "react": "^18.3.1",
62
64
  "react-dom": "^18.3.1"
63
65
  },
64
66
  "devDependencies": {
65
- "@likec4/tsconfig": "1.18.0",
66
- "@mantine/core": "7.15.1",
67
- "@mantine/hooks": "7.15.1",
68
- "@mantine/spotlight": "7.15.1",
67
+ "@likec4/tsconfig": "1.19.1",
68
+ "@mantine/core": "7.15.2",
69
+ "@mantine/hooks": "7.15.2",
70
+ "@mantine/spotlight": "7.15.2",
69
71
  "@types/bezier-js": "^4.1.3",
70
72
  "@types/d3-shape": "^3.1.6",
71
- "@types/react": "^18.3.11",
72
- "@types/react-dom": "^18.3.1",
73
- "execa": "^9.3.1",
74
- "react": "^18.3.1",
75
- "react-dom": "^18.3.1",
73
+ "@types/react": "18.3.11",
74
+ "@types/react-dom": "18.3.1",
75
+ "@vanilla-extract/css": "^1.16.1",
76
+ "@vanilla-extract/css-utils": "^0.1.4",
77
+ "@vanilla-extract/dynamic": "^2.1.2",
78
+ "bezier-js": "^6.1.4",
79
+ "react": "18.3.1",
80
+ "react-dom": "18.3.1",
76
81
  "typescript": "^5.7.2",
82
+ "vite": "5.4.11",
83
+ "vite-plugin-dts": "^4.4.0",
77
84
  "vitest": "^2.1.8"
78
85
  }
79
86
  }
@@ -1,4 +1,4 @@
1
- import { ComputedView, isDeploymentView } from '@likec4/core'
1
+ import { isDeploymentView } from '@likec4/core'
2
2
  import { ReactFlowProvider as XYFlowProvider } from '@xyflow/react'
3
3
  import clsx from 'clsx'
4
4
  import { deepEqual } from 'fast-equals'
@@ -17,7 +17,7 @@ import { EnsureMantine } from './ui/EnsureMantine'
17
17
  import { FramerMotionConfig } from './ui/FramerMotionConfig'
18
18
  import { FitViewOnDiagramChange } from './xyflow/FitviewOnDiagramChange'
19
19
  import { SelectEdgesOnNodeFocus } from './xyflow/SelectEdgesOnNodeFocus'
20
- import type { XYFlowEdge, XYFlowNode } from './xyflow/types'
20
+ import type { DiagramFlowTypes } from './xyflow/types'
21
21
  import { XYFlow } from './xyflow/XYFlow'
22
22
  import { XYFlowInner } from './xyflow/XYFlowInner'
23
23
 
@@ -63,8 +63,8 @@ export function LikeC4Diagram({
63
63
  }: LikeC4DiagramProps) {
64
64
  const hasLikec4model = !!useLikeC4Model()
65
65
  const initialRef = useRef({
66
- defaultNodes: [] as XYFlowNode[],
67
- defaultEdges: [] as XYFlowEdge[],
66
+ defaultNodes: [] as DiagramFlowTypes.Node[],
67
+ defaultEdges: [] as DiagramFlowTypes.Edge[],
68
68
  initialWidth: initialWidth ?? view.bounds.width,
69
69
  initialHeight: initialHeight ?? view.bounds.height
70
70
  })
@@ -0,0 +1,12 @@
1
+ import { rem } from '@mantine/core'
2
+ import { globalStyle, style } from '@vanilla-extract/css'
3
+
4
+ export const actionSection = style({
5
+ marginInlineEnd: 4
6
+ })
7
+
8
+ globalStyle(`:where(${actionSection}) .tabler-icon`, {
9
+ opacity: 0.8,
10
+ width: '70%',
11
+ height: '70%'
12
+ })
@@ -1,77 +1,16 @@
1
- import { Center, Group, Highlight, Text } from '@mantine/core'
2
- import { Spotlight, type SpotlightActionData, SpotlightActionsGroup } from '@mantine/spotlight'
3
- import { IconRectangularPrism, IconSearch, IconSitemap } from '@tabler/icons-react'
4
- import { memo, useMemo, useState } from 'react'
1
+ import { rem } from '@mantine/core'
2
+ import { Spotlight, type SpotlightActionData } from '@mantine/spotlight'
3
+ import { IconRectangularPrism, IconSearch, IconSitemap, IconStack2 } from '@tabler/icons-react'
4
+ import { memo, useMemo } from 'react'
5
5
  import { filter, map, pipe } from 'remeda'
6
6
  import { useDiagramState, useDiagramStoreApi, useMantinePortalProps } from './hooks'
7
7
  import { useLikeC4Model } from './likec4model'
8
-
9
- interface QueryMatch {
10
- data: SpotlightActionData
11
- keyword: string
12
- match: string
13
- }
14
-
15
- function filterAction(actionData: SpotlightActionData, query: string): QueryMatch | undefined {
16
- const queryLower = query.toLowerCase()
17
- const keywords = Array.isArray(actionData.keywords) ? actionData.keywords : []
18
- const keywordMatch = keywords
19
- .map(keyword => {
20
- const index = keyword.toLowerCase().indexOf(queryLower)
21
- return index !== -1
22
- ? {
23
- keyword: keyword,
24
- match: keyword.substring(index, index + query.length)
25
- }
26
- : null
27
- })
28
- .find(match => !!match)
29
- return !!keywordMatch
30
- ? {
31
- data: actionData,
32
- keyword: keywordMatch.keyword,
33
- match: keywordMatch.match
34
- }
35
- : undefined
36
- }
37
-
38
- function buildFilteredActions(actionsData: SpotlightActionData[], query: string): JSX.Element[] {
39
- return pipe(
40
- actionsData,
41
- map(a => filterAction(a, query)),
42
- filter(qm => !!qm),
43
- map(qm => buildSpotlightAction(qm))
44
- )
45
- }
46
-
47
- function highlightMatch(match: QueryMatch): JSX.Element {
48
- return <Highlight highlight={match.match}>{match.keyword}</Highlight>
49
- }
50
-
51
- function buildSpotlightAction(matchedAction: QueryMatch): JSX.Element {
52
- const isMatchInLabel = matchedAction.keyword == matchedAction.data.label
53
- return (
54
- <Spotlight.Action key={matchedAction.data.id} onClick={matchedAction.data.onClick}>
55
- <Center style={{ marginRight: '8px ' }}>
56
- {matchedAction.data.leftSection}
57
- </Center>
58
- <Group wrap="nowrap" w="100%">
59
- <div style={{ flex: 1 }}>
60
- <Text>
61
- {isMatchInLabel ? highlightMatch(matchedAction) : matchedAction.data.label}
62
- </Text>
63
- {!isMatchInLabel && <Text opacity={0.6} size="xs">{highlightMatch(matchedAction)}</Text>}
64
- </div>
65
- </Group>
66
- </Spotlight.Action>
67
- )
68
- }
8
+ import * as css from './LikeC4Search.css'
69
9
 
70
10
  export const LikeC4Search = memo(() => {
71
11
  const view = useDiagramState(s => s.view)
72
12
  const model = useLikeC4Model(true)
73
13
  const store = useDiagramStoreApi()
74
- const [query, setQuery] = useState('')
75
14
 
76
15
  const getNodeActionsData = (): SpotlightActionData[] => {
77
16
  const { focusOnNode } = store.getState()
@@ -82,6 +21,9 @@ export const LikeC4Search = memo(() => {
82
21
  map(n => ({
83
22
  id: n.id,
84
23
  label: n.title,
24
+ ...(n.description && {
25
+ description: n.description
26
+ }),
85
27
  keywords: [
86
28
  n.title,
87
29
  ...(n.tags ?? []).map(t => `#${t}`),
@@ -94,12 +36,14 @@ export const LikeC4Search = memo(() => {
94
36
  }
95
37
 
96
38
  const getViewActionsData = (): SpotlightActionData[] => {
97
- const { onNavigateTo } = store.getState()
98
- const views = model.views().toArray()
39
+ const views = [...model.views()]
99
40
 
100
41
  return map(views, v => ({
101
42
  id: v.id,
102
43
  label: v.title ?? v.id,
44
+ ...(v.$view.description && {
45
+ description: v.$view.description
46
+ }),
103
47
  keywords: [
104
48
  v.title ?? v.id,
105
49
  ...(v.tags ?? []),
@@ -107,43 +51,48 @@ export const LikeC4Search = memo(() => {
107
51
  ],
108
52
  onClick: () => {
109
53
  store.setState({
110
- hoveredNodeId: null,
111
54
  lastOnNavigate: {
112
55
  fromView: view.id,
113
56
  toView: v.id,
114
57
  fromNode: null
115
58
  }
116
59
  })
117
- onNavigateTo?.(v.id)
60
+ store.getState().onNavigateTo?.(v.id)
118
61
  },
119
- leftSection: <IconSitemap />
62
+ leftSection: v.isDeploymentView()
63
+ ? <IconStack2 />
64
+ : <IconSitemap />
120
65
  }))
121
66
  }
122
67
 
123
- const { nodeActions, viewActions } = useMemo(() => ({
124
- nodeActions: buildFilteredActions(getNodeActionsData(), query),
125
- viewActions: buildFilteredActions(getViewActionsData(), query)
126
- }), [model, store, view, query])
68
+ const actions = useMemo(() => [
69
+ {
70
+ group: 'Elements',
71
+ actions: getNodeActionsData()
72
+ },
73
+ {
74
+ group: 'Views',
75
+ actions: getViewActionsData()
76
+ }
77
+ ], [model, store, view])
127
78
 
128
79
  const portalProps = useMantinePortalProps()
129
80
  return (
130
- <Spotlight.Root
81
+ <Spotlight
131
82
  {...portalProps}
83
+ actions={actions}
84
+ nothingFound="Nothing found..."
132
85
  shortcut={['mod + f', 'mod + k']}
133
- query={query}
134
- onQueryChange={setQuery}
135
86
  scrollable
136
- maxHeight={'calc(100vh - 100px)'}
137
- >
138
- <Spotlight.Search
139
- placeholder="Search elements in current view and other views..."
140
- leftSection={<IconSearch stroke={1.5} />}
141
- />
142
- <Spotlight.ActionsList>
143
- {nodeActions.length > 0 && <SpotlightActionsGroup label="Elements">{nodeActions}</SpotlightActionsGroup>}
144
- {viewActions.length > 0 && <SpotlightActionsGroup label="Views">{viewActions}</SpotlightActionsGroup>}
145
- {nodeActions.length == 0 && viewActions.length == 0 && <Spotlight.Empty>Nothing found...</Spotlight.Empty>}
146
- </Spotlight.ActionsList>
147
- </Spotlight.Root>
87
+ highlightQuery
88
+ maxHeight={350}
89
+ classNames={{
90
+ actionSection: css.actionSection
91
+ }}
92
+ searchProps={{
93
+ leftSection: <IconSearch style={{ width: rem(18), height: rem(18) }} stroke={1.5} />,
94
+ placeholder: 'Search elements and views...'
95
+ }}
96
+ />
148
97
  )
149
98
  })
@@ -0,0 +1,5 @@
1
+ import { Text as MantineText } from '@mantine/core'
2
+
3
+ export const Text = MantineText.withProps({
4
+ component: 'div'
5
+ })
@@ -0,0 +1,13 @@
1
+ import { style } from "@vanilla-extract/css";
2
+
3
+ export const container = style({
4
+ zIndex: 100,
5
+ width: '100%',
6
+ display: 'flex',
7
+ flexDirection: 'row',
8
+ flexWrap: 'nowrap',
9
+ alignItems: 'center',
10
+ gap: 2,
11
+ justifyContent: 'center',
12
+ pointerEvents: 'none',
13
+ })
@@ -0,0 +1,138 @@
1
+ import { Box } from '@mantine/core'
2
+ import { useId } from '@mantine/hooks'
3
+ import clsx from 'clsx'
4
+ import { type Variants } from 'framer-motion'
5
+ import type { PropsWithChildren } from 'react'
6
+ import * as css from './ActionButtonBar.css'
7
+ import { ActionButtonBarContext } from './useActionButtonBarCtx'
8
+
9
+ const TRANSLATE_DIFF = 5
10
+
11
+ type ShiftX = 'left' | 'spread' | 'right'
12
+ type ShiftY = 'top' | 'spread' | 'bottom'
13
+ type ShiftMode = number | 'spread'
14
+
15
+ type ActionButtonBarProps = PropsWithChildren<{
16
+ shiftX?: ShiftX
17
+ shiftY?: ShiftY
18
+ }>
19
+
20
+ const elementVariants = (prefix: string, index: number, count: number, shiftX: ShiftMode, shiftY: ShiftMode) => {
21
+ const name = `${prefix}${index + 1}`
22
+ const translation = count > 1
23
+ ? {
24
+ x: shiftX === 'spread' ? 1 - count + index * 2 : shiftX,
25
+ y: shiftY === 'spread' ? 1 - count + index * 2 : shiftY,
26
+ }
27
+ : {
28
+ x: 0,
29
+ y: 1,
30
+ }
31
+
32
+ const variants = {
33
+ idle: {
34
+ '--icon-scale': 'scale(1)',
35
+ '--ai-bg': 'var(--ai-bg-idle)',
36
+ scale: 1,
37
+ opacity: 0.8,
38
+ translateX: 0,
39
+ translateY: 0,
40
+ originX: 0.5,
41
+ originY: 0.5,
42
+ // translateY: 0,
43
+ // ...align === 'left' && {
44
+ // originX: 0.75,
45
+ // translateX: -1
46
+ // },
47
+ // ...align === 'right' && {
48
+ // originX: 0.25,
49
+ // translateX: 1
50
+ // }
51
+ },
52
+ hovered: {
53
+ '--ai-bg': 'var(--ai-bg-hover)',
54
+ '--icon-scale': 'scale(1)',
55
+ // translateY: 3,
56
+ scale: 1.28,
57
+ opacity: 1,
58
+ translateX: translation.x * TRANSLATE_DIFF,
59
+ translateY: translation.y * TRANSLATE_DIFF,
60
+ // ...align === 'left' && {
61
+ // translateX: -4
62
+ // },
63
+ // ...align === 'right' && {
64
+ // translateX: 4
65
+ // }
66
+ },
67
+ [`hovered:${name}`]: {
68
+ '--ai-bg': 'var(--ai-hover)',
69
+ '--icon-scale': 'scale(1.08)',
70
+ scale: 1.45,
71
+ },
72
+ [`tap:${name}`]: {
73
+ '--icon-scale': 'scale(1)',
74
+ scale: 1.15,
75
+ },
76
+ selected: {},
77
+ } satisfies Variants
78
+ variants['selected'] = variants['hovered']
79
+ variants['hovered:details'] = variants['idle']
80
+ return {
81
+ variants,
82
+ ['data-animate-target']: name,
83
+ }
84
+ }
85
+
86
+ export const ActionButtonBar = ({
87
+ shiftX = 'spread',
88
+ shiftY = 'spread',
89
+ children,
90
+ }: ActionButtonBarProps) => {
91
+ const id = useId()
92
+ const childrenArray = Array.isArray(children) ? children : [children]
93
+
94
+ // determine offsets for shifting
95
+ let shiftDiffX: ShiftMode = 'spread'
96
+ if (shiftX == 'left') {
97
+ shiftDiffX = -1
98
+ }
99
+ else if (shiftX == 'right') {
100
+ shiftDiffX = 1
101
+ }
102
+
103
+ let shiftDiffY: ShiftMode = 'spread'
104
+ if (shiftY == 'top') {
105
+ shiftDiffY = -1
106
+ }
107
+ else if (shiftY == 'bottom') {
108
+ shiftDiffY = 1
109
+ }
110
+
111
+ return (
112
+ <Box className={clsx(css.container)}>
113
+ {childrenArray.map((child, i, all) => (
114
+ <ActionButtonBarContext.Provider
115
+ value={elementVariants(id, i, all.length, shiftDiffX, shiftDiffY)}>
116
+ {child}
117
+ </ActionButtonBarContext.Provider>
118
+ // <>{cloneElement(child, {
119
+ // key: i,
120
+ // variants: elementVariants(i, all.length, shiftDiffX, shiftDiffY),
121
+ // ['data-animate-target']: `i${i + 1}`,
122
+ // ...props
123
+ // })}</>
124
+ ))}
125
+ {
126
+ /* {childrenArray.filter(child => !!child).map((child, i) => (
127
+ <m.div
128
+ key={i}
129
+ variants={elementVariants(i, childrenArray.length, shiftDiffX, shiftDiffY)}
130
+ {...props}
131
+ >
132
+ {child}
133
+ </m.div>
134
+ ))} */
135
+ }
136
+ </Box>
137
+ )
138
+ }
@@ -0,0 +1,13 @@
1
+ import type { Variants } from 'framer-motion'
2
+ import { createContext, useContext } from 'react'
3
+
4
+ export const ActionButtonBarContext = createContext<
5
+ {
6
+ variants: Variants
7
+ ['data-animate-target']?: string
8
+ } | null
9
+ >(null)
10
+
11
+ export function useActionButtonBarCtx() {
12
+ return useContext(ActionButtonBarContext)
13
+ }
@@ -0,0 +1,29 @@
1
+ import { style } from '@vanilla-extract/css'
2
+ import { mantine, vars, whereLight } from '../../theme-vars'
3
+
4
+ export const btn = style({
5
+ pointerEvents: 'all',
6
+ color: vars.element.loContrast,
7
+ cursor: 'pointer',
8
+ backgroundColor: 'var(--ai-bg)',
9
+ 'vars': {
10
+ '--ai-bg-idle': `color-mix(in srgb , ${vars.element.fill}, transparent 99%)`,
11
+ '--ai-bg': `var(--ai-bg-idle)`,
12
+ '--ai-bg-hover': `color-mix(in srgb , ${vars.element.fill} 65%, ${vars.element.stroke})`,
13
+ '--ai-hover': `color-mix(in srgb , ${vars.element.fill} 50%, ${vars.element.stroke})`,
14
+ },
15
+ ':hover': {
16
+ boxShadow: mantine.shadows.md,
17
+ },
18
+ selectors: {
19
+ [`${whereLight} .likec4-compound-transparent &`]: {
20
+ color: vars.element.stroke,
21
+ opacity: 0.85,
22
+ vars: {
23
+ '--ai-bg-hover': `color-mix(in srgb , ${vars.element.fill}, transparent 20%)`,
24
+ '--ai-hover': `color-mix(in srgb , ${vars.element.fill}, transparent 10%)`,
25
+ '--ai-bg': `color-mix(in srgb , ${vars.element.fill}, transparent 99%)`,
26
+ },
27
+ },
28
+ },
29
+ })
@@ -0,0 +1,66 @@
1
+ import { type ActionIconProps, ActionIcon, Tooltip } from '@mantine/core'
2
+ import clsx from 'clsx'
3
+ import { type HTMLMotionProps, type Variants, m } from 'framer-motion'
4
+ import type { PropsWithoutRef } from 'react'
5
+ import { stopPropagation } from '../../xyflow/utils'
6
+ import { useActionButtonBarCtx } from '../action-button-bar/useActionButtonBarCtx'
7
+ import * as css from './ActionButton.css'
8
+
9
+ export type ActionButtonProps = PropsWithoutRef<
10
+ Omit<ActionIconProps & HTMLMotionProps<'div'>, 'onClick' | 'children'> & {
11
+ onClick: (e: React.MouseEvent) => void
12
+ IconComponent: React.ComponentType<any>
13
+ tooltipLabel?: string
14
+ }
15
+ >
16
+
17
+ const variants = {
18
+ idle: {
19
+ '--icon-scale': 'scale(1)',
20
+ '--ai-bg': 'var(--ai-bg-idle)',
21
+ },
22
+ hovered: {
23
+ '--icon-scale': 'scale(1)',
24
+ '--ai-bg': 'var(--ai-bg-hover)',
25
+ },
26
+ selected: {},
27
+ } satisfies Variants
28
+ variants['selected'] = variants['hovered']
29
+
30
+ export const ActionButton = ({
31
+ onClick: action,
32
+ IconComponent,
33
+ tooltipLabel,
34
+ ...props
35
+ }: ActionButtonProps) => {
36
+ const ctx = useActionButtonBarCtx() ?? {
37
+ variants: variants,
38
+ }
39
+ return (
40
+ <Tooltip
41
+ fz="xs"
42
+ color="dark"
43
+ label={tooltipLabel ?? ''}
44
+ disabled={!tooltipLabel}
45
+ withinPortal={false}
46
+ offset={2}
47
+ openDelay={600}>
48
+ <ActionIcon
49
+ component={m.div}
50
+ className={clsx('nodrag nopan', css.btn)}
51
+ radius="md"
52
+ role="button"
53
+ onClick={action}
54
+ onDoubleClick={stopPropagation}
55
+ {...ctx}
56
+ {...props}
57
+ >
58
+ <IconComponent
59
+ style={{
60
+ width: '70%',
61
+ transform: 'var(--icon-scale)',
62
+ }} />
63
+ </ActionIcon>
64
+ </Tooltip>
65
+ )
66
+ }