import MIME from 'mime'; import { computed, observable } from 'mobx'; import { highlight, languages } from 'prismjs'; import { attribute, component, observer, WebCell, WebCellProps } from 'web-cell'; import { IconButton } from '../Form'; export interface CodeBlockProps extends WebCellProps { name?: string; value: string; language: string; theme?: string; } export interface CodeBlock extends WebCell {} @component({ tagName: 'code-block', mode: 'open' }) @observer export class CodeBlock extends HTMLElement implements WebCell { @attribute @observable accessor name = ''; @observable accessor value = ''; @attribute @observable accessor language = ''; @attribute @observable accessor theme = 'okaidia'; @computed get markup() { const { value, language } = this; return ( value && language && highlight(value, languages[language], language) ); } @computed get dataURI() { return URL.createObjectURL( new Blob([this.value], { type: MIME.getType(this.name) }) ); } connectedCallback() { this.classList.add( 'd-block', 'bg-dark', 'rounded', 'p-3', 'position-relative' ); } render() { const { name, dataURI, theme, markup } = this; return ( <> {name && ( )}
            
        );
    }
}