ensure only active/referenced files are saved

This commit is contained in:
Tom 2022-04-10 18:47:42 +02:00
parent f1c9dda366
commit cf6b5c3b6e

View File

@ -224,20 +224,28 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
const elements = this.excalidrawRef.current.getSceneElements(); const elements = this.excalidrawRef.current.getSceneElements();
const appState = this.excalidrawRef.current.getAppState(); const appState = this.excalidrawRef.current.getAppState();
/** /**
* FIXME: a file is not deleted, even though removed from canvas * A file is not deleted, even though removed from canvas. therefore we only keep
* maybe cross-reference elements and files before saving?! * files that are referenced by an element. Maybe this will change with new excalidraw version?
*/ */
const files = this.excalidrawRef.current.getFiles(); const files = this.excalidrawRef.current.getFiles();
const activeFiles = {};
elements.forEach((element) => {
if (element.fileId) {
activeFiles[element.fileId] = files[element.fileId];
}
})
const content = { const content = {
elements, elements,
appState, appState,
files, files: activeFiles,
time, time,
}; };
this.log('getContent()', content); this.log('getContent()', content, activeFiles);
return JSON.stringify(content); return JSON.stringify(content);
} }