@procaaso/alphinity-ui-components 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +92 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +92 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2438,6 +2438,34 @@ function useViewBox(options) {
|
|
|
2438
2438
|
};
|
|
2439
2439
|
});
|
|
2440
2440
|
}, [initialViewBox, maxZoom]);
|
|
2441
|
+
const fitToContent = (0, import_react8.useCallback)((bounds, padding = 50) => {
|
|
2442
|
+
const contentWidth = bounds.maxX - bounds.minX;
|
|
2443
|
+
const contentHeight = bounds.maxY - bounds.minY;
|
|
2444
|
+
if (contentWidth === 0 || contentHeight === 0) {
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
const paddedWidth = contentWidth + padding * 2;
|
|
2448
|
+
const paddedHeight = contentHeight + padding * 2;
|
|
2449
|
+
const aspectRatio = initialViewBox.width / initialViewBox.height;
|
|
2450
|
+
const contentAspectRatio = paddedWidth / paddedHeight;
|
|
2451
|
+
let newWidth;
|
|
2452
|
+
let newHeight;
|
|
2453
|
+
if (contentAspectRatio > aspectRatio) {
|
|
2454
|
+
newWidth = paddedWidth;
|
|
2455
|
+
newHeight = paddedWidth / aspectRatio;
|
|
2456
|
+
} else {
|
|
2457
|
+
newHeight = paddedHeight;
|
|
2458
|
+
newWidth = paddedHeight * aspectRatio;
|
|
2459
|
+
}
|
|
2460
|
+
const centerX = bounds.minX + contentWidth / 2;
|
|
2461
|
+
const centerY = bounds.minY + contentHeight / 2;
|
|
2462
|
+
setViewBox({
|
|
2463
|
+
x: centerX - newWidth / 2,
|
|
2464
|
+
y: centerY - newHeight / 2,
|
|
2465
|
+
width: newWidth,
|
|
2466
|
+
height: newHeight
|
|
2467
|
+
});
|
|
2468
|
+
}, [initialViewBox]);
|
|
2441
2469
|
(0, import_react8.useEffect)(() => {
|
|
2442
2470
|
if (!enableZoom || !svgRef.current) return;
|
|
2443
2471
|
const svg = svgRef.current;
|
|
@@ -2669,6 +2697,8 @@ function useViewBox(options) {
|
|
|
2669
2697
|
resetViewBox,
|
|
2670
2698
|
zoomIn,
|
|
2671
2699
|
zoomOut,
|
|
2700
|
+
fitToContent,
|
|
2701
|
+
setViewBox,
|
|
2672
2702
|
screenToWorld,
|
|
2673
2703
|
svgRef
|
|
2674
2704
|
};
|
|
@@ -3323,6 +3353,7 @@ function PIDCanvas({
|
|
|
3323
3353
|
onPaste,
|
|
3324
3354
|
onSymbolDrop,
|
|
3325
3355
|
onPipeCreated,
|
|
3356
|
+
onMounted,
|
|
3326
3357
|
telemetry,
|
|
3327
3358
|
...props
|
|
3328
3359
|
}) {
|
|
@@ -3340,12 +3371,72 @@ function PIDCanvas({
|
|
|
3340
3371
|
const {
|
|
3341
3372
|
viewBox: controlledViewBox,
|
|
3342
3373
|
svgRef,
|
|
3343
|
-
screenToWorld
|
|
3374
|
+
screenToWorld,
|
|
3375
|
+
fitToContent: fitToContentViewBox,
|
|
3376
|
+
setViewBox
|
|
3344
3377
|
} = useViewBox({
|
|
3345
3378
|
initialViewBox: diagram.viewBox,
|
|
3346
3379
|
enablePan: features.pan ?? true,
|
|
3347
3380
|
enableZoom: features.zoom ?? true
|
|
3348
3381
|
});
|
|
3382
|
+
const calculateContentBounds = (0, import_react13.useCallback)(() => {
|
|
3383
|
+
const nodes2 = localDiagram.nodes.filter((n) => n.visible !== false);
|
|
3384
|
+
if (nodes2.length === 0) {
|
|
3385
|
+
return null;
|
|
3386
|
+
}
|
|
3387
|
+
let minX = Infinity;
|
|
3388
|
+
let minY = Infinity;
|
|
3389
|
+
let maxX = -Infinity;
|
|
3390
|
+
let maxY = -Infinity;
|
|
3391
|
+
nodes2.forEach((node) => {
|
|
3392
|
+
const symbol = getSymbolDefinition(node.symbolId);
|
|
3393
|
+
if (!symbol) return;
|
|
3394
|
+
const nodeMinX = node.transform.x;
|
|
3395
|
+
const nodeMinY = node.transform.y;
|
|
3396
|
+
const nodeMaxX = node.transform.x + symbol.viewBox.width;
|
|
3397
|
+
const nodeMaxY = node.transform.y + symbol.viewBox.height;
|
|
3398
|
+
minX = Math.min(minX, nodeMinX);
|
|
3399
|
+
minY = Math.min(minY, nodeMinY);
|
|
3400
|
+
maxX = Math.max(maxX, nodeMaxX);
|
|
3401
|
+
maxY = Math.max(maxY, nodeMaxY);
|
|
3402
|
+
});
|
|
3403
|
+
return { minX, minY, maxX, maxY };
|
|
3404
|
+
}, [localDiagram.nodes]);
|
|
3405
|
+
(0, import_react13.useEffect)(() => {
|
|
3406
|
+
if (onMounted) {
|
|
3407
|
+
const controls = {
|
|
3408
|
+
fitToContent: (padding = 50) => {
|
|
3409
|
+
const bounds = calculateContentBounds();
|
|
3410
|
+
if (bounds) {
|
|
3411
|
+
fitToContentViewBox(bounds, padding);
|
|
3412
|
+
}
|
|
3413
|
+
},
|
|
3414
|
+
setZoom: (zoomLevel) => {
|
|
3415
|
+
const centerX = controlledViewBox.x + controlledViewBox.width / 2;
|
|
3416
|
+
const centerY = controlledViewBox.y + controlledViewBox.height / 2;
|
|
3417
|
+
const newWidth = diagram.viewBox.width / zoomLevel;
|
|
3418
|
+
const newHeight = diagram.viewBox.height / zoomLevel;
|
|
3419
|
+
setViewBox({
|
|
3420
|
+
x: centerX - newWidth / 2,
|
|
3421
|
+
y: centerY - newHeight / 2,
|
|
3422
|
+
width: newWidth,
|
|
3423
|
+
height: newHeight
|
|
3424
|
+
});
|
|
3425
|
+
},
|
|
3426
|
+
getZoom: () => {
|
|
3427
|
+
return diagram.viewBox.width / controlledViewBox.width;
|
|
3428
|
+
}
|
|
3429
|
+
};
|
|
3430
|
+
onMounted(controls);
|
|
3431
|
+
}
|
|
3432
|
+
}, [
|
|
3433
|
+
onMounted,
|
|
3434
|
+
calculateContentBounds,
|
|
3435
|
+
fitToContentViewBox,
|
|
3436
|
+
setViewBox,
|
|
3437
|
+
controlledViewBox,
|
|
3438
|
+
diagram.viewBox
|
|
3439
|
+
]);
|
|
3349
3440
|
const { selection, selectNode, selectPipe, clearSelection } = useSelection({
|
|
3350
3441
|
multiSelect: features.multiSelect ?? true,
|
|
3351
3442
|
onSelectionChange
|