modify the stlye of the original, add an input field for the original, revise the definition of the canvas bounds
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
const DEFAULT_COMPONENT_BOX_SIZE = { width: 132, height: 82 };
|
||||
// Default editable canvas dimensions in micrometers.
|
||||
const DEFAULT_CANVAS_SIZE = { width: 5000, height: 5000 };
|
||||
// Default canvas bounds as a four-wall rectangle (xmin, xmax, ymin, ymax).
|
||||
const DEFAULT_CANVAS_BOUNDS = { xmin: 0, xmax: 5000, ymin: 0, ymax: 5000 };
|
||||
// Base visual diameter and hit area used for port and anchor handles.
|
||||
const PORT_NODE_SIZE = 11;
|
||||
const FREE_WIRES_BUNDLE_GROUP = 'free_wires';
|
||||
@@ -314,15 +316,35 @@
|
||||
height: positiveNumber(size && size.height) || DEFAULT_CANVAS_SIZE.height
|
||||
});
|
||||
|
||||
// Resolve valid canvas bounds (four-wall rectangle) from saved project metadata.
|
||||
// Accepts either legacy {width, height} or new {xmin, xmax, ymin, ymax}.
|
||||
const normalizeCanvasBounds = (bounds) => {
|
||||
if (!bounds) return { ...DEFAULT_CANVAS_BOUNDS };
|
||||
// New-style four-wall rectangle.
|
||||
if (bounds.xmin != null || bounds.xmax != null || bounds.ymin != null || bounds.ymax != null) {
|
||||
return {
|
||||
xmin: Number.isFinite(Number(bounds.xmin)) ? Number(bounds.xmin) : DEFAULT_CANVAS_BOUNDS.xmin,
|
||||
xmax: Number.isFinite(Number(bounds.xmax)) ? Number(bounds.xmax) : DEFAULT_CANVAS_BOUNDS.xmax,
|
||||
ymin: Number.isFinite(Number(bounds.ymin)) ? Number(bounds.ymin) : DEFAULT_CANVAS_BOUNDS.ymin,
|
||||
ymax: Number.isFinite(Number(bounds.ymax)) ? Number(bounds.ymax) : DEFAULT_CANVAS_BOUNDS.ymax
|
||||
};
|
||||
}
|
||||
// Legacy width/height format: treat as rectangle from (0,0).
|
||||
const w = positiveNumber(bounds.width) || DEFAULT_CANVAS_SIZE.width;
|
||||
const h = positiveNumber(bounds.height) || DEFAULT_CANVAS_SIZE.height;
|
||||
return { xmin: 0, xmax: w, ymin: 0, ymax: h };
|
||||
};
|
||||
|
||||
// Keep dragged or pasted nodes inside the active canvas bounds.
|
||||
// Accepts either legacy {width,height} or new {xmin,xmax,ymin,ymax} canvasSize.
|
||||
const clampPositionToCanvas = (position, canvasSize, boxSize) => {
|
||||
const size = normalizeCanvasSize(canvasSize);
|
||||
const bounds = normalizeCanvasBounds(canvasSize);
|
||||
const box = normalizeBoxSize({ box_size: [boxSize && boxSize.width, boxSize && boxSize.height] });
|
||||
const maxX = Math.max(0, size.width - box.width);
|
||||
const maxY = Math.max(0, size.height - box.height);
|
||||
const maxX = Math.max(bounds.xmin, bounds.xmax - box.width);
|
||||
const maxY = Math.max(bounds.ymin, bounds.ymax - box.height);
|
||||
return {
|
||||
x: Math.min(maxX, Math.max(0, Number(position && position.x) || 0)),
|
||||
y: Math.min(maxY, Math.max(0, Number(position && position.y) || 0))
|
||||
x: Math.min(maxX, Math.max(bounds.xmin, Number(position && position.x) || 0)),
|
||||
y: Math.min(maxY, Math.max(bounds.ymin, Number(position && position.y) || 0))
|
||||
};
|
||||
};
|
||||
|
||||
@@ -375,8 +397,8 @@
|
||||
});
|
||||
|
||||
if (points.length === 0) {
|
||||
const size = normalizeCanvasSize(page.canvasSize || DEFAULT_CANVAS_SIZE);
|
||||
points.push({ x: 0, y: 0 }, { x: size.width, y: size.height });
|
||||
const bounds = normalizeCanvasBounds(page.canvasSize || page.canvasBounds);
|
||||
points.push({ x: bounds.xmin, y: bounds.ymin }, { x: bounds.xmax, y: bounds.ymax });
|
||||
}
|
||||
|
||||
const minX = roundBoundsValue(Math.min(...points.map(point => point.x)));
|
||||
@@ -1321,6 +1343,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
|
||||
FORGE_COMPONENT_TYPE,
|
||||
DEFAULT_COMPONENT_BOX_SIZE,
|
||||
DEFAULT_CANVAS_SIZE,
|
||||
DEFAULT_CANVAS_BOUNDS,
|
||||
PORT_NODE_SIZE,
|
||||
DEFAULT_ELEMENT_PITCH,
|
||||
ELEMENT_COMPONENTS,
|
||||
@@ -1351,6 +1374,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
|
||||
normalizeBoxSize,
|
||||
chooseCategoryComponent,
|
||||
normalizeCanvasSize,
|
||||
normalizeCanvasBounds,
|
||||
clampPositionToCanvas,
|
||||
calculateLayoutBounds,
|
||||
calculateCompositeBoxSize,
|
||||
|
||||
Reference in New Issue
Block a user