chore(node-resizer): cleanup

This commit is contained in:
moklick
2024-01-09 12:30:29 +01:00
parent 0cbfcb5c7b
commit 616fb14c34
15 changed files with 62 additions and 71 deletions
@@ -2,7 +2,7 @@
import ResizeControl from './ResizeControl.svelte';
import type { NodeResizerProps } from './types';
import {
ResizerControlVariant,
ResizeControlVariant,
XY_RESIZER_HANDLE_POSITIONS,
XY_RESIZER_LINE_POSITIONS
} from '@xyflow/system';
@@ -39,7 +39,7 @@
style={lineStyle}
{nodeId}
{position}
variant={ResizerControlVariant.Line}
variant={ResizeControlVariant.Line}
{color}
minWidth={_minWidth}
minHeight={_minHeight}
@@ -4,8 +4,8 @@
import { useStore } from '$lib/store';
import {
XYResizer,
ResizerControlVariant,
type XYResizerControlPosition,
ResizeControlVariant,
type ControlPosition,
type XYResizerInstance,
type XYResizerChange
} from '@xyflow/system';
@@ -15,7 +15,7 @@
export let nodeId: $$Props['nodeId'] = undefined;
export let position: $$Props['position'] = undefined;
export let variant: $$Props['variant'] = ResizerControlVariant.Handle;
export let variant: $$Props['variant'] = ResizeControlVariant.Handle;
export let color: $$Props['color'] = undefined;
export let minWidth: $$Props['minWidth'] = 10;
$: _minWidth = minWidth ?? 10;
@@ -43,13 +43,13 @@
let resizer: XYResizerInstance | null = null;
$: defaultPosition = (
variant === ResizerControlVariant.Line ? 'right' : 'bottom-right'
) as XYResizerControlPosition;
variant === ResizeControlVariant.Line ? 'right' : 'bottom-right'
) as ControlPosition;
$: controlPosition = position ?? defaultPosition;
$: positionClassNames = controlPosition.split('-');
$: colorStyleProp = variant === ResizerControlVariant.Line ? 'border-color' : 'background-color';
$: colorStyleProp = variant === ResizeControlVariant.Line ? 'border-color' : 'background-color';
$: _style = style ?? '';
$: controlStyle = !!color ? `${_style} ${colorStyleProp}: ${color};` : _style;
@@ -1,10 +1,10 @@
import type {
XYResizeParams,
XYResizeParamsWithDirection,
XYResizeControlPosition,
ControlPosition,
ResizeControlVariant,
D3DragEvent,
SubjectPosition
ShouldResize,
OnResizeStart,
OnResize,
OnResizeEnd
} from '@xyflow/system';
export type NodeResizerProps = {
@@ -40,18 +40,8 @@ export type ResizeControlProps = Pick<
| 'onResize'
| 'onResizeEnd'
> & {
position?: XYResizeControlPosition;
position?: ControlPosition;
variant?: ResizeControlVariant;
class?: string;
style?: string;
};
type OnResizeHandler<Params = XYResizeParams, Result = void> = (
event: ResizeDragEvent,
params: Params
) => Result;
export type ResizeDragEvent = D3DragEvent<HTMLDivElement, null, SubjectPosition>;
export type ShouldResize = OnResizeHandler<XYResizeParamsWithDirection, boolean>;
export type OnResizeStart = OnResizeHandler;
export type OnResize = OnResizeHandler<XYResizeParamsWithDirection>;
export type OnResizeEnd = OnResizeHandler;