Skip to content

Commit 0abfc45

Browse files
authored
Binary support (codesandbox#284)
* Move to workspaces * Enable experimental workspaces * Lerna * Intermediate * Nice * Intermediate * Progress * Reorganize * Binary support * Test commit * UI * More commits * changes * Better support * Fix eslint * Updates * Almost done * Change Prettier * Fix tests * Build api before linting * Update CirleCI image * Add flag * Perf improvements * Perf improvements * IE11 support * Performance improvements * Fix scaling * Fix build script * Update config * Fix Gatsby static assets * Fix host * Wave adjustment * Fix URL of embed * Fix width artifacts for 1280px width * Update media queries * Fix false positives for low performance mode * Update footer & process feedback * Add 'New Sandbox' page * Update navigation button * Fix tests * Add entry fallback for smoother deployment * Export to GitHub * Fix ESLint * Fix ESLint * Fix merge conflict in yarn.lock * Add new article to homepage
1 parent 9e77c46 commit 0abfc45

File tree

73 files changed

+2145
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2145
-414
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"globals": {
1111
"Raven": true,
12-
"VERSION": true
12+
"VERSION": true,
13+
"$PropertyType": true
1314
},
1415
"rules": {
1516
"react/jsx-filename-extension": 0,

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.2.1
1+
FROM node:9
22
LABEL maintainer "Ives van Hoorne"
33

44
RUN mkdir /usr/src/app

Dockerfile.prod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.2.1
1+
FROM node:9
22
LABEL maintainer "Ives van Hoorne"
33

44
COPY package.json /app/package.json

config/webpack.common.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ module.exports = {
5353

5454
module: {
5555
rules: [
56-
{
57-
test: /\.js$/,
58-
loader: 'eslint-loader',
59-
enforce: 'pre',
60-
include: [paths.appSrc, paths.embedSrc],
61-
},
6256
{
6357
test: /\.js$/,
6458
include: [paths.src, /@emmetio/],

config/webpack.prod.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const merge = require('webpack-merge');
22
const webpack = require('webpack');
33
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
44
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
5+
const ManifestPlugin = require('webpack-manifest-plugin');
56
const childProcess = require('child_process');
67
const commonConfig = require('./webpack.common');
78

@@ -212,5 +213,8 @@ module.exports = merge(commonConfig, {
212213
// You can remove this if you don't use Moment.js:
213214
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
214215
new webpack.IgnorePlugin(/\/src\/node_modules/),
216+
new ManifestPlugin({
217+
fileName: 'file-manifest.json',
218+
}),
215219
],
216220
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"webpack-bundle-analyzer": "^2.9.0",
8787
"webpack-dev-middleware": "^1.11.0",
8888
"webpack-dev-server": "^2.5.1",
89+
"webpack-manifest-plugin": "^1.3.2",
8990
"webpack-merge": "^4.1.0",
9091
"whatwg-fetch": "^2.0.3",
9192
"worker-loader": "^0.8.1"
@@ -127,6 +128,7 @@
127128
"gulp-rev": "^7.1.2",
128129
"hash-sum": "^1.0.2",
129130
"humps": "CompuIves/humps",
131+
"is-image": "^2.0.0",
130132
"jszip": "^3.1.3",
131133
"lodash": "^4.17.2",
132134
"match-sorter": "^1.8.1",

src/app/components/Input.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import styled from 'styled-components';
22

3-
export default styled.input`
3+
const Input = styled.input`
44
transition: 0.3s ease border-color;
55
background-color: rgba(0, 0, 0, 0.3);
66
border: none;
77
outline: none;
88
border-radius: 4px;
99
color: white;
1010
padding: 0.25em;
11-
width: inherit;
11+
width: ${({ block }) => (block ? '100%' : 'inherit')};
1212
box-sizing: border-box;
1313
1414
border: 1px solid
@@ -19,3 +19,7 @@ export default styled.input`
1919
border-color: ${props => props.theme.secondary.clearer(0.6)};
2020
}
2121
`;
22+
23+
export default Input;
24+
25+
export const TextArea = Input.withComponent('textarea');
File renamed without changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
import Centered from 'app/components/flex/Centered';
5+
import Input from 'app/components/Input';
6+
import Button from 'app/components/buttons/Button';
7+
8+
const Container = styled(Centered)`
9+
height: 100%;
10+
color: rgba(255, 255, 255, 0.9);
11+
`;
12+
13+
const Title = styled.div`
14+
font-size: 2rem;
15+
margin-top: 3rem;
16+
margin: 1rem 0;
17+
`;
18+
19+
const SubTitle = styled.div`
20+
font-size: 1.5rem;
21+
color: rgba(255, 255, 255, 0.7);
22+
`;
23+
24+
const Image = styled.img`
25+
margin-top: 2rem;
26+
margin-bottom: 1rem;
27+
28+
max-width: 80%;
29+
max-height: 70%;
30+
`;
31+
32+
const MaxWidth = styled.form`
33+
display: flex;
34+
justify-content: centered;
35+
flex-direction: row;
36+
width: 80%;
37+
38+
input {
39+
flex: 4;
40+
font-size: 1.5rem;
41+
}
42+
43+
button {
44+
flex: 1;
45+
margin-left: 1rem;
46+
}
47+
`;
48+
49+
type Props = {
50+
id: string,
51+
code: string,
52+
title: string,
53+
isNotSynced: boolean,
54+
changeCode: (id: string, code: string) => Object,
55+
saveCode: ?() => void,
56+
};
57+
58+
export default class ImageViewer extends React.Component<Props> {
59+
onSubmit = e => {
60+
e.preventDefault();
61+
62+
this.props.saveCode();
63+
};
64+
65+
changeCode = e => {
66+
this.props.changeCode(this.props.id, e.target.value);
67+
};
68+
69+
render() {
70+
return (
71+
<Container horizontal>
72+
<Title>Image</Title>
73+
<SubTitle>
74+
We refer to these files by URL, you can edit this url to change the
75+
image.
76+
</SubTitle>
77+
78+
<Image src={this.props.code} alt={this.props.title} />
79+
80+
<MaxWidth onSubmit={this.onSubmit}>
81+
<Input
82+
innerRef={el => {
83+
this.input = el;
84+
}}
85+
onChange={this.changeCode}
86+
value={this.props.code}
87+
/>
88+
<Button disabled={!this.props.isNotSynced} type="submit">
89+
Save
90+
</Button>
91+
</MaxWidth>
92+
</Container>
93+
);
94+
}
95+
}

src/app/components/sandbox/CodeEditor/index.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import React from 'react';
22
import Loadable from 'react-loadable';
3+
34
import Loading from 'app/components/Loading';
4-
import { Preferences } from 'common/types';
5+
import Title from 'app/components/text/Title';
6+
import SubTitle from 'app/components/text/SubTitle';
7+
import Centered from 'app/components/flex/Centered';
8+
import Margin from 'app/components/spacing/Margin';
9+
import { Preferences, Module, Directory } from 'common/types';
10+
11+
import isImage from 'is-image';
512

613
import Monaco from './Monaco';
14+
import ImageViewer from './ImageViewer';
715

816
type Props = {
917
preferences: Preferences,
18+
id: string,
19+
modules: Array<Module>,
20+
directories: Array<Directory>,
21+
changeCode: (id: string, code: string) => Object,
22+
saveCode: ?() => void,
1023
};
1124

1225
const CodeMirror = Loadable({
@@ -15,6 +28,40 @@ const CodeMirror = Loadable({
1528
});
1629

1730
export default (props: Props) => {
31+
const module = props.modules.find(m => m.id === props.id);
32+
33+
if (module) {
34+
if (module.isBinary) {
35+
if (isImage(module.title)) {
36+
return (
37+
<ImageViewer
38+
changeCode={props.changeCode}
39+
saveCode={props.saveCode}
40+
code={module.code}
41+
title={module.title}
42+
id={module.id}
43+
isNotSynced={module.isNotSynced}
44+
/>
45+
);
46+
}
47+
48+
return (
49+
<Margin top={2}>
50+
<Centered horizontal vertical>
51+
<Title>This file is too big to edit</Title>
52+
<SubTitle>
53+
We will add support for this as soon as possible.
54+
</SubTitle>
55+
56+
<a href={module.code} target="_blank" rel="noreferrer noopener">
57+
Open file externally
58+
</a>
59+
</Centered>
60+
</Margin>
61+
);
62+
}
63+
}
64+
1865
// We are phasing towards Monaco, the only thing missing is vim mode. So use
1966
// CodeMirror until we have proper support
2067
if (props.preferences.vimMode || props.preferences.codeMirror) {

0 commit comments

Comments
 (0)