diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js index f86e483..3e5ca6c 100644 --- a/components/ConversionPanel.js +++ b/components/ConversionPanel.js @@ -3,7 +3,6 @@ import cn from "classnames"; import Router from "next/router"; import isBrowser from "is-in-browser"; import copy from "copy-text-to-clipboard"; -import { html_beautify, css_beautify, js_beautify } from "js-beautify"; import unfetch from "unfetch"; const theme = "tomorrow"; @@ -23,12 +22,15 @@ if (isBrowser) { require("codemirror/mode/go/go"); } -const prettifyMap = { - css: css_beautify, - json: js_beautify, - html: html_beautify, - typescript: js_beautify -}; +const prettierParsers = { + css: 'postcss', + javascript: 'babylon', + jsx: 'babylon', + graphql: 'graphql', + json: 'json', + typescript: 'typescript', + flow: 'flow' +} const modeMapping = { javascript: { @@ -46,6 +48,10 @@ const modeMapping = { name: "xml", htmlMode: true }, + flow: { + name: 'javascript', + typescript: true + }, mysql: "text/x-mysql", scala: "text/x-scala" }; @@ -155,13 +161,22 @@ export default class ConversionPanel extends PureComponent { }); }; + setSplitValue = splitValue => this.setState({splitValue}) + prettifyCode = () => { const { leftMode } = this.props; const { value } = this.state; - this.setResult(prettifyMap[leftMode](value, { indent_size: 2 })); + this.setResult(prettier.format(value, {parser: prettierParsers[leftMode]})); }; + prettifySplitCode = () => { + const { splitMode } = this.props; + const { splitValue } = this.state; + + this.setSplitValue(prettier.format(splitValue, {parser: prettierParsers[splitMode]})); + } + copyCode = () => { const { rightMode } = this.props; const { resultValue } = this.state; @@ -207,6 +222,7 @@ export default class ConversionPanel extends PureComponent { return (