mirror of
https://github.com/ritz078/transform.git
synced 2026-11-22 09:01:31 +03:00
add clear button. closes #44
This commit is contained in:
1 parent
94f82f81bc
commit
8285d2239a
40 files changed
+1865
-2187
No files matched your search
+211
-163
@@ -1,58 +1,58 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import cn from 'classnames'
|
||||
import isBrowser from 'is-in-browser'
|
||||
import copy from 'copy-text-to-clipboard'
|
||||
import unfetch from 'unfetch'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import React, { PureComponent } from "react";
|
||||
import cn from "classnames";
|
||||
import isBrowser from "is-in-browser";
|
||||
import copy from "copy-text-to-clipboard";
|
||||
import unfetch from "unfetch";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
|
||||
let CodeMirror
|
||||
let CodeMirror;
|
||||
if (isBrowser) {
|
||||
CodeMirror = require('react-codemirror2').default
|
||||
CodeMirror = require("react-codemirror2").default;
|
||||
|
||||
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')
|
||||
require('codemirror/mode/go/go')
|
||||
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");
|
||||
require("codemirror/mode/go/go");
|
||||
}
|
||||
|
||||
const prettierParsers = {
|
||||
css: 'postcss',
|
||||
javascript: 'babylon',
|
||||
jsx: 'babylon',
|
||||
graphql: 'graphql',
|
||||
json: 'json',
|
||||
typescript: 'typescript',
|
||||
flow: 'flow'
|
||||
}
|
||||
css: "postcss",
|
||||
javascript: "babylon",
|
||||
jsx: "babylon",
|
||||
graphql: "graphql",
|
||||
json: "json",
|
||||
typescript: "typescript",
|
||||
flow: "flow"
|
||||
};
|
||||
|
||||
const modeMapping = {
|
||||
javascript: {
|
||||
name: 'javascript'
|
||||
name: "javascript"
|
||||
},
|
||||
json: {
|
||||
name: 'javascript',
|
||||
name: "javascript",
|
||||
json: true
|
||||
},
|
||||
typescript: {
|
||||
name: 'javascript',
|
||||
name: "javascript",
|
||||
typescript: true
|
||||
},
|
||||
html: {
|
||||
name: 'xml',
|
||||
name: "xml",
|
||||
htmlMode: true
|
||||
},
|
||||
flow: {
|
||||
name: 'javascript',
|
||||
name: "javascript",
|
||||
typescript: true
|
||||
},
|
||||
mysql: 'text/x-mysql',
|
||||
scala: 'text/x-scala'
|
||||
}
|
||||
mysql: "text/x-mysql",
|
||||
scala: "text/x-scala"
|
||||
};
|
||||
|
||||
type Props = {
|
||||
leftMode: ?string,
|
||||
@@ -73,188 +73,205 @@ type Props = {
|
||||
fetchButtonText: ?string,
|
||||
getTransformedValue: Function,
|
||||
extensions: ?(string[])
|
||||
}
|
||||
};
|
||||
|
||||
function UploadIcon () {
|
||||
function UploadIcon() {
|
||||
return (
|
||||
<svg
|
||||
fill='#ffffff'
|
||||
fill="#ffffff"
|
||||
height={24}
|
||||
width={24}
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<style>{`
|
||||
svg {
|
||||
vertical-align: sub;
|
||||
}
|
||||
`}</style>
|
||||
<path d='M0 0h24v24H0z' fill='none' />
|
||||
<path d='M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z' />
|
||||
<path d="M0 0h24v24H0z" fill="none" />
|
||||
<path d="M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z" />
|
||||
</svg>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function ClearIcon() {
|
||||
return (
|
||||
<svg style={{ width: 24, height: 24 }} viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="#555"
|
||||
d="M19 4h-3.5l-1-1h-5l-1 1H5v2h14M6 19a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7H6v12z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
props: Props
|
||||
props: Props;
|
||||
|
||||
constructor (props) {
|
||||
super(props)
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
resultValue: '',
|
||||
resultValue: "",
|
||||
value: props.defaultText,
|
||||
splitValue: '',
|
||||
info: '',
|
||||
infoType: '',
|
||||
splitValue: "",
|
||||
info: "",
|
||||
infoType: "",
|
||||
isPrettierAvailable: true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
leftMode: 'javascript',
|
||||
rightMode: 'javascript',
|
||||
pathname: '/',
|
||||
leftMode: "javascript",
|
||||
rightMode: "javascript",
|
||||
pathname: "/",
|
||||
prettifyRightPanel: true,
|
||||
splitLeft: false,
|
||||
showFetchButton: true,
|
||||
fetchButtonText: 'Fetch JSON from URL',
|
||||
extensions: ['.json']
|
||||
}
|
||||
fetchButtonText: "Fetch JSON from URL",
|
||||
extensions: [".json"]
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
const { defaultText, splitValue } = this.props
|
||||
componentDidMount() {
|
||||
const { defaultText, splitValue } = this.props;
|
||||
|
||||
this.onChange(defaultText, splitValue)
|
||||
this.onChange(defaultText, splitValue);
|
||||
|
||||
const { worker, promiseWorker } = loadWorker('prettier.js')
|
||||
this.worker = worker
|
||||
this.promiseWorker = promiseWorker
|
||||
const { worker, promiseWorker } = loadWorker("prettier.js");
|
||||
this.worker = worker;
|
||||
this.promiseWorker = promiseWorker;
|
||||
|
||||
this.worker.onmessage = this.setPrettierAvailability
|
||||
this.worker.onmessage = this.setPrettierAvailability;
|
||||
}
|
||||
|
||||
setPrettierAvailability = ({ data }) => {
|
||||
if (!data.available || this.state.isPrettierAvailable === data.available) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
isPrettierAvailable: data.available
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
passCodeToWorker = (code, mode, section) => {
|
||||
this.promiseWorker.postMessage({ code, mode, section }).then(response => {
|
||||
const { available, prettyCode, section } = response
|
||||
const { available, prettyCode, section } = response;
|
||||
this.setState({
|
||||
isPrettierAvailable: available,
|
||||
[section]: prettyCode
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
clearText = () => {
|
||||
this.setState({
|
||||
value: ""
|
||||
});
|
||||
};
|
||||
|
||||
fetchJSON = async () => {
|
||||
const url = window.prompt('Enter URL to fetch JSON from a remote server.')
|
||||
if (!url) return
|
||||
const url = window.prompt("Enter URL to fetch JSON from a remote server.");
|
||||
if (!url) return;
|
||||
try {
|
||||
const res = await unfetch(url)
|
||||
const json = await res.json()
|
||||
this.onChange(JSON.stringify(json, null, 2))
|
||||
const res = await unfetch(url);
|
||||
const json = await res.json();
|
||||
this.onChange(JSON.stringify(json, null, 2));
|
||||
} catch (e) {
|
||||
this.setState({
|
||||
info: e.message,
|
||||
infoType: 'error'
|
||||
})
|
||||
infoType: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onChange = async (newValue, leftSplitValue) => {
|
||||
const { prettifyRightPanel, rightMode } = this.props
|
||||
const { prettifyRightPanel, rightMode } = this.props;
|
||||
|
||||
const nValue = newValue || this.state.value
|
||||
const nValue = newValue || this.state.value;
|
||||
const splitValue =
|
||||
leftSplitValue && typeof leftSplitValue === 'string'
|
||||
leftSplitValue && typeof leftSplitValue === "string"
|
||||
? leftSplitValue
|
||||
: this.state.splitValue
|
||||
: this.state.splitValue;
|
||||
|
||||
try {
|
||||
let code = await this.props.getTransformedValue(nValue, splitValue)
|
||||
code = code.prettyCode || code
|
||||
let code = await this.props.getTransformedValue(nValue, splitValue);
|
||||
code = code.prettyCode || code;
|
||||
if (prettifyRightPanel) {
|
||||
this.passCodeToWorker(code, rightMode, 'resultValue')
|
||||
this.passCodeToWorker(code, rightMode, "resultValue");
|
||||
} else {
|
||||
this.setState({
|
||||
resultValue: code
|
||||
})
|
||||
});
|
||||
}
|
||||
this.setState({
|
||||
info: '',
|
||||
infoType: ''
|
||||
})
|
||||
info: "",
|
||||
infoType: ""
|
||||
});
|
||||
} catch (e) {
|
||||
this.setState({
|
||||
info: e.message,
|
||||
infoType: 'error'
|
||||
})
|
||||
infoType: "error"
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
value: nValue,
|
||||
splitValue: splitValue
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
toggleCheckbox = e => {
|
||||
const checked = e.currentTarget.checked
|
||||
const checked = e.currentTarget.checked;
|
||||
if (this.props.onCheckboxChange) {
|
||||
this.props.onCheckboxChange(checked, () => {
|
||||
this.onChange()
|
||||
})
|
||||
this.onChange();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
prettifyCode = () => {
|
||||
if (!this.state.isPrettierAvailable) return
|
||||
const { leftMode } = this.props
|
||||
const { value } = this.state
|
||||
if (!this.state.isPrettierAvailable) return;
|
||||
const { leftMode } = this.props;
|
||||
const { value } = this.state;
|
||||
|
||||
this.passCodeToWorker(value, leftMode, 'value')
|
||||
}
|
||||
this.passCodeToWorker(value, leftMode, "value");
|
||||
};
|
||||
|
||||
prettifySplitCode = () => {
|
||||
if (!this.state.isPrettierAvailable) return
|
||||
const { splitMode } = this.props
|
||||
const { splitValue } = this.state
|
||||
if (!this.state.isPrettierAvailable) return;
|
||||
const { splitMode } = this.props;
|
||||
const { splitValue } = this.state;
|
||||
|
||||
this.passCodeToWorker(splitValue, splitMode, 'splitValue')
|
||||
}
|
||||
this.passCodeToWorker(splitValue, splitMode, "splitValue");
|
||||
};
|
||||
|
||||
copyCode = () => {
|
||||
const { resultValue } = this.state
|
||||
const { resultValue } = this.state;
|
||||
|
||||
copy(resultValue)
|
||||
copy(resultValue);
|
||||
|
||||
this.setState({
|
||||
info: 'Code copied to clipboard.',
|
||||
infoType: 'success'
|
||||
})
|
||||
}
|
||||
info: "Code copied to clipboard.",
|
||||
infoType: "success"
|
||||
});
|
||||
};
|
||||
|
||||
getPrettifyClass = () => {
|
||||
return cn('btn', {
|
||||
return cn("btn", {
|
||||
disabled: !this.state.isPrettierAvailable
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
loadFile = e => {
|
||||
const file = e.target.files[0]
|
||||
const reader = new FileReader()
|
||||
reader.readAsText(file, 'utf-8')
|
||||
const file = e.target.files[0];
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file, "utf-8");
|
||||
reader.onload = () => {
|
||||
this.onChange(reader.result)
|
||||
}
|
||||
}
|
||||
this.onChange(reader.result);
|
||||
};
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
const {
|
||||
leftMode,
|
||||
rightMode,
|
||||
@@ -269,35 +286,35 @@ export default class ConversionPanel extends PureComponent {
|
||||
showFetchButton,
|
||||
fetchButtonText,
|
||||
extensions
|
||||
} = this.props
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state
|
||||
} = this.props;
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state;
|
||||
|
||||
const leftClass = cn('section left', {
|
||||
const leftClass = cn("section left", {
|
||||
split: splitLeft
|
||||
})
|
||||
});
|
||||
|
||||
const codeMirrorOptions = {
|
||||
lineNumbers: true,
|
||||
theme: 'chrome-devtools',
|
||||
theme: "chrome-devtools",
|
||||
lineWrapping: true,
|
||||
scrollbarStyle: null
|
||||
}
|
||||
};
|
||||
|
||||
// hide success footer bannner after 2 seconds. Let other types be visible until fixed.
|
||||
clearTimeout(this.footerTimeout)
|
||||
if (infoType === 'success') {
|
||||
clearTimeout(this.footerTimeout);
|
||||
if (infoType === "success") {
|
||||
this.footerTimeout = setTimeout(
|
||||
() =>
|
||||
this.setState({
|
||||
info: '',
|
||||
infoType: ''
|
||||
info: "",
|
||||
infoType: ""
|
||||
}),
|
||||
2000
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='wrapper'>
|
||||
<div className="wrapper">
|
||||
<style jsx>{`
|
||||
.wrapper {
|
||||
display: flex;
|
||||
@@ -309,7 +326,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
.footer {
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
background-color: white;
|
||||
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
z-index: 99;
|
||||
@@ -351,8 +368,8 @@ export default class ConversionPanel extends PureComponent {
|
||||
|
||||
.info {
|
||||
color: white;
|
||||
font: 14px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas',
|
||||
'source-code-pro', monospace;
|
||||
font: 14px/normal "Monaco", "Menlo", "Ubuntu Mono", "Consolas",
|
||||
"source-code-pro", monospace;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@@ -389,7 +406,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
padding: 0 10px;
|
||||
position: relative;
|
||||
justify-content: space-between;
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -433,6 +450,31 @@ export default class ConversionPanel extends PureComponent {
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.clear {
|
||||
position: absolute;
|
||||
top: 60px;
|
||||
right: 20px;
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
height: 48px;
|
||||
width: 48px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
margin: 0px;
|
||||
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
|
||||
background-color: #fff;
|
||||
border: 1px solid rgba(0, 0, 0, 0.04);
|
||||
padding-left: 12px;
|
||||
box-sizing: border-box;
|
||||
transition: all 0.2s;
|
||||
z-index: 999;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.clear:hover {
|
||||
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.upload-wrapper:hover {
|
||||
background-color: #444;
|
||||
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
|
||||
@@ -496,7 +538,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
|
||||
label {
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -507,15 +549,15 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
`}</style>
|
||||
|
||||
<div className='content-wrapper'>
|
||||
<div className="content-wrapper">
|
||||
<div className={leftClass}>
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{leftTitle}</h4>
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{leftTitle}</h4>
|
||||
|
||||
{leftMode === 'json' &&
|
||||
{leftMode === "json" &&
|
||||
showFetchButton && (
|
||||
<button className='btn' onClick={this.fetchJSON}>
|
||||
<button className="btn" onClick={this.fetchJSON}>
|
||||
{fetchButtonText}
|
||||
</button>
|
||||
)}
|
||||
@@ -529,6 +571,12 @@ export default class ConversionPanel extends PureComponent {
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="clear" onClick={this.clearText}>
|
||||
{" "}
|
||||
<ClearIcon />
|
||||
</div>
|
||||
|
||||
{isBrowser && (
|
||||
<CodeMirror
|
||||
onChange={(editor, metadata, value) => this.onChange(value)}
|
||||
@@ -542,12 +590,12 @@ export default class ConversionPanel extends PureComponent {
|
||||
|
||||
{extensions &&
|
||||
extensions.length > 0 && (
|
||||
<label htmlFor='upload' className='btn upload-wrapper'>
|
||||
<label htmlFor="upload" className="btn upload-wrapper">
|
||||
<input
|
||||
id='upload'
|
||||
accept={extensions.join(',')}
|
||||
id="upload"
|
||||
accept={extensions.join(",")}
|
||||
onChange={this.loadFile}
|
||||
type='file'
|
||||
type="file"
|
||||
/>
|
||||
<UploadIcon />
|
||||
</label>
|
||||
@@ -555,9 +603,9 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
{splitLeft &&
|
||||
isBrowser && (
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{splitTitle}</h4>
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{splitTitle}</h4>
|
||||
{prettierParsers[splitMode] && (
|
||||
<button
|
||||
className={this.getPrettifyClass()}
|
||||
@@ -580,22 +628,22 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className='section right'>
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{rightTitle}</h4>
|
||||
<div className="section right">
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{rightTitle}</h4>
|
||||
{onCheckboxChange && (
|
||||
<label htmlFor='#text'>
|
||||
<label htmlFor="#text">
|
||||
<input
|
||||
type='checkbox'
|
||||
id='#text'
|
||||
type="checkbox"
|
||||
id="#text"
|
||||
defaultChecked={initialCheckboxValue}
|
||||
onChange={this.toggleCheckbox}
|
||||
/>{' '}
|
||||
/>{" "}
|
||||
{checkboxText}
|
||||
</label>
|
||||
)}
|
||||
<button className='btn' onClick={this.copyCode}>
|
||||
<button className="btn" onClick={this.copyCode}>
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
@@ -613,12 +661,12 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{infoType !== '' && (
|
||||
{infoType !== "" && (
|
||||
<div className={`footer has-${infoType}`}>
|
||||
<span className='info'>{info}</span>
|
||||
<span className="info">{info}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+113
-113
@@ -1,87 +1,87 @@
|
||||
import React, { PureComponent, Component } from 'react'
|
||||
import isBrowser from 'is-in-browser'
|
||||
import Link from 'next/link'
|
||||
import Head from 'next/head'
|
||||
import NProgress from 'nprogress'
|
||||
import Router from 'next/router'
|
||||
import GithubCorner from 'react-github-corner'
|
||||
import FuzzyPicker, { FuzzyWrapper } from 'react-fuzzy-picker'
|
||||
import Collapse, { Panel } from 'rc-collapse'
|
||||
import findIndex from 'lodash/findIndex'
|
||||
import { categorizedRoutes, routes, activeRouteData } from '../utils/routes'
|
||||
import React, { PureComponent, Component } from "react";
|
||||
import isBrowser from "is-in-browser";
|
||||
import Link from "next/link";
|
||||
import Head from "next/head";
|
||||
import NProgress from "nprogress";
|
||||
import Router from "next/router";
|
||||
import GithubCorner from "react-github-corner";
|
||||
import FuzzyPicker, { FuzzyWrapper } from "react-fuzzy-picker";
|
||||
import Collapse, { Panel } from "rc-collapse";
|
||||
import findIndex from "lodash/findIndex";
|
||||
import { categorizedRoutes, routes, activeRouteData } from "../utils/routes";
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
NProgress.configure({ showSpinner: false });
|
||||
|
||||
Router.onRouteChangeStart = url => {
|
||||
if (url.indexOf('code=') === -1) {
|
||||
NProgress.start()
|
||||
if (url.indexOf("code=") === -1) {
|
||||
NProgress.start();
|
||||
}
|
||||
}
|
||||
Router.onRouteChangeComplete = () => NProgress.done()
|
||||
Router.onRouteChangeError = () => NProgress.done()
|
||||
};
|
||||
Router.onRouteChangeComplete = () => NProgress.done();
|
||||
Router.onRouteChangeError = () => NProgress.done();
|
||||
|
||||
function Logo () {
|
||||
function Logo() {
|
||||
return (
|
||||
<svg
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
viewBox='0 0 100 125'
|
||||
fill='#ffffff'
|
||||
width='190'
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 100 125"
|
||||
fill="#ffffff"
|
||||
width="190"
|
||||
>
|
||||
<style jsx>{`
|
||||
svg {
|
||||
height: 125px;
|
||||
}
|
||||
`}</style>
|
||||
<path d='M68.6 34c-2.6 0-4.7 1.6-5.7 3.8l-25.4-6v-.4c0-3.4-2.8-6.2-6.2-6.2-3.4 0-6.2 2.8-6.2 6.2 0 3.1 2.2 5.6 5.2 6.1v25.1c-2.9.5-5.2 3-5.2 6.1 0 3.4 2.8 6.2 6.2 6.2 3.1 0 5.6-2.2 6.1-5.2h16.7c.5 2.9 3 5.2 6.1 5.2 3.4 0 6.2-2.8 6.2-6.2 0-2.4-1.4-4.4-3.3-5.5l4.8-16.9c.3 0 .6.1.9.1 3.4 0 6.2-2.8 6.2-6.2-.2-3.4-3-6.2-6.4-6.2zm0 10.3c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2zM31.4 27.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2zm4.1 41.4c0 2.3-1.9 4.2-4.2 4.2-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.4.1 4.2 1.9 4.2 4.2zm24.7 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2 4.2 1.9 4.2 4.2-1.9 4.2-4.2 4.2zm.9-10.3c-.3 0-.6-.1-.9-.1-3.1 0-5.6 2.2-6.1 5.2H37.5C37 65 35 63 32.4 62.5v-25c2.1-.3 3.9-1.8 4.7-3.7l25.4 6v.4c0 2.4 1.4 4.5 3.4 5.5l-4.8 16.8z' />
|
||||
<path d="M68.6 34c-2.6 0-4.7 1.6-5.7 3.8l-25.4-6v-.4c0-3.4-2.8-6.2-6.2-6.2-3.4 0-6.2 2.8-6.2 6.2 0 3.1 2.2 5.6 5.2 6.1v25.1c-2.9.5-5.2 3-5.2 6.1 0 3.4 2.8 6.2 6.2 6.2 3.1 0 5.6-2.2 6.1-5.2h16.7c.5 2.9 3 5.2 6.1 5.2 3.4 0 6.2-2.8 6.2-6.2 0-2.4-1.4-4.4-3.3-5.5l4.8-16.9c.3 0 .6.1.9.1 3.4 0 6.2-2.8 6.2-6.2-.2-3.4-3-6.2-6.4-6.2zm0 10.3c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2zM31.4 27.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2zm4.1 41.4c0 2.3-1.9 4.2-4.2 4.2-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.4.1 4.2 1.9 4.2 4.2zm24.7 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2 4.2 1.9 4.2 4.2-1.9 4.2-4.2 4.2zm.9-10.3c-.3 0-.6-.1-.9-.1-3.1 0-5.6 2.2-6.1 5.2H37.5C37 65 35 63 32.4 62.5v-25c2.1-.3 3.9-1.8 4.7-3.7l25.4 6v.4c0 2.4 1.4 4.5 3.4 5.5l-4.8 16.8z" />
|
||||
</svg>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
class CodeSponsor extends Component {
|
||||
shouldComponentUpdate () {
|
||||
return false
|
||||
shouldComponentUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<div id='code-sponsor-widget' />
|
||||
<div id="code-sponsor-widget" />
|
||||
<script
|
||||
type='text/javascript'
|
||||
src='https://app.codesponsor.io/scripts/mR5byaXd82L2zTVHo9eWvA?theme=dark&width=240&height=140&image=hide'
|
||||
type="text/javascript"
|
||||
src="https://app.codesponsor.io/scripts/mR5byaXd82L2zTVHo9eWvA?theme=dark&width=240&height=140&image=hide"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function trackingScript () {
|
||||
;(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r
|
||||
;(i[r] =
|
||||
function trackingScript() {
|
||||
(function(i, s, o, g, r, a, m) {
|
||||
i["GoogleAnalyticsObject"] = r;
|
||||
(i[r] =
|
||||
i[r] ||
|
||||
function () {
|
||||
;(i[r].q = i[r].q || []).push(arguments)
|
||||
function() {
|
||||
(i[r].q = i[r].q || []).push(arguments);
|
||||
}),
|
||||
(i[r].l = 1 * new Date())
|
||||
;(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0])
|
||||
a.async = 1
|
||||
a.src = g
|
||||
m.parentNode.insertBefore(a, m)
|
||||
(i[r].l = 1 * new Date());
|
||||
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
|
||||
a.async = 1;
|
||||
a.src = g;
|
||||
m.parentNode.insertBefore(a, m);
|
||||
})(
|
||||
window,
|
||||
document,
|
||||
'script',
|
||||
'https://www.google-analytics.com/analytics.js',
|
||||
'ga'
|
||||
)
|
||||
"script",
|
||||
"https://www.google-analytics.com/analytics.js",
|
||||
"ga"
|
||||
);
|
||||
|
||||
ga('create', 'UA-60624235-5', 'auto')
|
||||
ga('send', 'pageview')
|
||||
ga("create", "UA-60624235-5", "auto");
|
||||
ga("send", "pageview");
|
||||
}
|
||||
|
||||
function renderFuzzyPicker (isOpen, onClose) {
|
||||
function renderFuzzyPicker(isOpen, onClose) {
|
||||
return (
|
||||
<FuzzyPicker
|
||||
isOpen={isOpen}
|
||||
@@ -91,32 +91,32 @@ function renderFuzzyPicker (isOpen, onClose) {
|
||||
itemValue={item => item.label}
|
||||
renderItem={item => <span>{item.label}</span>}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Here, we check what key must be pressed to open the fuzzy picker
|
||||
// We'll use the '/' key for this example.
|
||||
function isCorrectKeyPressed (event) {
|
||||
return event.metaKey && event.key === 'p'
|
||||
function isCorrectKeyPressed(event) {
|
||||
return event.metaKey && event.key === "p";
|
||||
}
|
||||
|
||||
export default class Layout extends PureComponent {
|
||||
state = {}
|
||||
state = {};
|
||||
|
||||
getClass (path) {
|
||||
return path === this.props.pathname ? 'active' : ''
|
||||
getClass(path) {
|
||||
return path === this.props.pathname ? "active" : "";
|
||||
}
|
||||
|
||||
componentWillMount () {
|
||||
this.setKey(this.props.pathname)
|
||||
componentWillMount() {
|
||||
this.setKey(this.props.pathname);
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
routes.forEach(({ path }) => Router.prefetch(path))
|
||||
componentDidMount() {
|
||||
routes.forEach(({ path }) => Router.prefetch(path));
|
||||
}
|
||||
|
||||
componentWillReceiveProps ({ pathname }) {
|
||||
this.setKey(pathname)
|
||||
componentWillReceiveProps({ pathname }) {
|
||||
this.setKey(pathname);
|
||||
}
|
||||
|
||||
setKey = pathname => {
|
||||
@@ -125,52 +125,52 @@ export default class Layout extends PureComponent {
|
||||
categorizedRoutes,
|
||||
o => o.content.filter(a => a.path === pathname).length
|
||||
) + 1}`
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onChange = activeKey => {
|
||||
this.setState({
|
||||
activeKey
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
render () {
|
||||
const { label, desc, title } = activeRouteData(this.props.pathname)
|
||||
render() {
|
||||
const { label, desc, title } = activeRouteData(this.props.pathname);
|
||||
|
||||
return (
|
||||
<div className='main-wrapper'>
|
||||
<div className="main-wrapper">
|
||||
<Head>
|
||||
<title>{title || label}</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
||||
<link rel='icon' type='image/png' href='/static/favicon.png' />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
||||
<meta
|
||||
name='google-site-verification'
|
||||
content='bjJSOEahdert-7mwVScrwTTUVR3nSe0bEj5YjevUNn0'
|
||||
name="google-site-verification"
|
||||
content="bjJSOEahdert-7mwVScrwTTUVR3nSe0bEj5YjevUNn0"
|
||||
/>
|
||||
<meta name='description' content={desc} />
|
||||
<meta name="description" content={desc} />
|
||||
<link
|
||||
rel='stylesheet'
|
||||
type='text/css'
|
||||
href='https://cdnjs.cloudflare.com/ajax/libs/font-mfizz/2.4.1/font-mfizz.min.css'
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-mfizz/2.4.1/font-mfizz.min.css"
|
||||
/>
|
||||
<link rel='stylesheet' href='/static/styles.css' />
|
||||
<link rel='manifest' href='/static/manifest.json' />
|
||||
<meta name='theme-color' content='#2196f3' />
|
||||
<meta name='mobile-web-app-capable' content='yes' />
|
||||
<meta name='apple-mobile-web-app-capable' content='yes' />
|
||||
<meta name='application-name' content='Transform' />
|
||||
<meta name='apple-mobile-web-app-title' content='Transform' />
|
||||
<meta name='theme-color' content='#2196f3' />
|
||||
<meta name='msapplication-navbutton-color' content='#2196f3' />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<link rel="manifest" href="/static/manifest.json" />
|
||||
<meta name="theme-color" content="#2196f3" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="application-name" content="Transform" />
|
||||
<meta name="apple-mobile-web-app-title" content="Transform" />
|
||||
<meta name="theme-color" content="#2196f3" />
|
||||
<meta name="msapplication-navbutton-color" content="#2196f3" />
|
||||
<meta
|
||||
name='apple-mobile-web-app-status-bar-style'
|
||||
content='black-translucent'
|
||||
name="apple-mobile-web-app-status-bar-style"
|
||||
content="black-translucent"
|
||||
/>
|
||||
<meta name='msapplication-starturl' content='./' />
|
||||
<meta name='msapplication-TileColor' content='#2196f3' />
|
||||
<meta name="msapplication-starturl" content="./" />
|
||||
<meta name="msapplication-TileColor" content="#2196f3" />
|
||||
<meta
|
||||
name='msapplication-TileImage'
|
||||
content='/static/images/icons/icon-144x144.png'
|
||||
name="msapplication-TileImage"
|
||||
content="/static/images/icons/icon-144x144.png"
|
||||
/>
|
||||
</Head>
|
||||
<style jsx>{`
|
||||
@@ -212,7 +212,7 @@ export default class Layout extends PureComponent {
|
||||
padding: 20px 5px 30px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-family: "Lato", sans-serif;
|
||||
}
|
||||
|
||||
.badge {
|
||||
@@ -242,7 +242,7 @@ export default class Layout extends PureComponent {
|
||||
}
|
||||
|
||||
.info {
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
color: white;
|
||||
border: 1px solid #7b7b7b;
|
||||
padding: 8px;
|
||||
@@ -265,7 +265,7 @@ export default class Layout extends PureComponent {
|
||||
<style jsx global>{`
|
||||
.Collapsible__trigger {
|
||||
color: whitesmoke;
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-family: "Lato", sans-serif;
|
||||
line-height: 44px;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -298,7 +298,7 @@ export default class Layout extends PureComponent {
|
||||
.rc-collapse-content-box a {
|
||||
display: block;
|
||||
color: #fff;
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
line-height: 44px;
|
||||
padding-left: 20px;
|
||||
background-color: #3c3c3c;
|
||||
@@ -312,18 +312,18 @@ export default class Layout extends PureComponent {
|
||||
popup={renderFuzzyPicker}
|
||||
/>
|
||||
|
||||
<div className='sidebar'>
|
||||
<div className="sidebar">
|
||||
<GithubCorner
|
||||
href='https://github.com/ritz078/transform-www'
|
||||
href="https://github.com/ritz078/transform-www"
|
||||
height={80}
|
||||
width={80}
|
||||
direction='left'
|
||||
direction="left"
|
||||
/>
|
||||
<div className='logo'>
|
||||
<div className="logo">
|
||||
<Logo />
|
||||
</div>
|
||||
<div className='info'>Use Ctrl/Cmd + P for quick search</div>
|
||||
<div className='nav'>
|
||||
<div className="info">Use Ctrl/Cmd + P for quick search</div>
|
||||
<div className="nav">
|
||||
<Collapse
|
||||
onChange={this.onChange}
|
||||
accordion
|
||||
@@ -334,14 +334,14 @@ export default class Layout extends PureComponent {
|
||||
return (
|
||||
<Panel
|
||||
key={i + 1}
|
||||
headerClass='Collapsible__trigger'
|
||||
headerClass="Collapsible__trigger"
|
||||
header={
|
||||
<span>
|
||||
{route.iconName ? (
|
||||
<i className={route.iconName} />
|
||||
) : (
|
||||
route.icon
|
||||
)}{' '}
|
||||
)}{" "}
|
||||
{route.category}
|
||||
</span>
|
||||
}
|
||||
@@ -349,32 +349,32 @@ export default class Layout extends PureComponent {
|
||||
{route.content.map(a => (
|
||||
<Link key={a.path} href={a.path}>
|
||||
<a className={this.getClass(a.path)}>
|
||||
{a.label}{' '}
|
||||
{a.beta && <span className='beta'>Beta</span>}
|
||||
{a.label}{" "}
|
||||
{a.beta && <span className="beta">Beta</span>}
|
||||
</a>
|
||||
</Link>
|
||||
))}
|
||||
</Panel>
|
||||
)
|
||||
);
|
||||
})}
|
||||
</Collapse>
|
||||
</div>
|
||||
|
||||
<div className='footer'>
|
||||
<div className="footer">
|
||||
<CodeSponsor />
|
||||
Created by{' '}
|
||||
Created by{" "}
|
||||
<a
|
||||
target='_blank'
|
||||
className='twitter'
|
||||
href='https://twitter.com/ritz078'
|
||||
target="_blank"
|
||||
className="twitter"
|
||||
href="https://twitter.com/ritz078"
|
||||
>
|
||||
@ritz078
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className='content'>{this.props.children}</div>
|
||||
<div className="content">{this.props.children}</div>
|
||||
<script>{isBrowser && trackingScript()}</script>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -1,32 +1,32 @@
|
||||
import React from 'react'
|
||||
import { activeRouteData } from '../utils/routes'
|
||||
import React from "react";
|
||||
import { activeRouteData } from "../utils/routes";
|
||||
|
||||
function GitHub () {
|
||||
function GitHub() {
|
||||
return (
|
||||
<svg
|
||||
width='24px'
|
||||
height='24px'
|
||||
viewBox='0 0 256 250'
|
||||
version='1.1'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
xmlnsXlink='http://www.w3.org/1999/xlink'
|
||||
preserveAspectRatio='xMidYMid'
|
||||
width="24px"
|
||||
height="24px"
|
||||
viewBox="0 0 256 250"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||
preserveAspectRatio="xMidYMid"
|
||||
>
|
||||
<g>
|
||||
<path
|
||||
d='M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z'
|
||||
fill='#161614'
|
||||
d="M128.00106,0 C57.3172926,0 0,57.3066942 0,128.00106 C0,184.555281 36.6761997,232.535542 87.534937,249.460899 C93.9320223,250.645779 96.280588,246.684165 96.280588,243.303333 C96.280588,240.251045 96.1618878,230.167899 96.106777,219.472176 C60.4967585,227.215235 52.9826207,204.369712 52.9826207,204.369712 C47.1599584,189.574598 38.770408,185.640538 38.770408,185.640538 C27.1568785,177.696113 39.6458206,177.859325 39.6458206,177.859325 C52.4993419,178.762293 59.267365,191.04987 59.267365,191.04987 C70.6837675,210.618423 89.2115753,204.961093 96.5158685,201.690482 C97.6647155,193.417512 100.981959,187.77078 104.642583,184.574357 C76.211799,181.33766 46.324819,170.362144 46.324819,121.315702 C46.324819,107.340889 51.3250588,95.9223682 59.5132437,86.9583937 C58.1842268,83.7344152 53.8029229,70.715562 60.7532354,53.0843636 C60.7532354,53.0843636 71.5019501,49.6441813 95.9626412,66.2049595 C106.172967,63.368876 117.123047,61.9465949 128.00106,61.8978432 C138.879073,61.9465949 149.837632,63.368876 160.067033,66.2049595 C184.49805,49.6441813 195.231926,53.0843636 195.231926,53.0843636 C202.199197,70.715562 197.815773,83.7344152 196.486756,86.9583937 C204.694018,95.9223682 209.660343,107.340889 209.660343,121.315702 C209.660343,170.478725 179.716133,181.303747 151.213281,184.472614 C155.80443,188.444828 159.895342,196.234518 159.895342,208.176593 C159.895342,225.303317 159.746968,239.087361 159.746968,243.303333 C159.746968,246.709601 162.05102,250.70089 168.53925,249.443941 C219.370432,232.499507 256,184.536204 256,128.00106 C256,57.3066942 198.691187,0 128.00106,0 Z M47.9405593,182.340212 C47.6586465,182.976105 46.6581745,183.166873 45.7467277,182.730227 C44.8183235,182.312656 44.2968914,181.445722 44.5978808,180.80771 C44.8734344,180.152739 45.876026,179.97045 46.8023103,180.409216 C47.7328342,180.826786 48.2627451,181.702199 47.9405593,182.340212 Z M54.2367892,187.958254 C53.6263318,188.524199 52.4329723,188.261363 51.6232682,187.366874 C50.7860088,186.474504 50.6291553,185.281144 51.2480912,184.70672 C51.8776254,184.140775 53.0349512,184.405731 53.8743302,185.298101 C54.7115892,186.201069 54.8748019,187.38595 54.2367892,187.958254 Z M58.5562413,195.146347 C57.7719732,195.691096 56.4895886,195.180261 55.6968417,194.042013 C54.9125733,192.903764 54.9125733,191.538713 55.713799,190.991845 C56.5086651,190.444977 57.7719732,190.936735 58.5753181,192.066505 C59.3574669,193.22383 59.3574669,194.58888 58.5562413,195.146347 Z M65.8613592,203.471174 C65.1597571,204.244846 63.6654083,204.03712 62.5716717,202.981538 C61.4524999,201.94927 61.1409122,200.484596 61.8446341,199.710926 C62.5547146,198.935137 64.0575422,199.15346 65.1597571,200.200564 C66.2704506,201.230712 66.6095936,202.705984 65.8613592,203.471174 Z M75.3025151,206.281542 C74.9930474,207.284134 73.553809,207.739857 72.1039724,207.313809 C70.6562556,206.875043 69.7087748,205.700761 70.0012857,204.687571 C70.302275,203.678621 71.7478721,203.20382 73.2083069,203.659543 C74.6539041,204.09619 75.6035048,205.261994 75.3025151,206.281542 Z M86.046947,207.473627 C86.0829806,208.529209 84.8535871,209.404622 83.3316829,209.4237 C81.8013,209.457614 80.563428,208.603398 80.5464708,207.564772 C80.5464708,206.498591 81.7483088,205.631657 83.2786917,205.606221 C84.8005962,205.576546 86.046947,206.424403 86.046947,207.473627 Z M96.6021471,207.069023 C96.7844366,208.099171 95.7267341,209.156872 94.215428,209.438785 C92.7295577,209.710099 91.3539086,209.074206 91.1652603,208.052538 C90.9808515,206.996955 92.0576306,205.939253 93.5413813,205.66582 C95.054807,205.402984 96.4092596,206.021919 96.6021471,207.069023 Z"
|
||||
fill="#161614"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default function ({ pathname }) {
|
||||
const { packageName, packageUrl } = activeRouteData(pathname)
|
||||
export default function({ pathname }) {
|
||||
const { packageName, packageUrl } = activeRouteData(pathname);
|
||||
|
||||
return (
|
||||
<a className='powered-by'>
|
||||
<a className="powered-by">
|
||||
<style jsx>{`
|
||||
a {
|
||||
display: inline-block;
|
||||
@@ -41,7 +41,7 @@ export default function ({ pathname }) {
|
||||
padding: 3px 20px 8px 10px;
|
||||
border: 1px solid #eee;
|
||||
z-index: 999999;
|
||||
font-family: 'Lato';
|
||||
font-family: "Lato";
|
||||
box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.55);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
@@ -62,10 +62,10 @@ export default function ({ pathname }) {
|
||||
margin-left: 10px;
|
||||
}
|
||||
`}</style>
|
||||
<a href={packageUrl} target='_blank'>
|
||||
<i className='icon-npm' />
|
||||
<a href={packageUrl} target="_blank">
|
||||
<i className="icon-npm" />
|
||||
<span>{packageName}</span>
|
||||
</a>
|
||||
</a>
|
||||
)
|
||||
);
|
||||
}
|
||||
+35
-37
@@ -1,44 +1,40 @@
|
||||
const BabiliPlugin = require("babili-webpack-plugin")
|
||||
const webpack = require("webpack")
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
|
||||
const { ANALYZE } = process.env
|
||||
const glob = require("glob")
|
||||
const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin")
|
||||
const BabiliPlugin = require("babili-webpack-plugin");
|
||||
const webpack = require("webpack");
|
||||
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
||||
const { ANALYZE } = process.env;
|
||||
const glob = require("glob");
|
||||
const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
webpack: (config, { dev }) => {
|
||||
config.plugins = config.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin');
|
||||
config.plugins = config.plugins.filter(
|
||||
plugin => plugin.constructor.name !== "UglifyJsPlugin"
|
||||
);
|
||||
|
||||
config.node = {
|
||||
fs: 'empty'
|
||||
}
|
||||
fs: "empty"
|
||||
};
|
||||
|
||||
config.module.rules.push(
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [ 'style-loader', 'css-loader' ]
|
||||
}
|
||||
)
|
||||
config.module.rules.push({
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader"]
|
||||
});
|
||||
|
||||
config.plugins.push(
|
||||
new webpack.DefinePlugin({IN_BROWSER: true})
|
||||
)
|
||||
config.plugins.push(new webpack.DefinePlugin({ IN_BROWSER: true }));
|
||||
|
||||
config.resolve.alias = {
|
||||
'babel-core': 'babel-standalone'
|
||||
}
|
||||
"babel-core": "babel-standalone"
|
||||
};
|
||||
|
||||
if (!dev) {
|
||||
config.plugins.push(
|
||||
new BabiliPlugin()
|
||||
)
|
||||
config.plugins.push(new BabiliPlugin());
|
||||
|
||||
config.plugins.push(
|
||||
new SWPrecacheWebpackPlugin({
|
||||
minify: true,
|
||||
staticFileGlobsIgnorePatterns: [/\.next\//],
|
||||
staticFileGlobs: [
|
||||
'static/**/*' // Precache all static files by default
|
||||
"static/**/*" // Precache all static files by default
|
||||
],
|
||||
runtimeCaching: [
|
||||
{
|
||||
@@ -47,27 +43,29 @@ module.exports = {
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (ANALYZE) {
|
||||
config.plugins.push(new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'server',
|
||||
analyzerPort: 8888,
|
||||
openAnalyzer: true
|
||||
}))
|
||||
config.plugins.push(
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode: "server",
|
||||
analyzerPort: 8888,
|
||||
openAnalyzer: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
|
||||
exportPathMap() {
|
||||
const pathMap = {}
|
||||
glob.sync('pages/**/*.js', { ignore: 'pages/_document.js' }).forEach(s => {
|
||||
const path = s.split(/(pages|\.)/)[2].replace(/^\/index$/, '/')
|
||||
console.log(path)
|
||||
pathMap[path] = { page: path }
|
||||
})
|
||||
return pathMap
|
||||
const pathMap = {};
|
||||
glob.sync("pages/**/*.js", { ignore: "pages/_document.js" }).forEach(s => {
|
||||
const path = s.split(/(pages|\.)/)[2].replace(/^\/index$/, "/");
|
||||
console.log(path);
|
||||
pathMap[path] = { page: path };
|
||||
});
|
||||
return pathMap;
|
||||
}
|
||||
};
|
||||
+3
-4
@@ -10,13 +10,13 @@
|
||||
"dev": "next dev",
|
||||
"addContributor": "all-contributors add",
|
||||
"analyze": "cross-env ANALYZE=1 next build",
|
||||
"format": "prettier-standard **/*.js",
|
||||
"format": "prettier --write **/*.js",
|
||||
"deploy": "yarn build && cd transform && now",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"precommit": "lint-staged"
|
||||
},
|
||||
"lint-staged": {
|
||||
"**/*.{js,json,css}": ["prettier-standard", "git add"]
|
||||
"**/*.{js,json,css}": ["prettier --write", "git add"]
|
||||
},
|
||||
"keywords": [],
|
||||
"author": {
|
||||
@@ -50,7 +50,6 @@
|
||||
"lodash": "^4.17.4",
|
||||
"next": "4.0.0-beta.2",
|
||||
"nprogress": "^0.2.0",
|
||||
"prettier": "^1.8.2",
|
||||
"promise-worker": "^1.1.1",
|
||||
"prop-types": "^15.6.0",
|
||||
"rc-collapse": "^1.7.6",
|
||||
@@ -75,7 +74,7 @@
|
||||
"glob": "^7.1.2",
|
||||
"husky": "^0.14.3",
|
||||
"lint-staged": "^4.2.3",
|
||||
"prettier-standard": "^7.0.3",
|
||||
"prettier": "^1.8.2",
|
||||
"style-loader": "^0.19.0",
|
||||
"sw-precache-webpack-plugin": "^0.11.4",
|
||||
"webpack-bundle-analyzer": "^2.9.0",
|
||||
|
||||
+19
-19
@@ -1,8 +1,8 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import { convertCssForEmotion } from 'css-in-js-generator/lib/convertCssForEmotion'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
import { convertCssForEmotion } from "css-in-js-generator/lib/convertCssForEmotion";
|
||||
|
||||
const defaultText = `
|
||||
*,
|
||||
@@ -97,40 +97,40 @@ select.form-control:not([size]):not([multiple]) {
|
||||
color: #868e96;
|
||||
opacity: 1;
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export default class extends PureComponent {
|
||||
state = {
|
||||
isRn: false
|
||||
}
|
||||
};
|
||||
|
||||
getTransformedValue = code => {
|
||||
const emotionCode = convertCssForEmotion(code)
|
||||
const emotionCode = convertCssForEmotion(code);
|
||||
return emotionCode.replace(
|
||||
/injectGlobal`([\n\w\W]*)`/gi,
|
||||
(match, group) => {
|
||||
return `injectGlobal\`
|
||||
${group.replace(/[\r\n]+/g, '\n\n')}
|
||||
\``
|
||||
${group.replace(/[\r\n]+/g, "\n\n")}
|
||||
\``;
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='CSS'
|
||||
rightTitle='Emotion'
|
||||
leftMode='css'
|
||||
rightMode='typescript'
|
||||
leftTitle="CSS"
|
||||
rightTitle="Emotion"
|
||||
leftMode="css"
|
||||
rightMode="typescript"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'css_to_js'}
|
||||
name={"css_to_js"}
|
||||
defaultText={defaultText}
|
||||
extensions={null}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -1,8 +1,8 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
|
||||
const defaultText = `.main-wrapper {
|
||||
flex-direction: row;
|
||||
@@ -24,37 +24,37 @@ li {
|
||||
color: whitesmoke;
|
||||
line-height: 44px;
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export default class extends PureComponent {
|
||||
state = {
|
||||
isRn: false
|
||||
}
|
||||
};
|
||||
|
||||
getTransformedValue = code => {
|
||||
this.promiseWorker = loadWorker('css-to-js.js', this).promiseWorker
|
||||
return this.promiseWorker.postMessage({ code, isRn: this.state.isRn })
|
||||
}
|
||||
this.promiseWorker = loadWorker("css-to-js.js", this).promiseWorker;
|
||||
return this.promiseWorker.postMessage({ code, isRn: this.state.isRn });
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='CSS'
|
||||
rightTitle='JavaScript'
|
||||
leftMode='css'
|
||||
rightMode='javascript'
|
||||
leftTitle="CSS"
|
||||
rightTitle="JavaScript"
|
||||
leftMode="css"
|
||||
rightMode="javascript"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'css_to_js'}
|
||||
name={"css_to_js"}
|
||||
defaultText={defaultText}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isRn: checked }, cb)
|
||||
}
|
||||
checkboxText='React Native'
|
||||
checkboxText="React Native"
|
||||
extensions={null}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+21
-18
@@ -1,39 +1,42 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { dummySchema, dummyQuery } from '../utils/graphql-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { dummySchema, dummyQuery } from "../utils/graphql-schema";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = (newValue, splitValue) => {
|
||||
this.promiseWorker = loadWorker('graphql-to-flow-ts.js', this).promiseWorker
|
||||
this.promiseWorker = loadWorker(
|
||||
"graphql-to-flow-ts.js",
|
||||
this
|
||||
).promiseWorker;
|
||||
return this.promiseWorker.postMessage({
|
||||
schema: newValue,
|
||||
query: splitValue,
|
||||
convertTo: 'flow'
|
||||
})
|
||||
}
|
||||
convertTo: "flow"
|
||||
});
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='Schema'
|
||||
rightTitle='Flow'
|
||||
leftTitle="Schema"
|
||||
rightTitle="Flow"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'graphql_to_typescript'}
|
||||
name={"graphql_to_typescript"}
|
||||
defaultText={dummySchema}
|
||||
leftMode='json'
|
||||
rightMode='flow'
|
||||
leftMode="json"
|
||||
rightMode="flow"
|
||||
url={this.props.url}
|
||||
splitLeft={true}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={'Query'}
|
||||
splitMode={"graphql"}
|
||||
splitTitle={"Query"}
|
||||
splitValue={dummyQuery}
|
||||
prettifyRightPanel={false}
|
||||
extensions={null}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,42 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { dummySchema, dummyQuery } from '../utils/graphql-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { dummySchema, dummyQuery } from "../utils/graphql-schema";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = (newValue, splitValue) => {
|
||||
this.promiseWorker = loadWorker('graphql-to-flow-ts.js', this).promiseWorker
|
||||
this.promiseWorker = loadWorker(
|
||||
"graphql-to-flow-ts.js",
|
||||
this
|
||||
).promiseWorker;
|
||||
return this.promiseWorker.postMessage({
|
||||
schema: newValue,
|
||||
query: splitValue,
|
||||
convertTo: 'typescript'
|
||||
})
|
||||
}
|
||||
convertTo: "typescript"
|
||||
});
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='Schema'
|
||||
rightTitle='TypeScript Definition'
|
||||
leftTitle="Schema"
|
||||
rightTitle="TypeScript Definition"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'graphql_to_typescript'}
|
||||
name={"graphql_to_typescript"}
|
||||
defaultText={dummySchema}
|
||||
leftMode='json'
|
||||
rightMode='typescript'
|
||||
leftMode="json"
|
||||
rightMode="typescript"
|
||||
url={this.props.url}
|
||||
splitLeft={true}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={'Query'}
|
||||
splitMode={"graphql"}
|
||||
splitTitle={"Query"}
|
||||
splitValue={dummyQuery}
|
||||
prettifyRightPanel={false}
|
||||
extensions={null}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+25
-25
@@ -1,58 +1,58 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import HTMLtoJSX from '@tsuyoshiwada/htmltojsx'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import isSvg from 'is-svg'
|
||||
import svgo from 'transform-svg-to-native/dist/svgo'
|
||||
import React, { PureComponent } from "react";
|
||||
import HTMLtoJSX from "@tsuyoshiwada/htmltojsx";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import isSvg from "is-svg";
|
||||
import svgo from "transform-svg-to-native/dist/svgo";
|
||||
|
||||
const converter = new HTMLtoJSX({
|
||||
createClass: false
|
||||
})
|
||||
});
|
||||
|
||||
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>`
|
||||
</svg>`;
|
||||
|
||||
export default class Css2Js extends PureComponent {
|
||||
state = {
|
||||
shouldOptimize: true
|
||||
}
|
||||
};
|
||||
|
||||
convertHtmlToJsx = html => {
|
||||
if (isSvg(html) && this.state.shouldOptimize) {
|
||||
return new Promise(resolve => {
|
||||
svgo.optimize(html, result => {
|
||||
resolve(converter.convert(result.data))
|
||||
})
|
||||
})
|
||||
resolve(converter.convert(result.data));
|
||||
});
|
||||
});
|
||||
}
|
||||
return converter.convert(html)
|
||||
}
|
||||
return converter.convert(html);
|
||||
};
|
||||
|
||||
getTransformedValue = async (newValue: string) => {
|
||||
return this.convertHtmlToJsx(newValue)
|
||||
}
|
||||
return this.convertHtmlToJsx(newValue);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
url={this.props.url}
|
||||
leftTitle='HTML/SVG'
|
||||
rightTitle='JSX'
|
||||
leftMode='html'
|
||||
rightMode='jsx'
|
||||
leftTitle="HTML/SVG"
|
||||
rightTitle="JSX"
|
||||
leftMode="html"
|
||||
rightMode="jsx"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'html_to_jsx'}
|
||||
name={"html_to_jsx"}
|
||||
defaultText={defaultText}
|
||||
checkboxText='Optimize SVG'
|
||||
extensions={['.svg', '.html']}
|
||||
checkboxText="Optimize SVG"
|
||||
extensions={[".svg", ".html"]}
|
||||
initialCheckboxValue={this.state.shouldOptimize}
|
||||
onCheckboxChange={(checked: boolean, cb: Function) =>
|
||||
this.setState({ shouldOptimize: checked }, cb)
|
||||
}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+27
-27
@@ -1,58 +1,58 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import merge from 'lodash/merge'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import merge from "lodash/merge";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
|
||||
export default class Main extends PureComponent {
|
||||
state = {
|
||||
isImmutable: false
|
||||
}
|
||||
};
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
let code = JSON.parse(newValue)
|
||||
if (typeof code !== 'object' || Array.isArray(code)) {
|
||||
code = merge({}, ...code)
|
||||
let code = JSON.parse(newValue);
|
||||
if (typeof code !== "object" || Array.isArray(code)) {
|
||||
code = merge({}, ...code);
|
||||
}
|
||||
code = 'const propTypes = ' + JSON.stringify(code)
|
||||
this.promiseWorker = loadWorker('json-to-proptypes.js', this).promiseWorker
|
||||
code = "const propTypes = " + JSON.stringify(code);
|
||||
this.promiseWorker = loadWorker("json-to-proptypes.js", this).promiseWorker;
|
||||
return this.promiseWorker.postMessage({
|
||||
isImmutable: this.state.isImmutable,
|
||||
code
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
if ('serviceWorker' in navigator) {
|
||||
componentDidMount() {
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register('/service-worker.js')
|
||||
.register("/service-worker.js")
|
||||
.then(registration => {
|
||||
console.log('service worker registration successful')
|
||||
console.log("service worker registration successful");
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn('service worker registration failed')
|
||||
})
|
||||
console.warn("service worker registration failed");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='PropTypes'
|
||||
leftMode='json'
|
||||
leftTitle="JSON"
|
||||
rightTitle="PropTypes"
|
||||
leftMode="json"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'prop_types'}
|
||||
name={"prop_types"}
|
||||
defaultText={defaultText}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isImmutable: checked }, cb)
|
||||
}
|
||||
checkboxText='Immutable Proptypes'
|
||||
checkboxText="Immutable Proptypes"
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -1,31 +1,31 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import stringify from 'stringify-object'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import text from '../utils/dummy-object-json'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import stringify from "stringify-object";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import text from "../utils/dummy-object-json";
|
||||
|
||||
const defaultText = stringify(eval(`(${text})`))
|
||||
const defaultText = stringify(eval(`(${text})`));
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
return JSON.stringify(eval('(' + newValue + ')'), null, 2)
|
||||
}
|
||||
return JSON.stringify(eval("(" + newValue + ")"), null, 2);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JS Object'
|
||||
rightTitle='JSON'
|
||||
leftTitle="JS Object"
|
||||
rightTitle="JSON"
|
||||
url={this.props.url}
|
||||
leftMode='json'
|
||||
rightMode='json'
|
||||
leftMode="json"
|
||||
rightMode="json"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'js_to_json'}
|
||||
name={"js_to_json"}
|
||||
defaultText={defaultText}
|
||||
extensions={null}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import json from '../utils/dummy-json-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import json from "../utils/dummy-json-schema";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => {
|
||||
this.promiseWorker = loadWorker(
|
||||
'json-schema-to-rust-serde.js',
|
||||
"json-schema-to-rust-serde.js",
|
||||
this
|
||||
).promiseWorker
|
||||
return this.promiseWorker.postMessage(code)
|
||||
}
|
||||
).promiseWorker;
|
||||
return this.promiseWorker.postMessage(code);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON Schema'
|
||||
rightTitle='Rust Serde'
|
||||
leftTitle="JSON Schema"
|
||||
rightTitle="Rust Serde"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
defaultText={json}
|
||||
leftMode='javascript'
|
||||
rightMode='rust'
|
||||
leftMode="javascript"
|
||||
rightMode="rust"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { compile } from 'json-schema-to-typescript'
|
||||
import json from '../utils/dummy-json-schema'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { compile } from "json-schema-to-typescript";
|
||||
import json from "../utils/dummy-json-schema";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => compile(eval('(' + code + ')'))
|
||||
getTransformedValue = code => compile(eval("(" + code + ")"));
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON Schema'
|
||||
rightTitle='TypeScript Interface'
|
||||
leftTitle="JSON Schema"
|
||||
rightTitle="TypeScript Interface"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'ts_interface'}
|
||||
name={"ts_interface"}
|
||||
defaultText={json}
|
||||
leftMode='javascript'
|
||||
rightMode='typescript'
|
||||
leftMode="javascript"
|
||||
rightMode="typescript"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -1,32 +1,32 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import { bigquery } from 'generate-schema'
|
||||
import stringify from 'stringify-object'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import defaultText from '../utils/dummy-object-json'
|
||||
import React, { PureComponent } from "react";
|
||||
import { bigquery } from "generate-schema";
|
||||
import stringify from "stringify-object";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
import defaultText from "../utils/dummy-object-json";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue)
|
||||
return stringify(bigquery(value))
|
||||
}
|
||||
const value = JSON.parse(newValue);
|
||||
return stringify(bigquery(value));
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Big Query Schema'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Big Query Schema"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'big-query'}
|
||||
name={"big-query"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='javascript'
|
||||
leftMode="json"
|
||||
rightMode="javascript"
|
||||
url={this.props.url}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,28 +1,28 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
import React, { PureComponent } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => transform(code)
|
||||
getTransformedValue = code => transform(code);
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Flow Types'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Flow Types"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'ts_interface'}
|
||||
name={"ts_interface"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='flow'
|
||||
leftMode="json"
|
||||
rightMode="flow"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -1,30 +1,30 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import json2go from '../utils/json-to-go'
|
||||
import gofmt from 'gofmt.js'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import json2go from "../utils/json-to-go";
|
||||
import gofmt from "gofmt.js";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = code => gofmt(json2go(code).go)
|
||||
getTransformedValue = code => gofmt(json2go(code).go);
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Go Struct'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Go Struct"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'ts_interface'}
|
||||
name={"ts_interface"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='go'
|
||||
leftMode="json"
|
||||
rightMode="go"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import plugin from '../utils/babel-plugin-js-to-mobx-state-tree'
|
||||
import Layout from '../components/Layout'
|
||||
import { transform } from 'babel-standalone'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import React, { PureComponent } from "react";
|
||||
import plugin from "../utils/babel-plugin-js-to-mobx-state-tree";
|
||||
import Layout from "../components/Layout";
|
||||
import { transform } from "babel-standalone";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
|
||||
export default class Main extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
newValue = 'const MyModel = ' + newValue
|
||||
newValue = "const MyModel = " + newValue;
|
||||
const { code } = transform(newValue, {
|
||||
presets: ['es2015'],
|
||||
presets: ["es2015"],
|
||||
plugins: [plugin]
|
||||
})
|
||||
return code
|
||||
}
|
||||
});
|
||||
return code;
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='MobX-State-Tree Model'
|
||||
leftTitle="JSON"
|
||||
rightTitle="MobX-State-Tree Model"
|
||||
url={this.props.url}
|
||||
leftMode='json'
|
||||
leftMode="json"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'mobx_state_tree_model'}
|
||||
name={"mobx_state_tree_model"}
|
||||
defaultText={defaultText}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -1,33 +1,33 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import { mongoose } from 'generate-schema'
|
||||
import stringify from 'stringify-object'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import defaultText from '../utils/dummy-object-json'
|
||||
import React, { PureComponent } from "react";
|
||||
import { mongoose } from "generate-schema";
|
||||
import stringify from "stringify-object";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
import defaultText from "../utils/dummy-object-json";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue)
|
||||
return stringify(mongoose(value))
|
||||
}
|
||||
const value = JSON.parse(newValue);
|
||||
return stringify(mongoose(value));
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Mongoose Schema'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Mongoose Schema"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'mongoose'}
|
||||
name={"mongoose"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='javascript'
|
||||
leftMode="json"
|
||||
rightMode="javascript"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,32 +1,32 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import { mysql } from 'generate-schema'
|
||||
import Layout from '../components/Layout'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import React, { PureComponent } from "react";
|
||||
import { mysql } from "generate-schema";
|
||||
import Layout from "../components/Layout";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue)
|
||||
return mysql(value)
|
||||
}
|
||||
const value = JSON.parse(newValue);
|
||||
return mysql(value);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='MySQL Table Schema'
|
||||
leftTitle="JSON"
|
||||
rightTitle="MySQL Table Schema"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'mysql'}
|
||||
name={"mysql"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='mysql'
|
||||
leftMode="json"
|
||||
rightMode="mysql"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: 'rust-serde'
|
||||
})
|
||||
lang: "rust-serde"
|
||||
});
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Rust Serde'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Rust Serde"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'ts_interface'}
|
||||
name={"ts_interface"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='rust'
|
||||
leftMode="json"
|
||||
rightMode="rust"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: 'scala'
|
||||
})
|
||||
lang: "scala"
|
||||
});
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='Scala Case Class'
|
||||
leftTitle="JSON"
|
||||
rightTitle="Scala Case Class"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'scala_case_class'}
|
||||
name={"scala_case_class"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='scala'
|
||||
leftMode="json"
|
||||
rightMode="scala"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
import React, { PureComponent } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: 'typescript'
|
||||
})
|
||||
lang: "typescript"
|
||||
});
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON'
|
||||
rightTitle='TypeScript Interface'
|
||||
leftTitle="JSON"
|
||||
rightTitle="TypeScript Interface"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'ts_interface'}
|
||||
name={"ts_interface"}
|
||||
defaultText={defaultText}
|
||||
leftMode='json'
|
||||
rightMode='typescript'
|
||||
leftMode="json"
|
||||
rightMode="typescript"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import convertSvgString from 'transform-svg-to-native'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import isSvg from 'is-svg'
|
||||
import svgo from 'transform-svg-to-native/dist/svgo'
|
||||
import React, { PureComponent } from "react";
|
||||
import convertSvgString from "transform-svg-to-native";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import isSvg from "is-svg";
|
||||
import svgo from "transform-svg-to-native/dist/svgo";
|
||||
|
||||
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>`
|
||||
</svg>`;
|
||||
|
||||
export default class Svg2ReactNative extends PureComponent {
|
||||
getTransformedValue = async (newValue: string) => {
|
||||
if (!isSvg(newValue)) {
|
||||
throw new Error('Please provide a valid SVG markup.')
|
||||
throw new Error("Please provide a valid SVG markup.");
|
||||
}
|
||||
|
||||
return new Promise(resolve =>
|
||||
convertSvgString(newValue, code => resolve(code))
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
url={this.props.url}
|
||||
leftTitle='SVG'
|
||||
rightTitle='JSX'
|
||||
leftMode='html'
|
||||
rightMode='jsx'
|
||||
leftTitle="SVG"
|
||||
rightTitle="JSX"
|
||||
leftMode="html"
|
||||
rightMode="jsx"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'svg_to_react_native'}
|
||||
name={"svg_to_react_native"}
|
||||
defaultText={defaultText}
|
||||
extensions={['.svg', '.html']}
|
||||
extensions={[".svg", ".html"]}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -1,8 +1,8 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import { xml2json } from 'xml-js'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import PoweredBy from '../components/PoweredBy'
|
||||
import React, { PureComponent } from "react";
|
||||
import { xml2json } from "xml-js";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import PoweredBy from "../components/PoweredBy";
|
||||
|
||||
const text = `<note>
|
||||
<to>Tove</to>
|
||||
@@ -10,12 +10,12 @@ const text = `<note>
|
||||
<heading>Reminder</heading>
|
||||
<body>Don't forget me this weekend!</body>
|
||||
</note>
|
||||
`
|
||||
`;
|
||||
|
||||
export default class extends PureComponent {
|
||||
state = {
|
||||
isCompactMode: true
|
||||
}
|
||||
};
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
return JSON.stringify(
|
||||
@@ -24,30 +24,30 @@ export default class extends PureComponent {
|
||||
compact: this.state.isCompactMode
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
render () {
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='XML'
|
||||
rightTitle='JSON'
|
||||
leftTitle="XML"
|
||||
rightTitle="JSON"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'big-query'}
|
||||
name={"big-query"}
|
||||
defaultText={text}
|
||||
leftMode='html'
|
||||
rightMode='json'
|
||||
leftMode="html"
|
||||
rightMode="json"
|
||||
url={this.props.url}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isCompactMode: checked }, cb)
|
||||
}
|
||||
checkboxText='Compact Mode'
|
||||
checkboxText="Compact Mode"
|
||||
initialCheckboxValue={this.state.isCompactMode}
|
||||
extensions={null}
|
||||
/>
|
||||
<PoweredBy pathname={this.props.url.pathname} />
|
||||
</Layout>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
import uniqBy from 'lodash/uniqBy'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to ImmutablePropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function ({ types: t }) {
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression (path) {
|
||||
if (t.isCallExpression(path.parent)) return
|
||||
let uniqueElements = uniqBy(path.node.elements, 'type')
|
||||
ArrayExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('mapContains')
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -32,78 +32,78 @@ export default function ({ types: t }) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('listOf')
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("listOf")
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(t.identifier('ImmutablePropTypes.list'))
|
||||
path.replaceWith(t.identifier("ImmutablePropTypes.list"));
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.any'))
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.any"));
|
||||
},
|
||||
|
||||
StringLiteral (path) {
|
||||
if (path.parentKey === 'key') return
|
||||
path.replaceWith(t.identifier(`PropTypes.string`))
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`PropTypes.string`));
|
||||
},
|
||||
|
||||
NumericLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.number'))
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.number"));
|
||||
},
|
||||
|
||||
ArrowFunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.func'))
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
},
|
||||
|
||||
FunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.func'))
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
},
|
||||
|
||||
BooleanLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.bool'))
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.bool"));
|
||||
},
|
||||
|
||||
VariableDeclaration (path) {
|
||||
VariableDeclaration(path) {
|
||||
path.insertBefore(
|
||||
t.identifier(
|
||||
`import ImmutablePropTypes from 'react-immutable-proptypes'`
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
Program (path) {
|
||||
Program(path) {
|
||||
path.traverse({
|
||||
enter (path) {
|
||||
t.removeComments(path.node)
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
ObjectExpression (path) {
|
||||
ObjectExpression(path) {
|
||||
if (
|
||||
t.isVariableDeclarator(path.parent) ||
|
||||
t.isCallExpression(path.parent)
|
||||
) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
const elements = [path.node]
|
||||
const elements = [path.node];
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('mapContains')
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
),
|
||||
elements
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
import uniqBy from 'lodash/uniqBy'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to PropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function ({ types: t }) {
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression (path) {
|
||||
ArrayExpression(path) {
|
||||
// if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, 'type')
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier('t'), t.identifier('model')),
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
uniqueElements
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -28,66 +28,66 @@ export default function ({ types: t }) {
|
||||
) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier('t'), t.identifier('array')),
|
||||
t.memberExpression(t.identifier("t"), t.identifier("array")),
|
||||
uniqueElements
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(t.identifier('t.array'))
|
||||
path.replaceWith(t.identifier("t.array"));
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.null'))
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.null"));
|
||||
},
|
||||
|
||||
StringLiteral (path) {
|
||||
if (path.parentKey === 'key') return
|
||||
path.replaceWith(t.identifier(`t.string`))
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`t.string`));
|
||||
},
|
||||
|
||||
NumericLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.number'))
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.number"));
|
||||
},
|
||||
|
||||
ArrowFunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('t.frozen'))
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
},
|
||||
|
||||
FunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('t.frozen'))
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
},
|
||||
|
||||
BooleanLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.boolean'))
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.boolean"));
|
||||
},
|
||||
|
||||
Program (path) {
|
||||
Program(path) {
|
||||
path.traverse({
|
||||
enter (path) {
|
||||
t.removeComments(path.node)
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
ObjectProperty (path) {
|
||||
ObjectProperty(path) {
|
||||
if (t.isStringLiteral(path.node.key)) {
|
||||
path.node.key = t.identifier(path.node.key.value)
|
||||
path.node.key = t.identifier(path.node.key.value);
|
||||
}
|
||||
},
|
||||
|
||||
ObjectExpression (path) {
|
||||
if (t.isCallExpression(path.parent)) return
|
||||
ObjectExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
|
||||
const elements = [path.node]
|
||||
const elements = [path.node];
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier('t'), t.identifier('model')),
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
elements
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -29,6 +29,6 @@ const json = `{
|
||||
}
|
||||
},
|
||||
"required": ["firstName", "lastName"]
|
||||
}`
|
||||
}`;
|
||||
|
||||
export default json
|
||||
export default json;
|
||||
+2
-2
@@ -41,6 +41,6 @@ const x = `{
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export default x
|
||||
export default x;
|
||||
@@ -16,6 +16,6 @@ const y = `{
|
||||
"index": true,
|
||||
"required": true
|
||||
}
|
||||
}`
|
||||
}`;
|
||||
|
||||
export default y
|
||||
export default y;
|
||||
+649
-649
File diff suppressed because it is too large.
Load diff
+142
-142
@@ -7,227 +7,227 @@
|
||||
A simple utility to translate JSON into a Go type definition.
|
||||
*/
|
||||
|
||||
function jsonToGo (json, typename) {
|
||||
let data
|
||||
let scope
|
||||
let go = ''
|
||||
let tabs = 0
|
||||
function jsonToGo(json, typename) {
|
||||
let data;
|
||||
let scope;
|
||||
let go = "";
|
||||
let tabs = 0;
|
||||
|
||||
try {
|
||||
data = JSON.parse(json.replace(/\.0/g, '.1')) // hack that forces floats to stay as floats
|
||||
scope = data
|
||||
data = JSON.parse(json.replace(/\.0/g, ".1")); // hack that forces floats to stay as floats
|
||||
scope = data;
|
||||
} catch (e) {
|
||||
return {
|
||||
go: '',
|
||||
go: "",
|
||||
error: e.message
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
typename = format(typename || 'AutoGenerated')
|
||||
append('type ' + typename + ' ')
|
||||
typename = format(typename || "AutoGenerated");
|
||||
append("type " + typename + " ");
|
||||
|
||||
parseScope(scope)
|
||||
parseScope(scope);
|
||||
|
||||
return { go: go }
|
||||
return { go: go };
|
||||
|
||||
function parseScope (scope) {
|
||||
let keyname
|
||||
if (typeof scope === 'object' && scope !== null) {
|
||||
function parseScope(scope) {
|
||||
let keyname;
|
||||
if (typeof scope === "object" && scope !== null) {
|
||||
if (Array.isArray(scope)) {
|
||||
let i
|
||||
let i;
|
||||
let sliceType,
|
||||
scopeLength = scope.length
|
||||
scopeLength = scope.length;
|
||||
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
const thisType = goType(scope[i])
|
||||
if (!sliceType) sliceType = thisType
|
||||
const thisType = goType(scope[i]);
|
||||
if (!sliceType) sliceType = thisType;
|
||||
else if (sliceType !== thisType) {
|
||||
sliceType = mostSpecificPossibleGoType(thisType, sliceType)
|
||||
if (sliceType === 'interface{}') break
|
||||
sliceType = mostSpecificPossibleGoType(thisType, sliceType);
|
||||
if (sliceType === "interface{}") break;
|
||||
}
|
||||
}
|
||||
|
||||
append('[]')
|
||||
if (sliceType === 'struct') {
|
||||
let k
|
||||
let keys
|
||||
const allFields = {}
|
||||
append("[]");
|
||||
if (sliceType === "struct") {
|
||||
let k;
|
||||
let keys;
|
||||
const allFields = {};
|
||||
|
||||
// for each field counts how many times appears
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
keys = Object.keys(scope[i])
|
||||
keys = Object.keys(scope[i]);
|
||||
for (k in keys) {
|
||||
keyname = keys[k]
|
||||
keyname = keys[k];
|
||||
if (!(keyname in allFields)) {
|
||||
allFields[keyname] = {
|
||||
value: scope[i][keyname],
|
||||
count: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
allFields[keyname].count++
|
||||
allFields[keyname].count++;
|
||||
}
|
||||
}
|
||||
|
||||
// create a common struct with all fields found in the current array
|
||||
// omitempty dict indicates if a field is optional
|
||||
keys = Object.keys(allFields)
|
||||
keys = Object.keys(allFields);
|
||||
let struct = {},
|
||||
omitempty = {}
|
||||
omitempty = {};
|
||||
for (k in keys) {
|
||||
keyname = keys[k]
|
||||
let elem = allFields[keyname]
|
||||
keyname = keys[k];
|
||||
let elem = allFields[keyname];
|
||||
|
||||
struct[keyname] = elem.value
|
||||
omitempty[keyname] = elem.count !== scopeLength
|
||||
struct[keyname] = elem.value;
|
||||
omitempty[keyname] = elem.count !== scopeLength;
|
||||
}
|
||||
|
||||
parseStruct(struct, omitempty) // finally parse the struct !!
|
||||
} else if (sliceType === 'slice') {
|
||||
parseScope(scope[0])
|
||||
} else append(sliceType || 'interface{}')
|
||||
parseStruct(struct, omitempty); // finally parse the struct !!
|
||||
} else if (sliceType === "slice") {
|
||||
parseScope(scope[0]);
|
||||
} else append(sliceType || "interface{}");
|
||||
} else {
|
||||
parseStruct(scope)
|
||||
parseStruct(scope);
|
||||
}
|
||||
} else append(goType(scope))
|
||||
} else append(goType(scope));
|
||||
}
|
||||
|
||||
function parseStruct (scope, omitempty) {
|
||||
append('struct {\n')
|
||||
++tabs
|
||||
const keys = Object.keys(scope)
|
||||
function parseStruct(scope, omitempty) {
|
||||
append("struct {\n");
|
||||
++tabs;
|
||||
const keys = Object.keys(scope);
|
||||
for (const i in keys) {
|
||||
const keyname = keys[i]
|
||||
indent(tabs)
|
||||
append(format(keyname) + ' ')
|
||||
parseScope(scope[keyname])
|
||||
const keyname = keys[i];
|
||||
indent(tabs);
|
||||
append(format(keyname) + " ");
|
||||
parseScope(scope[keyname]);
|
||||
|
||||
append(' `json:"' + keyname)
|
||||
append(' `json:"' + keyname);
|
||||
if (omitempty && omitempty[keyname] === true) {
|
||||
append(',omitempty')
|
||||
append(",omitempty");
|
||||
}
|
||||
append('"`\n')
|
||||
append('"`\n');
|
||||
}
|
||||
indent(--tabs)
|
||||
append('}')
|
||||
indent(--tabs);
|
||||
append("}");
|
||||
}
|
||||
|
||||
function indent (tabs) {
|
||||
for (let i = 0; i < tabs; i++) go += '\t'
|
||||
function indent(tabs) {
|
||||
for (let i = 0; i < tabs; i++) go += "\t";
|
||||
}
|
||||
|
||||
function append (str) {
|
||||
go += str
|
||||
function append(str) {
|
||||
go += str;
|
||||
}
|
||||
|
||||
// Sanitizes and formats a string to make an appropriate identifier in Go
|
||||
function format (str) {
|
||||
if (!str) return ''
|
||||
else if (str.match(/^\d+$/)) str = 'Num' + str
|
||||
function format(str) {
|
||||
if (!str) return "";
|
||||
else if (str.match(/^\d+$/)) str = "Num" + str;
|
||||
else if (str.charAt(0).match(/\d/)) {
|
||||
const numbers = {
|
||||
'0': 'Zero_',
|
||||
'1': 'One_',
|
||||
'2': 'Two_',
|
||||
'3': 'Three_',
|
||||
'4': 'Four_',
|
||||
'5': 'Five_',
|
||||
'6': 'Six_',
|
||||
'7': 'Seven_',
|
||||
'8': 'Eight_',
|
||||
'9': 'Nine_'
|
||||
}
|
||||
str = numbers[str.charAt(0)] + str.substr(1)
|
||||
"0": "Zero_",
|
||||
"1": "One_",
|
||||
"2": "Two_",
|
||||
"3": "Three_",
|
||||
"4": "Four_",
|
||||
"5": "Five_",
|
||||
"6": "Six_",
|
||||
"7": "Seven_",
|
||||
"8": "Eight_",
|
||||
"9": "Nine_"
|
||||
};
|
||||
str = numbers[str.charAt(0)] + str.substr(1);
|
||||
}
|
||||
return toProperCase(str).replace(/[^a-z0-9]/gi, '') || 'NAMING_FAILED'
|
||||
return toProperCase(str).replace(/[^a-z0-9]/gi, "") || "NAMING_FAILED";
|
||||
}
|
||||
|
||||
// Determines the most appropriate Go type
|
||||
function goType (val) {
|
||||
if (val === null) return 'interface{}'
|
||||
function goType(val) {
|
||||
if (val === null) return "interface{}";
|
||||
|
||||
switch (typeof val) {
|
||||
case 'string':
|
||||
case "string":
|
||||
if (/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(\+\d\d:\d\d|Z)/.test(val)) {
|
||||
return 'time.Time'
|
||||
} else return 'string'
|
||||
case 'number':
|
||||
return "time.Time";
|
||||
} else return "string";
|
||||
case "number":
|
||||
if (val % 1 === 0) {
|
||||
if (val > -2147483648 && val < 2147483647) return 'int'
|
||||
else return 'int64'
|
||||
} else return 'float64'
|
||||
case 'boolean':
|
||||
return 'bool'
|
||||
case 'object':
|
||||
if (Array.isArray(val)) return 'slice'
|
||||
return 'struct'
|
||||
if (val > -2147483648 && val < 2147483647) return "int";
|
||||
else return "int64";
|
||||
} else return "float64";
|
||||
case "boolean":
|
||||
return "bool";
|
||||
case "object":
|
||||
if (Array.isArray(val)) return "slice";
|
||||
return "struct";
|
||||
default:
|
||||
return 'interface{}'
|
||||
return "interface{}";
|
||||
}
|
||||
}
|
||||
|
||||
// Given two types, returns the more specific of the two
|
||||
function mostSpecificPossibleGoType (typ1, typ2) {
|
||||
if (typ1.substr(0, 5) === 'float' && typ2.substr(0, 3) === 'int') {
|
||||
return typ1
|
||||
} else if (typ1.substr(0, 3) === 'int' && typ2.substr(0, 5) === 'float') {
|
||||
return typ1
|
||||
} else return 'interface{}'
|
||||
function mostSpecificPossibleGoType(typ1, typ2) {
|
||||
if (typ1.substr(0, 5) === "float" && typ2.substr(0, 3) === "int") {
|
||||
return typ1;
|
||||
} else if (typ1.substr(0, 3) === "int" && typ2.substr(0, 5) === "float") {
|
||||
return typ1;
|
||||
} else return "interface{}";
|
||||
}
|
||||
|
||||
// Proper cases a string according to Go conventions
|
||||
function toProperCase (str) {
|
||||
function toProperCase(str) {
|
||||
// https://github.com/golang/lint/blob/39d15d55e9777df34cdffde4f406ab27fd2e60c0/lint.go#L695-L731
|
||||
const commonInitialisms = [
|
||||
'API',
|
||||
'ASCII',
|
||||
'CPU',
|
||||
'CSS',
|
||||
'DNS',
|
||||
'EOF',
|
||||
'GUID',
|
||||
'HTML',
|
||||
'HTTP',
|
||||
'HTTPS',
|
||||
'ID',
|
||||
'IP',
|
||||
'JSON',
|
||||
'LHS',
|
||||
'QPS',
|
||||
'RAM',
|
||||
'RHS',
|
||||
'RPC',
|
||||
'SLA',
|
||||
'SMTP',
|
||||
'SSH',
|
||||
'TCP',
|
||||
'TLS',
|
||||
'TTL',
|
||||
'UDP',
|
||||
'UI',
|
||||
'UID',
|
||||
'UUID',
|
||||
'URI',
|
||||
'URL',
|
||||
'UTF8',
|
||||
'VM',
|
||||
'XML',
|
||||
'XSRF',
|
||||
'XSS'
|
||||
]
|
||||
"API",
|
||||
"ASCII",
|
||||
"CPU",
|
||||
"CSS",
|
||||
"DNS",
|
||||
"EOF",
|
||||
"GUID",
|
||||
"HTML",
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"ID",
|
||||
"IP",
|
||||
"JSON",
|
||||
"LHS",
|
||||
"QPS",
|
||||
"RAM",
|
||||
"RHS",
|
||||
"RPC",
|
||||
"SLA",
|
||||
"SMTP",
|
||||
"SSH",
|
||||
"TCP",
|
||||
"TLS",
|
||||
"TTL",
|
||||
"UDP",
|
||||
"UI",
|
||||
"UID",
|
||||
"UUID",
|
||||
"URI",
|
||||
"URL",
|
||||
"UTF8",
|
||||
"VM",
|
||||
"XML",
|
||||
"XSRF",
|
||||
"XSS"
|
||||
];
|
||||
|
||||
return str
|
||||
.replace(/(^|[^a-zA-Z])([a-z]+)/g, function (unused, sep, frag) {
|
||||
.replace(/(^|[^a-zA-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(frag.toUpperCase()) >= 0) {
|
||||
return sep + frag.toUpperCase()
|
||||
} else return sep + frag[0].toUpperCase() + frag.substr(1).toLowerCase()
|
||||
return sep + frag.toUpperCase();
|
||||
} else return sep + frag[0].toUpperCase() + frag.substr(1).toLowerCase();
|
||||
})
|
||||
.replace(/([A-Z])([a-z]+)/g, function (unused, sep, frag) {
|
||||
.replace(/([A-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(sep + frag.toUpperCase()) >= 0) {
|
||||
return (sep + frag).toUpperCase()
|
||||
} else return sep + frag
|
||||
})
|
||||
return (sep + frag).toUpperCase();
|
||||
} else return sep + frag;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = jsonToGo
|
||||
module.exports = jsonToGo;
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
export default function (fileName, self) {
|
||||
if (self && self.promiseWorker) return { promiseWorker: self.promiseWorker }
|
||||
const PromiseWorker = require('promise-worker')
|
||||
const MyWorker = require(`worker-loader?inline!../workers/${fileName}`)
|
||||
const worker = new MyWorker()
|
||||
const promiseWorker = new PromiseWorker(worker)
|
||||
export default function(fileName, self) {
|
||||
if (self && self.promiseWorker) return { promiseWorker: self.promiseWorker };
|
||||
const PromiseWorker = require("promise-worker");
|
||||
const MyWorker = require(`worker-loader?inline!../workers/${fileName}`);
|
||||
const worker = new MyWorker();
|
||||
const promiseWorker = new PromiseWorker(worker);
|
||||
|
||||
return { worker, promiseWorker }
|
||||
return { worker, promiseWorker };
|
||||
}
|
||||
+114
-114
@@ -1,218 +1,218 @@
|
||||
import flatten from 'lodash/flatten'
|
||||
import find from 'lodash/find'
|
||||
import flatten from "lodash/flatten";
|
||||
import find from "lodash/find";
|
||||
|
||||
function GraphQLIcon () {
|
||||
function GraphQLIcon() {
|
||||
return (
|
||||
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z'
|
||||
fill="#ffffff"
|
||||
d="M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z"
|
||||
/>
|
||||
<path fill='#ffffff' d='M39.8 272.2h320.3v16.6H39.8z' />
|
||||
<path fill="#ffffff" d="M39.8 272.2h320.3v16.6H39.8z" />
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z'
|
||||
fill="#ffffff"
|
||||
d="M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z"
|
||||
/>
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z'
|
||||
fill="#ffffff"
|
||||
d="M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z"
|
||||
/>
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z'
|
||||
fill="#ffffff"
|
||||
d="M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z"
|
||||
/>
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z'
|
||||
fill="#ffffff"
|
||||
d="M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z"
|
||||
/>
|
||||
<path
|
||||
fill='#ffffff'
|
||||
d='M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9'
|
||||
fill="#ffffff"
|
||||
d="M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export const categorizedRoutes = [
|
||||
{
|
||||
category: 'React',
|
||||
iconName: 'icon-reactjs',
|
||||
category: "React",
|
||||
iconName: "icon-reactjs",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to React PropTypes',
|
||||
path: '/',
|
||||
title: 'Transform | All important transforms at one place.',
|
||||
label: "JSON to React PropTypes",
|
||||
path: "/",
|
||||
title: "Transform | All important transforms at one place.",
|
||||
desc:
|
||||
'An online utility to convert a JSON object to prop-types, Typescript Interface, Rust serde or flow types. It also converts your CSS into JS and HTML into JSX.'
|
||||
"An online utility to convert a JSON object to prop-types, Typescript Interface, Rust serde or flow types. It also converts your CSS into JS and HTML into JSX."
|
||||
},
|
||||
{
|
||||
label: 'HTML/SVG to JSX',
|
||||
path: '/html-to-jsx',
|
||||
label: "HTML/SVG to JSX",
|
||||
path: "/html-to-jsx",
|
||||
desc:
|
||||
'An online REPL for converting HTML to JSX with proper support for SVG.'
|
||||
"An online REPL for converting HTML to JSX with proper support for SVG."
|
||||
},
|
||||
{
|
||||
label: 'SVG to React Native',
|
||||
path: '/svg-to-react-native',
|
||||
label: "SVG to React Native",
|
||||
path: "/svg-to-react-native",
|
||||
desc:
|
||||
'An online REPL for converting SVG to React Native compatible equivalent.'
|
||||
"An online REPL for converting SVG to React Native compatible equivalent."
|
||||
},
|
||||
{
|
||||
label: 'CSS to JS Objects',
|
||||
path: '/css-to-js',
|
||||
label: "CSS to JS Objects",
|
||||
path: "/css-to-js",
|
||||
desc:
|
||||
'An online REPL for converting CSS to JS object. It also gives style optimized for React Native.',
|
||||
packageName: 'transform-css-to-js',
|
||||
packageUrl: 'https://github.com/transform-it/transform-css-to-js'
|
||||
"An online REPL for converting CSS to JS object. It also gives style optimized for React Native.",
|
||||
packageName: "transform-css-to-js",
|
||||
packageUrl: "https://github.com/transform-it/transform-css-to-js"
|
||||
},
|
||||
{
|
||||
label: 'CSS to Emotion',
|
||||
path: '/css-to-emotion',
|
||||
desc: 'An online REPL for converting CSS to Emotion compatible code.',
|
||||
packageName: 'css-in-js-generator',
|
||||
packageUrl: 'https://github.com/brikou/CSS-in-JS-generator',
|
||||
label: "CSS to Emotion",
|
||||
path: "/css-to-emotion",
|
||||
desc: "An online REPL for converting CSS to Emotion compatible code.",
|
||||
packageName: "css-in-js-generator",
|
||||
packageUrl: "https://github.com/brikou/CSS-in-JS-generator",
|
||||
beta: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'JavaScript',
|
||||
iconName: 'icon-javascript',
|
||||
category: "JavaScript",
|
||||
iconName: "icon-javascript",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to Flow Types',
|
||||
path: '/json-to-flow-types',
|
||||
desc: 'An online REPL for converting JSON to generate Flow Types.'
|
||||
label: "JSON to Flow Types",
|
||||
path: "/json-to-flow-types",
|
||||
desc: "An online REPL for converting JSON to generate Flow Types."
|
||||
},
|
||||
{
|
||||
label: 'JSON to Typescript Interface',
|
||||
path: '/json-to-ts-interface',
|
||||
label: "JSON to Typescript Interface",
|
||||
path: "/json-to-ts-interface",
|
||||
desc:
|
||||
'An online REPL for converting JSON to generate TypeScript Interface.'
|
||||
"An online REPL for converting JSON to generate TypeScript Interface."
|
||||
},
|
||||
{
|
||||
label: 'JSON to MobX-State-Tree Model',
|
||||
path: '/json-to-mobx-state-tree',
|
||||
desc: 'An online REPL for converting JSON to generate Mobx State Tree.'
|
||||
label: "JSON to MobX-State-Tree Model",
|
||||
path: "/json-to-mobx-state-tree",
|
||||
desc: "An online REPL for converting JSON to generate Mobx State Tree."
|
||||
},
|
||||
{
|
||||
label: 'JS Object to JSON',
|
||||
path: '/js-object-to-json',
|
||||
desc: 'An online REPL for converting JS Object to JSON.'
|
||||
label: "JS Object to JSON",
|
||||
path: "/js-object-to-json",
|
||||
desc: "An online REPL for converting JS Object to JSON."
|
||||
},
|
||||
{
|
||||
label: 'JSON Schema to TypeScript',
|
||||
path: '/json-schema-to-ts',
|
||||
label: "JSON Schema to TypeScript",
|
||||
path: "/json-schema-to-ts",
|
||||
desc:
|
||||
'An online REPL for converting JSON Schema to TypeScript Interface.',
|
||||
packageName: 'json-schema-to-typescript',
|
||||
packageUrl: 'https://github.com/bcherny/json-schema-to-typescript'
|
||||
"An online REPL for converting JSON Schema to TypeScript Interface.",
|
||||
packageName: "json-schema-to-typescript",
|
||||
packageUrl: "https://github.com/bcherny/json-schema-to-typescript"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'Rust',
|
||||
iconName: 'icon-rust',
|
||||
category: "Rust",
|
||||
iconName: "icon-rust",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to Rust Serde',
|
||||
path: '/json-to-rust-serde',
|
||||
desc: 'An online REPL for converting JSON to Rust Serde Structs.'
|
||||
label: "JSON to Rust Serde",
|
||||
path: "/json-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON to Rust Serde Structs."
|
||||
},
|
||||
{
|
||||
label: 'JSON Schema to Rust Serde',
|
||||
path: '/json-schema-to-rust-serde',
|
||||
desc: 'An online REPL for converting JSON Schema to Rust Serde Structs.'
|
||||
label: "JSON Schema to Rust Serde",
|
||||
path: "/json-schema-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON Schema to Rust Serde Structs."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'Databases',
|
||||
iconName: 'icon-database',
|
||||
category: "Databases",
|
||||
iconName: "icon-database",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to Mongoose Schema',
|
||||
path: '/json-to-mongoose',
|
||||
desc: 'An online REPL to generate Mongoose Schema from JSON.',
|
||||
packageName: 'generate-schema',
|
||||
packageUrl: 'https://github.com/nijikokun/generate-schema'
|
||||
label: "JSON to Mongoose Schema",
|
||||
path: "/json-to-mongoose",
|
||||
desc: "An online REPL to generate Mongoose Schema from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: 'JSON to Big Query Schema',
|
||||
path: '/json-to-big-query',
|
||||
desc: 'An online REPL to generate Big Query Schema from JSON.',
|
||||
packageName: 'generate-schema',
|
||||
packageUrl: 'https://github.com/nijikokun/generate-schema'
|
||||
label: "JSON to Big Query Schema",
|
||||
path: "/json-to-big-query",
|
||||
desc: "An online REPL to generate Big Query Schema from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: 'JSON to MySQL',
|
||||
path: '/json-to-mysql',
|
||||
label: "JSON to MySQL",
|
||||
path: "/json-to-mysql",
|
||||
desc:
|
||||
'An online REPL to generate MySQL table generation code from JSON.',
|
||||
packageName: 'generate-schema',
|
||||
packageUrl: 'https://github.com/nijikokun/generate-schema'
|
||||
"An online REPL to generate MySQL table generation code from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'Scala',
|
||||
iconName: 'icon-scala',
|
||||
category: "Scala",
|
||||
iconName: "icon-scala",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to Scala Case Class',
|
||||
path: '/json-to-scala-case-class',
|
||||
desc: 'An online REPL to generate Scala Case Class from JSON.'
|
||||
label: "JSON to Scala Case Class",
|
||||
path: "/json-to-scala-case-class",
|
||||
desc: "An online REPL to generate Scala Case Class from JSON."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'GraphQL',
|
||||
category: "GraphQL",
|
||||
icon: <GraphQLIcon />,
|
||||
content: [
|
||||
{
|
||||
label: 'GraphQL to TypeScript',
|
||||
path: '/graphql-to-typescript',
|
||||
label: "GraphQL to TypeScript",
|
||||
path: "/graphql-to-typescript",
|
||||
desc:
|
||||
'An online REPL to generate TypeScript type annotations based on a GraphQL schema and query documents.'
|
||||
"An online REPL to generate TypeScript type annotations based on a GraphQL schema and query documents."
|
||||
},
|
||||
{
|
||||
label: 'GraphQL to Flow',
|
||||
path: '/graphql-to-flow',
|
||||
label: "GraphQL to Flow",
|
||||
path: "/graphql-to-flow",
|
||||
desc:
|
||||
'An online REPL to generate Flow type annotations based on a GraphQL schema and query documents.'
|
||||
"An online REPL to generate Flow type annotations based on a GraphQL schema and query documents."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'Go',
|
||||
iconName: 'icon-go',
|
||||
category: "Go",
|
||||
iconName: "icon-go",
|
||||
content: [
|
||||
{
|
||||
label: 'JSON to Go Struct',
|
||||
path: '/json-to-go',
|
||||
desc: 'An online REPL to generate Go Struct from JSON.',
|
||||
packageName: 'json-to-go',
|
||||
packageUrl: 'https://github.com/mholt/json-to-go'
|
||||
label: "JSON to Go Struct",
|
||||
path: "/json-to-go",
|
||||
desc: "An online REPL to generate Go Struct from JSON.",
|
||||
packageName: "json-to-go",
|
||||
packageUrl: "https://github.com/mholt/json-to-go"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'XML',
|
||||
iconName: 'icon-html',
|
||||
category: "XML",
|
||||
iconName: "icon-html",
|
||||
content: [
|
||||
{
|
||||
label: 'XML to JSON',
|
||||
path: '/xml-to-json',
|
||||
desc: 'An online REPL to generate basic JSON from a XML.',
|
||||
packageName: 'xml-js',
|
||||
packageUrl: 'https://github.com/nashwaan/xml-js'
|
||||
label: "XML to JSON",
|
||||
path: "/xml-to-json",
|
||||
desc: "An online REPL to generate basic JSON from a XML.",
|
||||
packageName: "xml-js",
|
||||
packageUrl: "https://github.com/nashwaan/xml-js"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
export const routes = flatten(categorizedRoutes.map(a => a.content))
|
||||
export const routes = flatten(categorizedRoutes.map(a => a.content));
|
||||
|
||||
export function activeRouteData (pathname) {
|
||||
return find(routes, o => o.path === pathname)
|
||||
export function activeRouteData(pathname) {
|
||||
return find(routes, o => o.path === pathname);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import cssToJS from 'transform-css-to-js'
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import cssToJS from "transform-css-to-js";
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { isRn, code } = message
|
||||
resolve(`const styles = ${cssToJS(code, isRn)}`)
|
||||
const { isRn, code } = message;
|
||||
resolve(`const styles = ${cssToJS(code, isRn)}`);
|
||||
})
|
||||
)
|
||||
);
|
||||
@@ -1,10 +1,10 @@
|
||||
import transform from 'transform-graphql-type-annotations'
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import transform from "transform-graphql-type-annotations";
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { query, schema, convertTo } = message
|
||||
resolve(transform(schema, query, convertTo))
|
||||
const { query, schema, convertTo } = message;
|
||||
resolve(transform(schema, query, convertTo));
|
||||
})
|
||||
)
|
||||
);
|
||||
@@ -1,10 +1,10 @@
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import transform from 'transform-json-types'
|
||||
import jsf from 'json-schema-faker'
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import transform from "transform-json-types";
|
||||
import jsf from "json-schema-faker";
|
||||
|
||||
jsf.option({
|
||||
alwaysFakeOptionals: true
|
||||
})
|
||||
});
|
||||
|
||||
registerPromiseWorker(
|
||||
code =>
|
||||
@@ -12,9 +12,9 @@ registerPromiseWorker(
|
||||
jsf.resolve(JSON.parse(code)).then(_json => {
|
||||
resolve(
|
||||
transform(_json, {
|
||||
lang: 'rust-serde'
|
||||
lang: "rust-serde"
|
||||
})
|
||||
)
|
||||
})
|
||||
);
|
||||
});
|
||||
})
|
||||
)
|
||||
);
|
||||
@@ -1,19 +1,19 @@
|
||||
import { transform } from 'babel-standalone'
|
||||
import jsonToProptypes from 'babel-plugin-json-to-proptypes'
|
||||
import immutablePropsPlugin from '../utils/babel-plugin-js-to-immutable-prop-types'
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import { transform } from "babel-standalone";
|
||||
import jsonToProptypes from "babel-plugin-json-to-proptypes";
|
||||
import immutablePropsPlugin from "../utils/babel-plugin-js-to-immutable-prop-types";
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { isImmutable, code } = message
|
||||
const plugin = isImmutable ? immutablePropsPlugin : jsonToProptypes
|
||||
const { isImmutable, code } = message;
|
||||
const plugin = isImmutable ? immutablePropsPlugin : jsonToProptypes;
|
||||
const newCode = transform(code, {
|
||||
plugins: [plugin]
|
||||
}).code
|
||||
}).code;
|
||||
|
||||
resolve(`import PropTypes from "prop-types";
|
||||
|
||||
${newCode}`)
|
||||
${newCode}`);
|
||||
})
|
||||
)
|
||||
);
|
||||
+24
-24
@@ -1,46 +1,46 @@
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
|
||||
try {
|
||||
importScripts('https://bundle.run/prettier@1.6.1')
|
||||
importScripts("https://bundle.run/prettier@1.6.1");
|
||||
} catch (e) {
|
||||
self.postMessage({ available: false })
|
||||
self.postMessage({ available: false });
|
||||
}
|
||||
|
||||
const prettierParsers = {
|
||||
css: 'postcss',
|
||||
javascript: 'babylon',
|
||||
jsx: 'babylon',
|
||||
graphql: 'graphql',
|
||||
json: 'json',
|
||||
typescript: 'typescript',
|
||||
flow: 'flow'
|
||||
}
|
||||
css: "postcss",
|
||||
javascript: "babylon",
|
||||
jsx: "babylon",
|
||||
graphql: "graphql",
|
||||
json: "json",
|
||||
typescript: "typescript",
|
||||
flow: "flow"
|
||||
};
|
||||
|
||||
if (self.prettier) {
|
||||
postMessage({ available: true })
|
||||
postMessage({ available: true });
|
||||
}
|
||||
|
||||
function getPrettyCode (data) {
|
||||
const { code, mode, section } = data
|
||||
function getPrettyCode(data) {
|
||||
const { code, mode, section } = data;
|
||||
|
||||
const prettyCode =
|
||||
self.prettier && prettierParsers[mode] && code
|
||||
? self.prettier.format(code, {
|
||||
parser: prettierParsers[mode],
|
||||
printWidth: 70
|
||||
})
|
||||
: code
|
||||
parser: prettierParsers[mode],
|
||||
printWidth: 70
|
||||
})
|
||||
: code;
|
||||
|
||||
return { available: !!self.prettier, prettyCode, section }
|
||||
return { available: !!self.prettier, prettyCode, section };
|
||||
}
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
resolve(getPrettyCode(message))
|
||||
resolve(getPrettyCode(message));
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
onmessage = function ({ data }) {
|
||||
postMessage(getPrettyCode(data))
|
||||
}
|
||||
onmessage = function({ data }) {
|
||||
postMessage(getPrettyCode(data));
|
||||
};
|
||||
Reference in new issue
Block a user