Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
spring-raining committed Jun 28, 2017
0 parents commit 487aeaa
Show file tree
Hide file tree
Showing 16 changed files with 2,294 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
@@ -0,0 +1,25 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

yarn.lock
package-lock.json

3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "brackets"]
path = brackets
url = https://github.com/pentapod/brackets.git
1,901 changes: 1,901 additions & 0 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions brackets
Submodule brackets added at 5d27b4
18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{
"name": "viola",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"react-scripts": "1.0.7"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
1 change: 1 addition & 0 deletions public/bramble
Binary file added public/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions public/index.html
@@ -0,0 +1,42 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<script src="%PUBLIC_URL%/bramble/bramble.js"></script>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions public/manifest.json
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
54 changes: 54 additions & 0 deletions src/App.css
@@ -0,0 +1,54 @@
.App {
text-align: center;
}

.App-header {
box-sizing: border-box;
text-align: center;
background-color: #222;
height: 40px;
padding: 10px;
color: white;
}

.App-brambleroot {
position: absolute;
top: 90px;
bottom: 0;
left: 0;
right: 0;
}

.ToolBar,
.ToolBar-filetree_pane,
.ToolBar-editor_pane,
.ToolBar-preview_pane {
height: 50px;
}

.ToolBar {
display: flex;
flex-direction: row;
}
.ToolBar > * {
box-sizing: border-box;
overflow: hidden;
}

.ToolBar-filetree_pane {
background-color: #222;
}

.ToolBar-editor_pane {
display: flex;
flex-direction: row;
align-items: center;
padding-left: 20px;
padding-right: 20px;
background-color: #3F3F3F;
color: #dcdcdc;
}

.ToolBar-preview_pane {
background-color: #EAEAEA;
}
86 changes: 86 additions & 0 deletions src/App.js
@@ -0,0 +1,86 @@
import React, { Component } from 'react';
import ToolBar from './ToolBar';
import './App.css';

const projectRoot = '/viola';
const index = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Viola index page</title>
</head>
<body>
</body>
</html>
`;

class App extends Component {

state = {
bramble: null,
};

ensureFiles = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
const fs = window.Bramble.getFileSystem();
console.log(fs);
fs.exists(projectRoot, (exists) => {
if (!exists) {
const sh = new fs.Shell();
const Path = window.Bramble.Filer.Path;
sh.mkdirp(projectRoot, (err) => {
if (err && err.code !== 'EEXIST') {
reject(err);
}
});
fs.writeFile(Path.join(projectRoot, ''), index, () => {
resolve();
});
}
resolve();
});
}, 1000);
});
}

componentDidMount() {
window.Bramble.load('#bramble-root', {
url: 'http://localhost:8000/dist/index.html',
debug: true,
useLocationSearch: true,
});

window.Bramble.once('error', (error) => {
console.error('Bramble error', error);
});

window.Bramble.on('ready', (bramble) => {
this.setState({
bramble: bramble,
})
});

this.ensureFiles().then(() => {
window.Bramble.mount(projectRoot, 'index.html');
});
}

render() {
const { bramble } = this.state;

return (
<div className="App">
<div className="App-header">
<div>Viola</div>
</div>
{this.state.bramble &&
<ToolBar {...{ bramble }} />
}
<div id="bramble-root" className="App-brambleroot"></div>
</div>
);
}
}

export default App;
8 changes: 8 additions & 0 deletions src/App.test.js
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
75 changes: 75 additions & 0 deletions src/ToolBar.js
@@ -0,0 +1,75 @@
import React from 'react';
import './App.css';

export default class ToolBar extends React.Component {

props: {
bramble: any,
};

state = {
filetreePaneWidth: 0,
editorPaneWidth: 0,
previewPaneWidth: 0,
filename: '',
};

initBramble = (bramble) => {
let nextState = Object.assign({}, this.state);
if (bramble.getLayout()) {
const data = bramble.getLayout();
nextState = Object.assign(nextState, {
filetreePaneWidth: data.sidebarWidth,
editorPaneWidth: data.firstPaneWidth,
previewPaneWidth: data.secondPaneWidth,
});
}
if (bramble.getFilename()) {
nextState = Object.assign(nextState, {
filename: bramble.getFilename(),
});
}
this.setState(nextState);

bramble.on('layout', this.updateLayout);
bramble.on('activeEditorChange', (data) => {
this.setNavFilename(data.filename);
});
};

updateLayout = (data) => {
this.setState(Object.assign({}, this.state, {
filetreePaneWidth: data.sidebarWidth,
editorPaneWidth: data.firstPaneWidth,
previewPaneWidth: data.secondPaneWidth,
}));
};

setNavFilename = (filename) => {
this.setState(Object.assign({}, this.state, {
filename,
}));
}

componentWillMount() {
this.initBramble(this.props.bramble);
}

render() {
const {
filetreePaneWidth,
editorPaneWidth,
previewPaneWidth,
} = this.state;

return (
<div className="ToolBar">
<div className="ToolBar-filetree_pane" style={{ flexBasis: filetreePaneWidth }}></div>
<div className="ToolBar-editor_pane" style={{ flexBasis: editorPaneWidth }}>
<span className="ToolBar-filename">{this.state.filename}</span>
</div>
<div className="ToolBar-preview_pane" style={{ flexBasis: previewPaneWidth }}></div>
</div>
);
}
}
6 changes: 6 additions & 0 deletions src/index.css
@@ -0,0 +1,6 @@
body {
margin: 0;
padding: 0;
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
8 changes: 8 additions & 0 deletions src/index.js
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import './index.css';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

0 comments on commit 487aeaa

Please sign in to comment.