1+ import Tooltip from '@codesandbox/common/lib/components/Tooltip' ;
2+ import { getModulePath } from '@codesandbox/common/lib/sandbox/modules' ;
3+ import getDefinition from '@codesandbox/common/lib/templates' ;
4+ import getUI from '@codesandbox/common/lib/templates/configuration/ui' ;
15import React from 'react' ;
2- import UIIcon from 'react-icons/lib/md/dvr' ;
36import QuestionIcon from 'react-icons/lib/go/question' ;
4- import getUI from '@codesandbox/common/lib/templates/configuration/ui' ;
5- import Centered from '@codesandbox/common/lib/components/flex/Centered' ;
6- import Margin from '@codesandbox/common/lib/components/spacing/Margin' ;
7- import isImage from '@codesandbox/common/lib/utils/is-image' ;
8- import getDefinition from '@codesandbox/common/lib/templates' ;
9- import { Sandbox } from '@codesandbox/common/lib/types' ;
10- import { getModulePath } from '@codesandbox/common/lib/sandbox/modules' ;
11- import Tooltip from '@codesandbox/common/lib/components/Tooltip' ;
12- import { Title } from 'app/components/Title' ;
13- import { SubTitle } from 'app/components/SubTitle' ;
14- import Loadable from 'app/utils/Loadable' ;
15- import { ImageViewer } from './ImageViewer' ;
16- import { Configuration } from './Configuration' ;
17- import { VSCode } from './VSCode' ;
18- import MonacoDiff from './MonacoDiff' ;
19- import { Props } from './types' ; // eslint-disable-line
20- import { Icons , Icon } from './elements' ;
21-
22- const CodeMirror = Loadable ( ( ) =>
23- import ( /* webpackChunkName: 'codemirror-editor' */ './CodeMirror' )
24- ) ;
25-
26- const Monaco = Loadable ( ( ) =>
27- import ( /* webpackChunkName: 'codemirror-editor' */ './Monaco' )
28- ) ;
29-
30- const getDependencies = ( sandbox : Sandbox ) : { [ key : string ] : string } => {
31- const packageJSON = sandbox . modules . find (
32- m => m . title === 'package.json' && m . directoryShortid == null
33- ) ;
34-
35- if ( packageJSON != null ) {
36- try {
37- const { dependencies = { } , devDependencies = { } } = JSON . parse (
38- packageJSON . code || ''
39- ) ;
40-
41- const usedDevDependencies = { } ;
42- Object . keys ( devDependencies ) . forEach ( d => {
43- if ( d . startsWith ( '@types' ) ) {
44- usedDevDependencies [ d ] = devDependencies [ d ] ;
45- }
46- } ) ;
7+ import UIIcon from 'react-icons/lib/md/dvr' ;
478
48- return { ...dependencies , ...usedDevDependencies } ;
49- } catch ( e ) {
50- console . error ( e ) ;
51- return null ;
52- }
53- } else {
54- return typeof sandbox . npmDependencies . toJS === 'function'
55- ? ( sandbox . npmDependencies as any ) . toJS ( )
56- : sandbox . npmDependencies ;
57- }
58- } ;
9+ import { Icon , Icons } from './elements' ;
10+ import { Props } from './types' ; // eslint-disable-line
11+ import { VSCode } from './VSCode' ;
5912
6013type State = {
6114 showConfigUI : boolean ;
@@ -79,38 +32,7 @@ export class CodeEditor extends React.PureComponent<
7932 render ( ) {
8033 const { props } = this ;
8134
82- const {
83- isModuleSynced,
84- currentTab,
85- sandbox,
86- currentModule : module ,
87- settings,
88- } = props ;
89-
90- if ( currentTab && currentTab . type === 'DIFF' ) {
91- return (
92- < div
93- style = { {
94- height : props . height || '100%' ,
95- width : props . width || '100%' ,
96- position : 'absolute' ,
97- top : 0 ,
98- left : 0 ,
99- right : 0 ,
100- bottom : 0 ,
101- } }
102- >
103- < MonacoDiff
104- originalCode = { currentTab . codeA }
105- modifiedCode = { currentTab . codeB }
106- title = { currentTab . fileTitle }
107- { ...props }
108- />
109- </ div >
110- ) ;
111- }
112-
113- const dependencies = getDependencies ( sandbox ) ;
35+ const { isModuleSynced, sandbox, currentModule : module , settings } = props ;
11436
11537 const template = getDefinition ( sandbox . template ) ;
11638 const modulePath = getModulePath (
@@ -120,57 +42,6 @@ export class CodeEditor extends React.PureComponent<
12042 ) ;
12143 const config = template . configurationFiles [ modulePath ] ;
12244
123- if (
124- ! settings . experimentVSCode &&
125- config &&
126- getUI ( config . type ) &&
127- this . state . showConfigUI
128- ) {
129- return (
130- < Configuration
131- { ...props }
132- dependencies = { dependencies }
133- config = { config }
134- toggleConfigUI = { this . toggleConfigUI }
135- />
136- ) ;
137- }
138-
139- if ( ! settings . experimentVSCode && module . isBinary ) {
140- if ( isImage ( module . title ) ) {
141- return < ImageViewer { ...props } dependencies = { dependencies } /> ;
142- }
143-
144- return (
145- < Margin
146- style = { {
147- overflow : 'auto' ,
148- height : props . height || '100%' ,
149- width : props . width || '100%' ,
150- } }
151- top = { 2 }
152- >
153- < Centered horizontal vertical >
154- < Title > This file is too big to edit</ Title >
155- < SubTitle >
156- We will add support for this as soon as possible.
157- </ SubTitle >
158-
159- < a href = { module . code } target = "_blank" rel = "noreferrer noopener" >
160- Open file externally
161- </ a >
162- </ Centered >
163- </ Margin >
164- ) ;
165- }
166-
167- let Editor : React . ComponentClass < Props > =
168- settings . codeMirror && ! props . isLive ? CodeMirror : Monaco ;
169-
170- if ( settings . experimentVSCode ) {
171- Editor = VSCode ;
172- }
173-
17445 return (
17546 < div
17647 style = { {
@@ -218,7 +89,7 @@ export class CodeEditor extends React.PureComponent<
21889 ) }
21990 </ Icons >
22091 ) ) }
221- < Editor { ... props } dependencies = { dependencies } />
92+ < VSCode />
22293 </ div >
22394 ) ;
22495 }
0 commit comments