diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js
index 3e5ca6c..7a4ecf4 100644
--- a/components/ConversionPanel.js
+++ b/components/ConversionPanel.js
@@ -1,12 +1,9 @@
import React, { PureComponent } from "react";
import cn from "classnames";
-import Router from "next/router";
import isBrowser from "is-in-browser";
import copy from "copy-text-to-clipboard";
import unfetch from "unfetch";
-const theme = "tomorrow";
-
let CodeMirror;
if (isBrowser) {
CodeMirror = require("react-codemirror2").default;
@@ -72,7 +69,8 @@ type Props = {
splitValue: ?string,
splitMode: ?string,
showFetchButton: boolean,
- fetchButtonText: ?string
+ fetchButtonText: ?string,
+ getTransformedValue: Function
};
export default class ConversionPanel extends PureComponent {
@@ -99,13 +97,7 @@ export default class ConversionPanel extends PureComponent {
componentDidMount() {
const { defaultText, splitValue } = this.props;
- const code = defaultText;
- const sValue = splitValue;
- this.setState({
- value: code,
- splitValue: sValue,
- resultValue: this.props.getTransformedValue(code, sValue)
- });
+ this.onChange(defaultText, splitValue)
}
fetchJSON = async () => {
@@ -116,7 +108,7 @@ export default class ConversionPanel extends PureComponent {
this.onChange(JSON.stringify(json, null, 2))
}
- onChange = (newValue, leftSplitValue) => {
+ onChange = async (newValue, leftSplitValue) => {
const nValue = newValue || this.state.value;
const splitValue =
leftSplitValue && typeof leftSplitValue === "string"
@@ -124,8 +116,7 @@ export default class ConversionPanel extends PureComponent {
: this.state.splitValue;
try {
- const code = this.props.getTransformedValue(nValue, splitValue);
-
+ const code = await this.props.getTransformedValue(nValue, splitValue);
this.setState({
resultValue: code,
info: "",
@@ -148,9 +139,7 @@ export default class ConversionPanel extends PureComponent {
const checked = e.currentTarget.checked;
if (this.props.onCheckboxChange) {
this.props.onCheckboxChange(checked, () => {
- this.setState({
- resultValue: this.props.getTransformedValue(this.state.value)
- });
+ this.onChange()
});
}
};
diff --git a/next.config.js b/next.config.js
index f1651b2..34b374e 100644
--- a/next.config.js
+++ b/next.config.js
@@ -24,6 +24,10 @@ module.exports = {
new webpack.DefinePlugin({IN_BROWSER: true})
)
+ config.resolve.alias = {
+ 'babel-core': 'babel-standalone'
+ }
+
if (!dev) {
config.plugins.push(
new BabiliPlugin()
diff --git a/package.json b/package.json
index 33e81a6..a0bcc76 100644
--- a/package.json
+++ b/package.json
@@ -37,6 +37,7 @@
"copy-text-to-clipboard": "^1.0.3",
"generate-schema": "^2.5.1",
"is-in-browser": "^1.1.3",
+ "is-svg": "^2.1.0",
"lodash": "^4.17.4",
"next": "^3.2.1",
"nprogress": "^0.2.0",
@@ -51,6 +52,7 @@
"transform-css-to-js": "^0.1.1",
"transform-graphql-type-annotations": "^0.1.1",
"transform-json-types": "^0.2.1",
+ "transform-svg-to-native": "^0.1.1",
"unfetch": "^3.0.0",
"xml-js": "^1.4.1"
},
diff --git a/pages/html-to-jsx.js b/pages/html-to-jsx.js
index 0e4fc50..365c51e 100644
--- a/pages/html-to-jsx.js
+++ b/pages/html-to-jsx.js
@@ -1,26 +1,29 @@
import React, { PureComponent } from "react";
import HTMLtoJSX from "@tsuyoshiwada/htmltojsx";
+import convertSvgString from "transform-svg-to-native"
import Layout from "../components/Layout";
import ConversionPanel from "../components/ConversionPanel";
+import isSvg from "is-svg"
const converter = new HTMLtoJSX({
- createClass: false,
- outputClassName: "MainComponent"
+ createClass: false
});
-const defaultText = `
- Hello world!
-
-
`;
+const defaultText = ``;
export default class Css2Js extends PureComponent {
state = {
- createClass: false
+ native: false
};
- getTransformedValue = (newValue: string) => {
- converter.config.createClass = this.state.createClass;
- return converter.convert(newValue);
+ getTransformedValue = async (newValue: string) => {
+ if (this.state.native && !isSvg(newValue)) {
+ throw new Error('You can only convert an SVG in this mode. Try turning off the react-native-svg checkbox.')
+ }
+
+ return this.state.native ? new Promise(resolve => convertSvgString(newValue, (code) => resolve(code))) : converter.convert(newValue)
};
render() {
@@ -35,10 +38,10 @@ export default class Css2Js extends PureComponent {
getTransformedValue={this.getTransformedValue}
name={"html_to_jsx"}
defaultText={defaultText}
- checkboxText="Create Class"
- initialCheckboxValue={this.state.createClass}
+ checkboxText="react-native-svg"
+ initialCheckboxValue={this.state.native}
onCheckboxChange={(checked: boolean, cb: Function) =>
- this.setState({ createClass: checked }, cb)}
+ this.setState({ native: checked }, cb)}
/>
);
diff --git a/utils/babel-plugin-js-to-immutable-prop-types.js b/utils/babel-plugin-js-to-immutable-prop-types.js
index fec129d..1fd5a1e 100644
--- a/utils/babel-plugin-js-to-immutable-prop-types.js
+++ b/utils/babel-plugin-js-to-immutable-prop-types.js
@@ -70,9 +70,7 @@ export default function({ types: t }) {
VariableDeclaration(path) {
path.insertBefore(
- t.identifier(`import ImmutablePropTypes from 'react-immutable-proptypes'
- import PropTypes from 'prop-types
- `)
+ t.identifier(`import ImmutablePropTypes from 'react-immutable-proptypes'`)
);
},
diff --git a/yarn.lock b/yarn.lock
index f3abef5..61c8a55 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -551,6 +551,10 @@ babel-plugin-react-require@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-react-require/-/babel-plugin-react-require-3.0.0.tgz#2e4e7b4496b93a654a1c80042276de4e4eeb20e3"
+babel-plugin-react@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/babel-plugin-react/-/babel-plugin-react-1.0.0.tgz#29a959f9b06fc58a3af27bf58d16be2dc1031dff"
+
babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
@@ -571,7 +575,7 @@ babel-plugin-syntax-flow@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d"
-babel-plugin-syntax-jsx@6.18.0, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
+babel-plugin-syntax-jsx@6.18.0, babel-plugin-syntax-jsx@^6.18.0, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
@@ -1103,6 +1107,10 @@ block-stream@*:
dependencies:
inherits "~2.0.0"
+bluebird@^3.0.5:
+ version "3.5.0"
+ resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
+
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
version "4.11.7"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.7.tgz#ddb048e50d9482790094c13eb3fcfc833ce7ab46"
@@ -1469,7 +1477,7 @@ colormin@^1.0.5:
css-color-names "0.0.4"
has "^1.0.1"
-colors@~1.1.2:
+colors@^1.1.2, colors@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
@@ -1507,6 +1515,13 @@ concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
+config-chain@~1.1.5:
+ version "1.1.11"
+ resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.11.tgz#aba09747dfbe4c3e70e766a6e41586e1859fc6f2"
+ dependencies:
+ ini "^1.3.4"
+ proto-list "~1.2.1"
+
configstore@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-2.1.0.tgz#737a3a7036e9886102aa6099e47bb33ab1aba1a1"
@@ -1957,6 +1972,16 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"
+editorconfig@^0.13.2:
+ version "0.13.3"
+ resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.13.3.tgz#e5219e587951d60958fd94ea9a9a008cdeff1b34"
+ dependencies:
+ bluebird "^3.0.5"
+ commander "^2.9.0"
+ lru-cache "^3.2.0"
+ semver "^5.1.0"
+ sigmund "^1.0.1"
+
ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
@@ -2258,6 +2283,10 @@ figures@^2.0.0:
dependencies:
escape-string-regexp "^1.0.5"
+file-name@^0.1.0:
+ version "0.1.0"
+ resolved "https://registry.yarnpkg.com/file-name/-/file-name-0.1.0.tgz#12b122f120f9c34dbc176c1ab81a548aced6def7"
+
filename-regex@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
@@ -2370,6 +2399,14 @@ friendly-errors-webpack-plugin@1.5.0:
error-stack-parser "^2.0.0"
string-length "^1.0.1"
+fs-extra@^4.0.1:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.1.tgz#7fc0c6c8957f983f57f306a24e5b9ddd8d0dd880"
+ dependencies:
+ graceful-fs "^4.1.2"
+ jsonfile "^3.0.0"
+ universalify "^0.1.0"
+
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -2549,7 +2586,7 @@ got@^5.0.0:
unzip-response "^1.0.2"
url-parse-lax "^1.0.0"
-graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
+graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
@@ -2805,7 +2842,7 @@ inherits@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"
-ini@~1.3.0:
+ini@^1.3.4, ini@~1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
@@ -2870,6 +2907,10 @@ is-builtin-module@^1.0.0:
dependencies:
builtin-modules "^1.0.0"
+is-capitalized@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/is-capitalized/-/is-capitalized-1.0.0.tgz#4c8464b4d91d3e4eeb44889dd2cd8f1b0ac4c136"
+
is-dotfile@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1"
@@ -2988,7 +3029,7 @@ is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
-is-svg@^2.0.0:
+is-svg@^2.0.0, is-svg@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-svg/-/is-svg-2.1.0.tgz#cf61090da0d9efbcab8722deba6f032208dbb0e9"
dependencies:
@@ -3045,6 +3086,15 @@ js-base64@^2.1.9:
version "2.1.9"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
+js-beautify@^1.6.14:
+ version "1.6.14"
+ resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.6.14.tgz#d3b8f7322d02b9277d58bd238264c327e58044cd"
+ dependencies:
+ config-chain "~1.1.5"
+ editorconfig "^0.13.2"
+ mkdirp "~0.5.0"
+ nopt "~3.0.1"
+
js-tokens@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
@@ -3116,6 +3166,12 @@ json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
+jsonfile@^3.0.0:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-3.0.1.tgz#a5ecc6f65f53f662c4415c7675a0331d0992ec66"
+ optionalDependencies:
+ graceful-fs "^4.1.6"
+
jsonify@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
@@ -3283,6 +3339,12 @@ lowercase-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306"
+lru-cache@^3.2.0:
+ version "3.2.0"
+ resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-3.2.0.tgz#71789b3b7f5399bec8565dda38aa30d2a097efee"
+ dependencies:
+ pseudomap "^1.0.1"
+
lru-cache@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
@@ -3624,6 +3686,12 @@ nopt@~1.0.10:
dependencies:
abbrev "1"
+nopt@~3.0.1:
+ version "3.0.6"
+ resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
+ dependencies:
+ abbrev "1"
+
normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
version "2.4.0"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f"
@@ -4215,6 +4283,10 @@ pretty-bytes@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
+prettydiff@^99.0.1:
+ version "99.0.1"
+ resolved "https://registry.yarnpkg.com/prettydiff/-/prettydiff-99.0.1.tgz#95a5d973358daea342161661401a79b87832b412"
+
private@^0.1.6:
version "0.1.7"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1"
@@ -4251,6 +4323,10 @@ prop-types@15.5.10, prop-types@15.x, prop-types@^15.5.10, prop-types@^15.5.4, pr
fbjs "^0.8.9"
loose-envify "^1.3.1"
+proto-list@~1.2.1:
+ version "1.2.4"
+ resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
+
proxy-addr@~1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.5.tgz#71c0ee3b102de3f202f3b64f608d173fcba1a918"
@@ -4262,7 +4338,7 @@ prr@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a"
-pseudomap@^1.0.2:
+pseudomap@^1.0.1, pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
@@ -4808,6 +4884,10 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
+sigmund@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
+
signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
@@ -5071,7 +5151,7 @@ supports-color@^4.0.0, supports-color@^4.2.1:
dependencies:
has-flag "^2.0.0"
-svgo@^0.7.0:
+svgo@^0.7.0, svgo@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/svgo/-/svgo-0.7.2.tgz#9f5772413952135c6fefbf40afe6a4faa88b4bb5"
dependencies:
@@ -5227,6 +5307,24 @@ transform-json-types@^0.2.1:
lodash "^4.17.4"
sha1 "^1.1.1"
+transform-svg-to-native@^0.1.1:
+ version "0.1.1"
+ resolved "https://registry.yarnpkg.com/transform-svg-to-native/-/transform-svg-to-native-0.1.1.tgz#6d890603af21b0cca24ebb8e0a3b3f8b5c26a233"
+ dependencies:
+ "@tsuyoshiwada/htmltojsx" "^0.0.4"
+ all-contributors-cli "^4.4.0"
+ babel-plugin-react "^1.0.0"
+ babel-plugin-syntax-jsx "^6.18.0"
+ colors "^1.1.2"
+ file-name "^0.1.0"
+ fs-extra "^4.0.1"
+ globby "^6.1.0"
+ is-capitalized "^1.0.0"
+ js-beautify "^1.6.14"
+ lodash "^4.17.4"
+ prettydiff "^99.0.1"
+ svgo "^0.7.2"
+
trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
@@ -5318,6 +5416,10 @@ uniqs@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/uniqs/-/uniqs-2.0.0.tgz#ffede4b36b25290696e6e165d4a59edb998e6b02"
+universalify@^0.1.0:
+ version "0.1.1"
+ resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
+
unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"