import Centered from '@codesandbox/common/lib/components/flex/Centered'; import Margin from '@codesandbox/common/lib/components/spacing/Margin'; import { withTheme } from 'styled-components'; import Tooltip from '@codesandbox/common/lib/components/Tooltip'; import { getModulePath } from '@codesandbox/common/lib/sandbox/modules'; import getDefinition from '@codesandbox/common/lib/templates'; import getUI from '@codesandbox/common/lib/templates/configuration/ui'; import { Sandbox } from '@codesandbox/common/lib/types'; import isImage from '@codesandbox/common/lib/utils/is-image'; import { Configuration } from 'app/components/CodeEditor/Configuration'; import { Icon, Icons } from 'app/components/CodeEditor/elements'; import { Props } from 'app/components/CodeEditor/types'; // eslint-disable-line import { SubTitle } from 'app/components/SubTitle'; import { Title } from 'app/components/Title'; import { Loadable } from 'app/utils/Loadable'; import React from 'react'; import UIIcon from 'react-icons/lib/md/dvr'; import { ThemeProvider } from '@codesandbox/components'; import { ImageViewer } from './ImageViewer'; import MonacoDiff from './MonacoDiff'; const CodeMirror = Loadable( () => import( /* webpackChunkName: 'codemirror-editor' */ 'app/components/CodeEditor/CodeMirror' ) ); const Monaco = Loadable( () => import(/* webpackChunkName: 'monaco-editor' */ './Monaco') ); const getDependencies = (sandbox: Sandbox): { [key: string]: string } => { const packageJSON = sandbox.modules.find( m => m.title === 'package.json' && m.directoryShortid == null ); if (packageJSON != null) { try { const { dependencies = {}, devDependencies = {} } = JSON.parse( packageJSON.code || '' ); const usedDevDependencies = {}; Object.keys(devDependencies).forEach(d => { if (d.startsWith('@types')) { usedDevDependencies[d] = devDependencies[d]; } }); return { ...dependencies, ...usedDevDependencies }; } catch (e) { console.error(e); return null; } } else { return typeof sandbox.npmDependencies.toJS === 'function' ? (sandbox.npmDependencies as any).toJS() : sandbox.npmDependencies; } }; type State = { showConfigUI: boolean; }; class CodeEditorComponent extends React.PureComponent< Props & { editor?: 'vscode' | 'monaco' | 'codemirror'; style?: React.CSSProperties; }, State > { state = { showConfigUI: true, }; toggleConfigUI = () => { this.setState(state => ({ showConfigUI: !state.showConfigUI })); }; render() { const { props } = this; const { isModuleSynced, currentTab, sandbox, currentModule: module, settings, } = props; if (currentTab && currentTab.type === 'DIFF') { return (