Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 15x 15x | import { FIXED_ZONE_GAP } from "@/components/Canvas/constants";
import type { CanvasComponent as CanvasComponentModel } from "@/types/canvas";
export type ToolBarEdge = "north" | "south" | "east" | "west";
export function normalizeToolBarPosition(
position: CanvasComponentModel["position"] | undefined,
): ToolBarEdge {
switch (position) {
case "north":
case "top":
return "north";
case "south":
case "bottom":
return "south";
case "east":
case "right":
return "east";
case "west":
case "left":
return "west";
default:
return "north";
}
}
export function getOrderedChildren(
parent: CanvasComponentModel,
componentsById: Map<string, CanvasComponentModel>,
allComponents: CanvasComponentModel[],
): CanvasComponentModel[] {
const explicitChildren = (parent.children ?? [])
.map((childId) => componentsById.get(childId))
.filter((child): child is CanvasComponentModel => child !== undefined);
const explicitChildIds = new Set(explicitChildren.map((child) => child.id));
const implicitChildren = allComponents.filter(
(candidate) => candidate.parentId === parent.id && !explicitChildIds.has(candidate.id),
);
return [...explicitChildren, ...implicitChildren];
}
export function collectDescendantIds(
parent: CanvasComponentModel,
componentsById: Map<string, CanvasComponentModel>,
allComponents: CanvasComponentModel[],
collected: Set<string>,
visiting = new Set<string>(),
): void {
if (visiting.has(parent.id)) {
return;
}
visiting.add(parent.id);
collected.add(parent.id);
for (const child of getOrderedChildren(parent, componentsById, allComponents)) {
collectDescendantIds(child, componentsById, allComponents, collected, visiting);
}
visiting.delete(parent.id);
}
export function getStackExtent<T>(items: T[], getSize: (item: T, index: number) => number): number {
Eif (items.length === 0) {
return 0;
}
const size = items.reduce((total, item, index) => total + getSize(item, index), 0);
return size + FIXED_ZONE_GAP * (items.length - 1);
}
|