@nolwenture/formik-jsonschema-form 0.1.0 → 0.1.2
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/package.json +90 -86
- package/src/Form.d.ts +4 -0
- package/src/Form.js +52 -0
- package/src/Form.stories.d.ts +11 -0
- package/src/Form.stories.js +135 -0
- package/src/Form.test.d.ts +1 -0
- package/src/Form.test.js +9 -0
- package/src/FormEditor.d.ts +8 -0
- package/src/FormEditor.js +74 -0
- package/src/FormEditor.stories.d.ts +5 -0
- package/src/FormEditor.stories.js +22 -0
- package/src/_sampleData.d.ts +10 -0
- package/src/_sampleData.js +262 -0
- package/src/fields/AnyField.d.ts +3 -0
- package/src/fields/AnyField.js +34 -0
- package/src/fields/ArrayField.d.ts +3 -0
- package/src/fields/ArrayField.js +119 -0
- package/src/fields/BooleanField.d.ts +3 -0
- package/src/fields/BooleanField.js +22 -0
- package/src/fields/DateField.d.ts +3 -0
- package/src/fields/DateField.js +22 -0
- package/src/fields/NullField.d.ts +3 -0
- package/src/fields/NullField.js +19 -0
- package/src/fields/NumberField.d.ts +3 -0
- package/src/fields/NumberField.js +17 -0
- package/src/fields/ObjectField.d.ts +3 -0
- package/src/fields/ObjectField.js +56 -0
- package/src/fields/SchemaField.d.ts +3 -0
- package/src/fields/SchemaField.js +39 -0
- package/src/fields/StringField.d.ts +3 -0
- package/src/fields/StringField.js +60 -0
- package/src/fields/{index.ts → index.d.ts} +0 -0
- package/src/fields/index.js +9 -0
- package/src/fields/types.d.ts +10 -0
- package/src/fields/types.js +10 -0
- package/src/formEditorSchemas.d.ts +3 -0
- package/src/formEditorSchemas.js +36 -0
- package/src/{index.tsx → index.d.ts} +0 -0
- package/src/index.js +5 -0
- package/src/setupTests.d.ts +1 -0
- package/src/{setupTests.ts → setupTests.js} +0 -0
- package/src/styledComponents.d.ts +26 -0
- package/src/styledComponents.js +89 -0
- package/src/templates/ArrayFieldTemplate.d.ts +3 -0
- package/src/templates/ArrayFieldTemplate.js +27 -0
- package/src/templates/FieldTemplate.d.ts +3 -0
- package/src/templates/FieldTemplate.js +27 -0
- package/src/templates/ObjectFieldTemplate.d.ts +3 -0
- package/src/templates/ObjectFieldTemplate.js +11 -0
- package/src/templates/{index.ts → index.d.ts} +0 -0
- package/src/templates/index.js +3 -0
- package/src/types.d.ts +168 -0
- package/src/types.js +14 -0
- package/src/utils.d.ts +22 -0
- package/src/utils.js +108 -0
- package/.storybook/main.js +0 -13
- package/.storybook/preview.js +0 -9
- package/README.md +0 -46
- package/src/Form.stories.tsx +0 -124
- package/src/Form.test.tsx +0 -10
- package/src/Form.tsx +0 -71
- package/src/FormEditor.stories.tsx +0 -17
- package/src/FormEditor.tsx +0 -53
- package/src/_sampleData.ts +0 -273
- package/src/fields/AnyField.tsx +0 -35
- package/src/fields/ArrayField.tsx +0 -177
- package/src/fields/BooleanField.tsx +0 -23
- package/src/fields/DateField.tsx +0 -20
- package/src/fields/NullField.tsx +0 -12
- package/src/fields/NumberField.tsx +0 -14
- package/src/fields/ObjectField.tsx +0 -68
- package/src/fields/SchemaField.tsx +0 -37
- package/src/fields/StringField.tsx +0 -89
- package/src/fields/types.tsx +0 -10
- package/src/formEditorSchemas.ts +0 -40
- package/src/styledComponents.tsx +0 -107
- package/src/templates/ArrayFieldTemplate.tsx +0 -46
- package/src/templates/FieldTemplate.tsx +0 -46
- package/src/templates/ObjectFieldTemplate.tsx +0 -22
- package/src/types.ts +0 -260
- package/src/utils.ts +0 -124
- package/tsconfig.json +0 -26
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
export var simpleSchema = {
|
|
2
|
+
title: "TITLE",
|
|
3
|
+
properties: {
|
|
4
|
+
firstName: { type: "string", title: "First name" },
|
|
5
|
+
lastName: { type: "string", title: "Last name" },
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
export var simpleUiSchema = {
|
|
9
|
+
"ui:description": "Description text",
|
|
10
|
+
};
|
|
11
|
+
export var completeSchema = {
|
|
12
|
+
title: "Inventory",
|
|
13
|
+
type: "object",
|
|
14
|
+
required: ["string", "number", "boolean", "enum"],
|
|
15
|
+
properties: {
|
|
16
|
+
string: {
|
|
17
|
+
type: "string",
|
|
18
|
+
title: "String",
|
|
19
|
+
description: "String description",
|
|
20
|
+
},
|
|
21
|
+
number: {
|
|
22
|
+
type: "number",
|
|
23
|
+
title: "Number",
|
|
24
|
+
description: "Number description",
|
|
25
|
+
},
|
|
26
|
+
date: {
|
|
27
|
+
type: "string",
|
|
28
|
+
title: "Date",
|
|
29
|
+
description: "Date description",
|
|
30
|
+
},
|
|
31
|
+
boolean: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
title: "Boolean",
|
|
34
|
+
description: "Boolean description",
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
enum: {
|
|
38
|
+
type: "number",
|
|
39
|
+
title: "Enum",
|
|
40
|
+
description: "Enum description",
|
|
41
|
+
enum: [1, 2, 3, 4],
|
|
42
|
+
},
|
|
43
|
+
enumOneOf: {
|
|
44
|
+
type: "number",
|
|
45
|
+
title: "Enum oneOf (non-standard)",
|
|
46
|
+
description: "Enum oneOf description",
|
|
47
|
+
oneOf: [
|
|
48
|
+
{ const: 1, title: "one" },
|
|
49
|
+
{ const: 2, title: "two" },
|
|
50
|
+
{ const: 3, title: "three" },
|
|
51
|
+
{ const: 4, title: "four" },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
enumAnyOf: {
|
|
55
|
+
type: "number",
|
|
56
|
+
title: "Enum anyOf (non-standard)",
|
|
57
|
+
description: "Enum anyOf description",
|
|
58
|
+
anyOf: [
|
|
59
|
+
{ const: 1, title: "one" },
|
|
60
|
+
{ const: 2, title: "two" },
|
|
61
|
+
{ const: 3, title: "three" },
|
|
62
|
+
{ const: 4, title: "four" },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
null: { type: "null", title: "Null", description: "Null description" },
|
|
66
|
+
nested: {
|
|
67
|
+
type: "object",
|
|
68
|
+
title: "Nested object",
|
|
69
|
+
description: "Nested object description",
|
|
70
|
+
properties: {
|
|
71
|
+
string: {
|
|
72
|
+
type: "string",
|
|
73
|
+
title: "Nested String",
|
|
74
|
+
description: "Nested String description",
|
|
75
|
+
},
|
|
76
|
+
number: {
|
|
77
|
+
type: "number",
|
|
78
|
+
title: "Nested Number",
|
|
79
|
+
description: "Nested Number description",
|
|
80
|
+
},
|
|
81
|
+
date: {
|
|
82
|
+
type: "string",
|
|
83
|
+
title: "Date",
|
|
84
|
+
description: "Date description",
|
|
85
|
+
},
|
|
86
|
+
boolean: {
|
|
87
|
+
type: "boolean",
|
|
88
|
+
title: "Nested Boolean",
|
|
89
|
+
description: "Nested Boolean description",
|
|
90
|
+
default: false,
|
|
91
|
+
},
|
|
92
|
+
enum: {
|
|
93
|
+
type: "number",
|
|
94
|
+
title: "Nested Enum",
|
|
95
|
+
description: "Nested Enum description",
|
|
96
|
+
enum: [1, 2, 3, 4],
|
|
97
|
+
},
|
|
98
|
+
null: {
|
|
99
|
+
type: "null",
|
|
100
|
+
title: "Nested Null",
|
|
101
|
+
description: "Nested Null description",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
additionalProperties: {
|
|
105
|
+
type: "string",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
array: {
|
|
109
|
+
type: "array",
|
|
110
|
+
title: "Array",
|
|
111
|
+
description: "Array description",
|
|
112
|
+
additionalItems: {
|
|
113
|
+
type: "string",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
partiallyFixedArray: {
|
|
117
|
+
type: "array",
|
|
118
|
+
title: "Partially fixed array",
|
|
119
|
+
description: "Partially fixed array description",
|
|
120
|
+
items: [{ type: "string", default: "Hello" }, { type: "string" }],
|
|
121
|
+
additionalItems: {
|
|
122
|
+
type: "string",
|
|
123
|
+
default: "defaultForAdditional",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
enumArray: {
|
|
127
|
+
type: "array",
|
|
128
|
+
title: "Enum array",
|
|
129
|
+
description: "Enum array description",
|
|
130
|
+
additionalItems: {
|
|
131
|
+
type: "number",
|
|
132
|
+
enum: [1, 2, 3, 4],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
objectArray: {
|
|
136
|
+
type: "array",
|
|
137
|
+
title: "Object array",
|
|
138
|
+
description: "Object array description",
|
|
139
|
+
additionalItems: {
|
|
140
|
+
type: "object",
|
|
141
|
+
title: "Array object",
|
|
142
|
+
description: "Array object description",
|
|
143
|
+
properties: {
|
|
144
|
+
string: {
|
|
145
|
+
type: "string",
|
|
146
|
+
title: "Array String",
|
|
147
|
+
description: "Array String description",
|
|
148
|
+
},
|
|
149
|
+
number: {
|
|
150
|
+
type: "number",
|
|
151
|
+
title: "Array Number",
|
|
152
|
+
description: "Array Number description",
|
|
153
|
+
},
|
|
154
|
+
date: {
|
|
155
|
+
type: "string",
|
|
156
|
+
title: "Date",
|
|
157
|
+
description: "Date description",
|
|
158
|
+
},
|
|
159
|
+
boolean: {
|
|
160
|
+
type: "boolean",
|
|
161
|
+
title: "Array Boolean",
|
|
162
|
+
description: "Array Boolean description",
|
|
163
|
+
default: false,
|
|
164
|
+
},
|
|
165
|
+
enum: {
|
|
166
|
+
type: "array",
|
|
167
|
+
title: "Array Enum",
|
|
168
|
+
description: "Array Enum description",
|
|
169
|
+
items: {
|
|
170
|
+
type: "number",
|
|
171
|
+
enum: [1, 2, 3, 4],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
null: {
|
|
175
|
+
type: "null",
|
|
176
|
+
title: "Array Null",
|
|
177
|
+
description: "Array Null description",
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
export var completeUiSchema = {
|
|
185
|
+
string: {
|
|
186
|
+
"ui:help": "String help",
|
|
187
|
+
"ui:options": {
|
|
188
|
+
placeholder: "String placeholder",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
number: {
|
|
192
|
+
"ui:help": "Number help",
|
|
193
|
+
"ui:options": {
|
|
194
|
+
placeholder: "Number placeholder",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
date: {
|
|
198
|
+
"ui:field": "DateField",
|
|
199
|
+
"ui:help": "Date help",
|
|
200
|
+
},
|
|
201
|
+
boolean: {
|
|
202
|
+
"ui:help": "Boolean help",
|
|
203
|
+
"ui:options": {
|
|
204
|
+
valueDescription: "Boolean specific label",
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
enum: {
|
|
208
|
+
"ui:help": "Enum help",
|
|
209
|
+
},
|
|
210
|
+
null: {
|
|
211
|
+
"ui:help": "Null help",
|
|
212
|
+
},
|
|
213
|
+
nested: {
|
|
214
|
+
string: {
|
|
215
|
+
"ui:help": "String help",
|
|
216
|
+
"ui:options": {
|
|
217
|
+
placeholder: "String placeholder",
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
number: {
|
|
221
|
+
"ui:help": "Number help",
|
|
222
|
+
"ui:options": {
|
|
223
|
+
placeholder: "Number placeholder",
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
date: {
|
|
227
|
+
"ui:field": "DateField",
|
|
228
|
+
"ui:help": "Date help",
|
|
229
|
+
},
|
|
230
|
+
boolean: {
|
|
231
|
+
"ui:help": "Boolean help",
|
|
232
|
+
"ui:options": {
|
|
233
|
+
valueDescription: "Boolean specific label",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
enum: {
|
|
237
|
+
"ui:help": "Enum help",
|
|
238
|
+
},
|
|
239
|
+
null: {
|
|
240
|
+
"ui:help": "Null help",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
export var generatedSchema = {
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: {
|
|
247
|
+
object: {
|
|
248
|
+
type: "object",
|
|
249
|
+
additionalProperties: {},
|
|
250
|
+
},
|
|
251
|
+
value: {},
|
|
252
|
+
array: {
|
|
253
|
+
type: "array",
|
|
254
|
+
items: {},
|
|
255
|
+
},
|
|
256
|
+
property: {
|
|
257
|
+
type: "string",
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
required: ["object", "value", "property"],
|
|
261
|
+
additionalProperties: false,
|
|
262
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from "react";
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { useField } from "formik";
|
|
16
|
+
import { SchemaField } from "./SchemaField";
|
|
17
|
+
import { guessType } from "../utils";
|
|
18
|
+
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 () {
|
|
24
|
+
switch (type) {
|
|
25
|
+
case "object":
|
|
26
|
+
return __assign(__assign({}, (schema || {})), { type: type, additionalProperties: {} });
|
|
27
|
+
case "array":
|
|
28
|
+
return __assign(__assign({}, (schema || {})), { type: type, additionalItems: {} });
|
|
29
|
+
default:
|
|
30
|
+
return __assign(__assign({}, (schema || {})), { type: type });
|
|
31
|
+
}
|
|
32
|
+
}, [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
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { useContext, useMemo } from "react";
|
|
23
|
+
import { FormRegistry } from "../Form";
|
|
24
|
+
import { useField } from "formik";
|
|
25
|
+
import { ArrayFieldButtonPurpose } from "../types";
|
|
26
|
+
import { useExtractUiSchema } from "../utils";
|
|
27
|
+
function appendArray(values) {
|
|
28
|
+
return values ? __spreadArray(__spreadArray([], values, true), [""], false) : [""];
|
|
29
|
+
}
|
|
30
|
+
function removeFromArray(values, index) {
|
|
31
|
+
return __spreadArray(__spreadArray([], values.slice(0, index), true), values.slice(index + 1), true);
|
|
32
|
+
}
|
|
33
|
+
function moveInArray(values, index, direction) {
|
|
34
|
+
if (direction === -1) {
|
|
35
|
+
return __spreadArray(__spreadArray(__spreadArray([], values.slice(0, index - 1), true), [
|
|
36
|
+
values[index],
|
|
37
|
+
values[index - 1]
|
|
38
|
+
], false), values.slice(index + 1), true);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return __spreadArray(__spreadArray(__spreadArray([], values.slice(0, index), true), [
|
|
42
|
+
values[index + 1],
|
|
43
|
+
values[index]
|
|
44
|
+
], false), values.slice(index + 2), true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function ArrayField(props) {
|
|
48
|
+
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ArrayFieldTemplate = _a.templates.ArrayFieldTemplate, _b = _a.components, ArrayFieldItem = _b.ArrayFieldItem, ArrayFieldList = _b.ArrayFieldList, ArrayFieldItemButtons = _b.ArrayFieldItemButtons, ArrayFieldButton = _b.ArrayFieldButton, useItemsAsAdditionalItems = _a.useItemsAsAdditionalItems;
|
|
49
|
+
var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
|
|
50
|
+
var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
|
|
51
|
+
var _d = useMemo(function () {
|
|
52
|
+
var items = schema.items && typeof schema.items !== "boolean" ? schema.items : [];
|
|
53
|
+
if (!Array.isArray(items)) {
|
|
54
|
+
items = [items];
|
|
55
|
+
}
|
|
56
|
+
return useItemsAsAdditionalItems && !schema.additionalItems
|
|
57
|
+
? {
|
|
58
|
+
items: [],
|
|
59
|
+
additionalItems: items.filter(function (item) { return typeof item !== "boolean"; })[0],
|
|
60
|
+
}
|
|
61
|
+
: {
|
|
62
|
+
items: items.filter(function (item) { return typeof item !== "boolean"; }),
|
|
63
|
+
additionalItems: typeof schema.additionalItems !== "boolean"
|
|
64
|
+
? schema.additionalItems
|
|
65
|
+
: undefined,
|
|
66
|
+
};
|
|
67
|
+
}, [schema]), items = _d.items, additionalItems = _d.additionalItems;
|
|
68
|
+
//This whole mess would give backwards compatibility, but maybe we don't do it
|
|
69
|
+
// const {
|
|
70
|
+
// items,
|
|
71
|
+
// additionalItems,
|
|
72
|
+
// }: {
|
|
73
|
+
// items: Schema[];
|
|
74
|
+
// additionalItems: Schema | undefined;
|
|
75
|
+
// } = useMemo(
|
|
76
|
+
// () =>
|
|
77
|
+
// !schema.additionalItems
|
|
78
|
+
// ? {
|
|
79
|
+
// additionalItems:
|
|
80
|
+
// typeof schema.items !== "boolean"
|
|
81
|
+
// ? Array.isArray(schema.items)
|
|
82
|
+
// ? typeof schema.items[0] !== "boolean"
|
|
83
|
+
// ? schema.items[0]
|
|
84
|
+
// : undefined
|
|
85
|
+
// : typeof schema.items !== "boolean"
|
|
86
|
+
// ? schema.items
|
|
87
|
+
// : undefined
|
|
88
|
+
// : undefined,
|
|
89
|
+
// items: [],
|
|
90
|
+
// }
|
|
91
|
+
// : {
|
|
92
|
+
// additionalItems:
|
|
93
|
+
// typeof schema.additionalItems !== "boolean"
|
|
94
|
+
// ? schema.additionalItems
|
|
95
|
+
// : undefined,
|
|
96
|
+
// items: schema.items
|
|
97
|
+
// ? Array.isArray(schema.items)
|
|
98
|
+
// ? (schema.items.filter(
|
|
99
|
+
// (item) => typeof item !== "boolean"
|
|
100
|
+
// ) as Schema[])
|
|
101
|
+
// : typeof schema.items !== "boolean"
|
|
102
|
+
// ? [schema.items]
|
|
103
|
+
// : []
|
|
104
|
+
// : [],
|
|
105
|
+
// },
|
|
106
|
+
// [schema]
|
|
107
|
+
// );
|
|
108
|
+
// Bacwards compatibility ends
|
|
109
|
+
var _e = useExtractUiSchema(uiSchema), inputProps = _e.props, disabled = _e.disabled;
|
|
110
|
+
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) }, index) })); }), ((value === null || value === void 0 ? void 0 : value.slice(items.length)) || []).map(function (_, index) { return (_jsxs(ArrayFieldItem, { children: [_jsx(SchemaField, __assign({}, __assign({ disabled: disabled }, inputProps), { name: "".concat(name, "[").concat(index + items.length, "]"), schema: additionalItems && typeof additionalItems !== "boolean"
|
|
111
|
+
? additionalItems
|
|
112
|
+
: {}, uiSchema: __assign({ disabled: disabled }, ((uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index + items.length]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items))) }), index), _jsxs(ArrayFieldItemButtons, { children: [_jsx(ArrayFieldButton, { purpose: ArrayFieldButtonPurpose.REMOVE, onClick: function () {
|
|
113
|
+
return setValue(removeFromArray(value, index + items.length));
|
|
114
|
+
} }), value.length > 1 && index > 0 && (_jsx(ArrayFieldButton, { purpose: ArrayFieldButtonPurpose.MOVE_UP, onClick: function () {
|
|
115
|
+
return setValue(moveInArray(value, index + items.length, -1));
|
|
116
|
+
} })), value.length > 1 && index < value.length - 1 && (_jsx(ArrayFieldButton, { purpose: ArrayFieldButtonPurpose.MOVE_DOWN, onClick: function () {
|
|
117
|
+
return setValue(moveInArray(value, index + items.length, 1));
|
|
118
|
+
} }))] })] })); })] }), additionalItems && (_jsx(ArrayFieldButton, { purpose: ArrayFieldButtonPurpose.ADD, onClick: function () { return setValue(appendArray(value)); } }))] })));
|
|
119
|
+
}
|
|
@@ -0,0 +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
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useContext } from "react";
|
|
14
|
+
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;
|
|
18
|
+
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
|
+
}
|
|
@@ -0,0 +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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useContext } from "react";
|
|
14
|
+
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;
|
|
18
|
+
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import { useContext } from "react";
|
|
14
|
+
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
import { StringField } from "./StringField";
|
|
14
|
+
export function NumberField(props) {
|
|
15
|
+
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
|
+
}
|
|
@@ -0,0 +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 __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
import { useField } from "formik";
|
|
25
|
+
import { useContext, useMemo } from "react";
|
|
26
|
+
import { FormRegistry } from "../Form";
|
|
27
|
+
import { ObjectFieldButtonPurpose } from "../types";
|
|
28
|
+
export function ObjectField(props) {
|
|
29
|
+
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ObjectFieldTemplate = _a.templates.ObjectFieldTemplate, _b = _a.components, ObjectFieldItem = _b.ObjectFieldItem, ObjectFieldList = _b.ObjectFieldList, ObjectFieldItemButtons = _b.ObjectFieldItemButtons, ObjectFieldButton = _b.ObjectFieldButton;
|
|
30
|
+
var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
|
|
31
|
+
var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
|
|
32
|
+
var properties = schema.properties, additionalProperties = schema.additionalProperties;
|
|
33
|
+
var propertyKeys = useMemo(function () { return Object.keys(properties || {}); }, [properties]);
|
|
34
|
+
var additionalValues = useMemo(function () {
|
|
35
|
+
return Object.fromEntries(Object.entries(value || {}).filter(function (_a) {
|
|
36
|
+
var key = _a[0], value = _a[1];
|
|
37
|
+
return !propertyKeys.includes(key);
|
|
38
|
+
}));
|
|
39
|
+
}, [value, propertyKeys]);
|
|
40
|
+
return (_jsxs(ObjectFieldTemplate, __assign({}, props, { children: [Object.entries(properties || {}).map(function (_a) {
|
|
41
|
+
var childName = _a[0], childSchema = _a[1];
|
|
42
|
+
return (_jsx(SchemaField, { name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName));
|
|
43
|
+
}), Object.entries(additionalValues || {}).map(function (_a) {
|
|
44
|
+
var childName = _a[0], childSchema = _a[1];
|
|
45
|
+
return (_jsxs(ObjectFieldItem, { children: [_jsx(SchemaField, { 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: _jsx(ObjectFieldButton, { purpose: ObjectFieldButtonPurpose.REMOVE, onClick: function () {
|
|
46
|
+
var _a = value, _b = childName, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
47
|
+
setValue(newValue);
|
|
48
|
+
} }) })] }));
|
|
49
|
+
}), additionalProperties && (_jsx(ObjectFieldButton, { purpose: ObjectFieldButtonPurpose.ADD, onClick: function () {
|
|
50
|
+
var _a;
|
|
51
|
+
var key = prompt("Give key");
|
|
52
|
+
if (key) {
|
|
53
|
+
setValue(__assign(__assign({}, value), (_a = {}, _a[key] = undefined, _a)));
|
|
54
|
+
}
|
|
55
|
+
} }))] })));
|
|
56
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
import { useContext } from "react";
|
|
14
|
+
import { useExtractUiSchema, getSchemaType } from "../utils";
|
|
15
|
+
import { FormRegistry } from "../Form";
|
|
16
|
+
import { COMPONENT_TYPES } from "./types";
|
|
17
|
+
function getFieldComponent(schema, uiSchema, fields) {
|
|
18
|
+
var field = useExtractUiSchema(uiSchema).field;
|
|
19
|
+
if (typeof field === "function") {
|
|
20
|
+
return field;
|
|
21
|
+
}
|
|
22
|
+
if (typeof field === "string" && field in fields) {
|
|
23
|
+
return fields[field];
|
|
24
|
+
}
|
|
25
|
+
var schemaType = getSchemaType(schema);
|
|
26
|
+
if (Array.isArray(schemaType)) {
|
|
27
|
+
schemaType = schemaType[0];
|
|
28
|
+
}
|
|
29
|
+
var componentName = COMPONENT_TYPES[schemaType || "any"];
|
|
30
|
+
return componentName in fields
|
|
31
|
+
? fields[componentName]
|
|
32
|
+
: fields.UnsupportedField;
|
|
33
|
+
}
|
|
34
|
+
export function SchemaField(props) {
|
|
35
|
+
var schema = props.schema, uiSchema = props.uiSchema;
|
|
36
|
+
var fields = useContext(FormRegistry).fields;
|
|
37
|
+
var FieldComponent = getFieldComponent(schema, uiSchema, fields);
|
|
38
|
+
return _jsx(FieldComponent, __assign({}, props));
|
|
39
|
+
}
|