@nolwenture/formik-jsonschema-form 0.4.2 → 0.6.0

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.
Files changed (88) hide show
  1. package/README.md +187 -0
  2. package/dist/Form.d.ts +2 -2
  3. package/dist/Form.js +15 -26
  4. package/dist/Form.stories.d.ts +12 -11
  5. package/dist/Form.stories.js +134 -101
  6. package/dist/Form.test.js +3 -3
  7. package/dist/FormEditor.d.ts +3 -3
  8. package/dist/FormEditor.js +14 -59
  9. package/dist/FormEditor.stories.d.ts +5 -4
  10. package/dist/FormEditor.stories.js +3 -16
  11. package/dist/fields/AnyField.d.ts +3 -3
  12. package/dist/fields/AnyField.js +12 -24
  13. package/dist/fields/ArrayField.d.ts +3 -3
  14. package/dist/fields/ArrayField.js +42 -64
  15. package/dist/fields/BooleanField.d.ts +3 -3
  16. package/dist/fields/BooleanField.js +7 -18
  17. package/dist/fields/DateField.d.ts +3 -3
  18. package/dist/fields/DateField.js +7 -18
  19. package/dist/fields/NullField.d.ts +3 -3
  20. package/dist/fields/NullField.js +5 -16
  21. package/dist/fields/NumberField.d.ts +3 -3
  22. package/dist/fields/NumberField.js +3 -14
  23. package/dist/fields/ObjectField.d.ts +3 -3
  24. package/dist/fields/ObjectField.js +43 -46
  25. package/dist/fields/RadioField.d.ts +3 -0
  26. package/dist/fields/RadioField.js +11 -0
  27. package/dist/fields/SchemaField.d.ts +3 -3
  28. package/dist/fields/SchemaField.js +13 -23
  29. package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
  30. package/dist/fields/SearchMultiTagSelectField.js +14 -0
  31. package/dist/fields/StringField.d.ts +3 -3
  32. package/dist/fields/StringField.js +13 -51
  33. package/dist/fields/ToggleField.d.ts +3 -0
  34. package/dist/fields/ToggleField.js +11 -0
  35. package/dist/fields/index.d.ts +3 -0
  36. package/dist/fields/index.js +3 -0
  37. package/dist/fields/types.js +1 -1
  38. package/dist/formEditorSchemas.d.ts +1 -1
  39. package/dist/formEditorSchemas.js +3 -3
  40. package/dist/hooks/index.d.ts +2 -0
  41. package/dist/hooks/index.js +2 -0
  42. package/dist/hooks/useExtractUiSchema.d.ts +8 -0
  43. package/dist/hooks/useExtractUiSchema.js +22 -0
  44. package/dist/hooks/useSetDefault.d.ts +2 -0
  45. package/dist/hooks/useSetDefault.js +16 -0
  46. package/dist/sampleData/completeSchema.d.ts +3 -0
  47. package/dist/{_sampleData.js → sampleData/completeSchema.js} +28 -97
  48. package/dist/sampleData/conditionsSchema.d.ts +3 -0
  49. package/dist/sampleData/conditionsSchema.js +80 -0
  50. package/dist/sampleData/generatedSchema.d.ts +2 -0
  51. package/dist/sampleData/generatedSchema.js +19 -0
  52. package/dist/sampleData/index.d.ts +5 -0
  53. package/dist/sampleData/index.js +5 -0
  54. package/dist/sampleData/requiredInputSchema.d.ts +3 -0
  55. package/dist/sampleData/requiredInputSchema.js +72 -0
  56. package/dist/sampleData/simpleData.d.ts +7 -0
  57. package/dist/sampleData/simpleData.js +16 -0
  58. package/dist/styledComponents.d.ts +193 -47
  59. package/dist/styledComponents.js +342 -138
  60. package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
  61. package/dist/templates/ArrayFieldTemplate.js +11 -23
  62. package/dist/templates/FieldTemplate.d.ts +3 -3
  63. package/dist/templates/FieldTemplate.js +11 -23
  64. package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
  65. package/dist/templates/ObjectFieldTemplate.js +13 -23
  66. package/dist/types.d.ts +34 -3
  67. package/dist/utils/__tests/getEnums.test.d.ts +1 -0
  68. package/dist/utils/__tests/getEnums.test.js +64 -0
  69. package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
  70. package/dist/utils/__tests/resolveSchema.test.js +106 -0
  71. package/dist/utils/deepEqual.d.ts +1 -0
  72. package/dist/utils/deepEqual.js +18 -0
  73. package/dist/utils/getEnums.d.ts +10 -0
  74. package/dist/utils/getEnums.js +30 -0
  75. package/dist/utils/getTitleAndDescription.d.ts +12 -0
  76. package/dist/utils/getTitleAndDescription.js +15 -0
  77. package/dist/utils/getTypes.d.ts +5 -0
  78. package/dist/utils/getTypes.js +53 -0
  79. package/dist/utils/index.d.ts +7 -0
  80. package/dist/utils/index.js +14 -0
  81. package/dist/utils/mergeSchemas.d.ts +1 -0
  82. package/dist/utils/mergeSchemas.js +26 -0
  83. package/dist/utils/resolveSchema.d.ts +2 -0
  84. package/dist/utils/resolveSchema.js +68 -0
  85. package/package.json +32 -37
  86. package/dist/_sampleData.d.ts +0 -11
  87. package/dist/utils.d.ts +0 -25
  88. package/dist/utils.js +0 -125
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolwenture/formik-jsonschema-form",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "description": "Formik form generation from json schema",
5
5
  "author": "Antti Vikman <antti.vikman@nolwenture.com>",
6
6
  "contributors": [
@@ -27,32 +27,41 @@
27
27
  "package.json",
28
28
  "LICENSE"
29
29
  ],
30
+ "scripts": {
31
+ "build": "tsc --build",
32
+ "clean": "tsc --build --clean",
33
+ "test": "jest",
34
+ "storybook": "storybook dev -p 6006"
35
+ },
30
36
  "dependencies": {
31
- "@testing-library/jest-dom": "^5.16.4",
32
- "@testing-library/react": "^13.3.0",
33
- "@testing-library/user-event": "^13.5.0",
34
- "@types/jest": "^27.5.2",
35
- "@types/node": "^16.11.45",
36
- "@types/react": "^18.0.15",
37
- "@types/react-dom": "^18.0.6",
38
- "@types/styled-components": "^5.1.25",
39
- "formik": "^2.2.9",
37
+ "formik": "^2.4.5",
40
38
  "json-schema": "^0.4.0",
41
39
  "react": "^18.2.0",
42
- "react-dom": "^18.2.0",
43
- "react-scripts": "5.0.1",
44
- "styled-components": "^5.3.5",
45
- "typescript": "^4.7.4",
46
- "web-vitals": "^2.1.4"
40
+ "styled-components": "^6.1.8",
41
+ "typescript": "^5.4.3"
47
42
  },
48
- "scripts": {
49
- "start": "react-scripts start",
50
- "build": "tsc --build",
51
- "clean": "tsc --build --clean",
52
- "test": "react-scripts test",
53
- "eject": "react-scripts eject",
54
- "storybook": "start-storybook -p 6006",
55
- "build-storybook": "build-storybook"
43
+ "devDependencies": {
44
+ "@babel/preset-react": "^7.24.1",
45
+ "@babel/preset-typescript": "^7.24.1",
46
+ "@storybook/addon-essentials": "^8.0.5",
47
+ "@storybook/addon-interactions": "^8.0.5",
48
+ "@storybook/addon-links": "^8.0.5",
49
+ "@storybook/addon-webpack5-compiler-babel": "^3.0.3",
50
+ "@storybook/react": "^8.0.5",
51
+ "@storybook/react-webpack5": "^8.0.5",
52
+ "@storybook/test": "^8.0.5",
53
+ "@testing-library/jest-dom": "^6.4.2",
54
+ "@testing-library/react": "^14.2.2",
55
+ "@testing-library/user-event": "^14.5.2",
56
+ "@types/jest": "^29.5.12",
57
+ "@types/node": "^20.12.2",
58
+ "@types/react": "^18.2.73",
59
+ "@types/styled-components": "^5.1.34",
60
+ "babel-plugin-named-exports-order": "^0.0.2",
61
+ "jest": "^29.7.0",
62
+ "storybook": "^8.0.5",
63
+ "ts-jest": "^29.1.2",
64
+ "webpack": "^5.91.0"
56
65
  },
57
66
  "eslintConfig": {
58
67
  "extends": [
@@ -81,19 +90,5 @@
81
90
  "last 1 firefox version",
82
91
  "last 1 safari version"
83
92
  ]
84
- },
85
- "devDependencies": {
86
- "@storybook/addon-essentials": "^6.5.15",
87
- "@storybook/addon-interactions": "^6.5.15",
88
- "@storybook/addon-links": "^6.5.15",
89
- "@storybook/builder-webpack5": "^6.5.15",
90
- "@storybook/manager-webpack5": "^6.5.15",
91
- "@storybook/node-logger": "^6.5.15",
92
- "@storybook/preset-create-react-app": "^4.1.2",
93
- "@storybook/react": "^6.5.15",
94
- "@storybook/testing-library": "^0.0.13",
95
- "babel-plugin-named-exports-order": "^0.0.2",
96
- "prop-types": "^15.8.1",
97
- "webpack": "^5.73.0"
98
93
  }
99
94
  }
@@ -1,11 +0,0 @@
1
- import { Schema, UiSchema } from "./types";
2
- export type SimpleFormDataType = {
3
- firstName: string;
4
- lastName: string;
5
- };
6
- export declare const simpleSchema: Schema;
7
- export declare const simpleUiSchema: UiSchema;
8
- export declare const completeSchema: Schema;
9
- export declare const completeUiSchema: UiSchema;
10
- export declare const generatedSchema: Schema;
11
- export declare const requiredInputSchema: Schema;
package/dist/utils.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { FieldProps, Schema, UiSchema } from "./types";
2
- import { JSONSchema7 } from "json-schema";
3
- export declare function getTitle({ title, uiSchema, schema, name, }: {
4
- title?: string;
5
- uiSchema?: UiSchema;
6
- schema?: Schema;
7
- name?: string;
8
- }): any;
9
- export declare function getDescription({ description, uiSchema, schema, }: {
10
- description?: string;
11
- uiSchema?: UiSchema;
12
- schema?: Schema;
13
- }): any;
14
- export declare function getDefaultValueForType(type: JSONSchema7["type"]): {} | null;
15
- export declare function useSetDefault(props: FieldProps): void;
16
- export declare function useExtractUiSchema(props?: UiSchema | undefined): {
17
- [name: string]: any;
18
- field?: UiSchema["ui:field"];
19
- props?: UiSchema["ui:props"];
20
- help?: UiSchema["ui:help"];
21
- info?: UiSchema["ui:info"];
22
- };
23
- export declare const guessType: (value: any) => "string" | "number" | "boolean" | "object" | "array" | "null";
24
- export declare function getSchemaType(schema: Schema): import("json-schema").JSONSchema7TypeName | import("json-schema").JSONSchema7TypeName[] | undefined;
25
- export declare function warnFromUnsupportedKeys(componentName: string, data: Record<string, any>, supportedKeys: string[]): void;
package/dist/utils.js DELETED
@@ -1,125 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- import { useField } from "formik";
24
- import { useEffect, useMemo } from "react";
25
- export function getTitle(_a) {
26
- var _b;
27
- var title = _a.title, uiSchema = _a.uiSchema, schema = _a.schema, name = _a.name;
28
- return (title ||
29
- ((_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:options"]) === null || _b === void 0 ? void 0 : _b.title) ||
30
- (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:title"]) ||
31
- (schema === null || schema === void 0 ? void 0 : schema.title) ||
32
- (name === null || name === void 0 ? void 0 : name.split(".")[(name === null || name === void 0 ? void 0 : name.split(".").length) - 1]));
33
- }
34
- export function getDescription(_a) {
35
- var _b;
36
- var description = _a.description, uiSchema = _a.uiSchema, schema = _a.schema;
37
- return (description ||
38
- ((_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:options"]) === null || _b === void 0 ? void 0 : _b.description) ||
39
- (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:description"]) ||
40
- (schema === null || schema === void 0 ? void 0 : schema.description));
41
- }
42
- export function getDefaultValueForType(type) {
43
- if (type && !Array.isArray(type)) {
44
- if (type === "array")
45
- return [];
46
- if (type === "object")
47
- return {};
48
- }
49
- return null;
50
- }
51
- export function useSetDefault(props) {
52
- var _a = useField(props.name), value = _a[0].value, _ = _a[1], setValue = _a[2].setValue;
53
- useEffect(function () {
54
- if (!value) {
55
- if (props.schema.default) {
56
- setValue(props.schema.default);
57
- }
58
- else if (props.forceDefaultValue) {
59
- setValue(getDefaultValueForType(props.schema.type));
60
- }
61
- }
62
- }, []);
63
- }
64
- export function useExtractUiSchema(props) {
65
- if (props === void 0) { props = {}; }
66
- if (props.props !== undefined) {
67
- props["ui:props"] = __assign(__assign({}, props["ui:props"]), props.props);
68
- }
69
- return useMemo(function () {
70
- var _a = props["ui:options"], options = _a === void 0 ? {} : _a, uiSchema = __rest(props, ["ui:options"]);
71
- return __assign(__assign({}, Object.keys(uiSchema || {}).reduce(function (result, key) {
72
- var _a;
73
- return (__assign(__assign({}, result), (_a = {}, _a[key.replace("ui:", "")] = uiSchema[key], _a)));
74
- }, {})), options);
75
- }, [props]);
76
- }
77
- export var guessType = function guessType(value) {
78
- if (Array.isArray(value)) {
79
- return "array";
80
- }
81
- else if (typeof value === "string") {
82
- return "string";
83
- }
84
- else if (value == null) {
85
- return "null";
86
- }
87
- else if (typeof value === "boolean") {
88
- return "boolean";
89
- }
90
- else if (!isNaN(value)) {
91
- return "number";
92
- }
93
- else if (typeof value === "object") {
94
- return "object";
95
- }
96
- // Default to string if we can't figure it out
97
- return "string";
98
- };
99
- export function getSchemaType(schema) {
100
- if (!schema) {
101
- return undefined;
102
- }
103
- var type = schema.type;
104
- if (!type && schema.const) {
105
- return guessType(schema.const);
106
- }
107
- if (!type && schema.enum) {
108
- return "string";
109
- }
110
- if (!type && (schema.properties || schema.additionalProperties)) {
111
- return "object";
112
- }
113
- if (type instanceof Array && type.length === 2 && type.includes("null")) {
114
- return type.find(function (type) { return type !== "null"; });
115
- }
116
- return type;
117
- }
118
- //TODO: REMOVE WHEN ALL SUPPORTED
119
- export function warnFromUnsupportedKeys(componentName, data, supportedKeys) {
120
- Object.keys(data).forEach(function (key) {
121
- if (!supportedKeys.includes(key)) {
122
- console.warn("Component \"".concat(componentName, "\" does not support (yet) key \"").concat(key, "\""));
123
- }
124
- });
125
- }