55currentSelected ,
66arrowStates ,
77arrows ,
8+ saveFSMAtom ,
89} from "../lib/backend" ;
910import { useAtom , useAtomValue , useSetAtom } from "jotai" ;
1011import { Nodes } from "../lib/backend" ;
@@ -28,6 +29,10 @@ const Editor = () => {
2829undefined ,
2930] ) ; // Will have [show/hide, current text, transition text id]
3031
32+ const [ showSaveFSM , setShowSaveFSM ] = useAtom ( saveFSMAtom ) ;
33+
34+ const [ saveFSM , setSaveFSM ] = useState ( [ 1 , "" , ".png" ] ) ; // Pop settings for downloading FSM
35+
3136// Konva Layer Reference
3237let layerRef = useRef ( null ) ;
3338
@@ -376,8 +381,8 @@ const Editor = () => {
376381fill = "#ffffff"
377382align = "center"
378383onClick = { ( ) =>
379- ( currentEditorState != "create" &&
380- currentEditorState != "delete" ) &&
384+ currentEditorState != "create" &&
385+ currentEditorState != "delete" &&
381386setTrNameEditor ( [ true , transition . name , transition . id ] )
382387}
383388/>
@@ -436,6 +441,72 @@ const Editor = () => {
436441</ button >
437442</ span >
438443</ TransitionNameEditor >
444+
445+ { /* Popup for Save FSM */ }
446+ < TransitionNameEditor showVar = { showSaveFSM } >
447+ < span className = "absolute text-center leading-13 w-fit px-2 h-15 bg-primary-bg border border-border-bg rounded-2xl shadow-[0px_0px_100px_0px_#000000] transition-all ease-in-out duration-300 flex justify-center items-center" >
448+ < select
449+ value = { saveFSM [ 0 ] }
450+ onChange = { ( e ) => {
451+ setSaveFSM ( [ parseInt ( e . target . value ) , saveFSM [ 1 ] ] ) ;
452+ } }
453+ className = "text-white font-github text-base px-2 border border-border-bg hover:border-input-active focus:border-2 focus:border-blue-500 transition-all ease-in-out outline-none h-10 rounded-lg mr-2"
454+ >
455+ < option value = { 1 } > 1x</ option >
456+ < option value = { 2 } > 2x</ option >
457+ < option value = { 3 } > 3x</ option >
458+ < option value = { 4 } > 4x</ option >
459+ < option value = { 5 } > 5x</ option >
460+ </ select >
461+
462+ < input
463+ type = "text"
464+ placeholder = "Enter File Name..."
465+ value = { saveFSM [ 1 ] ?? "" }
466+ required
467+ onChange = { ( e ) => {
468+ setSaveFSM ( [ saveFSM [ 0 ] , e . target . value ] ) ;
469+ } }
470+ className = "text-white font-github text-base px-2 border border-border-bg hover:border-input-active focus:border-2 focus:border-blue-500 transition-all ease-in-out outline-none w-full h-10 rounded-lg"
471+ />
472+
473+ < button
474+ onClick = { ( ) => {
475+ setShowSaveFSM ( false ) ;
476+ setSaveFSM ( [ 1 , "" ] ) ;
477+ } }
478+ className = "rounded-xl text-black bg-white ml-2 px-2 py-2 hover:scale-110 transition-all cursor-pointer active:scale-95 ease-in-out"
479+ >
480+ < X size = { 20 } color = "#000000" />
481+ </ button >
482+
483+ < button
484+ onClick = { ( ) => {
485+ console . log ( saveFSM ) ;
486+ // Save the FSM to disk
487+
488+ if ( saveFSM [ 1 ] . trim ( ) == "" ) { alert ( "Enter a valid file name" ) ; return }
489+
490+ const group = layerRef . current . findOne ( "Group" ) ;
491+ const dataUrl = group . toDataURL ( { pixelRatio :saveFSM [ 0 ] /* Resolution */ } ) ;
492+
493+ const link = document . createElement ( 'a' ) ;
494+
495+ link . download = saveFSM [ 1 ] ; // Name
496+ console . log ( `Gon download as${ link . download } ` )
497+ link . href = dataUrl ;
498+ document . body . appendChild ( link ) ;
499+ link . click ( ) ;
500+ document . body . removeChild ( link ) ;
501+
502+ setShowSaveFSM ( false )
503+ } }
504+ className = "rounded-xl text-black bg-blue-500 ml-2 px-2 py-2 hover:scale-110 transition-all cursor-pointer active:scale-95 ease-in-out"
505+ >
506+ < Check size = { 20 } color = "#ffffff" />
507+ </ button >
508+ </ span >
509+ </ TransitionNameEditor >
439510</ >
440511) ;
441512} ;