fix: alte Berichte ohne bgImage im JSON laden Quellbild nach
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
Wenn ein Bericht vor Phase 6 gespeichert wurde, enthält fabric_json nur Shapes (Pfeile, Text etc.) — das Quellbild war damals noch pdfCanvas-Hintergrund. Beim Restore war jsonHasObjects=true und rerenderCurrent wurde nicht aufgerufen → Canvas weiß. Fix: Zusätzlicher Check jsonHasBgImage. Wenn kein Image im JSON (weder bgImage=true noch type=image), wird zusätzlich zu den geladenen Shapes rerenderCurrent() aufgerufen, das das Quellbild als fabric.Image hinter die Shapes legt. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> [deploy]
This commit is contained in:
parent
e0ae936811
commit
01fbd72310
1 changed files with 5 additions and 6 deletions
11
js/editor.js
11
js/editor.js
|
|
@ -173,30 +173,29 @@
|
||||||
resizeFabricToCanvas();
|
resizeFabricToCanvas();
|
||||||
|
|
||||||
let jsonHasObjects = false;
|
let jsonHasObjects = false;
|
||||||
|
let jsonHasBgImage = false;
|
||||||
if (loadedFabricJson) {
|
if (loadedFabricJson) {
|
||||||
try {
|
try {
|
||||||
const parsed = (typeof loadedFabricJson === 'string') ? JSON.parse(loadedFabricJson) : loadedFabricJson;
|
const parsed = (typeof loadedFabricJson === 'string') ? JSON.parse(loadedFabricJson) : loadedFabricJson;
|
||||||
jsonHasObjects = parsed && Array.isArray(parsed.objects) && parsed.objects.length > 0;
|
jsonHasObjects = parsed && Array.isArray(parsed.objects) && parsed.objects.length > 0;
|
||||||
|
jsonHasBgImage = jsonHasObjects && parsed.objects.some(o => o.bgImage === true || (o.type === 'image'));
|
||||||
if (jsonHasObjects) {
|
if (jsonHasObjects) {
|
||||||
// WICHTIG: loadFromJSON ist für fabric.Image async — Bilder kommen erst
|
|
||||||
// im Callback ins Canvas. Wir warten auf den Callback.
|
|
||||||
await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
fabricCanvas.loadFromJSON(parsed, () => {
|
fabricCanvas.loadFromJSON(parsed, () => {
|
||||||
fabricCanvas.renderAll();
|
fabricCanvas.renderAll();
|
||||||
res();
|
res();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Re-apply tool state: wenn aktuelles Tool nicht select ist, Objekte sperren
|
|
||||||
applyTool();
|
applyTool();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Fabric-JSON restore fehlgeschlagen:', e);
|
console.warn('Fabric-JSON restore fehlgeschlagen:', e);
|
||||||
jsonHasObjects = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jsonHasObjects) {
|
// Wenn kein Bild im JSON (alter Bericht vor Phase 6) ODER nie gespeichert:
|
||||||
// Kein gespeicherter State → Quellbild frisch als Fabric-Image laden
|
// Quellbild frisch als Fabric-Image laden und hinter die existierenden Shapes legen
|
||||||
|
if (!jsonHasBgImage) {
|
||||||
await rerenderCurrent();
|
await rerenderCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue