File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed
Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,13 @@ class GraphUndoRedo extends GraphComponent {
9999 ) ,
100100 } ) ;
101101 this . curActionIndex += 1 ;
102+
103+ if ( this . actionArr . length > 100 ) {
104+ const drop = this . actionArr . length - 100 ;
105+ this . actionArr . splice ( 0 , drop ) ;
106+ this . curActionIndex -= drop ;
107+ }
108+
102109 this . informUI ( ) ;
103110 }
104111
Original file line number Diff line number Diff line change @@ -48,11 +48,15 @@ class GraphLoadSave extends GraphUndoRedo {
4848 }
4949
5050 static stringifyAction ( { actionName, parameters } ) {
51- return { actionName, parameters : window . btoa ( JSON . stringify ( parameters ) ) } ;
51+ return { actionName, parameters : JSON . stringify ( parameters ) } ;
5252 }
5353
5454 static parseAction ( { actionName, parameters } ) {
55- return { actionName, parameters : JSON . parse ( window . atob ( parameters ) ) } ;
55+ try {
56+ return { actionName, parameters : JSON . parse ( parameters ) } ;
57+ } catch {
58+ return { actionName, parameters : JSON . parse ( window . atob ( parameters ) ) } ;
59+ }
5660 }
5761
5862 jsonifyGraph ( ) {
Original file line number Diff line number Diff line change @@ -35,8 +35,10 @@ const localStorageGet = (key) => {
3535const localStorageSet = ( key , value ) => {
3636 try {
3737 window . localStorage . setItem ( key , value ) ;
38+ return true ;
3839 } catch ( e ) {
3940 toast . error ( e . message ) ;
41+ return false ;
4042 }
4143} ;
4244
@@ -82,16 +84,20 @@ const localStorageManager = {
8284 const raw = localStorageGet ( id ) ;
8385 if ( raw === null ) return null ;
8486 const parsed = parseStoredJson ( raw ) ;
85- if ( parsed === null ) {
86- localStorageRemove ( id ) ;
87+ if ( parsed !== null ) return parsed ;
88+ // fallback for legacy plain JSON data saved before base64 encoding was introduced
89+ try {
90+ return JSON . parse ( raw ) ;
91+ } catch {
8792 return null ;
8893 }
89- return parsed ;
9094 } ,
9195 save ( id , graphContent ) {
9296 this . addGraph ( id ) ;
93- const serializedJson = JSON . stringify ( graphContent ) ;
94- localStorageSet ( id , encodeBase64 ( serializedJson ) ) ;
97+ if ( ! localStorageSet ( id , encodeBase64 ( JSON . stringify ( graphContent ) ) ) ) {
98+ const stripped = { ...graphContent , actionHistory : [ ] } ;
99+ localStorageSet ( id , encodeBase64 ( JSON . stringify ( stripped ) ) ) ;
100+ }
95101 } ,
96102 remove ( id ) {
97103 if ( this . allgs . delete ( id ) ) this . saveAllgs ( ) ;
You can’t perform that action at this time.
0 commit comments