@likec4/diagram 1.6.0 → 1.6.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.6.0",
3
+ "version": "1.6.1",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -48,12 +48,16 @@
48
48
  "clean": "run -T rimraf -v -g 'dist/*' .tsbuildinfo"
49
49
  },
50
50
  "dependencies": {
51
- "@likec4/core": "1.6.0",
51
+ "@lume/kiwi": "^0.4.3",
52
52
  "@react-hookz/web": "^24.0.4",
53
53
  "@tabler/icons-react": "^3.11.0",
54
54
  "@vanilla-extract/css": "^1.15.3",
55
55
  "@vanilla-extract/css-utils": "^0.1.4",
56
56
  "@vanilla-extract/dynamic": "^2.1.1",
57
+ "@xyflow/react": "12.0.3",
58
+ "@xyflow/system": "0.0.37",
59
+ "bezier-js": "^6.1.4",
60
+ "clsx": "^2.1.1",
57
61
  "d3-shape": "^3.2.0",
58
62
  "esm-env": "^1.0.0",
59
63
  "fast-equals": "^5.0.1",
@@ -62,14 +66,15 @@
62
66
  "zustand": "^4.5.4"
63
67
  },
64
68
  "peerDependencies": {
69
+ "@likec4/core": "1.6.1",
65
70
  "@mantine/core": "^7.11.2",
66
71
  "@mantine/hooks": "^7.11.2",
67
72
  "react": "^18.3.1",
68
73
  "react-dom": "^18.3.1"
69
74
  },
70
75
  "devDependencies": {
71
- "@likec4/tsconfig": "1.6.0",
72
- "@lume/kiwi": "^0.4.3",
76
+ "@likec4/core": "1.6.1",
77
+ "@likec4/tsconfig": "1.6.1",
73
78
  "@mantine/core": "7.11.2",
74
79
  "@mantine/hooks": "7.11.2",
75
80
  "@mantine/vanilla-extract": "7.11.2",
@@ -80,15 +85,10 @@
80
85
  "@types/react-dom": "^18.3.0",
81
86
  "@vanilla-extract/esbuild-plugin": "^2.3.8",
82
87
  "@vitejs/plugin-react": "^4.3.1",
83
- "@xyflow/react": "12.0.3",
84
- "@xyflow/system": "0.0.37",
85
- "bezier-js": "^6.1.4",
86
- "clsx": "^2.1.1",
87
88
  "execa": "^9.3.0",
88
89
  "khroma": "^2.1.0",
89
90
  "react": "^18.3.1",
90
91
  "react-dom": "^18.3.1",
91
- "tilg": "^0.1.1",
92
92
  "type-fest": "^4.21.0",
93
93
  "typescript": "^5.5.3",
94
94
  "vite": "5.3.4",
@@ -1,13 +1,10 @@
1
1
  import { ReactFlowProvider as XYFlowProvider } from '@xyflow/react'
2
- import '@xyflow/react/dist/style.css'
3
2
  import clsx from 'clsx'
4
- import { DEV } from 'esm-env'
5
3
  import { shallowEqual } from 'fast-equals'
6
4
  import { domAnimation, LazyMotion } from 'framer-motion'
7
5
  import { memo, useEffect, useRef, useState } from 'react'
8
- import useTilg from 'tilg'
9
6
  import { rootClassName } from './globals.css'
10
- import { cssDisablePan, cssNoControls, cssReactFlow, cssTransparentBg } from './LikeC4Diagram.css'
7
+ import * as css from './LikeC4Diagram.css'
11
8
  import { type LikeC4DiagramEventHandlers, type LikeC4DiagramProperties } from './LikeC4Diagram.props'
12
9
  import { EnsureMantine } from './mantine/EnsureMantine'
13
10
  import { DiagramContextProvider } from './state/DiagramContext'
@@ -52,7 +49,6 @@ export function LikeC4Diagram({
52
49
  onNodeContextMenu,
53
50
  renderIcon
54
51
  }: LikeC4DiagramProps) {
55
- DEV && useTilg()
56
52
  const initialRef = useRef<{
57
53
  defaultNodes: XYFlowData['nodes']
58
54
  defaultEdges: XYFlowData['edges']
@@ -146,7 +142,6 @@ const LikeC4DiagramInnerMemo = memo<LikeC4DiagramInnerProps>(function LikeC4Diag
146
142
  showNavigationButtons,
147
143
  enableDynamicViewWalkthrough
148
144
  }) {
149
- DEV && useTilg()
150
145
  const diagramApi = useDiagramStoreApi()
151
146
  const [isInitialized, setIsInitialized] = useState(diagramApi.getState().initialized)
152
147
 
@@ -170,10 +165,10 @@ const LikeC4DiagramInnerMemo = memo<LikeC4DiagramInnerProps>(function LikeC4Diag
170
165
  defaultEdges={defaultEdges}
171
166
  className={clsx(
172
167
  'likec4-diagram',
173
- cssReactFlow,
174
- controls === false && cssNoControls,
175
- pannable !== true && cssDisablePan,
176
- background === 'transparent' && cssTransparentBg
168
+ css.cssReactFlow,
169
+ controls === false && css.cssNoControls,
170
+ pannable !== true && css.cssDisablePan,
171
+ background === 'transparent' && css.cssTransparentBg
177
172
  )}
178
173
  >
179
174
  <XYFlowInner
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import '@xyflow/react/dist/style.css'
2
+
1
3
  export { LikeC4Diagram } from './LikeC4Diagram'
2
4
  export { StaticLikeC4Diagram } from './StaticLikeC4Diagram'
3
5
 
@@ -52,16 +52,16 @@ export function DiagramContextProvider({
52
52
  () => {
53
53
  if (!store.current) return
54
54
  const state = store.current.getState()
55
- if (state.view !== view) {
56
- state.updateView(view)
57
- }
58
55
  const newProps = pickBy(props, isNonNullish)
59
56
  if (!hasSubObject(state, newProps)) {
60
57
  store.current.setState(newProps, false, 'update incoming props')
61
58
  }
59
+ if (state.view !== view) {
60
+ state.updateView(view)
61
+ }
62
62
  },
63
63
  [view, props],
64
- shallowEqual
64
+ (prev, next) => shallowEqual(prev[0], next[0]) && shallowEqual(prev[1], next[1])
65
65
  )
66
66
  return (
67
67
  <div
@@ -1,8 +1,6 @@
1
1
  import { ReactFlow, useOnViewportChange } from '@xyflow/react'
2
- import { DEV } from 'esm-env'
3
2
  import { deepEqual as eq } from 'fast-equals'
4
3
  import { type CSSProperties, type PropsWithChildren, useCallback } from 'react'
5
- import useTilg from 'tilg'
6
4
  import type { DiagramState } from '../state/diagramStore'
7
5
  import { useDiagramState, useDiagramStoreApi } from '../state/useDiagramStore'
8
6
  import { MinZoom } from './const'
@@ -68,7 +66,6 @@ export function XYFlow({
68
66
  defaultEdges,
69
67
  style
70
68
  }: XYFlowWrapperProps) {
71
- DEV && useTilg()
72
69
  const xyflowApi = useXYStoreApi()
73
70
  const diagramApi = useDiagramStoreApi()
74
71
  const {
@@ -52,3 +52,4 @@ export const XYFlowInner = memo(function XYFlowInnerR({
52
52
  </>
53
53
  )
54
54
  }, shallowEqual)
55
+ XYFlowInner.displayName = 'XYFlowInner'
@@ -6,7 +6,7 @@ import { deepEqual as eq } from 'fast-equals'
6
6
  import { m, type Variants } from 'framer-motion'
7
7
  import { memo } from 'react'
8
8
  import { isNumber, isTruthy } from 'remeda'
9
- import { useDiagramState } from '../../../state/useDiagramStore'
9
+ import { type DiagramStoreApi, useDiagramState, useDiagramStoreApi } from '../../../state/useDiagramStore'
10
10
  import type { ElementXYFlowNode } from '../../types'
11
11
  import { toDomPrecision } from '../../utils'
12
12
  import { NavigateToBtn } from '../shared/NavigateToBtn'
@@ -71,7 +71,7 @@ const isEqualProps = (prev: ElementNodeProps, next: ElementNodeProps) => (
71
71
  prev.id === next.id
72
72
  && eq(prev.selected ?? false, next.selected ?? false)
73
73
  && eq(prev.dragging ?? false, next.dragging ?? false)
74
- && eq(prev.draggable ?? false, next.draggable ?? false)
74
+ // && eq(prev.draggable ?? false, next.draggable ?? false)
75
75
  && eq(prev.width ?? 0, next.width ?? 0)
76
76
  && eq(prev.height ?? 0, next.height ?? 0)
77
77
  && eq(prev.data.element, next.data.element)
@@ -88,6 +88,7 @@ export const ElementNodeMemo = memo<ElementNodeProps>(function ElementNode({
88
88
  width,
89
89
  height
90
90
  }) {
91
+ const store = useDiagramStoreApi()
91
92
  const { isHovered, isDimmed, hasOnNavigateTo, isHovercards, isInteractive } = useDiagramState(s => ({
92
93
  isHovered: s.hoveredNodeId === id,
93
94
  isDimmed: s.dimmed.has(id),
@@ -120,7 +121,7 @@ export const ElementNodeMemo = memo<ElementNodeProps>(function ElementNode({
120
121
  break
121
122
  }
122
123
 
123
- // useTilg(animate, isHovered, isInteractive)
124
+ const elementIcon = ElementIcon({ node: element, store })
124
125
 
125
126
  return (
126
127
  <>
@@ -187,11 +188,11 @@ export const ElementNodeMemo = memo<ElementNodeProps>(function ElementNode({
187
188
  <div
188
189
  className={clsx(
189
190
  css.elementDataContainer,
190
- isTruthy(element.icon) && css.hasIcon,
191
+ isTruthy(elementIcon) && css.hasIcon,
191
192
  'likec4-element'
192
193
  )}
193
194
  >
194
- {isTruthy(element.icon) && <ElementIcon node={element} />}
195
+ {elementIcon}
195
196
  <div className={clsx(css.elementTextData, 'likec4-element-main-props')}>
196
197
  <Text
197
198
  className={clsx(css.title, 'likec4-element-title')}>
@@ -223,8 +224,7 @@ export const ElementNodeMemo = memo<ElementNodeProps>(function ElementNode({
223
224
  )
224
225
  }, isEqualProps)
225
226
 
226
- const ElementIcon = ({ node }: { node: DiagramNode }) => {
227
- const RenderIcon = useDiagramState(s => s.renderIcon)
227
+ const ElementIcon = ({ node, store }: { node: DiagramNode; store: DiagramStoreApi }) => {
228
228
  if (!node.icon) {
229
229
  return null
230
230
  }
@@ -235,6 +235,7 @@ const ElementIcon = ({ node }: { node: DiagramNode }) => {
235
235
  </div>
236
236
  )
237
237
  }
238
+ const RenderIcon = store.getState().renderIcon
238
239
  const icon = RenderIcon ? <RenderIcon node={node} /> : null
239
240
  if (!icon) {
240
241
  return null