import { injectable } from 'inversify' ; import { SModelElementSchema , RequestPopupModelAction , SModelRootSchema , PreRenderedElementSchema , IPopupModelProvider } from 'sprotty' ; import { DependencyGraphNodeSchema } from './graph-model' ; @ injectable ( ) export class PopupModelProvider implements IPopupModelProvider { getPopupModel ( request , element ? ) { if ( element && element . type === 'node' ) { const node = element as DependencyGraphNodeSchema ; const titleClass = 'sprotty-popup-title' ; let version = '' ; if ( node . version ) version = `<span class="popup-info-version">${ node . version }</span>` ; let title ; if ( node . url ) title = `<a href="${ node . url }">${ node . name }</a>${ version }` ; else title = `${ node . name }${ version }` ; let bodyClass = 'sprotty-popup-body' ; if ( node . error ) bodyClass += ' error' ; else if ( ! node . resolved ) bodyClass += ' unresolved' ; let body = '' ; if ( node . error ) body = escapeHTML ( node . error ) ; else if ( node . description ) body = escapeHTML ( node . description ) ; else if ( ! node . resolved ) body = 'This package has not been resolved yet. Select it to trigger resolution of package metadata.' ; return { type : 'html' , id : 'popup' , children : [ < PreRenderedElementSchema > { type : 'pre-rendered' , id : 'popup-title' , code : `<div class="${ titleClass }">${ title }</div>` } , < PreRenderedElementSchema > { type : 'pre-rendered' , id : 'popup-body' , code : `<div class="${ bodyClass }">${ body }</div>` } ] } ; } return undefined ; } } function escapeHTML ( s ) { return s . replace ( /&/g , '&amp;' ) . replace ( /</g , '&lt;' ) . replace ( />/g , '&gt;' ) ; }