fix render error after build
This commit is contained in:
1 parent
e21c32e800
commit
ef10851e64
3 files changed
+21
-17
No files matched your search
@@ -329,6 +329,20 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshGraph = async () => {
|
||||||
|
if (graph.hasSubtreeUpdated()) {
|
||||||
|
await graph.refreshSubtree();
|
||||||
|
} else {
|
||||||
|
await graph.refresh();
|
||||||
|
}
|
||||||
|
if (editor.focusId) {
|
||||||
|
graph.focusNode(editor.focusId);
|
||||||
|
editor.focusId = null;
|
||||||
|
} else if (graph.selectedId) {
|
||||||
|
graph.selectNode(graph.selectedId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// check should rebuild graph
|
// check should rebuild graph
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) {
|
if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) {
|
||||||
@@ -341,15 +355,7 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
|
|||||||
|
|
||||||
if (graph && workspace.editing === editor) {
|
if (graph && workspace.editing === editor) {
|
||||||
graph.setSize(editorSize.width, editorSize.height);
|
graph.setSize(editorSize.width, editorSize.height);
|
||||||
|
refreshGraph();
|
||||||
graph.refreshSubtree().then(() => {
|
|
||||||
if (editor.focusId) {
|
|
||||||
graph.focusNode(editor.focusId);
|
|
||||||
editor.focusId = null;
|
|
||||||
} else if (graph.selectedId) {
|
|
||||||
graph.selectNode(graph.selectedId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [editorSize, workspace.editing, graph]);
|
}, [editorSize, workspace.editing, graph]);
|
||||||
|
|
||||||
|
|||||||
@@ -137,19 +137,21 @@ export class Graph {
|
|||||||
const data = JSON.parse(str) as TreeData;
|
const data = JSON.parse(str) as TreeData;
|
||||||
this.editor.declare.import = data.import.map((v) => ({ path: v, vars: [], depends: [] }));
|
this.editor.declare.import = data.import.map((v) => ({ path: v, vars: [], depends: [] }));
|
||||||
this.editor.declare.vars = data.vars.map((v) => ({ ...v }));
|
this.editor.declare.vars = data.vars.map((v) => ({ ...v }));
|
||||||
await this._update(data);
|
await this._update(data, true, true);
|
||||||
// update tree inspector
|
// update tree inspector
|
||||||
this.selectNode(null);
|
this.selectNode(null);
|
||||||
this.onChange?.();
|
this.onChange?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _update(data: TreeData, refreshId: boolean = true) {
|
private async _update(data: TreeData, refreshId: boolean = true, refreshVars: boolean = false) {
|
||||||
this.editor.data = data;
|
this.editor.data = data;
|
||||||
if (refreshId) {
|
if (refreshId) {
|
||||||
b3util.refreshNodeData(this.data.root, 1);
|
b3util.refreshNodeData(this.data.root, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (refreshVars) {
|
||||||
workspace.refresh(this.editor.path);
|
workspace.refresh(this.editor.path);
|
||||||
|
}
|
||||||
|
|
||||||
// clear current target avoid hover error
|
// clear current target avoid hover error
|
||||||
const graph = this._graph as unknown as IGraph;
|
const graph = this._graph as unknown as IGraph;
|
||||||
@@ -909,9 +911,9 @@ export class Graph {
|
|||||||
this._storeHistory();
|
this._storeHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _isSubtreeUpdated(data: NodeData) {
|
hasSubtreeUpdated() {
|
||||||
let updated = false;
|
let updated = false;
|
||||||
b3util.dfs(data, (node) => {
|
b3util.dfs(this.data.root, (node) => {
|
||||||
if (node.path && b3util.files[node.path] !== node.mtime) {
|
if (node.path && b3util.files[node.path] !== node.mtime) {
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
@@ -920,12 +922,9 @@ export class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshSubtree() {
|
async refreshSubtree() {
|
||||||
if (this._isSubtreeUpdated(this.data.root)) {
|
|
||||||
this.selectNode(null);
|
|
||||||
await this.refresh();
|
await this.refresh();
|
||||||
this._storeHistory();
|
this._storeHistory();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (b3util.isNewVersion(this.data.version)) {
|
if (b3util.isNewVersion(this.data.version)) {
|
||||||
|
|||||||
@@ -519,7 +519,6 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
|
|
||||||
edit: (path, focusId) => {
|
edit: (path, focusId) => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
const setting = useSetting.getState();
|
|
||||||
const editor = workspace.editors.find((v) => v.path === path);
|
const editor = workspace.editors.find((v) => v.path === path);
|
||||||
if (editor) {
|
if (editor) {
|
||||||
editor.focusId = focusId;
|
editor.focusId = focusId;
|
||||||
|
|||||||
Reference in new issue
Block a user