feat(svelte): add autoScale for node resizer
This commit is contained in:
@@ -11,7 +11,7 @@ const CustomResizerNode: FC<NodeProps> = ({ data }) => {
|
||||
minWidth={100}
|
||||
maxWidth={500}
|
||||
color="orange"
|
||||
scaleControls
|
||||
autoScale={false}
|
||||
/>
|
||||
<Handle type="target" position={Position.Left} />
|
||||
<div>{data.label}</div>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
handleStyle,
|
||||
lineClass,
|
||||
lineStyle,
|
||||
autoScale = true,
|
||||
...rest
|
||||
}: NodeResizerProps = $props();
|
||||
</script>
|
||||
@@ -25,11 +26,19 @@
|
||||
style={lineStyle}
|
||||
{nodeId}
|
||||
{position}
|
||||
{autoScale}
|
||||
variant={ResizeControlVariant.Line}
|
||||
{...rest}
|
||||
/>
|
||||
{/each}
|
||||
{#each XY_RESIZER_HANDLE_POSITIONS as position (position)}
|
||||
<ResizeControl class={handleClass} style={handleStyle} {nodeId} {position} {...rest} />
|
||||
<ResizeControl
|
||||
class={handleClass}
|
||||
style={handleStyle}
|
||||
{nodeId}
|
||||
{position}
|
||||
{autoScale}
|
||||
{...rest}
|
||||
/>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
maxWidth = Number.MAX_VALUE,
|
||||
maxHeight = Number.MAX_VALUE,
|
||||
keepAspectRatio = false,
|
||||
autoScale = true,
|
||||
shouldResize,
|
||||
onResizeStart,
|
||||
onResize,
|
||||
@@ -121,7 +122,7 @@
|
||||
bind:this={resizeControlRef}
|
||||
style:border-color={isLineVariant ? color : undefined}
|
||||
style:background-color={isLineVariant ? undefined : color}
|
||||
style:scale={isLineVariant ? undefined : Math.max(1 / store.viewport.zoom, 1)}
|
||||
style:scale={isLineVariant || !autoScale ? undefined : Math.max(1 / store.viewport.zoom, 1)}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
|
||||
@@ -36,6 +36,8 @@ export type NodeResizerProps = {
|
||||
maxHeight?: number;
|
||||
/** Keep aspect ratio when resizing */
|
||||
keepAspectRatio?: boolean;
|
||||
/** Automatically scale the node when resizing */
|
||||
autoScale?: boolean;
|
||||
/** Callback to determine if node should resize */
|
||||
shouldResize?: ShouldResize;
|
||||
/** Callback called when resizing starts */
|
||||
@@ -55,6 +57,7 @@ export type ResizeControlProps = Pick<
|
||||
| 'maxWidth'
|
||||
| 'maxHeight'
|
||||
| 'keepAspectRatio'
|
||||
| 'autoScale'
|
||||
| 'shouldResize'
|
||||
| 'onResizeStart'
|
||||
| 'onResize'
|
||||
|
||||
Reference in New Issue
Block a user