@nolwenture/formik-jsonschema-form 0.4.2 → 0.5.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 +113 -0
- package/dist/Form.js +13 -24
- package/dist/Form.stories.js +91 -85
- package/dist/Form.test.js +2 -2
- package/dist/FormEditor.js +11 -56
- package/dist/FormEditor.stories.js +2 -13
- package/dist/_sampleData.d.ts +1 -0
- package/dist/_sampleData.js +45 -7
- package/dist/fields/AnyField.js +8 -19
- package/dist/fields/ArrayField.js +32 -54
- package/dist/fields/BooleanField.js +4 -15
- package/dist/fields/DateField.js +4 -15
- package/dist/fields/NullField.js +3 -14
- package/dist/fields/NumberField.js +1 -12
- package/dist/fields/ObjectField.js +18 -41
- package/dist/fields/RadioField.d.ts +3 -0
- package/dist/fields/RadioField.js +11 -0
- package/dist/fields/SchemaField.js +7 -18
- package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
- package/dist/fields/SearchMultiTagSelectField.js +13 -0
- package/dist/fields/StringField.js +9 -49
- package/dist/fields/ToggleField.d.ts +3 -0
- package/dist/fields/ToggleField.js +11 -0
- package/dist/fields/index.d.ts +3 -0
- package/dist/fields/index.js +3 -0
- package/dist/fields/types.js +1 -1
- package/dist/formEditorSchemas.js +3 -3
- package/dist/styledComponents.d.ts +50 -1
- package/dist/styledComponents.js +340 -135
- package/dist/templates/ArrayFieldTemplate.js +7 -20
- package/dist/templates/FieldTemplate.js +7 -20
- package/dist/templates/ObjectFieldTemplate.js +9 -20
- package/dist/types.d.ts +32 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +49 -36
- package/package.json +1 -1
package/dist/fields/AnyField.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useMemo } from "react";
|
|
14
3
|
import { useState } from "react";
|
|
@@ -17,18 +6,18 @@ import { SchemaField } from "./SchemaField";
|
|
|
17
6
|
import { guessType } from "../utils";
|
|
18
7
|
import { COMPONENT_TYPES } from "./types";
|
|
19
8
|
export function AnyField(props) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
const { name, schema, uiSchema } = props;
|
|
10
|
+
const [{ value }] = useField(name);
|
|
11
|
+
const [type, setType] = useState(value !== undefined ? guessType(value) : "string");
|
|
12
|
+
const enrichedSchema = useMemo(() => {
|
|
24
13
|
switch (type) {
|
|
25
14
|
case "object":
|
|
26
|
-
return
|
|
15
|
+
return Object.assign(Object.assign({}, (schema || {})), { type, additionalProperties: {} });
|
|
27
16
|
case "array":
|
|
28
|
-
return
|
|
17
|
+
return Object.assign(Object.assign({}, (schema || {})), { type, additionalItems: {} });
|
|
29
18
|
default:
|
|
30
|
-
return
|
|
19
|
+
return Object.assign(Object.assign({}, (schema || {})), { type });
|
|
31
20
|
}
|
|
32
21
|
}, [type, schema]);
|
|
33
|
-
return (_jsxs("div", { children: [_jsx("select",
|
|
22
|
+
return (_jsxs("div", { children: [_jsx("select", Object.assign({ value: type, onChange: (event) => setType(event.target.value) }, { children: Object.keys(COMPONENT_TYPES).map((type) => (_jsx("option", Object.assign({ value: type }, { children: type }), type))) })), _jsx(SchemaField, { name: name, schema: enrichedSchema, uiSchema: uiSchema })] }));
|
|
34
23
|
}
|
|
@@ -1,23 +1,3 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
2
|
import { useContext, useMemo } from "react";
|
|
23
3
|
import { FormRegistry } from "../Form";
|
|
@@ -26,47 +6,51 @@ import { ArrayFieldButtonPurpose } from "../types";
|
|
|
26
6
|
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
27
7
|
import { GetArrayFieldButton } from "../styledComponents";
|
|
28
8
|
function appendArray(values) {
|
|
29
|
-
return values ?
|
|
9
|
+
return values ? [...values, ""] : [""];
|
|
30
10
|
}
|
|
31
11
|
function removeFromArray(values, index) {
|
|
32
|
-
return
|
|
12
|
+
return [...values.slice(0, index), ...values.slice(index + 1)];
|
|
33
13
|
}
|
|
34
14
|
function moveInArray(values, index, direction) {
|
|
35
15
|
if (direction === -1) {
|
|
36
|
-
return
|
|
16
|
+
return [
|
|
17
|
+
...values.slice(0, index - 1),
|
|
37
18
|
values[index],
|
|
38
|
-
values[index - 1]
|
|
39
|
-
|
|
19
|
+
values[index - 1],
|
|
20
|
+
...values.slice(index + 1),
|
|
21
|
+
];
|
|
40
22
|
}
|
|
41
23
|
else {
|
|
42
|
-
return
|
|
24
|
+
return [
|
|
25
|
+
...values.slice(0, index),
|
|
43
26
|
values[index + 1],
|
|
44
|
-
values[index]
|
|
45
|
-
|
|
27
|
+
values[index],
|
|
28
|
+
...values.slice(index + 2),
|
|
29
|
+
];
|
|
46
30
|
}
|
|
47
31
|
}
|
|
48
32
|
export function ArrayField(props) {
|
|
49
|
-
|
|
33
|
+
const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem, ArrayFieldList, ArrayFieldItemButtons }, useItemsAsAdditionalItems, } = useContext(FormRegistry);
|
|
50
34
|
useSetDefault(props);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
const { name, schema, uiSchema } = props;
|
|
36
|
+
const [{ value }, _, { setValue }] = useField(name);
|
|
37
|
+
const { items, additionalItems, } = useMemo(() => {
|
|
38
|
+
let items = schema.items && typeof schema.items !== "boolean" ? schema.items : [];
|
|
55
39
|
if (!Array.isArray(items)) {
|
|
56
40
|
items = [items];
|
|
57
41
|
}
|
|
58
42
|
return useItemsAsAdditionalItems && !schema.additionalItems
|
|
59
43
|
? {
|
|
60
44
|
items: [],
|
|
61
|
-
additionalItems: items.filter(
|
|
45
|
+
additionalItems: items.filter((item) => typeof item !== "boolean")[0],
|
|
62
46
|
}
|
|
63
47
|
: {
|
|
64
|
-
items: items.filter(
|
|
48
|
+
items: items.filter((item) => typeof item !== "boolean"),
|
|
65
49
|
additionalItems: typeof schema.additionalItems !== "boolean"
|
|
66
50
|
? schema.additionalItems
|
|
67
51
|
: undefined,
|
|
68
52
|
};
|
|
69
|
-
}, [schema])
|
|
53
|
+
}, [schema]);
|
|
70
54
|
//This whole mess would give backwards compatibility, but maybe we don't do it
|
|
71
55
|
// const {
|
|
72
56
|
// items,
|
|
@@ -108,35 +92,29 @@ export function ArrayField(props) {
|
|
|
108
92
|
// [schema]
|
|
109
93
|
// );
|
|
110
94
|
// Bacwards compatibility ends
|
|
111
|
-
|
|
112
|
-
return (_jsxs(ArrayFieldTemplate,
|
|
95
|
+
const { disabled } = useExtractUiSchema(uiSchema);
|
|
96
|
+
return (_jsxs(ArrayFieldTemplate, Object.assign({}, props, { children: [_jsxs(ArrayFieldList, { children: [(items || []).map((itemSchema, index) => (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: `${name}[${index}]`, schema: typeof itemSchema !== "boolean" ? itemSchema : {}, uiSchema: (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items), forceDefaultValue: true }) }, index))), ((value === null || value === void 0 ? void 0 : value.slice(items.length)) || []).map((_, index) => (_jsxs(ArrayFieldItem, { children: [_jsx(SchemaField, { name: `${name}[${index + items.length}]`, schema: additionalItems && typeof additionalItems !== "boolean"
|
|
113
97
|
? additionalItems
|
|
114
|
-
: {}, uiSchema:
|
|
98
|
+
: {}, uiSchema: Object.assign({ disabled }, ((uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index + items.length]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items))) }), _jsxs(ArrayFieldItemButtons, { children: [GetArrayFieldButton({
|
|
115
99
|
purpose: ArrayFieldButtonPurpose.REMOVE,
|
|
116
|
-
onClick:
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
uiSchema: uiSchema,
|
|
100
|
+
onClick: () => setValue(removeFromArray(value, index + items.length)),
|
|
101
|
+
uiSchema,
|
|
120
102
|
}), value.length > 1 &&
|
|
121
103
|
index > 0 &&
|
|
122
104
|
GetArrayFieldButton({
|
|
123
105
|
purpose: ArrayFieldButtonPurpose.MOVE_UP,
|
|
124
|
-
onClick:
|
|
125
|
-
|
|
126
|
-
},
|
|
127
|
-
uiSchema: uiSchema,
|
|
106
|
+
onClick: () => setValue(moveInArray(value, index + items.length, -1)),
|
|
107
|
+
uiSchema,
|
|
128
108
|
}), value.length > 1 &&
|
|
129
109
|
index < value.length - 1 &&
|
|
130
110
|
GetArrayFieldButton({
|
|
131
111
|
purpose: ArrayFieldButtonPurpose.MOVE_DOWN,
|
|
132
|
-
onClick:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
uiSchema: uiSchema,
|
|
136
|
-
})] })] }, index)); })] }), additionalItems &&
|
|
112
|
+
onClick: () => setValue(moveInArray(value, index + items.length, 1)),
|
|
113
|
+
uiSchema,
|
|
114
|
+
})] })] }, index)))] }), additionalItems &&
|
|
137
115
|
GetArrayFieldButton({
|
|
138
116
|
purpose: ArrayFieldButtonPurpose.ADD,
|
|
139
|
-
onClick:
|
|
140
|
-
uiSchema
|
|
117
|
+
onClick: () => setValue(appendArray(value)),
|
|
118
|
+
uiSchema,
|
|
141
119
|
})] })));
|
|
142
120
|
}
|
|
@@ -1,22 +1,11 @@
|
|
|
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
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
15
4
|
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
16
5
|
export function BooleanField(props) {
|
|
17
|
-
|
|
6
|
+
const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
|
|
18
7
|
useSetDefault(props);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return (_jsx(FieldTemplate,
|
|
8
|
+
const { name, uiSchema } = props;
|
|
9
|
+
const { label, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsxs(_Fragment, { children: [_jsx(FieldInput, Object.assign({}, inputProps, { name: name, type: "checkbox" })), label] }) })));
|
|
22
11
|
}
|
package/dist/fields/DateField.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
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
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
15
4
|
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
16
5
|
export function DateField(props) {
|
|
17
|
-
|
|
6
|
+
const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
|
|
18
7
|
useSetDefault(props);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return (_jsx(FieldTemplate,
|
|
8
|
+
const { name, uiSchema } = props;
|
|
9
|
+
const { props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(FieldInput, Object.assign({}, inputProps, { name: name, type: "date" })) })));
|
|
22
11
|
}
|
package/dist/fields/NullField.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
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
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
15
4
|
export function NullField(props) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return _jsx(FieldTemplate,
|
|
5
|
+
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
6
|
+
const { name } = props;
|
|
7
|
+
return _jsx(FieldTemplate, Object.assign({}, props));
|
|
19
8
|
}
|
|
@@ -1,17 +1,6 @@
|
|
|
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
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
2
|
import { StringField } from "./StringField";
|
|
14
3
|
export function NumberField(props) {
|
|
15
4
|
var _a;
|
|
16
|
-
return (_jsx(StringField,
|
|
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" }) }) })));
|
|
17
6
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
2
|
var t = {};
|
|
14
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -28,40 +17,28 @@ import { ObjectFieldButtonPurpose } from "../types";
|
|
|
28
17
|
import { useSetDefault } from "../utils";
|
|
29
18
|
import { getObjectFieldButton } from "../styledComponents";
|
|
30
19
|
export function ObjectField(props) {
|
|
31
|
-
|
|
20
|
+
const { fields: { SchemaField }, templates: { ObjectFieldTemplate }, components: { ObjectFieldItem, ObjectFieldItemButtons }, hideUnmarkedAdditionalProperties, } = useContext(FormRegistry);
|
|
32
21
|
useSetDefault(props);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Object.entries(additionalValues || {}).map(function (_a) {
|
|
48
|
-
var childName = _a[0], childSchema = _a[1];
|
|
49
|
-
return (_jsxs(ObjectFieldItem, { children: [_jsx(SchemaField, { required: required === null || required === void 0 ? void 0 : required.includes(childName), name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName), _jsx(ObjectFieldItemButtons, { children: getObjectFieldButton({
|
|
50
|
-
purpose: ObjectFieldButtonPurpose.REMOVE,
|
|
51
|
-
onClick: function () {
|
|
52
|
-
var _a = value, _b = childName, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
53
|
-
setValue(newValue);
|
|
54
|
-
},
|
|
55
|
-
uiSchema: uiSchema,
|
|
56
|
-
}) })] }, childName));
|
|
57
|
-
}), additionalProperties &&
|
|
22
|
+
const { name, schema, uiSchema } = props;
|
|
23
|
+
const [{ value }, _, { setValue }] = useField(name);
|
|
24
|
+
const { properties, additionalProperties, required } = schema;
|
|
25
|
+
const propertyKeys = useMemo(() => Object.keys(properties || {}), [properties]);
|
|
26
|
+
const additionalValues = useMemo(() => Object.fromEntries(Object.entries(value || {}).filter(([key, value]) => !propertyKeys.includes(key))), [value, propertyKeys]);
|
|
27
|
+
return (_jsxs(ObjectFieldTemplate, Object.assign({}, props, { children: [Object.entries(properties || {}).map(([childName, childSchema]) => (_jsx(SchemaField, { required: required === null || required === void 0 ? void 0 : required.includes(childName), name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName))), (!hideUnmarkedAdditionalProperties || additionalProperties) &&
|
|
28
|
+
Object.entries(additionalValues || {}).map(([childName, childSchema]) => (_jsxs(ObjectFieldItem, { children: [_jsx(SchemaField, { required: required === null || required === void 0 ? void 0 : required.includes(childName), name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName), _jsx(ObjectFieldItemButtons, { children: getObjectFieldButton({
|
|
29
|
+
purpose: ObjectFieldButtonPurpose.REMOVE,
|
|
30
|
+
onClick: () => {
|
|
31
|
+
const _a = value, _b = childName, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
32
|
+
setValue(newValue);
|
|
33
|
+
},
|
|
34
|
+
uiSchema: uiSchema,
|
|
35
|
+
}) })] }, childName))), additionalProperties &&
|
|
58
36
|
getObjectFieldButton({
|
|
59
37
|
purpose: ObjectFieldButtonPurpose.ADD,
|
|
60
|
-
onClick:
|
|
61
|
-
|
|
62
|
-
var key = prompt("Give key");
|
|
38
|
+
onClick: () => {
|
|
39
|
+
const key = prompt("Give key");
|
|
63
40
|
if (key) {
|
|
64
|
-
setValue(
|
|
41
|
+
setValue(Object.assign(Object.assign({}, value), { [key]: undefined }));
|
|
65
42
|
}
|
|
66
43
|
},
|
|
67
44
|
uiSchema: uiSchema,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { FormRegistry } from "../Form";
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
5
|
+
export function RadioField(props) {
|
|
6
|
+
const { templates: { FieldTemplate }, components: { RadioButtonField }, } = useContext(FormRegistry);
|
|
7
|
+
useSetDefault(props);
|
|
8
|
+
const { name, uiSchema } = props;
|
|
9
|
+
const { label, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(RadioButtonField, { inputProps: inputProps, label: label, name: name }) })));
|
|
11
|
+
}
|
|
@@ -1,39 +1,28 @@
|
|
|
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
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { useExtractUiSchema, getSchemaType } from "../utils";
|
|
15
4
|
import { FormRegistry } from "../Form";
|
|
16
5
|
import { COMPONENT_TYPES } from "./types";
|
|
17
6
|
function useFieldComponent(schema, uiSchema, fields) {
|
|
18
|
-
|
|
7
|
+
const { field } = useExtractUiSchema(uiSchema);
|
|
19
8
|
if (typeof field === "function") {
|
|
20
9
|
return field;
|
|
21
10
|
}
|
|
22
11
|
if (typeof field === "string" && field in fields) {
|
|
23
12
|
return fields[field];
|
|
24
13
|
}
|
|
25
|
-
|
|
14
|
+
let schemaType = getSchemaType(schema);
|
|
26
15
|
if (Array.isArray(schemaType)) {
|
|
27
16
|
schemaType = schemaType[0];
|
|
28
17
|
}
|
|
29
|
-
|
|
18
|
+
const componentName = COMPONENT_TYPES[schemaType || "any"];
|
|
30
19
|
return componentName in fields
|
|
31
20
|
? fields[componentName]
|
|
32
21
|
: fields.UnsupportedField;
|
|
33
22
|
}
|
|
34
23
|
export function SchemaField(props) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return _jsx(FieldComponent,
|
|
24
|
+
const { schema, uiSchema } = props;
|
|
25
|
+
const { fields } = useContext(FormRegistry);
|
|
26
|
+
const FieldComponent = useFieldComponent(schema, uiSchema, fields);
|
|
27
|
+
return _jsx(FieldComponent, Object.assign({}, props));
|
|
39
28
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { FormRegistry } from "../Form";
|
|
4
|
+
import { getEnums, useExtractUiSchema, useSetDefault } from "../utils";
|
|
5
|
+
import { SearchableMultiTagSelectField } from "../styledComponents";
|
|
6
|
+
export function SearchMultiTagSelectField(props) {
|
|
7
|
+
const { templates: { FieldTemplate }, } = useContext(FormRegistry);
|
|
8
|
+
useSetDefault(props);
|
|
9
|
+
const { name, uiSchema } = props;
|
|
10
|
+
const { placeholder, emptySearchMessage, props: inputProps, } = useExtractUiSchema(uiSchema);
|
|
11
|
+
const enums = useMemo(() => getEnums(props), [props]);
|
|
12
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(SearchableMultiTagSelectField, Object.assign({}, inputProps, { name: name, placeholder: placeholder, emptySearchMessage: emptySearchMessage, enums: enums })) })));
|
|
13
|
+
}
|
|
@@ -1,60 +1,20 @@
|
|
|
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
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext, useMemo } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
15
|
-
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
16
|
-
function getEnums(_a) {
|
|
17
|
-
var schema = _a.schema;
|
|
18
|
-
var numberOfDefined = [schema.enum, schema.oneOf, schema.anyOf].filter(function (x) { return x; }).length;
|
|
19
|
-
if (numberOfDefined === 0) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (numberOfDefined > 1) {
|
|
23
|
-
throw new Error('Only one of "enum", "oneOf" or "anyOf" can be defined!');
|
|
24
|
-
}
|
|
25
|
-
if (schema.enum) {
|
|
26
|
-
return {
|
|
27
|
-
type: "select",
|
|
28
|
-
values: schema.enum.map(function (option) { return ({
|
|
29
|
-
const: option,
|
|
30
|
-
title: "".concat(option),
|
|
31
|
-
}); }),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (schema.oneOf) {
|
|
35
|
-
return {
|
|
36
|
-
type: "select",
|
|
37
|
-
values: schema.oneOf,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (schema.anyOf) {
|
|
41
|
-
return {
|
|
42
|
-
type: "multiSelect",
|
|
43
|
-
values: schema.anyOf,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
4
|
+
import { getEnums, useExtractUiSchema, useSetDefault } from "../utils";
|
|
47
5
|
export function StringField(props) {
|
|
48
|
-
var _a
|
|
6
|
+
var _a;
|
|
7
|
+
const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
|
|
49
8
|
useSetDefault(props);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
9
|
+
const { name, uiSchema } = props;
|
|
10
|
+
const { type, placeholder, props: inputProps } = useExtractUiSchema(uiSchema);
|
|
11
|
+
const enums = useMemo(() => getEnums(props), [props]);
|
|
53
12
|
switch (enums === null || enums === void 0 ? void 0 : enums.type) {
|
|
54
13
|
case "select":
|
|
55
14
|
case "multiSelect":
|
|
56
|
-
return (_jsx(FieldTemplate,
|
|
15
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsxs(FieldInput, Object.assign({}, Object.assign({ type }, inputProps), { name: name, formikAs: "select", multiple: enums.type === "multiSelect" }, (enums.type !== "multiSelect" ? { defaultValue: "" } : {}), { children: [enums.type !== "multiSelect" && (_jsx("option", Object.assign({ value: "" }, Object.assign({ disabled: true, hidden: true }, (_a = uiSchema["ui:placeholderOptionOptions"]) === null || _a === void 0 ? void 0 : _a.props), { children: placeholder }))), enums === null || enums === void 0 ? void 0 : enums.values.map((option, index) => (_jsx("option", Object.assign({ value: option.const }, { children: option.title }), index)))] })) })));
|
|
57
16
|
default:
|
|
58
|
-
return (_jsx(FieldTemplate,
|
|
17
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(FieldInput, Object.assign({}, Object.assign({ type,
|
|
18
|
+
placeholder }, inputProps), { name: name })) })));
|
|
59
19
|
}
|
|
60
20
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { FormRegistry } from "../Form";
|
|
4
|
+
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
5
|
+
export function ToggleField(props) {
|
|
6
|
+
const { templates: { FieldTemplate }, components: { ToggleSwitchField }, } = useContext(FormRegistry);
|
|
7
|
+
useSetDefault(props);
|
|
8
|
+
const { name, uiSchema } = props;
|
|
9
|
+
const { props: inputProps } = useExtractUiSchema(uiSchema);
|
|
10
|
+
return (_jsx(FieldTemplate, Object.assign({}, props, { children: _jsx(ToggleSwitchField, Object.assign({}, inputProps, { name: name })) })));
|
|
11
|
+
}
|
package/dist/fields/index.d.ts
CHANGED
package/dist/fields/index.js
CHANGED
package/dist/fields/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const field = {
|
|
2
2
|
type: "object",
|
|
3
3
|
properties: {
|
|
4
4
|
type: {
|
|
@@ -17,7 +17,7 @@ var field = {
|
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export const schema = {
|
|
21
21
|
type: "object",
|
|
22
22
|
properties: {
|
|
23
23
|
"schema.type": {
|
|
@@ -31,6 +31,6 @@ export var schema = {
|
|
|
31
31
|
},
|
|
32
32
|
additionalProperties: field,
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export const uiSchema = {
|
|
35
35
|
"schema.type": { props: { type: "hidden" } },
|
|
36
36
|
};
|