import { injectNodeTemplate } from '@/components/node' ; import contextMenuHtml from './context-menu.html' ; import enlargeModalHtml from './enlarge-modal.html' ; const NODE_CONTENT_REGEX = /\s*<\!--\s*node-content\s*-->\s*[\r\n]+/ ; const CONTEXT_MENU_REGEX = /\s*<\!--\s*context-menu\s*-->\s*[\r\n]+/ ; param html const injectVisualizationTemplate = ( html ) : string => { let matched = html . match ( CONTEXT_MENU_REGEX ) ; if ( ! matched ) { html += '<!-- context-menu -->\n' + contextMenuHtml ; } else { const index = ( matched . index as number ) + matched [ 0 ] . length ; html = html . substr ( 0 , index ) + contextMenuHtml + html . substr ( index ) ; } matched = html . match ( NODE_CONTENT_REGEX ) ; if ( ! matched ) { console . error ( 'cannot inject a template without node content' ) ; } else { const index = ( matched . index as number ) + matched [ 0 ] . length ; html = html . substr ( 0 , index ) + enlargeModalHtml + html . substr ( index ) ; } return injectNodeTemplate ( html ) ; } ; export default injectVisualizationTemplate ;