Merge branch 'master' into toolbar

main
Jake Dexheimer 8 years ago
commit 459ede6765

@ -0,0 +1,6 @@
# Code
### Usage
- Drag a file onto the editor
- Append a GitHub Gist id to the url
- Paste your code directly!

@ -3,6 +3,7 @@ import React from 'react'
import domtoimage from 'dom-to-image' import domtoimage from 'dom-to-image'
import CodeMirror from 'react-codemirror' import CodeMirror from 'react-codemirror'
import WindowControls from '../components/svg/Controls' import WindowControls from '../components/svg/Controls'
import Spinner from 'react-spinner'
// hack to only call modes on browser // hack to only call modes on browser
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') { if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
@ -19,8 +20,24 @@ const DEFAULT_SETTINGS = {
language: 'javascript' language: 'javascript'
} }
const CodeImage = (props) => { class CodeImage extends React.Component {
const config = Object.assign(DEFAULT_SETTINGS, props.config)
constructor (props) {
super(props)
this.state = {
loading: true
}
}
componentDidMount() {
this.setState({
loading: false
})
}
render () {
const config = Object.assign(DEFAULT_SETTINGS, this.props.config)
const options = { const options = {
lineNumbers: false, lineNumbers: false,
@ -38,12 +55,30 @@ const CodeImage = (props) => {
paddingTop: `calc(${config.paddingVertical} - 19px)` // TODO fix hack: accomodates for space taken up by window controls paddingTop: `calc(${config.paddingVertical} - 19px)` // TODO fix hack: accomodates for space taken up by window controls
} }
return ( // set content to spinner if loading, else editor
<div id="section"> let content = (
<div>
<Spinner />
<style jsx>{`
div {
width: 680px;
height: 500px;
}
`}
</style>
</div>
)
if (this.state.loading === false) {
content = (
<div id="container" style={containerStyle}> <div id="container" style={containerStyle}>
{ true ? <WindowControls /> : null } <CodeMirror className="CodeMirrorContainer" value={this.props.children} options={options} />
<CodeMirror className="CodeMirrorContainer" value={props.children} options={options} />
</div> </div>
)
}
return (
<div id="section">
{ content }
<style jsx>{` <style jsx>{`
#section { #section {
height: 100%; height: 100%;
@ -55,5 +90,6 @@ const CodeImage = (props) => {
</div> </div>
) )
} }
}
export default CodeImage export default CodeImage

@ -14,6 +14,7 @@ export default () => (
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<link rel="shortcut icon" href="/static/favicon.ico" /> <link rel="shortcut icon" href="/static/favicon.ico" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/font-hack/2.020/css/hack-extended.min.css" /> <link rel="stylesheet" href="//cdn.jsdelivr.net/font-hack/2.020/css/hack-extended.min.css" />
<link rel="stylesheet" type="text/css" href="/static/react-spinner.css" />
</Head> </Head>
<style jsx>{` <style jsx>{`
.meta { .meta {

@ -19,12 +19,14 @@
"morgan": "^1.8.2", "morgan": "^1.8.2",
"next": "^2.4.3", "next": "^2.4.3",
"react": "^15.5.4", "react": "^15.5.4",
"react-codemirror": "^1.0.0",
"react-click-outside": "^2.3.1", "react-click-outside": "^2.3.1",
"react-codemirror": "^1.0.0",
"react-color": "^2.12.1", "react-color": "^2.12.1",
"react-dnd": "^2.4.0", "react-dnd": "^2.4.0",
"react-dnd-html5-backend": "^2.4.1", "react-dnd-html5-backend": "^2.4.1",
"react-dom": "^15.5.4", "react-dom": "^15.5.4",
"react-spinkit": "^3.0.0",
"react-spinner": "^0.2.7",
"react-syntax-highlight": "^0.0.6" "react-syntax-highlight": "^0.0.6"
} }
} }

@ -36,11 +36,10 @@ class Index extends React.Component {
save () { save () {
// domtoimage.toPng(document.getElementById('container')) // domtoimage.toPng(document.getElementById('container'))
domtoimage.toJpeg(document.getElementById('container')) domtoimage.toPng(document.getElementById('container'))
.then((dataUrl) => { .then((dataUrl) => {
const link = document.createElement('a') const link = document.createElement('a')
// link.download = 'snippet.png' link.download = 'snippet.png'
link.download = 'snippet.jpeg'
link.href = dataUrl link.href = dataUrl
link.click() link.click()
}) })

@ -0,0 +1,35 @@
.react-spinner {
position: relative;
width: 32px;
height: 32px;
top: 50%;
left: 50%;
}
.react-spinner_bar {
-webkit-animation: react-spinner_spin 1.2s linear infinite;
-moz-animation: react-spinner_spin 1.2s linear infinite;
animation: react-spinner_spin 1.2s linear infinite;
border-radius: 5px;
background-color: white;
position: absolute;
width: 20%;
height: 7.8%;
top: -3.9%;
left: -10%;
}
@keyframes react-spinner_spin {
0% { opacity: 1; }
100% { opacity: 0.15; }
}
@-moz-keyframes react-spinner_spin {
0% { opacity: 1; }
100% { opacity: 0.15; }
}
@-webkit-keyframes react-spinner_spin {
0% { opacity: 1; }
100% { opacity: 0.15; }
}

@ -1036,7 +1036,7 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
dependencies: dependencies:
inherits "^2.0.1" inherits "^2.0.1"
classnames@^2.2.5: classnames@^2.2.3, classnames@^2.2.5:
version "2.2.5" version "2.2.5"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d" resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
@ -2114,6 +2114,10 @@ loader-utils@^0.2.16:
json5 "^0.5.0" json5 "^0.5.0"
object-assign "^4.0.1" object-assign "^4.0.1"
loaders.css@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/loaders.css/-/loaders.css-0.1.2.tgz#3a9fb43726c73334a38142af9d0629019b658743"
locate-path@^2.0.0: locate-path@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@ -2841,6 +2845,19 @@ react-proxy@^3.0.0-alpha.0:
dependencies: dependencies:
lodash "^4.6.1" lodash "^4.6.1"
react-spinkit@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-spinkit/-/react-spinkit-3.0.0.tgz#31fdaf4e18177766c57d1b1f3330290f8492a85a"
dependencies:
classnames "^2.2.3"
loaders.css "^0.1.2"
object-assign "^4.1.0"
prop-types "^15.5.8"
react-spinner@^0.2.7:
version "0.2.7"
resolved "https://registry.yarnpkg.com/react-spinner/-/react-spinner-0.2.7.tgz#ea3ca3375dd7a54edbb5cc01d17496a2e2fc14db"
react-syntax-highlight@^0.0.6: react-syntax-highlight@^0.0.6:
version "0.0.6" version "0.0.6"
resolved "https://registry.yarnpkg.com/react-syntax-highlight/-/react-syntax-highlight-0.0.6.tgz#2a657a9a693ffd16a22181ad08de96902957f87a" resolved "https://registry.yarnpkg.com/react-syntax-highlight/-/react-syntax-highlight-0.0.6.tgz#2a657a9a693ffd16a22181ad08de96902957f87a"

Loading…
Cancel
Save