-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
816 additions
and
847 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es6: true, | ||
commonjs: true | ||
}, | ||
extends: 'eslint:recommended', | ||
rules: { | ||
quotes: ['error', 'single'] | ||
}, | ||
parserOptions: { | ||
sourceType: 'module' | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
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,8 +1,10 @@ | ||
/src/ | ||
.eslintignore | ||
.eslintrc.json | ||
.eslintrc.js | ||
prettier.config.js | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
index.html | ||
webpack.config.js | ||
webpack.config.js | ||
.prettierignore |
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 @@ | ||
eruda-code.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,3 @@ | ||
## v2.0.0 (6 Jan 2020) | ||
|
||
* feat: theme support |
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,14 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | ||
<title>Eruda-code</title> | ||
</head> | ||
<body> | ||
<script src="node_modules/eruda/eruda.min.js"></script> | ||
<script>eruda.init({tool: 'console'});</script> | ||
<script src="assets/eruda-code.js"></script> | ||
<script>eruda.add(erudaCode).show('code').show();</script> | ||
</body> | ||
</html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" | ||
/> | ||
<title>Eruda-code</title> | ||
</head> | ||
<body> | ||
<script src="node_modules/eruda/eruda.js"></script> | ||
<script> | ||
eruda.init({ tool: 'console' }) | ||
</script> | ||
<script src="assets/eruda-code.js"></script> | ||
<script> | ||
eruda | ||
.add(erudaCode) | ||
.show('code') | ||
.show() | ||
</script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
tabWidth: 2, | ||
semi: false | ||
} |
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,15 +1,36 @@ | ||
.CodeMirror { | ||
height: 100%; | ||
height: 100%; | ||
} | ||
|
||
/* Sync style with chrome dev-tool */ | ||
.cm-keyword {color: hsl(310, 86%, 36%);} | ||
.cm-number {color: hsl(248, 100%, 41%);} | ||
.cm-comment {color: hsl(120, 100%, 23%) !important; font-style: italic;} | ||
.cm-string {color: hsl(1, 80%, 43%) !important;} | ||
.cm-string-2 {color: hsl(1, 99%, 39%) !important;} | ||
.cm-atom {color: hsl(310, 86%, 36%);} | ||
.cm-def {color: hsl(240, 73%, 38%);} | ||
.cm-operator {color: hsl(27, 100%, 30%);} | ||
.cm-meta {color: hsl(27, 100%, 30%);} | ||
.cm-variable-2 {color: hsl(240, 73%, 38%);} | ||
.cm-keyword { | ||
color: hsl(310, 86%, 36%); | ||
} | ||
.cm-number { | ||
color: hsl(248, 100%, 41%); | ||
} | ||
.cm-comment { | ||
color: hsl(120, 100%, 23%) !important; | ||
font-style: italic; | ||
} | ||
.cm-string { | ||
color: hsl(1, 80%, 43%) !important; | ||
} | ||
.cm-string-2 { | ||
color: hsl(1, 99%, 39%) !important; | ||
} | ||
.cm-atom { | ||
color: hsl(310, 86%, 36%); | ||
} | ||
.cm-def { | ||
color: hsl(240, 73%, 38%); | ||
} | ||
.cm-operator { | ||
color: hsl(27, 100%, 30%); | ||
} | ||
.cm-meta { | ||
color: hsl(27, 100%, 30%); | ||
} | ||
.cm-variable-2 { | ||
color: hsl(240, 73%, 38%); | ||
} |
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,85 @@ | ||
import CodeMirror from 'codemirror' | ||
import 'codemirror/mode/javascript/javascript' | ||
import { nextTick, copy } from './util' | ||
|
||
export default function(eruda) { | ||
let { evalCss, beautify } = eruda.util | ||
|
||
class Code extends eruda.Tool { | ||
constructor() { | ||
super() | ||
this.name = 'code' | ||
this._style = evalCss(require('./style.scss')) | ||
this._CodeMirrorStyle = evalCss(require('codemirror/lib/codemirror.css')) | ||
this._CodeMirrorCustomStyle = evalCss(require('./CodeMirror.css')) | ||
this._editor = null | ||
} | ||
init($el, container) { | ||
super.init($el, container) | ||
|
||
$el.html(require('./template.hbs')()) | ||
this._bindEvent() | ||
} | ||
show() { | ||
super.show() | ||
if (!this._editor) { | ||
let container = this._$el.find('.eruda-editor').get(0) | ||
this._editor = CodeMirror.fromTextArea(container, { | ||
lineNumbers: 'true', | ||
mode: 'javascript' | ||
}) | ||
nextTick(() => this._editor.refresh()) | ||
} | ||
} | ||
hide() { | ||
super.hide() | ||
} | ||
run() { | ||
try { | ||
evalJs(this._editor.getValue()) | ||
} catch (e) { | ||
/* eslint-disable no-console */ | ||
console.error(e) | ||
} | ||
} | ||
beautify() { | ||
let editor = this._editor | ||
|
||
let value = editor.getValue() | ||
editor.setValue(beautify(value)) | ||
} | ||
copy() { | ||
copy(this._editor.getValue()) | ||
} | ||
clear() { | ||
this._editor.setValue('') | ||
} | ||
destroy() { | ||
super.destroy() | ||
evalCss.remove(this._style) | ||
evalCss.remove(this._CodeMirrorStyle) | ||
evalCss.remove(this._CodeMirrorCustomStyle) | ||
} | ||
_bindEvent() { | ||
this._$el | ||
.on('click', '.eruda-run', () => this.run()) | ||
.on('click', '.eruda-beautify', () => this.beautify()) | ||
.on('click', '.eruda-clear', () => this.clear()) | ||
.on('click', '.eruda-copy', () => this.copy()) | ||
} | ||
} | ||
|
||
let evalJs = code => { | ||
let ret | ||
|
||
try { | ||
ret = eval.call(window, `(${code})`) | ||
} catch (e) { | ||
ret = eval.call(window, code) | ||
} | ||
|
||
return ret | ||
} | ||
|
||
return new Code() | ||
} |
Oops, something went wrong.