From 9652433b4ad1e6d80422bcc13dfa52a2eebd3bb8 Mon Sep 17 00:00:00 2001 From: miyanokomiya Date: Fri, 3 May 2024 11:41:01 +0900 Subject: [PATCH] fix: Prevent child shapes whose parents aren't align box shapes from attending to a align box shape - Child shapes belonging to tree root shapes other than group shapes should be exluded. - => Only align box shapes can be parents when a shape can attend to a align box shape. --- src/composables/alignHandler.spec.ts | 14 +++++++++++--- src/composables/alignHandler.ts | 12 ++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/composables/alignHandler.spec.ts b/src/composables/alignHandler.spec.ts index 89800303..33c59ac3 100644 --- a/src/composables/alignHandler.spec.ts +++ b/src/composables/alignHandler.spec.ts @@ -306,15 +306,23 @@ describe("canAttendToAlignBox", () => { id: "child1", parentId: "unknown", }); + const align = createShape(getCommonStruct, "align_box", { + id: "align", + }); + const align_child = createShape(getCommonStruct, "rectangle", { + id: "align_child", + parentId: align.id, + }); const shapeComposite = newShapeComposite({ - shapes: [rect0, line0, label0, group0, child0, child1], + shapes: [rect0, line0, label0, group0, child0, child1, align, align_child], getStruct: getCommonStruct, }); expect(canAttendToAlignBox(shapeComposite, rect0)).toBe(true); expect(canAttendToAlignBox(shapeComposite, line0)).toBe(false); expect(canAttendToAlignBox(shapeComposite, label0)).toBe(false); expect(canAttendToAlignBox(shapeComposite, group0)).toBe(true); - expect(canAttendToAlignBox(shapeComposite, child0)).toBe(false); - expect(canAttendToAlignBox(shapeComposite, child1)).toBe(true); + expect(canAttendToAlignBox(shapeComposite, child0), "child of group shape").toBe(false); + expect(canAttendToAlignBox(shapeComposite, child1), "child of missing shape").toBe(true); + expect(canAttendToAlignBox(shapeComposite, align_child), "child of align box shape").toBe(true); }); }); diff --git a/src/composables/alignHandler.ts b/src/composables/alignHandler.ts index efc35933..280076e5 100644 --- a/src/composables/alignHandler.ts +++ b/src/composables/alignHandler.ts @@ -37,7 +37,6 @@ import { renderArrowUnit, renderValueLabel } from "../utils/renderer"; import { COLORS } from "../utils/color"; import { getPaddingRect } from "../utils/boxPadding"; import { isLineShape } from "../shapes/line"; -import { isGroupShape } from "../shapes/group"; import { isLineLabelShape } from "../utils/lineLabel"; export type AlignHitResult = { @@ -883,11 +882,12 @@ export function getModifiedAlignRootIds( export function canAttendToAlignBox(shapeComposite: ShapeComposite, shape: Shape): boolean { if (isLineShape(shape)) return false; if (isLineLabelShape(shapeComposite, shape)) return false; - return ( - !shape.parentId || - !shapeComposite.shapeMap[shape.parentId] || - !isGroupShape(shapeComposite.shapeMap[shape.parentId]) - ); + if (!shape.parentId) return true; + + const parent = shapeComposite.shapeMap[shape.parentId]; + if (!parent) return true; + + return isAlignBoxShape(parent); } export function generateAlignTemplate(