@nolwenture/formik-jsonschema-form 0.1.0 → 0.1.2
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.
- package/package.json +90 -86
- package/src/Form.d.ts +4 -0
- package/src/Form.js +52 -0
- package/src/Form.stories.d.ts +11 -0
- package/src/Form.stories.js +135 -0
- package/src/Form.test.d.ts +1 -0
- package/src/Form.test.js +9 -0
- package/src/FormEditor.d.ts +8 -0
- package/src/FormEditor.js +74 -0
- package/src/FormEditor.stories.d.ts +5 -0
- package/src/FormEditor.stories.js +22 -0
- package/src/_sampleData.d.ts +10 -0
- package/src/_sampleData.js +262 -0
- package/src/fields/AnyField.d.ts +3 -0
- package/src/fields/AnyField.js +34 -0
- package/src/fields/ArrayField.d.ts +3 -0
- package/src/fields/ArrayField.js +119 -0
- package/src/fields/BooleanField.d.ts +3 -0
- package/src/fields/BooleanField.js +22 -0
- package/src/fields/DateField.d.ts +3 -0
- package/src/fields/DateField.js +22 -0
- package/src/fields/NullField.d.ts +3 -0
- package/src/fields/NullField.js +19 -0
- package/src/fields/NumberField.d.ts +3 -0
- package/src/fields/NumberField.js +17 -0
- package/src/fields/ObjectField.d.ts +3 -0
- package/src/fields/ObjectField.js +56 -0
- package/src/fields/SchemaField.d.ts +3 -0
- package/src/fields/SchemaField.js +39 -0
- package/src/fields/StringField.d.ts +3 -0
- package/src/fields/StringField.js +60 -0
- package/src/fields/{index.ts → index.d.ts} +0 -0
- package/src/fields/index.js +9 -0
- package/src/fields/types.d.ts +10 -0
- package/src/fields/types.js +10 -0
- package/src/formEditorSchemas.d.ts +3 -0
- package/src/formEditorSchemas.js +36 -0
- package/src/{index.tsx → index.d.ts} +0 -0
- package/src/index.js +5 -0
- package/src/setupTests.d.ts +1 -0
- package/src/{setupTests.ts → setupTests.js} +0 -0
- package/src/styledComponents.d.ts +26 -0
- package/src/styledComponents.js +89 -0
- package/src/templates/ArrayFieldTemplate.d.ts +3 -0
- package/src/templates/ArrayFieldTemplate.js +27 -0
- package/src/templates/FieldTemplate.d.ts +3 -0
- package/src/templates/FieldTemplate.js +27 -0
- package/src/templates/ObjectFieldTemplate.d.ts +3 -0
- package/src/templates/ObjectFieldTemplate.js +11 -0
- package/src/templates/{index.ts → index.d.ts} +0 -0
- package/src/templates/index.js +3 -0
- package/src/types.d.ts +168 -0
- package/src/types.js +14 -0
- package/src/utils.d.ts +22 -0
- package/src/utils.js +108 -0
- package/.storybook/main.js +0 -13
- package/.storybook/preview.js +0 -9
- package/README.md +0 -46
- package/src/Form.stories.tsx +0 -124
- package/src/Form.test.tsx +0 -10
- package/src/Form.tsx +0 -71
- package/src/FormEditor.stories.tsx +0 -17
- package/src/FormEditor.tsx +0 -53
- package/src/_sampleData.ts +0 -273
- package/src/fields/AnyField.tsx +0 -35
- package/src/fields/ArrayField.tsx +0 -177
- package/src/fields/BooleanField.tsx +0 -23
- package/src/fields/DateField.tsx +0 -20
- package/src/fields/NullField.tsx +0 -12
- package/src/fields/NumberField.tsx +0 -14
- package/src/fields/ObjectField.tsx +0 -68
- package/src/fields/SchemaField.tsx +0 -37
- package/src/fields/StringField.tsx +0 -89
- package/src/fields/types.tsx +0 -10
- package/src/formEditorSchemas.ts +0 -40
- package/src/styledComponents.tsx +0 -107
- package/src/templates/ArrayFieldTemplate.tsx +0 -46
- package/src/templates/FieldTemplate.tsx +0 -46
- package/src/templates/ObjectFieldTemplate.tsx +0 -22
- package/src/types.ts +0 -260
- package/src/utils.ts +0 -124
- package/tsconfig.json +0 -26
package/src/utils.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { useField } from "formik";
|
|
2
|
-
import { useEffect, useMemo } from "react";
|
|
3
|
-
import { FieldProps, Schema, UiSchema } from "./types";
|
|
4
|
-
|
|
5
|
-
export function getTitle({
|
|
6
|
-
title,
|
|
7
|
-
uiSchema,
|
|
8
|
-
schema,
|
|
9
|
-
}: {
|
|
10
|
-
title?: string;
|
|
11
|
-
uiSchema?: UiSchema;
|
|
12
|
-
schema?: Schema;
|
|
13
|
-
}) {
|
|
14
|
-
return (
|
|
15
|
-
title ||
|
|
16
|
-
uiSchema?.["ui:options"]?.title ||
|
|
17
|
-
uiSchema?.["ui:title"] ||
|
|
18
|
-
schema?.title
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
export function getDescription({
|
|
22
|
-
description,
|
|
23
|
-
uiSchema,
|
|
24
|
-
schema,
|
|
25
|
-
}: {
|
|
26
|
-
description?: string;
|
|
27
|
-
uiSchema?: UiSchema;
|
|
28
|
-
schema?: Schema;
|
|
29
|
-
}) {
|
|
30
|
-
return (
|
|
31
|
-
description ||
|
|
32
|
-
uiSchema?.["ui:options"]?.description ||
|
|
33
|
-
uiSchema?.["ui:description"] ||
|
|
34
|
-
schema?.description
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function useSetDefault(props: FieldProps) {
|
|
39
|
-
const [{ value }, _, { setValue }] = useField(props.name);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (!value && props.schema.default) {
|
|
42
|
-
setValue(props.schema.default);
|
|
43
|
-
}
|
|
44
|
-
}, []);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function useExtractUiSchema(props: UiSchema | undefined = {}): {
|
|
48
|
-
[name: string]: any;
|
|
49
|
-
field?: UiSchema["ui:field"];
|
|
50
|
-
props?: UiSchema["ui:props"];
|
|
51
|
-
help?: UiSchema["ui:help"];
|
|
52
|
-
} {
|
|
53
|
-
return useMemo(() => {
|
|
54
|
-
const { "ui:options": options = {}, ...uiSchema } = props;
|
|
55
|
-
return {
|
|
56
|
-
...Object.keys(uiSchema || {}).reduce(
|
|
57
|
-
(result, key) => ({
|
|
58
|
-
...result,
|
|
59
|
-
[key.replace("ui:", "")]: uiSchema[key],
|
|
60
|
-
}),
|
|
61
|
-
{}
|
|
62
|
-
),
|
|
63
|
-
...options,
|
|
64
|
-
};
|
|
65
|
-
}, [props]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const guessType = function guessType(value: any) {
|
|
69
|
-
if (Array.isArray(value)) {
|
|
70
|
-
return "array";
|
|
71
|
-
} else if (typeof value === "string") {
|
|
72
|
-
return "string";
|
|
73
|
-
} else if (value == null) {
|
|
74
|
-
return "null";
|
|
75
|
-
} else if (typeof value === "boolean") {
|
|
76
|
-
return "boolean";
|
|
77
|
-
} else if (!isNaN(value)) {
|
|
78
|
-
return "number";
|
|
79
|
-
} else if (typeof value === "object") {
|
|
80
|
-
return "object";
|
|
81
|
-
}
|
|
82
|
-
// Default to string if we can't figure it out
|
|
83
|
-
return "string";
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export function getSchemaType(schema: Schema) {
|
|
87
|
-
if (!schema) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
let { type } = schema;
|
|
91
|
-
|
|
92
|
-
if (!type && schema.const) {
|
|
93
|
-
return guessType(schema.const);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!type && schema.enum) {
|
|
97
|
-
return "string";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
101
|
-
return "object";
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (type instanceof Array && type.length === 2 && type.includes("null")) {
|
|
105
|
-
return type.find((type) => type !== "null");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return type;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//TODO: REMOVE WHEN ALL SUPPORTED
|
|
112
|
-
export function warnFromUnsupportedKeys(
|
|
113
|
-
componentName: string,
|
|
114
|
-
data: Record<string, any>,
|
|
115
|
-
supportedKeys: string[]
|
|
116
|
-
) {
|
|
117
|
-
Object.keys(data).forEach((key) => {
|
|
118
|
-
if (!supportedKeys.includes(key)) {
|
|
119
|
-
console.warn(
|
|
120
|
-
`Component "${componentName}" does not support (yet) key "${key}"`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"lib": [
|
|
5
|
-
"dom",
|
|
6
|
-
"dom.iterable",
|
|
7
|
-
"esnext"
|
|
8
|
-
],
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"strict": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": true,
|
|
16
|
-
"module": "esnext",
|
|
17
|
-
"moduleResolution": "node",
|
|
18
|
-
"resolveJsonModule": true,
|
|
19
|
-
"isolatedModules": true,
|
|
20
|
-
"noEmit": true,
|
|
21
|
-
"jsx": "react-jsx"
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"src"
|
|
25
|
-
]
|
|
26
|
-
}
|