-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace buble with babel, react-live with codemirror
- Loading branch information
Showing
10 changed files
with
183 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,27 @@ | ||
/** | ||
* react-live does not support React 14. For this version, just return | ||
* a textarea. | ||
* | ||
* TODO: Could we just get rid of react-live? It only adds syntax highlighting | ||
*/ | ||
import 'codemirror/lib/codemirror.css'; | ||
import './codemirror-gruvbox-dark.css'; | ||
import 'codemirror/mode/jsx/jsx'; | ||
|
||
import semver from 'semver'; | ||
import {LiveProvider, LiveEditor, LiveError} from 'react-live'; | ||
import CodeMirror from 'react-codemirror'; | ||
|
||
const React = window.React; | ||
const supportsReactLive = semver(React.version).major > 1; // React 15 or higher | ||
|
||
export class CodeProvider extends React.Component { | ||
render() { | ||
const {code, children} = this.props; | ||
|
||
if (supportsReactLive) { | ||
return <LiveProvider code={code} children={children} />; | ||
} | ||
|
||
return <div>{children}</div>; | ||
} | ||
} | ||
const options = { | ||
lineNumbers: true, | ||
mode: 'jsx', | ||
theme: 'gruvbox-dark', | ||
}; | ||
|
||
export class CodeEditor extends React.Component { | ||
render() { | ||
const {code, onChange} = this.props; | ||
|
||
if (supportsReactLive) { | ||
return <LiveEditor onChange={onChange} />; | ||
} | ||
|
||
return ( | ||
<textarea value={code} onChange={event => onChange(event.target.value)} /> | ||
); | ||
return <CodeMirror value={code} options={options} onChange={onChange} />; | ||
} | ||
} | ||
|
||
export class CodeError extends React.Component { | ||
render() { | ||
let {error, className} = this.props; | ||
|
||
if (supportsReactLive) { | ||
return <LiveError className={className} />; | ||
} | ||
|
||
return error ? <div className={className}>{error.message}</div> : null; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
fixtures/dom/src/components/fixtures/hydration/code-transformer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Babel works across all browsers, however it requires many polyfills. | ||
*/ | ||
|
||
import 'core-js/es6/weak-map'; | ||
import 'core-js/es6/weak-set'; | ||
import 'core-js/es6/number'; | ||
import 'core-js/es6/string'; | ||
import 'core-js/es6/array'; | ||
|
||
import {transform} from '@babel/standalone'; | ||
|
||
const presets = ['es2015', 'stage-3', 'react']; | ||
|
||
export function compile(raw) { | ||
return transform(raw, {presets}).code; | ||
} |
34 changes: 34 additions & 0 deletions
34
fixtures/dom/src/components/fixtures/hydration/codemirror-gruvbox-dark.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Name: gruvbox-dark | ||
Author: kRkk (https://github.com/krkk) | ||
Original gruvbox color scheme by Pavel Pertsev (https://github.com/morhetz/gruvbox) | ||
*/ | ||
|
||
.cm-s-gruvbox-dark.CodeMirror, .cm-s-gruvbox-dark .CodeMirror-gutters { background-color: #282828; color: #bdae93; } | ||
.cm-s-gruvbox-dark .CodeMirror-gutters {background: #282828; border-right: 0px;} | ||
.cm-s-gruvbox-dark .CodeMirror-linenumber {color: #7c6f64;} | ||
.cm-s-gruvbox-dark .CodeMirror-cursor { border-left: 1px solid #ebdbb2; } | ||
.cm-s-gruvbox-dark div.CodeMirror-selected { background: #928374; } | ||
.cm-s-gruvbox-dark span.cm-meta { color: #808000; } | ||
|
||
.cm-s-gruvbox-dark span.cm-comment { color: #928374; } | ||
.cm-s-gruvbox-dark span.cm-number, span.cm-atom { color: #d3869b; } | ||
.cm-s-gruvbox-dark span.cm-keyword { color: #f84934; } | ||
|
||
.cm-s-gruvbox-dark span.cm-variable { color: #ebdbb2; } | ||
.cm-s-gruvbox-dark span.cm-variable-2 { color: #ebdbb2; } | ||
.cm-s-gruvbox-dark span.cm-variable-3, .cm-s-gruvbox-dark span.cm-type { color: black; } | ||
.cm-s-gruvbox-dark span.cm-operator { color: #ebdbb2; } | ||
.cm-s-gruvbox-dark span.cm-def { color: #ebdbb2; } | ||
.cm-s-gruvbox-dark span.cm-string { color: #b8bb26; } | ||
.cm-s-gruvbox-dark span.cm-string-2 { color: #8ec07c; } | ||
.cm-s-gruvbox-dark span.cm-qualifier { color: #555; } | ||
.cm-s-gruvbox-dark span.cm-attribute { color: #8ec07c; } | ||
|
||
.cm-s-gruvbox-dark .CodeMirror-activeline-background { background: #3c3836; } | ||
.cm-s-gruvbox-dark .CodeMirror-matchingbracket { background: #928374; color:#282828 !important; } | ||
|
||
.cm-s-gruvbox-dark span.cm-builtin { color: #fe8019; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import 'core-js/es6/symbol'; | ||
import 'core-js/es6/promise'; | ||
import 'core-js/es6/set'; | ||
import 'core-js/es6/map'; | ||
|
Oops, something went wrong.