From b5395c4bac2ba279db332c8e128fe443a4e5844b Mon Sep 17 00:00:00 2001 From: miyanokomiya Date: Thu, 12 Dec 2024 12:55:38 +0900 Subject: [PATCH] fix: Add null check for snapping targets - It can be grid lines that aren't shapes --- src/composables/states/appCanvas/droppingNewShapeState.ts | 3 ++- src/composables/states/appCanvas/duplicatingShapesState.ts | 3 ++- src/composables/states/appCanvas/lines/lineDrawingState.ts | 3 ++- src/composables/states/appCanvas/lines/lineNormalReadyState.ts | 3 ++- src/composables/states/appCanvas/lines/lineReadyState.ts | 3 ++- .../states/appCanvas/lines/lineTangentReadyState.ts | 3 ++- .../states/appCanvas/lines/movingElbowSegmentState.ts | 2 +- .../states/appCanvas/lines/movingLineBezierState.ts | 3 ++- .../states/appCanvas/lines/movingLineSegmentState.ts | 3 ++- .../states/appCanvas/lines/movingLineVertexState.ts | 3 ++- src/composables/states/appCanvas/lines/movingNewVertexState.ts | 3 ++- src/composables/states/appCanvas/lines/movingOnLineState.ts | 2 +- src/composables/states/appCanvas/movingShapeControlState.ts | 3 ++- src/composables/states/appCanvas/movingShapeState.ts | 2 +- src/composables/states/appCanvas/resizingState.ts | 2 +- src/composables/states/appCanvas/text/textReadyState.ts | 3 ++- 16 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/composables/states/appCanvas/droppingNewShapeState.ts b/src/composables/states/appCanvas/droppingNewShapeState.ts index 8eef8b47..8ee135d6 100644 --- a/src/composables/states/appCanvas/droppingNewShapeState.ts +++ b/src/composables/states/appCanvas/droppingNewShapeState.ts @@ -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, }); } }, diff --git a/src/composables/states/appCanvas/duplicatingShapesState.ts b/src/composables/states/appCanvas/duplicatingShapesState.ts index 7c3b8b5a..0a637204 100644 --- a/src/composables/states/appCanvas/duplicatingShapesState.ts +++ b/src/composables/states/appCanvas/duplicatingShapesState.ts @@ -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, }); } }, diff --git a/src/composables/states/appCanvas/lines/lineDrawingState.ts b/src/composables/states/appCanvas/lines/lineDrawingState.ts index 0eedf9a5..e8df031c 100644 --- a/src/composables/states/appCanvas/lines/lineDrawingState.ts +++ b/src/composables/states/appCanvas/lines/lineDrawingState.ts @@ -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, }); } }, diff --git a/src/composables/states/appCanvas/lines/lineNormalReadyState.ts b/src/composables/states/appCanvas/lines/lineNormalReadyState.ts index 17d96236..13772678 100644 --- a/src/composables/states/appCanvas/lines/lineNormalReadyState.ts +++ b/src/composables/states/appCanvas/lines/lineNormalReadyState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/lineReadyState.ts b/src/composables/states/appCanvas/lines/lineReadyState.ts index 0dd74187..2514cc41 100644 --- a/src/composables/states/appCanvas/lines/lineReadyState.ts +++ b/src/composables/states/appCanvas/lines/lineReadyState.ts @@ -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, }); } }, diff --git a/src/composables/states/appCanvas/lines/lineTangentReadyState.ts b/src/composables/states/appCanvas/lines/lineTangentReadyState.ts index 491bbb25..87240e22 100644 --- a/src/composables/states/appCanvas/lines/lineTangentReadyState.ts +++ b/src/composables/states/appCanvas/lines/lineTangentReadyState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/movingElbowSegmentState.ts b/src/composables/states/appCanvas/lines/movingElbowSegmentState.ts index 785a27ad..6149446a 100644 --- a/src/composables/states/appCanvas/lines/movingElbowSegmentState.ts +++ b/src/composables/states/appCanvas/lines/movingElbowSegmentState.ts @@ -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), }); } diff --git a/src/composables/states/appCanvas/lines/movingLineBezierState.ts b/src/composables/states/appCanvas/lines/movingLineBezierState.ts index 08f8263f..7dd42433 100644 --- a/src/composables/states/appCanvas/lines/movingLineBezierState.ts +++ b/src/composables/states/appCanvas/lines/movingLineBezierState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/movingLineSegmentState.ts b/src/composables/states/appCanvas/lines/movingLineSegmentState.ts index e7bd1163..1f10dcf9 100644 --- a/src/composables/states/appCanvas/lines/movingLineSegmentState.ts +++ b/src/composables/states/appCanvas/lines/movingLineSegmentState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/movingLineVertexState.ts b/src/composables/states/appCanvas/lines/movingLineVertexState.ts index 0fc6cd84..1e50ee43 100644 --- a/src/composables/states/appCanvas/lines/movingLineVertexState.ts +++ b/src/composables/states/appCanvas/lines/movingLineVertexState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/movingNewVertexState.ts b/src/composables/states/appCanvas/lines/movingNewVertexState.ts index ebd648cf..54c5f8a5 100644 --- a/src/composables/states/appCanvas/lines/movingNewVertexState.ts +++ b/src/composables/states/appCanvas/lines/movingNewVertexState.ts @@ -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, }); } diff --git a/src/composables/states/appCanvas/lines/movingOnLineState.ts b/src/composables/states/appCanvas/lines/movingOnLineState.ts index bb72e9ef..6f9fc404 100644 --- a/src/composables/states/appCanvas/lines/movingOnLineState.ts +++ b/src/composables/states/appCanvas/lines/movingOnLineState.ts @@ -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), }); } }, diff --git a/src/composables/states/appCanvas/movingShapeControlState.ts b/src/composables/states/appCanvas/movingShapeControlState.ts index 04f7c495..d9f48004 100644 --- a/src/composables/states/appCanvas/movingShapeControlState.ts +++ b/src/composables/states/appCanvas/movingShapeControlState.ts @@ -105,7 +105,8 @@ export function movingShapeControlState(option: Option): 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, }); } diff --git a/src/composables/states/appCanvas/movingShapeState.ts b/src/composables/states/appCanvas/movingShapeState.ts index a305c258..2e5681ce 100644 --- a/src/composables/states/appCanvas/movingShapeState.ts +++ b/src/composables/states/appCanvas/movingShapeState.ts @@ -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), }); } diff --git a/src/composables/states/appCanvas/resizingState.ts b/src/composables/states/appCanvas/resizingState.ts index 44ba4b62..4c18f8a4 100644 --- a/src/composables/states/appCanvas/resizingState.ts +++ b/src/composables/states/appCanvas/resizingState.ts @@ -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), }); } diff --git a/src/composables/states/appCanvas/text/textReadyState.ts b/src/composables/states/appCanvas/text/textReadyState.ts index b7f6239f..45e3f944 100644 --- a/src/composables/states/appCanvas/text/textReadyState.ts +++ b/src/composables/states/appCanvas/text/textReadyState.ts @@ -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, }); } },