2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  utils  from  '../services/utils.js' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  server  from  '../services/server.js' ;  
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  toastService  from  "../services/toast.js" ;  
						 
					
						
							
								
									
										
										
										
											2020-01-20 22:35:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  appContext  from  "../services/app_context.js" ;  
						 
					
						
							
								
									
										
										
										
											2020-10-30 15:06:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  libraryLoader  from  "../services/library_loader.js" ;  
						 
					
						
							
								
									
										
										
										
											2020-11-05 21:26:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  openService  from  "../services/open.js" ;  
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  $dialog  =  $ ( "#note-revisions-dialog" ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  $list  =  $ ( "#note-revision-list" ) ;  
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  $listDropdown  =  $ ( "#note-revision-list-dropdown" ) ;  
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const  $content  =  $ ( "#note-revision-content" ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  $title  =  $ ( "#note-revision-title" ) ;  
						 
					
						
							
								
									
										
										
										
											2019-11-09 08:53:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  $titleButtons  =  $ ( "#note-revision-title-buttons" ) ;  
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  $eraseAllRevisionsButton  =  $ ( "#note-revisions-erase-all-revisions-button" ) ;  
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$listDropdown . dropdown ( ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$listDropdown . parent ( ) . on ( 'hide.bs.dropdown' ,  e  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // prevent closing dropdown by clicking outside
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( e . clickEvent )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        e . preventDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								let  revisionItems  =  [ ] ;  
						 
					
						
							
								
									
										
										
										
											2018-11-14 14:52:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								let  note ;  
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								let  noteRevisionId ;  
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-02 19:56:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export  async  function  showCurrentNoteRevisions ( )  {  
						 
					
						
							
								
									
										
										
										
											2021-05-22 12:35:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await  showNoteRevisionsDialog ( appContext . tabManager . getActiveContextNoteId ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-20 21:40:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								export  async  function  showNoteRevisionsDialog ( noteId ,  noteRevisionId )  {  
						 
					
						
							
								
									
										
										
										
											2020-02-09 10:00:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    utils . openDialog ( $dialog ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await  loadNoteRevisions ( noteId ,  noteRevisionId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async  function  loadNoteRevisions ( noteId ,  noteRevId )  {  
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    $list . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $content . empty ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-07 23:14:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $titleButtons . empty ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-22 12:35:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    note  =  appContext . tabManager . getActiveContextNote ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-01 19:21:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    revisionItems  =  await  server . get ( ` notes/ ${ noteId } /revisions ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  item  of  revisionItems )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-07 23:02:46 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $list . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $ ( '<a class="dropdown-item" tabindex="0">' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . text ( item . dateLastEdited . substr ( 0 ,  16 )  +  `  ( ${ item . contentLength }  bytes) ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . attr ( 'data-note-revision-id' ,  item . noteRevisionId ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                . attr ( 'title' ,  'This revision was last edited on '  +  item . dateLastEdited ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $listDropdown . dropdown ( 'show' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    noteRevisionId  =  noteRevId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    if  ( revisionItems . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! noteRevisionId )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            noteRevisionId  =  revisionItems [ 0 ] . noteRevisionId ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        $title . text ( "No revisions for this note yet..." ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        noteRevisionId  =  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-07 23:14:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $eraseAllRevisionsButton . toggle ( revisionItems . length  >  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$dialog . on ( 'shown.bs.modal' ,  ( )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $list . find ( ` [data-note-revision-id=" ${ noteRevisionId } "] ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . trigger ( 'focus' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async  function  setContentPane ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  noteRevisionId  =  $list . find ( ".active" ) . attr ( 'data-note-revision-id' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  revisionItem  =  revisionItems . find ( r  =>  r . noteRevisionId  ===  noteRevisionId ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $titleButtons . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $content . empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-03-25 20:52:38 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    $title . html ( revisionItem . title ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-08 12:13:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-05-07 23:34:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  $restoreRevisionButton  =  $ ( '<button class="btn btn-sm" type="button">Restore this revision</button>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $restoreRevisionButton . on ( 'click' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  confirmDialog  =  await  import ( '../dialogs/confirm.js' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  text  =  'Do you want to restore this revision? This will overwrite current title/content of the note with this revision.' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( await  confirmDialog . confirm ( text ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  server . put ( ` notes/ ${ revisionItem . noteId } /restore-revision/ ${ revisionItem . noteRevisionId } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $dialog . modal ( 'hide' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            toastService . showMessage ( 'Note revision has been restored.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 16:51:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  $eraseRevisionButton  =  $ ( '<button class="btn btn-sm" type="button">Delete this revision</button>' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $eraseRevisionButton . on ( 'click' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  confirmDialog  =  await  import ( '../dialogs/confirm.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 16:51:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  text  =  'Do you want to delete this revision? This action will delete revision title and content, but still preserve revision metadata.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( await  confirmDialog . confirm ( text ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  server . remove ( ` notes/ ${ revisionItem . noteId } /revisions/ ${ revisionItem . noteRevisionId } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            loadNoteRevisions ( revisionItem . noteId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 16:51:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            toastService . showMessage ( 'Note revision has been deleted.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $titleButtons 
							 
						 
					
						
							
								
									
										
										
										
											2020-05-07 23:34:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . append ( $restoreRevisionButton ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . append ( '   ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . append ( $eraseRevisionButton ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . append ( '   ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 08:53:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  $downloadButton  =  $ ( '<button class="btn btn-sm btn-primary" type="button">Download</button>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-05 21:26:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $downloadButton . on ( 'click' ,  ( )  =>  openService . downloadNoteRevision ( revisionItem . noteId ,  revisionItem . noteRevisionId ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 08:53:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    $titleButtons . append ( $downloadButton ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 08:53:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-01 19:21:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  fullNoteRevision  =  await  server . get ( ` notes/ ${ revisionItem . noteId } /revisions/ ${ revisionItem . noteRevisionId } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 13:01:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( revisionItem . type  ===  'text' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-01 19:21:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $content . html ( fullNoteRevision . content ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-30 15:06:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( $content . find ( 'span.math-tex' ) . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            await  libraryLoader . requireLibrary ( libraryLoader . KATEX ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-08 14:58:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            renderMathInElement ( $content [ 0 ] ,  { trust :  true } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-30 15:06:11 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-08 12:13:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 13:01:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( revisionItem . type  ===  'code' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-01 19:21:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $content . html ( $ ( "<pre>" ) . text ( fullNoteRevision . content ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-08 12:13:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 13:01:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( revisionItem . type  ===  'image' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 23:09:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $content . html ( $ ( "<img>" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 08:53:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            // reason why we put this inline as base64 is that we do not want to let user to copy this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // as a URL to be used in a note. Instead if they copy and paste it into a note, it will be a uploaded as a new note
 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 23:09:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            . attr ( "src" ,  ` data: ${ note . mime } ;base64, `  +  fullNoteRevision . content ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            . css ( "max-width" ,  "100%" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . css ( "max-height" ,  "100%" ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 23:09:57 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 13:01:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( revisionItem . type  ===  'file' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  $table  =  $ ( "<table cellpadding='10'>" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( "<th>" ) . text ( "MIME: " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( "<td>" ) . text ( revisionItem . mime ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( "<th>" ) . text ( "File size:" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                $ ( "<td>" ) . text ( revisionItem . contentLength  +  " bytes" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( fullNoteRevision . content )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $table . append ( $ ( "<tr>" ) . append ( 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-13 23:09:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                $ ( '<td colspan="2">' ) . append ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $ ( '<div style="font-weight: bold;">' ) . text ( "Preview:" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 13:01:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    $ ( '<pre class="file-preview-content"></pre>' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        . text ( fullNoteRevision . content ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $content . html ( $table ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 11:58:52 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-09 15:51:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  if  ( revisionItem . type  ===  'canvas-note' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-10 13:55:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         *  FIXME :  We  load  a  font  called  Virgil . wof2 ,  which  originates  from  excalidraw . com 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         *         REMOVE  external  dependency ! ! ! !  This  is  defined  in  the  svg  in  defs . style 
							 
						 
					
						
							
								
									
										
											 
										
											
												missing path2d support for freedawings, remove node-side rendering, allow async getContent()
 * ## Excalidraw and SVG
 * 2022-04-16 - @thfrei
 *
 * Known issues:
 *  - excalidraw-to-svg (node.js) does not render any hand drawn (freedraw) paths. There is an issue with
 *    Path2D object not present in node-canvas library used by jsdom. (See Trilium PR for samples and other issues
 *    in respective library. Link will be added later). Related links:
 *     - https://github.com/Automattic/node-canvas/pull/2013
 *     - https://github.com/google/canvas-5-polyfill
 *     - https://github.com/Automattic/node-canvas/issues/1116
 *     - https://www.npmjs.com/package/path2d-polyfill
 *  - excalidraw-to-svg (node.js) takes quite some time to load an image (1-2s)
 *  - excalidraw-utils (browser) does render freedraw, however NOT freedraw with background
 *
 * Due to this issues, we opt to use **only excalidraw in the frontend**. Upon saving, we will also get the SVG
 * output from the live excalidraw instance. We will save this **SVG side by side the native excalidraw format
 * in the trilium note**.
 *
 * Pro: we will combat bit-rot. Showing the SVG will be very fast, since it is already rendered.
 * Con: The note will get bigger (maybe +30%?), we will generate more bandwith.
 *      (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably
 *       acceptable, as a trade off.)
											 
										 
										
											2022-04-19 00:21:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         * / 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-09 15:51:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  content  =  fullNoteRevision . content ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  data  =  JSON . parse ( content ) 
							 
						 
					
						
							
								
									
										
											 
										
											
												missing path2d support for freedawings, remove node-side rendering, allow async getContent()
 * ## Excalidraw and SVG
 * 2022-04-16 - @thfrei
 *
 * Known issues:
 *  - excalidraw-to-svg (node.js) does not render any hand drawn (freedraw) paths. There is an issue with
 *    Path2D object not present in node-canvas library used by jsdom. (See Trilium PR for samples and other issues
 *    in respective library. Link will be added later). Related links:
 *     - https://github.com/Automattic/node-canvas/pull/2013
 *     - https://github.com/google/canvas-5-polyfill
 *     - https://github.com/Automattic/node-canvas/issues/1116
 *     - https://www.npmjs.com/package/path2d-polyfill
 *  - excalidraw-to-svg (node.js) takes quite some time to load an image (1-2s)
 *  - excalidraw-utils (browser) does render freedraw, however NOT freedraw with background
 *
 * Due to this issues, we opt to use **only excalidraw in the frontend**. Upon saving, we will also get the SVG
 * output from the live excalidraw instance. We will save this **SVG side by side the native excalidraw format
 * in the trilium note**.
 *
 * Pro: we will combat bit-rot. Showing the SVG will be very fast, since it is already rendered.
 * Con: The note will get bigger (maybe +30%?), we will generate more bandwith.
 *      (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably
 *       acceptable, as a trade off.)
											 
										 
										
											2022-04-19 00:21:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  svg  =  data . svg  ||  "no svg present." 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-17 22:28:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            / * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             *  Debatable 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             *  maxWidth :  100 %  use  full  width  of  container  but  do  not  enlarge ! 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             *  height : auto  to  ensure  that  height  scales  with  width 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  svgHtml  =  $ ( svg ) . css ( { maxWidth :  "100%" ,  height :  "auto" } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $content . html ( $ ( '<div>' ) . append ( svgHtml ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-09 15:51:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }  catch ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            console . error ( "error parsing fullNoteRevision.content as JSON" ,  fullNoteRevision . content ,  err ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-10 13:55:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $content . html ( $ ( "<div>" ) . text ( "Error parsing content. Please check console.error() for more details." ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-10 16:03:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-09 15:51:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-14 14:52:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $content . text ( "Preview isn't available for this note type." ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$eraseAllRevisionsButton . on ( 'click' ,  async  ( )  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  confirmDialog  =  await  import ( '../dialogs/confirm.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 16:51:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  text  =  'Do you want to delete all revisions of this note? This action will erase revision title and content, but still preserve revision metadata.' ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( await  confirmDialog . confirm ( text ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        await  server . remove ( ` notes/ ${ note . noteId } /revisions ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $dialog . modal ( 'hide' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 16:51:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        toastService . showMessage ( 'Note revisions has been deleted.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 15:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-09 20:59:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$list . on ( 'click' ,  '.dropdown-item' ,  e  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   e . preventDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$list . on ( 'focus' ,  '.dropdown-item' ,  e  =>  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $list . find ( '.dropdown-item' ) . each ( ( i ,  el )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $ ( el ) . toggleClass ( 'active' ,  el  ===  e . target ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    setContentPane ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-13 23:09:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ) ;