@likec4/diagram 1.36.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likec4/diagram",
3
- "version": "1.36.0",
3
+ "version": "1.36.1",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -87,8 +87,8 @@
87
87
  "remeda": "^2.23.1",
88
88
  "type-fest": "^4.41.0",
89
89
  "xstate": "^5.20.1",
90
- "@likec4/core": "1.36.0",
91
- "@likec4/styles": "1.36.0"
90
+ "@likec4/core": "1.36.1",
91
+ "@likec4/styles": "1.36.1"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "@pandacss/dev": "^0.54.0",
@@ -118,7 +118,7 @@
118
118
  "vite-plugin-dts": "^4.5.4",
119
119
  "vitest": "3.2.4",
120
120
  "wireit": "0.14.12",
121
- "@likec4/tsconfig": "1.36.0"
121
+ "@likec4/tsconfig": "1.36.1"
122
122
  },
123
123
  "scripts": {
124
124
  "typecheck": "tsc --build --verbose",
@@ -2,6 +2,7 @@ import { memo } from 'react'
2
2
  import { useEnabledFeatures } from '../context'
3
3
  import { useOverlaysActorRef } from '../hooks/useOverlaysActor'
4
4
  import { useSearchActorRef } from '../hooks/useSearchActor'
5
+ import { EnsureCurrentViewModel } from '../likec4model/LikeC4ModelContext'
5
6
  import { NavigationPanel } from '../navigationpanel'
6
7
  import { Overlays } from '../overlays/Overlays'
7
8
  import { Search } from '../search/Search'
@@ -15,13 +16,18 @@ export const DiagramUI = memo(() => {
15
16
  enableDynamicViewWalkthrough,
16
17
  enableSearch,
17
18
  } = useEnabledFeatures()
18
-
19
19
  const overlaysActorRef = useOverlaysActorRef()
20
20
  const searchActorRef = useSearchActorRef()
21
21
 
22
22
  return (
23
23
  <>
24
- {enableControls === 'next' ? <NavigationPanel /> : <Controls />}
24
+ {enableControls === 'next'
25
+ ? (
26
+ <EnsureCurrentViewModel>
27
+ <NavigationPanel />
28
+ </EnsureCurrentViewModel>
29
+ )
30
+ : <Controls />}
25
31
  {overlaysActorRef && <Overlays overlaysActorRef={overlaysActorRef} />}
26
32
  {enableNotations && <NotationPanel />}
27
33
  {enableControls !== 'next' && (
@@ -1,4 +1,3 @@
1
- import { RichText } from '@likec4/core/types'
2
1
  import { cx as clsx } from '@likec4/styles/css'
3
2
  import { Button, Card, CardSection, Group, Spoiler, Stack, Text } from '@mantine/core'
4
3
  import { useLocalStorage } from '@mantine/hooks'
@@ -7,7 +6,7 @@ import { AnimatePresence, m } from 'motion/react'
7
6
  import { MarkdownBlock } from '../../../base/primitives'
8
7
  import { Link } from '../../../components/Link'
9
8
  import { useDiagramContext } from '../../../hooks/useDiagram'
10
- import { useCurrentViewModel } from '../../../likec4model'
9
+ import { useOptionalCurrentViewModel } from '../../../likec4model/useCurrentViewModel'
11
10
  import type { DiagramContext } from '../../../state/types'
12
11
  import * as styles from './DiagramTitlePanel.css'
13
12
 
@@ -22,13 +21,13 @@ function selector(context: DiagramContext) {
22
21
  }
23
22
 
24
23
  export function DiagramTitlePanel() {
25
- const view = useCurrentViewModel()
24
+ const view = useOptionalCurrentViewModel()
26
25
  const { isNotActiveWalkthrough } = useDiagramContext(selector)
27
26
  const [isCollapsed, setCollapsed] = useLocalStorage({
28
27
  key: 'diagram-title-webview-collapsed',
29
28
  defaultValue: false,
30
29
  })
31
- const title = view.title ?? 'untitled'
30
+ const title = view?.title ?? 'untitled'
32
31
  const toggle = () => setCollapsed(v => !v)
33
32
 
34
33
  return (
@@ -49,7 +48,7 @@ export function DiagramTitlePanel() {
49
48
  </div>
50
49
  </ViewportPortal> */
51
50
  }
52
- {isNotActiveWalkthrough && (
51
+ {view && isNotActiveWalkthrough && (
53
52
  <m.div
54
53
  initial={{ opacity: 0.05, scale: 0.7 }}
55
54
  animate={{ opacity: 1, scale: 1 }}
@@ -1,8 +1,16 @@
1
1
  import type { LikeC4Model, LikeC4ViewModel } from '@likec4/core/model'
2
2
  import type { aux, DiagramView } from '@likec4/core/types'
3
- import { createContext } from 'react'
3
+ import { type PropsWithChildren, createContext, useContext } from 'react'
4
4
 
5
5
  export const LikeC4ModelContext = createContext<LikeC4Model<any> | null>(null)
6
6
 
7
7
  export type CurrentViewModel = LikeC4ViewModel<aux.UnknownLayouted, DiagramView<aux.UnknownLayouted>>
8
8
  export const CurrentViewModelContext = createContext<CurrentViewModel | null>(null)
9
+
10
+ export function EnsureCurrentViewModel({ children }: PropsWithChildren) {
11
+ const viewmodel = useContext(CurrentViewModelContext)
12
+ if (!viewmodel) {
13
+ return null
14
+ }
15
+ return <>{children}</>
16
+ }
@@ -1,6 +1,10 @@
1
1
  import { useContext } from 'react'
2
2
  import { type CurrentViewModel, CurrentViewModelContext } from './LikeC4ModelContext'
3
3
 
4
+ export function useOptionalCurrentViewModel(): CurrentViewModel | null {
5
+ return useContext(CurrentViewModelContext)
6
+ }
7
+
4
8
  export function useCurrentViewModel(): CurrentViewModel {
5
9
  const vm = useContext(CurrentViewModelContext)
6
10
  if (!vm) {
@@ -21,7 +21,7 @@ export const OpenSource = () => {
21
21
  e.stopPropagation()
22
22
  onOpenSource?.({ view: viewId })
23
23
  }}
24
- children={<IconFileSymlink stroke={1.5} style={{ width: '65%' }} />}
24
+ children={<IconFileSymlink style={{ width: '60%', height: '60%' }} />}
25
25
  />
26
26
  </Tooltip>
27
27
  )
@@ -1,4 +1,4 @@
1
- import type { DiagramView, WhereOperator } from '@likec4/core/types'
1
+ import type { DiagramView, ViewId, WhereOperator } from '@likec4/core/types'
2
2
  import { useCustomCompareEffect } from '@react-hookz/web'
3
3
  import { useActorRef, useSelector } from '@xstate/react'
4
4
  import { useStoreApi } from '@xyflow/react'
@@ -8,7 +8,6 @@ import { ErrorBoundary } from '../components/ErrorFallback'
8
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'
@@ -114,7 +113,7 @@ export function DiagramActorProvider({
114
113
  <DiagramActorContextProvider value={actorRef}>
115
114
  <DiagramFeatures overrides={toggledFeatures}>
116
115
  <ErrorBoundary>
117
- <CurrentViewModelProvider>
116
+ <CurrentViewModelProvider viewId={view.id}>
118
117
  {children}
119
118
  </CurrentViewModelProvider>
120
119
  </ErrorBoundary>
@@ -125,28 +124,30 @@ export function DiagramActorProvider({
125
124
 
126
125
  function CurrentViewModelProvider({
127
126
  children,
128
- }: PropsWithChildren) {
129
- const viewId = useCurrentViewId()
127
+ viewId,
128
+ }: PropsWithChildren<{
129
+ viewId: ViewId
130
+ }>) {
130
131
  const likec4model = useLikeC4Model()
131
- const [viewmodel, setViewmodel] = useState(() => likec4model.view(viewId))
132
+ const [viewmodel, setViewmodel] = useState(() => likec4model.findView(viewId))
132
133
 
133
134
  useEffect(() => {
134
135
  setViewmodel(current => {
135
136
  const nextviewmodel = likec4model.findView(viewId)
136
137
  if (!nextviewmodel) {
137
- 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}`, {
138
139
  currentViewModel: current,
139
140
  likec4model,
140
141
  })
141
142
  return current
142
143
  }
144
+ if (!nextviewmodel.isDiagram()) {
145
+ console.warn(`View "${viewId}" is not diagram.\nMake sure you have LikeC4ModelProvider with layouted model.`)
146
+ }
143
147
  return nextviewmodel
144
148
  })
145
149
  }, [likec4model, viewId])
146
150
 
147
- if (!viewmodel.isDiagram()) {
148
- console.warn(`View "${viewId}" is not diagram.\nMake sure you have LikeC4ModelProvider with layouted model.`)
149
- }
150
151
  return (
151
152
  <CurrentViewModelContext.Provider value={viewmodel}>
152
153
  {children}