chore(system): add polyfill for Promise.withResolvers #5210

This commit is contained in:
moklick
2025-04-14 10:19:30 +02:00
parent f4528f5b00
commit 5412f71ae5
6 changed files with 32 additions and 8 deletions

View File

@@ -18,7 +18,8 @@ import {
type UpdateConnection,
type ConnectionState,
type NodeOrigin,
updateAbsolutePositions
updateAbsolutePositions,
withResolvers
} from '@xyflow/system';
import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types';
@@ -146,7 +147,7 @@ export function createStore({
function fitView(options?: FitViewOptions) {
// We either create a new Promise or reuse the existing one
// Even if fitView is called multiple times in a row, we only end up with a single Promise
const fitViewResolver = get(store.fitViewResolver) ?? Promise.withResolvers<boolean>();
const fitViewResolver = get(store.fitViewResolver) ?? withResolvers<boolean>();
// We schedule a fitView by setting fitViewQueued and triggering a setNodes
store.fitViewQueued.set(true);

View File

@@ -25,7 +25,8 @@ import {
type EdgeLookup,
type ConnectionState,
type ParentLookup,
getInternalNodesBounds
getInternalNodesBounds,
withResolvers
} from '@xyflow/system';
import DefaultNode from '$lib/components/nodes/DefaultNode.svelte';
@@ -114,7 +115,7 @@ export const getInitialStore = ({
const fitViewQueued = writable<boolean>(false);
const fitViewOptions = writable<FitViewOptions | undefined>(undefined);
const fitViewResolver = writable<PromiseWithResolvers<boolean> | null>(null);
const fitViewResolver = writable<ReturnType<typeof withResolvers<boolean>> | null>(null);
const panZoom = writable<PanZoomInstance | null>(null);
const widthStore = writable<number>(500);
const heightStore = writable<number>(500);

View File

@@ -18,7 +18,8 @@ import {
type NodeOrigin,
infiniteExtent,
type CoordinateExtent,
fitViewport
fitViewport,
withResolvers
} from '@xyflow/system';
import type {
@@ -145,7 +146,7 @@ export const createNodesStore = (
nodeExtent: CoordinateExtent = infiniteExtent,
fitViewQueued: Writable<boolean>,
fitViewOptions: Writable<FitViewOptions | undefined>,
fitViewResolver: Writable<PromiseWithResolvers<boolean> | null>,
fitViewResolver: Writable<ReturnType<typeof withResolvers<boolean>> | null>,
panZoom: Writable<PanZoomInstance | null>,
width: Writable<number>,
height: Writable<number>,