@nolwenture/formik-jsonschema-form 0.23.3 → 0.25.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/dist/Form.stories.d.ts +1 -0
- package/dist/Form.stories.js +4 -0
- package/dist/FormPdf.d.ts +6 -0
- package/dist/FormPdf.js +48 -0
- package/dist/FormPdf.stories.d.ts +11 -0
- package/dist/FormPdf.stories.js +148 -0
- package/dist/FormPdf.test.d.ts +1 -0
- package/dist/FormPdf.test.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pdfFields/AnyField.d.ts +3 -0
- package/dist/pdfFields/AnyField.js +22 -0
- package/dist/pdfFields/ArrayField.d.ts +3 -0
- package/dist/pdfFields/ArrayField.js +41 -0
- package/dist/pdfFields/BooleanField.d.ts +3 -0
- package/dist/pdfFields/BooleanField.js +27 -0
- package/dist/pdfFields/DateField.d.ts +3 -0
- package/dist/pdfFields/DateField.js +16 -0
- package/dist/pdfFields/EJSField.d.ts +3 -0
- package/dist/pdfFields/EJSField.js +24 -0
- package/dist/pdfFields/MultipleChoiceField.d.ts +3 -0
- package/dist/pdfFields/MultipleChoiceField.js +20 -0
- package/dist/pdfFields/NullField.d.ts +3 -0
- package/dist/pdfFields/NullField.js +8 -0
- package/dist/pdfFields/NumberField.d.ts +3 -0
- package/dist/pdfFields/NumberField.js +6 -0
- package/dist/pdfFields/ObjectField.d.ts +3 -0
- package/dist/pdfFields/ObjectField.js +59 -0
- package/dist/pdfFields/RadioField.d.ts +3 -0
- package/dist/pdfFields/RadioField.js +6 -0
- package/dist/pdfFields/SchemaField.d.ts +3 -0
- package/dist/pdfFields/SchemaField.js +31 -0
- package/dist/pdfFields/SearchMultiTagSelectField.d.ts +3 -0
- package/dist/pdfFields/SearchMultiTagSelectField.js +14 -0
- package/dist/pdfFields/SearchableSelectField.d.ts +3 -0
- package/dist/pdfFields/SearchableSelectField.js +9 -0
- package/dist/pdfFields/StringField.d.ts +3 -0
- package/dist/pdfFields/StringField.js +27 -0
- package/dist/pdfFields/TextAreaField.d.ts +3 -0
- package/dist/pdfFields/TextAreaField.js +13 -0
- package/dist/pdfFields/ToggleField.d.ts +3 -0
- package/dist/pdfFields/ToggleField.js +6 -0
- package/dist/pdfFields/index.d.ts +16 -0
- package/dist/pdfFields/index.js +16 -0
- package/dist/pdfFields/types.d.ts +10 -0
- package/dist/pdfFields/types.js +10 -0
- package/dist/pdfTemplates/ArrayFieldTemplate.d.ts +3 -0
- package/dist/pdfTemplates/ArrayFieldTemplate.js +16 -0
- package/dist/pdfTemplates/CollapsibleObjectFieldTemplate.d.ts +3 -0
- package/dist/pdfTemplates/CollapsibleObjectFieldTemplate.js +20 -0
- package/dist/pdfTemplates/FieldTemplate.d.ts +3 -0
- package/dist/pdfTemplates/FieldTemplate.js +15 -0
- package/dist/pdfTemplates/ObjectFieldTemplate.d.ts +3 -0
- package/dist/pdfTemplates/ObjectFieldTemplate.js +18 -0
- package/dist/pdfTemplates/index.d.ts +4 -0
- package/dist/pdfTemplates/index.js +4 -0
- package/dist/sampleData/completeSchema.d.ts +1 -0
- package/dist/sampleData/completeSchema.js +23 -2
- package/dist/sampleData/ejsSchema.d.ts +6 -0
- package/dist/sampleData/ejsSchema.js +25 -0
- package/dist/sampleData/multipleChoiceSchema.d.ts +6 -0
- package/dist/sampleData/multipleChoiceSchema.js +8 -1
- package/dist/sampleData/pdfProExampleSchema.d.ts +21 -0
- package/dist/sampleData/pdfProExampleSchema.js +185 -0
- package/dist/sampleData/simpleData.js +1 -0
- package/dist/styledComponents.d.ts +12 -1
- package/dist/styledComponents.js +55 -0
- package/dist/types.d.ts +26 -0
- package/dist/utils/__tests/createValidationSchema.test.js +208 -20
- package/dist/utils/__tests/hasReferences.test.d.ts +1 -0
- package/dist/utils/__tests/hasReferences.test.js +100 -0
- package/dist/utils/createValidationSchema.js +23 -4
- package/dist/utils/getEnums.d.ts +13 -0
- package/dist/utils/getEnums.js +12 -0
- package/dist/utils/hasReferences.d.ts +2 -0
- package/dist/utils/hasReferences.js +12 -0
- package/package.json +2 -1
package/dist/Form.stories.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ export declare const WithConditions: Story;
|
|
|
14
14
|
export declare const WithRefAndDefinitions: Story;
|
|
15
15
|
export declare const MultipleChoice: Story;
|
|
16
16
|
export declare const Collapsible: Story;
|
|
17
|
+
export declare const proExample: Story;
|
|
17
18
|
export declare const FileUploadForm: Story;
|
|
18
19
|
export declare const HideSubmitButton: Story;
|
package/dist/Form.stories.js
CHANGED
|
@@ -25,6 +25,7 @@ import { Formik, useFormikContext } from "formik";
|
|
|
25
25
|
import { InfoFieldButton, SearchableMultiTagSelectField, } from "./styledComponents";
|
|
26
26
|
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, requiredInputUiSchema, conditionsSchema, conditionsUiSchema, refDefSchema, refDefUiSchema, multipleChoiceSchema, multipleChoiceUiSchema, collapsibleSchema, collapsibleUiSchema, } from "./sampleData";
|
|
27
27
|
import { Form, styledComponents } from "./";
|
|
28
|
+
import { pdfProExampleSchema, pdfProExampleUiSchema, } from "./sampleData/pdfProExampleSchema";
|
|
28
29
|
import { fileUploadSchema, fileUploadUiSchema } from "./sampleData/fileUpload";
|
|
29
30
|
import { FileUploadContext } from "./FileUploadContext";
|
|
30
31
|
import { mockFetchFile, mockRemoveFile, mockUploadFile, } from "./fields/stories/FileUploadField.stories";
|
|
@@ -226,6 +227,9 @@ export const Collapsible = {
|
|
|
226
227
|
uiSchema: collapsibleUiSchema,
|
|
227
228
|
},
|
|
228
229
|
};
|
|
230
|
+
export const proExample = {
|
|
231
|
+
args: { schema: pdfProExampleSchema, uiSchema: pdfProExampleUiSchema },
|
|
232
|
+
};
|
|
229
233
|
export const FileUploadForm = {
|
|
230
234
|
args: {
|
|
231
235
|
schema: fileUploadSchema,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FormProps, FormRegistryContextValue, FormValues } from "./types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const FormPdfRegistry: React.Context<FormRegistryContextValue>;
|
|
4
|
+
export declare const FormPdf: <T>(props: FormProps<T> & {
|
|
5
|
+
values: FormValues;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
package/dist/FormPdf.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import * as defaultComponents from "./styledComponents";
|
|
4
|
+
import { warnFromUnsupportedKeys } from "./utils";
|
|
5
|
+
import * as defaultFields from "./pdfFields";
|
|
6
|
+
import * as defaultTemplates from "./pdfTemplates";
|
|
7
|
+
export const FormPdfRegistry = React.createContext({
|
|
8
|
+
fields: defaultFields,
|
|
9
|
+
templates: defaultTemplates,
|
|
10
|
+
components: defaultComponents,
|
|
11
|
+
definitions: {},
|
|
12
|
+
uiSchemaDefinitions: {},
|
|
13
|
+
formContext: {},
|
|
14
|
+
useItemsAsAdditionalItems: false,
|
|
15
|
+
hideUnmarkedAdditionalProperties: false,
|
|
16
|
+
});
|
|
17
|
+
export const FormPdf = (props) => {
|
|
18
|
+
warnFromUnsupportedKeys("Form", props, [
|
|
19
|
+
"schema",
|
|
20
|
+
"onSubmit",
|
|
21
|
+
"uiSchema",
|
|
22
|
+
"className",
|
|
23
|
+
"formData",
|
|
24
|
+
"className",
|
|
25
|
+
"children",
|
|
26
|
+
"fields",
|
|
27
|
+
"formContext",
|
|
28
|
+
"components",
|
|
29
|
+
"hideUnmarkedAdditionalProperties",
|
|
30
|
+
"values",
|
|
31
|
+
]);
|
|
32
|
+
const { schema, uiSchema = {}, className, fields = {}, templates = {}, components = {}, formContext = {}, useItemsAsAdditionalItems = false, hideUnmarkedAdditionalProperties = false, values = {}, } = props;
|
|
33
|
+
const schemaDefinitions = schema.definitions;
|
|
34
|
+
const uiSchemaDefinitions = uiSchema.definitions;
|
|
35
|
+
const registry = {
|
|
36
|
+
fields: Object.assign(Object.assign({}, defaultFields), fields),
|
|
37
|
+
templates: Object.assign(Object.assign({}, defaultTemplates), templates),
|
|
38
|
+
components: Object.assign(Object.assign({}, defaultComponents), components),
|
|
39
|
+
definitions: schemaDefinitions,
|
|
40
|
+
uiSchemaDefinitions,
|
|
41
|
+
formContext,
|
|
42
|
+
useItemsAsAdditionalItems,
|
|
43
|
+
hideUnmarkedAdditionalProperties,
|
|
44
|
+
};
|
|
45
|
+
const { Form: FormEl } = registry.components;
|
|
46
|
+
const SchemaField = registry.fields.SchemaField;
|
|
47
|
+
return (_jsx(FormPdfRegistry.Provider, { value: registry, children: _jsx(FormEl, { className: className, children: _jsx(SchemaField, { name: "", schema: schema, uiSchema: uiSchema, values: values }) }) }));
|
|
48
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from "@storybook/react";
|
|
2
|
+
import { FormPdf } from "./";
|
|
3
|
+
declare const meta: Meta<typeof FormPdf>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof FormPdf>;
|
|
6
|
+
export declare const SimplePdf: Story;
|
|
7
|
+
export declare const CompletePdfSchema: Story;
|
|
8
|
+
export declare const StylesCustomized: () => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const ProExamplePdf: Story;
|
|
10
|
+
export declare const EJSTest: Story;
|
|
11
|
+
export declare const MultiChoice: Story;
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
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
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import { action } from "@storybook/addon-actions";
|
|
23
|
+
import { Formik } from "formik";
|
|
24
|
+
import { completeSchema, completeUiSchema, multipleChoiceSchema, multipleChoiceUiSchema, multipleChoiceValue, simpleSchema, } from "./sampleData";
|
|
25
|
+
import { FormPdf, styledComponents } from "./";
|
|
26
|
+
import { StringFieldPdf } from "./styledComponents";
|
|
27
|
+
import { styled } from "styled-components";
|
|
28
|
+
import { pdfProExampleData, pdfProExampleSchema, pdfProExampleUiSchema, } from "./sampleData/pdfProExampleSchema";
|
|
29
|
+
import { ejsSchema, ejsTestValues, ejsUiSchema } from "./sampleData/ejsSchema";
|
|
30
|
+
const meta = {
|
|
31
|
+
title: "FormPdf",
|
|
32
|
+
component: FormPdf,
|
|
33
|
+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
34
|
+
argTypes: {
|
|
35
|
+
schema: { control: { type: "object" } },
|
|
36
|
+
uiSchema: { control: { type: "object" } },
|
|
37
|
+
values: {},
|
|
38
|
+
},
|
|
39
|
+
render: (_a) => {
|
|
40
|
+
var args = __rest(_a, []);
|
|
41
|
+
return (_jsx(Formik, { initialValues: args.values, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
43
|
+
action("onSubmit(values)")(values);
|
|
44
|
+
formikHelpers.setSubmitting(false);
|
|
45
|
+
}), children: _jsx(FormPdf, Object.assign({}, args)) }));
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
export default meta;
|
|
49
|
+
export const SimplePdf = {
|
|
50
|
+
args: {
|
|
51
|
+
schema: simpleSchema,
|
|
52
|
+
uiSchema: {},
|
|
53
|
+
values: { firstName: "Doro", lastName: "Heck", age: 31, pet: "dog" },
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
export const CompletePdfSchema = {
|
|
57
|
+
args: {
|
|
58
|
+
schema: completeSchema,
|
|
59
|
+
uiSchema: completeUiSchema,
|
|
60
|
+
values: {
|
|
61
|
+
string: "This is a string value",
|
|
62
|
+
number: 123,
|
|
63
|
+
date: "2024-09-13",
|
|
64
|
+
boolean: true,
|
|
65
|
+
enum: 3,
|
|
66
|
+
enumOneOf: 4,
|
|
67
|
+
enumAnyOf: [1, 3],
|
|
68
|
+
enumTagSelectAnyOf: ["dog", "cat"],
|
|
69
|
+
searchableSelect: "hamster",
|
|
70
|
+
array: ["First field", "Second field"],
|
|
71
|
+
partiallyFixedArray: ["Hello", "To you"],
|
|
72
|
+
enumArray: [2, 4],
|
|
73
|
+
nested: { string: "This is a string inside a nested object" },
|
|
74
|
+
objectArray: [
|
|
75
|
+
{
|
|
76
|
+
string: "this is a string in an object in an array",
|
|
77
|
+
number: 1,
|
|
78
|
+
date: "2020-09-20",
|
|
79
|
+
boolean: false,
|
|
80
|
+
enum: [3],
|
|
81
|
+
enumWithTitle: 2,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
textArea: "This is a little longer text, but not really that long. Just a little longer to test out this text area.",
|
|
85
|
+
radio: true,
|
|
86
|
+
toggle: false,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
/*** CUSTOMIZATION ***/
|
|
91
|
+
const CustomizedForm = styled(FormPdf) `
|
|
92
|
+
${styledComponents.FieldTitle} {
|
|
93
|
+
color: red;
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
const CustomizedFieldWrapper = styled.div `
|
|
97
|
+
outline: 2px solid
|
|
98
|
+
${(props) => (props.title === "ABC" ? "blue" : "transparent")};
|
|
99
|
+
`;
|
|
100
|
+
const CustomizedStringFieldPdf = styled(StringFieldPdf) `
|
|
101
|
+
color: purple;
|
|
102
|
+
`;
|
|
103
|
+
export const StylesCustomized = () => {
|
|
104
|
+
return (_jsx(Formik, { initialValues: { firstName: "Doro", lastName: "Heck", age: 31 }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
action("onSubmit(_, formHelper)")(formikHelpers);
|
|
106
|
+
action("onSubmit(values)")(values);
|
|
107
|
+
formikHelpers.setSubmitting(false);
|
|
108
|
+
}), children: _jsx(CustomizedForm, { schema: simpleSchema, uiSchema: {
|
|
109
|
+
age: {
|
|
110
|
+
props: {
|
|
111
|
+
wrapper: {
|
|
112
|
+
title: "ABC",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
firstName: {
|
|
117
|
+
props: {
|
|
118
|
+
wrapper: {
|
|
119
|
+
title: "ABC",
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
}, components: {
|
|
124
|
+
FieldWrapper: CustomizedFieldWrapper,
|
|
125
|
+
StringFieldPdf: CustomizedStringFieldPdf,
|
|
126
|
+
}, values: { firstName: "Doro", lastName: "Heck", age: 31 } }) }));
|
|
127
|
+
};
|
|
128
|
+
export const ProExamplePdf = {
|
|
129
|
+
args: {
|
|
130
|
+
schema: pdfProExampleSchema,
|
|
131
|
+
uiSchema: pdfProExampleUiSchema,
|
|
132
|
+
values: pdfProExampleData,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
export const EJSTest = {
|
|
136
|
+
args: {
|
|
137
|
+
schema: ejsSchema,
|
|
138
|
+
uiSchema: ejsUiSchema,
|
|
139
|
+
values: ejsTestValues,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
export const MultiChoice = {
|
|
143
|
+
args: {
|
|
144
|
+
schema: multipleChoiceSchema,
|
|
145
|
+
uiSchema: multipleChoiceUiSchema,
|
|
146
|
+
values: multipleChoiceValue,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import "@testing-library/jest-dom";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { Formik } from "formik";
|
|
5
|
+
import { FormPdf } from "./FormPdf";
|
|
6
|
+
import { simpleSchema } from "./sampleData";
|
|
7
|
+
test("renders title", () => {
|
|
8
|
+
render(_jsx(Formik, { initialValues: { firstName: "Lisa" }, onSubmit: () => { }, children: _jsx(FormPdf, { schema: simpleSchema, values: { firstName: "Lisa" } }) }));
|
|
9
|
+
const titleElement = screen.getByText(/TITLE/i);
|
|
10
|
+
const valueElement = screen.getByText("Lisa");
|
|
11
|
+
expect(titleElement).toBeInTheDocument();
|
|
12
|
+
expect(valueElement).toBeInTheDocument();
|
|
13
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { useField } from "formik";
|
|
4
|
+
import { guessType } from "../utils";
|
|
5
|
+
import { SchemaField } from "./SchemaField";
|
|
6
|
+
import { COMPONENT_TYPES } from "./types";
|
|
7
|
+
export const AnyField = (props) => {
|
|
8
|
+
const { name, schema, uiSchema } = props;
|
|
9
|
+
const [{ value }] = useField(name);
|
|
10
|
+
const [type, setType] = useState(value !== undefined ? guessType(value) : "string");
|
|
11
|
+
const enrichedSchema = useMemo(() => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case "object":
|
|
14
|
+
return Object.assign(Object.assign({}, (schema || {})), { type, additionalProperties: {} });
|
|
15
|
+
case "array":
|
|
16
|
+
return Object.assign(Object.assign({}, (schema || {})), { type, additionalItems: {} });
|
|
17
|
+
default:
|
|
18
|
+
return Object.assign(Object.assign({}, (schema || {})), { type });
|
|
19
|
+
}
|
|
20
|
+
}, [type, schema]);
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useField, useFormikContext } from "formik";
|
|
3
|
+
import { useContext, useMemo } from "react";
|
|
4
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
5
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
6
|
+
import { getEnums } from "../utils";
|
|
7
|
+
import { styled } from "styled-components";
|
|
8
|
+
const ArrayFieldPdf = styled.div ``;
|
|
9
|
+
export const ArrayField = (props) => {
|
|
10
|
+
const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem, ArrayFieldList }, useItemsAsAdditionalItems, } = useContext(FormPdfRegistry);
|
|
11
|
+
useSetDefault(props);
|
|
12
|
+
const { name, schema, uiSchema } = props;
|
|
13
|
+
const { type, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
14
|
+
const [{ value }, _, { setValue }] = useField(name);
|
|
15
|
+
const { items } = useMemo(() => {
|
|
16
|
+
let items = schema.items && typeof schema.items !== "boolean" ? schema.items : [];
|
|
17
|
+
if (!Array.isArray(items)) {
|
|
18
|
+
items = [items];
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
items: items.filter((item) => typeof item !== "boolean"),
|
|
22
|
+
};
|
|
23
|
+
}, [schema]);
|
|
24
|
+
const { disabled } = useExtractUiSchema(uiSchema);
|
|
25
|
+
const { values } = useFormikContext();
|
|
26
|
+
const findEnumInProps = props.schema.additionalItems
|
|
27
|
+
? { schema: props.schema.additionalItems }
|
|
28
|
+
: props;
|
|
29
|
+
const enums = useMemo(() => getEnums(findEnumInProps), [props]);
|
|
30
|
+
function getValue(item) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
if (enums !== undefined) {
|
|
33
|
+
return ((_b = (_a = enums.values.find((element) => element.const === item)) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : "");
|
|
34
|
+
}
|
|
35
|
+
return item;
|
|
36
|
+
}
|
|
37
|
+
return (_jsx(ArrayFieldTemplate, Object.assign({}, props, { children: value &&
|
|
38
|
+
value.map((item, index) => typeof item === "object" ? (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: `${name}[${index}]`, schema: typeof props.schema.additionalItems !== "boolean"
|
|
39
|
+
? props.schema.additionalItems
|
|
40
|
+
: {}, uiSchema: uiSchema }) }, index)) : (_jsx(ArrayFieldItem, { children: _jsx("div", { "data-keyword": item, children: getValue(item) }) }, item))) })));
|
|
41
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
+
import { useFormikContext } from "formik";
|
|
6
|
+
export const BooleanField = (props) => {
|
|
7
|
+
const { templates: { FieldTemplate }, components: { BooleanFieldPdf, BooleanFieldWrapper }, } = useContext(FormPdfRegistry);
|
|
8
|
+
useSetDefault(props);
|
|
9
|
+
const { name, uiSchema } = props;
|
|
10
|
+
const { label, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
11
|
+
const { values } = useFormikContext();
|
|
12
|
+
const value = values[name];
|
|
13
|
+
function findLabel(label) {
|
|
14
|
+
if (typeof label === "object" && label !== null) {
|
|
15
|
+
switch (value) {
|
|
16
|
+
case true:
|
|
17
|
+
return label.true;
|
|
18
|
+
case false:
|
|
19
|
+
return label.false;
|
|
20
|
+
case undefined:
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return typeof label === "string" ? label : undefined;
|
|
25
|
+
}
|
|
26
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(BooleanFieldWrapper, { children: _jsx(BooleanFieldPdf, { name: name, value: value, label: findLabel(label) }) }) })));
|
|
27
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
+
import { useFormikContext } from "formik";
|
|
6
|
+
import { styled } from "styled-components";
|
|
7
|
+
const DateFieldPdf = styled.div ``;
|
|
8
|
+
export const DateField = (props) => {
|
|
9
|
+
const { templates: { FieldTemplate }, components: {}, } = useContext(FormPdfRegistry);
|
|
10
|
+
useSetDefault(props);
|
|
11
|
+
const { name, uiSchema } = props;
|
|
12
|
+
const { values } = useFormikContext();
|
|
13
|
+
const { props: inputProps } = useExtractUiSchema(uiSchema);
|
|
14
|
+
const value = values[name];
|
|
15
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(DateFieldPdf, { children: value }) })));
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { useSetDefault } from "../hooks";
|
|
4
|
+
import ejs from "ejs";
|
|
5
|
+
import { useFormikContext } from "formik";
|
|
6
|
+
import { getDescription, getTitle } from "../utils";
|
|
7
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
8
|
+
export const EJSField = (props) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const { components: { EJSField }, } = useContext(FormPdfRegistry);
|
|
11
|
+
useSetDefault(props);
|
|
12
|
+
const { name, uiSchema = {} } = props;
|
|
13
|
+
const { values } = useFormikContext();
|
|
14
|
+
const title = getTitle(props);
|
|
15
|
+
const description = getDescription(props);
|
|
16
|
+
const template = (_b = (_a = uiSchema["ui:options"]) === null || _a === void 0 ? void 0 : _a.template) !== null && _b !== void 0 ? _b : "";
|
|
17
|
+
return (_jsx(EJSField, { dangerouslySetInnerHTML: {
|
|
18
|
+
__html: ejs.render(template.toString(), {
|
|
19
|
+
title,
|
|
20
|
+
description,
|
|
21
|
+
value: values[name],
|
|
22
|
+
}),
|
|
23
|
+
} }));
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
+
import { getEnums, getSelectedEnum } from "../utils/getEnums";
|
|
6
|
+
import { getIn, useFormikContext } from "formik";
|
|
7
|
+
export const MultipleChoiceField = (props) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const { templates: { FieldTemplate }, components: { MultipleChoiceFieldPdf }, } = useContext(FormPdfRegistry);
|
|
10
|
+
useSetDefault(props);
|
|
11
|
+
const { name, uiSchema } = props;
|
|
12
|
+
const { props: inputProps, style, onlyShowSelected, } = useExtractUiSchema(uiSchema);
|
|
13
|
+
const enums = useMemo(() => getEnums(props), [props]);
|
|
14
|
+
const { values } = useFormikContext();
|
|
15
|
+
const value = getIn(values, name);
|
|
16
|
+
const selected = getSelectedEnum(value, enums);
|
|
17
|
+
const notSelected = (_a = enums === null || enums === void 0 ? void 0 : enums.values) === null || _a === void 0 ? void 0 : _a.filter((v) => Array.isArray(value) && !value.includes(v));
|
|
18
|
+
const hideNotSelected = onlyShowSelected === true || selected === undefined;
|
|
19
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(MultipleChoiceFieldPdf, { inputProps: inputProps, name: name, style: style, selected: selected, notSelected: hideNotSelected ? undefined : notSelected }) })));
|
|
20
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { FormRegistry } from "../Form";
|
|
4
|
+
export const NullField = (props) => {
|
|
5
|
+
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
6
|
+
const { name } = props;
|
|
7
|
+
return _jsx(FieldTemplate, Object.assign({}, props));
|
|
8
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StringField } from "./StringField";
|
|
3
|
+
export const NumberField = (props) => {
|
|
4
|
+
var _a;
|
|
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
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useField, useFormikContext } from "formik";
|
|
14
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
15
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
16
|
+
import { resolveSchema } from "../utils/resolveSchema";
|
|
17
|
+
import { useSetDefault } from "../hooks";
|
|
18
|
+
import { orderByUiSchema } from "../utils";
|
|
19
|
+
const useObjectField = (name) => {
|
|
20
|
+
if (!name) {
|
|
21
|
+
const { values = {}, setValues } = useFormikContext();
|
|
22
|
+
return { value: values, setValue: setValues };
|
|
23
|
+
}
|
|
24
|
+
const [{ value = {} }, _, { setValue }] = useField(name);
|
|
25
|
+
return { value, setValue };
|
|
26
|
+
};
|
|
27
|
+
export const ObjectField = (props) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const { fields: { SchemaField }, templates: { ObjectFieldTemplate, CollapsibleObjectFieldTemplate }, components: { ObjectFieldItem }, hideUnmarkedAdditionalProperties, } = useContext(FormPdfRegistry);
|
|
30
|
+
useSetDefault(props);
|
|
31
|
+
const { name, schema, uiSchema } = props;
|
|
32
|
+
const { value, setValue } = useObjectField(name);
|
|
33
|
+
const [{ properties, additionalProperties, required }, valuesToRemove] = useMemo(() => {
|
|
34
|
+
return resolveSchema(schema, value);
|
|
35
|
+
}, [schema, value]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (valuesToRemove.length > 0) {
|
|
38
|
+
const newValue = valuesToRemove.reduce((prevValue, key) => {
|
|
39
|
+
const _a = prevValue, _b = key, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
40
|
+
return newValue;
|
|
41
|
+
}, value);
|
|
42
|
+
setValue(newValue);
|
|
43
|
+
}
|
|
44
|
+
}, [valuesToRemove]);
|
|
45
|
+
const propertyKeys = useMemo(() => Object.keys(properties || {}), [properties]);
|
|
46
|
+
const additionalValues = useMemo(() => Object.fromEntries(Object.entries(value || {}).filter(([key, value]) => !propertyKeys.includes(key))), [value, propertyKeys]);
|
|
47
|
+
const FieldTemplateComponent = ((_b = (_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.isCollapsible)
|
|
48
|
+
? CollapsibleObjectFieldTemplate
|
|
49
|
+
: ObjectFieldTemplate;
|
|
50
|
+
const orderedProperties = orderByUiSchema(uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:order"], Object.keys(properties || {}));
|
|
51
|
+
return (_jsx(FieldTemplateComponent, Object.assign({}, props, { children: (orderedProperties !== null && orderedProperties !== void 0 ? orderedProperties : Object.keys(properties || {}))
|
|
52
|
+
.map((childName) => {
|
|
53
|
+
const childSchema = properties === null || properties === void 0 ? void 0 : properties[childName];
|
|
54
|
+
if (!childSchema)
|
|
55
|
+
return undefined;
|
|
56
|
+
return (_jsx(SchemaField, { name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName));
|
|
57
|
+
})
|
|
58
|
+
.filter((x) => x) })));
|
|
59
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BooleanField } from "./BooleanField";
|
|
3
|
+
export const RadioField = (props) => {
|
|
4
|
+
var _a;
|
|
5
|
+
return (_jsx(BooleanField, 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: "boolean" }) }) })));
|
|
6
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { getSchemaType, solveReferences } from "../utils";
|
|
4
|
+
import { useExtractUiSchema } from "../hooks";
|
|
5
|
+
import { FormPdfRegistry } from "../FormPdf";
|
|
6
|
+
import { COMPONENT_TYPES } from "./types";
|
|
7
|
+
const useFieldComponent = (schema, uiSchema, fields) => {
|
|
8
|
+
const { field } = useExtractUiSchema(uiSchema);
|
|
9
|
+
if (typeof field === "function") {
|
|
10
|
+
return field;
|
|
11
|
+
}
|
|
12
|
+
if (typeof field === "string" && field in fields) {
|
|
13
|
+
return fields[field];
|
|
14
|
+
}
|
|
15
|
+
let schemaType = getSchemaType(schema);
|
|
16
|
+
if (Array.isArray(schemaType)) {
|
|
17
|
+
schemaType = schemaType[0];
|
|
18
|
+
}
|
|
19
|
+
const componentName = COMPONENT_TYPES[schemaType || "any"];
|
|
20
|
+
return componentName in fields
|
|
21
|
+
? fields[componentName]
|
|
22
|
+
: fields.UnsupportedField;
|
|
23
|
+
};
|
|
24
|
+
export const SchemaField = (props) => {
|
|
25
|
+
const { schema, uiSchema } = props;
|
|
26
|
+
const { fields, definitions, uiSchemaDefinitions } = useContext(FormPdfRegistry);
|
|
27
|
+
const schemaSolvedForReferences = useMemo(() => solveReferences(schema, definitions, uiSchema, uiSchemaDefinitions), [schema, definitions]);
|
|
28
|
+
const FieldComponent = useFieldComponent(schemaSolvedForReferences.schema, schemaSolvedForReferences.uiSchema, fields);
|
|
29
|
+
const newProps = Object.assign(Object.assign({}, props), { schema: schemaSolvedForReferences.schema, uiSchema: schemaSolvedForReferences.uiSchema });
|
|
30
|
+
return _jsx(FieldComponent, Object.assign({}, newProps));
|
|
31
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { FormRegistry } from "../Form";
|
|
4
|
+
import { getEnums } from "../utils/getEnums";
|
|
5
|
+
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
6
|
+
import { ArrayField } from "./ArrayField";
|
|
7
|
+
export const SearchMultiTagSelectField = (props) => {
|
|
8
|
+
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
9
|
+
useSetDefault(props);
|
|
10
|
+
const { name, uiSchema } = props;
|
|
11
|
+
const { placeholder, emptySearchMessage, props: inputProps, } = useExtractUiSchema(uiSchema);
|
|
12
|
+
const enums = useMemo(() => getEnums(props), [props]);
|
|
13
|
+
return (_jsx(ArrayField, Object.assign({}, props, inputProps, { name: name, placeholder: placeholder, emptySearchMessage: emptySearchMessage, enums: enums })));
|
|
14
|
+
};
|