@@ -154,7 +154,7 @@ export class TreeView implements ITreeInterface {
154
154
1 ,
155
155
{
156
156
...node ,
157
- ...extra ,
157
+ ...extra
158
158
}
159
159
) ;
160
160
this . updateChildren ( parentIndex [ this . childNodeName ] ) ;
@@ -164,12 +164,14 @@ export class TreeView implements ITreeInterface {
164
164
165
165
updateChildren ( children : IIndex ) {
166
166
const self = this ;
167
- children . forEach ( function ( id , i ) {
168
- const index = self . getIndex ( id ) ;
169
- index . prev = index . next = null ;
170
- if ( i > 0 ) index . prev = children [ i - 1 ] ;
171
- if ( i < children . length - 1 ) index . next = children [ i + 1 ] ;
172
- } ) ;
167
+ children . forEach (
168
+ function ( id , i ) {
169
+ const index = self . getIndex ( id ) ;
170
+ index . prev = index . next = null ;
171
+ if ( i > 0 ) index . prev = children [ i - 1 ] ;
172
+ if ( i < children . length - 1 ) index . next = children [ i + 1 ] ;
173
+ }
174
+ ) ;
173
175
}
174
176
175
177
insert ( obj : ITreeNodeItem , parentId : number , i : number ) {
@@ -220,6 +222,7 @@ export class TreeView implements ITreeInterface {
220
222
}
221
223
}
222
224
225
+
223
226
export interface IExplorerService extends Component < IExplorer > {
224
227
addPanel ( panel : IPanelItem | IPanelItem [ ] ) : void ;
225
228
reset ( ) : void ;
@@ -272,16 +275,13 @@ export class ExplorerService
272
275
next . splice ( index , 1 ) ;
273
276
}
274
277
this . setState ( {
275
- data : next ,
278
+ data : next
276
279
} ) ;
277
280
}
278
281
279
282
/* ============================Tree============================ */
280
283
281
- private getFileIconByExtensionName (
282
- name : string ,
283
- fileType : FileType
284
- ) : string {
284
+ private getFileIconByExtensionName ( name : string , fileType : FileType ) : string {
285
285
if ( fileType === FileTypes . FOLDER ) return '' ;
286
286
const fileExtension = name && name . split ( '.' ) ?. [ 1 ] ;
287
287
let icon = 'symbol-file' ;
@@ -310,19 +310,15 @@ export class ExplorerService
310
310
311
311
private getCurrentRootFolderAndIndex ( id : number ) {
312
312
const currentRootFolder : ITreeNodeItem = this . getRootFolderById ( id ) ;
313
- const index = this . getRootFolderIndexByRootId (
314
- ( currentRootFolder as any ) . id
315
- ) ;
313
+ const index = this . getRootFolderIndexByRootId ( ( currentRootFolder as any ) . id ) as number ;
316
314
return {
317
315
index,
318
- currentRootFolder,
319
- } ;
316
+ currentRootFolder
317
+ }
320
318
}
321
319
322
- public getRootFolderIndexByRootId ( id : number ) : number {
323
- return this . state . folderTree ?. data ! . findIndex (
324
- ( folder ) => folder . id === id
325
- ) ;
320
+ public getRootFolderIndexByRootId ( id : number ) : number | undefined {
321
+ return this . state . folderTree ?. data ! . findIndex ( ( folder ) => folder . id === id ) ;
326
322
}
327
323
328
324
public getRootFolderByRootId ( id : number ) : ITreeNodeItem | undefined {
@@ -331,12 +327,12 @@ export class ExplorerService
331
327
332
328
public getRootFolderById ( id : number ) : ITreeNodeItem {
333
329
let rootNode = { } ;
334
- this . state . folderTree ?. data ?. forEach ( ( folder ) => {
330
+ this . state . folderTree ?. data ?. forEach ( folder => {
335
331
const treeInstance = new TreeView ( folder ) ;
336
332
if ( treeInstance . get ( id ) ) {
337
333
rootNode = folder ;
338
334
}
339
- } ) ;
335
+ } )
340
336
return rootNode ;
341
337
}
342
338
@@ -349,123 +345,107 @@ export class ExplorerService
349
345
next ?. push ( folder ) ;
350
346
}
351
347
this . setState ( {
352
- folderTree : { ...folderTree , data : next } ,
348
+ folderTree : { ...folderTree , data : next }
353
349
} ) ;
354
350
}
355
351
356
352
public removeRootFolder ( id : number ) {
357
353
const { folderTree } = this . state ;
358
354
const next = [ ...folderTree ?. data ! ] ;
359
- const index = this . getRootFolderIndexByRootId ( id ) ;
355
+ const index = this . getRootFolderIndexByRootId ( id ) as number ;
360
356
if ( index > - 1 ) {
361
357
next . splice ( index , 1 ) ;
362
358
}
363
359
this . setState ( {
364
- folderTree : { ...folderTree , data : next } ,
360
+ folderTree : { ...folderTree , data : next }
365
361
} ) ;
366
362
}
367
363
368
364
public updateFile ( file , callback ) {
369
365
const { folderTree } = this . state ;
370
366
const { id, name, fileType } = file ;
371
367
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
372
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
373
- id
374
- ) ;
368
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
375
369
const tree = new TreeView ( currentRootFolder ) ;
376
370
if ( name ) {
377
371
tree . update ( id , {
378
372
...file ,
379
373
icon : this . getFileIconByExtensionName ( name , fileType ) ,
380
- modify : false ,
381
- } ) ;
374
+ modify : false
375
+ } )
382
376
} else {
383
- tree . remove ( id ) ;
377
+ tree . remove ( id )
384
378
}
385
379
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
386
380
this . setState ( {
387
- folderTree : { ...folderTree , data : cloneData } ,
381
+ folderTree : { ...folderTree , data : cloneData }
388
382
} ) ;
389
383
if ( callback ) callback ( ) ;
390
384
}
391
385
392
386
public rename ( id : number , callback ?: Function ) {
393
387
const { folderTree } = this . state ;
394
388
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
395
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
396
- id
397
- ) ;
389
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
398
390
const tree = new TreeView ( currentRootFolder ) ;
399
391
tree . update ( id , {
400
- modify : true ,
401
- } ) ;
392
+ modify : true
393
+ } )
402
394
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
403
395
this . setState ( {
404
- folderTree : { ...folderTree , data : cloneData } ,
396
+ folderTree : { ...folderTree , data : cloneData }
405
397
} ) ;
406
398
if ( callback ) callback ( ) ;
407
399
}
408
400
409
401
public delete ( id : number , callback ?: Function ) {
410
402
const { folderTree } = this . state ;
411
403
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
412
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
413
- id
414
- ) ;
404
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
415
405
const tree = new TreeView ( currentRootFolder ) ;
416
406
tree . remove ( id ) ;
417
407
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
418
408
this . setState ( {
419
- folderTree : { ...folderTree , data : cloneData } ,
409
+ folderTree : { ...folderTree , data : cloneData }
420
410
} ) ;
421
411
if ( callback ) callback ( ) ;
422
412
}
423
413
424
414
public newFile ( parentId : number , callback ?: Function ) {
425
415
const { folderTree } = this . state ;
426
416
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
427
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
428
- parentId
429
- ) ;
417
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( parentId )
430
418
const tree = new TreeView ( currentRootFolder ) ;
431
419
if ( ! parentId ) {
432
420
const tabData = {
433
421
id : `${ Math . random ( ) * 10 + 1 } ` ,
434
422
name : `Untitled` ,
435
- modified : false ,
423
+ modified : false
436
424
} ;
437
- editorService . open ( tabData ) ;
425
+ editorService . open ( tabData )
438
426
}
439
- tree . append (
440
- new TreeNodeModel ( {
441
- modify : true ,
442
- } ) ,
443
- parentId
444
- ) ;
427
+ tree . append ( new TreeNodeModel ( {
428
+ modify : true
429
+ } ) , parentId )
445
430
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
446
431
this . setState ( {
447
- folderTree : { ...folderTree , data : cloneData } ,
432
+ folderTree : { ...folderTree , data : cloneData }
448
433
} ) ;
449
434
if ( callback ) callback ( ) ;
450
435
}
451
436
452
437
public newFolder ( parentId , callback : Function ) {
453
438
const { folderTree } = this . state ;
454
439
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
455
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
456
- parentId
457
- ) ;
440
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( parentId )
458
441
const tree = new TreeView ( currentRootFolder ) ;
459
- tree . append (
460
- new TreeNodeModel ( {
461
- fileType : FileTypes . FOLDER as FileType ,
462
- modify : true ,
463
- } ) ,
464
- parentId
465
- ) ;
442
+ tree . append ( new TreeNodeModel ( {
443
+ fileType : FileTypes . FOLDER as FileType ,
444
+ modify : true
445
+ } ) , parentId )
466
446
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
467
447
this . setState ( {
468
- folderTree : { ...folderTree , data : cloneData } ,
448
+ folderTree : { ...folderTree , data : cloneData }
469
449
} ) ;
470
450
if ( callback ) callback ( ) ;
471
451
}
@@ -477,4 +457,5 @@ export class ExplorerService
477
457
} ) ,
478
458
} ) ;
479
459
} ;
460
+
480
461
}
0 commit comments