Skip to content

Commit 33fb8a5

Browse files
authored
Merge pull request #17 from drizuid/red-x
don't always show red-x on connection lines
2 parents 94baa8e + b36dfe1 commit 33fb8a5

1 file changed

Lines changed: 57 additions & 11 deletions

File tree

static/js/app.js

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -888,35 +888,58 @@ showAddBox && React.createElement(
888888
connections.map((conn, index) => {
889889
const from = getDeviceCenter(conn.from);
890890
const to = getDeviceCenter(conn.to);
891+
const midX = (from.x + to.x) / 2;
892+
const midY = (from.y + to.y) / 2;
891893
return React.createElement(
892894
'g',
893-
{ key: index },
895+
{
896+
key: index,
897+
onMouseEnter: (e) => {
898+
e.currentTarget.querySelectorAll('.hover-show').forEach(el => {
899+
el.style.opacity = '1';
900+
});
901+
},
902+
onMouseLeave: (e) => {
903+
e.currentTarget.querySelectorAll('.hover-show').forEach(el => {
904+
el.style.opacity = '0';
905+
});
906+
}
907+
},
894908
React.createElement('line', {
895909
x1: from.x,
896910
y1: from.y,
897911
x2: to.x,
898912
y2: to.y,
899913
stroke: '#4b5563',
900-
strokeWidth: '2'
914+
strokeWidth: '2',
915+
style: { pointerEvents: 'stroke' }
901916
}),
902917
React.createElement('circle', {
903-
cx: (from.x + to.x) / 2,
904-
cy: (from.y + to.y) / 2,
918+
cx: midX,
919+
cy: midY,
905920
r: '8',
906921
fill: '#ef4444',
907-
className: 'cursor-pointer pointer-events-auto',
922+
className: 'cursor-pointer pointer-events-auto hover-show',
923+
style: {
924+
opacity: '0',
925+
transition: 'opacity 0.2s'
926+
},
908927
onClick: () => removeConnection(index)
909928
}),
910929
React.createElement(
911930
'text',
912931
{
913-
x: (from.x + to.x) / 2,
914-
y: (from.y + to.y) / 2,
932+
x: midX,
933+
y: midY,
915934
fill: 'white',
916935
fontSize: '10',
917936
textAnchor: 'middle',
918937
dominantBaseline: 'middle',
919-
className: 'pointer-events-none'
938+
className: 'pointer-events-none hover-show',
939+
style: {
940+
opacity: '0',
941+
transition: 'opacity 0.2s'
942+
}
920943
},
921944
'×'
922945
)
@@ -934,13 +957,36 @@ showAddBox && React.createElement(
934957
top: `${box.y}px`,
935958
width: `${box.width}px`,
936959
height: `${box.height}px`,
937-
zIndex: 2
960+
zIndex: 2,
961+
pointerEvents: 'none' // fix because i couldn't hover the connection lines while they were behind a box
938962
},
939-
onMouseDown: (e) => handleBoxMouseDown(e, box)
963+
onMouseDown: (e) => { //yah i broke dragging the box with the connection line fix.. smh
964+
const rect = e.currentTarget.getBoundingClientRect();
965+
const borderWidth = 2;
966+
const clickX = e.clientX - rect.left;
967+
const clickY = e.clientY - rect.top;
968+
const onBorder = clickX < borderWidth || clickX > rect.width - borderWidth ||
969+
clickY < borderWidth || clickY > rect.height - borderWidth;
970+
971+
if (onBorder) {
972+
handleBoxMouseDown(e, box)
973+
}
974+
}
940975
},
976+
React.createElement('div', {
977+
style: {
978+
position: 'absolute',
979+
top: '2px',
980+
left: '2px',
981+
right: '2px',
982+
bottom: '2px',
983+
pointerEvents: 'none'
984+
}
985+
}),
941986
React.createElement(
942987
'div',
943-
{ className: 'absolute -top-6 left-0 bg-gray-800 px-2 py-1 rounded text-white text-sm font-semibold' },
988+
{
989+
className: 'absolute -top-6 left-0 bg-gray-800 px-2 py-1 rounded text-white text-sm font-semibold' },
944990
box.name
945991
),
946992
React.createElement(

0 commit comments

Comments
 (0)