Skip to content

Commit fe159c3

Browse files
cleanup and started testing
1 parent 9c73f24 commit fe159c3

File tree

38 files changed

+1039
-1745
lines changed

38 files changed

+1039
-1745
lines changed

packages/app/src/app/components/CodeEditor/VSCode/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import getTemplate from '@codesandbox/common/lib/templates';
22
import getUI from '@codesandbox/common/lib/templates/configuration/ui';
33
import theme from '@codesandbox/common/lib/theme';
44
import { useOvermind } from 'app/overmind';
5-
import { json } from 'overmind';
65
import React, { useEffect, useRef } from 'react';
76
import { render } from 'react-dom';
87
import { ThemeProvider } from 'styled-components';
@@ -55,8 +54,6 @@ export const VSCode: React.FunctionComponent = () => {
5554
.className.split(' ')
5655
.filter(x => !['monaco-shell', 'vs-dark'].includes(x))
5756
.join(' ');
58-
59-
effects.vscode.unmount();
6057
};
6158
}, [effects.vscode, state.editor.currentSandbox.template]);
6259

packages/app/src/app/components/CodeEditor/index.tsx

Lines changed: 10 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
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';
15
import React from 'react';
2-
import UIIcon from 'react-icons/lib/md/dvr';
36
import 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

6013
type 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

Comments
 (0)