fix(ui): move neighbouring columns aside when a step card opens

This commit is contained in:
sam committed 2026-10-18 23:45:27 +11:00
1 parent 5aba9b8707
commit bc291255e8
1 file changed
+24 -3
+24 -3
View File
@@ -125,6 +125,26 @@ function card(node: GraphNode): GraphNode {
return { ...node, data: { ...data, ...extra } };
}
// An open card widens about its centre, and every column to either side moves
// out by half the growth so no neighbour sits under it.
const WIDEN = OPEN_WIDTH - NODE_WIDTH;
const holdsOpen = (node: GraphNode) => {
const open = anchor.value;
if (!open || !node.style?.width) return false;
return node.position.x <= open.position.x && node.position.x + parseFloat(String(node.style.width)) >= open.position.x + NODE_WIDTH;
};
function spread(node: GraphNode): number {
const open = anchor.value;
if (!open) return 0;
if (node.id === open.id || holdsOpen(node)) return -WIDEN / 2;
const centre = open.position.x + NODE_WIDTH / 2;
const width = node.style?.width ? parseFloat(String(node.style.width)) : node.type === "step" ? NODE_WIDTH : 32;
const mid = node.position.x + width / 2;
// The open card's own column stays put; insertion glyphs sit near its centre.
if (Math.abs(mid - centre) < NODE_WIDTH / 2) return 0;
return mid < centre ? -WIDEN / 2 : WIDEN / 2;
}
const nodes = computed(() => {
const open = anchor.value;
return graph.value.nodes.map((node) => {
@@ -134,16 +154,17 @@ const nodes = computed(() => {
else if (node.type === "step") node = card(node);
const mark = props.marks?.[node.id];
if (mark) node = { ...node, data: { ...node.data, mark } };
const { x } = node.position;
const x = node.position.x + spread(node);
const opened = (at: number) => (open && at > open.position.y ? shift.value : 0);
const y = node.position.y + pushed(node.position.y) + opened(node.position.y);
if (original === open) return { ...node, position: { x: x - (OPEN_WIDTH - NODE_WIDTH) / 2, y }, zIndex: 10 };
if (original === open) return { ...node, position: { x, y }, zIndex: 10 };
// A lane grows with the cards inside it.
if (node.type === "lane" && node.style) {
const top = node.position.y;
const bottom = top + parseFloat(node.style.height);
const height = bottom + pushed(bottom) + opened(bottom) - y;
return { ...node, position: { x, y }, style: { ...node.style, height: `${height}px` } };
const width = parseFloat(String(node.style.width)) + (holdsOpen(node) ? WIDEN : 0);
return { ...node, position: { x, y }, style: { ...node.style, width: `${width}px`, height: `${height}px` } };
}
return { ...node, position: { x, y } };
});