mirror of
https://github.com/ritz078/transform.git
synced 2026-11-27 02:59:48 +03:00
replace ace-editor with codemirror
This commit is contained in:
1 parent
9e1a1e16e3
commit
91ad9ee6c1
8 files changed
+810
-253
No files matched your search
+104
-81
@@ -6,20 +6,18 @@ import copy from "copy-text-to-clipboard";
|
||||
|
||||
const theme = "tomorrow";
|
||||
|
||||
let brace;
|
||||
let AceEditor;
|
||||
let CodeMirror;
|
||||
if (isBrowser) {
|
||||
brace = require("brace").default;
|
||||
AceEditor = require("react-ace").default;
|
||||
CodeMirror = require("react-codemirror2").default;
|
||||
|
||||
require("brace/mode/javascript");
|
||||
require(`brace/theme/${theme}`);
|
||||
require("brace/mode/json");
|
||||
require("brace/mode/typescript");
|
||||
require("brace/mode/css");
|
||||
require("brace/mode/html");
|
||||
require("brace/mode/rust");
|
||||
require("brace/mode/mysql");
|
||||
require("codemirror-graphql/mode");
|
||||
require("codemirror/mode/javascript/javascript");
|
||||
require("codemirror/mode/xml/xml");
|
||||
require("codemirror/mode/jsx/jsx")
|
||||
require("codemirror/mode/css/css")
|
||||
require("codemirror/mode/rust/rust")
|
||||
require("codemirror/mode/sql/sql")
|
||||
require("codemirror/mode/clike/clike")
|
||||
}
|
||||
|
||||
// const prettierParsers = {
|
||||
@@ -36,6 +34,26 @@ const prettifyMap = {
|
||||
typescript: "js_beautify"
|
||||
};
|
||||
|
||||
const modeMapping = {
|
||||
javascript: {
|
||||
name: 'javascript'
|
||||
},
|
||||
json: {
|
||||
name: 'javascript',
|
||||
json: true
|
||||
},
|
||||
typescript: {
|
||||
name: 'javascript',
|
||||
typescript: true
|
||||
},
|
||||
html: {
|
||||
name: 'xml',
|
||||
htmlMode: true
|
||||
},
|
||||
mysql: 'text/x-mysql',
|
||||
scala: 'text/x-scala'
|
||||
}
|
||||
|
||||
type Props = {
|
||||
leftMode: ?string,
|
||||
rightMode: ?string,
|
||||
@@ -49,7 +67,8 @@ type Props = {
|
||||
prettifyRightPanel: ?boolean,
|
||||
splitLeft: ?boolean,
|
||||
splitTitle: ?string,
|
||||
splitValue: ?string
|
||||
splitValue: ?string,
|
||||
splitMode: ?string
|
||||
};
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
@@ -72,7 +91,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const {defaultText, splitValue} = this.props
|
||||
const { defaultText, splitValue } = this.props;
|
||||
|
||||
const code = defaultText;
|
||||
const sValue = splitValue;
|
||||
@@ -84,7 +103,6 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
|
||||
onChange = (newValue, leftSplitValue) => {
|
||||
debugger
|
||||
const nValue = newValue || this.state.value;
|
||||
const splitValue =
|
||||
leftSplitValue && typeof leftSplitValue === "string"
|
||||
@@ -112,7 +130,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
});
|
||||
};
|
||||
|
||||
toggleCheckbox = (e) => {
|
||||
toggleCheckbox = e => {
|
||||
const checked = e.currentTarget.checked;
|
||||
if (this.props.onCheckboxChange) {
|
||||
this.props.onCheckboxChange(checked, () => {
|
||||
@@ -123,12 +141,10 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
};
|
||||
|
||||
setResult = (result) => {
|
||||
this.setState(
|
||||
{
|
||||
value: result
|
||||
}
|
||||
);
|
||||
setResult = result => {
|
||||
this.setState({
|
||||
value: result
|
||||
});
|
||||
};
|
||||
|
||||
prettifyCode = () => {
|
||||
@@ -163,7 +179,8 @@ export default class ConversionPanel extends PureComponent {
|
||||
rightTitle,
|
||||
prettifyRightPanel,
|
||||
splitLeft,
|
||||
splitTitle
|
||||
splitTitle,
|
||||
splitMode
|
||||
} = this.props;
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state;
|
||||
|
||||
@@ -171,6 +188,13 @@ export default class ConversionPanel extends PureComponent {
|
||||
split: splitLeft
|
||||
});
|
||||
|
||||
const codeMirrorOptions = {
|
||||
lineNumbers: true,
|
||||
theme: "coda",
|
||||
lineWrapping: true,
|
||||
scrollbarStyle: null
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.6.14/beautify.js" />
|
||||
@@ -274,25 +298,36 @@ export default class ConversionPanel extends PureComponent {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
#code {
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.react-codemirror2, .CodeMirror {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
height: calc(100%) !important;
|
||||
}
|
||||
|
||||
.split #code {
|
||||
.right .CodeMirror-scroll {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.CodeMirror-scroll {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.split #code,
|
||||
.split .CodeMirror {
|
||||
height: calc(100%) !important;
|
||||
}
|
||||
.split .react-codemirror2 {
|
||||
height: calc(50% - 52px) !important;
|
||||
}
|
||||
|
||||
.right #code {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.right .ace_content,
|
||||
.right,
|
||||
.right .ace-tomorrow {
|
||||
.right .CodeMirror {
|
||||
background-color: #fafafa;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.right .ace_scroller {
|
||||
@@ -318,28 +353,24 @@ export default class ConversionPanel extends PureComponent {
|
||||
|
||||
<div className="content-wrapper">
|
||||
<div className={leftClass}>
|
||||
<div style={{display: 'contents'}}>
|
||||
<div className="header">
|
||||
<div className="title">{leftTitle}</div>
|
||||
<button className="btn" onClick={this.prettifyCode}>
|
||||
Prettify
|
||||
</button>
|
||||
</div>
|
||||
{isBrowser && (
|
||||
<AceEditor
|
||||
mode={leftMode}
|
||||
theme={theme}
|
||||
onChange={this.onChange}
|
||||
name="code"
|
||||
value={value}
|
||||
editorProps={{ $blockScrolling: true }}
|
||||
highlightActiveLine={false}
|
||||
scrollMargin={[20]}
|
||||
focus
|
||||
fontSize={14}
|
||||
wrapEnabled
|
||||
/>
|
||||
)}
|
||||
<div style={{ display: "contents" }}>
|
||||
<div className="header">
|
||||
<div className="title">{leftTitle}</div>
|
||||
<button className="btn" onClick={this.prettifyCode}>
|
||||
Prettify
|
||||
</button>
|
||||
</div>
|
||||
{isBrowser && (
|
||||
<CodeMirror
|
||||
onValueChange={(editor, metadata, value) =>
|
||||
this.onChange(value)}
|
||||
value={value}
|
||||
options={{
|
||||
mode: modeMapping[leftMode] || leftMode,
|
||||
...codeMirrorOptions
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{splitLeft &&
|
||||
isBrowser && (
|
||||
@@ -347,18 +378,14 @@ export default class ConversionPanel extends PureComponent {
|
||||
<div className="header">
|
||||
<div className="title">{splitTitle}</div>
|
||||
</div>
|
||||
<AceEditor
|
||||
mode={leftMode}
|
||||
theme={theme}
|
||||
onChange={x => this.onChange(null, x)}
|
||||
name="code"
|
||||
<CodeMirror
|
||||
onValueChange={(editor, metadata, value) =>
|
||||
this.onChange(this.state.value, value)}
|
||||
value={splitValue}
|
||||
editorProps={{ $blockScrolling: true }}
|
||||
highlightActiveLine={false}
|
||||
scrollMargin={[20]}
|
||||
focus
|
||||
fontSize={14}
|
||||
wrapEnabled
|
||||
options={{
|
||||
mode: modeMapping[splitMode] || splitMode,
|
||||
...codeMirrorOptions
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -382,25 +409,21 @@ export default class ConversionPanel extends PureComponent {
|
||||
</button>
|
||||
</div>
|
||||
{isBrowser && (
|
||||
<AceEditor
|
||||
mode={rightMode === "jsx" ? "javascript" : rightMode}
|
||||
theme={theme}
|
||||
name="code"
|
||||
readOnly
|
||||
value={
|
||||
prettifyRightPanel ? (
|
||||
<CodeMirror
|
||||
value={
|
||||
prettifyRightPanel ? (
|
||||
window.js_beautify(resultValue, { e4x: true })
|
||||
) : (
|
||||
resultValue
|
||||
)
|
||||
}
|
||||
editorProps={{ $blockScrolling: true }}
|
||||
scrollMargin={[20]}
|
||||
fontSize={14}
|
||||
showGutter={false}
|
||||
highlightActiveLine={false}
|
||||
wrapEnabled
|
||||
/>
|
||||
}
|
||||
options={{
|
||||
readOnly: true,
|
||||
mode: modeMapping[rightMode] || rightMode,
|
||||
...codeMirrorOptions,
|
||||
lineNumbers: false
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -90,7 +90,7 @@ const x = [
|
||||
iconName: "icon-scala",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Scala case class",
|
||||
label: "JSON to Scala Case Class",
|
||||
path: "/json-to-scala-case-class"
|
||||
}
|
||||
]
|
||||
@@ -257,6 +257,7 @@ export default class Layout extends PureComponent {
|
||||
/>
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/nprogress.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/static/codemirror.css" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
@@ -351,6 +352,7 @@ export default class Layout extends PureComponent {
|
||||
`}</style>
|
||||
|
||||
<style jsx global>{`
|
||||
|
||||
.Collapsible__trigger {
|
||||
color: whitesmoke;
|
||||
font-family: "Lato", sans-serif;
|
||||
|
||||
@@ -11,6 +11,13 @@ module.exports = {
|
||||
fs: 'empty'
|
||||
}
|
||||
|
||||
config.module.rules.push(
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [ 'style-loader', 'css-loader' ]
|
||||
}
|
||||
)
|
||||
|
||||
config.plugins.push(
|
||||
new webpack.DefinePlugin({IN_BROWSER: true})
|
||||
)
|
||||
|
||||
+5
-2
@@ -21,7 +21,10 @@
|
||||
"babel-standalone": "^6.26.0",
|
||||
"babili-webpack-plugin": "^0.1.2",
|
||||
"classnames": "^2.2.5",
|
||||
"codemirror": "^5.29.0",
|
||||
"codemirror-graphql": "^0.6.11",
|
||||
"copy-text-to-clipboard": "^1.0.3",
|
||||
"css-loader": "^0.28.7",
|
||||
"css-to-react-native": "^2.0.4",
|
||||
"generate-schema": "^2.5.1",
|
||||
"graphql": "^0.10.5",
|
||||
@@ -30,15 +33,15 @@
|
||||
"lodash": "^4.17.4",
|
||||
"next": "^3.1.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"pretty": "^2.0.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"rc-collapse": "^1.7.6",
|
||||
"react": "^15.6.1",
|
||||
"react-ace": "^5.2.0",
|
||||
"react-codemirror2": "^0.0.14",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-fuzzy-picker": "^0.5.1",
|
||||
"react-github-corner": "^1.0.0",
|
||||
"stringify-object": "^3.2.0",
|
||||
"style-loader": "^0.18.2",
|
||||
"webpack-bundle-analyzer": "^2.9.0",
|
||||
"xml-js": "^1.4.1"
|
||||
},
|
||||
|
||||
@@ -18,11 +18,12 @@ export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"graphql_to_typescript"}
|
||||
defaultText={dummySchema}
|
||||
leftMode="typescript"
|
||||
leftMode="javascript"
|
||||
rightMode="typescript"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
splitLeft={true}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={"Query"}
|
||||
splitValue={dummyQuery}
|
||||
/>
|
||||
|
||||
@@ -23,6 +23,7 @@ export default class Json2Ts extends PureComponent {
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
splitLeft={true}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={"Query"}
|
||||
splitValue={dummyQuery}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Lato');
|
||||
|
||||
.rc-collapse {
|
||||
background-color: #f7f7f7;
|
||||
border-radius: 3px;
|
||||
|
||||
Reference in new issue
Block a user