@nolwenture/formik-jsonschema-form 0.5.0 → 0.7.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 +93 -0
- package/dist/Form.d.ts +2 -2
- package/dist/Form.js +4 -4
- package/dist/Form.stories.d.ts +12 -11
- package/dist/Form.stories.js +65 -38
- package/dist/Form.test.js +1 -1
- package/dist/FormEditor.d.ts +3 -3
- package/dist/FormEditor.js +6 -6
- package/dist/FormEditor.stories.d.ts +5 -4
- package/dist/FormEditor.stories.js +3 -5
- package/dist/fields/AnyField.d.ts +3 -3
- package/dist/fields/AnyField.js +5 -6
- package/dist/fields/ArrayField.d.ts +3 -3
- package/dist/fields/ArrayField.js +10 -10
- package/dist/fields/BooleanField.d.ts +3 -3
- package/dist/fields/BooleanField.js +3 -3
- package/dist/fields/DateField.d.ts +3 -3
- package/dist/fields/DateField.js +3 -3
- package/dist/fields/NullField.d.ts +3 -3
- package/dist/fields/NullField.js +2 -2
- package/dist/fields/NumberField.d.ts +3 -3
- package/dist/fields/NumberField.js +2 -2
- package/dist/fields/ObjectField.d.ts +3 -3
- package/dist/fields/ObjectField.js +36 -8
- package/dist/fields/RadioField.d.ts +3 -3
- package/dist/fields/RadioField.js +3 -3
- package/dist/fields/SchemaField.d.ts +3 -3
- package/dist/fields/SchemaField.js +6 -5
- package/dist/fields/SearchMultiTagSelectField.d.ts +3 -3
- package/dist/fields/SearchMultiTagSelectField.js +4 -3
- package/dist/fields/StringField.d.ts +3 -3
- package/dist/fields/StringField.js +9 -7
- package/dist/fields/ToggleField.d.ts +3 -3
- package/dist/fields/ToggleField.js +3 -3
- package/dist/formEditorSchemas.d.ts +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useExtractUiSchema.d.ts +8 -0
- package/dist/hooks/useExtractUiSchema.js +22 -0
- package/dist/hooks/useSetDefault.d.ts +2 -0
- package/dist/hooks/useSetDefault.js +16 -0
- package/dist/sampleData/completeSchema.d.ts +3 -0
- package/dist/{_sampleData.js → sampleData/completeSchema.js} +0 -107
- package/dist/sampleData/conditionsSchema.d.ts +3 -0
- package/dist/sampleData/conditionsSchema.js +82 -0
- package/dist/sampleData/generatedSchema.d.ts +2 -0
- package/dist/sampleData/generatedSchema.js +19 -0
- package/dist/sampleData/index.d.ts +5 -0
- package/dist/sampleData/index.js +5 -0
- package/dist/sampleData/requiredInputSchema.d.ts +3 -0
- package/dist/sampleData/requiredInputSchema.js +72 -0
- package/dist/sampleData/simpleData.d.ts +7 -0
- package/dist/sampleData/simpleData.js +16 -0
- package/dist/styledComponents.d.ts +181 -84
- package/dist/styledComponents.js +28 -29
- package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
- package/dist/templates/ArrayFieldTemplate.js +5 -4
- package/dist/templates/FieldTemplate.d.ts +3 -3
- package/dist/templates/FieldTemplate.js +6 -5
- package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
- package/dist/templates/ObjectFieldTemplate.js +4 -3
- package/dist/types.d.ts +2 -2
- package/dist/utils/__tests/getEnums.test.d.ts +1 -0
- package/dist/utils/__tests/getEnums.test.js +64 -0
- package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
- package/dist/utils/__tests/resolveSchema.test.js +106 -0
- package/dist/utils/deepOverlap.d.ts +1 -0
- package/dist/utils/deepOverlap.js +14 -0
- package/dist/utils/getEnums.d.ts +10 -0
- package/dist/utils/getEnums.js +30 -0
- package/dist/utils/getTitleAndDescription.d.ts +12 -0
- package/dist/utils/getTitleAndDescription.js +15 -0
- package/dist/utils/getTypes.d.ts +5 -0
- package/dist/utils/getTypes.js +53 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/mergeSchemas.d.ts +1 -0
- package/dist/utils/mergeSchemas.js +26 -0
- package/dist/utils/resolveSchema.d.ts +2 -0
- package/dist/utils/resolveSchema.js +68 -0
- package/package.json +32 -37
- package/dist/_sampleData.d.ts +0 -12
- package/dist/utils.d.ts +0 -32
- package/dist/utils.js +0 -138
package/README.md
CHANGED
|
@@ -453,6 +453,99 @@ RadioButtonField.styles = {
|
|
|
453
453
|
};
|
|
454
454
|
```
|
|
455
455
|
|
|
456
|
+
### Conditional fields
|
|
457
|
+
|
|
458
|
+
Conditional fields depending on a parent field input can be given with an `if-then-else` logic inside the schema making use of `allOf`. While `if`and `then` are required to make the condition work, `else` is optional.
|
|
459
|
+
|
|
460
|
+
```tsx
|
|
461
|
+
export const conditionsSchema = {
|
|
462
|
+
type: "object",
|
|
463
|
+
properties: {
|
|
464
|
+
animal: {
|
|
465
|
+
type: "string",
|
|
466
|
+
oneOf: [
|
|
467
|
+
{ const: "cat", title: "Cat" },
|
|
468
|
+
{ const: "fish", title: "Fish" },
|
|
469
|
+
{ const: "dog", title: "Dog" },
|
|
470
|
+
],
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
allOf: [
|
|
474
|
+
{
|
|
475
|
+
if: {
|
|
476
|
+
properties: {
|
|
477
|
+
animal: {
|
|
478
|
+
const: "cat",
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
then: {
|
|
483
|
+
properties: {
|
|
484
|
+
food: {
|
|
485
|
+
type: "string",
|
|
486
|
+
enum: ["meat", "grass", "fish"],
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
required: ["food"],
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
if: {
|
|
494
|
+
properties: {
|
|
495
|
+
animal: {
|
|
496
|
+
const: "fish",
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
then: {
|
|
501
|
+
properties: {
|
|
502
|
+
food: {
|
|
503
|
+
type: "string",
|
|
504
|
+
enum: ["insect", "worms"],
|
|
505
|
+
},
|
|
506
|
+
water: {
|
|
507
|
+
type: "string",
|
|
508
|
+
enum: ["lake", "sea"],
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
required: ["food", "water"],
|
|
512
|
+
},
|
|
513
|
+
else: {
|
|
514
|
+
properties: {
|
|
515
|
+
likesWalkiesWhere: {
|
|
516
|
+
type: "string",
|
|
517
|
+
enum: ["park", "forest", "garden"],
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
{
|
|
524
|
+
required: ["animal"],
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
};
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Ordering fields
|
|
531
|
+
|
|
532
|
+
The order of fields can be set using `"ui:order": ["fieldName"]` inside the uiSchema.
|
|
533
|
+
If using "ui:order", all fields that should be visible in the form need to be included in the given array.
|
|
534
|
+
|
|
535
|
+
```tsx
|
|
536
|
+
const schema = {
|
|
537
|
+
properties: {
|
|
538
|
+
secondField: { type: "string" },
|
|
539
|
+
firstField: { type: "string" },
|
|
540
|
+
thirdField: { type: "string" },
|
|
541
|
+
},
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
const uiSchema = {
|
|
545
|
+
"ui:order": ["firstField", "secondField", "thirdField"],
|
|
546
|
+
};
|
|
547
|
+
```
|
|
548
|
+
|
|
456
549
|
## Props
|
|
457
550
|
|
|
458
551
|
`Form` component props:
|
package/dist/Form.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { FormProps, FormRegistryContextValue } from "./types";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import { FormProps, FormRegistryContextValue } from "./types";
|
|
3
3
|
export declare const FormRegistry: React.Context<FormRegistryContextValue>;
|
|
4
|
-
export declare
|
|
4
|
+
export declare const Form: <T>(props: FormProps<T>) => import("react/jsx-runtime").JSX.Element;
|
package/dist/Form.js
CHANGED
|
@@ -14,7 +14,7 @@ export const FormRegistry = React.createContext({
|
|
|
14
14
|
useItemsAsAdditionalItems: false,
|
|
15
15
|
hideUnmarkedAdditionalProperties: false,
|
|
16
16
|
});
|
|
17
|
-
export
|
|
17
|
+
export const Form = (props) => {
|
|
18
18
|
warnFromUnsupportedKeys("Form", props, [
|
|
19
19
|
"schema",
|
|
20
20
|
"onSubmit",
|
|
@@ -40,6 +40,6 @@ export function Form(props) {
|
|
|
40
40
|
hideUnmarkedAdditionalProperties,
|
|
41
41
|
};
|
|
42
42
|
const { Form: FormEl, FormButton, FormButtonWrapper } = registry.components;
|
|
43
|
-
const
|
|
44
|
-
return (_jsx(FormRegistry.Provider,
|
|
45
|
-
}
|
|
43
|
+
const SchemaField = registry.fields.SchemaField;
|
|
44
|
+
return (_jsx(FormRegistry.Provider, { value: registry, children: _jsxs(FormEl, { className: className, children: [_jsx(SchemaField, { name: "", schema: schema, uiSchema: uiSchema }), children ? (children) : (_jsx(FormButtonWrapper, { children: _jsx(FormButton, { type: "submit", disabled: isSubmitting, children: "Send" }) }))] }) }));
|
|
45
|
+
};
|
package/dist/Form.stories.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
1
|
+
import type { StoryObj, Meta } from "@storybook/react";
|
|
3
2
|
import { Form } from "./";
|
|
4
|
-
declare const
|
|
5
|
-
export default
|
|
6
|
-
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
3
|
+
declare const meta: Meta<typeof Form>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Form>;
|
|
6
|
+
export declare const Simple: Story;
|
|
7
|
+
export declare const WithUiSchema: Story;
|
|
8
|
+
export declare const CompleteSchema: Story;
|
|
9
|
+
export declare const StrictlyTyped: () => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const StylesCustomized: () => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const WithGeneratedSchema: Story;
|
|
12
|
+
export declare const WithRequiredInput: Story;
|
|
13
|
+
export declare const WithConditions: Story;
|
package/dist/Form.stories.js
CHANGED
|
@@ -7,14 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
10
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
22
|
import { action } from "@storybook/addon-actions";
|
|
12
23
|
import styled from "styled-components";
|
|
13
24
|
import { Formik, useFormikContext } from "formik";
|
|
14
25
|
import { InfoFieldButton, SearchableMultiTagSelectField, } from "./styledComponents";
|
|
15
|
-
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, } from "./
|
|
26
|
+
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, conditionsSchema, conditionsUiSchema, } from "./sampleData";
|
|
16
27
|
import { Form, styledComponents } from "./";
|
|
17
|
-
|
|
28
|
+
const meta = {
|
|
18
29
|
title: "Form",
|
|
19
30
|
component: Form,
|
|
20
31
|
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
@@ -22,15 +33,20 @@ export default {
|
|
|
22
33
|
schema: { control: { type: "object" } },
|
|
23
34
|
uiSchema: { control: { type: "object" } },
|
|
24
35
|
},
|
|
36
|
+
render: (_a) => {
|
|
37
|
+
var args = __rest(_a, []);
|
|
38
|
+
return (_jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
40
|
+
action("onSubmit(values)")(values);
|
|
41
|
+
formikHelpers.setSubmitting(false);
|
|
42
|
+
}), children: _jsx(Form, Object.assign({}, args)) }));
|
|
43
|
+
},
|
|
25
44
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
export const Simple = Template.bind({});
|
|
32
|
-
Simple.args = {
|
|
33
|
-
schema: simpleSchema,
|
|
45
|
+
export default meta;
|
|
46
|
+
export const Simple = {
|
|
47
|
+
args: {
|
|
48
|
+
schema: simpleSchema,
|
|
49
|
+
},
|
|
34
50
|
};
|
|
35
51
|
const InfoFieldButtonNew = styled(InfoFieldButton) `
|
|
36
52
|
outline: 2px red solid;
|
|
@@ -44,11 +60,12 @@ const InfoFieldButtonNew = styled(InfoFieldButton) `
|
|
|
44
60
|
color: green;
|
|
45
61
|
}
|
|
46
62
|
`;
|
|
47
|
-
export const WithUiSchema =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
export const WithUiSchema = {
|
|
64
|
+
args: {
|
|
65
|
+
schema: simpleSchema,
|
|
66
|
+
uiSchema: simpleUiSchema,
|
|
67
|
+
components: { InfoFieldButton: InfoFieldButtonNew },
|
|
68
|
+
},
|
|
52
69
|
};
|
|
53
70
|
// TODO: get customisable styling to work
|
|
54
71
|
const MyStyledSearchField = styled(SearchableMultiTagSelectField) `
|
|
@@ -59,18 +76,19 @@ const MyStyledSearchField = styled(SearchableMultiTagSelectField) `
|
|
|
59
76
|
background: blue;
|
|
60
77
|
}
|
|
61
78
|
`;
|
|
62
|
-
export const CompleteSchema =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
export const CompleteSchema = {
|
|
80
|
+
args: {
|
|
81
|
+
schema: completeSchema,
|
|
82
|
+
uiSchema: completeUiSchema,
|
|
83
|
+
components: { SearchableMultiTagSelectField: MyStyledSearchField },
|
|
84
|
+
},
|
|
67
85
|
};
|
|
68
86
|
export const StrictlyTyped = () => {
|
|
69
|
-
return (_jsx(Formik,
|
|
87
|
+
return (_jsx(Formik, { initialValues: { firstName: "", lastName: "" }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
88
|
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
71
89
|
action("onSubmit(values)")(values);
|
|
72
90
|
formikHelpers.setSubmitting(false);
|
|
73
|
-
})
|
|
91
|
+
}), children: _jsx(Form, { schema: simpleSchema }) }));
|
|
74
92
|
};
|
|
75
93
|
/*** CUSTOMIZATION ***/
|
|
76
94
|
const CustomizedForm = styled(Form) `
|
|
@@ -92,11 +110,11 @@ const CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator) `
|
|
|
92
110
|
color: aqua;
|
|
93
111
|
`;
|
|
94
112
|
export const StylesCustomized = () => {
|
|
95
|
-
return (_jsx(Formik,
|
|
113
|
+
return (_jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
114
|
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
97
115
|
action("onSubmit(values)")(values);
|
|
98
116
|
formikHelpers.setSubmitting(false);
|
|
99
|
-
})
|
|
117
|
+
}), children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
|
|
100
118
|
age: {
|
|
101
119
|
props: {
|
|
102
120
|
wrapper: {
|
|
@@ -115,13 +133,14 @@ export const StylesCustomized = () => {
|
|
|
115
133
|
FieldWrapper: CustomizedFieldWrapper,
|
|
116
134
|
ErrorMessage: CustomizedErrorMessage,
|
|
117
135
|
RequiredIndicator: CustomizedRequiredIndicator,
|
|
118
|
-
} }) }))
|
|
136
|
+
} }) }));
|
|
119
137
|
};
|
|
120
|
-
export const WithGeneratedSchema =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
export const WithGeneratedSchema = {
|
|
139
|
+
args: {
|
|
140
|
+
schema: generatedSchema,
|
|
141
|
+
uiSchema: {},
|
|
142
|
+
useItemsAsAdditionalItems: true,
|
|
143
|
+
},
|
|
125
144
|
};
|
|
126
145
|
// Test to add style to RadioButtonField and ToggleSwitchField
|
|
127
146
|
// const MyRadioButtonField = styled(RadioButtonField)`
|
|
@@ -147,12 +166,20 @@ WithGeneratedSchema.args = {
|
|
|
147
166
|
// background: pink;
|
|
148
167
|
// }
|
|
149
168
|
// `;
|
|
150
|
-
export const WithRequiredInput =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
169
|
+
export const WithRequiredInput = {
|
|
170
|
+
args: {
|
|
171
|
+
schema: requiredInputSchema,
|
|
172
|
+
uiSchema: requiredInputUiSchema,
|
|
173
|
+
// components: {
|
|
174
|
+
// RadioButtonField: MyRadioButtonField,
|
|
175
|
+
// ToggleSwitchField: MyToggleSwitchField,
|
|
176
|
+
// },
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
export const WithConditions = {
|
|
180
|
+
args: {
|
|
181
|
+
schema: conditionsSchema,
|
|
182
|
+
uiSchema: conditionsUiSchema,
|
|
183
|
+
hideUnmarkedAdditionalProperties: true,
|
|
184
|
+
},
|
|
158
185
|
};
|
package/dist/Form.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, screen } from "@testing-library/react";
|
|
3
3
|
import { Form } from "./Form";
|
|
4
|
-
import { simpleSchema } from "./
|
|
4
|
+
import { simpleSchema } from "./sampleData";
|
|
5
5
|
test("renders title", () => {
|
|
6
6
|
render(_jsx(Form, { schema: simpleSchema }));
|
|
7
7
|
const titleElement = screen.getByText(/TITLE/i);
|
package/dist/FormEditor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import type { Schema, UiSchema } from "./types";
|
|
2
|
+
import React from "react";
|
|
3
3
|
export type FormEditorProps = {};
|
|
4
4
|
export type FormEditorValues = {
|
|
5
5
|
schema: Schema;
|
|
6
6
|
uiSchema: UiSchema;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
8
|
+
export declare const FormEditor: React.FC<FormEditorProps>;
|
package/dist/FormEditor.js
CHANGED
|
@@ -8,22 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { Formik } from "formik";
|
|
12
11
|
import { useEffect, useState } from "react";
|
|
12
|
+
import { Formik } from "formik";
|
|
13
13
|
import { Form } from "./Form";
|
|
14
14
|
import * as formEditorSchemas from "./formEditorSchemas";
|
|
15
|
-
export
|
|
15
|
+
export const FormEditor = (props) => {
|
|
16
16
|
const [editorGeneratedSchemas, setEditorGeneratedSchemas] = useState({
|
|
17
17
|
schema: {},
|
|
18
18
|
uiSchema: {},
|
|
19
19
|
});
|
|
20
20
|
useEffect(() => console.log(editorGeneratedSchemas), [editorGeneratedSchemas]);
|
|
21
|
-
return (_jsxs("div",
|
|
21
|
+
return (_jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [_jsxs("div", { children: [_jsx("h1", { children: "Editor" }), _jsx(Formik, { initialValues: { schema: {}, uiSchema: {} }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
setEditorGeneratedSchemas(values);
|
|
23
23
|
formikHelpers.setSubmitting(false);
|
|
24
|
-
})
|
|
24
|
+
}), children: _jsx(Form, Object.assign({}, formEditorSchemas)) })] }), _jsxs("div", { children: [_jsx("h1", { children: "Preview" }), _jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
// action("onSubmit(_, formHelper)")(formikHelpers);
|
|
26
26
|
// action("onSubmit(values)")(values);
|
|
27
27
|
formikHelpers.setSubmitting(false);
|
|
28
|
-
})
|
|
29
|
-
}
|
|
28
|
+
}), children: _jsx(Form, Object.assign({}, editorGeneratedSchemas)) })] })] }));
|
|
29
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StoryObj, Meta } from "@storybook/react";
|
|
2
2
|
import { FormEditor } from "./FormEditor";
|
|
3
|
-
declare const
|
|
4
|
-
export default
|
|
5
|
-
|
|
3
|
+
declare const meta: Meta<typeof FormEditor>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof FormEditor>;
|
|
6
|
+
export declare const Default: Story;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { FormEditor } from "./FormEditor";
|
|
3
|
-
|
|
2
|
+
const meta = {
|
|
4
3
|
title: "FormEditor",
|
|
5
4
|
component: FormEditor,
|
|
6
5
|
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
7
6
|
argTypes: {},
|
|
8
7
|
};
|
|
9
|
-
|
|
10
|
-
export const Default =
|
|
11
|
-
Default.args = {};
|
|
8
|
+
export default meta;
|
|
9
|
+
export const Default = {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const AnyField: React.FC<FieldProps>;
|
package/dist/fields/AnyField.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useState } from "react";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
4
3
|
import { useField } from "formik";
|
|
5
|
-
import { SchemaField } from "./SchemaField";
|
|
6
4
|
import { guessType } from "../utils";
|
|
5
|
+
import { SchemaField } from "./SchemaField";
|
|
7
6
|
import { COMPONENT_TYPES } from "./types";
|
|
8
|
-
export
|
|
7
|
+
export const AnyField = (props) => {
|
|
9
8
|
const { name, schema, uiSchema } = props;
|
|
10
9
|
const [{ value }] = useField(name);
|
|
11
10
|
const [type, setType] = useState(value !== undefined ? guessType(value) : "string");
|
|
@@ -19,5 +18,5 @@ export function AnyField(props) {
|
|
|
19
18
|
return Object.assign(Object.assign({}, (schema || {})), { type });
|
|
20
19
|
}
|
|
21
20
|
}, [type, schema]);
|
|
22
|
-
return (_jsxs("div", { children: [_jsx("select",
|
|
23
|
-
}
|
|
21
|
+
return (_jsxs("div", { children: [_jsx("select", { value: type, onChange: (event) => setType(event.target.value), children: Object.keys(COMPONENT_TYPES).map((type) => (_jsx("option", { value: type, children: type }, type))) }), _jsx(SchemaField, { name: name, schema: enrichedSchema, uiSchema: uiSchema })] }));
|
|
22
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const ArrayField: React.FC<FieldProps>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useMemo } from "react";
|
|
3
|
-
import { FormRegistry } from "../Form";
|
|
4
3
|
import { useField } from "formik";
|
|
4
|
+
import { FormRegistry } from "../Form";
|
|
5
5
|
import { ArrayFieldButtonPurpose } from "../types";
|
|
6
|
-
import { useExtractUiSchema, useSetDefault } from "../
|
|
6
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
7
7
|
import { GetArrayFieldButton } from "../styledComponents";
|
|
8
|
-
|
|
8
|
+
const appendArray = (values) => {
|
|
9
9
|
return values ? [...values, ""] : [""];
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
};
|
|
11
|
+
const removeFromArray = (values, index) => {
|
|
12
12
|
return [...values.slice(0, index), ...values.slice(index + 1)];
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
};
|
|
14
|
+
const moveInArray = (values, index, direction) => {
|
|
15
15
|
if (direction === -1) {
|
|
16
16
|
return [
|
|
17
17
|
...values.slice(0, index - 1),
|
|
@@ -28,8 +28,8 @@ function moveInArray(values, index, direction) {
|
|
|
28
28
|
...values.slice(index + 2),
|
|
29
29
|
];
|
|
30
30
|
}
|
|
31
|
-
}
|
|
32
|
-
export
|
|
31
|
+
};
|
|
32
|
+
export const ArrayField = (props) => {
|
|
33
33
|
const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem, ArrayFieldList, ArrayFieldItemButtons }, useItemsAsAdditionalItems, } = useContext(FormRegistry);
|
|
34
34
|
useSetDefault(props);
|
|
35
35
|
const { name, schema, uiSchema } = props;
|
|
@@ -117,4 +117,4 @@ export function ArrayField(props) {
|
|
|
117
117
|
onClick: () => setValue(appendArray(value)),
|
|
118
118
|
uiSchema,
|
|
119
119
|
})] })));
|
|
120
|
-
}
|
|
120
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const BooleanField: React.FC<FieldProps>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormRegistry } from "../Form";
|
|
4
|
-
import { useExtractUiSchema, useSetDefault } from "../
|
|
5
|
-
export
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
+
export const BooleanField = (props) => {
|
|
6
6
|
const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
|
|
7
7
|
useSetDefault(props);
|
|
8
8
|
const { name, uiSchema } = props;
|
|
9
9
|
const { label, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
10
|
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsxs(_Fragment, { children: [_jsx(FieldInput, Object.assign({}, inputProps, { name: name, type: "checkbox" })), label] }) })));
|
|
11
|
-
}
|
|
11
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const DateField: React.FC<FieldProps>;
|
package/dist/fields/DateField.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormRegistry } from "../Form";
|
|
4
|
-
import { useExtractUiSchema, useSetDefault } from "../
|
|
5
|
-
export
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
+
export const DateField = (props) => {
|
|
6
6
|
const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
|
|
7
7
|
useSetDefault(props);
|
|
8
8
|
const { name, uiSchema } = props;
|
|
9
9
|
const { props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
10
|
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(FieldInput, Object.assign({}, inputProps, { name: name, type: "date" })) })));
|
|
11
|
-
}
|
|
11
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const NullField: React.FC<FieldProps>;
|
package/dist/fields/NullField.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormRegistry } from "../Form";
|
|
4
|
-
export
|
|
4
|
+
export const NullField = (props) => {
|
|
5
5
|
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
6
6
|
const { name } = props;
|
|
7
7
|
return _jsx(FieldTemplate, Object.assign({}, props));
|
|
8
|
-
}
|
|
8
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const NumberField: React.FC<FieldProps>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { StringField } from "./StringField";
|
|
3
|
-
export
|
|
3
|
+
export const NumberField = (props) => {
|
|
4
4
|
var _a;
|
|
5
5
|
return (_jsx(StringField, Object.assign({}, props, { uiSchema: Object.assign(Object.assign({}, props.uiSchema), { "ui:props": Object.assign(Object.assign({}, (((_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:props"]) || {})), { type: "number" }) }) })));
|
|
6
|
-
}
|
|
6
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const ObjectField: React.FC<FieldProps>;
|