feat(svelte): add fitViewOptions for Controls closes #4201
This commit is contained in:
@@ -13,8 +13,8 @@
|
|||||||
type Node,
|
type Node,
|
||||||
type Edge,
|
type Edge,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
useSvelteFlow,
|
ControlButton,
|
||||||
ControlButton
|
type FitViewOptions
|
||||||
} from '@xyflow/svelte';
|
} from '@xyflow/svelte';
|
||||||
|
|
||||||
import CustomNode from './CustomNode.svelte';
|
import CustomNode from './CustomNode.svelte';
|
||||||
@@ -33,6 +33,11 @@
|
|||||||
custom: CustomEdge
|
custom: CustomEdge
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fitViewOptions: FitViewOptions = {
|
||||||
|
padding: 0.2,
|
||||||
|
nodes: [{ id: '1' }, { id: '2' }]
|
||||||
|
};
|
||||||
|
|
||||||
const nodes = writable<Node[]>([
|
const nodes = writable<Node[]>([
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
@@ -191,7 +196,7 @@
|
|||||||
attributionPosition={'top-center'}
|
attributionPosition={'top-center'}
|
||||||
deleteKey={['Backspace', 'd']}
|
deleteKey={['Backspace', 'd']}
|
||||||
>
|
>
|
||||||
<Controls orientation="horizontal">
|
<Controls orientation="horizontal" {fitViewOptions}>
|
||||||
<ControlButton slot="before">xy</ControlButton>
|
<ControlButton slot="before">xy</ControlButton>
|
||||||
<ControlButton aria-label="log" on:click={() => console.log('control button')}
|
<ControlButton aria-label="log" on:click={() => console.log('control button')}
|
||||||
>log</ControlButton
|
>log</ControlButton
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
export let ariaLabel: $$Props['aria-label'] = undefined;
|
export let ariaLabel: $$Props['aria-label'] = undefined;
|
||||||
export let style: $$Props['style'] = undefined;
|
export let style: $$Props['style'] = undefined;
|
||||||
export let orientation: $$Props['orientation'] = 'vertical';
|
export let orientation: $$Props['orientation'] = 'vertical';
|
||||||
|
export let fitViewOptions: $$Props['fitViewOptions'] = undefined;
|
||||||
|
|
||||||
let className: $$Props['class'] = '';
|
let className: $$Props['class'] = '';
|
||||||
export { className as class };
|
export { className as class };
|
||||||
@@ -63,7 +64,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onFitViewHandler = () => {
|
const onFitViewHandler = () => {
|
||||||
fitView();
|
fitView(fitViewOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onToggleInteractivity = () => {
|
const onToggleInteractivity = () => {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { HTMLButtonAttributes } from 'svelte/elements';
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
||||||
import type { PanelPosition } from '@xyflow/system';
|
import type { PanelPosition } from '@xyflow/system';
|
||||||
|
|
||||||
|
import type { FitViewOptions } from '$lib/types';
|
||||||
|
|
||||||
export type ControlsProps = {
|
export type ControlsProps = {
|
||||||
/** Position of the controls on the pane
|
/** Position of the controls on the pane
|
||||||
* @example PanelPosition.TopLeft, PanelPosition.TopRight,
|
* @example PanelPosition.TopLeft, PanelPosition.TopRight,
|
||||||
@@ -21,6 +23,7 @@ export type ControlsProps = {
|
|||||||
style?: string;
|
style?: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
orientation?: 'horizontal' | 'vertical';
|
orientation?: 'horizontal' | 'vertical';
|
||||||
|
fitViewOptions?: FitViewOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ControlButtonProps = HTMLButtonAttributes & {
|
export type ControlButtonProps = HTMLButtonAttributes & {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getContext, setContext } from 'svelte';
|
|||||||
import { derived, get, writable } from 'svelte/store';
|
import { derived, get, writable } from 'svelte/store';
|
||||||
import {
|
import {
|
||||||
createMarkerIds,
|
createMarkerIds,
|
||||||
fitView as fitViewUtil,
|
fitView as fitViewSystem,
|
||||||
getElementsToRemove,
|
getElementsToRemove,
|
||||||
panBy as panBySystem,
|
panBy as panBySystem,
|
||||||
updateNodeInternals as updateNodeInternalsSystem,
|
updateNodeInternals as updateNodeInternalsSystem,
|
||||||
@@ -140,7 +140,7 @@ export function createStore({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fitViewUtil(
|
return fitViewSystem(
|
||||||
{
|
{
|
||||||
nodeLookup: get(store.nodeLookup),
|
nodeLookup: get(store.nodeLookup),
|
||||||
width: get(store.width),
|
width: get(store.width),
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export type HandleComponentProps = {
|
|||||||
ondisconnect?: (connections: Connection[]) => void;
|
ondisconnect?: (connections: Connection[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FitViewOptions = FitViewOptionsBase<Node>;
|
export type FitViewOptions<NodeType extends Node = Node> = FitViewOptionsBase<NodeType>;
|
||||||
|
|
||||||
export type OnDelete = (params: { nodes: Node[]; edges: Edge[] }) => void;
|
export type OnDelete = (params: { nodes: Node[]; edges: Edge[] }) => void;
|
||||||
export type OnEdgeCreate = (connection: Connection) => Edge | Connection | void;
|
export type OnEdgeCreate = (connection: Connection) => Edge | Connection | void;
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ export type FitViewParamsBase<NodeType extends NodeBase> = {
|
|||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FitViewOptionsBase<NodeType extends NodeBase> = {
|
export type FitViewOptionsBase<NodeType extends NodeBase = NodeBase> = {
|
||||||
padding?: number;
|
padding?: number;
|
||||||
includeHiddenNodes?: boolean;
|
includeHiddenNodes?: boolean;
|
||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
nodes?: (NodeType | { id: NodeType['id'] })[];
|
nodes?: (NodeType | { id: string })[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Viewport = {
|
export type Viewport = {
|
||||||
|
|||||||
Reference in New Issue
Block a user