mirror of
https://github.com/ritz078/transform.git
synced 2026-11-20 16:22:53 +03:00
Merge pull request #38 from transform-it/react-native-svg
transform-svg-to-native
This commit is contained in:
commit
32db3a5f2b
6 files changed
+86
-38
No files matched your search
@@ -1,13 +1,10 @@
|
||||
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 { html_beautify, css_beautify, js_beautify } from "js-beautify";
|
||||
import unfetch from "unfetch";
|
||||
|
||||
const theme = "tomorrow";
|
||||
|
||||
let CodeMirror;
|
||||
if (isBrowser) {
|
||||
CodeMirror = require("react-codemirror2").default;
|
||||
@@ -66,7 +63,8 @@ type Props = {
|
||||
splitValue: ?string,
|
||||
splitMode: ?string,
|
||||
showFetchButton: boolean,
|
||||
fetchButtonText: ?string
|
||||
fetchButtonText: ?string,
|
||||
getTransformedValue: Function
|
||||
};
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
@@ -93,13 +91,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 () => {
|
||||
@@ -110,7 +102,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"
|
||||
@@ -118,8 +110,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: "",
|
||||
@@ -142,9 +133,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()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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",
|
||||
"js-beautify": "^1.6.14",
|
||||
"lodash": "^4.17.4",
|
||||
"next": "^3.2.1",
|
||||
@@ -52,6 +53,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"
|
||||
},
|
||||
|
||||
+16
-13
@@ -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 = `<div class="hello" data-id="1">
|
||||
Hello world!
|
||||
<input type="text" name="foo">
|
||||
</div>`;
|
||||
const defaultText = `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1">
|
||||
<rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/>
|
||||
</svg>`;
|
||||
|
||||
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)}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
@@ -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'`)
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1473,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"
|
||||
|
||||
@@ -2279,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"
|
||||
@@ -2391,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"
|
||||
@@ -2570,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"
|
||||
|
||||
@@ -2891,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"
|
||||
@@ -3009,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:
|
||||
@@ -3146,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"
|
||||
@@ -4257,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"
|
||||
@@ -5121,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:
|
||||
@@ -5277,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"
|
||||
@@ -5368,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"
|
||||
|
||||
Reference in new issue
Block a user