@@ -19,3 +19,52 @@ async function runCode(){
1919 alert ( "Error: " + e ) ;
2020 }
2121}
22+
23+ function saveWorkspace ( ) {
24+ const data = Blockly . serialization . workspaces . save ( workspace ) ;
25+ const json = JSON . stringify ( data , null , 2 ) ;
26+ const blob = new Blob ( [ json ] , { type :"application/json" } ) ;
27+ const a = document . createElement ( "a" ) ;
28+ a . href = URL . createObjectURL ( blob ) ;
29+ let name = document . getElementById ( "projectName" ) . value . trim ( ) ;
30+ if ( ! name ) {
31+ name = "새 프로젝트" ;
32+ }
33+ a . download = name + ".mint" ; a . click ( ) ;
34+ showToast ( "프로젝트가 저장되었습니다!" , 2500 ) ;
35+ console . log ( "저장 완료" )
36+ }
37+
38+ function loadWorkspace ( event ) {
39+ const file = event . target . files [ 0 ] ;
40+ if ( ! file ) return ;
41+ const reader = new FileReader ( ) ;
42+ reader . onload = function ( e ) {
43+ const data = JSON . parse ( e . target . result ) ;
44+ workspace . clear ( ) ;
45+ Blockly . serialization . workspaces . load ( data , workspace ) ;
46+ } ;
47+ reader . readAsText ( file ) ;
48+ document . getElementById ( "projectName" ) . value =
49+ file . name . replace ( / \. m i n t $ / i, "" ) ;
50+ showToast ( "프로젝트가 로드되었습니다." , 2500 ) ;
51+ document . title = `MintCoding Editor - ${ document . getElementById ( "projectName" ) . value . trim ( ) } ` ;
52+ }
53+
54+ // Ctrl + S 저장
55+ window . addEventListener ( 'keydown' , function ( e ) {
56+ if ( ( e . ctrlKey || e . metaKey ) && e . key === 's' ) {
57+ e . preventDefault ( ) ;
58+ saveWorkspace ( ) ;
59+ }
60+ } ) ;
61+
62+ function showToast ( message , time ) {
63+ const toast = document . getElementById ( "toast" ) ;
64+ toast . textContent = message ;
65+ toast . classList . add ( "show" ) ;
66+
67+ setTimeout ( ( ) => {
68+ toast . classList . remove ( "show" ) ;
69+ } , time ) ;
70+ }
0 commit comments