swoop-common 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { Address } from '../types/address';
3
+ import { CustomType } from '../router/router';
4
+ interface Props {
5
+ address: Address;
6
+ submit?: (address: Address) => void;
7
+ }
8
+ export declare const FormAddress: React.FC<Props>;
9
+ export declare const TypeAddress: CustomType;
10
+ export {};
@@ -0,0 +1,31 @@
1
+ import React, { useState } from 'react';
2
+ import { getXType } from '../util/type';
3
+ import { Box, Button, TextField } from '@mui/material';
4
+ const tester = (uischema, schema, ctx) => {
5
+ const type = getXType(schema);
6
+ if (!type)
7
+ return -1;
8
+ else
9
+ return 10;
10
+ };
11
+ export const FormAddress = ({ address, submit }) => {
12
+ const [val, setVal] = useState(address);
13
+ // Typescript is great
14
+ const update = (field, value) => {
15
+ setVal(prev => (Object.assign(Object.assign({}, prev), { [field]: value })));
16
+ };
17
+ return (React.createElement(Box, { component: "form", onSubmit: () => submit === null || submit === void 0 ? void 0 : submit(val), sx: { display: 'flex', flexDirection: 'column', gap: 2, width: 400 }, noValidate: true, autoComplete: "off" },
18
+ React.createElement(TextField, { label: "Line 1", value: address.line1, onChange: (e) => update('line1', e.target.value), required: true }),
19
+ React.createElement(TextField, { label: "Line 2", value: address.line2, onChange: (e) => update('line2', e.target.value) }),
20
+ React.createElement(TextField, { label: "City", value: address.city, onChange: (e) => update('city', e.target.value), required: true }),
21
+ React.createElement(TextField, { label: "Postcode", value: address.postcode, onChange: (e) => update('postcode', e.target.value), required: true }),
22
+ React.createElement(TextField, { label: "Number", value: address.postcode, onChange: (e) => update('number', +e.target.value), required: true }),
23
+ React.createElement(Button, { type: "submit", variant: "contained", color: "primary" }, "Submit")));
24
+ };
25
+ const FormRendererAddress = ({ data, handleChange, path }) => {
26
+ return React.createElement(FormAddress, { address: data, submit: (addr) => handleChange(path, addr) });
27
+ };
28
+ export const TypeAddress = {
29
+ renderer: FormRendererAddress,
30
+ tester
31
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./test";
2
+ export * from "./render/StyledFormView";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./test";
2
+ export * from "./render/StyledFormView";
@@ -0,0 +1,9 @@
1
+ import { JsonSchema, UISchemaElement } from '@jsonforms/core';
2
+ import React from 'react';
3
+ interface Props {
4
+ data: any;
5
+ schema: JsonSchema;
6
+ uischema: UISchemaElement;
7
+ }
8
+ declare const StyledFormView: React.FC<Props>;
9
+ export default StyledFormView;
@@ -0,0 +1,7 @@
1
+ import { JsonForms } from '@jsonforms/react';
2
+ import React from 'react';
3
+ import { FormTypes } from '../router/router';
4
+ const StyledFormView = ({ data, schema, uischema }) => {
5
+ return (React.createElement(JsonForms, { data: data, schema: schema, uischema: uischema, renderers: FormTypes }));
6
+ };
7
+ export default StyledFormView;
@@ -0,0 +1,6 @@
1
+ import { ControlProps, RankedTester } from "@jsonforms/core";
2
+ export interface CustomType {
3
+ tester: RankedTester;
4
+ renderer: React.FC<ControlProps>;
5
+ }
6
+ export declare const FormTypes: Array<CustomType>;
@@ -0,0 +1,4 @@
1
+ import { TypeAddress } from "../components/Address";
2
+ export const FormTypes = [
3
+ TypeAddress
4
+ ];
package/dist/test.d.ts CHANGED
@@ -2,5 +2,5 @@ import React from "react";
2
2
  interface Props {
3
3
  text: string;
4
4
  }
5
- export declare const FormView: React.FC<Props>;
5
+ export declare const StyledSchema: React.FC<Props>;
6
6
  export {};
package/dist/test.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Typography } from "@mui/material";
2
2
  import React from "react";
3
- export const FormView = ({ text }) => {
3
+ export const StyledSchema = ({ text }) => {
4
4
  return React.createElement(Typography, { variant: "h1" }, text);
5
5
  };
@@ -0,0 +1,10 @@
1
+ export type Address = UKAddress;
2
+ interface UKAddress {
3
+ line1: string;
4
+ line2?: string;
5
+ city: string;
6
+ county?: string;
7
+ postcode: string;
8
+ number?: number;
9
+ }
10
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { JsonSchema } from "@jsonforms/core";
2
+ export declare const getXType: (schema: JsonSchema) => string | undefined;
@@ -0,0 +1,4 @@
1
+ export const getXType = (schema) => {
2
+ let typed = schema;
3
+ return typed["x-type"];
4
+ };
package/package.json CHANGED
@@ -1,29 +1,28 @@
1
1
  {
2
- "name": "swoop-common",
3
- "version": "1.0.3",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "files": [
7
- "dist"
8
- ],
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "build": "tsc"
12
- },
13
- "author": "",
14
- "license": "ISC",
15
- "description": "",
16
- "devDependencies": {
17
- "@eslint/js": "^9.30.1",
18
- "eslint": "^9.30.1",
19
- "eslint-plugin-react": "^7.37.5",
20
- "globals": "^16.3.0",
21
- "typescript-eslint": "^8.35.1"
22
- },
23
- "dependencies": {
24
- "@emotion/react": "^11.14.0",
25
- "@emotion/styled": "^11.14.1",
26
- "@mui/material": "^7.2.0",
27
- "react": "^19.1.0"
28
- }
29
- }
2
+ "name": "swoop-common",
3
+ "version": "1.0.4",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "build": "tsc"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "description": "",
16
+ "dependencies": {
17
+ "@jsonforms/core": "^3.5.1",
18
+ "@jsonforms/material-renderers": "^3.5.1",
19
+ "@jsonforms/react": "^3.5.1",
20
+ "@emotion/react": "^11.14.0",
21
+ "@emotion/styled": "^11.14.1",
22
+ "react": "^19.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^19",
26
+ "typescript": "^5"
27
+ }
28
+ }