chore(svelte/nodewrapper): cleanup
This commit is contained in:
@@ -14,7 +14,8 @@ import {
|
||||
type ConnectionState,
|
||||
updateAbsolutePositions,
|
||||
snapPosition,
|
||||
calculateNodePosition
|
||||
calculateNodePosition,
|
||||
type SetCenterOptions
|
||||
} from '@xyflow/system';
|
||||
|
||||
import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types';
|
||||
@@ -126,6 +127,26 @@ export function createStore<NodeType extends Node = Node, EdgeType extends Edge
|
||||
return fitViewResolver.promise;
|
||||
}
|
||||
|
||||
async function setCenter(x: number, y: number, options?: SetCenterOptions) {
|
||||
const nextZoom = typeof options?.zoom !== 'undefined' ? options.zoom : store.maxZoom;
|
||||
const currentPanZoom = store.panZoom;
|
||||
|
||||
if (!currentPanZoom) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
await currentPanZoom.setViewport(
|
||||
{
|
||||
x: store.width / 2 - x * nextZoom,
|
||||
y: store.height / 2 - y * nextZoom,
|
||||
zoom: nextZoom
|
||||
},
|
||||
{ duration: options?.duration, ease: options?.ease, interpolate: options?.interpolate }
|
||||
);
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
function zoomBy(factor: number, options?: ViewportHelperFunctionOptions) {
|
||||
const panZoom = store.panZoom;
|
||||
if (!panZoom) {
|
||||
@@ -372,6 +393,7 @@ export function createStore<NodeType extends Node = Node, EdgeType extends Edge
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
fitView,
|
||||
setCenter,
|
||||
setMinZoom,
|
||||
setMaxZoom,
|
||||
setTranslateExtent,
|
||||
|
||||
@@ -6,7 +6,8 @@ import type {
|
||||
UpdateNodePositions,
|
||||
CoordinateExtent,
|
||||
UpdateConnection,
|
||||
Viewport
|
||||
Viewport,
|
||||
SetCenter
|
||||
} from '@xyflow/system';
|
||||
|
||||
import type { getInitialStore } from './initial-store.svelte';
|
||||
@@ -24,6 +25,7 @@ export type SvelteFlowStoreActions<NodeType extends Node = Node, EdgeType extend
|
||||
setTranslateExtent: (extent: CoordinateExtent) => void;
|
||||
setPaneClickDistance: (distance: number) => void;
|
||||
fitView: (options?: FitViewOptions) => Promise<boolean>;
|
||||
setCenter: SetCenter;
|
||||
updateNodePositions: UpdateNodePositions;
|
||||
updateNodeInternals: (updates: Map<string, InternalNodeUpdate>) => void;
|
||||
unselectNodesAndEdges: (params?: { nodes?: NodeType[]; edges?: EdgeType[] }) => void;
|
||||
|
||||
Reference in New Issue
Block a user