import { Dialog } from '@jupyterlab/apputils' ; import { Widget } from '@lumino/widgets' ; import { Message } from '@lumino/messaging' ; import checkSVGstr from '../style/icon/jupyter_checkmark.svg' ; /**
 * The class name for message
 */ const CONFIRM_CONTENT = 'jp-codeSnippet-Message-content' ; const CONFIRM_BODY = 'jp-codeSnippet-Message-body' ; const CODE_SNIPPET_CONFIRM_TEXT = 'jp-codeSnippet-confirm-text' ; param options returns export function showMessage < T > ( type ) { const confirmMessage = new CodeSnippetMessage ( { body : new MessageHandler ( type ) , buttons : [ ] , } ) ; return confirmMessage . launch ( ) ; } /**
 * A widget used to show message.
 */ export class CodeSnippetMessage < T > extends Dialog < any > { constructor ( options = { } ) { super ( options ) ; this . children ( ) . next ( ) . addClass ( CONFIRM_CONTENT ) ; } protected onAfterAttach ( msg ) { const node = this . node ; node . addEventListener ( 'click' , this , true ) ; document . addEventListener ( 'keydown' , this , false ) ; } /**
     *  A message handler invoked on an `'after-detach'` message.
     */ protected onAfterDetach ( msg ) { const node = this . node ; node . removeEventListener ( 'click' , this , true ) ; document . removeEventListener ( 'keydown' , this , false ) ; } handleEvent ( event ) { switch ( event . type ) { case 'keydown' : this . _evtKeydown ( event as KeyboardEvent ) ; break ; case 'click' : this . _evtClick ( event as MouseEvent ) ; break ; } } protected _evtKeydown ( event ) { switch ( event . key ) { case 'Escape' : event . stopPropagation ( ) ; event . preventDefault ( ) ; this . reject ( ) ; break ; } } } class MessageHandler extends Widget { constructor ( type ) { super ( { node : Private . createMessageNode ( type ) } ) ; this . addClass ( CONFIRM_BODY ) ; } } /**
 * The namespace for module private data.
 */ namespace Private { export function createMessageNode ( type ) { const body = document . createElement ( 'div' ) ; body . innerHTML = checkSVGstr ; const messageContainer = document . createElement ( 'div' ) ; messageContainer . className = CODE_SNIPPET_CONFIRM_TEXT ; const message = document . createElement ( 'text' ) ; if ( type === 'confirm' ) { message . textContent = 'Saved as Snippet!' ; } else if ( type === 'copy' ) { message . textContent = 'Saved to Clipboard!' ; } else if ( type === 'export' ) { message . textContent = 'Exported the Snippet!' ; } messageContainer . appendChild ( message ) ; body . append ( messageContainer ) ; return body ; } }