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