Skip to content

Commit 7acd6d7

Browse files
authored
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>
1 parent 62a1d41 commit 7acd6d7

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

.changeset/modern-rocks-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": minor
3+
---
4+
5+
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.

packages/core/src/store/actions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,18 +830,18 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
830830
setEdges(edges)
831831
}
832832

833-
if ((viewport?.x && viewport?.y) || position) {
834-
const x = viewport?.x || position[0]
835-
const y = viewport?.y || position[1]
833+
const [xPos, yPos] = viewport?.x && viewport?.y ? [viewport.x, viewport.y] : position ?? [null, null]
834+
835+
if (xPos && yPos) {
836836
const nextZoom = viewport?.zoom || zoom || state.viewport.zoom
837837

838838
return until(() => viewportHelper.value.viewportInitialized)
839839
.toBe(true)
840840
.then(() => {
841841
viewportHelper.value
842842
.setViewport({
843-
x,
844-
y,
843+
x: xPos,
844+
y: yPos,
845845
zoom: nextZoom,
846846
})
847847
.then(() => {

packages/core/src/types/flow.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export interface FlowExportObject {
140140
viewport: ViewportTransform
141141
}
142142

143+
export type FlowImportObject = { [key in keyof FlowExportObject]?: FlowExportObject[key] }
144+
143145
export interface FlowProps {
144146
id?: string
145147
/**

packages/core/src/types/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
Elements,
88
FlowElements,
99
FlowExportObject,
10+
FlowImportObject,
1011
FlowOptions,
1112
FlowProps,
1213
Rect,
@@ -297,7 +298,7 @@ export interface Actions extends Omit<ViewportHelper, 'viewportInitialized'> {
297298
/** return an object of graph values (elements, viewport transform) for storage and re-loading a graph */
298299
toObject: () => FlowExportObject
299300
/** load graph from export obj */
300-
fromObject: (obj: FlowExportObject) => Promise<boolean>
301+
fromObject: (obj: FlowImportObject) => Promise<boolean>
301302
/** force update node internal data, if handle bounds are incorrect, you might want to use this */
302303
updateNodeInternals: UpdateNodeInternals
303304
/** start a connection */

0 commit comments

Comments
 (0)