implemented resize direction for svelte

This commit is contained in:
peterkogo
2025-09-29 18:52:57 +02:00
parent 7d9203fc56
commit 1f118ad404
4 changed files with 48 additions and 5 deletions

View File

@@ -22,6 +22,7 @@
maxWidth = Number.MAX_VALUE,
maxHeight = Number.MAX_VALUE,
keepAspectRatio = false,
resizeDirection,
autoScale = true,
shouldResize,
onResizeStart,
@@ -78,15 +79,18 @@
store.nodes = store.nodes.map((node) => {
const change = changes.get(node.id);
const horizontal = !resizeDirection || resizeDirection === 'horizontal';
const vertical = !resizeDirection || resizeDirection === 'vertical';
if (change) {
return {
...node,
position: {
x: change.position?.x ?? node.position.x,
y: change.position?.y ?? node.position.y
x: horizontal ? (change.position?.x ?? node.position.x) : node.position.x,
y: vertical ? (change.position?.y ?? node.position.y) : node.position.y
},
width: change.width ?? node.width,
height: change.height ?? node.height
width: horizontal ? (change.width ?? node.width) : node.width,
height: vertical ? (change.height ?? node.height) : node.height
};
}
return node;
@@ -109,6 +113,7 @@
maxHeight
},
keepAspectRatio: !!keepAspectRatio,
resizeDirection,
onResizeStart,
onResize,
onResizeEnd,

View File

@@ -3,6 +3,7 @@ import type { HTMLAttributes } from 'svelte/elements';
import type {
ControlPosition,
ResizeControlVariant,
ResizeControlDirection,
ShouldResize,
OnResizeStart,
OnResize,
@@ -46,6 +47,8 @@ export type NodeResizerProps = {
onResize?: OnResize;
/** Callback called when resizing ends */
onResizeEnd?: OnResizeEnd;
/** The direction the user can resize the node */
resizeDirection?: ResizeControlDirection;
} & HTMLAttributes<HTMLDivElement>;
export type ResizeControlProps = Pick<
@@ -62,6 +65,7 @@ export type ResizeControlProps = Pick<
| 'onResizeStart'
| 'onResize'
| 'onResizeEnd'
| 'resizeDirection'
> & {
/** Position of control
* @example ControlPosition.TopLeft, ControlPosition.TopRight,