@@ -9,6 +9,7 @@ self.MonacoEnvironment = {
99import * as monaco from 'monaco-editor' ;
1010import { ChatCompletionRunner } from 'openai/lib/ChatCompletionRunner.mjs' ;
1111import { ChatUI } from './chat' ;
12+ import { deleteFile } from './llmCall' ;
1213//import { getMonacoWorker } from './monaco-editor-workers.js';
1314
1415
@@ -84,7 +85,7 @@ class aiFiddleEditor {
8485 this . chatPanel . style . width = '20%' ;
8586 this . chatPanel . style . minWidth = '100px' ;
8687 this . chatPanel . style . borderRight = '1px solid #333' ;
87-
88+
8889
8990 this . editorPanel = createPanel ( ) ;
9091 this . editorPanel . style . width = '40%' ;
@@ -114,6 +115,86 @@ class aiFiddleEditor {
114115 this . iframeToolbar . style . fontSize = '14px' ;
115116 this . iframeToolbar . style . height = '33px' ;
116117
118+
119+ // add an open button using the unicode character for folder
120+ const openBtn = document . createElement ( 'button' ) ;
121+ openBtn . textContent = '📂'
122+ openBtn . style . background = '#555' ;
123+ openBtn . style . border = 'none' ;
124+ openBtn . style . color = '#fff' ;
125+ openBtn . style . cursor = 'pointer' ;
126+ openBtn . style . padding = '6px 10px' ;
127+ openBtn . onclick = ( ) => {
128+ // display a list of projects in the local storage and allow the user to select one
129+ const projects = Object . keys ( localStorage ) . filter ( key => key . endsWith ( '.project' ) ) ;
130+ const projectList = document . createElement ( 'dialog' ) ;
131+
132+ projectList . style . position = 'absolute' ;
133+ projectList . style . background = '#333' ;
134+ projectList . style . color = '#fff' ;
135+ projectList . style . padding = '10px' ;
136+ projectList . style . borderRadius = '5px' ;
137+
138+ projectList . style . zIndex = '10000' ;
139+ projectList . style . width = '200px' ;
140+ projectList . style . maxHeight = '300px' ;
141+ projectList . style . overflowY = 'scroll' ;
142+ projectList . style . overflowX = 'hidden' ;
143+ projectList . style . left = '10px' ;
144+ projectList . style . top = '10px' ;
145+ projectList . style . boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)' ;
146+ projectList . style . border = '1px solid #666' ;
147+ projectList . style . fontFamily = 'sans-serif' ;
148+ projectList . style . fontSize = '14px' ;
149+ projectList . style . fontWeight = 'bold' ;
150+
151+
152+ projects . forEach ( project => {
153+ const projectName = project . replace ( '.project' , '' ) ;
154+ const projectItem = document . createElement ( 'div' ) ;
155+ const projectRow = document . createElement ( 'div' ) ;
156+
157+ // add a trach icon to delete the project
158+ const deleteBtn = document . createElement ( 'button' ) ;
159+ deleteBtn . textContent = '🗑️'
160+ deleteBtn . style . background = 'none' ;
161+ deleteBtn . style . border = 'none' ;
162+ deleteBtn . style . color = '#fff' ;
163+ deleteBtn . style . cursor = 'pointer' ;
164+ deleteBtn . style . padding = '0px 5px' ;
165+ deleteBtn . onclick = ( e ) => {
166+ e . stopPropagation ( ) ;
167+ if ( confirm ( `Do you really want to delete the ${ projectName } project` ) ) deleteFile ( project ) ;
168+ document . body . removeChild ( projectList ) ;
169+ } ;
170+
171+ projectRow . appendChild ( deleteBtn ) ;
172+
173+
174+ projectItem . innerHTML += projectName ;
175+ projectItem . style . padding = '5px' ;
176+ projectItem . style . cursor = 'pointer' ;
177+ projectItem . style . borderBottom = '1px solid #444' ;
178+ projectItem . onclick = ( ) => {
179+ this . project . name = projectName ;
180+ this . loadProjectFromStorage ( ) ;
181+ this . setEditorValues ( ) ;
182+ this . saveProjectToStorage ( ) ;
183+ document . body . removeChild ( projectList ) ;
184+ } ;
185+
186+ projectRow . appendChild ( projectItem ) ;
187+ projectList . appendChild ( projectRow ) ;
188+ projectRow . style . display = 'flex' ;
189+ } ) ;
190+ document . body . appendChild ( projectList ) ;
191+
192+ projectList . showModal ( ) ;
193+ }
194+
195+ this . iframeToolbar . appendChild ( openBtn ) ;
196+
197+
117198 this . nameInput = document . createElement ( 'input' ) ;
118199 this . nameInput . placeholder = 'Project name' ;
119200 this . nameInput . style . flex = '1' ;
@@ -251,7 +332,14 @@ class aiFiddleEditor {
251332 this . editors [ tab ] . onDidChangeModelContent ( ( ) => this . saveEditorValues ( ) ) ;
252333 } ) ;
253334
254- this . nameInput . addEventListener ( 'input' , ( ) => this . saveEditorValues ( ) ) ;
335+ //this.nameInput.addEventListener('onChange', () => this.saveEditorValues());
336+
337+ // use the onchange event to save the project name
338+ this . nameInput . addEventListener ( 'change' , ( ) => {
339+ this . project . name = this . nameInput . value ;
340+ this . saveProjectToStorage ( ) ;
341+ } ) ;
342+
255343 this . switchTab ( 'HTML' ) ;
256344 }
257345
0 commit comments