@likec4/diagram 1.0.0 → 1.0.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/dist/index.mjs +19 -19
- package/dist/style.css +1 -4
- package/package.json +14 -12
- package/src/xyflow/SyncWithDiagram.tsx +26 -23
- package/src/xyflow/edges/edges.css.ts +4 -4
package/dist/index.mjs
CHANGED
|
@@ -7764,7 +7764,9 @@ function toDomPrecision(v) {
|
|
|
7764
7764
|
return v === null ? 0.01 : Math.round(v * 100) / 100;
|
|
7765
7765
|
}
|
|
7766
7766
|
const isSameNode = (a) => (b) => a.id === b.id && a.type === b.type && Object.is(a.parentId, b.parentId), SyncWithDiagram = memo(() => {
|
|
7767
|
-
const
|
|
7767
|
+
const _xyflow = useXYFlow(), xyflowRef = useRef(_xyflow);
|
|
7768
|
+
xyflowRef.current = _xyflow;
|
|
7769
|
+
const xyflowApi = useXYStoreApi(), diagramStoreApi = useDiagramStoreApi();
|
|
7768
7770
|
return useEffect(() => diagramStoreApi.subscribe(
|
|
7769
7771
|
// selector
|
|
7770
7772
|
(state) => ({
|
|
@@ -7777,7 +7779,7 @@ const isSameNode = (a) => (b) => a.id === b.id && a.type === b.type && Object.is
|
|
|
7777
7779
|
// listener
|
|
7778
7780
|
({ viewId, nodes, edges, ...opts }) => {
|
|
7779
7781
|
const { lastOnNavigate } = diagramStoreApi.getState(), updates = diagramViewToXYFlowData({ nodes, edges }, opts);
|
|
7780
|
-
if (
|
|
7782
|
+
if (xyflowRef.current.setNodes(
|
|
7781
7783
|
(prev) => updates.nodes.map((update) => {
|
|
7782
7784
|
const existing = prev.find(isSameNode(update));
|
|
7783
7785
|
return existing ? deepEqual(existing.data.element, update.data.element) ? existing : {
|
|
@@ -7785,7 +7787,7 @@ const isSameNode = (a) => (b) => a.id === b.id && a.type === b.type && Object.is
|
|
|
7785
7787
|
...update
|
|
7786
7788
|
} : update;
|
|
7787
7789
|
})
|
|
7788
|
-
),
|
|
7790
|
+
), xyflowRef.current.setEdges(
|
|
7789
7791
|
(prev) => updates.edges.map((update) => {
|
|
7790
7792
|
const existing = prev.find((e) => e.id === update.id);
|
|
7791
7793
|
return existing ? deepEqual(existing.data, update.data) ? existing : {
|
|
@@ -7798,22 +7800,20 @@ const isSameNode = (a) => (b) => a.id === b.id && a.type === b.type && Object.is
|
|
|
7798
7800
|
if (elTo) {
|
|
7799
7801
|
const centerFrom = lastOnNavigate.elementCenterScreenPosition, nextZoom = Math.min(elFrom.width / elTo.width, elFrom.height / elTo.height);
|
|
7800
7802
|
requestAnimationFrame(() => {
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
zoom: nextZoom
|
|
7807
|
-
});
|
|
7808
|
-
const centerTo = xyflow.flowToScreenPosition({
|
|
7809
|
-
x: elTo.position[0] + elTo.width / 2,
|
|
7810
|
-
y: elTo.position[1] + elTo.height / 2
|
|
7811
|
-
}), diff = {
|
|
7812
|
-
x: toDomPrecision(centerFrom.x - centerTo.x),
|
|
7813
|
-
y: toDomPrecision(centerFrom.y - centerTo.y)
|
|
7814
|
-
};
|
|
7815
|
-
xyflowApi.getState().panBy(diff);
|
|
7803
|
+
const v = xyflowRef.current.getViewport();
|
|
7804
|
+
nextZoom < v.zoom && xyflowRef.current.setViewport({
|
|
7805
|
+
x: v.x,
|
|
7806
|
+
y: v.y,
|
|
7807
|
+
zoom: nextZoom
|
|
7816
7808
|
});
|
|
7809
|
+
const centerTo = xyflowRef.current.flowToScreenPosition({
|
|
7810
|
+
x: elTo.position[0] + elTo.width / 2,
|
|
7811
|
+
y: elTo.position[1] + elTo.height / 2
|
|
7812
|
+
}), diff = {
|
|
7813
|
+
x: toDomPrecision(centerFrom.x - centerTo.x),
|
|
7814
|
+
y: toDomPrecision(centerFrom.y - centerTo.y)
|
|
7815
|
+
};
|
|
7816
|
+
xyflowApi.getState().panBy(diff);
|
|
7817
7817
|
});
|
|
7818
7818
|
}
|
|
7819
7819
|
diagramStoreApi.setState(
|
|
@@ -7831,7 +7831,7 @@ const isSameNode = (a) => (b) => a.id === b.id && a.type === b.type && Object.is
|
|
|
7831
7831
|
{
|
|
7832
7832
|
equalityFn: shallowEqual
|
|
7833
7833
|
}
|
|
7834
|
-
), [
|
|
7834
|
+
), [xyflowApi, diagramStoreApi]), null;
|
|
7835
7835
|
});
|
|
7836
7836
|
function getVarName(variable) {
|
|
7837
7837
|
var matches = variable.match(/^var\((.*)\)$/);
|
package/dist/style.css
CHANGED
|
@@ -756,7 +756,7 @@ svg.react-flow__connectionline {
|
|
|
756
756
|
}
|
|
757
757
|
[data-mantine-color-scheme="dark"] .bexn7q0 {
|
|
758
758
|
--xy-edge-label-color: var(--likec4-relation-labelColor);
|
|
759
|
-
--xy-edge-label-background-color: color-mix(in srgb, var(--likec4-relation-labelBg), transparent
|
|
759
|
+
--xy-edge-label-background-color: color-mix(in srgb, var(--likec4-relation-labelBg), transparent 55%);
|
|
760
760
|
}
|
|
761
761
|
.bexn7q0[data-edge-hovered='true'] {
|
|
762
762
|
--xy-edge-stroke: color-mix(in srgb, var(--likec4-relation-lineColor), white 30%);
|
|
@@ -805,9 +805,6 @@ svg.react-flow__connectionline {
|
|
|
805
805
|
transform: var(--bexn7q6);
|
|
806
806
|
will-change: transform;
|
|
807
807
|
}
|
|
808
|
-
[data-mantine-color-scheme="dark"] .bexn7q7 {
|
|
809
|
-
mix-blend-mode: luminosity;
|
|
810
|
-
}
|
|
811
808
|
.bexn7q7[data-edge-hovered="true"] {
|
|
812
809
|
transition: all 140ms ease-out;
|
|
813
810
|
transform: var(--bexn7q6) scale(1.1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/diagram",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
6
|
"homepage": "https://likec4.dev",
|
|
@@ -40,36 +40,38 @@
|
|
|
40
40
|
"./style.css": "./dist/style.css"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
"packageManager": "yarn@4.
|
|
43
|
+
"packageManager": "yarn@4.2.2",
|
|
44
44
|
"scripts": {
|
|
45
45
|
"typecheck": "tsc",
|
|
46
46
|
"prepack": "vite build --mode production",
|
|
47
47
|
"build:turbo": "run -T turbo build --filter='diagram'",
|
|
48
48
|
"build": "vite build --mode development && tsc -b",
|
|
49
49
|
"lint": "run -T eslint src/ --fix",
|
|
50
|
-
"clean": "run -T rimraf -v dist/* .tsbuildinfo"
|
|
50
|
+
"clean": "run -T rimraf -v -g 'dist/*' .tsbuildinfo"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@likec4/core": "1.0.
|
|
54
|
-
"@mantine/core": "^7.9.0",
|
|
55
|
-
"@mantine/hooks": "^7.9.0",
|
|
53
|
+
"@likec4/core": "1.0.2",
|
|
56
54
|
"@react-hookz/web": "^24.0.4",
|
|
57
55
|
"esm-env": "^1.0.0",
|
|
58
56
|
"fast-equals": "^5.0.1",
|
|
59
|
-
"framer-motion": "^11.
|
|
57
|
+
"framer-motion": "^11.2.2",
|
|
60
58
|
"remeda": "^1.61.0",
|
|
61
59
|
"zustand": "^4.5.2"
|
|
62
60
|
},
|
|
63
61
|
"peerDependencies": {
|
|
64
|
-
"
|
|
65
|
-
"
|
|
62
|
+
"@mantine/core": "^7.9.2",
|
|
63
|
+
"@mantine/hooks": "^7.9.2",
|
|
64
|
+
"react": "^18.3.1",
|
|
65
|
+
"react-dom": "^18.3.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@lume/kiwi": "^0.4.3",
|
|
69
|
-
"@mantine/
|
|
69
|
+
"@mantine/core": "^7.9.2",
|
|
70
|
+
"@mantine/hooks": "^7.9.2",
|
|
71
|
+
"@mantine/vanilla-extract": "^7.9.2",
|
|
70
72
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
71
|
-
"@types/react": "
|
|
72
|
-
"@types/react-dom": "
|
|
73
|
+
"@types/react": "18.2.0",
|
|
74
|
+
"@types/react-dom": "18.2.4",
|
|
73
75
|
"@vanilla-extract/css": "^1.15.1",
|
|
74
76
|
"@vanilla-extract/dynamic": "^2.1.0",
|
|
75
77
|
"@vanilla-extract/esbuild-plugin": "^2.3.5",
|
|
@@ -2,7 +2,7 @@ import { deepEqual as eq, shallowEqual } from 'fast-equals'
|
|
|
2
2
|
import { useXYFlow, useXYStoreApi } from './hooks'
|
|
3
3
|
import type { XYFlowNode } from './types'
|
|
4
4
|
|
|
5
|
-
import { memo, useEffect } from 'react'
|
|
5
|
+
import { memo, useEffect, useRef } from 'react'
|
|
6
6
|
import { useDiagramStoreApi } from '../state'
|
|
7
7
|
import { diagramViewToXYFlowData } from './diagram-to-xyflow'
|
|
8
8
|
import { toDomPrecision } from './utils'
|
|
@@ -14,7 +14,10 @@ const isSameNode = (a: XYFlowNode) => (b: XYFlowNode) =>
|
|
|
14
14
|
* Syncs the diagram state with the XYFlow instance
|
|
15
15
|
*/
|
|
16
16
|
export const SyncWithDiagram = memo(() => {
|
|
17
|
-
const
|
|
17
|
+
const _xyflow = useXYFlow()
|
|
18
|
+
const xyflowRef = useRef(_xyflow)
|
|
19
|
+
xyflowRef.current = _xyflow
|
|
20
|
+
|
|
18
21
|
const xyflowApi = useXYStoreApi()
|
|
19
22
|
const diagramStoreApi = useDiagramStoreApi()
|
|
20
23
|
|
|
@@ -33,7 +36,7 @@ export const SyncWithDiagram = memo(() => {
|
|
|
33
36
|
const { lastOnNavigate } = diagramStoreApi.getState()
|
|
34
37
|
const updates = diagramViewToXYFlowData({ nodes, edges }, opts)
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
xyflowRef.current.setNodes(prev =>
|
|
37
40
|
updates.nodes.map(update => {
|
|
38
41
|
const existing = prev.find(isSameNode(update))
|
|
39
42
|
if (existing) {
|
|
@@ -49,7 +52,7 @@ export const SyncWithDiagram = memo(() => {
|
|
|
49
52
|
})
|
|
50
53
|
)
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
xyflowRef.current.setEdges(prev =>
|
|
53
56
|
updates.edges.map(update => {
|
|
54
57
|
const existing = prev.find(e => e.id === update.id)
|
|
55
58
|
if (existing) {
|
|
@@ -70,25 +73,25 @@ export const SyncWithDiagram = memo(() => {
|
|
|
70
73
|
const nextZoom = Math.min(elFrom.width / elTo.width, elFrom.height / elTo.height)
|
|
71
74
|
|
|
72
75
|
requestAnimationFrame(() => {
|
|
73
|
-
requestAnimationFrame(() => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
// requestAnimationFrame(() => {
|
|
77
|
+
const v = xyflowRef.current.getViewport()
|
|
78
|
+
if (nextZoom < v.zoom) {
|
|
79
|
+
xyflowRef.current.setViewport({
|
|
80
|
+
x: v.x,
|
|
81
|
+
y: v.y,
|
|
82
|
+
zoom: nextZoom
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
const centerTo = xyflowRef.current.flowToScreenPosition({
|
|
86
|
+
x: elTo.position[0] + elTo.width / 2,
|
|
87
|
+
y: elTo.position[1] + elTo.height / 2
|
|
88
|
+
}),
|
|
89
|
+
diff = {
|
|
90
|
+
x: toDomPrecision(centerFrom.x - centerTo.x),
|
|
91
|
+
y: toDomPrecision(centerFrom.y - centerTo.y)
|
|
81
92
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
y: elTo.position[1] + elTo.height / 2
|
|
85
|
-
}),
|
|
86
|
-
diff = {
|
|
87
|
-
x: toDomPrecision(centerFrom.x - centerTo.x),
|
|
88
|
-
y: toDomPrecision(centerFrom.y - centerTo.y)
|
|
89
|
-
}
|
|
90
|
-
xyflowApi.getState().panBy(diff)
|
|
91
|
-
})
|
|
93
|
+
xyflowApi.getState().panBy(diff)
|
|
94
|
+
// })
|
|
92
95
|
})
|
|
93
96
|
}
|
|
94
97
|
diagramStoreApi.setState(
|
|
@@ -107,7 +110,7 @@ export const SyncWithDiagram = memo(() => {
|
|
|
107
110
|
equalityFn: shallowEqual
|
|
108
111
|
}
|
|
109
112
|
)
|
|
110
|
-
}, [
|
|
113
|
+
}, [xyflowApi, diagramStoreApi])
|
|
111
114
|
|
|
112
115
|
return null
|
|
113
116
|
})
|
|
@@ -15,7 +15,7 @@ export const container = style({
|
|
|
15
15
|
[mantine.darkSelector]: {
|
|
16
16
|
vars: {
|
|
17
17
|
[xyvars.edge.labelColor]: vars.relation.labelColor,
|
|
18
|
-
[xyvars.edge.labelBgColor]: `color-mix(in srgb, ${vars.relation.labelBgColor}, transparent
|
|
18
|
+
[xyvars.edge.labelBgColor]: `color-mix(in srgb, ${vars.relation.labelBgColor}, transparent 55%)`
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
// [mantine.lightSelector]: {
|
|
@@ -105,9 +105,9 @@ export const edgeLabel = style({
|
|
|
105
105
|
[varLabelY]: '50%'
|
|
106
106
|
},
|
|
107
107
|
selectors: {
|
|
108
|
-
[mantine.darkSelector]: {
|
|
109
|
-
|
|
110
|
-
},
|
|
108
|
+
// [mantine.darkSelector]: {
|
|
109
|
+
// mixBlendMode: 'luminosity'
|
|
110
|
+
// },
|
|
111
111
|
'&[data-edge-hovered="true"]': {
|
|
112
112
|
transition: 'all 140ms ease-out',
|
|
113
113
|
transform: `${varTranslate} scale(1.1)`
|