fix: keep grouped object IDs unique

This commit is contained in:
Formsmith
2026-08-03 18:54:15 +03:00
parent 9d2ec76103
commit decf33521a
5 changed files with 130 additions and 14 deletions
+9
View File
@@ -1,3 +1,4 @@
import { createLocalId } from "@/lib/localIds";
import type { WorkplaneShape } from "@/types/sketchforge";
export function normalizeDegrees(value: number) {
@@ -21,6 +22,14 @@ export function cleanNearZero(value: number, epsilon = 0.005) {
return Math.abs(value) < epsilon ? 0 : value;
}
export function cloneWorkplaneShapeTreeWithFreshIds(shape: WorkplaneShape, suffix: string): WorkplaneShape {
return {
...shape,
id: createLocalId(`${shape.id}-${suffix}`),
groupedShapes: shape.groupedShapes?.map((child) => cloneWorkplaneShapeTreeWithFreshIds(child, suffix)),
};
}
export function shapeWidth(shape: WorkplaneShape) {
return shape.width ?? shape.size;
}