mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
update-json-typegen
This commit is contained in:
1 parent
16cf173411
commit
00499d07a7
11 files changed
+91971
-71221
No files matched your search
@@ -5,3 +5,4 @@ yarn-error.log
|
||||
dist
|
||||
.DS_Store
|
||||
public/static/monaco/*.worker.js.map
|
||||
.tool-versions
|
||||
+24
-4
@@ -1,10 +1,11 @@
|
||||
import React from "react";
|
||||
import { Formik, FormikProps } from "formik";
|
||||
import { Dialog, Heading, Pane, Switch, TextInput } from "evergreen-ui";
|
||||
import { Dialog, Heading, Pane, Switch, TextInput, Select } from "evergreen-ui";
|
||||
|
||||
export enum InputType {
|
||||
SWITCH = 1,
|
||||
TEXT_INPUT
|
||||
TEXT_INPUT,
|
||||
SELECT
|
||||
}
|
||||
|
||||
interface FormProps<T> {
|
||||
@@ -17,6 +18,7 @@ interface FormProps<T> {
|
||||
label: string;
|
||||
isDisabled?: (values: T) => boolean;
|
||||
props?: any;
|
||||
options?: { label: string; value: string | number }[];
|
||||
}[];
|
||||
open: boolean;
|
||||
toggle: () => void;
|
||||
@@ -50,10 +52,26 @@ const Form = <T extends object>({
|
||||
>
|
||||
<>
|
||||
{formsFields.map(
|
||||
({ type, key, label, isDisabled, props: _props }, i) => {
|
||||
let FormField;
|
||||
(
|
||||
{ type, key, label, isDisabled, props: _props, options },
|
||||
i
|
||||
) => {
|
||||
let FormField, select;
|
||||
if (type === InputType.TEXT_INPUT) FormField = TextInput;
|
||||
else if (type === InputType.SWITCH) FormField = Switch;
|
||||
else if (type === InputType.SELECT)
|
||||
select = (
|
||||
<Select
|
||||
value={props.values[key]}
|
||||
onChange={props.handleChange}
|
||||
>
|
||||
{options.map(({ label, value }) => (
|
||||
<option value={value} selected>
|
||||
{label} selected={props.values[key] === value}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
|
||||
const _isDisabled = isDisabled
|
||||
? isDisabled(props.values)
|
||||
@@ -86,6 +104,8 @@ const Form = <T extends object>({
|
||||
disabled={_isDisabled}
|
||||
/>
|
||||
)}
|
||||
|
||||
{select}
|
||||
</Pane>
|
||||
);
|
||||
}
|
||||
|
||||
+1
-6
@@ -40,12 +40,7 @@ const config = {
|
||||
"java",
|
||||
"pug"
|
||||
],
|
||||
features: [
|
||||
"folding",
|
||||
"goToDefinitionMouse",
|
||||
"referenceSearch",
|
||||
"coreCommands"
|
||||
]
|
||||
features: ["folding", "goToSymbol", "coreCommands"]
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
+12
-12
@@ -43,10 +43,10 @@
|
||||
"babel-plugin-json-to-proptypes": "^0.1.0",
|
||||
"babel-plugin-object-styles-to-template": "^0.2.2",
|
||||
"babel-standalone": "^6.26.0",
|
||||
"clipboard-copy": "^3.0.0",
|
||||
"clipboard-copy": "^3.1.0",
|
||||
"evergreen-ui": "^4.18.1",
|
||||
"flow-to-ts": "gist:3f49c8bd7a2b71429dcae28f2c2d1d97",
|
||||
"flowgen": "^1.9.2",
|
||||
"flowgen": "^1.10.0",
|
||||
"formik": "^1.5.8",
|
||||
"generate-schema": "^2.6.0",
|
||||
"gofmt.js": "^0.0.2",
|
||||
@@ -60,30 +60,30 @@
|
||||
"json-schema-to-typescript": "^6.1.3",
|
||||
"json-to-go": "gist:0d0b8324131c80eeb7e1df20001be32f",
|
||||
"json-ts": "^1.6.4",
|
||||
"json_typegen_wasm": "^0.3.3",
|
||||
"json_typegen_wasm": "^0.4.0",
|
||||
"jsonld": "^1.6.2",
|
||||
"load-script": "^1.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"markdown": "^0.5.0",
|
||||
"monaco-editor": "^0.17.1",
|
||||
"next": "^9.1.1",
|
||||
"monaco-editor": "^0.19.0",
|
||||
"next": "^9.1.7",
|
||||
"nprogress": "^0.2.0",
|
||||
"postcss": "^7.0.17",
|
||||
"postcss-js": "^2.0.2",
|
||||
"postcss": "^7.0.26",
|
||||
"postcss-js": "^2.0.3",
|
||||
"qrcode.react": "^0.9.3",
|
||||
"react": "^16.11.0",
|
||||
"react-dom": "^16.11.0",
|
||||
"react-ga": "^2.6.0",
|
||||
"react": "^16.12.0",
|
||||
"react-dom": "^16.12.0",
|
||||
"react-ga": "^2.7.0",
|
||||
"rust-keywords": "^1.1.0",
|
||||
"sha1": "^1.1.1",
|
||||
"snack-sdk": "^2.3.1",
|
||||
"stringify-object": "^3.3.0",
|
||||
"svg-to-dataurl": "^1.0.0",
|
||||
"svgo": "^1.3.0",
|
||||
"svgo": "^1.3.2",
|
||||
"text-encoding-utf-8": "^1.0.2",
|
||||
"transform-json-types": "^0.7.0",
|
||||
"xml-js": "^1.6.11",
|
||||
"yaml": "^1.6.0"
|
||||
"yaml": "^1.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/bundle-analyzer": "^9.0.2",
|
||||
|
||||
@@ -1,18 +1,70 @@
|
||||
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
||||
import * as React from "react";
|
||||
import { useCallback } from "react";
|
||||
import Form, { InputType } from "@components/Form";
|
||||
import { useSettings } from "@hooks/useSettings";
|
||||
import { EditorPanelProps } from "@components/EditorPanel";
|
||||
import { Settings } from "@constants/svgoConfig";
|
||||
|
||||
const formFields = [
|
||||
{
|
||||
type: InputType.SELECT,
|
||||
key: "property_name_format",
|
||||
label: "Property Name Format",
|
||||
options: [
|
||||
"PascalCase",
|
||||
"camelCase",
|
||||
"snake_case",
|
||||
"SCREAMING_SNAKE_CASE",
|
||||
"kebab-case",
|
||||
"SCREAMING-KEBAB-CASE",
|
||||
"UPPERCASE"
|
||||
].map(value => ({
|
||||
label: value,
|
||||
value
|
||||
}))
|
||||
}
|
||||
];
|
||||
|
||||
const defaultSettings = {
|
||||
property_name_format: "camelCase"
|
||||
};
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback<Transformer>(async ({ value }) => {
|
||||
const { run } = await import("json_typegen_wasm");
|
||||
return run(
|
||||
"Root",
|
||||
value,
|
||||
JSON.stringify({
|
||||
output_mode: "rust"
|
||||
})
|
||||
);
|
||||
}, []);
|
||||
const name = "json-to-rust-serde";
|
||||
|
||||
const [settings, setSettings] = useSettings(name, defaultSettings);
|
||||
|
||||
const transformer = useCallback<Transformer>(
|
||||
async ({ value }) => {
|
||||
const { run } = await import("json_typegen_wasm");
|
||||
return run(
|
||||
"Root",
|
||||
value,
|
||||
JSON.stringify({
|
||||
output_mode: "rust",
|
||||
property_name_format: settings.property_name_format
|
||||
})
|
||||
);
|
||||
},
|
||||
[settings]
|
||||
);
|
||||
|
||||
const getSettingsElement = useCallback<EditorPanelProps["settingElement"]>(
|
||||
({ open, toggle }) => {
|
||||
return (
|
||||
<Form<Settings>
|
||||
title="JSON to Rust Serde"
|
||||
onSubmit={setSettings}
|
||||
open={open}
|
||||
toggle={toggle}
|
||||
formsFields={formFields}
|
||||
initialValues={settings}
|
||||
/>
|
||||
);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
@@ -21,6 +73,7 @@ export default function() {
|
||||
editorLanguage="json"
|
||||
resultTitle="Rust Serde"
|
||||
resultLanguage={"rust"}
|
||||
resultSettingsElement={getSettingsElement}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+24721
-18282
File diff suppressed because it is too large.
Load diff
+8096
-7405
File diff suppressed because it is too large.
Load diff
+16829
-12981
File diff suppressed because it is too large.
Load diff
+9344
-7985
File diff suppressed because it is too large.
Load diff
+32173
-22716
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user