Skip to content

Commit

Permalink
bugfixes, dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-coding committed Oct 21, 2024
1 parent 2b5db7b commit 04e5e43
Show file tree
Hide file tree
Showing 3 changed files with 315 additions and 305 deletions.
16 changes: 10 additions & 6 deletions .vitepress/components/GraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { inject } from "vue";
import { Disposable } from "vscode-languageserver-protocol";
import {
asyncComputed,
refThrottled,
watchImmediate,
} from "@vueuse/core";
import { v4 as uuid } from "uuid";
Expand Down Expand Up @@ -74,7 +75,7 @@ const disposables = shallowRef<Disposable[]>([]);
const hideMainContent = ref(true);
watch(model, (value) => {
if (editor.value != undefined) {
if (editor.value != undefined && editor.value.getValue() != value) {
editor.value.setValue(value);
}
});
Expand Down Expand Up @@ -102,7 +103,7 @@ class ModelSource extends GraphModelSource {
protected handleCreateRelation(context: CreateRelationContext): void {}
}
const editor = shallowRef<{ setValue(value: string): void }>()
const editor = shallowRef<{ setValue(value: string): void; getValue(): string }>()
const modelSource = shallowRef<ModelSource | undefined>();
const parsedModel = ref<Graph>();
Expand All @@ -124,16 +125,19 @@ const settings = inject(settingsKey);
const layoutServerUrl = computed(() => settings!.value.serverUrl ?? "");
const throttledParsedModel = refThrottled(parsedModel, 800, true, true);
const layout = asyncComputed<GraphLayout>(async () => {
if (parsedModel.value == undefined || layoutServerUrl.value == "") {
const modelValue = throttledParsedModel.value;
if (modelValue == undefined || layoutServerUrl.value == "") {
return {};
}
const res = await fetch(layoutServerUrl.value, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(toRaw(parsedModel.value)),
body: JSON.stringify(toRaw(modelValue)),
}).then((response) => response.json());
return res.data;
}, {});
Expand All @@ -142,10 +146,10 @@ watchEffect(() => {
if (
layout.value != undefined &&
modelSource.value != undefined &&
parsedModel.value != null
throttledParsedModel.value != null
) {
modelSource.value.updateGraph({
graph: parsedModel.value,
graph: throttledParsedModel.value,
layout: layout.value,
fitToBounds: true,
});
Expand Down
Loading

0 comments on commit 04e5e43

Please sign in to comment.