Skip to content

Commit

Permalink
fix: Add null check for snapping targets
Browse files Browse the repository at this point in the history
- It can be grid lines that aren't shapes
  • Loading branch information
miyanokomiya committed Dec 12, 2024
1 parent 0b351e0 commit b5395c4
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/droppingNewShapeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export function newDroppingNewShapeState(option: Option): AppCanvasState {
style: ctx.getStyleScheme(),
scale: ctx.getScale(),
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/duplicatingShapesState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export function newDuplicatingShapesState(): AppCanvasState {
style: ctx.getStyleScheme(),
scale: ctx.getScale(),
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/lines/lineDrawingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export function newLineDrawingState(option: Option): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export function newLineNormalReadyState(): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/lines/lineReadyState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export function newLineReadyState(option: Option): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export function newLineTangentReadyState(): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function newMovingElbowSegmentState(option: Option): AppCanvasState {
style,
scale,
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeMap[id]),
getTargetRect: (id) => (shapeMap[id] ? shapeComposite.getWrapperRect(shapeMap[id]) : undefined),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export function newMovingLineBezierState(option: Option): AppCanvasState {
style,
scale,
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export function newMovingLineSegmentState(option: Option): AppCanvasState {
style: ctx.getStyleScheme(),
scale: ctx.getScale(),
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export function newMovingLineVertexState(option: Option): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export function newMovingNewVertexState(option: Option): AppCanvasState {
result: connectionResult,
scale: ctx.getScale(),
style: ctx.getStyleScheme(),
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function newMovingOnLineState(option: Option): AppCanvasState {
style,
scale,
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeMap[id]),
getTargetRect: (id) => (shapeMap[id] ? shapeComposite.getWrapperRect(shapeMap[id]) : undefined),
});
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/movingShapeControlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export function movingShapeControlState<T extends Shape>(option: Option<T>): App
style: ctx.getStyleScheme(),
scale: ctx.getScale(),
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/composables/states/appCanvas/movingShapeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function newMovingShapeState(option?: Option): AppCanvasState {
style,
scale,
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeMap[id]),
getTargetRect: (id) => (shapeMap[id] ? shapeComposite.getWrapperRect(shapeMap[id]) : undefined),
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/composables/states/appCanvas/resizingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function newResizingState(option: Option): AppCanvasState {
style,
scale,
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeMap[id]),
getTargetRect: (id) => (shapeMap[id] ? shapeComposite.getWrapperRect(shapeMap[id]) : undefined),
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/composables/states/appCanvas/text/textReadyState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export function newTextReadyState(): AppCanvasState {
style: ctx.getStyleScheme(),
scale: ctx.getScale(),
result: snappingResult,
getTargetRect: (id) => shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]),
getTargetRect: (id) =>
shapeComposite.shapeMap[id] ? shapeComposite.getWrapperRect(shapeComposite.shapeMap[id]) : undefined,
});
}
},
Expand Down

0 comments on commit b5395c4

Please sign in to comment.