@likec4/diagram 1.31.0 → 1.32.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 (264) hide show
  1. package/bundle/{chunk-BBzMXzCg.js → chunk-BvTQaUYl.js} +1675 -1207
  2. package/bundle/custom.js +50 -47
  3. package/bundle/index.js +2482 -2438
  4. package/dist/LikeC4CustomColors.d.ts +2 -7
  5. package/dist/LikeC4CustomColors.js +17 -6
  6. package/dist/LikeC4Diagram.d.ts +3 -2
  7. package/dist/LikeC4Diagram.js +10 -14
  8. package/dist/LikeC4Diagram.props.d.ts +28 -22
  9. package/dist/LikeC4ModelProvider.d.ts +5 -4
  10. package/dist/StaticLikeC4Diagram.d.ts +3 -2
  11. package/dist/StaticLikeC4Diagram.js +2 -2
  12. package/dist/base/BaseXYFlow.js +5 -5
  13. package/dist/base/const.d.ts +1 -1
  14. package/dist/base/const.js +1 -1
  15. package/dist/base/index.d.ts +2 -1
  16. package/dist/base/primitives/compound/CompoundActionButton.js +2 -1
  17. package/dist/base/primitives/compound/CompoundDetailsButton.js +2 -1
  18. package/dist/base/primitives/compound/CompoundTitle.d.ts +1 -1
  19. package/dist/base/primitives/compound/CompoundTitle.js +2 -1
  20. package/dist/base/primitives/edge/EdgeContainer.d.ts +1 -1
  21. package/dist/base/primitives/edge/EdgeLabel.css.js +1 -0
  22. package/dist/base/primitives/edge/EdgeLabel.d.ts +3 -3
  23. package/dist/base/primitives/edge/EdgeLabel.js +6 -4
  24. package/dist/base/primitives/edge/EdgeLabelContainer.d.ts +1 -1
  25. package/dist/base/primitives/edge/EdgeMarkers.d.ts +1 -1
  26. package/dist/base/primitives/edge/EdgePath.d.ts +1 -1
  27. package/dist/base/primitives/element/ElementActionButtons.js +10 -9
  28. package/dist/base/primitives/element/ElementDetailsButton.js +2 -1
  29. package/dist/base/primitives/element/ElementShape.d.ts +1 -1
  30. package/dist/base/primitives/element/ElementTags.d.ts +14 -0
  31. package/dist/base/primitives/element/ElementTags.js +176 -0
  32. package/dist/base/primitives/element/ElementTitle.d.ts +5 -4
  33. package/dist/base/primitives/element/ElementTitle.js +6 -6
  34. package/dist/base/primitives/index.d.ts +1 -0
  35. package/dist/base/types.Base.d.ts +54 -0
  36. package/dist/base/types.Base.js +48 -0
  37. package/dist/base/types.d.ts +2 -52
  38. package/dist/bundle/LikeC4View.d.ts +2 -1
  39. package/dist/bundle/LikeC4View.js +8 -6
  40. package/dist/bundle/LikeC4View.props.d.ts +15 -4
  41. package/dist/bundle/ReactLikeC4.d.ts +4 -7
  42. package/dist/bundle/ReactLikeC4.js +3 -2
  43. package/dist/bundle/index.js +1 -1
  44. package/dist/components/ErrorFallback.d.ts +2 -0
  45. package/dist/components/ErrorFallback.js +29 -0
  46. package/dist/context/DiagramEventHandlers.d.ts +6 -5
  47. package/dist/context/DiagramFeatures.d.ts +2 -2
  48. package/dist/context/DiagramFeatures.js +3 -31
  49. package/dist/context/EnsureMantine.js +1 -1
  50. package/dist/context/IconRenderer.js +1 -4
  51. package/dist/context/RootContainer.js +5 -1
  52. package/dist/context/TagStylesContext.d.ts +7 -0
  53. package/dist/context/TagStylesContext.js +85 -0
  54. package/dist/custom/components.d.ts +1 -1
  55. package/dist/custom/customNodes.d.ts +27 -17
  56. package/dist/custom/hooks.d.ts +1 -1
  57. package/dist/hooks/index.d.ts +1 -1
  58. package/dist/hooks/useDiagram.d.ts +73 -38
  59. package/dist/hooks/useDiagram.js +7 -3
  60. package/dist/hooks/useMantinePortalProps.d.ts +2 -2
  61. package/dist/hooks/useSearchActor.d.ts +2 -0
  62. package/dist/hooks/useSearchActor.js +10 -0
  63. package/dist/hooks/useUpdateEffect.js +3 -0
  64. package/dist/hooks/useXYFlow.d.ts +39 -37
  65. package/dist/hooks/useXYFlow.js +5 -1
  66. package/dist/index.js +1 -1
  67. package/dist/likec4diagram/DiagramUI.js +7 -2
  68. package/dist/likec4diagram/DiagramXYFlow.d.ts +4 -3
  69. package/dist/likec4diagram/DiagramXYFlow.js +104 -107
  70. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +7 -6
  71. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +8 -0
  72. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +7 -5
  73. package/dist/likec4diagram/custom/index.d.ts +7 -6
  74. package/dist/likec4diagram/custom/nodes/nodes.js +39 -26
  75. package/dist/likec4diagram/custom/nodes/toolbar/_shared.d.ts +3 -3
  76. package/dist/likec4diagram/types.d.ts +5 -5
  77. package/dist/likec4diagram/ui/controls/Controls.js +12 -4
  78. package/dist/likec4diagram/ui/notation/NotationPanel.js +1 -1
  79. package/dist/likec4diagram/useViewToNodesEdges.d.ts +5 -3
  80. package/dist/likec4diagram/useViewToNodesEdges.js +20 -30
  81. package/dist/likec4model/LikeC4ModelContext.d.ts +2 -2
  82. package/dist/likec4model/useLikeC4ElementsTree.js +1 -1
  83. package/dist/likec4model/useLikeC4Model.d.ts +22 -10
  84. package/dist/likec4model/useLikeC4Model.js +11 -7
  85. package/dist/overlays/Overlays.js +4 -27
  86. package/dist/overlays/element-details/ElementDetailsCard.d.ts +1 -1
  87. package/dist/overlays/element-details/ElementDetailsCard.js +19 -12
  88. package/dist/overlays/element-details/TabPanelDeployments.d.ts +1 -1
  89. package/dist/overlays/element-details/TabPanelDeployments.js +1 -1
  90. package/dist/overlays/element-details/TabPanelRelationships.d.ts +1 -1
  91. package/dist/overlays/element-details/TabPanelStructure.d.ts +1 -1
  92. package/dist/overlays/element-details/actor.d.ts +288 -286
  93. package/dist/overlays/overlay/Overlay.css.d.ts +57 -2
  94. package/dist/overlays/overlay/Overlay.css.js +76 -39
  95. package/dist/overlays/overlay/Overlay.d.ts +12 -0
  96. package/dist/overlays/overlay/Overlay.js +36 -25
  97. package/dist/overlays/overlaysActor.d.ts +1 -1
  98. package/dist/overlays/relationship-details/RelationshipDetails.d.ts +3 -2
  99. package/dist/overlays/relationship-details/RelationshipDetails.js +3 -3
  100. package/dist/overlays/relationship-details/_types.d.ts +2 -2
  101. package/dist/overlays/relationship-details/actor.js +7 -7
  102. package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +3 -2
  103. package/dist/overlays/relationship-details/custom/nodeTypes.js +4 -0
  104. package/dist/overlays/relationship-details/hooks.d.ts +10 -9
  105. package/dist/overlays/relationship-details/layout-to-xyflow.js +1 -0
  106. package/dist/overlays/relationship-details/layout.js +3 -1
  107. package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +3 -2
  108. package/dist/overlays/relationships-browser/SelectElement.js +1 -1
  109. package/dist/overlays/relationships-browser/_types.d.ts +2 -2
  110. package/dist/overlays/relationships-browser/actor.d.ts +1 -1
  111. package/dist/overlays/relationships-browser/actor.js +7 -7
  112. package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +3 -2
  113. package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +8 -5
  114. package/dist/overlays/relationships-browser/custom/nodeTypes.js +4 -0
  115. package/dist/overlays/relationships-browser/layout.d.ts +2 -2
  116. package/dist/overlays/relationships-browser/layout.js +10 -6
  117. package/dist/overlays/relationships-browser/useViewToNodesEdges.js +4 -3
  118. package/dist/search/Search.d.ts +5 -0
  119. package/dist/search/Search.js +192 -0
  120. package/dist/{likec4diagram/ui/search → search/components}/ElementsColumn.css.js +0 -1
  121. package/dist/search/components/ElementsColumn.d.ts +2 -0
  122. package/dist/{likec4diagram/ui/search → search/components}/ElementsColumn.js +21 -19
  123. package/dist/search/components/PickView.d.ts +4 -0
  124. package/dist/search/components/PickView.js +135 -0
  125. package/dist/search/components/SearchByTags.d.ts +1 -0
  126. package/dist/search/components/SearchByTags.js +116 -0
  127. package/dist/search/components/SearchInput.d.ts +2 -0
  128. package/dist/{likec4diagram/ui/search → search/components}/SearchInput.js +53 -34
  129. package/dist/{likec4diagram/ui/search → search/components}/ViewsColum.d.ts +3 -2
  130. package/dist/{likec4diagram/ui/search → search/components}/ViewsColum.js +14 -13
  131. package/dist/{likec4diagram/ui/search → search/components}/_shared.css.js +26 -35
  132. package/dist/{likec4diagram/ui/search/LikeC4Search.css.d.ts → search/components/styles.css.d.ts} +0 -2
  133. package/dist/search/components/styles.css.js +60 -0
  134. package/dist/{likec4diagram/ui/search → search/components}/utils.d.ts +1 -0
  135. package/dist/{likec4diagram/ui/search → search/components}/utils.js +7 -1
  136. package/dist/search/hooks.d.ts +16 -0
  137. package/dist/search/hooks.js +35 -0
  138. package/dist/search/searchActor.d.ts +90 -0
  139. package/dist/search/searchActor.js +75 -0
  140. package/dist/state/DiagramActorProvider.d.ts +9 -7
  141. package/dist/state/DiagramActorProvider.js +24 -18
  142. package/dist/state/assign.d.ts +0 -1
  143. package/dist/state/assign.js +9 -19
  144. package/dist/state/diagram-machine.d.ts +430 -176
  145. package/dist/state/diagram-machine.js +119 -54
  146. package/dist/state/syncManualLayoutActor.d.ts +2 -2
  147. package/dist/state/types.d.ts +2 -0
  148. package/dist/state/utils.d.ts +2 -0
  149. package/dist/state/utils.js +3 -0
  150. package/dist/styles-min.css +1 -1
  151. package/dist/styles-xyflow.css +1 -1
  152. package/dist/styles.css +1 -1
  153. package/dist/styles.css2.js +1 -1
  154. package/package.json +18 -18
  155. package/panda.buildinfo.json +171 -148
  156. package/src/LikeC4CustomColors.tsx +21 -6
  157. package/src/LikeC4Diagram.props.ts +35 -30
  158. package/src/LikeC4Diagram.tsx +19 -20
  159. package/src/LikeC4ModelProvider.tsx +6 -5
  160. package/src/StaticLikeC4Diagram.tsx +8 -6
  161. package/src/base/const.ts +1 -1
  162. package/src/base/index.ts +2 -1
  163. package/src/base/primitives/compound/CompoundActionButton.tsx +2 -1
  164. package/src/base/primitives/compound/CompoundDetailsButton.tsx +2 -1
  165. package/src/base/primitives/compound/CompoundTitle.tsx +3 -2
  166. package/src/base/primitives/edge/EdgeContainer.tsx +2 -1
  167. package/src/base/primitives/edge/EdgeLabel.css.ts +1 -0
  168. package/src/base/primitives/edge/EdgeLabel.tsx +20 -15
  169. package/src/base/primitives/edge/EdgeLabelContainer.tsx +1 -1
  170. package/src/base/primitives/edge/EdgeMarkers.tsx +2 -1
  171. package/src/base/primitives/edge/EdgePath.tsx +1 -1
  172. package/src/base/primitives/element/ElementActionButtons.tsx +11 -10
  173. package/src/base/primitives/element/ElementDetailsButton.tsx +2 -1
  174. package/src/base/primitives/element/ElementShape.tsx +2 -1
  175. package/src/base/primitives/element/ElementTags.tsx +182 -0
  176. package/src/base/primitives/element/ElementTitle.tsx +21 -15
  177. package/src/base/primitives/index.ts +1 -0
  178. package/src/base/types.Base.ts +104 -0
  179. package/src/base/types.ts +2 -99
  180. package/src/bundle/LikeC4View.props.ts +17 -4
  181. package/src/bundle/LikeC4View.tsx +17 -19
  182. package/src/bundle/ReactLikeC4.tsx +14 -26
  183. package/src/components/ErrorFallback.tsx +30 -0
  184. package/src/context/DiagramEventHandlers.tsx +5 -4
  185. package/src/context/DiagramFeatures.tsx +3 -22
  186. package/src/context/EnsureMantine.tsx +1 -1
  187. package/src/context/IconRenderer.tsx +1 -4
  188. package/src/context/RootContainer.tsx +9 -3
  189. package/src/context/TagStylesContext.tsx +96 -0
  190. package/src/custom/components.ts +2 -0
  191. package/src/custom/customNodes.tsx +24 -14
  192. package/src/custom/hooks.ts +1 -0
  193. package/src/hooks/index.ts +1 -1
  194. package/src/hooks/useCurrentViewId.ts +1 -4
  195. package/src/hooks/useDiagram.ts +104 -12
  196. package/src/hooks/useMantinePortalProps.ts +10 -1
  197. package/src/hooks/useSearchActor.ts +11 -0
  198. package/src/hooks/useUpdateEffect.ts +7 -4
  199. package/src/hooks/useXYFlow.ts +5 -0
  200. package/src/likec4diagram/DiagramUI.tsx +5 -0
  201. package/src/likec4diagram/DiagramXYFlow.tsx +115 -118
  202. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +9 -0
  203. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +10 -9
  204. package/src/likec4diagram/custom/nodes/nodes.tsx +45 -43
  205. package/src/likec4diagram/custom/nodes/toolbar/_shared.tsx +11 -3
  206. package/src/likec4diagram/types.ts +5 -3
  207. package/src/likec4diagram/ui/controls/Controls.tsx +11 -4
  208. package/src/likec4diagram/ui/notation/NotationPanel.tsx +2 -2
  209. package/src/likec4diagram/useViewToNodesEdges.ts +34 -36
  210. package/src/likec4model/LikeC4ModelContext.ts +2 -2
  211. package/src/likec4model/useLikeC4ElementsTree.ts +1 -1
  212. package/src/likec4model/useLikeC4Model.ts +18 -16
  213. package/src/overlays/Overlays.tsx +5 -32
  214. package/src/overlays/element-details/ElementDetailsCard.tsx +25 -18
  215. package/src/overlays/element-details/TabPanelDeployments.tsx +3 -2
  216. package/src/overlays/element-details/TabPanelRelationships.tsx +2 -1
  217. package/src/overlays/element-details/TabPanelStructure.tsx +1 -1
  218. package/src/overlays/element-details/actor.ts +2 -2
  219. package/src/overlays/overlay/Overlay.css.ts +75 -38
  220. package/src/overlays/overlay/Overlay.tsx +43 -26
  221. package/src/overlays/overlaysActor.ts +1 -1
  222. package/src/overlays/relationship-details/RelationshipDetails.tsx +4 -4
  223. package/src/overlays/relationship-details/_types.ts +2 -1
  224. package/src/overlays/relationship-details/custom/nodeTypes.tsx +4 -0
  225. package/src/overlays/relationship-details/layout-to-xyflow.ts +1 -0
  226. package/src/overlays/relationship-details/layout.ts +3 -1
  227. package/src/overlays/relationships-browser/SelectElement.tsx +1 -1
  228. package/src/overlays/relationships-browser/_types.ts +2 -1
  229. package/src/overlays/relationships-browser/custom/nodeTypes.tsx +4 -0
  230. package/src/overlays/relationships-browser/layout.ts +12 -7
  231. package/src/overlays/relationships-browser/useViewToNodesEdges.ts +4 -4
  232. package/src/search/Search.tsx +237 -0
  233. package/src/{likec4diagram/ui/search → search/components}/ElementsColumn.css.ts +0 -29
  234. package/src/{likec4diagram/ui/search → search/components}/ElementsColumn.tsx +24 -22
  235. package/src/search/components/PickView.tsx +140 -0
  236. package/src/search/components/SearchByTags.tsx +109 -0
  237. package/src/{likec4diagram/ui/search → search/components}/SearchInput.tsx +63 -36
  238. package/src/{likec4diagram/ui/search → search/components}/ViewsColum.tsx +17 -18
  239. package/src/{likec4diagram/ui/search → search/components}/_shared.css.ts +26 -37
  240. package/src/{likec4diagram/ui/search/LikeC4Search.css.ts → search/components/styles.css.ts} +9 -36
  241. package/src/{likec4diagram/ui/search → search/components}/utils.ts +7 -0
  242. package/src/search/hooks.ts +41 -0
  243. package/src/search/searchActor.ts +99 -0
  244. package/src/state/DiagramActorProvider.tsx +36 -25
  245. package/src/state/assign.ts +10 -10
  246. package/src/state/diagram-machine.ts +115 -52
  247. package/src/state/syncManualLayoutActor.ts +1 -1
  248. package/src/state/types.ts +2 -0
  249. package/src/state/utils.ts +4 -0
  250. package/dist/base/types.js +0 -54
  251. package/dist/likec4diagram/ui/search/ElementsColumn.d.ts +0 -1
  252. package/dist/likec4diagram/ui/search/LikeC4Search.css.js +0 -87
  253. package/dist/likec4diagram/ui/search/LikeC4Search.d.ts +0 -2
  254. package/dist/likec4diagram/ui/search/LikeC4Search.js +0 -267
  255. package/dist/likec4diagram/ui/search/SearchInput.d.ts +0 -1
  256. package/dist/likec4diagram/ui/search/state.d.ts +0 -19
  257. package/dist/likec4diagram/ui/search/state.js +0 -63
  258. package/src/likec4diagram/ui/search/LikeC4Search.tsx +0 -301
  259. package/src/likec4diagram/ui/search/state.ts +0 -78
  260. /package/dist/{likec4diagram/ui/search → search/components}/ElementsColumn.css.d.ts +0 -0
  261. /package/dist/{likec4diagram/ui/search → search/components}/ViewsColumn.css.d.ts +0 -0
  262. /package/dist/{likec4diagram/ui/search → search/components}/ViewsColumn.css.js +0 -0
  263. /package/dist/{likec4diagram/ui/search → search/components}/_shared.css.d.ts +0 -0
  264. /package/src/{likec4diagram/ui/search → search/components}/ViewsColumn.css.ts +0 -0
@@ -0,0 +1,237 @@
1
+ import { css } from '@likec4/styles/css'
2
+ import { VStack } from '@likec4/styles/jsx'
3
+ import { FocusTrap, Grid, GridCol, Group, ScrollArea, Title } from '@mantine/core'
4
+ import {
5
+ useCallbackRef,
6
+ useHotkeys,
7
+ } from '@mantine/hooks'
8
+ import { useTimeoutEffect } from '@react-hookz/web'
9
+ import { useSelector } from '@xstate/react'
10
+ import { AnimatePresence, LayoutGroup } from 'motion/react'
11
+ import { memo, useRef } from 'react'
12
+ import { ErrorBoundary } from 'react-error-boundary'
13
+ import { isTruthy } from 'remeda'
14
+ import { ErrorFallback } from '../components/ErrorFallback'
15
+ import { DiagramFeatures } from '../context/DiagramFeatures'
16
+ import { Overlay } from '../overlays/overlay/Overlay'
17
+ import { ElementsColumn } from './components/ElementsColumn'
18
+ import { PickView } from './components/PickView'
19
+ import { SearchByTags } from './components/SearchByTags'
20
+ import { LikeC4SearchInput } from './components/SearchInput'
21
+ import { focusToFirstFoundElement, moveFocusToSearchInput } from './components/utils'
22
+ import { ViewsColumn } from './components/ViewsColum'
23
+ import { SearchActorContext, usePickViewFor } from './hooks'
24
+ import { type SearchActorRef, type SearchActorSnapshot } from './searchActor'
25
+
26
+ const dialog = css({
27
+ backgroundColor: `[rgb(34 34 34 / var(--_opacity, 95%))]`,
28
+ _light: {
29
+ backgroundColor: `[rgb(250 250 250 / var(--_opacity, 95%))]`,
30
+ },
31
+ backdropFilter: 'auto',
32
+ backdropBlur: 'var(--_blur, 10px)',
33
+ // base: `[rgb(34 34 34 / var(${backdropOpacity}))]`,
34
+ // _light: `[rgb(255 255 255/ var(${backdropOpacity}))]`,
35
+ // },
36
+ })
37
+
38
+ const body = css({
39
+ // containerName: 'likec4-search',
40
+ // containerType: 'size',
41
+ // position: 'fixed',
42
+ // zIndex: 901,
43
+ // top: 0,
44
+ // left: 0,
45
+ width: '100%',
46
+ height: '100%',
47
+ maxHeight: '100vh',
48
+ overflow: 'hidden',
49
+ display: 'flex',
50
+ flexDirection: 'column',
51
+ justifyContent: 'stretch',
52
+ gap: 'sm',
53
+ paddingTop: 20,
54
+ paddingLeft: 16,
55
+ paddingRight: 16,
56
+ paddingBottom: 8,
57
+ background: '[transparent]',
58
+ // backgroundColor: {
59
+ // _dark: `[rgb(34 34 34 / 0.95)]`,
60
+ // _light: `[rgb(255 255 255/ 0.95)]`,
61
+ // },
62
+ })
63
+
64
+ const selectIsOpened = (s: SearchActorSnapshot) => !s.matches('inactive')
65
+
66
+ export const Search = memo<{ searchActorRef: SearchActorRef }>(({ searchActorRef }) => {
67
+ const isOpened = useSelector(searchActorRef, selectIsOpened)
68
+
69
+ const openSearch = () => {
70
+ searchActorRef.send({ type: 'open' })
71
+ }
72
+
73
+ const sendClose = () => {
74
+ searchActorRef.send({ type: 'close' })
75
+ }
76
+
77
+ const afterCloseCbRef = useRef<(() => void)>(null)
78
+ const close = useCallbackRef((cb?: () => void) => {
79
+ afterCloseCbRef.current = cb ?? null
80
+ sendClose()
81
+ })
82
+ const onExitComplete = useCallbackRef(() => {
83
+ if (afterCloseCbRef.current) {
84
+ afterCloseCbRef.current()
85
+ afterCloseCbRef.current = null
86
+ }
87
+ })
88
+
89
+ useHotkeys([
90
+ ['mod+k', openSearch, {
91
+ preventDefault: true,
92
+ }],
93
+ ['mod+f', openSearch, {
94
+ preventDefault: true,
95
+ }],
96
+ ])
97
+
98
+ return (
99
+ <SearchActorContext
100
+ value={{
101
+ searchActorRef,
102
+ close,
103
+ }}>
104
+ <DiagramFeatures.Overlays>
105
+ <ErrorBoundary FallbackComponent={ErrorFallback} onReset={sendClose}>
106
+ <LayoutGroup>
107
+ <AnimatePresence onExitComplete={onExitComplete}>
108
+ {isOpened && (
109
+ <Overlay
110
+ fullscreen
111
+ withBackdrop={false}
112
+ backdrop={{
113
+ opacity: 0.9,
114
+ }}
115
+ classes={{
116
+ dialog,
117
+ body,
118
+ }}
119
+ openDelay={0}
120
+ onClose={close}
121
+ data-likec4-search="true"
122
+ >
123
+ <SearchOverlay close={close} searchActorRef={searchActorRef} />
124
+ </Overlay>
125
+ )}
126
+ </AnimatePresence>
127
+ </LayoutGroup>
128
+ </ErrorBoundary>
129
+ </DiagramFeatures.Overlays>
130
+ </SearchActorContext>
131
+ )
132
+ })
133
+
134
+ const scrollArea = css({
135
+ height: [
136
+ '100%',
137
+ '100cqh',
138
+ ],
139
+ '& .mantine-ScrollArea-viewport': {
140
+ minHeight: '100%',
141
+ '& > div': {
142
+ minHeight: '100%',
143
+ height: '100%',
144
+ },
145
+ },
146
+ })
147
+
148
+ const SearchOverlay = ({ close, searchActorRef }: { close: () => void; searchActorRef: SearchActorRef }) => {
149
+ const pickViewFor = usePickViewFor()
150
+
151
+ useTimeoutEffect(() => {
152
+ if (isTruthy(searchActorRef.getSnapshot().context.openedWithSearch)) {
153
+ focusToFirstFoundElement()
154
+ }
155
+ }, 150)
156
+
157
+ return (
158
+ <FocusTrap>
159
+ <Group
160
+ className={'group'}
161
+ wrap="nowrap"
162
+ onClick={e => {
163
+ e.stopPropagation()
164
+ moveFocusToSearchInput()
165
+ }}>
166
+ <VStack flex={1} px={'sm'}>
167
+ <LikeC4SearchInput />
168
+ <SearchByTags />
169
+ </VStack>
170
+ {
171
+ /* <Box
172
+ css={{
173
+ alignSelf: 'flex-start',
174
+ flex: '0 0 auto',
175
+ display: 'flex',
176
+ alignItems: 'center',
177
+ justifyContent: 'center',
178
+ minHeight: 50,
179
+ }}>
180
+ <ActionIcon
181
+ size={'lg'}
182
+ variant="default"
183
+ onClick={(e) => {
184
+ e.stopPropagation()
185
+ close()
186
+ }}>
187
+ <IconX />
188
+ </ActionIcon>
189
+ </Box> */
190
+ }
191
+ </Group>
192
+ <Grid>
193
+ <GridCol span={6}>
194
+ <Title component={'div'} order={6} c="dimmed" pl="sm">Elements</Title>
195
+ </GridCol>
196
+ <GridCol span={6}>
197
+ <Title component={'div'} order={6} c="dimmed" pl="sm">Views</Title>
198
+ </GridCol>
199
+ </Grid>
200
+ <Grid
201
+ className={css({
202
+ containerName: 'likec4-search-elements',
203
+ containerType: 'size',
204
+ overflow: 'hidden',
205
+ flexGrow: 1,
206
+ })}>
207
+ <GridCol span={6}>
208
+ <ScrollArea
209
+ type="scroll"
210
+ className={scrollArea}
211
+ pr="xs"
212
+ scrollbars="y">
213
+ <AnimatePresence>
214
+ <LayoutGroup id="likec4-search-elements">
215
+ <ElementsColumn />
216
+ </LayoutGroup>
217
+ </AnimatePresence>
218
+ </ScrollArea>
219
+ </GridCol>
220
+ <GridCol span={6}>
221
+ <ScrollArea
222
+ type="scroll"
223
+ className={scrollArea}
224
+ pr="xs"
225
+ scrollbars="y">
226
+ <AnimatePresence>
227
+ <LayoutGroup id="likec4-search-views">
228
+ <ViewsColumn />
229
+ </LayoutGroup>
230
+ </AnimatePresence>
231
+ </ScrollArea>
232
+ </GridCol>
233
+ </Grid>
234
+ {pickViewFor && <PickView elementFqn={pickViewFor} />}
235
+ </FocusTrap>
236
+ )
237
+ }
@@ -14,7 +14,6 @@ export const treeRoot = css(
14
14
  containerName: 'likec4-tree',
15
15
  }),
16
16
  {
17
- overflow: 'hidden',
18
17
  containerType: 'inline-size',
19
18
  height: '100%',
20
19
  },
@@ -65,40 +64,12 @@ export const elementId = css({
65
64
  },
66
65
  })
67
66
 
68
- // const iconSizeVar = `var(${iconSize}, 32px)`
69
67
  export const elementIcon = css({
70
68
  ['--likec4-icon-size']: '24px',
71
69
  [whenContainerIsNarrow]: {
72
70
  ['--likec4-icon-size']: '18px',
73
71
  },
74
72
  })
75
- // flex: `0 0 ${iconSizeVar}`,
76
- // height: iconSizeVar,
77
- // width: iconSizeVar,
78
- // display: 'flex',
79
- // alignItems: 'center',
80
- // justifyContent: 'center',
81
- // alignSelf: 'flex-start',
82
- // marginTop: 4,
83
- // [`& svg, & img`]: {
84
- // width: '100%',
85
- // height: 'auto',
86
- // maxHeight: '100%',
87
- // pointerEvents: 'none',
88
- // },
89
- // [`& img`]: {
90
- // objectFit: 'contain',
91
- // },
92
- // '&.likec4-shape-icon svg': {
93
- // color: `[var(${iconColor})]`,
94
- // width: '90%',
95
- // strokeWidth: 1.5,
96
- // },
97
- // [iconSize]: '24px',
98
- // [whenContainerIsNarrow]: {
99
- // [iconSize]: '18px',
100
- // },
101
- // })
102
73
 
103
74
  export const elementViewsCount = css({
104
75
  flex: 0,
@@ -1,11 +1,11 @@
1
1
  import {
2
- type Fqn,
3
- type LikeC4Model,
4
2
  ifilter,
5
3
  isAncestor,
6
4
  nameFromFqn,
7
5
  sortParentsFirst,
8
6
  } from '@likec4/core'
7
+ import type { LikeC4Model } from '@likec4/core/model'
8
+ import type { Fqn } from '@likec4/core/types'
9
9
  import { cx, cx as clsx } from '@likec4/styles/css'
10
10
  import {
11
11
  type RenderTreeNodePayload,
@@ -22,14 +22,15 @@ import {
22
22
  import { useCallbackRef } from '@mantine/hooks'
23
23
  import { IconChevronRight } from '@tabler/icons-react'
24
24
  import * as m from 'motion/react-m'
25
- import { type KeyboardEventHandler, useCallback, useEffect, useMemo } from 'react'
26
- import { first, isEmpty, only, partition, pipe, reduce } from 'remeda'
27
- import { IconOrShapeRenderer } from '../../../context/IconRenderer'
28
- import { sortByLabel } from '../../../likec4model/useLikeC4ElementsTree'
29
- import { useLikeC4Model } from '../../../likec4model/useLikeC4Model'
25
+ import { type KeyboardEventHandler, memo, useCallback, useEffect, useMemo } from 'react'
26
+ import { first, isEmpty, only, pipe, reduce } from 'remeda'
27
+ import { IconOrShapeRenderer } from '../../context/IconRenderer'
28
+ import { useDiagram } from '../../hooks/useDiagram'
29
+ import { sortByLabel } from '../../likec4model/useLikeC4ElementsTree'
30
+ import { useLikeC4Model } from '../../likec4model/useLikeC4Model'
31
+ import { useNormalizedSearch, useSearchActor } from '../hooks'
30
32
  import { buttonsva } from './_shared.css'
31
33
  import * as styles from './ElementsColumn.css'
32
- import { setPickView, useCloseSearchAndNavigateTo, useNormalizedSearch } from './state'
33
34
  import { centerY, moveFocusToSearchInput, stopAndPrevent } from './utils'
34
35
  import { NothingFound } from './ViewsColum'
35
36
 
@@ -56,14 +57,13 @@ function buildNode(
56
57
 
57
58
  const btn = buttonsva()
58
59
 
59
- export function ElementsColumn() {
60
+ export const ElementsColumn = memo(() => {
61
+ const model = useLikeC4Model()
60
62
  const search = useNormalizedSearch()
61
- const model = useLikeC4Model(true)
62
-
63
63
  const data = useMemo(() => {
64
64
  const searchTerms = search.split('.')
65
65
  let elements
66
- if (isEmpty(search) || search === 'kind:') {
66
+ if (isEmpty(searchTerms) || searchTerms[0] === 'kind:') {
67
67
  elements = model.elements()
68
68
  } else {
69
69
  elements = ifilter(model.elements(), element => {
@@ -120,7 +120,7 @@ export function ElementsColumn() {
120
120
  }
121
121
 
122
122
  return <ElementsTree data={data} handleClick={handleClick} />
123
- }
123
+ })
124
124
 
125
125
  const setHoveredNode = () => {}
126
126
 
@@ -254,6 +254,7 @@ function ElementTreeNode(
254
254
  component={m.button}
255
255
  layout
256
256
  tabIndex={-1}
257
+ data-value={element.id}
257
258
  className={clsx(btn.root, 'group', 'likec4-element-button')}
258
259
  {...views.length > 0 && {
259
260
  onClick: (e) => {
@@ -297,7 +298,9 @@ function ElementTreeNode(
297
298
  }
298
299
 
299
300
  function useHandleElementSelection() {
300
- const navigateTo = useCloseSearchAndNavigateTo()
301
+ const diagram = useDiagram()
302
+ const { searchActorRef } = useSearchActor()
303
+ // const naviconst { searchActorRef } = useSearchActor(gateTo = useCloseSearchAndNavigateTo()
301
304
 
302
305
  return useCallback((element: LikeC4Model.Element) => {
303
306
  const views = [...element.views()]
@@ -306,14 +309,13 @@ function useHandleElementSelection() {
306
309
  }
307
310
  const singleView = only(views)
308
311
  if (singleView) {
309
- navigateTo(singleView.id, element.id)
312
+ if (singleView.id === diagram.currentView.id) {
313
+ searchActorRef.send({ type: 'close' })
314
+ } else {
315
+ diagram.navigateTo(singleView.id)
316
+ }
310
317
  return
311
318
  }
312
- const [scoped, others] = partition(views, v => v.viewOf?.id === element.id)
313
- setPickView({
314
- elementFqn: element.id,
315
- scoped,
316
- others,
317
- })
318
- }, [setPickView, navigateTo])
319
+ searchActorRef.send({ type: 'pickview.open', elementFqn: element.id })
320
+ }, [])
319
321
  }
@@ -0,0 +1,140 @@
1
+ import type { LikeC4ViewModel } from '@likec4/core/model'
2
+ import type { Fqn } from '@likec4/core/types'
3
+ import { ActionIcon, FocusTrap, Group, ScrollAreaAutosize, Stack, Title } from '@mantine/core'
4
+ import { useWindowEvent } from '@mantine/hooks'
5
+ import { IconX } from '@tabler/icons-react'
6
+ import * as m from 'motion/react-m'
7
+ import { useLikeC4Model } from '../../likec4model'
8
+ import { useSearchActor } from '../hooks'
9
+ import * as styles from './styles.css'
10
+ import { ViewButton } from './ViewsColum'
11
+
12
+ export function PickView({ elementFqn }: { elementFqn: Fqn }) {
13
+ const { searchActorRef } = useSearchActor()
14
+ const element = useLikeC4Model().element(elementFqn)
15
+ // const pickview = usePickView()
16
+ // const navigateTo = useCloseSearchAndNavigateTo()
17
+ // const focusTrapRef = useFocusTrap(!!pickview)
18
+ // useFocusReturn({
19
+ // opened: !!pickview,
20
+ // })
21
+ const scoped = [] as LikeC4ViewModel[]
22
+ const others = [] as LikeC4ViewModel[]
23
+
24
+ for (const view of element.views()) {
25
+ if (view.viewOf === element) {
26
+ scoped.push(view)
27
+ } else {
28
+ others.push(view)
29
+ }
30
+ }
31
+
32
+ const closePickView = () => {
33
+ searchActorRef.send({ type: 'pickview.close' })
34
+ }
35
+
36
+ useWindowEvent(
37
+ 'keydown',
38
+ (event) => {
39
+ try {
40
+ if (event.key === 'Escape') {
41
+ event.stopPropagation()
42
+ event.preventDefault()
43
+ closePickView()
44
+ }
45
+ } catch (e) {
46
+ console.warn(e)
47
+ }
48
+ },
49
+ {
50
+ capture: true,
51
+ },
52
+ )
53
+
54
+ return (
55
+ <>
56
+ <m.div
57
+ key="pickview-backdrop"
58
+ className={styles.pickviewBackdrop}
59
+ onClick={e => {
60
+ e.stopPropagation()
61
+ closePickView()
62
+ }}>
63
+ </m.div>
64
+ <m.div
65
+ key="pickview"
66
+ initial={{
67
+ opacity: 0,
68
+ scale: 0.95,
69
+ originY: 0,
70
+ translateX: '-50%',
71
+ translateY: -20,
72
+ }}
73
+ animate={{
74
+ opacity: 1,
75
+ scale: 1,
76
+ translateY: 0,
77
+ }}
78
+ exit={{
79
+ opacity: 0,
80
+ scale: 0.98,
81
+ translateY: -20,
82
+ transition: {
83
+ duration: 0.1,
84
+ },
85
+ }}
86
+ className={styles.pickview}
87
+ data-likec4-search-views>
88
+ <Group px="sm" py="md" justify="space-between">
89
+ <Title order={2} lh={1}>Select view</Title>
90
+ <ActionIcon
91
+ size={'md'}
92
+ variant="default"
93
+ onClick={(e) => {
94
+ e.stopPropagation()
95
+ closePickView()
96
+ }}>
97
+ <IconX />
98
+ </ActionIcon>
99
+ </Group>
100
+ <FocusTrap>
101
+ <ScrollAreaAutosize mah={'calc(100vh - 8rem - 50px)'} type="never">
102
+ {scoped.length > 0 && (
103
+ <Stack gap={'sm'} px={'sm'} className={styles.pickviewGroup}>
104
+ <Title order={6} c={'dimmed'}>scoped views of the element</Title>
105
+ {scoped.map((view, i) => (
106
+ <ViewButton
107
+ key={view.id}
108
+ view={view}
109
+ search={''}
110
+ loop
111
+ mod={{
112
+ autofocus: i === 0,
113
+ }}
114
+ />
115
+ ))}
116
+ </Stack>
117
+ )}
118
+
119
+ {others.length > 0 && (
120
+ <Stack gap={'sm'} px={'sm'} className={styles.pickviewGroup}>
121
+ <Title order={6} c={'dimmed'}>views including this element</Title>
122
+ {others.map((view, i) => (
123
+ <ViewButton
124
+ key={view.id}
125
+ view={view}
126
+ search={''}
127
+ loop
128
+ mod={{
129
+ autofocus: i === 0 && scoped.length === 0,
130
+ }}
131
+ />
132
+ ))}
133
+ </Stack>
134
+ )}
135
+ </ScrollAreaAutosize>
136
+ </FocusTrap>
137
+ </m.div>
138
+ </>
139
+ )
140
+ }
@@ -0,0 +1,109 @@
1
+ import { css } from '@likec4/styles/css'
2
+ import { HStack } from '@likec4/styles/jsx'
3
+ import { Button } from '@mantine/core'
4
+ import { IconX } from '@tabler/icons-react'
5
+ import { ElementTag } from '../../base/primitives'
6
+ import { useLikeC4Model } from '../../likec4model/useLikeC4Model'
7
+ import { useNormalizedSearch, useUpdateSearch } from '../hooks'
8
+ import { focusToFirstFoundElement, moveFocusToSearchInput } from './utils'
9
+
10
+ export function SearchByTags() {
11
+ let tags = useLikeC4Model().tagsSortedByUsage
12
+ let setSearch = useUpdateSearch()
13
+ let search = useNormalizedSearch()
14
+ let countBefore = tags.length
15
+ if (search.startsWith('#')) {
16
+ const searchTag = search.slice(1)
17
+ tags = tags.filter(({ tag }) => tag.toLocaleLowerCase().includes(searchTag))
18
+ }
19
+ if (tags.length === 0) {
20
+ return null
21
+ }
22
+
23
+ const isFiltered = tags.length !== countBefore
24
+
25
+ return (
26
+ <HStack
27
+ css={{
28
+ gap: 'md',
29
+ paddingLeft: 48,
30
+ flexWrap: 'nowrap',
31
+ }}
32
+ >
33
+ <HStack
34
+ css={{
35
+ gap: 6,
36
+ flexWrap: 'wrap',
37
+ opacity: isFiltered ? 1 : .3,
38
+ grayscale: isFiltered ? 0 : .9,
39
+ filter: 'auto',
40
+ transition: 'fast',
41
+ _groupHover: {
42
+ opacity: 1,
43
+ grayscale: 0,
44
+ },
45
+ _groupFocusWithin: {
46
+ opacity: 1,
47
+ grayscale: 0,
48
+ },
49
+ }}
50
+ >
51
+ {tags.map(({ tag }) => (
52
+ // <Pill
53
+ // key={tag}
54
+ // data-likec4-tag={tag}
55
+ // className={cx(
56
+ // likec4tag(),
57
+ // css({
58
+ // minWidth: 'unset',
59
+ // cursor: 'pointer',
60
+ // }),
61
+ // )}
62
+ // onClick={(e) => {
63
+ // e.stopPropagation()
64
+ // setSearch(`#${tag}`)
65
+ // }}
66
+ // onRemove={() => {
67
+ // setSearch('#')
68
+ // moveFocusToSearchInput()
69
+ // }}
70
+ // withRemoveButton={tag === `${search.slice(1)}`}
71
+ // >
72
+ // <span style={{ opacity: 0.7, fontSize: '1.05em' }}>#</span>
73
+ // {tag}
74
+ // </Pill>
75
+ <ElementTag
76
+ key={tag}
77
+ tag={tag}
78
+ className={css({
79
+ userSelect: 'none',
80
+ cursor: 'pointer',
81
+ })}
82
+ onClick={(e) => {
83
+ e.stopPropagation()
84
+ setSearch(`#${tag}`)
85
+ // Let react to display filtered elements
86
+ setTimeout(() => {
87
+ focusToFirstFoundElement()
88
+ }, 350)
89
+ }}
90
+ />
91
+ ))}
92
+ </HStack>
93
+ {isFiltered && (
94
+ <Button
95
+ size="compact-xs"
96
+ variant="light"
97
+ onClick={(e) => {
98
+ e.stopPropagation()
99
+ setSearch('')
100
+ moveFocusToSearchInput()
101
+ }}
102
+ rightSection={<IconX size={14} />}
103
+ >
104
+ Clear
105
+ </Button>
106
+ )}
107
+ </HStack>
108
+ )
109
+ }