From 88bfa7ab01d90b4976f4bde484aa0227aafdb9ae Mon Sep 17 00:00:00 2001 From: Ritesh Kumar Date: Tue, 29 Aug 2017 22:36:10 +0530 Subject: [PATCH] added accordion for navigation --- components/ConversionPanel.js | 16 +- components/Layout.js | 485 ++++++++++++-------- package.json | 3 + pages/json-to-big-query.js | 8 +- pages/json-to-mongoose.js | 8 +- pages/json-to-mysql.js | 8 +- static/nprogress.css | 49 ++ utils/babel-plugin-js-to-mobx-state-tree.js | 28 +- utils/dummy-object-json.js | 4 +- utils/json-to-rust-serde.js | 22 +- utils/json-to-ts-flow.js | 7 +- yarn.lock | 59 ++- 12 files changed, 462 insertions(+), 235 deletions(-) diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js index 1006fdd..07c8da4 100644 --- a/components/ConversionPanel.js +++ b/components/ConversionPanel.js @@ -137,9 +137,13 @@ export default class ConversionPanel extends PureComponent { }; copyCode = () => { - const { rightMode } = this.props - const { resultValue } = this.state - copy(rightMode !== "rust" ? window.js_beautify(resultValue, { e4x: true }) : resultValue); + const { rightMode } = this.props; + const { resultValue } = this.state; + copy( + rightMode !== "rust" + ? window.js_beautify(resultValue, { e4x: true }) + : resultValue + ); this.setState({ info: "Code copied to clipboard.", infoType: "success" @@ -348,7 +352,11 @@ export default class ConversionPanel extends PureComponent { theme={theme} name="code" readOnly - value={rightMode !== "rust" ? window.js_beautify(resultValue, { e4x: true }) : resultValue} + value={ + rightMode !== "rust" + ? window.js_beautify(resultValue, { e4x: true }) + : resultValue + } editorProps={{ $blockScrolling: true }} scrollMargin={[20]} fontSize={14} diff --git a/components/Layout.js b/components/Layout.js index 96019d0..fe39e05 100644 --- a/components/Layout.js +++ b/components/Layout.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { PureComponent } from "react"; import isBrowser from "is-in-browser"; import Link from "next/link"; import Head from "next/head"; @@ -6,6 +6,9 @@ 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 flatten from "lodash/flatten"; +import findIndex from "lodash/findIndex"; NProgress.configure({ showSpinner: false }); @@ -17,49 +20,75 @@ Router.onRouteChangeStart = url => { Router.onRouteChangeComplete = () => NProgress.done(); Router.onRouteChangeError = () => NProgress.done(); -const routes = [ +const x = [ { - label: "JSON to React PropTypes", - path: "/" + category: "React", + iconName: "icon-reactjs", + content: [ + { + label: "JSON to React PropTypes", + path: "/" + }, + { + label: "HTML to JSX", + path: "/html-to-jsx" + }, + { + label: "CSS to JS Objects", + path: "/css-to-js" + } + ] }, { - label: "JSON to Flow Types", - path: "/json-to-flow-types", + category: "JavaScript", + iconName: "icon-javascript", + content: [ + { + label: "JSON to Flow Types", + path: "/json-to-flow-types" + }, + { + label: "JSON to Typescript Interface", + path: "/json-to-ts-interface" + }, + { + label: "JSON to MobX-State-Tree Model", + path: "/json-to-mobx-state-tree" + } + ] }, { - label: "JSON to Typescript Interface", - path: "/json-to-ts-interface" + category: "Rust", + iconName: "icon-rust", + content: [ + { + label: "JSON to Rust Serde", + path: "/json-to-rust-serde" + } + ] }, { - label: "JSON to MobX-State-Tree Model", - path: "/json-to-mobx-state-tree" - }, - { - label: "CSS to JS Objects", - path: "/css-to-js" - }, - { - label: "HTML to JSX", - path: "/html-to-jsx" - }, - { - label: "JSON to Rust Serde", - path: "/json-to-rust-serde" - }, - { - label: "JSON to Mongoose Schema", - path: "/json-to-mongoose" - }, - { - label: "JSON to Big Query Schema", - path: "/json-to-big-query" - }, - { - label: "JSON to MySQL", - path: "/json-to-mysql" + category: "Databases", + iconName: "icon-database", + content: [ + { + label: "JSON to Mongoose Schema", + path: "/json-to-mongoose" + }, + { + label: "JSON to Big Query Schema", + path: "/json-to-big-query" + }, + { + label: "JSON to MySQL", + path: "/json-to-mysql" + } + ] } ]; +const routes = flatten(x.map(a => a.content)); + function Logo() { return ( - - Transform | All important transforms at one place. - { + this.setState({ + activeKey: `${findIndex( + x, + o => o.content.filter(a => a.path === pathname).length + ) + 1}` + }); + }; + + onChange = activeKey => { + this.setState({ + activeKey + }); + }; + + render() { + return ( +
+ + Transform | All important transforms at one place. + + + + + + + + + + + - - - - - - - -
- -
- +
+
Created by{" "} + + @ritz078 + +
- - -
-
Created by{" "} - - @ritz078 - +
+ {this.props.children}
+
-
- {children} -
- -
- ); + ); + } } diff --git a/package.json b/package.json index ba000d4..d24fe6e 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,15 @@ "nprogress": "^0.2.0", "pretty": "^2.0.0", "prop-types": "^15.5.10", + "rc-collapse": "^1.7.6", "react": "^15.6.1", "react-ace": "^5.1.2", + "react-collapse": "^4.0.3", "react-collapsible": "^2.0.0", "react-dom": "^15.6.1", "react-fuzzy-picker": "^0.5.1", "react-github-corner": "^0.3.0", + "react-responsive-accordion": "^1.0.0", "stringify-object": "^3.2.0", "webpack-bundle-analyzer": "^2.9.0" }, diff --git a/pages/json-to-big-query.js b/pages/json-to-big-query.js index e16b300..61ff21c 100644 --- a/pages/json-to-big-query.js +++ b/pages/json-to-big-query.js @@ -1,14 +1,14 @@ import React, { PureComponent } from "react"; -import { bigquery } from "generate-schema" -import stringify from "stringify-object" +import { bigquery } from "generate-schema"; +import stringify from "stringify-object"; import Layout from "../components/Layout"; import ConversionPanel from "../components/ConversionPanel"; 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() { diff --git a/pages/json-to-mongoose.js b/pages/json-to-mongoose.js index 162fca1..746ad46 100644 --- a/pages/json-to-mongoose.js +++ b/pages/json-to-mongoose.js @@ -1,14 +1,14 @@ import React, { PureComponent } from "react"; -import { mongoose } from "generate-schema" -import stringify from "stringify-object" +import { mongoose } from "generate-schema"; +import stringify from "stringify-object"; import Layout from "../components/Layout"; import ConversionPanel from "../components/ConversionPanel"; 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() { diff --git a/pages/json-to-mysql.js b/pages/json-to-mysql.js index 6c431b7..435e3d9 100644 --- a/pages/json-to-mysql.js +++ b/pages/json-to-mysql.js @@ -1,14 +1,14 @@ import React, { PureComponent } from "react"; -import { mysql } from "generate-schema" -import stringify from "stringify-object" +import { mysql } from "generate-schema"; +import stringify from "stringify-object"; import Layout from "../components/Layout"; 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() { diff --git a/static/nprogress.css b/static/nprogress.css index 623b588..741cc7d 100644 --- a/static/nprogress.css +++ b/static/nprogress.css @@ -1,4 +1,53 @@ @import url('https://fonts.googleapis.com/css?family=Lato'); +.rc-collapse { + background-color: #f7f7f7; + border-radius: 3px; +} +.rc-collapse-anim-active { + transition: height 0.2s ease-out; +} + +.rc-collapse > .rc-collapse-item > .rc-collapse-header { + height: 38px; + line-height: 38px; + cursor: pointer; +} +.rc-collapse > .rc-collapse-item > .rc-collapse-header .arrow { + display: inline-block; + content: '\20'; + width: 0; + height: 0; + font-size: 0; + line-height: 0; + border-top: 3px solid transparent; + border-bottom: 3px solid transparent; + border-left: 4px solid #b3b3b3; + vertical-align: middle; + margin-right: 8px; +} +.rc-collapse > .rc-collapse-item-disabled > .rc-collapse-header { + cursor: not-allowed; + color: #999; + background-color: #f3f3f3; +} +.rc-collapse-content { + overflow: hidden; +} + +.rc-collapse-content-inactive { + display: none; +} +.rc-collapse-item:last-child > .rc-collapse-content { + border-radius: 0 0 3px 3px; +} +.rc-collapse > .rc-collapse-item-active > .rc-collapse-header .arrow { + border-left: 3px solid transparent; + border-right: 3px solid transparent; + border-top: 4px solid #666; + margin-right: 6px; +} + + /* Make clicks pass-through */ #nprogress { pointer-events: none; diff --git a/utils/babel-plugin-js-to-mobx-state-tree.js b/utils/babel-plugin-js-to-mobx-state-tree.js index 564d71c..828da57 100644 --- a/utils/babel-plugin-js-to-mobx-state-tree.js +++ b/utils/babel-plugin-js-to-mobx-state-tree.js @@ -16,10 +16,7 @@ export default function({ types: t }) { 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 ) ]; @@ -31,10 +28,7 @@ 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 ) ); @@ -76,26 +70,20 @@ export default function({ types: t }) { }); }, - ObjectProperty(path){ - if(t.isStringLiteral(path.node.key)){ - path.node.key = t.identifier(path.node.key.value) - } + ObjectProperty(path) { + if (t.isStringLiteral(path.node.key)) { + path.node.key = t.identifier(path.node.key.value); + } }, ObjectExpression(path) { - if ( - t.isCallExpression(path.parent) - ) - return; + if (t.isCallExpression(path.parent)) return; 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 ) ); diff --git a/utils/dummy-object-json.js b/utils/dummy-object-json.js index 2303d38..6a0e532 100644 --- a/utils/dummy-object-json.js +++ b/utils/dummy-object-json.js @@ -16,6 +16,6 @@ const y = `{ "index": true, "required": true } -}` +}`; -export default y \ No newline at end of file +export default y; diff --git a/utils/json-to-rust-serde.js b/utils/json-to-rust-serde.js index bd3d462..a6cd5c6 100644 --- a/utils/json-to-rust-serde.js +++ b/utils/json-to-rust-serde.js @@ -21,11 +21,15 @@ var is; } is.string = string; function number(n) { - return (typeof n === "number" || n instanceof Number) && !Number.isInteger(n) + return ( + (typeof n === "number" || n instanceof Number) && !Number.isInteger(n) + ); } is.number = number; function integer(n) { - return (typeof n === "number" || n instanceof Number) && Number.isInteger(n) + return ( + (typeof n === "number" || n instanceof Number) && Number.isInteger(n) + ); } is.integer = integer; function boolean(b) { @@ -277,7 +281,7 @@ var Types = (function() { function Types() {} Types.STRING = "String"; Types.NUMBER = "f64"; - Types.INTEGER = "i64" + Types.INTEGER = "i64"; Types.BOOLEAN = "boolean"; Types.ARRAY = "[]"; return Types; @@ -327,9 +331,14 @@ var Json2dts = (function() { var interfaceTab = outputModule ? " " : ""; var propertyTab = interfaceTab + " "; Object.keys(this.classes).map(function(clsName) { - output = interfaceTab + "#[derive(Serialize, Deserialize)]\nstruct " + clsName + " {\n"; + output = + interfaceTab + + "#[derive(Serialize, Deserialize)]\nstruct " + + clsName + + " {\n"; Object.keys(_this.classes[clsName]).map(function(key) { - output += propertyTab + key + ": " + _this.classes[clsName][key] + ",\n"; + output += + propertyTab + key + ": " + _this.classes[clsName][key] + ",\n"; }); output += interfaceTab + "}\n\n"; classes[clsName] = output; @@ -372,7 +381,8 @@ var Json2dts = (function() { type = "Vec<()>"; } else { if (is.object(value[0])) { - type = "Vec<" + _this.getInterfaceType(key, value[0]).trim() + ">"; + type = + "Vec<" + _this.getInterfaceType(key, value[0]).trim() + ">"; _this.analyse_object(value[0], key); } else { type = "Vec<" + _this.getBasicType(value[0]) + ">"; diff --git a/utils/json-to-ts-flow.js b/utils/json-to-ts-flow.js index aab1420..d8ebea6 100644 --- a/utils/json-to-ts-flow.js +++ b/utils/json-to-ts-flow.js @@ -326,7 +326,12 @@ var Json2dts = (function() { ? interfaceTab + "type " + clsName + " = \n" + interfaceTab + "{\n" : interfaceTab + "interface " + clsName + " \n" + interfaceTab + "{\n"; Object.keys(_this.classes[clsName]).map(function(key) { - output += propertyTab + key + ":" + _this.classes[clsName][key] + (flow ? ",\n" : ";\n"); + output += + propertyTab + + key + + ":" + + _this.classes[clsName][key] + + (flow ? ",\n" : ";\n"); }); output += interfaceTab + (flow ? "};\n\n" : "}\n\n"); classes[clsName] = output; diff --git a/yarn.lock b/yarn.lock index fd7db4b..c343427 100644 --- a/yarn.lock +++ b/yarn.lock @@ -920,6 +920,13 @@ babel-runtime@6.23.0, babel-runtime@^6.18.0, babel-runtime@^6.20.0, babel-runtim core-js "^2.4.0" regenerator-runtime "^0.10.0" +babel-runtime@6.x: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + babel-standalone@^6.25.0: version "6.25.0" resolved "https://registry.yarnpkg.com/babel-standalone/-/babel-standalone-6.25.0.tgz#759ef04574402b6d1a1b5efa62d18c9a47e4abeb" @@ -1208,7 +1215,7 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: inherits "^2.0.1" safe-buffer "^5.0.1" -classnames@^2.2.5: +classnames@2.x, classnames@^2.2.5: version "2.2.5" resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d" @@ -1262,6 +1269,16 @@ commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" +component-classes@^1.2.5: + version "1.2.6" + resolved "https://registry.yarnpkg.com/component-classes/-/component-classes-1.2.6.tgz#c642394c3618a4d8b0b8919efccbbd930e5cd691" + dependencies: + component-indexof "0.0.3" + +component-indexof@0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/component-indexof/-/component-indexof-0.0.3.tgz#11d091312239eb8f32c8f25ae9cb002ffe8d3c24" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -1399,6 +1416,13 @@ crypto-browserify@^3.11.0: public-encrypt "^4.0.0" randombytes "^2.0.0" +css-animation@1.x, css-animation@^1.3.2: + version "1.4.1" + resolved "https://registry.yarnpkg.com/css-animation/-/css-animation-1.4.1.tgz#5b8813125de0fbbbb0bbe1b472ae84221469b7a8" + dependencies: + babel-runtime "6.x" + component-classes "^1.2.5" + css-color-keywords@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05" @@ -3271,7 +3295,7 @@ prop-types-exact@^1.1.1: has "^1.0.1" object.assign "^4.0.4" -prop-types@15.5.10, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8: +prop-types@15.5.10, prop-types@15.x, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8: version "15.5.10" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154" dependencies: @@ -3344,6 +3368,23 @@ range-parser@^1.0.3, range-parser@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" +rc-animate@2.x: + version "2.4.1" + resolved "https://registry.yarnpkg.com/rc-animate/-/rc-animate-2.4.1.tgz#df3e0f56fe106afe4bf52ff408ced241c5178919" + dependencies: + babel-runtime "6.x" + css-animation "^1.3.2" + prop-types "15.x" + +rc-collapse@^1.7.6: + version "1.7.6" + resolved "https://registry.yarnpkg.com/rc-collapse/-/rc-collapse-1.7.6.tgz#64433512d921f750df61433e675bb9547ba5ef6b" + dependencies: + classnames "2.x" + css-animation "1.x" + prop-types "^15.5.6" + rc-animate "2.x" + rc@^1.1.7: version "1.2.1" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95" @@ -3363,6 +3404,12 @@ react-ace@^5.1.2: opencollective "^1.0.3" prop-types "^15.5.8" +react-collapse@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/react-collapse/-/react-collapse-4.0.3.tgz#b96de959ed0092a43534630b599a4753dd76d543" + dependencies: + prop-types "^15.5.8" + react-collapsible@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/react-collapsible/-/react-collapsible-2.0.0.tgz#a98113bb26ab55fc5ed95a4835c3fbf8cbf973af" @@ -3420,6 +3467,10 @@ react-proxy@^3.0.0-alpha.0: dependencies: lodash "^4.6.1" +react-responsive-accordion@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/react-responsive-accordion/-/react-responsive-accordion-1.0.0.tgz#e2c39ee13e18daa40d9d78486beccd27f4988cba" + react@^15.5.4, react@^15.6.1: version "15.6.1" resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df" @@ -3506,6 +3557,10 @@ regenerator-runtime@^0.10.0: version "0.10.5" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" +regenerator-runtime@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" + regenerator-transform@0.9.11: version "0.9.11" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.9.11.tgz#3a7d067520cb7b7176769eb5ff868691befe1283"