Skip to content

Commit 89ffa74

Browse files
committed
format
1 parent ac4e935 commit 89ffa74

File tree

9 files changed

+61
-56
lines changed

9 files changed

+61
-56
lines changed

src/pages/edit/Editor/hooks/drag.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, type PointerEvent } from "react";
1+
import { type PointerEvent, useRef } from "react";
22
import type { Vector2 } from "../../../../common/vector2";
33
import { useComponentEditorStore } from "../store";
44

@@ -24,12 +24,12 @@ export function useDraggable(props: UseDraggableProps) {
2424
pointerId: e.pointerId,
2525
initialPosition: { x: e.nativeEvent.clientX, y: e.nativeEvent.clientY },
2626
};
27-
onDragStart(e);
27+
onDragStart(e);
2828
e.currentTarget.setPointerCapture(e.pointerId);
2929
},
30-
onPointerMove: (e: PointerEvent) => {
31-
if (!dragStateRef.current) return;
32-
},
30+
onPointerMove: (e: PointerEvent) => {
31+
if (!dragStateRef.current) return;
32+
},
3333
onPointerUp: (e: PointerEvent) => {
3434
e.currentTarget.releasePointerCapture(e.pointerId);
3535
},

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function CCComponentEditorRendererBackground() {
1717
const startPoint = vector2.fromDomEvent(pointerDownEvent.nativeEvent);
1818

1919
pointerDownEvent.currentTarget.setPointerCapture(
20-
pointerDownEvent.pointerId
20+
pointerDownEvent.pointerId,
2121
);
2222
const onPointerMove = (pointerMoveEvent: PointerEvent) => {
2323
const endPoint = vector2.fromDomEvent(pointerMoveEvent);
@@ -27,32 +27,34 @@ export default function CCComponentEditorRendererBackground() {
2727
startPerspective.center,
2828
vector2.mul(
2929
vector2.sub(endPoint, startPoint),
30-
startPerspective.scale
31-
)
30+
startPerspective.scale,
31+
),
3232
),
3333
});
3434
};
3535
const onPointerUp = () => {
3636
currentTarget.removeEventListener("pointermove", onPointerMove);
3737
currentTarget.removeEventListener("pointerup", onPointerUp);
38-
pointerDownEvent.currentTarget.releasePointerCapture(pointerDownEvent.pointerId);
38+
pointerDownEvent.currentTarget.releasePointerCapture(
39+
pointerDownEvent.pointerId,
40+
);
3941
};
4042
currentTarget.addEventListener("pointermove", onPointerMove);
4143
currentTarget.addEventListener("pointerup", onPointerUp);
4244
}}
4345
onWheel={(wheelEvent) => {
4446
const scaleDelta = Math.exp(wheelEvent.deltaY / 256);
4547
const scaleCenter = componentEditorState.fromCanvasToStage(
46-
vector2.fromDomEvent(wheelEvent.nativeEvent)
48+
vector2.fromDomEvent(wheelEvent.nativeEvent),
4749
);
4850
componentEditorState.setPerspective({
4951
scale: componentEditorState.perspective.scale * scaleDelta,
5052
center: vector2.add(
5153
scaleCenter,
5254
vector2.mul(
5355
vector2.sub(componentEditorState.perspective.center, scaleCenter),
54-
scaleDelta
55-
)
56+
scaleDelta,
57+
),
5658
),
5759
});
5860
}}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CCComponentEditorRendererNode = ensureStoreItem(
2424
const [dragging, setDragging] = useState(false);
2525
const [dragStartPosition, setDragStartPosition] = useState(vector2.zero);
2626
const [previousNodePosition, setPreviousNodePosition] = useState(
27-
vector2.zero
27+
vector2.zero,
2828
);
2929

3030
const handlePointerDown = (e: React.PointerEvent) => {
@@ -43,10 +43,10 @@ const CCComponentEditorRendererNode = ensureStoreItem(
4343
vector2.mul(
4444
vector2.sub(
4545
vector2.fromDomEvent(e.nativeEvent),
46-
dragStartPosition
46+
dragStartPosition,
4747
),
48-
componentEditorState.perspective.scale
49-
)
48+
componentEditorState.perspective.scale,
49+
),
5050
),
5151
});
5252
}
@@ -94,7 +94,7 @@ const CCComponentEditorRendererNode = ensureStoreItem(
9494
</g>
9595
{store.nodePins.getManyByNodeId(nodeId).map((nodePin) => {
9696
const position = nullthrows(
97-
geometry.nodePinPositionById.get(nodePin.id)
97+
geometry.nodePinPositionById.get(nodePin.id),
9898
);
9999
return (
100100
<CCComponentEditorRendererNodePin
@@ -106,6 +106,6 @@ const CCComponentEditorRendererNode = ensureStoreItem(
106106
})}
107107
</>
108108
);
109-
}
109+
},
110110
);
111111
export default CCComponentEditorRendererNode;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function CCComponentEditorRendererNodePin({
2626
const nodePin = nullthrows(store.nodePins.get(nodePinId));
2727
const node = nullthrows(store.nodes.get(nodePin.nodeId));
2828
const componentPin = nullthrows(
29-
store.componentPins.get(nodePin.componentPinId)
29+
store.componentPins.get(nodePin.componentPinId),
3030
);
3131

3232
const [draggingState, setDraggingState] = useState<{
@@ -37,7 +37,7 @@ export default function CCComponentEditorRendererNodePin({
3737
let nodePinPositionKDTree = draggingState?.nodePinPositionKDTree;
3838
if (!nodePinPositionKDTree) {
3939
const nodes = store.nodes.getManyByParentComponentId(
40-
node.parentComponentId
40+
node.parentComponentId,
4141
);
4242
nodePinPositionKDTree = KDTree.from(
4343
nodes
@@ -49,19 +49,19 @@ export default function CCComponentEditorRendererNodePin({
4949
.flatMap(([yourNodePinId, yourNodePinPosition]) => {
5050
const yourNodePin = nullthrows(store.nodePins.get(yourNodePinId));
5151
const yourComponentPin = nullthrows(
52-
store.componentPins.get(yourNodePin.componentPinId)
52+
store.componentPins.get(yourNodePin.componentPinId),
5353
);
5454
if (yourComponentPin.type === componentPin.type) return [];
5555
return [
5656
[yourNodePinId, [yourNodePinPosition.x, yourNodePinPosition.y]],
5757
] as const;
5858
}),
59-
2
59+
2,
6060
);
6161
}
6262
setDraggingState({
6363
cursorPosition: componentEditorState.fromCanvasToStage(
64-
vector2.fromDomEvent(e.nativeEvent)
64+
vector2.fromDomEvent(e.nativeEvent),
6565
),
6666
nodePinPositionKDTree,
6767
});
@@ -79,12 +79,12 @@ export default function CCComponentEditorRendererNodePin({
7979
const nearestNodePinPosition = nullthrows(
8080
getCCComponentEditorRendererNodeGeometry(
8181
store,
82-
nearestNodePin.nodeId
83-
).nodePinPositionById.get(nearestNodePinId)
82+
nearestNodePin.nodeId,
83+
).nodePinPositionById.get(nearestNodePinId),
8484
);
8585
const distance = Math.hypot(
8686
nearestNodePinPosition.x - draggingState.cursorPosition.x,
87-
nearestNodePinPosition.y - draggingState.cursorPosition.y
87+
nearestNodePinPosition.y - draggingState.cursorPosition.y,
8888
);
8989
if (distance < NODE_PIN_POSITION_SENSITIVITY) {
9090
nodePinIdToConnect = nearestNodePinId;
@@ -102,7 +102,7 @@ export default function CCComponentEditorRendererNodePin({
102102
}
103103

104104
const isSimulationMode = useComponentEditorStore()(
105-
(s) => s.editorMode === "play"
105+
(s) => s.editorMode === "play",
106106
);
107107
const hasNoConnection =
108108
store.connections.getConnectionsByNodePinId(nodePinId).length === 0;
@@ -111,7 +111,7 @@ export default function CCComponentEditorRendererNodePin({
111111
const simulationValueToString = (simulationValue: SimulationValue) => {
112112
return simulationValue.reduce(
113113
(acm, currentValue) => acm + (currentValue === true ? "1" : "0"),
114-
""
114+
"",
115115
);
116116
};
117117
const implementationComponentPin =
@@ -121,11 +121,11 @@ export default function CCComponentEditorRendererNodePin({
121121
if (isSimulationMode && hasNoConnection) {
122122
if (implementationComponentPin) {
123123
nodePinValue = nullthrows(
124-
componentEditorState.getInputValue(implementationComponentPin.id)
124+
componentEditorState.getInputValue(implementationComponentPin.id),
125125
);
126126
} else {
127127
nodePinValue = nullthrows(
128-
componentEditorState.getNodePinValue(nodePinId)
128+
componentEditorState.getNodePinValue(nodePinId),
129129
);
130130
}
131131
nodePinValueAsString = simulationValueToString(nodePinValue);
@@ -136,7 +136,7 @@ export default function CCComponentEditorRendererNodePin({
136136
updatedPinValue[0] = !updatedPinValue[0];
137137
componentEditorState.setInputValue(
138138
implementationComponentPin.id,
139-
updatedPinValue
139+
updatedPinValue,
140140
);
141141
};
142142

@@ -169,7 +169,7 @@ export default function CCComponentEditorRendererNodePin({
169169
parentComponentId: node.parentComponentId,
170170
...route,
171171
bentPortion: 0.5,
172-
})
172+
}),
173173
);
174174
}}
175175
onLostPointerCapture={() => {

src/store/componentEvaluator.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import type {
66
SimulationValue,
77
} from "../pages/edit/Editor/store/slices/core";
88
import type { CCComponentId } from "./component";
9-
import type { CCComponentPinId, CCComponentPin } from "./componentPin";
9+
import type { CCComponentPin, CCComponentPinId } from "./componentPin";
1010
import * as intrinsics from "./intrinsics";
11-
import type { CCNodeId } from "./node";
12-
import type { CCNodePin, CCNodePinId } from "./nodePin";
1311
import {
1412
aggregate,
1513
and,
1614
decompose,
15+
definitionByComponentId,
1716
flipflop,
1817
input,
1918
not,
2019
or,
2120
xor,
22-
definitionByComponentId,
2321
} from "./intrinsics/definitions";
22+
import type { CCNodeId } from "./node";
23+
import type { CCNodePin, CCNodePinId } from "./nodePin";
2424

2525
function getNodePinIdByComponentPinId(
2626
nodePins: CCNodePin[],
@@ -42,12 +42,12 @@ function createInput(
4242
const input: Partial<Record<string, SimulationValue[]>> = {};
4343
for (const key in inputPin) {
4444
const componentPin = nullthrows(inputPin[key]);
45-
const targetNodePins = nodePins.filter((nodePin: CCNodePin) =>
46-
componentPin.id === nodePin.componentPinId
45+
const targetNodePins = nodePins.filter(
46+
(nodePin: CCNodePin) => componentPin.id === nodePin.componentPinId,
4747
);
4848
targetNodePins.sort((a, b) => a.order - b.order);
4949
const values = targetNodePins.map((nodePin: CCNodePin) =>
50-
nullthrows(inputValues.get(nodePin.id))
50+
nullthrows(inputValues.get(nodePin.id)),
5151
);
5252
input[key] = values;
5353
}
@@ -57,17 +57,19 @@ function createInput(
5757
function createOutputShape(
5858
store: CCStore,
5959
nodePins: CCNodePin[],
60-
outputPin: Record<string, CCComponentPin>
60+
outputPin: Record<string, CCComponentPin>,
6161
): Record<string, { multiplicity: number }[]> {
6262
const outputShape: Record<string, { multiplicity: number }[]> = {};
6363
for (const key in outputPin) {
6464
const componentPin = nullthrows(outputPin[key]);
65-
const targetNodePins = nodePins.filter((nodePin: CCNodePin) =>
66-
componentPin.id === nodePin.componentPinId
65+
const targetNodePins = nodePins.filter(
66+
(nodePin: CCNodePin) => componentPin.id === nodePin.componentPinId,
6767
);
6868
targetNodePins.sort((a, b) => a.order - b.order);
6969
const multiplicity = targetNodePins.map((nodePin: CCNodePin) => {
70-
const multiplexability = store.nodePins.getNodePinMultiplexability(nodePin.id);
70+
const multiplexability = store.nodePins.getNodePinMultiplexability(
71+
nodePin.id,
72+
);
7173
if (multiplexability.isMultiplexable) {
7274
return 1;
7375
}
@@ -95,7 +97,9 @@ function simulateIntrinsic(
9597
const outputShape = createOutputShape(store, nodePins, outputPin);
9698
const previousInputValues = new Map<CCNodePinId, SimulationValue>();
9799
for (const nodePin of nodePins) {
98-
const previousValue = parentPreviousFrame?.nodes.get(nodeId)?.pins.get(nodePin.id);
100+
const previousValue = parentPreviousFrame?.nodes
101+
.get(nodeId)
102+
?.pins.get(nodePin.id);
99103
if (previousValue) {
100104
previousInputValues.set(nodePin.id, previousValue);
101105
}
@@ -107,9 +111,9 @@ function simulateIntrinsic(
107111
previousInput,
108112
);
109113
const outputValues = new Map<CCNodePinId, SimulationValue>();
110-
const componentPin = nullthrows(outputPin['Out' as any]);
111-
const targetNodePins = nodePins.filter((nodePin: CCNodePin) =>
112-
componentPin.id === nodePin.componentPinId
114+
const componentPin = nullthrows(outputPin["Out" as any]);
115+
const targetNodePins = nodePins.filter(
116+
(nodePin: CCNodePin) => componentPin.id === nodePin.componentPinId,
113117
);
114118
targetNodePins.sort((a, b) => a.order - b.order);
115119
for (let i = 0; i < output.length; i++) {

src/store/componentPin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class CCComponentPinStore extends EventEmitter<CCComponentPinStoreEvents>
288288
case nullthrows(
289289
intrinsic.broadcastIntrinsicComponentDefinition.inputPins[0],
290290
).id: {
291-
return {isMultiplexable: false, multiplicity: 1}
291+
return { isMultiplexable: false, multiplicity: 1 };
292292
}
293293
case nullthrows(
294294
intrinsic.broadcastIntrinsicComponentDefinition.outputPins[0],

src/store/intrinsics/definitions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import nullthrows from "nullthrows";
12
import invariant from "tiny-invariant";
3+
import type { CCComponentId } from "../component";
4+
import type { CCComponentPin, CCComponentPinId } from "../componentPin";
25
import { IntrinsicComponentDefinition } from "./base";
36
import {
4-
ccIntrinsicComponentTypes,
57
type CCIntrinsicComponentType,
8+
ccIntrinsicComponentTypes,
69
} from "./types";
7-
import nullthrows from "nullthrows";
8-
import type { CCComponentId } from "../component";
9-
import type { CCComponentPin, CCComponentPinId } from "../componentPin";
1010

1111
function createUnaryOperator(
1212
type: CCIntrinsicComponentType,

src/store/nodePin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {
247247
static create(
248248
partialPin: Omit<CCNodePin, "id" | "userSpecifiedBitWidth">,
249249
): CCNodePin {
250-
const intrinsicComponentDefinition = intrinsics.definitionByComponentPinId.get(
251-
partialPin.componentPinId,
252-
);
250+
const intrinsicComponentDefinition =
251+
intrinsics.definitionByComponentPinId.get(partialPin.componentPinId);
253252
return {
254253
id: crypto.randomUUID() as CCNodePinId,
255254
userSpecifiedBitWidth: null,

src/store/react/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import invariant from "tiny-invariant";
1111
import CCStore, { type CCStorePropsFromJson } from "..";
1212
import { CCComponentStore } from "../component";
1313
import { CCConnectionStore } from "../connection";
14-
import { CCNodeStore } from "../node";
1514
import { and, not } from "../intrinsics/definitions";
15+
import { CCNodeStore } from "../node";
1616

1717
function useContextValue() {
1818
const [store, setStore] = useState(() => {

0 commit comments

Comments
 (0)