@nolwenture/formik-jsonschema-form 0.25.0 → 0.25.1
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/FormPdf.stories.js +6 -1
- package/dist/pdfFields/ArrayField.js +5 -19
- package/dist/pdfFields/BooleanField.js +3 -3
- package/dist/pdfFields/DateField.js +5 -6
- package/dist/pdfFields/EJSField.js +2 -2
- package/dist/pdfFields/NullField.js +0 -1
- package/dist/pdfFields/ObjectField.js +2 -4
- package/dist/pdfFields/SearchMultiTagSelectField.js +1 -3
- package/dist/pdfFields/StringField.js +5 -12
- package/dist/pdfFields/TextAreaField.js +4 -4
- package/package.json +1 -1
package/dist/FormPdf.stories.js
CHANGED
|
@@ -70,7 +70,12 @@ export const CompletePdfSchema = {
|
|
|
70
70
|
array: ["First field", "Second field"],
|
|
71
71
|
partiallyFixedArray: ["Hello", "To you"],
|
|
72
72
|
enumArray: [2, 4],
|
|
73
|
-
nested: {
|
|
73
|
+
nested: {
|
|
74
|
+
string: "This is a string inside a nested object",
|
|
75
|
+
number: 987,
|
|
76
|
+
date: "2021-12-09",
|
|
77
|
+
enum: 1,
|
|
78
|
+
},
|
|
74
79
|
objectArray: [
|
|
75
80
|
{
|
|
76
81
|
string: "this is a string in an object in an array",
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useField
|
|
2
|
+
import { useField } from "formik";
|
|
3
3
|
import { useContext, useMemo } from "react";
|
|
4
4
|
import { FormPdfRegistry } from "../FormPdf";
|
|
5
|
-
import {
|
|
5
|
+
import { useSetDefault } from "../hooks";
|
|
6
6
|
import { getEnums } from "../utils";
|
|
7
|
-
import { styled } from "styled-components";
|
|
8
|
-
const ArrayFieldPdf = styled.div ``;
|
|
9
7
|
export const ArrayField = (props) => {
|
|
10
|
-
const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem
|
|
8
|
+
const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem }, } = useContext(FormPdfRegistry);
|
|
11
9
|
useSetDefault(props);
|
|
12
|
-
const { name,
|
|
13
|
-
const {
|
|
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();
|
|
10
|
+
const { name, uiSchema } = props;
|
|
11
|
+
const [{ value }, _] = useField(name);
|
|
26
12
|
const findEnumInProps = props.schema.additionalItems
|
|
27
13
|
? { schema: props.schema.additionalItems }
|
|
28
14
|
: props;
|
|
@@ -2,14 +2,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormPdfRegistry } from "../FormPdf";
|
|
4
4
|
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
5
|
-
import { useFormikContext } from "formik";
|
|
5
|
+
import { getIn, useFormikContext } from "formik";
|
|
6
6
|
export const BooleanField = (props) => {
|
|
7
7
|
const { templates: { FieldTemplate }, components: { BooleanFieldPdf, BooleanFieldWrapper }, } = useContext(FormPdfRegistry);
|
|
8
8
|
useSetDefault(props);
|
|
9
9
|
const { name, uiSchema } = props;
|
|
10
|
-
const { label
|
|
10
|
+
const { label } = useExtractUiSchema(uiSchema);
|
|
11
11
|
const { values } = useFormikContext();
|
|
12
|
-
const value = values
|
|
12
|
+
const value = getIn(values, name);
|
|
13
13
|
function findLabel(label) {
|
|
14
14
|
if (typeof label === "object" && label !== null) {
|
|
15
15
|
switch (value) {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
-
import {
|
|
5
|
-
import { useFormikContext } from "formik";
|
|
4
|
+
import { useSetDefault } from "../hooks";
|
|
5
|
+
import { getIn, useFormikContext } from "formik";
|
|
6
6
|
import { styled } from "styled-components";
|
|
7
7
|
const DateFieldPdf = styled.div ``;
|
|
8
8
|
export const DateField = (props) => {
|
|
9
|
-
const { templates: { FieldTemplate },
|
|
9
|
+
const { templates: { FieldTemplate }, } = useContext(FormPdfRegistry);
|
|
10
10
|
useSetDefault(props);
|
|
11
|
-
const { name
|
|
11
|
+
const { name } = props;
|
|
12
12
|
const { values } = useFormikContext();
|
|
13
|
-
const
|
|
14
|
-
const value = values[name];
|
|
13
|
+
const value = getIn(values, name);
|
|
15
14
|
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(DateFieldPdf, { children: value }) })));
|
|
16
15
|
};
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { useSetDefault } from "../hooks";
|
|
4
4
|
import ejs from "ejs";
|
|
5
|
-
import { useFormikContext } from "formik";
|
|
5
|
+
import { getIn, useFormikContext } from "formik";
|
|
6
6
|
import { getDescription, getTitle } from "../utils";
|
|
7
7
|
import { FormPdfRegistry } from "../FormPdf";
|
|
8
8
|
export const EJSField = (props) => {
|
|
@@ -18,7 +18,7 @@ export const EJSField = (props) => {
|
|
|
18
18
|
__html: ejs.render(template.toString(), {
|
|
19
19
|
title,
|
|
20
20
|
description,
|
|
21
|
-
value: values
|
|
21
|
+
value: getIn(values, name),
|
|
22
22
|
}),
|
|
23
23
|
} }));
|
|
24
24
|
};
|
|
@@ -3,6 +3,5 @@ import { useContext } from "react";
|
|
|
3
3
|
import { FormRegistry } from "../Form";
|
|
4
4
|
export const NullField = (props) => {
|
|
5
5
|
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
6
|
-
const { name } = props;
|
|
7
6
|
return _jsx(FieldTemplate, Object.assign({}, props));
|
|
8
7
|
};
|
|
@@ -26,11 +26,11 @@ const useObjectField = (name) => {
|
|
|
26
26
|
};
|
|
27
27
|
export const ObjectField = (props) => {
|
|
28
28
|
var _a, _b;
|
|
29
|
-
const { fields: { SchemaField }, templates: { ObjectFieldTemplate, CollapsibleObjectFieldTemplate },
|
|
29
|
+
const { fields: { SchemaField }, templates: { ObjectFieldTemplate, CollapsibleObjectFieldTemplate }, } = useContext(FormPdfRegistry);
|
|
30
30
|
useSetDefault(props);
|
|
31
31
|
const { name, schema, uiSchema } = props;
|
|
32
32
|
const { value, setValue } = useObjectField(name);
|
|
33
|
-
const [{ properties
|
|
33
|
+
const [{ properties }, valuesToRemove] = useMemo(() => {
|
|
34
34
|
return resolveSchema(schema, value);
|
|
35
35
|
}, [schema, value]);
|
|
36
36
|
useEffect(() => {
|
|
@@ -42,8 +42,6 @@ export const ObjectField = (props) => {
|
|
|
42
42
|
setValue(newValue);
|
|
43
43
|
}
|
|
44
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
45
|
const FieldTemplateComponent = ((_b = (_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.isCollapsible)
|
|
48
46
|
? CollapsibleObjectFieldTemplate
|
|
49
47
|
: ObjectFieldTemplate;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { FormRegistry } from "../Form";
|
|
2
|
+
import { useMemo } from "react";
|
|
4
3
|
import { getEnums } from "../utils/getEnums";
|
|
5
4
|
import { useExtractUiSchema, useSetDefault } from "../hooks";
|
|
6
5
|
import { ArrayField } from "./ArrayField";
|
|
7
6
|
export const SearchMultiTagSelectField = (props) => {
|
|
8
|
-
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
9
7
|
useSetDefault(props);
|
|
10
8
|
const { name, uiSchema } = props;
|
|
11
9
|
const { placeholder, emptySearchMessage, props: inputProps, } = useExtractUiSchema(uiSchema);
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useMemo } from "react";
|
|
3
3
|
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
-
import {
|
|
5
|
-
import { useFormikContext } from "formik";
|
|
4
|
+
import { useSetDefault } from "../hooks";
|
|
5
|
+
import { getIn, useFormikContext } from "formik";
|
|
6
6
|
import { getEnums } from "../utils";
|
|
7
|
-
function getValueByPath(obj, path) {
|
|
8
|
-
const parts = path
|
|
9
|
-
.split(".")
|
|
10
|
-
.flatMap((part) => part.replace(/\[(\d+)\]/g, ".$1").split("."));
|
|
11
|
-
return parts.reduce((acc, part) => acc && acc[part], obj);
|
|
12
|
-
}
|
|
13
7
|
export const StringField = (props) => {
|
|
14
8
|
var _a, _b;
|
|
15
9
|
const { templates: { FieldTemplate }, components: { StringFieldPdf }, } = useContext(FormPdfRegistry);
|
|
16
10
|
useSetDefault(props);
|
|
17
|
-
const { name
|
|
11
|
+
const { name } = props;
|
|
18
12
|
const { values } = useFormikContext();
|
|
19
|
-
const { type, placeholder, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
20
13
|
const enums = useMemo(() => getEnums(props), [props]);
|
|
21
|
-
let value =
|
|
14
|
+
let value = getIn(values, name);
|
|
22
15
|
if (enums !== undefined) {
|
|
23
16
|
value =
|
|
24
17
|
(_b = (_a = enums.values.find((element) => element.const === value)) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : value;
|
|
25
18
|
}
|
|
26
|
-
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(StringFieldPdf, { name: name, "data-keyword": values[name],
|
|
19
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(StringFieldPdf, { name: name, "data-keyword": values[name], children: value }) })));
|
|
27
20
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { FormPdfRegistry } from "../FormPdf";
|
|
4
|
-
import {
|
|
5
|
-
import { useFormikContext } from "formik";
|
|
4
|
+
import { useSetDefault } from "../hooks";
|
|
5
|
+
import { getIn, useFormikContext } from "formik";
|
|
6
6
|
export const TextAreaField = (props) => {
|
|
7
7
|
const { templates: { FieldTemplate }, components: { TextAreaPdf }, } = useContext(FormPdfRegistry);
|
|
8
8
|
useSetDefault(props);
|
|
9
9
|
const { name, uiSchema } = props;
|
|
10
|
-
const { props: inputProps } = useExtractUiSchema(uiSchema);
|
|
11
10
|
const { values } = useFormikContext();
|
|
12
|
-
|
|
11
|
+
const value = getIn(values, name);
|
|
12
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(TextAreaPdf, { name: name, children: value }) })));
|
|
13
13
|
};
|