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-11-21 21:53:58 +01:00
parent 62a1d41a43
commit 6008d63304
4 changed files with 14 additions and 6 deletions
+5
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.
+5 -5
View File
@@ -830,9 +830,9 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
setEdges(edges) setEdges(edges)
} }
if ((viewport?.x && viewport?.y) || position) { const [xPos, yPos] = viewport?.x && viewport?.y ? [viewport.x, viewport.y] : position ?? [null, null]
const x = viewport?.x || position[0]
const y = viewport?.y || position[1] if (xPos && yPos) {
const nextZoom = viewport?.zoom || zoom || state.viewport.zoom const nextZoom = viewport?.zoom || zoom || state.viewport.zoom
return until(() => viewportHelper.value.viewportInitialized) return until(() => viewportHelper.value.viewportInitialized)
@@ -840,8 +840,8 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
.then(() => { .then(() => {
viewportHelper.value viewportHelper.value
.setViewport({ .setViewport({
x, x: xPos,
y, y: yPos,
zoom: nextZoom, zoom: nextZoom,
}) })
.then(() => { .then(() => {
+2
View File
@@ -140,6 +140,8 @@ export interface FlowExportObject {
viewport: ViewportTransform viewport: ViewportTransform
} }
export type FlowImportObject = { [key in keyof FlowExportObject]?: FlowExportObject[key] }
export interface FlowProps { export interface FlowProps {
id?: string id?: string
/** /**
+2 -1
View File
@@ -7,6 +7,7 @@ import type {
Elements, Elements,
FlowElements, FlowElements,
FlowExportObject, FlowExportObject,
FlowImportObject,
FlowOptions, FlowOptions,
FlowProps, FlowProps,
Rect, 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 */ /** return an object of graph values (elements, viewport transform) for storage and re-loading a graph */
toObject: () => FlowExportObject toObject: () => FlowExportObject
/** load graph from export obj */ /** 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 */ /** force update node internal data, if handle bounds are incorrect, you might want to use this */
updateNodeInternals: UpdateNodeInternals updateNodeInternals: UpdateNodeInternals
/** start a connection */ /** start a connection */