@likec4/diagram 1.35.0 → 1.36.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 (224) hide show
  1. package/bundle/{chunk-C0Eg81Gj.js → chunk-DHvr-RGh.js} +323 -311
  2. package/bundle/custom.js +52 -52
  3. package/bundle/index.js +1594 -749
  4. package/dist/LikeC4Diagram.js +6 -6
  5. package/dist/LikeC4Diagram.props.d.ts +2 -3
  6. package/dist/LikeC4ModelProvider.d.ts +3 -3
  7. package/dist/LikeC4ProjectsProvider.d.ts +17 -0
  8. package/dist/LikeC4ProjectsProvider.js +22 -0
  9. package/dist/LikeC4Styles.d.ts +1 -0
  10. package/dist/LikeC4Styles.js +94 -0
  11. package/dist/StaticLikeC4Diagram.d.ts +3 -3
  12. package/dist/base/BaseXYFlow.js +23 -26
  13. package/dist/base/primitives/MarkdownBlock.d.ts +7 -1
  14. package/dist/base/primitives/MarkdownBlock.js +1 -1
  15. package/dist/base/primitives/compound/CompoundActionButton.js +2 -2
  16. package/dist/base/primitives/compound/CompoundDetailsButton.js +2 -2
  17. package/dist/base/primitives/compound/CompoundNodeContainer.css.js +4 -4
  18. package/dist/base/primitives/compound/CompoundNodeContainer.js +1 -4
  19. package/dist/base/primitives/compound/CompoundTitle.js +9 -8
  20. package/dist/base/primitives/compound/actionbtns.css.js +6 -6
  21. package/dist/base/primitives/edge/EdgeActionButton.js +2 -2
  22. package/dist/base/primitives/edge/EdgeContainer.js +4 -7
  23. package/dist/base/primitives/edge/EdgeLabel.css.d.ts +0 -22
  24. package/dist/base/primitives/edge/EdgeLabel.css.js +6 -84
  25. package/dist/base/primitives/edge/EdgeLabel.js +16 -6
  26. package/dist/base/primitives/edge/EdgeLabelContainer.js +1 -6
  27. package/dist/base/primitives/edge/EdgeMarkers.js +3 -3
  28. package/dist/base/primitives/edge/edge.css.d.ts +0 -2
  29. package/dist/base/primitives/edge/edge.css.js +1 -55
  30. package/dist/base/primitives/element/ElementActionButtons.js +2 -2
  31. package/dist/base/primitives/element/ElementDetailsButton.js +8 -7
  32. package/dist/base/primitives/element/ElementNodeContainer.css.js +4 -4
  33. package/dist/base/primitives/element/ElementNodeContainer.js +1 -4
  34. package/dist/base/primitives/element/ElementShape.css.js +11 -11
  35. package/dist/base/primitives/element/ElementTags.d.ts +1 -0
  36. package/dist/base/primitives/element/ElementTags.js +17 -14
  37. package/dist/bundle/LikeC4View.d.ts +1 -1
  38. package/dist/bundle/LikeC4View.js +7 -1
  39. package/dist/bundle/LikeC4View.props.d.ts +1 -2
  40. package/dist/bundle/ReactLikeC4.d.ts +1 -1
  41. package/dist/bundle/ViewNotFound.js +1 -1
  42. package/dist/bundle/index.d.ts +2 -1
  43. package/dist/bundle/index.js +1 -0
  44. package/dist/bundle/styles.css.js +1 -1
  45. package/dist/components/ErrorFallback.js +1 -1
  46. package/dist/components/GithubIcon.d.ts +2 -0
  47. package/dist/components/GithubIcon.js +17 -0
  48. package/dist/components/Link.d.ts +4 -3
  49. package/dist/components/Link.js +84 -87
  50. package/dist/components/NavigationLink.d.ts +2 -2
  51. package/dist/components/SearchControl.css.js +6 -5
  52. package/dist/context/DiagramEventHandlers.d.ts +6 -6
  53. package/dist/context/DiagramEventHandlers.js +4 -7
  54. package/dist/globals.css.js +3 -0
  55. package/dist/hooks/useXYFlow.d.ts +10 -10
  56. package/dist/index.d.ts +1 -0
  57. package/dist/index.js +1 -0
  58. package/dist/likec4diagram/DiagramUI.js +2 -1
  59. package/dist/likec4diagram/custom/edges/NotePopover.css.js +2 -2
  60. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +2 -2
  61. package/dist/likec4diagram/custom/edges/RelationshipEdge.js +1 -1
  62. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.css.js +7 -7
  63. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +3 -3
  64. package/dist/likec4diagram/custom/edges/edges.css.js +4 -4
  65. package/dist/likec4diagram/custom/index.d.ts +2 -2
  66. package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.js +2 -2
  67. package/dist/likec4diagram/ui/controls/styles.css.js +5 -5
  68. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +4 -4
  69. package/dist/likec4diagram/ui/notation/NotationPanel.css.js +11 -11
  70. package/dist/likec4diagram/ui/notation/NotationPanel.js +2 -5
  71. package/dist/likec4diagram/ui/walkthrough/DynamicViewWalkthrough.css.js +10 -10
  72. package/dist/likec4model/LikeC4ModelContext.d.ts +2 -1
  73. package/dist/likec4model/LikeC4ModelContext.js +10 -2
  74. package/dist/likec4model/LikeC4ProjectsContext.d.ts +7 -0
  75. package/dist/likec4model/LikeC4ProjectsContext.js +5 -0
  76. package/dist/likec4model/index.d.ts +1 -0
  77. package/dist/likec4model/useCurrentViewModel.d.ts +1 -0
  78. package/dist/likec4model/useCurrentViewModel.js +4 -1
  79. package/dist/likec4model/useLikeC4Project.d.ts +22 -0
  80. package/dist/likec4model/useLikeC4Project.js +23 -0
  81. package/dist/navigationpanel/NavigationPanel.js +15 -17
  82. package/dist/navigationpanel/NavigationPanelControls.js +34 -21
  83. package/dist/navigationpanel/NavigationPanelDropdown.js +33 -17
  84. package/dist/navigationpanel/_common.js +4 -1
  85. package/dist/navigationpanel/actor.d.ts +11 -15
  86. package/dist/navigationpanel/actor.js +14 -15
  87. package/dist/navigationpanel/controls/BurgerButton.js +5 -7
  88. package/dist/navigationpanel/controls/NavigationButtons.js +37 -24
  89. package/dist/navigationpanel/controls/OpenSource.js +1 -1
  90. package/dist/navigationpanel/controls/SearchControl.js +6 -4
  91. package/dist/navigationpanel/controls/ToggleReadonly.js +3 -3
  92. package/dist/navigationpanel/controls/ViewDetailsCard.d.ts +2 -0
  93. package/dist/navigationpanel/controls/ViewDetailsCard.js +232 -0
  94. package/dist/navigationpanel/controls/index.d.ts +1 -0
  95. package/dist/navigationpanel/dropdown/ProjectsMenu.d.ts +2 -0
  96. package/dist/navigationpanel/dropdown/ProjectsMenu.js +75 -0
  97. package/dist/navigationpanel/editorpanel/EditorPanel.js +3 -3
  98. package/dist/navigationpanel/editorpanel/ManualLayoutToolsButton.js +19 -20
  99. package/dist/navigationpanel/editorpanel/styles.js +5 -5
  100. package/dist/navigationpanel/hooks.d.ts +2 -2
  101. package/dist/navigationpanel/styles.css.js +0 -2
  102. package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +12 -7
  103. package/dist/node_modules/.pnpm/@tabler_icons-react@3.34.1_react@19.1.1/node_modules/@tabler/icons-react/dist/esm/icons/IconChevronDown.js +14 -0
  104. package/dist/node_modules/.pnpm/@tabler_icons-react@3.34.1_react@19.1.1/node_modules/@tabler/icons-react/dist/esm/icons/IconLink.js +14 -0
  105. package/dist/overlays/element-details/ElementDetailsCard.css.js +18 -17
  106. package/dist/overlays/element-details/ElementDetailsCard.js +8 -13
  107. package/dist/overlays/element-details/TabPanelDeployments.css.js +5 -4
  108. package/dist/overlays/element-details/TabPanelRelationships.css.js +7 -7
  109. package/dist/overlays/overlay/Overlay.css.d.ts +3 -3
  110. package/dist/overlays/overlay/Overlay.css.js +8 -7
  111. package/dist/overlays/relationship-details/SelectEdge.css.js +8 -8
  112. package/dist/overlays/relationships-browser/SelectElement.css.js +1 -1
  113. package/dist/search/Search.js +6 -6
  114. package/dist/search/components/ElementsColumn.css.js +5 -5
  115. package/dist/search/components/SearchByTags.js +3 -2
  116. package/dist/search/components/ViewsColum.js +1 -1
  117. package/dist/search/components/ViewsColumn.css.js +1 -1
  118. package/dist/search/components/_shared.css.js +3 -3
  119. package/dist/search/components/styles.css.js +5 -5
  120. package/dist/state/DiagramActorProvider.js +43 -25
  121. package/dist/state/diagram-machine.d.ts +29 -247
  122. package/dist/state/diagram-machine.js +16 -16
  123. package/dist/styles-min.css +1 -1
  124. package/dist/styles.css +1 -1
  125. package/dist/styles.css2.js +1 -1
  126. package/package.json +10 -8
  127. package/panda.buildinfo.json +254 -326
  128. package/src/LikeC4Diagram.props.ts +2 -2
  129. package/src/LikeC4Diagram.tsx +2 -2
  130. package/src/LikeC4ModelProvider.tsx +4 -4
  131. package/src/LikeC4ProjectsProvider.tsx +41 -0
  132. package/src/LikeC4Styles.tsx +107 -0
  133. package/src/StaticLikeC4Diagram.tsx +3 -3
  134. package/src/base/BaseXYFlow.tsx +24 -29
  135. package/src/base/primitives/MarkdownBlock.tsx +11 -3
  136. package/src/base/primitives/compound/CompoundActionButton.tsx +2 -2
  137. package/src/base/primitives/compound/CompoundDetailsButton.tsx +2 -2
  138. package/src/base/primitives/compound/CompoundNodeContainer.css.ts +4 -13
  139. package/src/base/primitives/compound/CompoundNodeContainer.tsx +0 -3
  140. package/src/base/primitives/compound/CompoundTitle.tsx +8 -8
  141. package/src/base/primitives/compound/actionbtns.css.ts +6 -6
  142. package/src/base/primitives/edge/EdgeActionButton.tsx +2 -2
  143. package/src/base/primitives/edge/EdgeContainer.tsx +3 -6
  144. package/src/base/primitives/edge/EdgeLabel.css.ts +4 -83
  145. package/src/base/primitives/edge/EdgeLabel.tsx +16 -10
  146. package/src/base/primitives/edge/EdgeLabelContainer.tsx +1 -6
  147. package/src/base/primitives/edge/EdgeMarkers.tsx +3 -3
  148. package/src/base/primitives/edge/edge.css.ts +0 -60
  149. package/src/base/primitives/element/ElementActionButtons.tsx +2 -2
  150. package/src/base/primitives/element/ElementDetailsButton.tsx +7 -7
  151. package/src/base/primitives/element/ElementNodeContainer.css.ts +4 -4
  152. package/src/base/primitives/element/ElementNodeContainer.tsx +0 -3
  153. package/src/base/primitives/element/ElementShape.css.ts +11 -11
  154. package/src/base/primitives/element/ElementTags.tsx +17 -14
  155. package/src/bundle/LikeC4View.props.ts +1 -2
  156. package/src/bundle/LikeC4View.tsx +10 -3
  157. package/src/bundle/ReactLikeC4.tsx +1 -2
  158. package/src/bundle/ViewNotFound.tsx +1 -1
  159. package/src/bundle/index.ts +2 -1
  160. package/src/bundle/styles.css.ts +1 -1
  161. package/src/components/ErrorFallback.tsx +1 -1
  162. package/src/components/GithubIcon.tsx +16 -0
  163. package/src/components/Link.tsx +102 -113
  164. package/src/components/NavigationLink.tsx +2 -1
  165. package/src/components/SearchControl.css.ts +5 -5
  166. package/src/context/DiagramEventHandlers.tsx +12 -12
  167. package/src/globals.css +71 -0
  168. package/src/index.ts +5 -0
  169. package/src/likec4diagram/DiagramUI.tsx +8 -2
  170. package/src/likec4diagram/custom/edges/NotePopover.css.ts +2 -2
  171. package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +1 -1
  172. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.css.ts +7 -7
  173. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +3 -3
  174. package/src/likec4diagram/custom/edges/edges.css.ts +4 -4
  175. package/src/likec4diagram/custom/nodes/toolbar/CompoundToolbar.tsx +2 -2
  176. package/src/likec4diagram/ui/controls/styles.css.ts +5 -5
  177. package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +4 -5
  178. package/src/likec4diagram/ui/notation/NotationPanel.css.ts +11 -11
  179. package/src/likec4diagram/ui/notation/NotationPanel.tsx +1 -4
  180. package/src/likec4diagram/ui/walkthrough/DynamicViewWalkthrough.css.ts +10 -10
  181. package/src/likec4model/{LikeC4ModelContext.ts → LikeC4ModelContext.tsx} +9 -1
  182. package/src/likec4model/LikeC4ProjectsContext.ts +9 -0
  183. package/src/likec4model/index.ts +8 -0
  184. package/src/likec4model/useCurrentViewModel.ts +4 -0
  185. package/src/likec4model/useLikeC4Project.ts +61 -0
  186. package/src/navigationpanel/NavigationPanel.tsx +16 -17
  187. package/src/navigationpanel/NavigationPanelControls.tsx +24 -46
  188. package/src/navigationpanel/NavigationPanelDropdown.tsx +32 -16
  189. package/src/navigationpanel/_common.tsx +4 -1
  190. package/src/navigationpanel/actor.ts +14 -15
  191. package/src/navigationpanel/controls/BurgerButton.tsx +5 -7
  192. package/src/navigationpanel/controls/NavigationButtons.tsx +9 -1
  193. package/src/navigationpanel/controls/OpenSource.tsx +1 -1
  194. package/src/navigationpanel/controls/SearchControl.tsx +6 -4
  195. package/src/navigationpanel/controls/ToggleReadonly.tsx +3 -3
  196. package/src/navigationpanel/controls/ViewDetailsCard.tsx +244 -0
  197. package/src/navigationpanel/controls/index.ts +1 -0
  198. package/src/navigationpanel/dropdown/ProjectsMenu.tsx +74 -0
  199. package/src/navigationpanel/editorpanel/EditorPanel.tsx +3 -3
  200. package/src/navigationpanel/editorpanel/ManualLayoutToolsButton.tsx +19 -22
  201. package/src/navigationpanel/editorpanel/styles.ts +5 -5
  202. package/src/navigationpanel/hooks.tsx +2 -2
  203. package/src/navigationpanel/styles.css.ts +0 -2
  204. package/src/navigationpanel/walkthrough/ActiveWalkthroughControls.tsx +9 -4
  205. package/src/overlays/element-details/ElementDetailsCard.css.ts +17 -17
  206. package/src/overlays/element-details/ElementDetailsCard.tsx +8 -13
  207. package/src/overlays/element-details/TabPanelDeployments.css.ts +4 -4
  208. package/src/overlays/element-details/TabPanelRelationships.css.ts +7 -7
  209. package/src/overlays/overlay/Overlay.css.ts +7 -7
  210. package/src/overlays/relationship-details/SelectEdge.css.ts +8 -8
  211. package/src/overlays/relationships-browser/SelectElement.css.ts +1 -1
  212. package/src/search/Search.tsx +6 -6
  213. package/src/search/components/ElementsColumn.css.ts +5 -5
  214. package/src/search/components/SearchByTags.tsx +2 -2
  215. package/src/search/components/ViewsColum.tsx +1 -1
  216. package/src/search/components/ViewsColumn.css.ts +1 -1
  217. package/src/search/components/_shared.css.ts +3 -3
  218. package/src/search/components/styles.css.ts +5 -5
  219. package/src/state/DiagramActorProvider.tsx +56 -30
  220. package/src/state/diagram-machine.ts +22 -16
  221. package/dist/LikeC4CustomColors.d.ts +0 -2
  222. package/dist/LikeC4CustomColors.js +0 -45
  223. package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +0 -45
  224. package/src/LikeC4CustomColors.tsx +0 -85
@@ -1,14 +1,13 @@
1
- import type { DiagramView, WhereOperator } from '@likec4/core/types'
2
- import { useCustomCompareEffect, useDeepCompareEffect } from '@react-hookz/web'
1
+ import type { DiagramView, ViewId, WhereOperator } from '@likec4/core/types'
2
+ import { useCustomCompareEffect } from '@react-hookz/web'
3
3
  import { useActorRef, useSelector } from '@xstate/react'
4
4
  import { useStoreApi } from '@xyflow/react'
5
5
  import { deepEqual, shallowEqual } from 'fast-equals'
6
6
  import { type PropsWithChildren, useEffect, useRef, useState } from 'react'
7
7
  import { ErrorBoundary } from '../components/ErrorFallback'
8
- import { useDiagramEventHandlersRef } from '../context/DiagramEventHandlers'
8
+ import { useDiagramEventHandlers } from '../context/DiagramEventHandlers'
9
9
  import { DiagramFeatures, useEnabledFeatures } from '../context/DiagramFeatures'
10
10
  import { DiagramActorContextProvider } from '../hooks/safeContext'
11
- import { useCurrentViewId } from '../hooks/useCurrentViewId'
12
11
  import type { ViewPadding } from '../LikeC4Diagram.props'
13
12
  import type { Types } from '../likec4diagram/types'
14
13
  import { useViewToNodesEdges } from '../likec4diagram/useViewToNodesEdges'
@@ -16,7 +15,7 @@ import { CurrentViewModelContext } from '../likec4model/LikeC4ModelContext'
16
15
  import { useLikeC4Model } from '../likec4model/useLikeC4Model'
17
16
  import { type DiagramMachine, diagramMachine } from './diagram-machine'
18
17
  import { syncManualLayoutActorLogic } from './syncManualLayoutActor'
19
- import type { DiagramActorSnapshot } from './types'
18
+ import type { DiagramActorRef, DiagramActorSnapshot } from './types'
20
19
 
21
20
  const selectToggledFeatures = (state: DiagramActorSnapshot) => {
22
21
  if (state.context.features.enableReadOnly || state.context.activeWalkthrough) {
@@ -44,28 +43,12 @@ export function DiagramActorProvider({
44
43
  nodesSelectable: boolean
45
44
  where: WhereOperator | null
46
45
  }>) {
47
- const handlersRef = useDiagramEventHandlersRef()
46
+ const { handlersRef } = useDiagramEventHandlers()
48
47
  const xystore = useStoreApi<Types.Node, Types.Edge>()
49
48
 
50
49
  const machineRef = useRef<DiagramMachine | null>(null)
51
50
  if (!machineRef.current) {
52
51
  machineRef.current = diagramMachine.provide({
53
- actions: {
54
- 'trigger:NavigateTo': ((_, { viewId }) => {
55
- // Slightly defer callback for better responsiveness
56
- setTimeout(() => {
57
- handlersRef.current.onNavigateTo?.(viewId)
58
- }, 40)
59
- }),
60
-
61
- 'trigger:OnChange': ((_, params) => {
62
- handlersRef.current.onChange?.(params)
63
- }),
64
-
65
- 'trigger:OpenSource': ((_, params) => {
66
- handlersRef.current.onOpenSource?.(params)
67
- }),
68
- },
69
52
  actors: {
70
53
  syncManualLayoutActorLogic: syncManualLayoutActorLogic.provide({
71
54
  actions: {
@@ -95,6 +78,8 @@ export function DiagramActorProvider({
95
78
  },
96
79
  )
97
80
 
81
+ useActorEventHandlers(actorRef)
82
+
98
83
  const features = useEnabledFeatures()
99
84
  useCustomCompareEffect(
100
85
  () => {
@@ -128,7 +113,7 @@ export function DiagramActorProvider({
128
113
  <DiagramActorContextProvider value={actorRef}>
129
114
  <DiagramFeatures overrides={toggledFeatures}>
130
115
  <ErrorBoundary>
131
- <CurrentViewModelProvider>
116
+ <CurrentViewModelProvider viewId={view.id}>
132
117
  {children}
133
118
  </CurrentViewModelProvider>
134
119
  </ErrorBoundary>
@@ -139,31 +124,72 @@ export function DiagramActorProvider({
139
124
 
140
125
  function CurrentViewModelProvider({
141
126
  children,
142
- }: PropsWithChildren) {
143
- const viewId = useCurrentViewId()
127
+ viewId,
128
+ }: PropsWithChildren<{
129
+ viewId: ViewId
130
+ }>) {
144
131
  const likec4model = useLikeC4Model()
145
- const [viewmodel, setViewmodel] = useState(() => likec4model.view(viewId))
132
+ const [viewmodel, setViewmodel] = useState(() => likec4model.findView(viewId))
146
133
 
147
134
  useEffect(() => {
148
135
  setViewmodel(current => {
149
136
  const nextviewmodel = likec4model.findView(viewId)
150
137
  if (!nextviewmodel) {
151
- console.error(`View "${viewId}" not found in likec4model, current viewmodel: ${current.id}`, {
138
+ console.error(`View "${viewId}" not found in likec4model, current viewmodel: ${current?.id}`, {
152
139
  currentViewModel: current,
153
140
  likec4model,
154
141
  })
155
142
  return current
156
143
  }
144
+ if (!nextviewmodel.isDiagram()) {
145
+ console.warn(`View "${viewId}" is not diagram.\nMake sure you have LikeC4ModelProvider with layouted model.`)
146
+ }
157
147
  return nextviewmodel
158
148
  })
159
149
  }, [likec4model, viewId])
160
150
 
161
- if (!viewmodel.isDiagram()) {
162
- console.warn(`View "${viewId}" is not diagram.\nMake sure you have LikeC4ModelProvider with layouted model.`)
163
- }
164
151
  return (
165
152
  <CurrentViewModelContext.Provider value={viewmodel}>
166
153
  {children}
167
154
  </CurrentViewModelContext.Provider>
168
155
  )
169
156
  }
157
+
158
+ function useActorEventHandlers(
159
+ actorRef: DiagramActorRef,
160
+ ) {
161
+ const {
162
+ onChange,
163
+ onNavigateTo,
164
+ onOpenSource,
165
+ } = useDiagramEventHandlers()
166
+
167
+ useEffect(() => {
168
+ if (!onChange) return
169
+ const subscription = actorRef.on('viewChange', ({ change }) => onChange({ change }))
170
+ return () => subscription.unsubscribe()
171
+ }, [actorRef, onChange])
172
+
173
+ useEffect(() => {
174
+ if (!onNavigateTo) return
175
+ let frame: number
176
+
177
+ const subscription = actorRef.on('navigateTo', ({ viewId }) => {
178
+ cancelAnimationFrame(frame)
179
+ // Slightly defer callback for better responsiveness
180
+ frame = requestAnimationFrame(() => {
181
+ onNavigateTo(viewId)
182
+ })
183
+ })
184
+ return () => {
185
+ cancelAnimationFrame(frame)
186
+ subscription.unsubscribe()
187
+ }
188
+ }, [actorRef, onNavigateTo])
189
+
190
+ useEffect(() => {
191
+ if (!onOpenSource) return
192
+ const subscription = actorRef.on('openSource', ({ params }) => onOpenSource(params))
193
+ return () => subscription.unsubscribe()
194
+ }, [actorRef, onOpenSource])
195
+ }
@@ -35,6 +35,7 @@ import {
35
35
  assertEvent,
36
36
  assign,
37
37
  cancel,
38
+ emit,
38
39
  enqueueActions,
39
40
  or,
40
41
  raise,
@@ -179,6 +180,11 @@ export type Events =
179
180
  | { type: 'tag.unhighlight' }
180
181
  | { type: 'toggle.feature'; feature: FeatureName; forceValue?: boolean }
181
182
 
183
+ export type EmittedEvents =
184
+ | { type: 'navigateTo'; viewId: ViewId }
185
+ | { type: 'viewChange'; change: ViewChange }
186
+ | { type: 'openSource'; params: OpenSourceParams }
187
+
182
188
  export type ActionArg = { context: Context; event: Events }
183
189
 
184
190
  // TODO: naming convention for actors
@@ -193,6 +199,7 @@ const _diagramMachine = setup({
193
199
  search: 'searchActorLogic'
194
200
  },
195
201
  events: {} as Events,
202
+ emitted: {} as EmittedEvents,
196
203
  },
197
204
  actors: {
198
205
  syncManualLayoutActorLogic,
@@ -241,14 +248,20 @@ const _diagramMachine = setup({
241
248
  },
242
249
  },
243
250
  actions: {
244
- 'trigger:NavigateTo': (_, _params: { viewId: ViewId }) => {
245
- // navigate to view
246
- },
247
- 'trigger:OnChange': (_, _params: { change: ViewChange }) => {
248
- // apply change
249
- },
250
- 'trigger:OpenSource': (_, _params: OpenSourceParams) => {
251
- },
251
+ 'trigger:NavigateTo': emit(({ context }) => ({
252
+ type: 'navigateTo',
253
+ viewId: nonNullable(context.lastOnNavigate, 'Invalid state, lastOnNavigate is null').toView,
254
+ })),
255
+
256
+ 'trigger:OnChange': emit((_, _params: { change: ViewChange }) => ({
257
+ type: 'viewChange',
258
+ change: _params.change,
259
+ })),
260
+
261
+ 'trigger:OpenSource': emit((_, _params: OpenSourceParams) => ({
262
+ type: 'openSource',
263
+ params: _params,
264
+ })),
252
265
 
253
266
  'assign lastClickedNode': assign(({ context, event }) => {
254
267
  assertEvent(event, 'xyflow.nodeClick')
@@ -1023,14 +1036,7 @@ const _diagramMachine = setup({
1023
1036
  'closeAllOverlays',
1024
1037
  'closeSearch',
1025
1038
  'stopSyncLayout',
1026
- enqueueActions(({ enqueue, context }) => {
1027
- enqueue({
1028
- type: 'trigger:NavigateTo',
1029
- params: {
1030
- viewId: nonNullable(context.lastOnNavigate, 'Invalid state, lastOnNavigate is null').toView,
1031
- },
1032
- })
1033
- }),
1039
+ 'trigger:NavigateTo',
1034
1040
  ],
1035
1041
  on: {
1036
1042
  'update.view': {
@@ -1,2 +0,0 @@
1
- import { MemoExoticComponent } from 'react';
2
- export declare const LikeC4CustomColors: MemoExoticComponent<() => import("react/jsx-runtime").JSX.Element | null>;
@@ -1,45 +0,0 @@
1
- import { jsx, Fragment } from 'react/jsx-runtime';
2
- import '@likec4/core';
3
- import { useMantineStyleNonce } from '@mantine/core';
4
- import { memo, useState } from 'react';
5
- import { isEmpty, entries } from 'remeda';
6
- import { useLikeC4Specification } from './likec4model/useLikeC4Model.js';
7
- import { useUpdateEffect } from './hooks/useUpdateEffect.js';
8
-
9
- function toStyle(name, colors) {
10
- const darken = (color) => `color-mix(in srgb, ${color} 80%, black)`;
11
- return `
12
- :where([data-likec4-color=${name}]) {
13
- --colors-likec4-palette-hi-contrast: ${colors.elements.hiContrast};
14
- --colors-likec4-palette-lo-contrast: ${colors.elements.loContrast};
15
- --colors-likec4-palette-fill: ${colors.elements.fill};
16
- --colors-likec4-palette-stroke: ${colors.elements.stroke};
17
- --colors-likec4-relation-stroke: ${colors.relationships.lineColor};
18
- --colors-likec4-relation-stroke-selected: color-mix(in srgb, ${colors.relationships.lineColor}, var(--colors-likec4-mix-color) 20%);
19
- --colors-likec4-relation-label: ${colors.relationships.labelColor};
20
- --colors-likec4-relation-label-bg: ${colors.relationships.labelBgColor};
21
- }
22
- :where(.likec4-compound-node[data-likec4-color=${name}]) {
23
- --colors-likec4-palette-fill: ${darken(colors.elements.fill)};
24
- --colors-likec4-palette-stroke: ${darken(colors.elements.stroke)};
25
- }
26
- `;
27
- }
28
- function generateCustomColorStyles(customColors) {
29
- return entries(customColors).map(([name, color]) => toStyle(name, color)).join("\n").trim();
30
- }
31
- const LikeC4CustomColors = memo(() => {
32
- const customColors = useLikeC4Specification().customColors ?? {};
33
- const [styles, setStyles] = useState(() => generateCustomColorStyles(customColors));
34
- useUpdateEffect(() => {
35
- setStyles(generateCustomColorStyles(customColors));
36
- }, [customColors]);
37
- const nonce = useMantineStyleNonce()?.();
38
- if (isEmpty(customColors)) {
39
- return null;
40
- }
41
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("style", { type: "text/css", dangerouslySetInnerHTML: { __html: styles }, nonce }) });
42
- });
43
- LikeC4CustomColors.displayName = "LikeC4CustomColors";
44
-
45
- export { LikeC4CustomColors };
@@ -1,45 +0,0 @@
1
- import { NodeProps } from '../../../base';
2
- import { RelationshipsBrowserTypes } from '../_types';
3
- import { MemoExoticComponent } from 'react';
4
- import { Dimmed } from '../../../base/types.Base';
5
- import { ElementStyle, Color, Any, ViewId, Fqn, RichTextOrEmpty, IconUrl } from '@likec4/core';
6
- import { Tags } from '@likec4/core/types/_aux';
7
- export declare const ElementNode: MemoExoticComponent<(props: NodeProps<{
8
- hovered?: boolean;
9
- dimmed?: Dimmed;
10
- width: number;
11
- height: number;
12
- style: ElementStyle;
13
- color: Color;
14
- title: string;
15
- shape: "rectangle" | "person" | "browser" | "mobile" | "cylinder" | "storage" | "queue";
16
- tags: Tags<Any>;
17
- technology: string | null | undefined;
18
- navigateTo: ViewId<string> | null | undefined;
19
- column: RelationshipsBrowserTypes.Column;
20
- fqn: Fqn;
21
- icon: string | null;
22
- ports: RelationshipsBrowserTypes.Ports;
23
- existsInCurrentView: boolean;
24
- description: RichTextOrEmpty;
25
- }, string>) => import("react/jsx-runtime").JSX.Element>;
26
- export declare const CompoundNode: MemoExoticComponent<(props: NodeProps<{
27
- hovered?: boolean;
28
- dimmed?: Dimmed;
29
- style: ElementStyle;
30
- color: Color;
31
- title: string;
32
- shape: "rectangle" | "person" | "browser" | "mobile" | "cylinder" | "storage" | "queue";
33
- column: RelationshipsBrowserTypes.Column;
34
- fqn: Fqn;
35
- depth: number;
36
- icon: IconUrl;
37
- ports: RelationshipsBrowserTypes.Ports;
38
- existsInCurrentView: boolean;
39
- }, string>) => import("react/jsx-runtime").JSX.Element>;
40
- export declare const EmptyNode: MemoExoticComponent<(props: NodeProps<RelationshipsBrowserTypes.EmptyNodeData, string>) => import("react/jsx-runtime").JSX.Element>;
41
- type ElementPortsProps = NodeProps<Pick<RelationshipsBrowserTypes.ElementNodeData, 'ports' | 'height'>>;
42
- export declare const ElementPorts: ({ data: { ports, height: h } }: ElementPortsProps) => import("react/jsx-runtime").JSX.Element;
43
- type CompoundPortsProps = NodeProps<Pick<RelationshipsBrowserTypes.CompoundNodeData, 'ports'>>;
44
- export declare const CompoundPorts: ({ data }: CompoundPortsProps) => import("react/jsx-runtime").JSX.Element;
45
- export {};
@@ -1,85 +0,0 @@
1
- import {
2
- type CustomColorDefinitions,
3
- type ElementThemeColorValues,
4
- type RelationshipThemeColorValues,
5
- type ThemeColorValues,
6
- nonexhaustive,
7
- } from '@likec4/core'
8
- import { useMantineStyleNonce } from '@mantine/core'
9
- import { memo, useState } from 'react'
10
- import { entries, isEmpty } from 'remeda'
11
- import { useUpdateEffect } from './hooks'
12
- import { useLikeC4Specification } from './likec4model/useLikeC4Model'
13
-
14
- interface LikeC4CustomColorsProperties {
15
- customColors: CustomColorDefinitions
16
- }
17
- function keyToCssVar(key: keyof RelationshipThemeColorValues | keyof ElementThemeColorValues): string {
18
- switch (key) {
19
- case 'lineColor':
20
- return 'line'
21
- case 'labelBgColor':
22
- return 'label-bg'
23
- case 'labelColor':
24
- return 'label'
25
- case 'fill':
26
- return 'fill'
27
- case 'stroke':
28
- return 'stroke'
29
- case 'hiContrast':
30
- return 'hi-contrast'
31
- case 'loContrast':
32
- return 'lo-contrast'
33
- default:
34
- nonexhaustive(key)
35
- }
36
- }
37
-
38
- function toStyle(name: String, colors: ThemeColorValues): String {
39
- const darken = (color: string) => `color-mix(in srgb, ${color} 80%, black)`
40
- return `
41
- :where([data-likec4-color=${name}]) {
42
- --colors-likec4-palette-hi-contrast: ${colors.elements.hiContrast};
43
- --colors-likec4-palette-lo-contrast: ${colors.elements.loContrast};
44
- --colors-likec4-palette-fill: ${colors.elements.fill};
45
- --colors-likec4-palette-stroke: ${colors.elements.stroke};
46
- --colors-likec4-relation-stroke: ${colors.relationships.lineColor};
47
- --colors-likec4-relation-stroke-selected: color-mix(in srgb, ${colors.relationships.lineColor}, var(--colors-likec4-mix-color) 20%);
48
- --colors-likec4-relation-label: ${colors.relationships.labelColor};
49
- --colors-likec4-relation-label-bg: ${colors.relationships.labelBgColor};
50
- }
51
- :where(.likec4-compound-node[data-likec4-color=${name}]) {
52
- --colors-likec4-palette-fill: ${darken(colors.elements.fill)};
53
- --colors-likec4-palette-stroke: ${darken(colors.elements.stroke)};
54
- }
55
- `
56
- }
57
-
58
- function generateCustomColorStyles(customColors: CustomColorDefinitions) {
59
- return entries(customColors)
60
- .map(([name, color]) => toStyle(name, color))
61
- .join('\n')
62
- .trim()
63
- }
64
-
65
- export const LikeC4CustomColors = memo(() => {
66
- const customColors = useLikeC4Specification().customColors ?? {}
67
- const [styles, setStyles] = useState(() => generateCustomColorStyles(customColors))
68
-
69
- useUpdateEffect(() => {
70
- setStyles(generateCustomColorStyles(customColors))
71
- }, [customColors])
72
-
73
- const nonce = useMantineStyleNonce()?.()
74
-
75
- if (isEmpty(customColors)) {
76
- return null
77
- }
78
-
79
- return (
80
- <>
81
- <style type="text/css" dangerouslySetInnerHTML={{ __html: styles }} nonce={nonce} />
82
- </>
83
- )
84
- })
85
- LikeC4CustomColors.displayName = 'LikeC4CustomColors'