Skip to content

Commit c59a730

Browse files
committed
20250726 update
1 parent eebcb7b commit c59a730

File tree

14 files changed

+314
-203
lines changed

14 files changed

+314
-203
lines changed

src/pages/edit/Editor/components/ContextMenu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export default function CCComponentEditorContextMenu({
4747
width: "200px",
4848
}}
4949
>
50-
<MenuItem onClick={componentEditorState.closeContextMenu}>
50+
{/* <MenuItem onClick={componentEditorState.closeContextMenu}>
5151
Create a node
52-
</MenuItem>
52+
</MenuItem> */}
5353
{componentEditorState.selectedNodeIds.size > 0 && (
5454
<MenuItem
5555
onClick={() => {
@@ -135,7 +135,7 @@ export default function CCComponentEditorContextMenu({
135135
store.connections.unregister([
136136
...componentEditorState.selectedConnectionIds,
137137
]);
138-
componentEditorState.selectNode([], true);
138+
// componentEditorState.selectNode([], true);
139139
componentEditorState.selectConnection([], false);
140140
componentEditorState.closeContextMenu();
141141
}}

src/pages/edit/Editor/components/NodePinPropertyEditor.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function CCComponentEditorNodePinPropertyEditor() {
2828
.getManyByNodeIdAndComponentPinId(target.nodeId, target.componentPinId)
2929
.toSorted((a, b) => a.order - b.order);
3030
invariant(
31-
nodePins.every((p) => p.userSpecifiedBitWidth !== null),
31+
nodePins.every((p) => p.manualBitWidth !== null),
3232
"NodePinPropertyEditor can only be used for node pins with user specified bit width",
3333
);
3434
const componentPinAttributes = nullthrows(
@@ -64,7 +64,7 @@ export function CCComponentEditorNodePinPropertyEditor() {
6464

6565
const bitWidthList =
6666
newBitWidthList ??
67-
nodePins.map((nodePin) => nullthrows(nodePin.userSpecifiedBitWidth));
67+
nodePins.map((nodePin) => nullthrows(nodePin.manualBitWidth));
6868

6969
const isTouched = Boolean(newBitWidthList);
7070
const isValid = bitWidthList.every((bitWidth) => bitWidth > 0);
@@ -103,7 +103,7 @@ export function CCComponentEditorNodePinPropertyEditor() {
103103
componentPinId: target.componentPinId,
104104
nodeId: target.nodeId,
105105
order: ++maxOrder,
106-
userSpecifiedBitWidth: bitWidth,
106+
manualBitWidth: bitWidth,
107107
}),
108108
);
109109
continue;
@@ -116,10 +116,24 @@ export function CCComponentEditorNodePinPropertyEditor() {
116116
// Update NodePin
117117
if (nodePin && bitWidth) {
118118
maxOrder = nodePin.order; // nodePins are sorted by order
119-
if (nodePin.userSpecifiedBitWidth !== bitWidth)
119+
if (nodePin.manualBitWidth !== bitWidth) {
120120
store.nodePins.update(nodePin.id, {
121-
userSpecifiedBitWidth: bitWidth,
121+
manualBitWidth: bitWidth,
122122
});
123+
const connections = store.connections.getConnectionsByNodePinId(
124+
nodePin.id,
125+
);
126+
for (const connection of connections) {
127+
const anotherNodePinId = connection.from === nodePin.id
128+
? connection.to
129+
: connection.from;
130+
if (!store.nodePins.isConnectable(
131+
nodePin.id, anotherNodePinId
132+
)) {
133+
store.connections.unregister([connection.id]);
134+
}
135+
}
136+
}
123137
continue;
124138
}
125139
throw new Error("Unreachable");

src/pages/edit/Editor/renderer/Connection.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@ import { useStore } from "../../../../store/react";
55
import ensureStoreItem from "../../../../store/react/error";
66
import { useNode } from "../../../../store/react/selectors";
77
import getCCComponentEditorRendererNodeGeometry from "./Node.geometry";
8+
import { useComponentEditorStore } from "../store";
89

910
export type CCComponentEditorRendererConnectionCoreProps = {
1011
from: { x: number; y: number };
1112
to: { x: number; y: number };
13+
connectionId?: CCConnectionId;
1214
};
1315
export function CCComponentEditorRendererConnectionCore({
1416
from,
1517
to,
18+
connectionId,
1619
}: CCComponentEditorRendererConnectionCoreProps) {
1720
const straightGap = 10;
1821
const direction = from.x < to.x ? 1 : -1;
1922

23+
const componentEditorState = useComponentEditorStore()();
24+
25+
26+
const handleClick = (e: React.MouseEvent) => {
27+
if (!connectionId) {
28+
return;
29+
}
30+
componentEditorState.selectConnection(
31+
[connectionId],
32+
!e.shiftKey
33+
)
34+
}
35+
2036
return (
2137
<path
2238
d={[
@@ -32,9 +48,22 @@ export function CCComponentEditorRendererConnectionCore({
3248
].join(" ")}`,
3349
`h ${straightGap * direction}`,
3450
].join(" ")}
35-
stroke={theme.palette.textPrimary}
51+
stroke={connectionId && componentEditorState.selectedConnectionIds.has(connectionId) ? theme.palette.primary: theme.palette.textPrimary}
3652
strokeWidth="2"
3753
fill="none"
54+
onClick={handleClick}
55+
onContextMenu={(e) => {
56+
if (!connectionId) {
57+
return;
58+
}
59+
e.preventDefault();
60+
e.stopPropagation();
61+
componentEditorState.selectConnection(
62+
[connectionId],
63+
true
64+
);
65+
componentEditorState.openContextMenu(e);
66+
}}
3867
/>
3968
);
4069
}
@@ -70,6 +99,7 @@ const CCComponentEditorRendererConnection = ensureStoreItem(
7099
<CCComponentEditorRendererConnectionCore
71100
from={fromNodePinPosition}
72101
to={toNodePinPosition}
102+
connectionId={connectionId}
73103
/>
74104
);
75105
},

src/pages/edit/Editor/renderer/Node.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const CCComponentEditorRendererNode = ensureStoreItem(
2828
);
2929

3030
const handlePointerDown = (e: React.PointerEvent) => {
31-
componentEditorState.selectNode([nodeId], true);
31+
if (e.button === 0) {
32+
componentEditorState.selectNode([nodeId], !e.shiftKey);
33+
}
3234
setDragStartPosition(vector2.fromDomEvent(e.nativeEvent));
3335
setPreviousNodePosition(node.position);
3436
setDragging(true);
@@ -65,7 +67,10 @@ const CCComponentEditorRendererNode = ensureStoreItem(
6567
onPointerUp={handlePointerUp}
6668
onContextMenu={(e) => {
6769
e.preventDefault();
68-
componentEditorState.selectNode([nodeId], true);
70+
const selectedNodeIds = componentEditorState.selectedNodeIds;
71+
if (!selectedNodeIds.has(nodeId)) {
72+
componentEditorState.selectNode([nodeId], true);
73+
}
6974
componentEditorState.openContextMenu(e);
7075
}}
7176
>

src/pages/edit/Editor/renderer/NodePin.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default function CCComponentEditorRendererNodePin({
126126
setDraggingState(null);
127127
},
128128
onClick: () => {
129-
if (nodePin.userSpecifiedBitWidth === null) return;
129+
if (nodePin.manualBitWidth === null) return;
130130
componentEditorState.setNodePinPropertyEditorTarget({
131131
componentPinId: nodePin.componentPinId,
132132
nodeId: nodePin.nodeId,
@@ -156,24 +156,24 @@ export default function CCComponentEditorRendererNodePin({
156156
stroke={theme.palette.textPrimary}
157157
strokeWidth={2}
158158
/>
159-
{nodePin.userSpecifiedBitWidth !== null && (
159+
{nodePin.manualBitWidth !== null && (
160160
<text
161161
x={position.x}
162162
y={position.y}
163163
textAnchor="middle"
164164
dominantBaseline="central"
165165
fontSize={
166-
nodePin.userSpecifiedBitWidth >= 100
166+
nodePin.manualBitWidth >= 100
167167
? 4
168-
: nodePin.userSpecifiedBitWidth >= 10
168+
: nodePin.manualBitWidth >= 10
169169
? 6
170170
: 8
171171
}
172172
fill={theme.palette.textPrimary}
173173
>
174-
{nodePin.userSpecifiedBitWidth >= 100
174+
{nodePin.manualBitWidth >= 100
175175
? "99+"
176-
: nodePin.userSpecifiedBitWidth}
176+
: nodePin.manualBitWidth}
177177
</text>
178178
)}
179179
</g>

src/pages/edit/Editor/store/slices/core/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ export const createComponentEditorStoreCoreSlice: ComponentEditorSliceCreator<
6868
getInputValue(componentPinId: CCComponentPinId) {
6969
const value = get().inputValues.get(componentPinId);
7070
if (!value) {
71-
const multiplexability =
72-
store.componentPins.getComponentPinMultiplexability(
71+
const bitWidthStatus =
72+
store.componentPins.getComponentPinBitWidthStatus(
7373
componentPinId,
7474
);
75-
if (multiplexability === "undecidable") {
76-
throw new Error("Cannot determine multiplexability");
77-
}
78-
if (multiplexability.isMultiplexable) {
79-
const newValue = [false];
75+
if (bitWidthStatus.isFixed) {
76+
const newValue = new Array(bitWidthStatus.bitWidth).fill(
77+
false,
78+
);
8079
return newValue;
8180
}
82-
const newValue = new Array(multiplexability.multiplicity).fill(
83-
false,
84-
);
81+
if (bitWidthStatus.fixMode === "manual") {
82+
throw new Error("Cannot determine bit width");
83+
}
84+
const newValue = [false];
8585
return newValue;
8686
}
8787
return value;
@@ -169,7 +169,7 @@ export const createComponentEditorStoreCoreSlice: ComponentEditorSliceCreator<
169169
.join() +
170170
store.nodePins
171171
.getMany()
172-
.map((nodePin) => nodePin.userSpecifiedBitWidth || 0)
172+
.map((nodePin) => nodePin.id + "_" + (nodePin.manualBitWidth || 0))
173173
.join(",") +
174174
store.connections
175175
.getMany()

0 commit comments

Comments
 (0)