Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/graph-builder/graph-core/4-undo-redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class GraphUndoRedo extends GraphComponent {
),
});
this.curActionIndex += 1;

if (this.actionArr.length > 100) {
const drop = this.actionArr.length - 100;
this.actionArr.splice(0, drop);
this.curActionIndex -= drop;
}

this.informUI();
}

Expand Down
8 changes: 6 additions & 2 deletions src/graph-builder/graph-core/5-load-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ class GraphLoadSave extends GraphUndoRedo {
}

static stringifyAction({ actionName, parameters }) {
return { actionName, parameters: window.btoa(JSON.stringify(parameters)) };
return { actionName, parameters: JSON.stringify(parameters) };
}

static parseAction({ actionName, parameters }) {
return { actionName, parameters: JSON.parse(window.atob(parameters)) };
try {
return { actionName, parameters: JSON.parse(parameters) };
} catch {
return { actionName, parameters: JSON.parse(window.atob(parameters)) };
}
}

jsonifyGraph() {
Expand Down
16 changes: 11 additions & 5 deletions src/graph-builder/local-storage-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const localStorageGet = (key) => {
const localStorageSet = (key, value) => {
try {
window.localStorage.setItem(key, value);
return true;
} catch (e) {
toast.error(e.message);
return false;
}
};

Expand Down Expand Up @@ -82,16 +84,20 @@ const localStorageManager = {
const raw = localStorageGet(id);
if (raw === null) return null;
const parsed = parseStoredJson(raw);
if (parsed === null) {
localStorageRemove(id);
if (parsed !== null) return parsed;
// fallback for legacy plain JSON data saved before base64 encoding was introduced
try {
return JSON.parse(raw);
} catch {
return null;
}
return parsed;
},
save(id, graphContent) {
this.addGraph(id);
const serializedJson = JSON.stringify(graphContent);
localStorageSet(id, encodeBase64(serializedJson));
if (!localStorageSet(id, encodeBase64(JSON.stringify(graphContent)))) {
const stripped = { ...graphContent, actionHistory: [] };
localStorageSet(id, encodeBase64(JSON.stringify(stripped)));
}
},
remove(id) {
if (this.allgs.delete(id)) this.saveAllgs();
Expand Down