Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 7, 2024
1 parent d0256a0 commit 242ceef
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions packages/project-editor/flow/editor/flow-document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Component } from "project-editor/flow/component";
import { ProjectEditor } from "project-editor/project-editor-interface";
import type { Page } from "project-editor/features/page/page";
import { canPasteWithDependencies } from "project-editor/store/paste-with-dependencies";
import { PageTabState } from "project-editor/features/page/PageEditor";

export class FlowDocument implements IDocument {
constructor(
Expand Down Expand Up @@ -176,36 +177,47 @@ export class FlowDocument implements IDocument {
for (const page of this.projectStore.project
.pages) {
if (page != this.flow.object) {
let uiState =
this.projectStore.uiStateStore.getObjectUIState(
page,
"flow-state"
const editor =
this.projectStore.editorsStore.getEditorByObject(
page
);

if (!uiState) {
uiState = {};
if (editor?.state) {
const pageTabState =
editor.state as PageTabState;

pageTabState.centerView();
} else {
let uiState =
this.projectStore.uiStateStore.getObjectUIState(
page,
"flow-state"
);

if (!uiState) {
uiState = {};
}

uiState.transform = {
translate: {
x: this.flowContext.viewState
.transform.translate.x,
y: this.flowContext.viewState
.transform.translate.y
},
scale:
uiState.transform?.scale ??
this.flowContext.viewState
.transform.scale
};

runInAction(() => {
this.projectStore.uiStateStore.updateObjectUIState(
page,
"flow-state",
uiState
);
});
}

uiState.transform = {
translate: {
x: this.flowContext.viewState
.transform.translate.x,
y: this.flowContext.viewState
.transform.translate.y
},
scale:
uiState.transform?.scale ??
this.flowContext.viewState
.transform.scale
};

runInAction(() => {
this.projectStore.uiStateStore.updateObjectUIState(
page,
"flow-state",
uiState
);
});
}
}
}
Expand Down

0 comments on commit 242ceef

Please sign in to comment.