@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.
@@ -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
- var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
21
- var value = useField(name)[0].value;
22
- var _a = useState(value !== undefined ? guessType(value) : "string"), type = _a[0], setType = _a[1];
23
- var enrichedSchema = useMemo(function () {
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 __assign(__assign({}, (schema || {})), { type: type, additionalProperties: {} });
15
+ return Object.assign(Object.assign({}, (schema || {})), { type, additionalProperties: {} });
27
16
  case "array":
28
- return __assign(__assign({}, (schema || {})), { type: type, additionalItems: {} });
17
+ return Object.assign(Object.assign({}, (schema || {})), { type, additionalItems: {} });
29
18
  default:
30
- return __assign(__assign({}, (schema || {})), { type: type });
19
+ return Object.assign(Object.assign({}, (schema || {})), { type });
31
20
  }
32
21
  }, [type, schema]);
33
- return (_jsxs("div", { children: [_jsx("select", __assign({ value: type, onChange: function (event) { return setType(event.target.value); } }, { children: Object.keys(COMPONENT_TYPES).map(function (type) { return (_jsx("option", __assign({ value: type }, { children: type }), type)); }) })), _jsx(SchemaField, { name: name, schema: enrichedSchema, uiSchema: uiSchema })] }));
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 ? __spreadArray(__spreadArray([], values, true), [""], false) : [""];
9
+ return values ? [...values, ""] : [""];
30
10
  }
31
11
  function removeFromArray(values, index) {
32
- return __spreadArray(__spreadArray([], values.slice(0, index), true), values.slice(index + 1), true);
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 __spreadArray(__spreadArray(__spreadArray([], values.slice(0, index - 1), true), [
16
+ return [
17
+ ...values.slice(0, index - 1),
37
18
  values[index],
38
- values[index - 1]
39
- ], false), values.slice(index + 1), true);
19
+ values[index - 1],
20
+ ...values.slice(index + 1),
21
+ ];
40
22
  }
41
23
  else {
42
- return __spreadArray(__spreadArray(__spreadArray([], values.slice(0, index), true), [
24
+ return [
25
+ ...values.slice(0, index),
43
26
  values[index + 1],
44
- values[index]
45
- ], false), values.slice(index + 2), true);
27
+ values[index],
28
+ ...values.slice(index + 2),
29
+ ];
46
30
  }
47
31
  }
48
32
  export function ArrayField(props) {
49
- var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ArrayFieldTemplate = _a.templates.ArrayFieldTemplate, _b = _a.components, ArrayFieldItem = _b.ArrayFieldItem, ArrayFieldList = _b.ArrayFieldList, ArrayFieldItemButtons = _b.ArrayFieldItemButtons, useItemsAsAdditionalItems = _a.useItemsAsAdditionalItems;
33
+ const { fields: { SchemaField }, templates: { ArrayFieldTemplate }, components: { ArrayFieldItem, ArrayFieldList, ArrayFieldItemButtons }, useItemsAsAdditionalItems, } = useContext(FormRegistry);
50
34
  useSetDefault(props);
51
- var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
52
- var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
53
- var _d = useMemo(function () {
54
- var items = schema.items && typeof schema.items !== "boolean" ? schema.items : [];
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(function (item) { return typeof item !== "boolean"; })[0],
45
+ additionalItems: items.filter((item) => typeof item !== "boolean")[0],
62
46
  }
63
47
  : {
64
- items: items.filter(function (item) { return typeof item !== "boolean"; }),
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]), items = _d.items, additionalItems = _d.additionalItems;
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
- var disabled = useExtractUiSchema(uiSchema).disabled;
112
- return (_jsxs(ArrayFieldTemplate, __assign({}, props, { children: [_jsxs(ArrayFieldList, { children: [(items || []).map(function (itemSchema, index) { return (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: "".concat(name, "[").concat(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(function (_, index) { return (_jsxs(ArrayFieldItem, { children: [_jsx(SchemaField, { name: "".concat(name, "[").concat(index + items.length, "]"), schema: additionalItems && typeof additionalItems !== "boolean"
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: __assign({ disabled: 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({
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: function () {
117
- return setValue(removeFromArray(value, index + items.length));
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: function () {
125
- return setValue(moveInArray(value, index + items.length, -1));
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: function () {
133
- return setValue(moveInArray(value, index + items.length, 1));
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: function () { return setValue(appendArray(value)); },
140
- uiSchema: 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
- var _a = useContext(FormRegistry), FieldTemplate = _a.templates.FieldTemplate, FieldInput = _a.components.FieldInput;
6
+ const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
18
7
  useSetDefault(props);
19
- var name = props.name, uiSchema = props.uiSchema;
20
- var _b = useExtractUiSchema(uiSchema), label = _b.label, inputProps = _b.props;
21
- return (_jsx(FieldTemplate, __assign({}, props, { children: _jsxs(_Fragment, { children: [_jsx(FieldInput, __assign({}, inputProps, { name: name, type: "checkbox" })), label] }) })));
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
  }
@@ -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
- var _a = useContext(FormRegistry), FieldTemplate = _a.templates.FieldTemplate, FieldInput = _a.components.FieldInput;
6
+ const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
18
7
  useSetDefault(props);
19
- var name = props.name, uiSchema = props.uiSchema;
20
- var inputProps = useExtractUiSchema(uiSchema).props;
21
- return (_jsx(FieldTemplate, __assign({}, props, { children: _jsx(FieldInput, __assign({}, inputProps, { name: name, type: "date" })) })));
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
  }
@@ -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
- var FieldTemplate = useContext(FormRegistry).templates.FieldTemplate;
17
- var name = props.name;
18
- return _jsx(FieldTemplate, __assign({}, props));
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, __assign({}, props, { uiSchema: __assign(__assign({}, props.uiSchema), { "ui:props": __assign(__assign({}, (((_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:props"]) || {})), { type: "number" }) }) })));
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
- var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ObjectFieldTemplate = _a.templates.ObjectFieldTemplate, _b = _a.components, ObjectFieldItem = _b.ObjectFieldItem, ObjectFieldItemButtons = _b.ObjectFieldItemButtons, hideUnmarkedAdditionalProperties = _a.hideUnmarkedAdditionalProperties;
20
+ const { fields: { SchemaField }, templates: { ObjectFieldTemplate }, components: { ObjectFieldItem, ObjectFieldItemButtons }, hideUnmarkedAdditionalProperties, } = useContext(FormRegistry);
32
21
  useSetDefault(props);
33
- var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
34
- var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
35
- var properties = schema.properties, additionalProperties = schema.additionalProperties, required = schema.required;
36
- var propertyKeys = useMemo(function () { return Object.keys(properties || {}); }, [properties]);
37
- var additionalValues = useMemo(function () {
38
- return Object.fromEntries(Object.entries(value || {}).filter(function (_a) {
39
- var key = _a[0], value = _a[1];
40
- return !propertyKeys.includes(key);
41
- }));
42
- }, [value, propertyKeys]);
43
- return (_jsxs(ObjectFieldTemplate, __assign({}, props, { children: [Object.entries(properties || {}).map(function (_a) {
44
- var childName = _a[0], childSchema = _a[1];
45
- return (_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));
46
- }), (!hideUnmarkedAdditionalProperties || additionalProperties) &&
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: function () {
61
- var _a;
62
- var key = prompt("Give key");
38
+ onClick: () => {
39
+ const key = prompt("Give key");
63
40
  if (key) {
64
- setValue(__assign(__assign({}, value), (_a = {}, _a[key] = undefined, _a)));
41
+ setValue(Object.assign(Object.assign({}, value), { [key]: undefined }));
65
42
  }
66
43
  },
67
44
  uiSchema: uiSchema,
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldProps } from "../types";
3
+ export declare function RadioField(props: FieldProps): JSX.Element;
@@ -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
- var field = useExtractUiSchema(uiSchema).field;
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
- var schemaType = getSchemaType(schema);
14
+ let schemaType = getSchemaType(schema);
26
15
  if (Array.isArray(schemaType)) {
27
16
  schemaType = schemaType[0];
28
17
  }
29
- var componentName = COMPONENT_TYPES[schemaType || "any"];
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
- var schema = props.schema, uiSchema = props.uiSchema;
36
- var fields = useContext(FormRegistry).fields;
37
- var FieldComponent = useFieldComponent(schema, uiSchema, fields);
38
- return _jsx(FieldComponent, __assign({}, props));
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,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldProps } from "../types";
3
+ export declare function SearchMultiTagSelectField(props: FieldProps): JSX.Element;
@@ -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 = useContext(FormRegistry), FieldTemplate = _a.templates.FieldTemplate, FieldInput = _a.components.FieldInput;
6
+ var _a;
7
+ const { templates: { FieldTemplate }, components: { FieldInput }, } = useContext(FormRegistry);
49
8
  useSetDefault(props);
50
- var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
51
- var _b = useExtractUiSchema(uiSchema), type = _b.type, placeholder = _b.placeholder, inputProps = _b.props;
52
- var enums = useMemo(function () { return getEnums(props); }, [props]);
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, __assign({}, props, { children: _jsxs(FieldInput, __assign({}, __assign({ type: type, placeholder: placeholder }, inputProps), { name: name, formikAs: "select", multiple: enums.type === "multiSelect" }, { children: [enums.type !== "multiSelect" && (_jsx("option", __assign({ value: "", disabled: true, selected: true, hidden: true }, { children: placeholder }))), enums === null || enums === void 0 ? void 0 : enums.values.map(function (option, index) { return (_jsx("option", __assign({ value: option.const }, { children: option.title }), index)); })] })) })));
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, __assign({}, props, { children: _jsx(FieldInput, __assign({}, __assign({ type: type, placeholder: placeholder }, inputProps), { name: name })) })));
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,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldProps } from "../types";
3
+ export declare function ToggleField(props: FieldProps): JSX.Element;
@@ -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
+ }
@@ -7,3 +7,6 @@ export * from "./ObjectField";
7
7
  export * from "./SchemaField";
8
8
  export * from "./StringField";
9
9
  export * from "./AnyField";
10
+ export * from "./RadioField";
11
+ export * from "./ToggleField";
12
+ export * from "./SearchMultiTagSelectField";
@@ -7,3 +7,6 @@ export * from "./ObjectField";
7
7
  export * from "./SchemaField";
8
8
  export * from "./StringField";
9
9
  export * from "./AnyField";
10
+ export * from "./RadioField";
11
+ export * from "./ToggleField";
12
+ export * from "./SearchMultiTagSelectField";
@@ -1,4 +1,4 @@
1
- export var COMPONENT_TYPES = {
1
+ export const COMPONENT_TYPES = {
2
2
  array: "ArrayField",
3
3
  boolean: "BooleanField",
4
4
  integer: "NumberField",
@@ -1,4 +1,4 @@
1
- var field = {
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 var schema = {
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 var uiSchema = {
34
+ export const uiSchema = {
35
35
  "schema.type": { props: { type: "hidden" } },
36
36
  };