Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-rocks-breathe.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,18 +830,18 @@ 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)
.toBe(true)
.then(() => {
viewportHelper.value
.setViewport({
x,
y,
x: xPos,
y: yPos,
zoom: nextZoom,
})
.then(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export interface FlowExportObject {
viewport: ViewportTransform
}

export type FlowImportObject = { [key in keyof FlowExportObject]?: FlowExportObject[key] }

export interface FlowProps {
id?: string
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
Elements,
FlowElements,
FlowExportObject,
FlowImportObject,
FlowOptions,
FlowProps,
Rect,
Expand Down Expand Up @@ -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 */
Expand Down
Loading