@nolwenture/formik-jsonschema-form 0.4.1 → 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,12 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- export var simpleSchema = {
2
+ export const simpleSchema = {
3
3
  title: "TITLE",
4
4
  properties: {
5
5
  firstName: { type: "string", title: "First name" },
6
6
  lastName: { type: "string", title: "Last name" },
7
+ age: { type: "number", title: "Age" },
7
8
  },
8
9
  };
9
- export var simpleUiSchema = {
10
+ export const simpleUiSchema = {
10
11
  "ui:description": "Description text",
11
12
  firstName: {
12
13
  "ui:info": {
@@ -14,7 +15,7 @@ export var simpleUiSchema = {
14
15
  },
15
16
  },
16
17
  };
17
- export var completeSchema = {
18
+ export const completeSchema = {
18
19
  title: "Inventory",
19
20
  type: "object",
20
21
  required: ["string", "number", "boolean", "enum"],
@@ -45,6 +46,7 @@ export var completeSchema = {
45
46
  title: "Enum",
46
47
  description: "Enum description",
47
48
  enum: [1, 2, 3, 4],
49
+ default: 1,
48
50
  },
49
51
  enumOneOf: {
50
52
  type: "number",
@@ -68,6 +70,20 @@ export var completeSchema = {
68
70
  { const: 4, title: "four" },
69
71
  ],
70
72
  },
73
+ enumTagSelectAnyOf: {
74
+ type: "string",
75
+ title: "Enum searchable tag select anyOf",
76
+ description: "Enum searchable tag select anyOf description",
77
+ anyOf: [
78
+ { const: "cat", title: "cat" },
79
+ { const: "dog", title: "dog" },
80
+ { const: "bunny", title: "bunny" },
81
+ { const: "canary", title: "canary" },
82
+ { const: "hamster", title: "hamster" },
83
+ { const: "goldfish", title: "goldfish" },
84
+ { const: "dragon", title: "dragon" },
85
+ ],
86
+ },
71
87
  null: { type: "null", title: "Null", description: "Null description" },
72
88
  nested: {
73
89
  type: "object",
@@ -188,7 +204,7 @@ export var completeSchema = {
188
204
  },
189
205
  },
190
206
  };
191
- export var completeUiSchema = {
207
+ export const completeUiSchema = {
192
208
  string: {
193
209
  "ui:help": "String help",
194
210
  "ui:options": {
@@ -213,8 +229,13 @@ export var completeUiSchema = {
213
229
  },
214
230
  enum: {
215
231
  "ui:help": "Enum help",
232
+ "ui:placeholderOptionOptions": {
233
+ props: { disabled: false, hidden: false },
234
+ },
235
+ },
236
+ enumOneOf: {
237
+ placeholder: "Select one",
216
238
  },
217
- enumOneOf: { placeholder: "Select one" },
218
239
  null: {
219
240
  "ui:help": "Null help",
220
241
  },
@@ -276,8 +297,15 @@ export var completeUiSchema = {
276
297
  },
277
298
  },
278
299
  },
300
+ enumTagSelectAnyOf: {
301
+ "ui:field": "SearchMultiTagSelectField",
302
+ "ui:options": {
303
+ placeholder: "Search...",
304
+ emptySearchMessage: "...no matching results found",
305
+ },
306
+ },
279
307
  };
280
- export var generatedSchema = {
308
+ export const generatedSchema = {
281
309
  type: "object",
282
310
  properties: {
283
311
  object: {
@@ -296,12 +324,14 @@ export var generatedSchema = {
296
324
  required: ["object", "value", "property"],
297
325
  additionalProperties: false,
298
326
  };
299
- export var requiredInputSchema = {
327
+ export const requiredInputSchema = {
300
328
  title: "TITLE",
301
- required: ["lastName"],
329
+ required: ["lastName", "requiredNestedObject", "requiredArray"],
302
330
  properties: {
303
331
  firstName: { type: "string", title: "First name" },
304
332
  lastName: { type: "string", title: "Last name" },
333
+ feeling: { type: "boolean", title: "Feeling happy today?" },
334
+ vibes: { type: "boolean", title: "Turn on the good vibes" },
305
335
  arrayOfObject: {
306
336
  type: "array",
307
337
  title: "Array of objects",
@@ -319,13 +349,13 @@ export var requiredInputSchema = {
319
349
  title: "Second favourites",
320
350
  required: ["secondFavouriteSong"],
321
351
  properties: {
322
- secondFavouriteFood: {
352
+ anotherFavouriteFood: {
323
353
  type: "string",
324
- title: "Second favourite food",
354
+ title: "Another favourite food",
325
355
  },
326
- secondFavouriteSong: {
356
+ anotherFavouriteSong: {
327
357
  type: "string",
328
- title: "Second favourite song",
358
+ title: "Another favourite song",
329
359
  },
330
360
  },
331
361
  },
@@ -339,5 +369,30 @@ export var requiredInputSchema = {
339
369
  tasks: { type: "string", title: "Tasks" },
340
370
  },
341
371
  },
372
+ requiredNestedObject: {
373
+ type: "object",
374
+ title: "Required Nested Object",
375
+ properties: {
376
+ plans: { type: "string", title: "Future plans" },
377
+ past: { type: "string", title: "Past achievements" },
378
+ },
379
+ },
380
+ requiredArray: {
381
+ type: "array",
382
+ title: "Required Array",
383
+ description: "Array description for required array",
384
+ additionalItems: {
385
+ type: "string",
386
+ },
387
+ },
388
+ },
389
+ };
390
+ export const requiredInputUiSchema = {
391
+ feeling: {
392
+ "ui:field": "RadioField",
393
+ "ui:label": { true: "yes", false: "no" },
394
+ },
395
+ vibes: {
396
+ "ui:field": "ToggleField",
342
397
  },
343
398
  };
@@ -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
+ }