fix: include all visible canvas nodes in agent fit-all view
This commit is contained in:
parent
8ee7eb1f0a
commit
0bb134d3b8
@ -1,4 +1,5 @@
|
||||
import type { CanvasViewOperationPlan } from "@/types/canvas/agent-protocol";
|
||||
import type { NodeType } from "@/types/canvas";
|
||||
|
||||
export type CanvasAgentViewNodeLike = {
|
||||
id: string;
|
||||
@ -28,6 +29,18 @@ export type ResolvedCanvasViewOperation = {
|
||||
|
||||
const VIEWPORT_ANCHOR_X_RATIO = 0.52;
|
||||
const VIEWPORT_ANCHOR_Y_RATIO = 0.46;
|
||||
const FIT_ALL_VISIBLE_NODE_TYPES = new Set([
|
||||
"message",
|
||||
"image",
|
||||
"video",
|
||||
"text",
|
||||
"ui-screen",
|
||||
"workflow",
|
||||
"scene-fusion",
|
||||
"model3d",
|
||||
"world3d",
|
||||
"agent-slot",
|
||||
] satisfies NodeType[]);
|
||||
|
||||
function toFiniteNumber(value: unknown, fallback = 0) {
|
||||
const numericValue = Number(value);
|
||||
@ -213,8 +226,9 @@ function computeCanvasAgentFocusNodesViewport(params: {
|
||||
}
|
||||
|
||||
function getFitAllViewNodes(nodes: CanvasAgentViewNodeLike[]) {
|
||||
const visibleNodeTypes = new Set(["image", "video", "agent-slot", "ui-screen", "text"]);
|
||||
return nodes.filter((node) => visibleNodeTypes.has(String(node.type)));
|
||||
return nodes.filter((node) =>
|
||||
FIT_ALL_VISIBLE_NODE_TYPES.has(String(node.type) as NodeType)
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveCanvasViewOperation(params: {
|
||||
|
||||
@ -1822,9 +1822,9 @@ test.describe("canvas chat pure helpers", () => {
|
||||
});
|
||||
|
||||
expect(fitAll?.targetNodeIds).toEqual([]);
|
||||
expect(fitAll?.viewport.zoom).toBeCloseTo(0.675);
|
||||
expect(fitAll?.viewport.x).toBeCloseTo(317.5);
|
||||
expect(fitAll?.viewport.y).toBeCloseTo(266.75);
|
||||
expect(fitAll?.viewport.zoom).toBeCloseTo(0.1784615385);
|
||||
expect(fitAll?.viewport.x).toBeCloseTo(305.8461538);
|
||||
expect(fitAll?.viewport.y).toBeCloseTo(153.8461538);
|
||||
});
|
||||
|
||||
test("resolves grid media placements to the right of an anchor node", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user