@nolwenture/formik-jsonschema-form 0.4.2 → 0.6.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.
Files changed (88) hide show
  1. package/README.md +187 -0
  2. package/dist/Form.d.ts +2 -2
  3. package/dist/Form.js +15 -26
  4. package/dist/Form.stories.d.ts +12 -11
  5. package/dist/Form.stories.js +134 -101
  6. package/dist/Form.test.js +3 -3
  7. package/dist/FormEditor.d.ts +3 -3
  8. package/dist/FormEditor.js +14 -59
  9. package/dist/FormEditor.stories.d.ts +5 -4
  10. package/dist/FormEditor.stories.js +3 -16
  11. package/dist/fields/AnyField.d.ts +3 -3
  12. package/dist/fields/AnyField.js +12 -24
  13. package/dist/fields/ArrayField.d.ts +3 -3
  14. package/dist/fields/ArrayField.js +42 -64
  15. package/dist/fields/BooleanField.d.ts +3 -3
  16. package/dist/fields/BooleanField.js +7 -18
  17. package/dist/fields/DateField.d.ts +3 -3
  18. package/dist/fields/DateField.js +7 -18
  19. package/dist/fields/NullField.d.ts +3 -3
  20. package/dist/fields/NullField.js +5 -16
  21. package/dist/fields/NumberField.d.ts +3 -3
  22. package/dist/fields/NumberField.js +3 -14
  23. package/dist/fields/ObjectField.d.ts +3 -3
  24. package/dist/fields/ObjectField.js +43 -46
  25. package/dist/fields/RadioField.d.ts +3 -0
  26. package/dist/fields/RadioField.js +11 -0
  27. package/dist/fields/SchemaField.d.ts +3 -3
  28. package/dist/fields/SchemaField.js +13 -23
  29. package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
  30. package/dist/fields/SearchMultiTagSelectField.js +14 -0
  31. package/dist/fields/StringField.d.ts +3 -3
  32. package/dist/fields/StringField.js +13 -51
  33. package/dist/fields/ToggleField.d.ts +3 -0
  34. package/dist/fields/ToggleField.js +11 -0
  35. package/dist/fields/index.d.ts +3 -0
  36. package/dist/fields/index.js +3 -0
  37. package/dist/fields/types.js +1 -1
  38. package/dist/formEditorSchemas.d.ts +1 -1
  39. package/dist/formEditorSchemas.js +3 -3
  40. package/dist/hooks/index.d.ts +2 -0
  41. package/dist/hooks/index.js +2 -0
  42. package/dist/hooks/useExtractUiSchema.d.ts +8 -0
  43. package/dist/hooks/useExtractUiSchema.js +22 -0
  44. package/dist/hooks/useSetDefault.d.ts +2 -0
  45. package/dist/hooks/useSetDefault.js +16 -0
  46. package/dist/sampleData/completeSchema.d.ts +3 -0
  47. package/dist/{_sampleData.js → sampleData/completeSchema.js} +28 -97
  48. package/dist/sampleData/conditionsSchema.d.ts +3 -0
  49. package/dist/sampleData/conditionsSchema.js +80 -0
  50. package/dist/sampleData/generatedSchema.d.ts +2 -0
  51. package/dist/sampleData/generatedSchema.js +19 -0
  52. package/dist/sampleData/index.d.ts +5 -0
  53. package/dist/sampleData/index.js +5 -0
  54. package/dist/sampleData/requiredInputSchema.d.ts +3 -0
  55. package/dist/sampleData/requiredInputSchema.js +72 -0
  56. package/dist/sampleData/simpleData.d.ts +7 -0
  57. package/dist/sampleData/simpleData.js +16 -0
  58. package/dist/styledComponents.d.ts +193 -47
  59. package/dist/styledComponents.js +342 -138
  60. package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
  61. package/dist/templates/ArrayFieldTemplate.js +11 -23
  62. package/dist/templates/FieldTemplate.d.ts +3 -3
  63. package/dist/templates/FieldTemplate.js +11 -23
  64. package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
  65. package/dist/templates/ObjectFieldTemplate.js +13 -23
  66. package/dist/types.d.ts +34 -3
  67. package/dist/utils/__tests/getEnums.test.d.ts +1 -0
  68. package/dist/utils/__tests/getEnums.test.js +64 -0
  69. package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
  70. package/dist/utils/__tests/resolveSchema.test.js +106 -0
  71. package/dist/utils/deepEqual.d.ts +1 -0
  72. package/dist/utils/deepEqual.js +18 -0
  73. package/dist/utils/getEnums.d.ts +10 -0
  74. package/dist/utils/getEnums.js +30 -0
  75. package/dist/utils/getTitleAndDescription.d.ts +12 -0
  76. package/dist/utils/getTitleAndDescription.js +15 -0
  77. package/dist/utils/getTypes.d.ts +5 -0
  78. package/dist/utils/getTypes.js +53 -0
  79. package/dist/utils/index.d.ts +7 -0
  80. package/dist/utils/index.js +14 -0
  81. package/dist/utils/mergeSchemas.d.ts +1 -0
  82. package/dist/utils/mergeSchemas.js +26 -0
  83. package/dist/utils/resolveSchema.d.ts +2 -0
  84. package/dist/utils/resolveSchema.js +68 -0
  85. package/package.json +32 -37
  86. package/dist/_sampleData.d.ts +0 -11
  87. package/dist/utils.d.ts +0 -25
  88. package/dist/utils.js +0 -125
@@ -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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,57 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19
8
  });
20
9
  };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
49
- import { Formik } from "formik";
50
11
  import { useEffect, useState } from "react";
12
+ import { Formik } from "formik";
51
13
  import { Form } from "./Form";
52
14
  import * as formEditorSchemas from "./formEditorSchemas";
53
- export function FormEditor(props) {
54
- var _this = this;
55
- var _a = useState({
15
+ export const FormEditor = (props) => {
16
+ const [editorGeneratedSchemas, setEditorGeneratedSchemas] = useState({
56
17
  schema: {},
57
18
  uiSchema: {},
58
- }), editorGeneratedSchemas = _a[0], setEditorGeneratedSchemas = _a[1];
59
- useEffect(function () { return console.log(editorGeneratedSchemas); }, [editorGeneratedSchemas]);
60
- return (_jsxs("div", __assign({ style: { display: "flex", justifyContent: "space-between" } }, { children: [_jsxs("div", { children: [_jsx("h1", { children: "Editor" }), _jsx(Formik, __assign({ initialValues: { schema: {}, uiSchema: {} }, onSubmit: function (values, formikHelpers) { return __awaiter(_this, void 0, void 0, function () {
61
- return __generator(this, function (_a) {
62
- setEditorGeneratedSchemas(values);
63
- formikHelpers.setSubmitting(false);
64
- return [2 /*return*/];
65
- });
66
- }); } }, { children: _jsx(Form, __assign({}, formEditorSchemas)) }))] }), _jsxs("div", { children: [_jsx("h1", { children: "Preview" }), _jsx(Formik, __assign({ initialValues: {}, onSubmit: function (values, formikHelpers) { return __awaiter(_this, void 0, void 0, function () {
67
- return __generator(this, function (_a) {
68
- // action("onSubmit(_, formHelper)")(formikHelpers);
69
- // action("onSubmit(values)")(values);
70
- formikHelpers.setSubmitting(false);
71
- return [2 /*return*/];
72
- });
73
- }); } }, { children: _jsx(Form, __assign({}, editorGeneratedSchemas)) }))] })] })));
74
- }
19
+ });
20
+ useEffect(() => console.log(editorGeneratedSchemas), [editorGeneratedSchemas]);
21
+ return (_jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [_jsxs("div", { children: [_jsx("h1", { children: "Editor" }), _jsx(Formik, { initialValues: { schema: {}, uiSchema: {} }, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
22
+ setEditorGeneratedSchemas(values);
23
+ formikHelpers.setSubmitting(false);
24
+ }), children: _jsx(Form, Object.assign({}, formEditorSchemas)) })] }), _jsxs("div", { children: [_jsx("h1", { children: "Preview" }), _jsx(Formik, { initialValues: {}, onSubmit: (values, formikHelpers) => __awaiter(void 0, void 0, void 0, function* () {
25
+ // action("onSubmit(_, formHelper)")(formikHelpers);
26
+ // action("onSubmit(values)")(values);
27
+ formikHelpers.setSubmitting(false);
28
+ }), children: _jsx(Form, Object.assign({}, editorGeneratedSchemas)) })] })] }));
29
+ };
@@ -1,5 +1,6 @@
1
- import { ComponentStory, ComponentMeta } from "@storybook/react";
1
+ import { StoryObj, Meta } from "@storybook/react";
2
2
  import { FormEditor } from "./FormEditor";
3
- declare const _default: ComponentMeta<typeof FormEditor>;
4
- export default _default;
5
- export declare const Default: ComponentStory<typeof FormEditor>;
3
+ declare const meta: Meta<typeof FormEditor>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof FormEditor>;
6
+ export declare const Default: Story;
@@ -1,22 +1,9 @@
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
- import { jsx as _jsx } from "react/jsx-runtime";
13
1
  import { FormEditor } from "./FormEditor";
14
- export default {
2
+ const meta = {
15
3
  title: "FormEditor",
16
4
  component: FormEditor,
17
5
  // More on argTypes: https://storybook.js.org/docs/react/api/argtypes
18
6
  argTypes: {},
19
7
  };
20
- var Template = function (args) { return (_jsx(FormEditor, __assign({}, args))); };
21
- export var Default = Template.bind({});
22
- Default.args = {};
8
+ export default meta;
9
+ export const Default = {};
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function AnyField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const AnyField: React.FC<FieldProps>;
@@ -1,34 +1,22 @@
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
- import { useMemo } from "react";
14
- import { useState } from "react";
2
+ import { useMemo, useState } from "react";
15
3
  import { useField } from "formik";
16
- import { SchemaField } from "./SchemaField";
17
4
  import { guessType } from "../utils";
5
+ import { SchemaField } from "./SchemaField";
18
6
  import { COMPONENT_TYPES } from "./types";
19
- 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 () {
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(() => {
24
12
  switch (type) {
25
13
  case "object":
26
- return __assign(__assign({}, (schema || {})), { type: type, additionalProperties: {} });
14
+ return Object.assign(Object.assign({}, (schema || {})), { type, additionalProperties: {} });
27
15
  case "array":
28
- return __assign(__assign({}, (schema || {})), { type: type, additionalItems: {} });
16
+ return Object.assign(Object.assign({}, (schema || {})), { type, additionalItems: {} });
29
17
  default:
30
- return __assign(__assign({}, (schema || {})), { type: type });
18
+ return Object.assign(Object.assign({}, (schema || {})), { type });
31
19
  }
32
20
  }, [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 })] }));
34
- }
21
+ return (_jsxs("div", { children: [_jsx("select", { value: type, onChange: (event) => setType(event.target.value), children: Object.keys(COMPONENT_TYPES).map((type) => (_jsx("option", { value: type, children: type }, type))) }), _jsx(SchemaField, { name: name, schema: enrichedSchema, uiSchema: uiSchema })] }));
22
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function ArrayField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const ArrayField: React.FC<FieldProps>;
@@ -1,72 +1,56 @@
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
- import { FormRegistry } from "../Form";
24
3
  import { useField } from "formik";
4
+ import { FormRegistry } from "../Form";
25
5
  import { ArrayFieldButtonPurpose } from "../types";
26
- import { useExtractUiSchema, useSetDefault } from "../utils";
6
+ import { useExtractUiSchema, useSetDefault } from "../hooks";
27
7
  import { GetArrayFieldButton } from "../styledComponents";
28
- function appendArray(values) {
29
- return values ? __spreadArray(__spreadArray([], values, true), [""], false) : [""];
30
- }
31
- function removeFromArray(values, index) {
32
- return __spreadArray(__spreadArray([], values.slice(0, index), true), values.slice(index + 1), true);
33
- }
34
- function moveInArray(values, index, direction) {
8
+ const appendArray = (values) => {
9
+ return values ? [...values, ""] : [""];
10
+ };
11
+ const removeFromArray = (values, index) => {
12
+ return [...values.slice(0, index), ...values.slice(index + 1)];
13
+ };
14
+ const 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
- }
48
- 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;
31
+ };
32
+ export const ArrayField = (props) => {
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,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function BooleanField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const BooleanField: React.FC<FieldProps>;
@@ -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
- import { useExtractUiSchema, useSetDefault } from "../utils";
16
- export function BooleanField(props) {
17
- var _a = useContext(FormRegistry), FieldTemplate = _a.templates.FieldTemplate, FieldInput = _a.components.FieldInput;
4
+ import { useExtractUiSchema, useSetDefault } from "../hooks";
5
+ export const BooleanField = (props) => {
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] }) })));
22
- }
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] }) })));
11
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function DateField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const DateField: React.FC<FieldProps>;
@@ -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
- import { useExtractUiSchema, useSetDefault } from "../utils";
16
- export function DateField(props) {
17
- var _a = useContext(FormRegistry), FieldTemplate = _a.templates.FieldTemplate, FieldInput = _a.components.FieldInput;
4
+ import { useExtractUiSchema, useSetDefault } from "../hooks";
5
+ export const DateField = (props) => {
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" })) })));
22
- }
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" })) })));
11
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function NullField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const NullField: React.FC<FieldProps>;
@@ -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
- export function NullField(props) {
16
- var FieldTemplate = useContext(FormRegistry).templates.FieldTemplate;
17
- var name = props.name;
18
- return _jsx(FieldTemplate, __assign({}, props));
19
- }
4
+ export const NullField = (props) => {
5
+ const { templates: { FieldTemplate }, } = useContext(FormRegistry);
6
+ const { name } = props;
7
+ return _jsx(FieldTemplate, Object.assign({}, props));
8
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function NumberField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const NumberField: React.FC<FieldProps>;
@@ -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
- export function NumberField(props) {
3
+ export const 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" }) }) })));
17
- }
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
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- import { FieldProps } from "../types";
3
- export declare function ObjectField(props: FieldProps): JSX.Element;
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const ObjectField: React.FC<FieldProps>;
@@ -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)
@@ -21,49 +10,57 @@ var __rest = (this && this.__rest) || function (s, e) {
21
10
  return t;
22
11
  };
23
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
- import { useField } from "formik";
25
- import { useContext, useMemo } from "react";
13
+ import { useField, useFormikContext } from "formik";
14
+ import { useContext, useEffect, useMemo } from "react";
26
15
  import { FormRegistry } from "../Form";
27
16
  import { ObjectFieldButtonPurpose } from "../types";
28
- import { useSetDefault } from "../utils";
17
+ import { resolveSchema } from "../utils";
18
+ import { useSetDefault } from "../hooks";
29
19
  import { getObjectFieldButton } from "../styledComponents";
30
- 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 useObjectField = (name) => {
21
+ if (!name) {
22
+ const { values = {}, setValues } = useFormikContext();
23
+ return { value: values, setValue: setValues };
24
+ }
25
+ const [{ value = {} }, _, { setValue }] = useField(name);
26
+ return { value, setValue };
27
+ };
28
+ export const ObjectField = (props) => {
29
+ const { fields: { SchemaField }, templates: { ObjectFieldTemplate }, components: { ObjectFieldItem, ObjectFieldItemButtons }, hideUnmarkedAdditionalProperties, } = useContext(FormRegistry);
32
30
  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 &&
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
+ 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) &&
48
+ 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({
49
+ purpose: ObjectFieldButtonPurpose.REMOVE,
50
+ onClick: () => {
51
+ const _a = value, _b = childName, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
52
+ setValue(newValue);
53
+ },
54
+ uiSchema: uiSchema,
55
+ }) })] }, childName))), additionalProperties &&
58
56
  getObjectFieldButton({
59
57
  purpose: ObjectFieldButtonPurpose.ADD,
60
- onClick: function () {
61
- var _a;
62
- var key = prompt("Give key");
58
+ onClick: () => {
59
+ const key = prompt("Give key");
63
60
  if (key) {
64
- setValue(__assign(__assign({}, value), (_a = {}, _a[key] = undefined, _a)));
61
+ setValue(Object.assign(Object.assign({}, value), { [key]: undefined }));
65
62
  }
66
63
  },
67
64
  uiSchema: uiSchema,
68
65
  })] })));
69
- }
66
+ };
@@ -0,0 +1,3 @@
1
+ import type { FieldProps } from "../types";
2
+ import React from "react";
3
+ export declare const RadioField: React.FC<FieldProps>;