From ebfc650a641e5d9be9796ab6a38cf9bcd6e8ccaf Mon Sep 17 00:00:00 2001 From: Ryan Sites Date: Wed, 2 Jun 2021 13:15:54 -0400 Subject: [PATCH 1/2] bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0029768..fc8e5a6 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "@optum/json-schema-editor", - "version": "2.0.1", + "version": "2.0.3", "description": "JsonSchema Editor React Control", "repository": "https://github.com/optum/jsonschema-editor-react", "license": "Apache 2.0", "engines": { "node": ">=10.18.0 <11 || >=12.14.0 <13 || >=13.5.0" }, - "source": "src/JsonSchemaEditor/index.ts", + "source": "src/index.ts", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" From cce20c10779c3f0f90c0a4e6b48b4e5416869cdc Mon Sep 17 00:00:00 2001 From: Ryan Sites Date: Wed, 2 Jun 2021 13:16:08 -0400 Subject: [PATCH 2/2] refactor to include typescript.types exported --- src/JsonSchemaEditor.test.tsx | 40 +- .../JsonSchemaEditor.types.ts | 0 src/JsonSchemaEditor/JsonSchemaEditor.tsx | 78 +-- .../advanced-boolean/index.tsx | 72 +-- .../advanced-number/index.tsx | 253 ++++----- .../advanced-string/index.tsx | 339 +++++------ src/JsonSchemaEditor/drop-plus/index.tsx | 165 +++--- src/JsonSchemaEditor/index.ts | 1 - .../schema-advanced/index.tsx | 40 +- src/JsonSchemaEditor/schema-array/index.tsx | 378 ++++++------- src/JsonSchemaEditor/schema-item/index.tsx | 524 +++++++++--------- src/JsonSchemaEditor/schema-object/index.tsx | 177 +++--- src/JsonSchemaEditor/schema-root/index.tsx | 232 ++++---- src/JsonSchemaEditor/state/schema.ts | 52 +- src/JsonSchemaEditor/state/test.ts | 380 ++++++------- src/JsonSchemaEditor/utils.ts | 326 +++++------ src/index.ts | 1 + 17 files changed, 1535 insertions(+), 1523 deletions(-) rename src/{JsonSchemaEditor => }/JsonSchemaEditor.types.ts (100%) delete mode 100644 src/JsonSchemaEditor/index.ts create mode 100644 src/index.ts diff --git a/src/JsonSchemaEditor.test.tsx b/src/JsonSchemaEditor.test.tsx index 8ea2d9e..cc2003b 100644 --- a/src/JsonSchemaEditor.test.tsx +++ b/src/JsonSchemaEditor.test.tsx @@ -1,38 +1,38 @@ import React from "react"; import { render } from "@testing-library/react"; -import JsonSchemaEditor from "./JsonSchemaEditor"; -import { SchemaEditorProps } from "./JsonSchemaEditor/JsonSchemaEditor.types"; +import JsonSchemaEditor from "."; +import { SchemaEditorProps } from "./JsonSchemaEditor.types"; const printIt = (schema: string) => { - console.log(schema); + console.log(schema); }; describe("JsonSchemaEditor", () => { - let props: SchemaEditorProps; + let props: SchemaEditorProps; - beforeEach(() => { - props = { - onSchemaChange: printIt, - }; - }); + beforeEach(() => { + props = { + onSchemaChange: printIt, + }; + }); - const renderComponent = () => render(); + const renderComponent = () => render(); - it("should have primary className with default props", () => { - renderComponent(); + it("should have primary className with default props", () => { + renderComponent(); - const { container } = renderComponent(); + const { container } = renderComponent(); - // const testComponent = getByTestId("jsonschema-editor"); - console.log(container.innerHTML); + // const testComponent = getByTestId("jsonschema-editor"); + console.log(container.innerHTML); - // expect(testComponent).toHaveClass("test-component-primary"); + // expect(testComponent).toHaveClass("test-component-primary"); - // console.log(result.asFragment.toString); - // // expect(screen.getByText("root")).toBeInTheDocument(); - // expect(true).toBe(true); - }); + // console.log(result.asFragment.toString); + // // expect(screen.getByText("root")).toBeInTheDocument(); + // expect(true).toBe(true); + }); }); // test("renders learn react link", () => { diff --git a/src/JsonSchemaEditor/JsonSchemaEditor.types.ts b/src/JsonSchemaEditor.types.ts similarity index 100% rename from src/JsonSchemaEditor/JsonSchemaEditor.types.ts rename to src/JsonSchemaEditor.types.ts diff --git a/src/JsonSchemaEditor/JsonSchemaEditor.tsx b/src/JsonSchemaEditor/JsonSchemaEditor.tsx index d0eb0d3..a0ee243 100644 --- a/src/JsonSchemaEditor/JsonSchemaEditor.tsx +++ b/src/JsonSchemaEditor/JsonSchemaEditor.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { useState } from "@hookstate/core"; import { useSchemaState, defaultSchema } from "./state"; -import { SchemaEditorProps } from "./JsonSchemaEditor.types"; +import { SchemaEditorProps } from "../JsonSchemaEditor.types"; import { Flex, ChakraProvider, theme } from "@chakra-ui/react"; import { SchemaRoot } from "./schema-root"; @@ -9,49 +9,49 @@ import { Whoops } from "./whoops"; import { SchemaObject } from "./schema-object"; import { SchemaArray } from "./schema-array"; -export * from "./JsonSchemaEditor.types"; +export * from "../JsonSchemaEditor.types"; export const JsonSchemaEditor = (props: SchemaEditorProps) => { - const { onSchemaChange, readOnly, data } = props; + const { onSchemaChange, readOnly, data } = props; - const schemaState = useSchemaState({ - jsonSchema: data ?? defaultSchema(), - isReadOnly: readOnly ?? false, - fieldId: 0, - }); + const schemaState = useSchemaState({ + jsonSchema: data ?? defaultSchema(), + isReadOnly: readOnly ?? false, + fieldId: 0, + }); - const jsonSchemaState = useState(schemaState.jsonSchema); + const jsonSchemaState = useState(schemaState.jsonSchema); - return ( - - {schemaState.isValidSchema ? ( - - + return ( + + {schemaState.isValidSchema ? ( + + - {jsonSchemaState.type.value === "object" && ( - - )} + {jsonSchemaState.type.value === "object" && ( + + )} - {jsonSchemaState.type.value === "array" && ( - - )} - - ) : ( - - - - )} - {/* + )} + + ) : ( + + + + )} + {/* { */} - - ); + + ); }; diff --git a/src/JsonSchemaEditor/advanced-boolean/index.tsx b/src/JsonSchemaEditor/advanced-boolean/index.tsx index c136470..f6b0b1a 100644 --- a/src/JsonSchemaEditor/advanced-boolean/index.tsx +++ b/src/JsonSchemaEditor/advanced-boolean/index.tsx @@ -1,46 +1,46 @@ import * as React from "react"; import { Flex, FormLabel, Stack, Select } from "@chakra-ui/react"; -import { AdvancedItemStateProps } from "../JsonSchemaEditor.types"; +import { AdvancedItemStateProps } from "../../JsonSchemaEditor.types"; import { useState } from "@hookstate/core"; export const AdvancedBoolean: React.FunctionComponent = ( - props: React.PropsWithChildren + props: React.PropsWithChildren ) => { - const { itemStateProp } = props; + const { itemStateProp } = props; - const item = useState(itemStateProp); + const item = useState(itemStateProp); - return ( - - - - Default:{" "} - - - - - ); + return ( + + + + Default:{" "} + + + + + ); }; diff --git a/src/JsonSchemaEditor/advanced-number/index.tsx b/src/JsonSchemaEditor/advanced-number/index.tsx index dd049b5..c9ece6f 100644 --- a/src/JsonSchemaEditor/advanced-number/index.tsx +++ b/src/JsonSchemaEditor/advanced-number/index.tsx @@ -1,141 +1,144 @@ import * as React from "react"; import { - Flex, - FormLabel, - Stack, - NumberInput, - NumberInputField, - NumberInputStepper, - NumberIncrementStepper, - NumberDecrementStepper, - Checkbox, - Textarea, + Flex, + FormLabel, + Stack, + NumberInput, + NumberInputField, + NumberInputStepper, + NumberIncrementStepper, + NumberDecrementStepper, + Checkbox, + Textarea, } from "@chakra-ui/react"; -import { AdvancedItemStateProps, JSONSchema7 } from "../JsonSchemaEditor.types"; +import { + AdvancedItemStateProps, + JSONSchema7, +} from "../../JsonSchemaEditor.types"; import { none, useState } from "@hookstate/core"; export const AdvancedNumber: React.FunctionComponent = ( - props: React.PropsWithChildren + props: React.PropsWithChildren ) => { - const { itemStateProp } = props; + const { itemStateProp } = props; - const changeEnumOtherValue = (value: string): string[] | null => { - const array = value.split("\n"); - if (array.length === 0 || (array.length === 1 && !array[0])) { - return null; - } + const changeEnumOtherValue = (value: string): string[] | null => { + const array = value.split("\n"); + if (array.length === 0 || (array.length === 1 && !array[0])) { + return null; + } - return array; - }; + return array; + }; - const itemState = useState(itemStateProp); + const itemState = useState(itemStateProp); - const isEnumChecked = (itemState.value as JSONSchema7).enum !== undefined; - const enumData = (itemState.value as JSONSchema7).enum - ? (itemState.enum.value as string[]) - : []; - const enumValue = enumData?.join("\n"); + const isEnumChecked = (itemState.value as JSONSchema7).enum !== undefined; + const enumData = (itemState.value as JSONSchema7).enum + ? (itemState.enum.value as string[]) + : []; + const enumValue = enumData?.join("\n"); - return ( - - - Default: + return ( + + + Default: - { - itemState.default.set(Number(value)); - }} - > - - - - - - - + { + itemState.default.set(Number(value)); + }} + > + + + + + + + - - Min Value: - { - itemState.minimum.set(Number(value)); - }} - > - - - - - - - Max Value: - { - itemState.maximum.set(Number(value)); - }} - > - - - - - - - - - Enum: - ) => { - if (!evt.target.checked) { - itemState.enum.set(none); - } else { - itemState.enum.set(Array()); - } - }} - /> -