@nolwenture/formik-jsonschema-form 0.7.1 → 0.9.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.
- package/README.md +176 -1
- package/dist/Form.js +2 -1
- package/dist/Form.stories.d.ts +2 -0
- package/dist/Form.stories.js +15 -0
- package/dist/Form.test.d.ts +1 -1
- package/dist/Form.test.js +3 -1
- package/dist/fields/ArrayField.js +2 -1
- package/dist/fields/MultipleChoiceField.d.ts +3 -0
- package/dist/fields/MultipleChoiceField.js +13 -0
- package/dist/fields/ObjectField.js +3 -1
- package/dist/fields/SchemaField.js +7 -5
- package/dist/fields/StringField.js +1 -1
- package/dist/fields/index.d.ts +1 -0
- package/dist/fields/index.js +1 -0
- package/dist/fields/stories/AnyField.stories.d.ts +5 -0
- package/dist/fields/stories/AnyField.stories.js +79 -0
- package/dist/fields/stories/ArrayField.stories.d.ts +7 -0
- package/dist/fields/stories/ArrayField.stories.js +191 -0
- package/dist/fields/stories/BooleanField.stories.d.ts +5 -0
- package/dist/fields/stories/BooleanField.stories.js +36 -0
- package/dist/fields/stories/DateField.stories.d.ts +5 -0
- package/dist/fields/stories/DateField.stories.js +34 -0
- package/dist/fields/stories/NullField.stories.d.ts +5 -0
- package/dist/fields/stories/NullField.stories.js +38 -0
- package/dist/fields/stories/NumberField.stories.d.ts +5 -0
- package/dist/fields/stories/NumberField.stories.js +33 -0
- package/dist/fields/stories/ObjectField.stories.d.ts +5 -0
- package/dist/fields/stories/ObjectField.stories.js +76 -0
- package/dist/fields/stories/RadioField.stories.d.ts +5 -0
- package/dist/fields/stories/RadioField.stories.js +42 -0
- package/dist/fields/stories/SchemaField.stories.d.ts +1716 -0
- package/dist/fields/stories/SchemaField.stories.js +85 -0
- package/dist/fields/stories/SearchMultiTagSelectField.stories.d.ts +5 -0
- package/dist/fields/stories/SearchMultiTagSelectField.stories.js +58 -0
- package/dist/fields/stories/StringField.stories.d.ts +7 -0
- package/dist/fields/stories/StringField.stories.js +75 -0
- package/dist/fields/stories/ToggleField.stories.d.ts +5 -0
- package/dist/fields/stories/ToggleField.stories.js +34 -0
- package/dist/formEditorSchemas.js +177 -21
- package/dist/hooks/__tests__/useExtractUiSchema.test.d.ts +1 -0
- package/dist/hooks/__tests__/useExtractUiSchema.test.js +45 -0
- package/dist/hooks/__tests__/useSetDefault.test.d.ts +1 -0
- package/dist/hooks/__tests__/useSetDefault.test.js +65 -0
- package/dist/hooks/useExtractUiSchema.js +7 -3
- package/dist/sampleData/ageFieldDefinition.d.ts +2 -0
- package/dist/sampleData/ageFieldDefinition.js +5 -0
- package/dist/sampleData/multipleChoiceSchema.d.ts +3 -0
- package/dist/sampleData/multipleChoiceSchema.js +112 -0
- package/dist/sampleData/refDefSchema.d.ts +3 -0
- package/dist/sampleData/refDefSchema.js +219 -0
- package/dist/sampleData/requiredInputSchema.js +0 -5
- package/dist/styledComponents.d.ts +2 -1
- package/dist/styledComponents.js +8 -0
- package/dist/types.d.ts +19 -2
- package/dist/utils/__tests/createInitialValues.test.d.ts +1 -0
- package/dist/utils/__tests/createInitialValues.test.js +72 -0
- package/dist/utils/__tests/deepOverlap.test.d.ts +1 -0
- package/dist/utils/__tests/deepOverlap.test.js +41 -0
- package/dist/utils/__tests/getEnums.test.js +11 -16
- package/dist/utils/__tests/getTitleAndDescription.test.d.ts +1 -0
- package/dist/utils/__tests/getTitleAndDescription.test.js +53 -0
- package/dist/utils/__tests/getTypes.test.d.ts +1 -0
- package/dist/utils/__tests/getTypes.test.js +62 -0
- package/dist/utils/__tests/mergeSchemas.test.d.ts +1 -0
- package/dist/utils/__tests/mergeSchemas.test.js +40 -0
- package/dist/utils/__tests/resolveSchema.test.js +43 -33
- package/dist/utils/__tests/solveReferences.test.d.ts +1 -0
- package/dist/utils/__tests/solveReferences.test.js +12 -0
- package/dist/utils/__tests/testSchemas.d.ts +4 -0
- package/dist/utils/__tests/testSchemas.js +67 -0
- package/dist/utils/createInitialValues.d.ts +4 -0
- package/dist/utils/createInitialValues.js +27 -0
- package/dist/utils/getStyle.d.ts +5 -0
- package/dist/utils/getStyle.js +18 -0
- package/dist/utils/getTypes.js +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/resolveSchema.d.ts +1 -1
- package/dist/utils/resolveSchema.js +88 -39
- package/dist/utils/solveReferences.d.ts +2 -0
- package/dist/utils/solveReferences.js +8 -0
- package/package.json +5 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { userEvent, expect } from "@storybook/test";
|
|
12
|
+
import { Formik, Form } from "formik";
|
|
13
|
+
import { BooleanField } from "./../BooleanField";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/BooleanField",
|
|
16
|
+
component: BooleanField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: { acceptTerms: false }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "acceptTerms",
|
|
24
|
+
schema: { type: "boolean" },
|
|
25
|
+
uiSchema: {
|
|
26
|
+
"ui:label": "I accept the terms and conditions",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
30
|
+
const checkbox = canvasElement.querySelector('input[type="checkbox"][name="acceptTerms"]');
|
|
31
|
+
yield userEvent.click(checkbox);
|
|
32
|
+
yield expect(checkbox).toBeChecked();
|
|
33
|
+
yield userEvent.click(checkbox);
|
|
34
|
+
yield expect(checkbox).not.toBeChecked();
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StoryObj } from "@storybook/react";
|
|
2
|
+
import { DateField } from "./../DateField";
|
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const Default: StoryObj<typeof DateField>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { userEvent, expect } from "@storybook/test";
|
|
12
|
+
import { Formik, Form } from "formik";
|
|
13
|
+
import { DateField } from "./../DateField";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/DateField",
|
|
16
|
+
component: DateField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: { birthDate: "" }, onSubmit: (values) => console.log(values), children: _jsx(Form, { children: Story() }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "birthDate",
|
|
24
|
+
schema: { type: "string", format: "date" },
|
|
25
|
+
uiSchema: {},
|
|
26
|
+
},
|
|
27
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
28
|
+
const dateInput = canvasElement.querySelector('input[name="birthDate"]');
|
|
29
|
+
expect(dateInput).toBeInTheDocument();
|
|
30
|
+
const dateToInput = "2023-02-01";
|
|
31
|
+
yield userEvent.type(dateInput, dateToInput);
|
|
32
|
+
yield expect(dateInput).toHaveValue(dateToInput);
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StoryObj } from "@storybook/react";
|
|
2
|
+
import { NullField } from "./../NullField";
|
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const Default: StoryObj<typeof NullField>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { within, expect } from "@storybook/test";
|
|
12
|
+
import { Formik, Form } from "formik";
|
|
13
|
+
import { NullField } from "./../NullField";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/NullField",
|
|
16
|
+
component: NullField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: { someField: null }, onSubmit: (values) => console.log(values), children: _jsxs(Form, { children: [Story(), _jsx("button", { type: "submit", children: "Submit" })] }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "nullField",
|
|
24
|
+
description: "Additional info",
|
|
25
|
+
schema: { type: "null", title: "Null Field" },
|
|
26
|
+
uiSchema: {},
|
|
27
|
+
},
|
|
28
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
29
|
+
const canvas = within(canvasElement);
|
|
30
|
+
const title = canvasElement.querySelector('label[for="nullField"]');
|
|
31
|
+
const submitButton = canvasElement.querySelector('button[type="submit"]');
|
|
32
|
+
const additionalInfo = yield canvas.findByText("Additional info");
|
|
33
|
+
expect(title).toBeInTheDocument();
|
|
34
|
+
expect(title.textContent).toBeTruthy();
|
|
35
|
+
expect(additionalInfo).toBeInTheDocument();
|
|
36
|
+
expect(submitButton).toBeInTheDocument();
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StoryObj } from "@storybook/react";
|
|
2
|
+
import { NumberField } from "./../NumberField";
|
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const Default: StoryObj<typeof NumberField>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { userEvent, expect } from "@storybook/test";
|
|
12
|
+
import { Formik, Form } from "formik";
|
|
13
|
+
import { NumberField } from "./../NumberField";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/NumberField",
|
|
16
|
+
component: NumberField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: { numberInput: "" }, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "numberInput",
|
|
24
|
+
schema: { type: "number" },
|
|
25
|
+
uiSchema: {},
|
|
26
|
+
},
|
|
27
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
28
|
+
const numberInput = canvasElement.querySelector('input[name="numberInput"]');
|
|
29
|
+
yield userEvent.type(numberInput, "asd123");
|
|
30
|
+
yield expect(numberInput).toHaveValue(123);
|
|
31
|
+
// Add tests, such as validation adn incrementing/decrementing the value
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StoryObj } from "@storybook/react";
|
|
2
|
+
import { ObjectField } from "./../ObjectField";
|
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const Default: StoryObj<typeof ObjectField>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { userEvent, expect } from "@storybook/test";
|
|
12
|
+
import { Formik, Form } from "formik";
|
|
13
|
+
import { ObjectField } from "./../ObjectField";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/ObjectField",
|
|
16
|
+
component: ObjectField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: {}, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "object",
|
|
24
|
+
schema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
title: "Object field test",
|
|
27
|
+
properties: {
|
|
28
|
+
string: {
|
|
29
|
+
type: "string",
|
|
30
|
+
title: "stringField",
|
|
31
|
+
description: "String description",
|
|
32
|
+
},
|
|
33
|
+
number: {
|
|
34
|
+
type: "number",
|
|
35
|
+
title: "numberField",
|
|
36
|
+
description: "Number description",
|
|
37
|
+
},
|
|
38
|
+
boolean: {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
title: "booleanField",
|
|
41
|
+
description: "Boolean description",
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
enum: {
|
|
45
|
+
type: "array",
|
|
46
|
+
title: "Array Enum",
|
|
47
|
+
description: "Array Enum description",
|
|
48
|
+
items: {
|
|
49
|
+
type: "number",
|
|
50
|
+
enum: [1, 2, 3, 4],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
null: {
|
|
54
|
+
type: "null",
|
|
55
|
+
title: "nullField",
|
|
56
|
+
description: "Null description",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
uiSchema: {},
|
|
61
|
+
},
|
|
62
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
63
|
+
const stringField = canvasElement.querySelector('input[name="object.string"]');
|
|
64
|
+
const numberField = canvasElement.querySelector('input[name="object.number"]');
|
|
65
|
+
const booleanField = canvasElement.querySelector('input[name="object.boolean"]');
|
|
66
|
+
const enumField = canvasElement.querySelector('select[name="object.enum[0]"]');
|
|
67
|
+
yield userEvent.type(stringField, "string");
|
|
68
|
+
yield userEvent.type(numberField, "123");
|
|
69
|
+
yield userEvent.click(booleanField);
|
|
70
|
+
yield userEvent.selectOptions(enumField, "2");
|
|
71
|
+
expect(stringField).toHaveValue("string");
|
|
72
|
+
expect(numberField).toHaveValue(123);
|
|
73
|
+
expect(booleanField).toBeChecked();
|
|
74
|
+
expect(enumField).toHaveValue("2");
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StoryObj } from "@storybook/react";
|
|
2
|
+
import { RadioField } from "./../RadioField";
|
|
3
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react").ReactRenderer, import("../../types").FieldProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const Default: StoryObj<typeof RadioField>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { userEvent, expect } from "@storybook/test";
|
|
12
|
+
import { RadioField } from "./../RadioField";
|
|
13
|
+
import { Formik, Form } from "formik";
|
|
14
|
+
export default {
|
|
15
|
+
title: "Fields/RadioField",
|
|
16
|
+
component: RadioField,
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (_jsx(Formik, { initialValues: {}, onSubmit: () => { }, children: _jsx(Form, { children: Story() }) })),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export const Default = {
|
|
22
|
+
args: {
|
|
23
|
+
name: "RadioField",
|
|
24
|
+
title: "Radio field test",
|
|
25
|
+
schema: {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
},
|
|
28
|
+
uiSchema: {
|
|
29
|
+
"ui:label": { true: "yes", false: "no" },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
play: (_a) => __awaiter(void 0, [_a], void 0, function* ({ canvasElement }) {
|
|
33
|
+
const radioTrue = canvasElement.querySelector('input[type="radio"][name="RadioField"][value="true"]');
|
|
34
|
+
const radioFalse = canvasElement.querySelector('input[type="radio"][name="RadioField"][value="false"]');
|
|
35
|
+
yield userEvent.click(radioTrue);
|
|
36
|
+
yield expect(radioTrue).toBeChecked();
|
|
37
|
+
yield expect(radioFalse).not.toBeChecked();
|
|
38
|
+
yield userEvent.click(radioFalse);
|
|
39
|
+
yield expect(radioFalse).toBeChecked();
|
|
40
|
+
yield expect(radioTrue).not.toBeChecked();
|
|
41
|
+
}),
|
|
42
|
+
};
|