@@ -32,7 +32,7 @@ import {CodeMirrorEditor} from './code-mirror-editor.service';
3232import { DiagnosticWithLocation , DiagnosticsState } from './services/diagnostics-state.service' ;
3333import { DownloadManager } from '../download-manager.service' ;
3434import { StackBlitzOpener } from '../stackblitz-opener.service' ;
35- import { ClickOutside , IconComponent } from '@angular/docs' ;
35+ import { IconComponent } from '@angular/docs' ;
3636import { CdkMenu , CdkMenuItem , CdkMenuTrigger } from '@angular/cdk/menu' ;
3737import { FirebaseStudioLauncher } from '../firebase-studio-launcher.service' ;
3838import { MatTooltip } from '@angular/material/tooltip' ;
@@ -51,15 +51,7 @@ const ANGULAR_DEV = 'https://angular.dev';
5151 templateUrl : './code-editor.component.html' ,
5252 styleUrls : [ './code-editor.component.scss' ] ,
5353 changeDetection : ChangeDetectionStrategy . OnPush ,
54- imports : [
55- MatTabsModule ,
56- MatTooltip ,
57- IconComponent ,
58- ClickOutside ,
59- CdkMenu ,
60- CdkMenuItem ,
61- CdkMenuTrigger ,
62- ] ,
54+ imports : [ MatTabsModule , MatTooltip , IconComponent , CdkMenu , CdkMenuItem , CdkMenuTrigger ] ,
6355} )
6456export class CodeEditor {
6557 readonly restrictedMode = input ( false ) ;
@@ -155,10 +147,6 @@ export class CodeEditor {
155147 this . displayErrorsBox . set ( false ) ;
156148 }
157149
158- protected closeRenameFile ( ) : void {
159- this . isRenamingFile . set ( false ) ;
160- }
161-
162150 protected canRenameFile = ( filename : string ) => this . canDeleteFile ( filename ) ;
163151
164152 protected canDeleteFile ( filename : string ) {
@@ -189,12 +177,7 @@ export class CodeEditor {
189177
190178 const renameFileInputValue = renameFileInput . nativeElement . value ;
191179
192- if ( renameFileInputValue ) {
193- if ( renameFileInputValue . includes ( '..' ) ) {
194- alert ( 'File name can not contain ".."' ) ;
195- return ;
196- }
197-
180+ if ( this . validateFileName ( renameFileInputValue ) ) {
198181 // src is hidden from users, here we manually add it to the new filename
199182 const newFile = 'src/' + renameFileInputValue ;
200183
@@ -209,20 +192,15 @@ export class CodeEditor {
209192 this . isRenamingFile . set ( false ) ;
210193 }
211194
212- protected async createFile ( event : SubmitEvent ) {
195+ protected async createFile ( event ? : SubmitEvent ) {
213196 const fileInput = this . createFileInputRef ( ) ;
214197 if ( ! fileInput ) return ;
215198
216- event . preventDefault ( ) ;
199+ event ? .preventDefault ( ) ;
217200
218201 const newFileInputValue = fileInput . nativeElement . value ;
219202
220- if ( newFileInputValue ) {
221- if ( newFileInputValue . includes ( '..' ) ) {
222- alert ( 'File name can not contain ".."' ) ;
223- return ;
224- }
225-
203+ if ( this . validateFileName ( newFileInputValue ) ) {
226204 // src is hidden from users, here we manually add it to the new filename
227205 const newFile = 'src/' + newFileInputValue ;
228206
@@ -237,6 +215,21 @@ export class CodeEditor {
237215 this . isCreatingFile . set ( false ) ;
238216 }
239217
218+ private validateFileName ( fileName : string ) : boolean {
219+ if ( ! fileName ) {
220+ return false ;
221+ }
222+ if ( fileName . split ( '/' ) . pop ( ) ?. indexOf ( '.' ) === 0 ) {
223+ alert ( 'File must contain a name.' ) ;
224+ return false ;
225+ }
226+ if ( fileName . includes ( '..' ) ) {
227+ alert ( 'File name can not contain ".."' ) ;
228+ return false ;
229+ }
230+ return true ;
231+ }
232+
240233 private listenToDiagnosticsChange ( ) : void {
241234 this . errors$ . subscribe ( ( diagnostics ) => {
242235 this . errors . set ( diagnostics ) ;
0 commit comments