mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 16:43:56 +03:00
closes #25
This commit is contained in:
1 parent
bd7faeec88
commit
60ad63eb9e
3 files changed
+22
-5
No files matched your search
@@ -3,7 +3,8 @@ import cn from "classnames";
|
||||
import Router from "next/router";
|
||||
import isBrowser from "is-in-browser";
|
||||
import copy from "copy-text-to-clipboard";
|
||||
import { html_beautify, css_beautify, js_beautify } from "js-beautify"
|
||||
import { html_beautify, css_beautify, js_beautify } from "js-beautify";
|
||||
import unfetch from "unfetch";
|
||||
|
||||
const theme = "tomorrow";
|
||||
|
||||
@@ -62,7 +63,9 @@ type Props = {
|
||||
splitLeft: ?boolean,
|
||||
splitTitle: ?string,
|
||||
splitValue: ?string,
|
||||
splitMode: ?string
|
||||
splitMode: ?string,
|
||||
showFetchButton: boolean,
|
||||
fetchButtonText: ?string
|
||||
};
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
@@ -73,7 +76,9 @@ export default class ConversionPanel extends PureComponent {
|
||||
rightMode: "javascript",
|
||||
pathname: "/",
|
||||
prettifyRightPanel: true,
|
||||
splitLeft: false
|
||||
splitLeft: false,
|
||||
showFetchButton: true,
|
||||
fetchButtonText: 'Fetch JSON from URL'
|
||||
};
|
||||
|
||||
state = {
|
||||
@@ -96,6 +101,14 @@ export default class ConversionPanel extends PureComponent {
|
||||
});
|
||||
}
|
||||
|
||||
fetchJSON = async () => {
|
||||
const url = window.prompt('Enter URL to fetch JSON from a remote server.')
|
||||
if (!url) return
|
||||
const res = await unfetch(url)
|
||||
const json = await res.json()
|
||||
this.onChange(JSON.stringify(json, null, 2))
|
||||
}
|
||||
|
||||
onChange = (newValue, leftSplitValue) => {
|
||||
const nValue = newValue || this.state.value;
|
||||
const splitValue =
|
||||
@@ -174,7 +187,9 @@ export default class ConversionPanel extends PureComponent {
|
||||
prettifyRightPanel,
|
||||
splitLeft,
|
||||
splitTitle,
|
||||
splitMode
|
||||
splitMode,
|
||||
showFetchButton,
|
||||
fetchButtonText
|
||||
} = this.props;
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state;
|
||||
|
||||
@@ -351,6 +366,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
<div style={{ display: "contents" }}>
|
||||
<div className="header">
|
||||
<h4 className="title">{leftTitle}</h4>
|
||||
{leftMode === 'json' && showFetchButton && <button className="btn" onClick={this.fetchJSON}>{fetchButtonText}</button>}
|
||||
<button className="btn" onClick={this.prettifyCode}>
|
||||
Prettify
|
||||
</button>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"react-fuzzy-picker": "^0.5.1",
|
||||
"react-github-corner": "^1.0.0",
|
||||
"stringify-object": "^3.2.0",
|
||||
"unfetch": "^3.0.0",
|
||||
"xml-js": "^1.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -5002,7 +5002,7 @@ ultron@~1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.0.tgz#b07a2e6a541a815fc6a34ccd4533baec307ca864"
|
||||
|
||||
unfetch@3.0.0:
|
||||
unfetch@3.0.0, unfetch@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-3.0.0.tgz#8d1e0513a4ecd0e5ff2d41a6ba77771aae8b6482"
|
||||
|
||||
|
||||
Reference in new issue
Block a user