refactor(core): separate import and export objects and interfaces (#1978)

* refactor(core): separate import and export objects and interfaces

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

* chore(changeset): add

* chore: cleanup

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>

---------

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2025-10-23 16:30:27 +02:00
parent 62a1d41a43
commit 6008d63304
4 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@vue-flow/core": minor
---
Separate flow import and export object shapes and interfaces. An export object has all fields as required, while an import object makes all fields optional.

View File

@@ -830,9 +830,9 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
setEdges(edges)
}
if ((viewport?.x && viewport?.y) || position) {
const x = viewport?.x || position[0]
const y = viewport?.y || position[1]
const [xPos, yPos] = viewport?.x && viewport?.y ? [viewport.x, viewport.y] : position ?? [null, null]
if (xPos && yPos) {
const nextZoom = viewport?.zoom || zoom || state.viewport.zoom
return until(() => viewportHelper.value.viewportInitialized)
@@ -840,8 +840,8 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
.then(() => {
viewportHelper.value
.setViewport({
x,
y,
x: xPos,
y: yPos,
zoom: nextZoom,
})
.then(() => {

View File

@@ -140,6 +140,8 @@ export interface FlowExportObject {
viewport: ViewportTransform
}
export type FlowImportObject = { [key in keyof FlowExportObject]?: FlowExportObject[key] }
export interface FlowProps {
id?: string
/**

View File

@@ -7,6 +7,7 @@ import type {
Elements,
FlowElements,
FlowExportObject,
FlowImportObject,
FlowOptions,
FlowProps,
Rect,
@@ -297,7 +298,7 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
/** return an object of graph values (elements, viewport transform) for storage and re-loading a graph */
toObject: () => FlowExportObject
/** load graph from export obj */
fromObject: (obj: FlowExportObject) => Promise<boolean>
fromObject: (obj: FlowImportObject) => Promise<boolean>
/** force update node internal data, if handle bounds are incorrect, you might want to use this */
updateNodeInternals: UpdateNodeInternals
/** start a connection */