feat(viewport-helpers): return promises
This commit is contained in:
@@ -90,7 +90,7 @@ export function createStore({
|
||||
store.nodes.update((nds) => nds);
|
||||
};
|
||||
|
||||
function updateNodeInternals(updates: Map<string, InternalNodeUpdate>) {
|
||||
async function updateNodeInternals(updates: Map<string, InternalNodeUpdate>) {
|
||||
const nodeLookup = get(store.nodeLookup);
|
||||
const { changes, updatedInternals } = updateNodeInternalsSystem(
|
||||
updates,
|
||||
@@ -106,7 +106,7 @@ export function createStore({
|
||||
|
||||
if (!get(store.fitViewOnInitDone) && get(store.fitViewOnInit)) {
|
||||
const fitViewOptions = get(store.fitViewOptions);
|
||||
const fitViewOnInitDone = fitView({
|
||||
const fitViewOnInitDone = await fitView({
|
||||
...fitViewOptions,
|
||||
nodes: fitViewOptions?.nodes
|
||||
});
|
||||
@@ -150,7 +150,7 @@ export function createStore({
|
||||
const panZoom = get(store.panZoom);
|
||||
|
||||
if (!panZoom) {
|
||||
return false;
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
return fitViewSystem(
|
||||
@@ -168,18 +168,19 @@ export function createStore({
|
||||
|
||||
function zoomBy(factor: number, options?: ViewportHelperFunctionOptions) {
|
||||
const panZoom = get(store.panZoom);
|
||||
|
||||
if (panZoom) {
|
||||
panZoom.scaleBy(factor, options);
|
||||
if (!panZoom) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
return panZoom.scaleBy(factor, options);
|
||||
}
|
||||
|
||||
function zoomIn(options?: ViewportHelperFunctionOptions) {
|
||||
zoomBy(1.2, options);
|
||||
return zoomBy(1.2, options);
|
||||
}
|
||||
|
||||
function zoomOut(options?: ViewportHelperFunctionOptions) {
|
||||
zoomBy(1 / 1.2, options);
|
||||
return zoomBy(1 / 1.2, options);
|
||||
}
|
||||
|
||||
function setMinZoom(minZoom: number) {
|
||||
|
||||
@@ -20,19 +20,19 @@ export type SvelteFlowStoreActions = {
|
||||
setNodeTypes: (nodeTypes: NodeTypes) => void;
|
||||
setEdgeTypes: (edgeTypes: EdgeTypes) => void;
|
||||
addEdge: (edge: Edge | Connection) => void;
|
||||
zoomIn: (options?: ViewportHelperFunctionOptions) => void;
|
||||
zoomOut: (options?: ViewportHelperFunctionOptions) => void;
|
||||
zoomIn: (options?: ViewportHelperFunctionOptions) => Promise<boolean>;
|
||||
zoomOut: (options?: ViewportHelperFunctionOptions) => Promise<boolean>;
|
||||
setMinZoom: (minZoom: number) => void;
|
||||
setMaxZoom: (maxZoom: number) => void;
|
||||
setTranslateExtent: (extent: CoordinateExtent) => void;
|
||||
fitView: (options?: FitViewOptions) => boolean;
|
||||
fitView: (options?: FitViewOptions) => Promise<boolean>;
|
||||
updateNodePositions: UpdateNodePositions;
|
||||
updateNodeInternals: (updates: Map<string, InternalNodeUpdate>) => void;
|
||||
unselectNodesAndEdges: (params?: { nodes?: Node[]; edges?: Edge[] }) => void;
|
||||
addSelectedNodes: (ids: string[]) => void;
|
||||
addSelectedEdges: (ids: string[]) => void;
|
||||
handleNodeSelection: (id: string) => void;
|
||||
panBy: (delta: XYPosition) => boolean;
|
||||
panBy: (delta: XYPosition) => Promise<boolean>;
|
||||
updateConnection: UpdateConnection;
|
||||
cancelConnection: () => void;
|
||||
reset(): void;
|
||||
|
||||
Reference in New Issue
Block a user