@likec4/diagram 1.12.1 → 1.12.2

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.12.1",
3
+ "version": "1.12.2",
4
4
  "license": "MIT",
5
5
  "bugs": "https://github.com/likec4/likec4/issues",
6
6
  "homepage": "https://likec4.dev",
@@ -30,11 +30,11 @@
30
30
  "clean": "rm -r -f -g 'dist/*' .tsbuildinfo"
31
31
  },
32
32
  "dependencies": {
33
- "@likec4/core": "1.12.1",
33
+ "@likec4/core": "1.12.2",
34
34
  "@lume/kiwi": "^0.4.4",
35
35
  "@mantine/vanilla-extract": "7.13.2",
36
36
  "@react-hookz/web": "^24.0.4",
37
- "@tabler/icons-react": "^3.19.0",
37
+ "@tabler/icons-react": "3.17.0",
38
38
  "@vanilla-extract/css": "^1.16.0",
39
39
  "@vanilla-extract/css-utils": "^0.1.4",
40
40
  "@vanilla-extract/dynamic": "^2.1.2",
@@ -58,7 +58,7 @@
58
58
  "react-dom": "^18.3.1"
59
59
  },
60
60
  "devDependencies": {
61
- "@likec4/tsconfig": "1.12.1",
61
+ "@likec4/tsconfig": "1.12.2",
62
62
  "@mantine/core": "7.13.2",
63
63
  "@mantine/hooks": "7.13.2",
64
64
  "@types/bezier-js": "^4.1.3",
@@ -10,10 +10,17 @@ import {
10
10
  Text,
11
11
  UnstyledButton
12
12
  } from '@mantine/core'
13
- import { clampUseMovePosition, useMove, type UseMovePosition, useUncontrolled } from '@mantine/hooks'
13
+ import {
14
+ clampUseMovePosition,
15
+ useHover,
16
+ useMergedRef,
17
+ useMove,
18
+ type UseMovePosition,
19
+ useUncontrolled
20
+ } from '@mantine/hooks'
14
21
  import { useDebouncedCallback } from '@react-hookz/web'
15
22
  import { IconLayoutDashboard } from '@tabler/icons-react'
16
- import { useState } from 'react'
23
+ import { forwardRef, useState } from 'react'
17
24
  import { type DiagramState, useDiagramState, useDiagramStoreApi } from '../../hooks/useDiagramState'
18
25
  import { ActionIcon, Tooltip } from './_shared'
19
26
  import * as css from './styles.css'
@@ -32,6 +39,8 @@ export const ChangeAutoLayoutButton = (props: PopoverProps) => {
32
39
  viewId
33
40
  } = useDiagramState(selector)
34
41
 
42
+ const { ref, hovered: isSpacingHovered } = useHover()
43
+
35
44
  const setControlRef = (name: AutoLayoutDirection) => (node: HTMLButtonElement) => {
36
45
  controlsRefs[name] = node
37
46
  setControlsRefs(controlsRefs)
@@ -51,6 +60,10 @@ export const ChangeAutoLayoutButton = (props: PopoverProps) => {
51
60
  }
52
61
 
53
62
  const setSpacing = (nodeSep: number, rankSep: number) => {
63
+ // Force fitDiagram
64
+ store.setState({
65
+ viewportChanged: false
66
+ })
54
67
  store.getState().onChange?.({
55
68
  change: {
56
69
  op: 'change-autolayout',
@@ -82,7 +95,7 @@ export const ChangeAutoLayoutButton = (props: PopoverProps) => {
82
95
  </ActionIcon>
83
96
  </Tooltip>
84
97
  </PopoverTarget>
85
- <PopoverDropdown className="likec4-top-left-panel" p={8} pt={6}>
98
+ <PopoverDropdown className="likec4-top-left-panel" p={8} pt={6} opacity={isSpacingHovered ? 0.6 : 1}>
86
99
  <Box pos={'relative'} ref={setRootRef}>
87
100
  <FloatingIndicator
88
101
  target={controlsRefs[autoLayout.direction]}
@@ -110,6 +123,7 @@ export const ChangeAutoLayoutButton = (props: PopoverProps) => {
110
123
  <Text inline fz={'xs'} c={'dimmed'} fw={500}>Spacing:</Text>
111
124
  </Box>
112
125
  <SpacingSliders
126
+ ref={ref}
113
127
  isVertical={autoLayout.direction === 'TB' || autoLayout.direction === 'BT'}
114
128
  key={viewId}
115
129
  nodeSep={autoLayout.nodeSep}
@@ -122,17 +136,18 @@ export const ChangeAutoLayoutButton = (props: PopoverProps) => {
122
136
  )
123
137
  }
124
138
 
125
- const SpacingSliders = ({
126
- isVertical,
127
- nodeSep,
128
- rankSep,
129
- onChange
130
- }: {
139
+ const MAX_SPACING = 400
140
+ const SpacingSliders = forwardRef<HTMLDivElement, {
131
141
  isVertical: boolean
132
142
  nodeSep: number | undefined
133
143
  rankSep: number | undefined
134
144
  onChange: (nodeSep: number, rankSep: number) => void
135
- }) => {
145
+ }>(({
146
+ isVertical,
147
+ nodeSep,
148
+ rankSep,
149
+ onChange
150
+ }, _ref) => {
136
151
  if (!isVertical) {
137
152
  ;[nodeSep, rankSep] = [rankSep, nodeSep]
138
153
  }
@@ -142,7 +157,7 @@ const SpacingSliders = ({
142
157
  if (!isVertical) {
143
158
  ;[x, y] = [y, x]
144
159
  }
145
- onChange(Math.round(x * 500), Math.round(y * 500))
160
+ onChange(Math.round(x * MAX_SPACING), Math.round(y * MAX_SPACING))
146
161
  },
147
162
  [onChange, isVertical],
148
163
  150,
@@ -151,22 +166,24 @@ const SpacingSliders = ({
151
166
 
152
167
  const [value, setValue] = useUncontrolled({
153
168
  defaultValue: clampUseMovePosition({
154
- x: (nodeSep ?? 250) / 500,
155
- y: (rankSep ?? 250) / 500
169
+ x: (nodeSep ?? 100) / MAX_SPACING,
170
+ y: (rankSep ?? 120) / MAX_SPACING
156
171
  }),
157
172
  onChange: propagateChange
158
173
  })
159
174
 
160
175
  const { ref } = useMove(setValue)
161
176
 
162
- let nodeSepValue = Math.round(value.x * 500)
163
- let rankSepValue = Math.round(value.y * 500)
177
+ let nodeSepValue = Math.round(value.x * MAX_SPACING)
178
+ let rankSepValue = Math.round(value.y * MAX_SPACING)
164
179
  if (!isVertical) {
165
180
  ;[nodeSepValue, rankSepValue] = [rankSepValue, nodeSepValue]
166
181
  }
167
182
 
183
+ const mergedRef = useMergedRef(ref, _ref)
184
+
168
185
  return (
169
- <Box ref={ref} className={css.spacingSliderBody} pt={'100%'}>
186
+ <Box ref={mergedRef} className={css.spacingSliderBody} pt={'100%'}>
170
187
  <Box
171
188
  className={css.spacingSliderThumb}
172
189
  style={{
@@ -179,4 +196,4 @@ const SpacingSliders = ({
179
196
  </Box>
180
197
  </Box>
181
198
  )
182
- }
199
+ })