@rjsf/core 6.0.0-beta.21 → 6.0.0-beta.23
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/dist/core.umd.js +1580 -1771
- package/dist/index.cjs +2019 -2206
- package/dist/index.cjs.map +4 -4
- package/dist/index.esm.js +2011 -2182
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +50 -12
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +114 -31
- package/lib/components/fields/ArrayField.d.ts +2 -197
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +518 -536
- package/lib/components/fields/BooleanField.js +2 -2
- package/lib/components/fields/FallbackField.d.ts +7 -0
- package/lib/components/fields/FallbackField.d.ts.map +1 -0
- package/lib/components/fields/FallbackField.js +72 -0
- package/lib/components/fields/LayoutGridField.d.ts +109 -191
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +417 -444
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +2 -3
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +5 -3
- package/lib/components/fields/ObjectField.d.ts +2 -68
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +166 -168
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +35 -22
- package/lib/components/fields/StringField.js +2 -2
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +2 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +2 -4
- package/lib/components/templates/BaseInputTemplate.js +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +12 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +5 -43
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +7 -87
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/HiddenWidget.js +2 -2
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -2
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +5 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +5 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -5
- package/src/components/Form.tsx +176 -43
- package/src/components/fields/ArrayField.tsx +849 -758
- package/src/components/fields/BooleanField.tsx +2 -2
- package/src/components/fields/FallbackField.tsx +157 -0
- package/src/components/fields/LayoutGridField.tsx +613 -600
- package/src/components/fields/LayoutMultiSchemaField.tsx +4 -5
- package/src/components/fields/MultiSchemaField.tsx +30 -25
- package/src/components/fields/ObjectField.tsx +315 -242
- package/src/components/fields/OptionalDataControlsField.tsx +1 -1
- package/src/components/fields/SchemaField.tsx +46 -70
- package/src/components/fields/StringField.tsx +2 -2
- package/src/components/fields/index.ts +2 -0
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +11 -16
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -13
- package/src/components/templates/BaseInputTemplate.tsx +2 -2
- package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -2
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +4 -4
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +8 -124
- package/src/components/widgets/CheckboxWidget.tsx +2 -1
- package/src/components/widgets/CheckboxesWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +11 -102
- package/src/components/widgets/HiddenWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +2 -1
- package/src/components/widgets/RatingWidget.tsx +2 -1
- package/src/components/widgets/SelectWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +2 -1
- package/src/getDefaultRegistry.ts +5 -1
- package/src/getTestRegistry.tsx +5 -1
package/dist/core.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/cloneDeep'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/pick'), require('lodash/set'), require('lodash/toPath'), require('lodash/isObject'), require('lodash/uniqueId'), require('react/jsx-runtime'), require('lodash/each'), require('lodash/flatten'), require('lodash/has'), require('lodash/includes'), require('lodash/intersection'), require('lodash/isFunction'), require('lodash/isEqual'), require('lodash/isPlainObject'), require('lodash/isString'), require('lodash/isUndefined'), require('lodash/last'), require('lodash/noop'), require('lodash/omit'), require('markdown-to-jsx'), require('lodash/unset'), require('@rjsf/validator-ajv8')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/cloneDeep', 'lodash/get', 'lodash/isEmpty', 'lodash/pick', 'lodash/set', 'lodash/toPath', 'lodash/isObject', 'lodash/uniqueId', 'react/jsx-runtime', 'lodash/each', 'lodash/flatten', 'lodash/has', 'lodash/includes', 'lodash/intersection', 'lodash/isFunction', 'lodash/isEqual', 'lodash/isPlainObject', 'lodash/isString', 'lodash/isUndefined', 'lodash/last', 'lodash/noop', 'lodash/omit', 'markdown-to-jsx', 'lodash/unset', '@rjsf/validator-ajv8'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.cloneDeep, global.
|
|
5
|
-
})(this, (function (exports, react, utils, cloneDeep,
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.cloneDeep, global.get, global.isEmpty, global._pick, global.set, global._toPath, global.isObject, global.uniqueId, global.jsxRuntime, global.each, global.flatten, global.has, global.includes, global.intersection, global.isFunction, global.isEqual, global.isPlainObject, global.isString, global.isUndefined, global.last, global.noop, global.omit3, global.Markdown, global.unset, global.validator));
|
|
5
|
+
})(this, (function (exports, react, utils, cloneDeep, get, isEmpty, _pick, set, _toPath, isObject, uniqueId, jsxRuntime, each, flatten, has, includes, intersection, isFunction, isEqual, isPlainObject, isString, isUndefined, last, noop, omit3, Markdown, unset, validator) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/components/Form.tsx
|
|
8
8
|
function generateRowId() {
|
|
@@ -22,176 +22,610 @@
|
|
|
22
22
|
}
|
|
23
23
|
return [];
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @param props - The `FieldProps` for this template
|
|
29
|
-
*/
|
|
30
|
-
constructor(props) {
|
|
31
|
-
super(props);
|
|
32
|
-
const { formData } = props;
|
|
33
|
-
const keyedFormData = generateKeyedFormData(formData);
|
|
34
|
-
this.state = {
|
|
35
|
-
keyedFormData,
|
|
36
|
-
updatedKeyedFormData: false
|
|
37
|
-
};
|
|
25
|
+
function isItemRequired(itemSchema) {
|
|
26
|
+
if (Array.isArray(itemSchema.type)) {
|
|
27
|
+
return !itemSchema.type.includes("null");
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
updatedKeyedFormData: false
|
|
49
|
-
};
|
|
29
|
+
return itemSchema.type !== "null";
|
|
30
|
+
}
|
|
31
|
+
function canAddItem(registry, schema, formItems, uiSchema) {
|
|
32
|
+
let { addable } = utils.getUiOptions(uiSchema, registry.globalUiOptions);
|
|
33
|
+
if (addable !== false) {
|
|
34
|
+
if (schema.maxItems !== void 0) {
|
|
35
|
+
addable = formItems.length < schema.maxItems;
|
|
36
|
+
} else {
|
|
37
|
+
addable = true;
|
|
50
38
|
}
|
|
51
|
-
const nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
|
|
52
|
-
const previousKeyedFormData = prevState.keyedFormData || [];
|
|
53
|
-
const newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => {
|
|
54
|
-
return {
|
|
55
|
-
key: previousKeyedFormDatum.key,
|
|
56
|
-
item: nextFormData[index]
|
|
57
|
-
};
|
|
58
|
-
}) : generateKeyedFormData(nextFormData);
|
|
59
|
-
return {
|
|
60
|
-
keyedFormData: newKeyedFormData
|
|
61
|
-
};
|
|
62
39
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
/** Determines whether the item described in the schema is always required, which is determined by whether any item
|
|
76
|
-
* may be null.
|
|
77
|
-
*
|
|
78
|
-
* @param itemSchema - The schema for the item
|
|
79
|
-
* @return - True if the item schema type does not contain the "null" type
|
|
80
|
-
*/
|
|
81
|
-
isItemRequired(itemSchema) {
|
|
82
|
-
if (Array.isArray(itemSchema.type)) {
|
|
83
|
-
return !itemSchema.type.includes("null");
|
|
40
|
+
return addable;
|
|
41
|
+
}
|
|
42
|
+
function computeItemUiSchema(uiSchema, item, index, formContext) {
|
|
43
|
+
if (typeof uiSchema.items === "function") {
|
|
44
|
+
try {
|
|
45
|
+
const result = uiSchema.items(item, index, formContext);
|
|
46
|
+
return result;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
49
|
+
return void 0;
|
|
84
50
|
}
|
|
85
|
-
|
|
51
|
+
} else {
|
|
52
|
+
return uiSchema.items;
|
|
86
53
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
54
|
+
}
|
|
55
|
+
function getNewFormDataRow(registry, schema) {
|
|
56
|
+
const { schemaUtils } = registry;
|
|
57
|
+
let itemSchema = schema.items;
|
|
58
|
+
if (utils.isFixedItems(schema) && utils.allowAdditionalItems(schema)) {
|
|
59
|
+
itemSchema = schema.additionalItems;
|
|
60
|
+
}
|
|
61
|
+
return schemaUtils.getDefaultFormState(itemSchema);
|
|
62
|
+
}
|
|
63
|
+
function ArrayAsMultiSelect(props) {
|
|
64
|
+
const {
|
|
65
|
+
schema,
|
|
66
|
+
fieldPathId,
|
|
67
|
+
uiSchema,
|
|
68
|
+
formData: items = [],
|
|
69
|
+
disabled = false,
|
|
70
|
+
readonly = false,
|
|
71
|
+
autofocus = false,
|
|
72
|
+
required = false,
|
|
73
|
+
placeholder,
|
|
74
|
+
onBlur,
|
|
75
|
+
onFocus,
|
|
76
|
+
registry,
|
|
77
|
+
rawErrors,
|
|
78
|
+
name,
|
|
79
|
+
onSelectChange
|
|
80
|
+
} = props;
|
|
81
|
+
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
|
|
82
|
+
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
83
|
+
const enumOptions = utils.optionsList(itemsSchema, uiSchema);
|
|
84
|
+
const { widget = "select", title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
85
|
+
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
86
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
87
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
88
|
+
const multiValueFieldPathId = utils.useDeepCompareMemo(utils.toFieldPathId("", globalFormOptions, fieldPathId, true));
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
Widget,
|
|
91
|
+
{
|
|
92
|
+
id: multiValueFieldPathId[utils.ID_KEY],
|
|
93
|
+
name,
|
|
94
|
+
multiple: true,
|
|
95
|
+
onChange: onSelectChange,
|
|
96
|
+
onBlur,
|
|
97
|
+
onFocus,
|
|
98
|
+
options: { ...options, enumOptions },
|
|
99
|
+
schema,
|
|
100
|
+
uiSchema,
|
|
101
|
+
registry,
|
|
102
|
+
value: items,
|
|
103
|
+
disabled,
|
|
104
|
+
readonly,
|
|
105
|
+
required,
|
|
106
|
+
label,
|
|
107
|
+
hideLabel: !displayLabel,
|
|
108
|
+
placeholder,
|
|
109
|
+
autofocus,
|
|
110
|
+
rawErrors,
|
|
111
|
+
htmlName: multiValueFieldPathId.name
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
function ArrayAsCustomWidget(props) {
|
|
116
|
+
const {
|
|
117
|
+
schema,
|
|
118
|
+
fieldPathId,
|
|
119
|
+
uiSchema,
|
|
120
|
+
disabled = false,
|
|
121
|
+
readonly = false,
|
|
122
|
+
autofocus = false,
|
|
123
|
+
required = false,
|
|
124
|
+
hideError,
|
|
125
|
+
placeholder,
|
|
126
|
+
onBlur,
|
|
127
|
+
onFocus,
|
|
128
|
+
formData: items = [],
|
|
129
|
+
registry,
|
|
130
|
+
rawErrors,
|
|
131
|
+
name,
|
|
132
|
+
onSelectChange
|
|
133
|
+
} = props;
|
|
134
|
+
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
|
|
135
|
+
const { widget, title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
136
|
+
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
137
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
138
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
139
|
+
const multiValueFieldPathId = utils.useDeepCompareMemo(utils.toFieldPathId("", globalFormOptions, fieldPathId, true));
|
|
140
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
141
|
+
Widget,
|
|
142
|
+
{
|
|
143
|
+
id: multiValueFieldPathId[utils.ID_KEY],
|
|
144
|
+
name,
|
|
145
|
+
multiple: true,
|
|
146
|
+
onChange: onSelectChange,
|
|
147
|
+
onBlur,
|
|
148
|
+
onFocus,
|
|
149
|
+
options,
|
|
150
|
+
schema,
|
|
151
|
+
uiSchema,
|
|
152
|
+
registry,
|
|
153
|
+
value: items,
|
|
154
|
+
disabled,
|
|
155
|
+
readonly,
|
|
156
|
+
hideError,
|
|
157
|
+
required,
|
|
158
|
+
label,
|
|
159
|
+
hideLabel: !displayLabel,
|
|
160
|
+
placeholder,
|
|
161
|
+
autofocus,
|
|
162
|
+
rawErrors,
|
|
163
|
+
htmlName: multiValueFieldPathId.name
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function ArrayAsFiles(props) {
|
|
168
|
+
const {
|
|
169
|
+
schema,
|
|
170
|
+
uiSchema,
|
|
171
|
+
fieldPathId,
|
|
172
|
+
name,
|
|
173
|
+
disabled = false,
|
|
174
|
+
readonly = false,
|
|
175
|
+
autofocus = false,
|
|
176
|
+
required = false,
|
|
177
|
+
onBlur,
|
|
178
|
+
onFocus,
|
|
179
|
+
registry,
|
|
180
|
+
formData: items = [],
|
|
181
|
+
rawErrors,
|
|
182
|
+
onSelectChange
|
|
183
|
+
} = props;
|
|
184
|
+
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
|
|
185
|
+
const { widget = "files", title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
186
|
+
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
187
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
188
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
189
|
+
const multiValueFieldPathId = utils.useDeepCompareMemo(utils.toFieldPathId("", globalFormOptions, fieldPathId, true));
|
|
190
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
191
|
+
Widget,
|
|
192
|
+
{
|
|
193
|
+
options,
|
|
194
|
+
id: multiValueFieldPathId[utils.ID_KEY],
|
|
195
|
+
name,
|
|
196
|
+
multiple: true,
|
|
197
|
+
onChange: onSelectChange,
|
|
198
|
+
onBlur,
|
|
199
|
+
onFocus,
|
|
200
|
+
schema,
|
|
201
|
+
uiSchema,
|
|
202
|
+
value: items,
|
|
203
|
+
disabled,
|
|
204
|
+
readonly,
|
|
205
|
+
required,
|
|
206
|
+
registry,
|
|
207
|
+
autofocus,
|
|
208
|
+
rawErrors,
|
|
209
|
+
label,
|
|
210
|
+
hideLabel: !displayLabel,
|
|
211
|
+
htmlName: multiValueFieldPathId.name
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function ArrayFieldItem(props) {
|
|
216
|
+
const {
|
|
217
|
+
itemKey,
|
|
218
|
+
index,
|
|
219
|
+
name,
|
|
220
|
+
disabled,
|
|
221
|
+
hideError,
|
|
222
|
+
readonly,
|
|
223
|
+
registry,
|
|
224
|
+
uiOptions,
|
|
225
|
+
parentUiSchema,
|
|
226
|
+
canAdd,
|
|
227
|
+
canRemove = true,
|
|
228
|
+
canMoveUp,
|
|
229
|
+
canMoveDown,
|
|
230
|
+
itemSchema,
|
|
231
|
+
itemData,
|
|
232
|
+
itemUiSchema,
|
|
233
|
+
itemFieldPathId,
|
|
234
|
+
itemErrorSchema,
|
|
235
|
+
autofocus,
|
|
236
|
+
onBlur,
|
|
237
|
+
onFocus,
|
|
238
|
+
onChange,
|
|
239
|
+
rawErrors,
|
|
240
|
+
totalItems,
|
|
241
|
+
title,
|
|
242
|
+
handleAddItem,
|
|
243
|
+
handleCopyItem,
|
|
244
|
+
handleRemoveItem,
|
|
245
|
+
handleReorderItems
|
|
246
|
+
} = props;
|
|
247
|
+
const {
|
|
248
|
+
fields: { ArraySchemaField, SchemaField: SchemaField2 }
|
|
249
|
+
} = registry;
|
|
250
|
+
const fieldPathId = utils.useDeepCompareMemo(itemFieldPathId);
|
|
251
|
+
const ItemSchemaField = ArraySchemaField || SchemaField2;
|
|
252
|
+
const ArrayFieldItemTemplate2 = utils.getTemplate(
|
|
253
|
+
"ArrayFieldItemTemplate",
|
|
254
|
+
registry,
|
|
255
|
+
uiOptions
|
|
256
|
+
);
|
|
257
|
+
const { orderable = true, removable = true, copyable = false } = uiOptions;
|
|
258
|
+
const has4 = {
|
|
259
|
+
moveUp: orderable && canMoveUp,
|
|
260
|
+
moveDown: orderable && canMoveDown,
|
|
261
|
+
copy: copyable && canAdd,
|
|
262
|
+
remove: removable && canRemove,
|
|
263
|
+
toolbar: false
|
|
264
|
+
};
|
|
265
|
+
has4.toolbar = Object.keys(has4).some((key) => has4[key]);
|
|
266
|
+
const onAddItem = react.useCallback(
|
|
267
|
+
(event) => {
|
|
268
|
+
handleAddItem(event, index + 1);
|
|
269
|
+
},
|
|
270
|
+
[handleAddItem, index]
|
|
271
|
+
);
|
|
272
|
+
const onCopyItem = react.useCallback(
|
|
273
|
+
(event) => {
|
|
274
|
+
handleCopyItem(event, index);
|
|
275
|
+
},
|
|
276
|
+
[handleCopyItem, index]
|
|
277
|
+
);
|
|
278
|
+
const onRemoveItem = react.useCallback(
|
|
279
|
+
(event) => {
|
|
280
|
+
handleRemoveItem(event, index);
|
|
281
|
+
},
|
|
282
|
+
[handleRemoveItem, index]
|
|
283
|
+
);
|
|
284
|
+
const onMoveUpItem = react.useCallback(
|
|
285
|
+
(event) => {
|
|
286
|
+
handleReorderItems(event, index, index - 1);
|
|
287
|
+
},
|
|
288
|
+
[handleReorderItems, index]
|
|
289
|
+
);
|
|
290
|
+
const onMoveDownItem = react.useCallback(
|
|
291
|
+
(event) => {
|
|
292
|
+
handleReorderItems(event, index, index + 1);
|
|
293
|
+
},
|
|
294
|
+
[handleReorderItems, index]
|
|
295
|
+
);
|
|
296
|
+
const templateProps = {
|
|
297
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
298
|
+
ItemSchemaField,
|
|
299
|
+
{
|
|
300
|
+
name,
|
|
301
|
+
title,
|
|
302
|
+
index,
|
|
303
|
+
schema: itemSchema,
|
|
304
|
+
uiSchema: itemUiSchema,
|
|
305
|
+
formData: itemData,
|
|
306
|
+
errorSchema: itemErrorSchema,
|
|
307
|
+
fieldPathId,
|
|
308
|
+
required: isItemRequired(itemSchema),
|
|
309
|
+
onChange,
|
|
310
|
+
onBlur,
|
|
311
|
+
onFocus,
|
|
312
|
+
registry,
|
|
313
|
+
disabled,
|
|
314
|
+
readonly,
|
|
315
|
+
hideError,
|
|
316
|
+
autofocus,
|
|
317
|
+
rawErrors
|
|
318
|
+
}
|
|
319
|
+
),
|
|
320
|
+
buttonsProps: {
|
|
321
|
+
fieldPathId,
|
|
322
|
+
disabled,
|
|
323
|
+
readonly,
|
|
324
|
+
canAdd,
|
|
325
|
+
hasCopy: has4.copy,
|
|
326
|
+
hasMoveUp: has4.moveUp,
|
|
327
|
+
hasMoveDown: has4.moveDown,
|
|
328
|
+
hasRemove: has4.remove,
|
|
329
|
+
index,
|
|
330
|
+
totalItems,
|
|
331
|
+
onAddItem,
|
|
332
|
+
onCopyItem,
|
|
333
|
+
onRemoveItem,
|
|
334
|
+
onMoveUpItem,
|
|
335
|
+
onMoveDownItem,
|
|
336
|
+
registry,
|
|
337
|
+
schema: itemSchema,
|
|
338
|
+
uiSchema: itemUiSchema
|
|
339
|
+
},
|
|
340
|
+
itemKey,
|
|
341
|
+
className: "rjsf-array-item",
|
|
342
|
+
disabled,
|
|
343
|
+
hasToolbar: has4.toolbar,
|
|
344
|
+
index,
|
|
345
|
+
totalItems,
|
|
346
|
+
readonly,
|
|
347
|
+
registry,
|
|
348
|
+
schema: itemSchema,
|
|
349
|
+
uiSchema: itemUiSchema,
|
|
350
|
+
parentUiSchema
|
|
351
|
+
};
|
|
352
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItemTemplate2, { ...templateProps });
|
|
353
|
+
}
|
|
354
|
+
function NormalArray(props) {
|
|
355
|
+
const {
|
|
356
|
+
schema,
|
|
357
|
+
uiSchema = {},
|
|
358
|
+
errorSchema,
|
|
359
|
+
fieldPathId,
|
|
360
|
+
formData: formDataFromProps,
|
|
361
|
+
name,
|
|
362
|
+
title,
|
|
363
|
+
disabled = false,
|
|
364
|
+
readonly = false,
|
|
365
|
+
autofocus = false,
|
|
366
|
+
required = false,
|
|
367
|
+
hideError = false,
|
|
368
|
+
registry,
|
|
369
|
+
onBlur,
|
|
370
|
+
onFocus,
|
|
371
|
+
rawErrors,
|
|
372
|
+
onChange,
|
|
373
|
+
keyedFormData,
|
|
374
|
+
handleAddItem,
|
|
375
|
+
handleCopyItem,
|
|
376
|
+
handleRemoveItem,
|
|
377
|
+
handleReorderItems
|
|
378
|
+
} = props;
|
|
379
|
+
const fieldTitle = schema.title || title || name;
|
|
380
|
+
const { schemaUtils, fields: fields2, formContext, globalFormOptions, globalUiOptions } = registry;
|
|
381
|
+
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
382
|
+
const uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
383
|
+
const _schemaItems = isObject(schema.items) ? schema.items : {};
|
|
384
|
+
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
385
|
+
const formData = keyedToPlainFormData(keyedFormData);
|
|
386
|
+
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
387
|
+
const hasFormData = utils.isFormDataAvailable(formDataFromProps);
|
|
388
|
+
const canAdd = canAddItem(registry, schema, formData, uiSchema) && (!renderOptionalField || hasFormData);
|
|
389
|
+
const actualFormData = hasFormData ? keyedFormData : [];
|
|
390
|
+
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
|
|
391
|
+
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...props }) : void 0;
|
|
392
|
+
const arrayProps = {
|
|
393
|
+
canAdd,
|
|
394
|
+
items: actualFormData.map((keyedItem, index) => {
|
|
395
|
+
const { key, item } = keyedItem;
|
|
396
|
+
const itemCast = item;
|
|
397
|
+
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
398
|
+
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
399
|
+
const itemFieldPathId = utils.toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
400
|
+
const itemUiSchema = computeItemUiSchema(uiSchema, item, index, formContext);
|
|
401
|
+
const itemProps = {
|
|
402
|
+
itemKey: key,
|
|
403
|
+
index,
|
|
404
|
+
name: name && `${name}-${index}`,
|
|
405
|
+
registry,
|
|
406
|
+
uiOptions,
|
|
407
|
+
hideError,
|
|
408
|
+
readonly,
|
|
409
|
+
disabled,
|
|
410
|
+
required,
|
|
411
|
+
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
412
|
+
canAdd,
|
|
413
|
+
canMoveUp: index > 0,
|
|
414
|
+
canMoveDown: index < formData.length - 1,
|
|
415
|
+
itemSchema,
|
|
416
|
+
itemFieldPathId,
|
|
417
|
+
itemErrorSchema,
|
|
418
|
+
itemData: itemCast,
|
|
419
|
+
itemUiSchema,
|
|
420
|
+
autofocus: autofocus && index === 0,
|
|
421
|
+
onBlur,
|
|
422
|
+
onFocus,
|
|
423
|
+
rawErrors,
|
|
424
|
+
totalItems: keyedFormData.length,
|
|
425
|
+
handleAddItem,
|
|
426
|
+
handleCopyItem,
|
|
427
|
+
handleRemoveItem,
|
|
428
|
+
handleReorderItems,
|
|
429
|
+
onChange
|
|
430
|
+
};
|
|
431
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItem, { ...itemProps }, key);
|
|
432
|
+
}),
|
|
433
|
+
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}${extraClass}`,
|
|
434
|
+
disabled,
|
|
435
|
+
fieldPathId,
|
|
436
|
+
uiSchema,
|
|
437
|
+
onAddClick: handleAddItem,
|
|
438
|
+
readonly,
|
|
439
|
+
required,
|
|
440
|
+
schema,
|
|
441
|
+
title: fieldTitle,
|
|
442
|
+
formData,
|
|
443
|
+
rawErrors,
|
|
444
|
+
registry,
|
|
445
|
+
optionalDataControl
|
|
446
|
+
};
|
|
447
|
+
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
448
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...arrayProps });
|
|
449
|
+
}
|
|
450
|
+
function FixedArray(props) {
|
|
451
|
+
const {
|
|
452
|
+
schema,
|
|
453
|
+
uiSchema = {},
|
|
454
|
+
formData,
|
|
455
|
+
errorSchema,
|
|
456
|
+
fieldPathId,
|
|
457
|
+
name,
|
|
458
|
+
title,
|
|
459
|
+
disabled = false,
|
|
460
|
+
readonly = false,
|
|
461
|
+
autofocus = false,
|
|
462
|
+
required = false,
|
|
463
|
+
hideError = false,
|
|
464
|
+
registry,
|
|
465
|
+
onBlur,
|
|
466
|
+
onFocus,
|
|
467
|
+
rawErrors,
|
|
468
|
+
keyedFormData,
|
|
469
|
+
onChange,
|
|
470
|
+
handleAddItem,
|
|
471
|
+
handleCopyItem,
|
|
472
|
+
handleRemoveItem,
|
|
473
|
+
handleReorderItems
|
|
474
|
+
} = props;
|
|
475
|
+
let { formData: items = [] } = props;
|
|
476
|
+
const fieldTitle = schema.title || title || name;
|
|
477
|
+
const { schemaUtils, fields: fields2, formContext, globalFormOptions, globalUiOptions } = registry;
|
|
478
|
+
const uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
479
|
+
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
480
|
+
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
481
|
+
const hasFormData = utils.isFormDataAvailable(formData);
|
|
482
|
+
const _schemaItems = isObject(schema.items) ? schema.items : [];
|
|
483
|
+
const itemSchemas = _schemaItems.map(
|
|
484
|
+
(item, index) => schemaUtils.retrieveSchema(item, items[index])
|
|
485
|
+
);
|
|
486
|
+
const additionalSchema = isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
487
|
+
if (items.length < itemSchemas.length) {
|
|
488
|
+
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
489
|
+
}
|
|
490
|
+
const actualFormData = hasFormData ? keyedFormData : [];
|
|
491
|
+
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
|
|
492
|
+
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...props }) : void 0;
|
|
493
|
+
const canAdd = canAddItem(registry, schema, items, uiSchema) && !!additionalSchema && (!renderOptionalField || hasFormData);
|
|
494
|
+
const arrayProps = {
|
|
495
|
+
canAdd,
|
|
496
|
+
className: `rjsf-field rjsf-field-array rjsf-field-array-fixed-items${extraClass}`,
|
|
497
|
+
disabled,
|
|
498
|
+
fieldPathId,
|
|
499
|
+
formData,
|
|
500
|
+
items: actualFormData.map((keyedItem, index) => {
|
|
501
|
+
const { key, item } = keyedItem;
|
|
502
|
+
const itemCast = item;
|
|
503
|
+
const additional = index >= itemSchemas.length;
|
|
504
|
+
const itemSchema = (additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
505
|
+
const itemFieldPathId = utils.toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
506
|
+
let itemUiSchema;
|
|
507
|
+
if (additional) {
|
|
508
|
+
itemUiSchema = uiSchema.additionalItems;
|
|
100
509
|
} else {
|
|
101
|
-
|
|
510
|
+
if (Array.isArray(uiSchema.items)) {
|
|
511
|
+
itemUiSchema = uiSchema.items[index];
|
|
512
|
+
} else {
|
|
513
|
+
itemUiSchema = computeItemUiSchema(uiSchema, item, index, formContext);
|
|
514
|
+
}
|
|
102
515
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
516
|
+
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
517
|
+
const itemProps = {
|
|
518
|
+
index,
|
|
519
|
+
itemKey: key,
|
|
520
|
+
name: name && `${name}-${index}`,
|
|
521
|
+
registry,
|
|
522
|
+
uiOptions,
|
|
523
|
+
hideError,
|
|
524
|
+
readonly,
|
|
525
|
+
disabled,
|
|
526
|
+
required,
|
|
527
|
+
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
528
|
+
canAdd,
|
|
529
|
+
canRemove: additional,
|
|
530
|
+
canMoveUp: index >= itemSchemas.length + 1,
|
|
531
|
+
canMoveDown: additional && index < items.length - 1,
|
|
532
|
+
itemSchema,
|
|
533
|
+
itemData: itemCast,
|
|
534
|
+
itemUiSchema,
|
|
535
|
+
itemFieldPathId,
|
|
536
|
+
itemErrorSchema,
|
|
537
|
+
autofocus: autofocus && index === 0,
|
|
538
|
+
onBlur,
|
|
539
|
+
onFocus,
|
|
540
|
+
rawErrors,
|
|
541
|
+
totalItems: keyedFormData.length,
|
|
542
|
+
onChange,
|
|
543
|
+
handleAddItem,
|
|
544
|
+
handleCopyItem,
|
|
545
|
+
handleRemoveItem,
|
|
546
|
+
handleReorderItems
|
|
547
|
+
};
|
|
548
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItem, { ...itemProps }, key);
|
|
549
|
+
}),
|
|
550
|
+
onAddClick: handleAddItem,
|
|
551
|
+
readonly,
|
|
552
|
+
required,
|
|
553
|
+
registry,
|
|
554
|
+
schema,
|
|
555
|
+
uiSchema,
|
|
556
|
+
title: fieldTitle,
|
|
557
|
+
errorSchema,
|
|
558
|
+
rawErrors,
|
|
559
|
+
optionalDataControl
|
|
117
560
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
561
|
+
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
562
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...arrayProps });
|
|
563
|
+
}
|
|
564
|
+
function useKeyedFormData(formData = []) {
|
|
565
|
+
const newHash = react.useMemo(() => utils.hashObject(formData), [formData]);
|
|
566
|
+
const [state, setState] = react.useState(() => ({
|
|
567
|
+
formDataHash: newHash,
|
|
568
|
+
keyedFormData: generateKeyedFormData(formData)
|
|
569
|
+
}));
|
|
570
|
+
let { keyedFormData, formDataHash } = state;
|
|
571
|
+
if (newHash !== formDataHash) {
|
|
572
|
+
const nextFormData = Array.isArray(formData) ? formData : [];
|
|
573
|
+
const previousKeyedFormData = keyedFormData || [];
|
|
574
|
+
keyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => ({
|
|
575
|
+
key: previousKeyedFormDatum.key,
|
|
576
|
+
item: nextFormData[index]
|
|
577
|
+
})) : generateKeyedFormData(nextFormData);
|
|
578
|
+
formDataHash = newHash;
|
|
579
|
+
setState({ formDataHash, keyedFormData });
|
|
580
|
+
}
|
|
581
|
+
const updateKeyedFormData = react.useCallback((newData) => {
|
|
582
|
+
const plainFormData = keyedToPlainFormData(newData);
|
|
583
|
+
const newHash2 = utils.hashObject(plainFormData);
|
|
584
|
+
setState({ formDataHash: newHash2, keyedFormData: newData });
|
|
585
|
+
return plainFormData;
|
|
586
|
+
}, []);
|
|
587
|
+
return { keyedFormData, updateKeyedFormData };
|
|
588
|
+
}
|
|
589
|
+
function ArrayField(props) {
|
|
590
|
+
const { schema, uiSchema, errorSchema, fieldPathId, registry, formData, onChange } = props;
|
|
591
|
+
const { schemaUtils, translateString } = registry;
|
|
592
|
+
const { keyedFormData, updateKeyedFormData } = useKeyedFormData(formData);
|
|
593
|
+
const handleAddItem = react.useCallback(
|
|
594
|
+
(event, index) => {
|
|
595
|
+
if (event) {
|
|
596
|
+
event.preventDefault();
|
|
597
|
+
}
|
|
598
|
+
let newErrorSchema;
|
|
599
|
+
if (errorSchema) {
|
|
600
|
+
newErrorSchema = {};
|
|
601
|
+
for (const idx in errorSchema) {
|
|
602
|
+
const i = parseInt(idx);
|
|
603
|
+
if (index === void 0 || i < index) {
|
|
604
|
+
set(newErrorSchema, [i], errorSchema[idx]);
|
|
605
|
+
} else if (i >= index) {
|
|
606
|
+
set(newErrorSchema, [i + 1], errorSchema[idx]);
|
|
607
|
+
}
|
|
140
608
|
}
|
|
141
609
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// add click will pass the empty `path` array to the onChange which adds the appropriate path
|
|
159
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema)
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
163
|
-
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
164
|
-
* keyed data
|
|
165
|
-
*
|
|
166
|
-
* @param event - The event for the click
|
|
167
|
-
*/
|
|
168
|
-
onAddClick = (event) => {
|
|
169
|
-
this._handleAddClick(event);
|
|
170
|
-
};
|
|
171
|
-
/** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
|
|
172
|
-
* keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
|
|
173
|
-
* form data converted from the keyed data
|
|
174
|
-
*
|
|
175
|
-
* @param index - The index at which the add button is clicked
|
|
176
|
-
*/
|
|
177
|
-
onAddIndexClick = (index) => {
|
|
178
|
-
return (event) => {
|
|
179
|
-
this._handleAddClick(event, index);
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
183
|
-
* keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
|
|
184
|
-
* form data converted from the keyed data
|
|
185
|
-
*
|
|
186
|
-
* @param index - The index at which the copy button is clicked
|
|
187
|
-
*/
|
|
188
|
-
onCopyIndexClick = (index) => {
|
|
189
|
-
return (event) => {
|
|
610
|
+
const newKeyedFormDataRow = {
|
|
611
|
+
key: generateRowId(),
|
|
612
|
+
item: getNewFormDataRow(registry, schema)
|
|
613
|
+
};
|
|
614
|
+
const newKeyedFormData = [...keyedFormData];
|
|
615
|
+
if (index !== void 0) {
|
|
616
|
+
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
617
|
+
} else {
|
|
618
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
619
|
+
}
|
|
620
|
+
onChange(updateKeyedFormData(newKeyedFormData), fieldPathId.path, newErrorSchema);
|
|
621
|
+
},
|
|
622
|
+
[keyedFormData, registry, schema, onChange, updateKeyedFormData, errorSchema, fieldPathId]
|
|
623
|
+
);
|
|
624
|
+
const handleCopyItem = react.useCallback(
|
|
625
|
+
(event, index) => {
|
|
190
626
|
if (event) {
|
|
191
627
|
event.preventDefault();
|
|
192
628
|
}
|
|
193
|
-
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
194
|
-
const { keyedFormData } = this.state;
|
|
195
629
|
let newErrorSchema;
|
|
196
630
|
if (errorSchema) {
|
|
197
631
|
newErrorSchema = {};
|
|
@@ -214,28 +648,15 @@
|
|
|
214
648
|
} else {
|
|
215
649
|
newKeyedFormData.push(newKeyedFormDataRow);
|
|
216
650
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
);
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
227
|
-
* keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
|
|
228
|
-
* from the keyed data
|
|
229
|
-
*
|
|
230
|
-
* @param index - The index at which the remove button is clicked
|
|
231
|
-
*/
|
|
232
|
-
onDropIndexClick = (index) => {
|
|
233
|
-
return (event) => {
|
|
651
|
+
onChange(updateKeyedFormData(newKeyedFormData), fieldPathId.path, newErrorSchema);
|
|
652
|
+
},
|
|
653
|
+
[keyedFormData, onChange, updateKeyedFormData, errorSchema, fieldPathId]
|
|
654
|
+
);
|
|
655
|
+
const handleRemoveItem = react.useCallback(
|
|
656
|
+
(event, index) => {
|
|
234
657
|
if (event) {
|
|
235
658
|
event.preventDefault();
|
|
236
659
|
}
|
|
237
|
-
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
238
|
-
const { keyedFormData } = this.state;
|
|
239
660
|
let newErrorSchema;
|
|
240
661
|
if (errorSchema) {
|
|
241
662
|
newErrorSchema = {};
|
|
@@ -249,568 +670,99 @@
|
|
|
249
670
|
}
|
|
250
671
|
}
|
|
251
672
|
const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
);
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
262
|
-
* row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
|
|
263
|
-
* plain form data converted from the keyed data
|
|
264
|
-
*
|
|
265
|
-
* @param index - The index of the item to move
|
|
266
|
-
* @param newIndex - The index to where the item is to be moved
|
|
267
|
-
*/
|
|
268
|
-
onReorderClick = (index, newIndex) => {
|
|
269
|
-
return (event) => {
|
|
673
|
+
onChange(updateKeyedFormData(newKeyedFormData), fieldPathId.path, newErrorSchema);
|
|
674
|
+
},
|
|
675
|
+
[keyedFormData, onChange, updateKeyedFormData, errorSchema, fieldPathId]
|
|
676
|
+
);
|
|
677
|
+
const handleReorderItems = react.useCallback(
|
|
678
|
+
(event, index, newIndex) => {
|
|
270
679
|
if (event) {
|
|
271
680
|
event.preventDefault();
|
|
272
681
|
event.currentTarget.blur();
|
|
273
682
|
}
|
|
274
|
-
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
275
683
|
let newErrorSchema;
|
|
276
|
-
if (errorSchema) {
|
|
277
|
-
newErrorSchema = {};
|
|
278
|
-
for (const idx in errorSchema) {
|
|
279
|
-
const i = parseInt(idx);
|
|
280
|
-
if (i == index) {
|
|
281
|
-
set(newErrorSchema, [newIndex], errorSchema[index]);
|
|
282
|
-
} else if (i == newIndex) {
|
|
283
|
-
set(newErrorSchema, [index], errorSchema[newIndex]);
|
|
284
|
-
} else {
|
|
285
|
-
set(newErrorSchema, [idx], errorSchema[i]);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
const { keyedFormData } = this.state;
|
|
290
|
-
function reOrderArray() {
|
|
291
|
-
const _newKeyedFormData = keyedFormData.slice();
|
|
292
|
-
_newKeyedFormData.splice(index, 1);
|
|
293
|
-
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
294
|
-
return _newKeyedFormData;
|
|
295
|
-
}
|
|
296
|
-
const newKeyedFormData = reOrderArray();
|
|
297
|
-
this.setState(
|
|
298
|
-
{
|
|
299
|
-
keyedFormData: newKeyedFormData
|
|
300
|
-
},
|
|
301
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema)
|
|
302
|
-
);
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
306
|
-
* `onChange` callback with the updated form data
|
|
307
|
-
*
|
|
308
|
-
* @param index - The index of the item being changed
|
|
309
|
-
*/
|
|
310
|
-
onChangeForIndex = (index) => {
|
|
311
|
-
return (value, path, newErrorSchema, id) => {
|
|
312
|
-
const { onChange } = this.props;
|
|
313
|
-
onChange(
|
|
314
|
-
// We need to treat undefined items as nulls to have validation.
|
|
315
|
-
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
316
|
-
value === void 0 ? null : value,
|
|
317
|
-
path,
|
|
318
|
-
newErrorSchema,
|
|
319
|
-
id
|
|
320
|
-
);
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
|
-
/** Callback handler used to change the value for a checkbox */
|
|
324
|
-
onSelectChange = (value) => {
|
|
325
|
-
const { onChange, fieldPathId } = this.props;
|
|
326
|
-
onChange(value, fieldPathId.path, void 0, fieldPathId && fieldPathId.$id);
|
|
327
|
-
};
|
|
328
|
-
/** Helper method to compute item UI schema for both normal and fixed arrays
|
|
329
|
-
* Handles both static object and dynamic function cases
|
|
330
|
-
*
|
|
331
|
-
* @param uiSchema - The parent UI schema containing items definition
|
|
332
|
-
* @param item - The item data
|
|
333
|
-
* @param index - The index of the item
|
|
334
|
-
* @param formContext - The form context
|
|
335
|
-
* @returns The computed UI schema for the item
|
|
336
|
-
*/
|
|
337
|
-
computeItemUiSchema(uiSchema, item, index, formContext) {
|
|
338
|
-
if (typeof uiSchema.items === "function") {
|
|
339
|
-
try {
|
|
340
|
-
const result = uiSchema.items(item, index, formContext);
|
|
341
|
-
return result;
|
|
342
|
-
} catch (e) {
|
|
343
|
-
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
344
|
-
return void 0;
|
|
345
|
-
}
|
|
346
|
-
} else {
|
|
347
|
-
return uiSchema.items;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
351
|
-
*/
|
|
352
|
-
render() {
|
|
353
|
-
const { schema, uiSchema, fieldPathId, registry } = this.props;
|
|
354
|
-
const { schemaUtils, translateString } = registry;
|
|
355
|
-
if (!(utils.ITEMS_KEY in schema)) {
|
|
356
|
-
const uiOptions = utils.getUiOptions(uiSchema);
|
|
357
|
-
const UnsupportedFieldTemplate = utils.getTemplate(
|
|
358
|
-
"UnsupportedFieldTemplate",
|
|
359
|
-
registry,
|
|
360
|
-
uiOptions
|
|
361
|
-
);
|
|
362
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
363
|
-
UnsupportedFieldTemplate,
|
|
364
|
-
{
|
|
365
|
-
schema,
|
|
366
|
-
fieldPathId,
|
|
367
|
-
reason: translateString(utils.TranslatableString.MissingItems),
|
|
368
|
-
registry
|
|
369
|
-
}
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
if (schemaUtils.isMultiSelect(schema)) {
|
|
373
|
-
return this.renderMultiSelect();
|
|
374
|
-
}
|
|
375
|
-
if (utils.isCustomWidget(uiSchema)) {
|
|
376
|
-
return this.renderCustomWidget();
|
|
377
|
-
}
|
|
378
|
-
if (utils.isFixedItems(schema)) {
|
|
379
|
-
return this.renderFixedArray();
|
|
380
|
-
}
|
|
381
|
-
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
382
|
-
return this.renderFiles();
|
|
383
|
-
}
|
|
384
|
-
return this.renderNormalArray();
|
|
385
|
-
}
|
|
386
|
-
/** Renders a normal array without any limitations of length
|
|
387
|
-
*/
|
|
388
|
-
renderNormalArray() {
|
|
389
|
-
const {
|
|
390
|
-
schema,
|
|
391
|
-
uiSchema = {},
|
|
392
|
-
errorSchema,
|
|
393
|
-
fieldPathId,
|
|
394
|
-
name,
|
|
395
|
-
title,
|
|
396
|
-
disabled = false,
|
|
397
|
-
readonly = false,
|
|
398
|
-
autofocus = false,
|
|
399
|
-
required = false,
|
|
400
|
-
registry,
|
|
401
|
-
onBlur,
|
|
402
|
-
onFocus,
|
|
403
|
-
rawErrors
|
|
404
|
-
} = this.props;
|
|
405
|
-
const { keyedFormData } = this.state;
|
|
406
|
-
const fieldTitle = schema.title || title || name;
|
|
407
|
-
const { schemaUtils, fields: fields2, formContext, globalFormOptions } = registry;
|
|
408
|
-
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
409
|
-
const uiOptions = utils.getUiOptions(uiSchema);
|
|
410
|
-
const _schemaItems = isObject(schema.items) ? schema.items : {};
|
|
411
|
-
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
412
|
-
const formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
413
|
-
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
414
|
-
const hasFormData = utils.isFormDataAvailable(this.props.formData);
|
|
415
|
-
const canAdd = this.canAddItem(formData) && (!renderOptionalField || hasFormData);
|
|
416
|
-
const actualFormData = hasFormData ? keyedFormData : [];
|
|
417
|
-
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
|
|
418
|
-
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...this.props }) : void 0;
|
|
419
|
-
const arrayProps = {
|
|
420
|
-
canAdd,
|
|
421
|
-
items: actualFormData.map((keyedItem, index) => {
|
|
422
|
-
const { key, item } = keyedItem;
|
|
423
|
-
const itemCast = item;
|
|
424
|
-
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
425
|
-
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
426
|
-
const itemFieldPathId = utils.toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
427
|
-
const itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
428
|
-
return this.renderArrayFieldItem({
|
|
429
|
-
key,
|
|
430
|
-
index,
|
|
431
|
-
name: name && `${name}-${index}`,
|
|
432
|
-
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
433
|
-
canAdd,
|
|
434
|
-
canMoveUp: index > 0,
|
|
435
|
-
canMoveDown: index < formData.length - 1,
|
|
436
|
-
itemSchema,
|
|
437
|
-
itemFieldPathId,
|
|
438
|
-
itemErrorSchema,
|
|
439
|
-
itemData: itemCast,
|
|
440
|
-
itemUiSchema,
|
|
441
|
-
autofocus: autofocus && index === 0,
|
|
442
|
-
onBlur,
|
|
443
|
-
onFocus,
|
|
444
|
-
rawErrors,
|
|
445
|
-
totalItems: keyedFormData.length
|
|
446
|
-
});
|
|
447
|
-
}),
|
|
448
|
-
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}${extraClass}`,
|
|
449
|
-
disabled,
|
|
450
|
-
fieldPathId,
|
|
451
|
-
uiSchema,
|
|
452
|
-
onAddClick: this.onAddClick,
|
|
453
|
-
readonly,
|
|
454
|
-
required,
|
|
455
|
-
schema,
|
|
456
|
-
title: fieldTitle,
|
|
457
|
-
formData,
|
|
458
|
-
rawErrors,
|
|
459
|
-
registry,
|
|
460
|
-
optionalDataControl
|
|
461
|
-
};
|
|
462
|
-
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
463
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...arrayProps });
|
|
464
|
-
}
|
|
465
|
-
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
466
|
-
*/
|
|
467
|
-
renderCustomWidget() {
|
|
468
|
-
const {
|
|
469
|
-
schema,
|
|
470
|
-
fieldPathId,
|
|
471
|
-
uiSchema,
|
|
472
|
-
disabled = false,
|
|
473
|
-
readonly = false,
|
|
474
|
-
autofocus = false,
|
|
475
|
-
required = false,
|
|
476
|
-
hideError,
|
|
477
|
-
placeholder,
|
|
478
|
-
onBlur,
|
|
479
|
-
onFocus,
|
|
480
|
-
formData: items = [],
|
|
481
|
-
registry,
|
|
482
|
-
rawErrors,
|
|
483
|
-
name
|
|
484
|
-
} = this.props;
|
|
485
|
-
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
486
|
-
const { widget, title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
487
|
-
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
488
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
489
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
490
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
491
|
-
Widget,
|
|
492
|
-
{
|
|
493
|
-
id: fieldPathId.$id,
|
|
494
|
-
name,
|
|
495
|
-
multiple: true,
|
|
496
|
-
onChange: this.onSelectChange,
|
|
497
|
-
onBlur,
|
|
498
|
-
onFocus,
|
|
499
|
-
options,
|
|
500
|
-
schema,
|
|
501
|
-
uiSchema,
|
|
502
|
-
registry,
|
|
503
|
-
value: items,
|
|
504
|
-
disabled,
|
|
505
|
-
readonly,
|
|
506
|
-
hideError,
|
|
507
|
-
required,
|
|
508
|
-
label,
|
|
509
|
-
hideLabel: !displayLabel,
|
|
510
|
-
placeholder,
|
|
511
|
-
formContext,
|
|
512
|
-
autofocus,
|
|
513
|
-
rawErrors
|
|
514
|
-
}
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
/** Renders an array as a set of checkboxes
|
|
518
|
-
*/
|
|
519
|
-
renderMultiSelect() {
|
|
520
|
-
const {
|
|
521
|
-
schema,
|
|
522
|
-
fieldPathId,
|
|
523
|
-
uiSchema,
|
|
524
|
-
formData: items = [],
|
|
525
|
-
disabled = false,
|
|
526
|
-
readonly = false,
|
|
527
|
-
autofocus = false,
|
|
528
|
-
required = false,
|
|
529
|
-
placeholder,
|
|
530
|
-
onBlur,
|
|
531
|
-
onFocus,
|
|
532
|
-
registry,
|
|
533
|
-
rawErrors,
|
|
534
|
-
name
|
|
535
|
-
} = this.props;
|
|
536
|
-
const { widgets: widgets2, schemaUtils, formContext, globalUiOptions } = registry;
|
|
537
|
-
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
538
|
-
const enumOptions = utils.optionsList(itemsSchema, uiSchema);
|
|
539
|
-
const { widget = "select", title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
540
|
-
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
541
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
542
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
543
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
544
|
-
Widget,
|
|
545
|
-
{
|
|
546
|
-
id: fieldPathId.$id,
|
|
547
|
-
name,
|
|
548
|
-
multiple: true,
|
|
549
|
-
onChange: this.onSelectChange,
|
|
550
|
-
onBlur,
|
|
551
|
-
onFocus,
|
|
552
|
-
options: { ...options, enumOptions },
|
|
553
|
-
schema,
|
|
554
|
-
uiSchema,
|
|
555
|
-
registry,
|
|
556
|
-
value: items,
|
|
557
|
-
disabled,
|
|
558
|
-
readonly,
|
|
559
|
-
required,
|
|
560
|
-
label,
|
|
561
|
-
hideLabel: !displayLabel,
|
|
562
|
-
placeholder,
|
|
563
|
-
formContext,
|
|
564
|
-
autofocus,
|
|
565
|
-
rawErrors
|
|
684
|
+
if (errorSchema) {
|
|
685
|
+
newErrorSchema = {};
|
|
686
|
+
for (const idx in errorSchema) {
|
|
687
|
+
const i = parseInt(idx);
|
|
688
|
+
if (i == index) {
|
|
689
|
+
set(newErrorSchema, [newIndex], errorSchema[index]);
|
|
690
|
+
} else if (i == newIndex) {
|
|
691
|
+
set(newErrorSchema, [index], errorSchema[newIndex]);
|
|
692
|
+
} else {
|
|
693
|
+
set(newErrorSchema, [idx], errorSchema[i]);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
566
696
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
697
|
+
function reOrderArray() {
|
|
698
|
+
const _newKeyedFormData = keyedFormData.slice();
|
|
699
|
+
_newKeyedFormData.splice(index, 1);
|
|
700
|
+
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
701
|
+
return _newKeyedFormData;
|
|
702
|
+
}
|
|
703
|
+
const newKeyedFormData = reOrderArray();
|
|
704
|
+
onChange(updateKeyedFormData(newKeyedFormData), fieldPathId.path, newErrorSchema);
|
|
705
|
+
},
|
|
706
|
+
[keyedFormData, onChange, updateKeyedFormData, errorSchema, fieldPathId]
|
|
707
|
+
);
|
|
708
|
+
const handleChange = react.useCallback(
|
|
709
|
+
(value, path, newErrorSchema, id) => {
|
|
710
|
+
onChange(
|
|
711
|
+
// We need to treat undefined items as nulls to have validation.
|
|
712
|
+
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
713
|
+
value === void 0 ? null : value,
|
|
714
|
+
path,
|
|
715
|
+
newErrorSchema,
|
|
716
|
+
id
|
|
717
|
+
);
|
|
718
|
+
},
|
|
719
|
+
[onChange]
|
|
720
|
+
);
|
|
721
|
+
const onSelectChange = react.useCallback(
|
|
722
|
+
(value) => {
|
|
723
|
+
onChange(value, fieldPathId.path, void 0, fieldPathId?.[utils.ID_KEY]);
|
|
724
|
+
},
|
|
725
|
+
[onChange, fieldPathId]
|
|
726
|
+
);
|
|
727
|
+
if (!(utils.ITEMS_KEY in schema)) {
|
|
728
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
729
|
+
const UnsupportedFieldTemplate = utils.getTemplate(
|
|
730
|
+
"UnsupportedFieldTemplate",
|
|
583
731
|
registry,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
} = this.props;
|
|
587
|
-
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
588
|
-
const { widget = "files", title: uiTitle, ...options } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
589
|
-
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
590
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
591
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
732
|
+
uiOptions
|
|
733
|
+
);
|
|
592
734
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
593
|
-
|
|
735
|
+
UnsupportedFieldTemplate,
|
|
594
736
|
{
|
|
595
|
-
options,
|
|
596
|
-
id: fieldPathId.$id,
|
|
597
|
-
name,
|
|
598
|
-
multiple: true,
|
|
599
|
-
onChange: this.onSelectChange,
|
|
600
|
-
onBlur,
|
|
601
|
-
onFocus,
|
|
602
737
|
schema,
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
readonly,
|
|
607
|
-
required,
|
|
608
|
-
registry,
|
|
609
|
-
formContext,
|
|
610
|
-
autofocus,
|
|
611
|
-
rawErrors,
|
|
612
|
-
label,
|
|
613
|
-
hideLabel: !displayLabel
|
|
738
|
+
fieldPathId,
|
|
739
|
+
reason: translateString(utils.TranslatableString.MissingItems),
|
|
740
|
+
registry
|
|
614
741
|
}
|
|
615
742
|
);
|
|
616
743
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
title,
|
|
628
|
-
disabled = false,
|
|
629
|
-
readonly = false,
|
|
630
|
-
autofocus = false,
|
|
631
|
-
required = false,
|
|
632
|
-
registry,
|
|
633
|
-
onBlur,
|
|
634
|
-
onFocus,
|
|
635
|
-
rawErrors
|
|
636
|
-
} = this.props;
|
|
637
|
-
let { formData: items = [] } = this.props;
|
|
638
|
-
const { keyedFormData } = this.state;
|
|
639
|
-
const fieldTitle = schema.title || title || name;
|
|
640
|
-
const uiOptions = utils.getUiOptions(uiSchema);
|
|
641
|
-
const { schemaUtils, fields: fields2, formContext, globalFormOptions } = registry;
|
|
642
|
-
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
643
|
-
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
644
|
-
const hasFormData = utils.isFormDataAvailable(formData);
|
|
645
|
-
const _schemaItems = isObject(schema.items) ? schema.items : [];
|
|
646
|
-
const itemSchemas = _schemaItems.map(
|
|
647
|
-
(item, index) => schemaUtils.retrieveSchema(item, items[index])
|
|
648
|
-
);
|
|
649
|
-
const additionalSchema = isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
650
|
-
if (items.length < itemSchemas.length) {
|
|
651
|
-
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
652
|
-
}
|
|
653
|
-
const actualFormData = hasFormData ? keyedFormData : [];
|
|
654
|
-
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
|
|
655
|
-
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...this.props }) : void 0;
|
|
656
|
-
const canAdd = this.canAddItem(items) && !!additionalSchema && (!renderOptionalField || hasFormData);
|
|
657
|
-
const arrayProps = {
|
|
658
|
-
canAdd,
|
|
659
|
-
className: `rjsf-field rjsf-field-array rjsf-field-array-fixed-items${extraClass}`,
|
|
660
|
-
disabled,
|
|
661
|
-
fieldPathId,
|
|
662
|
-
formData,
|
|
663
|
-
items: actualFormData.map((keyedItem, index) => {
|
|
664
|
-
const { key, item } = keyedItem;
|
|
665
|
-
const itemCast = item;
|
|
666
|
-
const additional = index >= itemSchemas.length;
|
|
667
|
-
const itemSchema = (additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
668
|
-
const itemFieldPathId = utils.toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
669
|
-
let itemUiSchema;
|
|
670
|
-
if (additional) {
|
|
671
|
-
itemUiSchema = uiSchema.additionalItems;
|
|
672
|
-
} else {
|
|
673
|
-
if (Array.isArray(uiSchema.items)) {
|
|
674
|
-
itemUiSchema = uiSchema.items[index];
|
|
675
|
-
} else {
|
|
676
|
-
itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
680
|
-
return this.renderArrayFieldItem({
|
|
681
|
-
key,
|
|
682
|
-
index,
|
|
683
|
-
name: name && `${name}-${index}`,
|
|
684
|
-
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
685
|
-
canAdd,
|
|
686
|
-
canRemove: additional,
|
|
687
|
-
canMoveUp: index >= itemSchemas.length + 1,
|
|
688
|
-
canMoveDown: additional && index < items.length - 1,
|
|
689
|
-
itemSchema,
|
|
690
|
-
itemData: itemCast,
|
|
691
|
-
itemUiSchema,
|
|
692
|
-
itemFieldPathId,
|
|
693
|
-
itemErrorSchema,
|
|
694
|
-
autofocus: autofocus && index === 0,
|
|
695
|
-
onBlur,
|
|
696
|
-
onFocus,
|
|
697
|
-
rawErrors,
|
|
698
|
-
totalItems: keyedFormData.length
|
|
699
|
-
});
|
|
700
|
-
}),
|
|
701
|
-
onAddClick: this.onAddClick,
|
|
702
|
-
readonly,
|
|
703
|
-
required,
|
|
704
|
-
registry,
|
|
705
|
-
schema,
|
|
706
|
-
uiSchema,
|
|
707
|
-
title: fieldTitle,
|
|
708
|
-
errorSchema,
|
|
709
|
-
rawErrors,
|
|
710
|
-
optionalDataControl
|
|
711
|
-
};
|
|
712
|
-
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
713
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...arrayProps });
|
|
744
|
+
const arrayProps = {
|
|
745
|
+
handleAddItem,
|
|
746
|
+
handleCopyItem,
|
|
747
|
+
handleRemoveItem,
|
|
748
|
+
handleReorderItems,
|
|
749
|
+
keyedFormData,
|
|
750
|
+
onChange: handleChange
|
|
751
|
+
};
|
|
752
|
+
if (schemaUtils.isMultiSelect(schema)) {
|
|
753
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayAsMultiSelect, { ...props, onSelectChange });
|
|
714
754
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
*
|
|
718
|
-
* @param props - The props for the individual array item to be rendered
|
|
719
|
-
*/
|
|
720
|
-
renderArrayFieldItem(props) {
|
|
721
|
-
const {
|
|
722
|
-
key,
|
|
723
|
-
index,
|
|
724
|
-
name,
|
|
725
|
-
canAdd,
|
|
726
|
-
canRemove = true,
|
|
727
|
-
canMoveUp,
|
|
728
|
-
canMoveDown,
|
|
729
|
-
itemSchema,
|
|
730
|
-
itemData,
|
|
731
|
-
itemUiSchema,
|
|
732
|
-
itemFieldPathId,
|
|
733
|
-
itemErrorSchema,
|
|
734
|
-
autofocus,
|
|
735
|
-
onBlur,
|
|
736
|
-
onFocus,
|
|
737
|
-
rawErrors,
|
|
738
|
-
totalItems,
|
|
739
|
-
title
|
|
740
|
-
} = props;
|
|
741
|
-
const { disabled, hideError, readonly, uiSchema, registry, formContext } = this.props;
|
|
742
|
-
const {
|
|
743
|
-
fields: { ArraySchemaField, SchemaField: SchemaField2 },
|
|
744
|
-
globalUiOptions
|
|
745
|
-
} = registry;
|
|
746
|
-
const ItemSchemaField = ArraySchemaField || SchemaField2;
|
|
747
|
-
const { orderable = true, removable = true, copyable = false } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
748
|
-
const has4 = {
|
|
749
|
-
moveUp: orderable && canMoveUp,
|
|
750
|
-
moveDown: orderable && canMoveDown,
|
|
751
|
-
copy: copyable && canAdd,
|
|
752
|
-
remove: removable && canRemove,
|
|
753
|
-
toolbar: false
|
|
754
|
-
};
|
|
755
|
-
has4.toolbar = Object.keys(has4).some((key2) => has4[key2]);
|
|
756
|
-
return {
|
|
757
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
758
|
-
ItemSchemaField,
|
|
759
|
-
{
|
|
760
|
-
name,
|
|
761
|
-
title,
|
|
762
|
-
index,
|
|
763
|
-
schema: itemSchema,
|
|
764
|
-
uiSchema: itemUiSchema,
|
|
765
|
-
formData: itemData,
|
|
766
|
-
formContext,
|
|
767
|
-
errorSchema: itemErrorSchema,
|
|
768
|
-
fieldPathId: itemFieldPathId,
|
|
769
|
-
required: this.isItemRequired(itemSchema),
|
|
770
|
-
onChange: this.onChangeForIndex(index),
|
|
771
|
-
onBlur,
|
|
772
|
-
onFocus,
|
|
773
|
-
registry,
|
|
774
|
-
disabled,
|
|
775
|
-
readonly,
|
|
776
|
-
hideError,
|
|
777
|
-
autofocus,
|
|
778
|
-
rawErrors
|
|
779
|
-
}
|
|
780
|
-
),
|
|
781
|
-
buttonsProps: {
|
|
782
|
-
fieldPathId: itemFieldPathId,
|
|
783
|
-
disabled,
|
|
784
|
-
readonly,
|
|
785
|
-
canAdd,
|
|
786
|
-
hasCopy: has4.copy,
|
|
787
|
-
hasMoveUp: has4.moveUp,
|
|
788
|
-
hasMoveDown: has4.moveDown,
|
|
789
|
-
hasRemove: has4.remove,
|
|
790
|
-
index,
|
|
791
|
-
totalItems,
|
|
792
|
-
onAddIndexClick: this.onAddIndexClick,
|
|
793
|
-
onCopyIndexClick: this.onCopyIndexClick,
|
|
794
|
-
onDropIndexClick: this.onDropIndexClick,
|
|
795
|
-
onReorderClick: this.onReorderClick,
|
|
796
|
-
registry,
|
|
797
|
-
schema: itemSchema,
|
|
798
|
-
uiSchema: itemUiSchema
|
|
799
|
-
},
|
|
800
|
-
className: "rjsf-array-item",
|
|
801
|
-
disabled,
|
|
802
|
-
hasToolbar: has4.toolbar,
|
|
803
|
-
index,
|
|
804
|
-
totalItems,
|
|
805
|
-
key,
|
|
806
|
-
readonly,
|
|
807
|
-
registry,
|
|
808
|
-
schema: itemSchema,
|
|
809
|
-
uiSchema: itemUiSchema
|
|
810
|
-
};
|
|
755
|
+
if (utils.isCustomWidget(uiSchema)) {
|
|
756
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayAsCustomWidget, { ...props, onSelectChange });
|
|
811
757
|
}
|
|
812
|
-
|
|
813
|
-
|
|
758
|
+
if (utils.isFixedItems(schema)) {
|
|
759
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FixedArray, { ...props, ...arrayProps });
|
|
760
|
+
}
|
|
761
|
+
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
762
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArrayAsFiles, { ...props, onSelectChange });
|
|
763
|
+
}
|
|
764
|
+
return /* @__PURE__ */ jsxRuntime.jsx(NormalArray, { ...props, ...arrayProps });
|
|
765
|
+
}
|
|
814
766
|
function BooleanField(props) {
|
|
815
767
|
const {
|
|
816
768
|
schema,
|
|
@@ -831,7 +783,7 @@
|
|
|
831
783
|
rawErrors
|
|
832
784
|
} = props;
|
|
833
785
|
const { title: schemaTitle } = schema;
|
|
834
|
-
const { widgets: widgets2,
|
|
786
|
+
const { widgets: widgets2, translateString, globalUiOptions } = registry;
|
|
835
787
|
const {
|
|
836
788
|
widget = "checkbox",
|
|
837
789
|
title: uiTitle,
|
|
@@ -903,13 +855,123 @@
|
|
|
903
855
|
readonly,
|
|
904
856
|
hideError,
|
|
905
857
|
registry,
|
|
906
|
-
formContext,
|
|
907
858
|
autofocus,
|
|
908
|
-
rawErrors
|
|
859
|
+
rawErrors,
|
|
860
|
+
htmlName: fieldPathId.name
|
|
909
861
|
}
|
|
910
862
|
);
|
|
911
863
|
}
|
|
912
864
|
var BooleanField_default = BooleanField;
|
|
865
|
+
function getFallbackTypeSelectionSchema(title) {
|
|
866
|
+
return {
|
|
867
|
+
type: "string",
|
|
868
|
+
enum: ["string", "number", "boolean"],
|
|
869
|
+
default: "string",
|
|
870
|
+
title
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
function getTypeOfFormData(formData) {
|
|
874
|
+
const dataType = typeof formData;
|
|
875
|
+
if (dataType === "string" || dataType === "number" || dataType === "boolean") {
|
|
876
|
+
return dataType;
|
|
877
|
+
}
|
|
878
|
+
return "string";
|
|
879
|
+
}
|
|
880
|
+
function castToNewType(formData, newType) {
|
|
881
|
+
switch (newType) {
|
|
882
|
+
case "string":
|
|
883
|
+
return String(formData);
|
|
884
|
+
case "number": {
|
|
885
|
+
const castedNumber = Number(formData);
|
|
886
|
+
return isNaN(castedNumber) ? 0 : castedNumber;
|
|
887
|
+
}
|
|
888
|
+
case "boolean":
|
|
889
|
+
return Boolean(formData);
|
|
890
|
+
default:
|
|
891
|
+
return formData;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function FallbackField(props) {
|
|
895
|
+
const {
|
|
896
|
+
id,
|
|
897
|
+
formData,
|
|
898
|
+
displayLabel = true,
|
|
899
|
+
schema,
|
|
900
|
+
name,
|
|
901
|
+
uiSchema,
|
|
902
|
+
required,
|
|
903
|
+
disabled = false,
|
|
904
|
+
readonly = false,
|
|
905
|
+
onBlur,
|
|
906
|
+
onFocus,
|
|
907
|
+
registry,
|
|
908
|
+
fieldPathId,
|
|
909
|
+
onChange,
|
|
910
|
+
errorSchema
|
|
911
|
+
} = props;
|
|
912
|
+
const { translateString, fields: fields2, globalFormOptions } = registry;
|
|
913
|
+
const [type, setType] = react.useState(getTypeOfFormData(formData));
|
|
914
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
915
|
+
const typeSelectorInnerFieldPathId = utils.useDeepCompareMemo(
|
|
916
|
+
utils.toFieldPathId("__internal_type_selector", globalFormOptions, fieldPathId)
|
|
917
|
+
);
|
|
918
|
+
const schemaTitle = translateString(utils.TranslatableString.Type);
|
|
919
|
+
const typesOptionSchema = react.useMemo(() => getFallbackTypeSelectionSchema(schemaTitle), [schemaTitle]);
|
|
920
|
+
const onTypeChange = (newType) => {
|
|
921
|
+
if (newType != null) {
|
|
922
|
+
setType(newType);
|
|
923
|
+
onChange(castToNewType(formData, newType), fieldPathId.path, errorSchema, id);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
|
|
927
|
+
const UnsupportedFieldTemplate = utils.getTemplate(
|
|
928
|
+
"UnsupportedFieldTemplate",
|
|
929
|
+
registry,
|
|
930
|
+
uiOptions
|
|
931
|
+
);
|
|
932
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
933
|
+
UnsupportedFieldTemplate,
|
|
934
|
+
{
|
|
935
|
+
schema,
|
|
936
|
+
fieldPathId,
|
|
937
|
+
reason: translateString(utils.TranslatableString.UnknownFieldType, [String(schema.type)]),
|
|
938
|
+
registry
|
|
939
|
+
}
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
const FallbackFieldTemplate2 = utils.getTemplate(
|
|
943
|
+
"FallbackFieldTemplate",
|
|
944
|
+
registry,
|
|
945
|
+
uiOptions
|
|
946
|
+
);
|
|
947
|
+
const { SchemaField: SchemaField2 } = fields2;
|
|
948
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
949
|
+
FallbackFieldTemplate2,
|
|
950
|
+
{
|
|
951
|
+
schema,
|
|
952
|
+
registry,
|
|
953
|
+
typeSelector: /* @__PURE__ */ jsxRuntime.jsx(
|
|
954
|
+
SchemaField2,
|
|
955
|
+
{
|
|
956
|
+
fieldPathId: typeSelectorInnerFieldPathId,
|
|
957
|
+
name: `${name}__fallback_type`,
|
|
958
|
+
schema: typesOptionSchema,
|
|
959
|
+
formData: type,
|
|
960
|
+
onChange: onTypeChange,
|
|
961
|
+
onBlur,
|
|
962
|
+
onFocus,
|
|
963
|
+
registry,
|
|
964
|
+
hideLabel: !displayLabel,
|
|
965
|
+
disabled,
|
|
966
|
+
readonly,
|
|
967
|
+
required
|
|
968
|
+
},
|
|
969
|
+
formData ? utils.hashObject(formData) : "__empty__"
|
|
970
|
+
),
|
|
971
|
+
schemaField: /* @__PURE__ */ jsxRuntime.jsx(SchemaField2, { ...props, schema: { type, title: translateString(utils.TranslatableString.Value) } })
|
|
972
|
+
}
|
|
973
|
+
);
|
|
974
|
+
}
|
|
913
975
|
var LOOKUP_REGEX = /^\$lookup=(.+)/;
|
|
914
976
|
var LAYOUT_GRID_UI_OPTION = "layoutGrid";
|
|
915
977
|
function getNonNullishValue(value, fallback) {
|
|
@@ -918,518 +980,339 @@
|
|
|
918
980
|
function isNumericIndex(str) {
|
|
919
981
|
return /^\d+?$/.test(str);
|
|
920
982
|
}
|
|
921
|
-
var
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
* updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
|
|
930
|
-
* the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
|
|
931
|
-
* field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
|
|
932
|
-
*
|
|
933
|
-
* @param field - The name of the field to pull the existing UI Schema for
|
|
934
|
-
* @param uiProps - Any props that should be put into the field's uiSchema
|
|
935
|
-
* @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
|
|
936
|
-
* @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
|
|
937
|
-
* @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
|
|
938
|
-
*/
|
|
939
|
-
static computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
|
|
940
|
-
const globalUiOptions = get2(uiSchema, [utils.UI_GLOBAL_OPTIONS_KEY], {});
|
|
941
|
-
const localUiSchema = get2(uiSchema, field);
|
|
942
|
-
const localUiOptions = { ...get2(localUiSchema, [utils.UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
|
|
943
|
-
const fieldUiSchema = { ...localUiSchema };
|
|
944
|
-
if (!isEmpty(localUiOptions)) {
|
|
945
|
-
set(fieldUiSchema, [utils.UI_OPTIONS_KEY], localUiOptions);
|
|
946
|
-
}
|
|
947
|
-
if (!isEmpty(globalUiOptions)) {
|
|
948
|
-
set(fieldUiSchema, [utils.UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
|
|
949
|
-
}
|
|
950
|
-
let { readonly: uiReadonly } = utils.getUiOptions(fieldUiSchema);
|
|
951
|
-
if (forceReadonly === true || isUndefined(uiReadonly) && schemaReadonly === true) {
|
|
952
|
-
uiReadonly = true;
|
|
953
|
-
if (has(localUiOptions, utils.READONLY_KEY)) {
|
|
954
|
-
set(fieldUiSchema, [utils.UI_OPTIONS_KEY, utils.READONLY_KEY], true);
|
|
955
|
-
} else {
|
|
956
|
-
set(fieldUiSchema, `ui:${utils.READONLY_KEY}`, true);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
return { fieldUiSchema, uiReadonly };
|
|
983
|
+
var LAYOUT_GRID_FIELD_TEST_IDS = utils.getTestIds();
|
|
984
|
+
function computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
|
|
985
|
+
const globalUiOptions = get(uiSchema, [utils.UI_GLOBAL_OPTIONS_KEY], {});
|
|
986
|
+
const localUiSchema = get(uiSchema, field);
|
|
987
|
+
const localUiOptions = { ...get(localUiSchema, [utils.UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
|
|
988
|
+
const fieldUiSchema = { ...localUiSchema };
|
|
989
|
+
if (!isEmpty(localUiOptions)) {
|
|
990
|
+
set(fieldUiSchema, [utils.UI_OPTIONS_KEY], localUiOptions);
|
|
960
991
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
* contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
|
|
964
|
-
* equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
|
|
965
|
-
* common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
|
|
966
|
-
* to match.
|
|
967
|
-
*
|
|
968
|
-
* @param [operator] - The optional operator for the condition
|
|
969
|
-
* @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
|
|
970
|
-
* @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
|
|
971
|
-
* to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
|
|
972
|
-
* This can be an item or a list of items of type unknown
|
|
973
|
-
* @returns - True if the condition matches, false otherwise
|
|
974
|
-
*/
|
|
975
|
-
static conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
|
|
976
|
-
const data = flatten([datum]).sort();
|
|
977
|
-
const values = flatten([value]).sort();
|
|
978
|
-
switch (operator) {
|
|
979
|
-
case "all" /* ALL */:
|
|
980
|
-
return isEqual(data, values);
|
|
981
|
-
case "some" /* SOME */:
|
|
982
|
-
return intersection(data, values).length > 0;
|
|
983
|
-
case "none" /* NONE */:
|
|
984
|
-
return intersection(data, values).length === 0;
|
|
985
|
-
default:
|
|
986
|
-
return false;
|
|
987
|
-
}
|
|
992
|
+
if (!isEmpty(globalUiOptions)) {
|
|
993
|
+
set(fieldUiSchema, [utils.UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
|
|
988
994
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
* @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
|
|
997
|
-
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
998
|
-
* @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
|
|
999
|
-
* @throws - A `TypeError` when the `children` is not an array
|
|
1000
|
-
*/
|
|
1001
|
-
static findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
|
|
1002
|
-
let gridProps = {};
|
|
1003
|
-
let children = layoutGridSchema[schemaKey];
|
|
1004
|
-
if (isPlainObject(children)) {
|
|
1005
|
-
const { children: elements, className: toMapClassNames, ...otherProps } = children;
|
|
1006
|
-
children = elements;
|
|
1007
|
-
if (toMapClassNames) {
|
|
1008
|
-
const classes = toMapClassNames.split(" ");
|
|
1009
|
-
const className = classes.map((ele) => utils.lookupFromFormContext(registry, ele, ele)).join(" ");
|
|
1010
|
-
gridProps = { ...otherProps, className };
|
|
1011
|
-
} else {
|
|
1012
|
-
gridProps = otherProps;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
if (!Array.isArray(children)) {
|
|
1016
|
-
throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
|
|
995
|
+
let { readonly: uiReadonly } = utils.getUiOptions(fieldUiSchema);
|
|
996
|
+
if (forceReadonly === true || isUndefined(uiReadonly) && schemaReadonly === true) {
|
|
997
|
+
uiReadonly = true;
|
|
998
|
+
if (has(localUiOptions, utils.READONLY_KEY)) {
|
|
999
|
+
set(fieldUiSchema, [utils.UI_OPTIONS_KEY, utils.READONLY_KEY], true);
|
|
1000
|
+
} else {
|
|
1001
|
+
set(fieldUiSchema, `ui:${utils.READONLY_KEY}`, true);
|
|
1017
1002
|
}
|
|
1018
|
-
return { children, gridProps };
|
|
1019
1003
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
let rawSchema;
|
|
1035
|
-
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" && has(schema, utils.ITEMS_KEY)) {
|
|
1036
|
-
const index = Number(potentialIndex);
|
|
1037
|
-
const items = schema[utils.ITEMS_KEY];
|
|
1038
|
-
if (Array.isArray(items)) {
|
|
1039
|
-
if (index > items.length) {
|
|
1040
|
-
rawSchema = last(items);
|
|
1041
|
-
} else {
|
|
1042
|
-
rawSchema = items[index];
|
|
1043
|
-
}
|
|
1044
|
-
} else {
|
|
1045
|
-
rawSchema = items;
|
|
1046
|
-
}
|
|
1047
|
-
fieldPathId = {
|
|
1048
|
-
[utils.ID_KEY]: fieldPathId[utils.ID_KEY],
|
|
1049
|
-
path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index]
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
return { rawSchema, fieldPathId };
|
|
1004
|
+
return { fieldUiSchema, uiReadonly };
|
|
1005
|
+
}
|
|
1006
|
+
function conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
|
|
1007
|
+
const data = flatten([datum]).sort();
|
|
1008
|
+
const values = flatten([value]).sort();
|
|
1009
|
+
switch (operator) {
|
|
1010
|
+
case "all" /* ALL */:
|
|
1011
|
+
return isEqual(data, values);
|
|
1012
|
+
case "some" /* SOME */:
|
|
1013
|
+
return intersection(data, values).length > 0;
|
|
1014
|
+
case "none" /* NONE */:
|
|
1015
|
+
return intersection(data, values).length === 0;
|
|
1016
|
+
default:
|
|
1017
|
+
return false;
|
|
1053
1018
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
static getSchemaDetailsForField(registry, dottedPath, initialSchema, formData, initialFieldIdPath) {
|
|
1068
|
-
const { schemaUtils, globalFormOptions } = registry;
|
|
1069
|
-
let rawSchema = initialSchema;
|
|
1070
|
-
let fieldPathId = initialFieldIdPath;
|
|
1071
|
-
const parts = dottedPath.split(".");
|
|
1072
|
-
const leafPath = parts.pop();
|
|
1073
|
-
let schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1074
|
-
let innerData = formData;
|
|
1075
|
-
let isReadonly = schema.readOnly;
|
|
1076
|
-
parts.forEach((part) => {
|
|
1077
|
-
fieldPathId = utils.toFieldPathId(part, globalFormOptions, fieldPathId);
|
|
1078
|
-
if (has(schema, utils.PROPERTIES_KEY)) {
|
|
1079
|
-
rawSchema = get2(schema, [utils.PROPERTIES_KEY, part], {});
|
|
1080
|
-
} else if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1081
|
-
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1082
|
-
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
|
|
1083
|
-
rawSchema = get2(selectedSchema, [utils.PROPERTIES_KEY, part], {});
|
|
1084
|
-
} else {
|
|
1085
|
-
const result = _LayoutGridField.computeArraySchemasIfPresent(schema, fieldPathId, part);
|
|
1086
|
-
rawSchema = result.rawSchema ?? {};
|
|
1087
|
-
fieldPathId = result.fieldPathId;
|
|
1088
|
-
}
|
|
1089
|
-
innerData = get2(innerData, part, {});
|
|
1090
|
-
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
1091
|
-
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
|
|
1092
|
-
});
|
|
1093
|
-
let optionsInfo;
|
|
1094
|
-
let isRequired = false;
|
|
1095
|
-
if (isEmpty(schema)) {
|
|
1096
|
-
schema = void 0;
|
|
1019
|
+
}
|
|
1020
|
+
function findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
|
|
1021
|
+
let gridProps = {};
|
|
1022
|
+
let children = layoutGridSchema[schemaKey];
|
|
1023
|
+
if (isPlainObject(children)) {
|
|
1024
|
+
const { children: elements, className: toMapClassNames, ...otherProps } = children;
|
|
1025
|
+
children = elements;
|
|
1026
|
+
if (toMapClassNames) {
|
|
1027
|
+
const classes = toMapClassNames.split(" ");
|
|
1028
|
+
const className = classes.map((ele) => utils.lookupFromFormContext(registry, ele, ele)).join(" ");
|
|
1029
|
+
gridProps = { ...otherProps, className };
|
|
1030
|
+
} else {
|
|
1031
|
+
gridProps = otherProps;
|
|
1097
1032
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1033
|
+
}
|
|
1034
|
+
if (!Array.isArray(children)) {
|
|
1035
|
+
throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
|
|
1036
|
+
}
|
|
1037
|
+
return { children, gridProps };
|
|
1038
|
+
}
|
|
1039
|
+
function computeArraySchemasIfPresent(schema, fieldPathId, potentialIndex) {
|
|
1040
|
+
let rawSchema;
|
|
1041
|
+
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" && has(schema, utils.ITEMS_KEY)) {
|
|
1042
|
+
const index = Number(potentialIndex);
|
|
1043
|
+
const items = schema[utils.ITEMS_KEY];
|
|
1044
|
+
if (Array.isArray(items)) {
|
|
1045
|
+
if (index > items.length) {
|
|
1046
|
+
rawSchema = last(items);
|
|
1109
1047
|
} else {
|
|
1110
|
-
|
|
1111
|
-
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1112
|
-
}
|
|
1113
|
-
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1114
|
-
if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1115
|
-
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1116
|
-
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1117
|
-
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
|
|
1048
|
+
rawSchema = items[index];
|
|
1118
1049
|
}
|
|
1050
|
+
} else {
|
|
1051
|
+
rawSchema = items;
|
|
1119
1052
|
}
|
|
1120
|
-
|
|
1053
|
+
fieldPathId = {
|
|
1054
|
+
[utils.ID_KEY]: fieldPathId[utils.ID_KEY],
|
|
1055
|
+
path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index]
|
|
1056
|
+
};
|
|
1121
1057
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
if (
|
|
1136
|
-
|
|
1058
|
+
return { rawSchema, fieldPathId };
|
|
1059
|
+
}
|
|
1060
|
+
function getSchemaDetailsForField(registry, dottedPath, initialSchema, formData, initialFieldIdPath) {
|
|
1061
|
+
const { schemaUtils, globalFormOptions } = registry;
|
|
1062
|
+
let rawSchema = initialSchema;
|
|
1063
|
+
let fieldPathId = initialFieldIdPath;
|
|
1064
|
+
const parts = dottedPath.split(".");
|
|
1065
|
+
const leafPath = parts.pop();
|
|
1066
|
+
let schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1067
|
+
let innerData = formData;
|
|
1068
|
+
let isReadonly = schema.readOnly;
|
|
1069
|
+
parts.forEach((part) => {
|
|
1070
|
+
fieldPathId = utils.toFieldPathId(part, globalFormOptions, fieldPathId);
|
|
1071
|
+
if (has(schema, utils.PROPERTIES_KEY)) {
|
|
1072
|
+
rawSchema = get(schema, [utils.PROPERTIES_KEY, part], {});
|
|
1073
|
+
} else if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1074
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1075
|
+
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
|
|
1076
|
+
rawSchema = get(selectedSchema, [utils.PROPERTIES_KEY, part], {});
|
|
1077
|
+
} else {
|
|
1078
|
+
const result = computeArraySchemasIfPresent(schema, fieldPathId, part);
|
|
1079
|
+
rawSchema = result.rawSchema ?? {};
|
|
1080
|
+
fieldPathId = result.fieldPathId;
|
|
1137
1081
|
}
|
|
1138
|
-
|
|
1082
|
+
innerData = get(innerData, part, {});
|
|
1083
|
+
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
1084
|
+
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
|
|
1085
|
+
});
|
|
1086
|
+
let optionsInfo;
|
|
1087
|
+
let isRequired2 = false;
|
|
1088
|
+
if (isEmpty(schema)) {
|
|
1089
|
+
schema = void 0;
|
|
1139
1090
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
let uiProps = {};
|
|
1152
|
-
let rendered;
|
|
1153
|
-
if (isString(gridSchema) || isUndefined(gridSchema)) {
|
|
1154
|
-
name = gridSchema ?? "";
|
|
1091
|
+
if (schema && leafPath) {
|
|
1092
|
+
if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1093
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1094
|
+
schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
|
|
1095
|
+
}
|
|
1096
|
+
fieldPathId = utils.toFieldPathId(leafPath, globalFormOptions, fieldPathId);
|
|
1097
|
+
isRequired2 = schema !== void 0 && Array.isArray(schema.required) && includes(schema.required, leafPath);
|
|
1098
|
+
const result = computeArraySchemasIfPresent(schema, fieldPathId, leafPath);
|
|
1099
|
+
if (result.rawSchema) {
|
|
1100
|
+
schema = result.rawSchema;
|
|
1101
|
+
fieldPathId = result.fieldPathId;
|
|
1155
1102
|
} else {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const name2 = match[1];
|
|
1165
|
-
uiProps[key] = utils.lookupFromFormContext(registry, name2, name2);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
UIComponent = _LayoutGridField.getCustomRenderComponent(render, registry);
|
|
1171
|
-
if (!innerName && UIComponent) {
|
|
1172
|
-
rendered = /* @__PURE__ */ jsxRuntime.jsx(UIComponent, { ...innerProps, "data-testid": _LayoutGridField.TEST_IDS.uiComponent });
|
|
1173
|
-
}
|
|
1103
|
+
schema = get(schema, [utils.PROPERTIES_KEY, leafPath]);
|
|
1104
|
+
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1105
|
+
}
|
|
1106
|
+
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1107
|
+
if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1108
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1109
|
+
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1110
|
+
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
|
|
1174
1111
|
}
|
|
1175
|
-
return { name, UIComponent, uiProps, rendered };
|
|
1176
1112
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1113
|
+
return { schema, isRequired: isRequired2, isReadonly, optionsInfo, fieldPathId };
|
|
1114
|
+
}
|
|
1115
|
+
function getCustomRenderComponent(render, registry) {
|
|
1116
|
+
let customRenderer = render;
|
|
1117
|
+
if (isString(customRenderer)) {
|
|
1118
|
+
customRenderer = utils.lookupFromFormContext(registry, customRenderer);
|
|
1183
1119
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
* elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
|
|
1187
|
-
*
|
|
1188
|
-
* @param dottedPath - The dotted-path to the field for which to generate the onChange handler
|
|
1189
|
-
* @returns - The `onChange` handling function for the `dottedPath` field of the `schemaType` type
|
|
1190
|
-
*/
|
|
1191
|
-
onFieldChange = (dottedPath) => {
|
|
1192
|
-
return (value, path, errSchema, id) => {
|
|
1193
|
-
const { onChange } = this.props;
|
|
1194
|
-
onChange(value, path, errSchema, id);
|
|
1195
|
-
};
|
|
1196
|
-
};
|
|
1197
|
-
/** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
|
|
1198
|
-
* `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
|
|
1199
|
-
* the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
|
|
1200
|
-
* rendered, otherwise null is returned.
|
|
1201
|
-
*
|
|
1202
|
-
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1203
|
-
* @returns - The rendered the children for the `GridType.CONDITION` or null
|
|
1204
|
-
*/
|
|
1205
|
-
renderCondition(layoutGridSchema) {
|
|
1206
|
-
const { formData, registry } = this.props;
|
|
1207
|
-
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1208
|
-
layoutGridSchema,
|
|
1209
|
-
"ui:condition" /* CONDITION */,
|
|
1210
|
-
registry
|
|
1211
|
-
);
|
|
1212
|
-
const { operator, field = "", value } = gridProps;
|
|
1213
|
-
const fieldData = get2(formData, field, null);
|
|
1214
|
-
if (_LayoutGridField.conditionMatches(operator, fieldData, value)) {
|
|
1215
|
-
return this.renderChildren(children);
|
|
1216
|
-
}
|
|
1217
|
-
return null;
|
|
1120
|
+
if (isFunction(customRenderer)) {
|
|
1121
|
+
return customRenderer;
|
|
1218
1122
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
)
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
function computeUIComponentPropsFromGridSchema(registry, gridSchema) {
|
|
1126
|
+
let name;
|
|
1127
|
+
let UIComponent = null;
|
|
1128
|
+
let uiProps = {};
|
|
1129
|
+
let rendered;
|
|
1130
|
+
if (isString(gridSchema) || isUndefined(gridSchema)) {
|
|
1131
|
+
name = gridSchema ?? "";
|
|
1132
|
+
} else {
|
|
1133
|
+
const { name: innerName = "", render, ...innerProps } = gridSchema;
|
|
1134
|
+
name = innerName;
|
|
1135
|
+
uiProps = innerProps;
|
|
1136
|
+
if (!isEmpty(uiProps)) {
|
|
1137
|
+
each(uiProps, (prop, key) => {
|
|
1138
|
+
if (isString(prop)) {
|
|
1139
|
+
const match = LOOKUP_REGEX.exec(prop);
|
|
1140
|
+
if (Array.isArray(match) && match.length > 1) {
|
|
1141
|
+
const name2 = match[1];
|
|
1142
|
+
uiProps[key] = utils.lookupFromFormContext(registry, name2, name2);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
UIComponent = getCustomRenderComponent(render, registry);
|
|
1148
|
+
if (!innerName && UIComponent) {
|
|
1149
|
+
rendered = /* @__PURE__ */ jsxRuntime.jsx(UIComponent, { ...innerProps, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.uiComponent });
|
|
1150
|
+
}
|
|
1236
1151
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
));
|
|
1152
|
+
return { name, UIComponent, uiProps, rendered };
|
|
1153
|
+
}
|
|
1154
|
+
function LayoutGridFieldChildren(props) {
|
|
1155
|
+
const { childrenLayoutGridSchemaId, ...layoutGridFieldProps } = props;
|
|
1156
|
+
const { registry, schema: rawSchema, formData } = layoutGridFieldProps;
|
|
1157
|
+
const { schemaUtils } = registry;
|
|
1158
|
+
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1159
|
+
return childrenLayoutGridSchemaId.map((layoutGridSchema) => /* @__PURE__ */ react.createElement(
|
|
1160
|
+
LayoutGridField,
|
|
1161
|
+
{
|
|
1162
|
+
...layoutGridFieldProps,
|
|
1163
|
+
key: `layoutGrid-${utils.hashObject(layoutGridSchema)}`,
|
|
1164
|
+
schema,
|
|
1165
|
+
layoutGridSchema
|
|
1166
|
+
}
|
|
1167
|
+
));
|
|
1168
|
+
}
|
|
1169
|
+
function LayoutGridCondition(props) {
|
|
1170
|
+
const { layoutGridSchema, ...layoutGridFieldProps } = props;
|
|
1171
|
+
const { formData, registry } = layoutGridFieldProps;
|
|
1172
|
+
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:condition" /* CONDITION */, registry);
|
|
1173
|
+
const { operator, field = "", value } = gridProps;
|
|
1174
|
+
const fieldData = get(formData, field, null);
|
|
1175
|
+
if (conditionMatches(operator, fieldData, value)) {
|
|
1176
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children });
|
|
1263
1177
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1178
|
+
return null;
|
|
1179
|
+
}
|
|
1180
|
+
function LayoutGridCol(props) {
|
|
1181
|
+
const { layoutGridSchema, ...layoutGridFieldProps } = props;
|
|
1182
|
+
const { registry, uiSchema } = layoutGridFieldProps;
|
|
1183
|
+
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:col" /* COLUMN */, registry);
|
|
1184
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1185
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1186
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GridTemplate2, { column: true, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.col, ...gridProps, children: /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children }) });
|
|
1187
|
+
}
|
|
1188
|
+
function LayoutGridColumns(props) {
|
|
1189
|
+
const { layoutGridSchema, ...layoutGridFieldProps } = props;
|
|
1190
|
+
const { registry, uiSchema } = layoutGridFieldProps;
|
|
1191
|
+
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:columns" /* COLUMNS */, registry);
|
|
1192
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1193
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1194
|
+
return children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1195
|
+
GridTemplate2,
|
|
1196
|
+
{
|
|
1197
|
+
column: true,
|
|
1198
|
+
"data-testid": LAYOUT_GRID_FIELD_TEST_IDS.col,
|
|
1199
|
+
...gridProps,
|
|
1200
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: [child] })
|
|
1201
|
+
},
|
|
1202
|
+
`column-${utils.hashObject(child)}`
|
|
1203
|
+
));
|
|
1204
|
+
}
|
|
1205
|
+
function LayoutGridRow(props) {
|
|
1206
|
+
const { layoutGridSchema, ...layoutGridFieldProps } = props;
|
|
1207
|
+
const { registry, uiSchema } = layoutGridFieldProps;
|
|
1208
|
+
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:row" /* ROW */, registry);
|
|
1209
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1210
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1211
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GridTemplate2, { ...gridProps, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.row, children: /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children }) });
|
|
1212
|
+
}
|
|
1213
|
+
function LayoutGridFieldComponent(props) {
|
|
1214
|
+
const {
|
|
1215
|
+
gridSchema,
|
|
1216
|
+
schema: initialSchema,
|
|
1217
|
+
uiSchema,
|
|
1218
|
+
errorSchema,
|
|
1219
|
+
fieldPathId,
|
|
1220
|
+
onBlur,
|
|
1221
|
+
onFocus,
|
|
1222
|
+
formData,
|
|
1223
|
+
readonly,
|
|
1224
|
+
registry,
|
|
1225
|
+
layoutGridSchema,
|
|
1226
|
+
// Used to pull this out of otherProps since we don't want to pass it through
|
|
1227
|
+
...otherProps
|
|
1228
|
+
} = props;
|
|
1229
|
+
const { onChange } = otherProps;
|
|
1230
|
+
const { fields: fields2 } = registry;
|
|
1231
|
+
const { SchemaField: SchemaField2, LayoutMultiSchemaField: LayoutMultiSchemaField2 } = fields2;
|
|
1232
|
+
const uiComponentProps = computeUIComponentPropsFromGridSchema(registry, gridSchema);
|
|
1233
|
+
const { name, UIComponent, uiProps } = uiComponentProps;
|
|
1234
|
+
const {
|
|
1235
|
+
schema,
|
|
1236
|
+
isRequired: isRequired2,
|
|
1237
|
+
isReadonly,
|
|
1238
|
+
optionsInfo,
|
|
1239
|
+
fieldPathId: fieldIdSchema
|
|
1240
|
+
} = getSchemaDetailsForField(registry, name, initialSchema, formData, fieldPathId);
|
|
1241
|
+
const memoFieldPathId = utils.useDeepCompareMemo(fieldIdSchema);
|
|
1242
|
+
if (uiComponentProps.rendered) {
|
|
1243
|
+
return uiComponentProps.rendered;
|
|
1281
1244
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
* @param childrenLayoutGrfieldPathId - The list of strings or objects that represents the configurations for the
|
|
1288
|
-
* children fields
|
|
1289
|
-
* @returns - The nested `LayoutGridField`s
|
|
1290
|
-
*/
|
|
1291
|
-
renderChildren(childrenLayoutGrfieldPathId) {
|
|
1292
|
-
const { registry, schema: rawSchema, formData } = this.props;
|
|
1293
|
-
const { schemaUtils } = registry;
|
|
1294
|
-
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1295
|
-
return childrenLayoutGrfieldPathId.map((layoutGridSchema) => /* @__PURE__ */ react.createElement(
|
|
1296
|
-
_LayoutGridField,
|
|
1245
|
+
if (schema) {
|
|
1246
|
+
const Field2 = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
|
|
1247
|
+
const { fieldUiSchema, uiReadonly } = computeFieldUiSchema(name, uiProps, uiSchema, isReadonly, readonly);
|
|
1248
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1249
|
+
Field2,
|
|
1297
1250
|
{
|
|
1298
|
-
|
|
1299
|
-
|
|
1251
|
+
"data-testid": optionsInfo?.hasDiscriminator ? LAYOUT_GRID_FIELD_TEST_IDS.layoutMultiSchemaField : LAYOUT_GRID_FIELD_TEST_IDS.field,
|
|
1252
|
+
...otherProps,
|
|
1253
|
+
name,
|
|
1254
|
+
required: isRequired2,
|
|
1255
|
+
readonly: uiReadonly,
|
|
1300
1256
|
schema,
|
|
1301
|
-
|
|
1257
|
+
uiSchema: fieldUiSchema,
|
|
1258
|
+
errorSchema: get(errorSchema, name),
|
|
1259
|
+
fieldPathId: memoFieldPathId,
|
|
1260
|
+
formData: get(formData, name),
|
|
1261
|
+
onChange,
|
|
1262
|
+
onBlur,
|
|
1263
|
+
onFocus,
|
|
1264
|
+
options: optionsInfo?.options,
|
|
1265
|
+
registry
|
|
1302
1266
|
}
|
|
1303
|
-
)
|
|
1267
|
+
);
|
|
1304
1268
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
* `uiSchema`, `errorSchema`, `fieldPathId` and `formData` drilled down to the dotted-path field, spreading any other
|
|
1312
|
-
* props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
|
|
1313
|
-
* then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
|
|
1314
|
-
* schema was located, but a custom render component was found, then it will be rendered with many of the non-event
|
|
1315
|
-
* handling props. If none of the previous render paths are valid, then a null is returned.
|
|
1316
|
-
*
|
|
1317
|
-
* @param gridSchema - The string or object that represents the configuration for the grid field
|
|
1318
|
-
* @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
|
|
1319
|
-
*/
|
|
1320
|
-
renderField(gridSchema) {
|
|
1321
|
-
const {
|
|
1322
|
-
schema: initialSchema,
|
|
1323
|
-
uiSchema,
|
|
1324
|
-
errorSchema,
|
|
1325
|
-
fieldPathId,
|
|
1326
|
-
onBlur,
|
|
1327
|
-
onFocus,
|
|
1328
|
-
formData,
|
|
1329
|
-
readonly,
|
|
1330
|
-
registry,
|
|
1331
|
-
layoutGridSchema,
|
|
1332
|
-
// Used to pull this out of otherProps since we don't want to pass it through
|
|
1333
|
-
...otherProps
|
|
1334
|
-
} = this.props;
|
|
1335
|
-
const { fields: fields2 } = registry;
|
|
1336
|
-
const { SchemaField: SchemaField2, LayoutMultiSchemaField: LayoutMultiSchemaField2 } = fields2;
|
|
1337
|
-
const uiComponentProps = _LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
|
|
1338
|
-
if (uiComponentProps.rendered) {
|
|
1339
|
-
return uiComponentProps.rendered;
|
|
1340
|
-
}
|
|
1341
|
-
const { name, UIComponent, uiProps } = uiComponentProps;
|
|
1342
|
-
const {
|
|
1343
|
-
schema,
|
|
1344
|
-
isRequired,
|
|
1345
|
-
isReadonly,
|
|
1346
|
-
optionsInfo,
|
|
1347
|
-
fieldPathId: fieldIdSchema
|
|
1348
|
-
} = _LayoutGridField.getSchemaDetailsForField(registry, name, initialSchema, formData, fieldPathId);
|
|
1349
|
-
if (schema) {
|
|
1350
|
-
const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
|
|
1351
|
-
const { fieldUiSchema, uiReadonly } = _LayoutGridField.computeFieldUiSchema(
|
|
1269
|
+
if (UIComponent) {
|
|
1270
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1271
|
+
UIComponent,
|
|
1272
|
+
{
|
|
1273
|
+
"data-testid": LAYOUT_GRID_FIELD_TEST_IDS.uiComponent,
|
|
1274
|
+
...otherProps,
|
|
1352
1275
|
name,
|
|
1353
|
-
|
|
1276
|
+
required: isRequired2,
|
|
1277
|
+
formData,
|
|
1278
|
+
readOnly: !!isReadonly || readonly,
|
|
1279
|
+
errorSchema,
|
|
1354
1280
|
uiSchema,
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
}
|
|
1377
|
-
);
|
|
1281
|
+
schema: initialSchema,
|
|
1282
|
+
fieldPathId,
|
|
1283
|
+
onBlur,
|
|
1284
|
+
onFocus,
|
|
1285
|
+
registry,
|
|
1286
|
+
...uiProps
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
return null;
|
|
1291
|
+
}
|
|
1292
|
+
function LayoutGridField(props) {
|
|
1293
|
+
const { uiSchema } = props;
|
|
1294
|
+
let { layoutGridSchema } = props;
|
|
1295
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1296
|
+
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1297
|
+
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
|
|
1298
|
+
}
|
|
1299
|
+
if (isObject(layoutGridSchema)) {
|
|
1300
|
+
if ("ui:row" /* ROW */ in layoutGridSchema) {
|
|
1301
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridRow, { ...props, layoutGridSchema });
|
|
1378
1302
|
}
|
|
1379
|
-
if (
|
|
1380
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1381
|
-
UIComponent,
|
|
1382
|
-
{
|
|
1383
|
-
"data-testid": _LayoutGridField.TEST_IDS.uiComponent,
|
|
1384
|
-
...otherProps,
|
|
1385
|
-
name,
|
|
1386
|
-
required: isRequired,
|
|
1387
|
-
formData,
|
|
1388
|
-
readOnly: !!isReadonly || readonly,
|
|
1389
|
-
errorSchema,
|
|
1390
|
-
uiSchema,
|
|
1391
|
-
schema: initialSchema,
|
|
1392
|
-
fieldPathId,
|
|
1393
|
-
onBlur,
|
|
1394
|
-
onFocus,
|
|
1395
|
-
registry,
|
|
1396
|
-
...uiProps
|
|
1397
|
-
}
|
|
1398
|
-
);
|
|
1303
|
+
if ("ui:col" /* COLUMN */ in layoutGridSchema) {
|
|
1304
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridCol, { ...props, layoutGridSchema });
|
|
1399
1305
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
/** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
|
|
1403
|
-
* `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
|
|
1404
|
-
* match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
|
|
1405
|
-
* generic `renderField()` function with the `layoutGridSchema`.
|
|
1406
|
-
*
|
|
1407
|
-
* @returns - the rendered `LayoutGridField`
|
|
1408
|
-
*/
|
|
1409
|
-
render() {
|
|
1410
|
-
const { uiSchema } = this.props;
|
|
1411
|
-
let { layoutGridSchema } = this.props;
|
|
1412
|
-
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1413
|
-
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1414
|
-
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
|
|
1306
|
+
if ("ui:columns" /* COLUMNS */ in layoutGridSchema) {
|
|
1307
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridColumns, { ...props, layoutGridSchema });
|
|
1415
1308
|
}
|
|
1416
|
-
if (
|
|
1417
|
-
|
|
1418
|
-
return this.renderRow(layoutGridSchema);
|
|
1419
|
-
}
|
|
1420
|
-
if ("ui:col" /* COLUMN */ in layoutGridSchema) {
|
|
1421
|
-
return this.renderCol(layoutGridSchema);
|
|
1422
|
-
}
|
|
1423
|
-
if ("ui:columns" /* COLUMNS */ in layoutGridSchema) {
|
|
1424
|
-
return this.renderColumns(layoutGridSchema);
|
|
1425
|
-
}
|
|
1426
|
-
if ("ui:condition" /* CONDITION */ in layoutGridSchema) {
|
|
1427
|
-
return this.renderCondition(layoutGridSchema);
|
|
1428
|
-
}
|
|
1309
|
+
if ("ui:condition" /* CONDITION */ in layoutGridSchema) {
|
|
1310
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridCondition, { ...props, layoutGridSchema });
|
|
1429
1311
|
}
|
|
1430
|
-
return this.renderField(layoutGridSchema);
|
|
1431
1312
|
}
|
|
1432
|
-
|
|
1313
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldComponent, { ...props, gridSchema: layoutGridSchema });
|
|
1314
|
+
}
|
|
1315
|
+
LayoutGridField.TEST_IDS = LAYOUT_GRID_FIELD_TEST_IDS;
|
|
1433
1316
|
function LayoutHeaderField(props) {
|
|
1434
1317
|
const { fieldPathId, title, schema, uiSchema, required, registry, name } = props;
|
|
1435
1318
|
const options = utils.getUiOptions(uiSchema, registry.globalUiOptions);
|
|
@@ -1460,8 +1343,8 @@
|
|
|
1460
1343
|
const defaultValue = "!@#!@$@#$!@$#";
|
|
1461
1344
|
const schemaOptions = options.map(({ schema }) => schema);
|
|
1462
1345
|
return schemaOptions.find((option) => {
|
|
1463
|
-
const selector =
|
|
1464
|
-
const result =
|
|
1346
|
+
const selector = get(option, [utils.PROPERTIES_KEY, selectorField]);
|
|
1347
|
+
const result = get(selector, utils.DEFAULT_KEY, get(selector, utils.CONST_KEY, defaultValue));
|
|
1465
1348
|
return result === value;
|
|
1466
1349
|
});
|
|
1467
1350
|
}
|
|
@@ -1493,7 +1376,6 @@
|
|
|
1493
1376
|
registry,
|
|
1494
1377
|
uiSchema,
|
|
1495
1378
|
schema,
|
|
1496
|
-
formContext,
|
|
1497
1379
|
autofocus,
|
|
1498
1380
|
readonly,
|
|
1499
1381
|
required,
|
|
@@ -1502,7 +1384,7 @@
|
|
|
1502
1384
|
} = props;
|
|
1503
1385
|
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
1504
1386
|
const [enumOptions, setEnumOptions] = react.useState(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1505
|
-
const id =
|
|
1387
|
+
const id = get(fieldPathId, utils.ID_KEY);
|
|
1506
1388
|
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1507
1389
|
const FieldErrorTemplate2 = utils.getTemplate("FieldErrorTemplate", registry, options);
|
|
1508
1390
|
const FieldTemplate2 = utils.getTemplate("FieldTemplate", registry, options);
|
|
@@ -1524,13 +1406,13 @@
|
|
|
1524
1406
|
if (!selectorField) {
|
|
1525
1407
|
throw new Error("No selector field provided for the LayoutMultiSchemaField");
|
|
1526
1408
|
}
|
|
1527
|
-
const selectedOption =
|
|
1528
|
-
let optionSchema =
|
|
1409
|
+
const selectedOption = get(formData, selectorField);
|
|
1410
|
+
let optionSchema = get(enumOptions[0]?.schema, [utils.PROPERTIES_KEY, selectorField], {});
|
|
1529
1411
|
const option = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1530
1412
|
optionSchema = optionSchema?.type ? optionSchema : { ...optionSchema, type: option?.type || baseType };
|
|
1531
1413
|
const Widget = utils.getWidget(optionSchema, widget, widgets2);
|
|
1532
1414
|
const hideFieldError = uiSchemaHideError === void 0 ? hideError : Boolean(uiSchemaHideError);
|
|
1533
|
-
const rawErrors =
|
|
1415
|
+
const rawErrors = get(errorSchema, [utils.ERRORS_KEY], []);
|
|
1534
1416
|
const fieldErrorSchema = omit3(errorSchema, [utils.ERRORS_KEY]);
|
|
1535
1417
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1536
1418
|
const onOptionChange = (opt) => {
|
|
@@ -1547,7 +1429,6 @@
|
|
|
1547
1429
|
};
|
|
1548
1430
|
const widgetOptions = { enumOptions, ...uiOptions };
|
|
1549
1431
|
const errors = !hideFieldError && rawErrors.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(FieldErrorTemplate2, { fieldPathId, schema, errors: rawErrors, registry }) : void 0;
|
|
1550
|
-
const ignored = (value) => noop;
|
|
1551
1432
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1552
1433
|
FieldTemplate2,
|
|
1553
1434
|
{
|
|
@@ -1562,8 +1443,9 @@
|
|
|
1562
1443
|
displayLabel,
|
|
1563
1444
|
errors,
|
|
1564
1445
|
onChange,
|
|
1565
|
-
|
|
1566
|
-
|
|
1446
|
+
onKeyRename: noop,
|
|
1447
|
+
onKeyRenameBlur: noop,
|
|
1448
|
+
onRemoveProperty: noop,
|
|
1567
1449
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1568
1450
|
Widget,
|
|
1569
1451
|
{
|
|
@@ -1573,7 +1455,6 @@
|
|
|
1573
1455
|
label: (title || schema.title) ?? "",
|
|
1574
1456
|
disabled: disabled || Array.isArray(enumOptions) && isEmpty(enumOptions),
|
|
1575
1457
|
uiSchema,
|
|
1576
|
-
formContext,
|
|
1577
1458
|
autofocus,
|
|
1578
1459
|
readonly,
|
|
1579
1460
|
required,
|
|
@@ -1588,7 +1469,8 @@
|
|
|
1588
1469
|
onBlur,
|
|
1589
1470
|
onFocus,
|
|
1590
1471
|
value: selectedOption,
|
|
1591
|
-
options: widgetOptions
|
|
1472
|
+
options: widgetOptions,
|
|
1473
|
+
htmlName: fieldPathId.name
|
|
1592
1474
|
}
|
|
1593
1475
|
)
|
|
1594
1476
|
}
|
|
@@ -1690,10 +1572,11 @@
|
|
|
1690
1572
|
name,
|
|
1691
1573
|
disabled = false,
|
|
1692
1574
|
errorSchema = {},
|
|
1693
|
-
|
|
1575
|
+
formData,
|
|
1694
1576
|
onBlur,
|
|
1695
1577
|
onFocus,
|
|
1696
1578
|
readonly,
|
|
1579
|
+
required = false,
|
|
1697
1580
|
registry,
|
|
1698
1581
|
schema,
|
|
1699
1582
|
uiSchema
|
|
@@ -1705,6 +1588,8 @@
|
|
|
1705
1588
|
registry,
|
|
1706
1589
|
globalUiOptions
|
|
1707
1590
|
);
|
|
1591
|
+
const isOptionalRender = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
1592
|
+
const hasFormData = utils.isFormDataAvailable(formData);
|
|
1708
1593
|
const { selectedOption, retrievedOptions } = this.state;
|
|
1709
1594
|
const {
|
|
1710
1595
|
widget = "select",
|
|
@@ -1715,14 +1600,14 @@
|
|
|
1715
1600
|
...uiOptions
|
|
1716
1601
|
} = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1717
1602
|
const Widget = utils.getWidget({ type: "number" }, widget, widgets2);
|
|
1718
|
-
const rawErrors =
|
|
1603
|
+
const rawErrors = get(errorSchema, utils.ERRORS_KEY, []);
|
|
1719
1604
|
const fieldErrorSchema = omit3(errorSchema, [utils.ERRORS_KEY]);
|
|
1720
1605
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1721
1606
|
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
1722
1607
|
let optionSchema;
|
|
1723
1608
|
if (option) {
|
|
1724
|
-
const { required } = schema;
|
|
1725
|
-
optionSchema =
|
|
1609
|
+
const { required: required2 } = schema;
|
|
1610
|
+
optionSchema = required2 ? utils.mergeSchemas({ required: required2 }, option) : option;
|
|
1726
1611
|
}
|
|
1727
1612
|
let optionsUiSchema = [];
|
|
1728
1613
|
if (utils.ONE_OF_KEY in schema && uiSchema && utils.ONE_OF_KEY in uiSchema) {
|
|
@@ -1751,7 +1636,7 @@
|
|
|
1751
1636
|
value: index
|
|
1752
1637
|
};
|
|
1753
1638
|
});
|
|
1754
|
-
const selector = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1639
|
+
const selector = !isOptionalRender || hasFormData ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1755
1640
|
Widget,
|
|
1756
1641
|
{
|
|
1757
1642
|
id: this.getFieldId(),
|
|
@@ -1767,7 +1652,6 @@
|
|
|
1767
1652
|
value: selectedOption >= 0 ? selectedOption : void 0,
|
|
1768
1653
|
options: { enumOptions, ...uiOptions },
|
|
1769
1654
|
registry,
|
|
1770
|
-
formContext,
|
|
1771
1655
|
placeholder,
|
|
1772
1656
|
autocomplete,
|
|
1773
1657
|
autofocus,
|
|
@@ -1775,7 +1659,7 @@
|
|
|
1775
1659
|
hideLabel: !displayLabel,
|
|
1776
1660
|
readonly
|
|
1777
1661
|
}
|
|
1778
|
-
);
|
|
1662
|
+
) : void 0;
|
|
1779
1663
|
const optionsSchemaField = optionSchema && optionSchema.type !== "null" && /* @__PURE__ */ jsxRuntime.jsx(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema }) || null;
|
|
1780
1664
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1781
1665
|
MultiSchemaFieldTemplate2,
|
|
@@ -1817,132 +1701,154 @@
|
|
|
1817
1701
|
return /* @__PURE__ */ jsxRuntime.jsx(StringField2, { ...props, formData: value, onChange: handleChange });
|
|
1818
1702
|
}
|
|
1819
1703
|
var NumberField_default = NumberField;
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1704
|
+
function isRequired(schema, name) {
|
|
1705
|
+
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1706
|
+
}
|
|
1707
|
+
function getDefaultValue(translateString, type) {
|
|
1708
|
+
switch (type) {
|
|
1709
|
+
case "array":
|
|
1710
|
+
return [];
|
|
1711
|
+
case "boolean":
|
|
1712
|
+
return false;
|
|
1713
|
+
case "null":
|
|
1714
|
+
return null;
|
|
1715
|
+
case "number":
|
|
1716
|
+
return 0;
|
|
1717
|
+
case "object":
|
|
1718
|
+
return {};
|
|
1719
|
+
case "string":
|
|
1720
|
+
default:
|
|
1721
|
+
return translateString(utils.TranslatableString.NewStringDefault);
|
|
1834
1722
|
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1723
|
+
}
|
|
1724
|
+
function ObjectFieldProperty(props) {
|
|
1725
|
+
const {
|
|
1726
|
+
fieldPathId,
|
|
1727
|
+
schema,
|
|
1728
|
+
registry,
|
|
1729
|
+
uiSchema,
|
|
1730
|
+
errorSchema,
|
|
1731
|
+
formData,
|
|
1732
|
+
onChange,
|
|
1733
|
+
onBlur,
|
|
1734
|
+
onFocus,
|
|
1735
|
+
disabled,
|
|
1736
|
+
readonly,
|
|
1737
|
+
required,
|
|
1738
|
+
hideError,
|
|
1739
|
+
propertyName,
|
|
1740
|
+
handleKeyRename,
|
|
1741
|
+
handleRemoveProperty,
|
|
1742
|
+
addedByAdditionalProperties
|
|
1743
|
+
} = props;
|
|
1744
|
+
const [wasPropertyKeyModified, setWasPropertyKeyModified] = react.useState(false);
|
|
1745
|
+
const { globalFormOptions, fields: fields2 } = registry;
|
|
1746
|
+
const { SchemaField: SchemaField2 } = fields2;
|
|
1747
|
+
const innerFieldIdPathId = utils.useDeepCompareMemo(
|
|
1748
|
+
utils.toFieldPathId(propertyName, globalFormOptions, fieldPathId.path)
|
|
1749
|
+
);
|
|
1750
|
+
const onPropertyChange = react.useCallback(
|
|
1751
|
+
(value, path, newErrorSchema, id) => {
|
|
1846
1752
|
if (value === void 0 && addedByAdditionalProperties) {
|
|
1847
1753
|
value = "";
|
|
1848
1754
|
}
|
|
1849
1755
|
onChange(value, path, newErrorSchema, id);
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
*/
|
|
1858
|
-
onDropPropertyClick = (key) => {
|
|
1859
|
-
return (event) => {
|
|
1860
|
-
event.preventDefault();
|
|
1861
|
-
const { onChange, formData, fieldPathId } = this.props;
|
|
1862
|
-
const copiedFormData = { ...formData };
|
|
1863
|
-
unset(copiedFormData, key);
|
|
1864
|
-
onChange(copiedFormData, fieldPathId.path);
|
|
1865
|
-
};
|
|
1866
|
-
};
|
|
1867
|
-
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
1868
|
-
* that is already not assigned is found.
|
|
1869
|
-
*
|
|
1870
|
-
* @param preferredKey - The preferred name of a new key
|
|
1871
|
-
* @param [formData] - The form data in which to check if the desired key already exists
|
|
1872
|
-
* @returns - The name of the next available key from `preferredKey`
|
|
1873
|
-
*/
|
|
1874
|
-
getAvailableKey = (preferredKey, formData) => {
|
|
1875
|
-
const { uiSchema, registry } = this.props;
|
|
1876
|
-
const { duplicateKeySuffixSeparator = "-" } = utils.getUiOptions(uiSchema, registry.globalUiOptions);
|
|
1877
|
-
let index = 0;
|
|
1878
|
-
let newKey = preferredKey;
|
|
1879
|
-
while (has(formData, newKey)) {
|
|
1880
|
-
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
1881
|
-
}
|
|
1882
|
-
return newKey;
|
|
1883
|
-
};
|
|
1884
|
-
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
1885
|
-
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
1886
|
-
*
|
|
1887
|
-
* @param oldValue - The old value of a field
|
|
1888
|
-
* @returns - The key change callback function
|
|
1889
|
-
*/
|
|
1890
|
-
onKeyChange = (oldValue) => {
|
|
1891
|
-
return (value) => {
|
|
1892
|
-
if (oldValue === value) {
|
|
1893
|
-
return;
|
|
1756
|
+
},
|
|
1757
|
+
[onChange, addedByAdditionalProperties]
|
|
1758
|
+
);
|
|
1759
|
+
const onKeyRename = react.useCallback(
|
|
1760
|
+
(value) => {
|
|
1761
|
+
if (propertyName !== value) {
|
|
1762
|
+
setWasPropertyKeyModified(true);
|
|
1894
1763
|
}
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1764
|
+
handleKeyRename(propertyName, value);
|
|
1765
|
+
},
|
|
1766
|
+
[propertyName, handleKeyRename]
|
|
1767
|
+
);
|
|
1768
|
+
const onKeyRenameBlur = react.useCallback(
|
|
1769
|
+
(event) => {
|
|
1770
|
+
const {
|
|
1771
|
+
target: { value }
|
|
1772
|
+
} = event;
|
|
1773
|
+
onKeyRename(value);
|
|
1774
|
+
},
|
|
1775
|
+
[onKeyRename]
|
|
1776
|
+
);
|
|
1777
|
+
const onRemoveProperty = react.useCallback(() => {
|
|
1778
|
+
handleRemoveProperty(propertyName);
|
|
1779
|
+
}, [propertyName, handleRemoveProperty]);
|
|
1780
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1781
|
+
SchemaField2,
|
|
1782
|
+
{
|
|
1783
|
+
name: propertyName,
|
|
1784
|
+
required,
|
|
1785
|
+
schema,
|
|
1786
|
+
uiSchema,
|
|
1787
|
+
errorSchema,
|
|
1788
|
+
fieldPathId: innerFieldIdPathId,
|
|
1789
|
+
formData,
|
|
1790
|
+
wasPropertyKeyModified,
|
|
1791
|
+
onKeyRename,
|
|
1792
|
+
onKeyRenameBlur,
|
|
1793
|
+
onRemoveProperty,
|
|
1794
|
+
onChange: onPropertyChange,
|
|
1795
|
+
onBlur,
|
|
1796
|
+
onFocus,
|
|
1797
|
+
registry,
|
|
1798
|
+
disabled,
|
|
1799
|
+
readonly,
|
|
1800
|
+
hideError
|
|
1932
1801
|
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
function ObjectField(props) {
|
|
1805
|
+
const {
|
|
1806
|
+
schema: rawSchema,
|
|
1807
|
+
uiSchema = {},
|
|
1808
|
+
formData,
|
|
1809
|
+
errorSchema,
|
|
1810
|
+
fieldPathId,
|
|
1811
|
+
name,
|
|
1812
|
+
required = false,
|
|
1813
|
+
disabled,
|
|
1814
|
+
readonly,
|
|
1815
|
+
hideError,
|
|
1816
|
+
onBlur,
|
|
1817
|
+
onFocus,
|
|
1818
|
+
onChange,
|
|
1819
|
+
registry,
|
|
1820
|
+
title
|
|
1821
|
+
} = props;
|
|
1822
|
+
const { fields: fields2, schemaUtils, translateString, globalUiOptions } = registry;
|
|
1823
|
+
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
1824
|
+
const schema = schemaUtils.retrieveSchema(rawSchema, formData, true);
|
|
1825
|
+
const uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1826
|
+
const { properties: schemaProperties = {} } = schema;
|
|
1827
|
+
const formDataHash = utils.hashObject(formData || {});
|
|
1828
|
+
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
1829
|
+
const description = uiOptions.description ?? schema.description;
|
|
1830
|
+
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
1831
|
+
const hasFormData = utils.isFormDataAvailable(formData);
|
|
1832
|
+
let orderedProperties = [];
|
|
1833
|
+
const getAvailableKey = react.useCallback(
|
|
1834
|
+
(preferredKey, formData2) => {
|
|
1835
|
+
const { duplicateKeySuffixSeparator = "-" } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1836
|
+
let index = 0;
|
|
1837
|
+
let newKey = preferredKey;
|
|
1838
|
+
while (has(formData2, newKey)) {
|
|
1839
|
+
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
1840
|
+
}
|
|
1841
|
+
return newKey;
|
|
1842
|
+
},
|
|
1843
|
+
[uiSchema, globalUiOptions]
|
|
1844
|
+
);
|
|
1845
|
+
const onAddProperty = react.useCallback(() => {
|
|
1940
1846
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
1941
1847
|
return;
|
|
1942
1848
|
}
|
|
1943
|
-
const {
|
|
1849
|
+
const { translateString: translateString2 } = registry;
|
|
1944
1850
|
const newFormData = { ...formData };
|
|
1945
|
-
const newKey =
|
|
1851
|
+
const newKey = getAvailableKey("newKey", newFormData);
|
|
1946
1852
|
if (schema.patternProperties) {
|
|
1947
1853
|
set(newFormData, newKey, null);
|
|
1948
1854
|
} else {
|
|
@@ -1955,8 +1861,8 @@
|
|
|
1955
1861
|
defaultValue = schema.additionalProperties.default;
|
|
1956
1862
|
let apSchema = schema.additionalProperties;
|
|
1957
1863
|
if (utils.REF_KEY in apSchema) {
|
|
1958
|
-
const { schemaUtils } = registry;
|
|
1959
|
-
apSchema =
|
|
1864
|
+
const { schemaUtils: schemaUtils2 } = registry;
|
|
1865
|
+
apSchema = schemaUtils2.retrieveSchema({ [utils.REF_KEY]: apSchema[utils.REF_KEY] }, formData);
|
|
1960
1866
|
type = apSchema.type;
|
|
1961
1867
|
constValue = apSchema.const;
|
|
1962
1868
|
defaultValue = apSchema.default;
|
|
@@ -1965,111 +1871,104 @@
|
|
|
1965
1871
|
type = "object";
|
|
1966
1872
|
}
|
|
1967
1873
|
}
|
|
1968
|
-
const newValue = constValue ?? defaultValue ??
|
|
1874
|
+
const newValue = constValue ?? defaultValue ?? getDefaultValue(translateString2, type);
|
|
1969
1875
|
set(newFormData, newKey, newValue);
|
|
1970
1876
|
}
|
|
1971
1877
|
onChange(newFormData, fieldPathId.path);
|
|
1972
|
-
};
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
onBlur,
|
|
1988
|
-
onFocus,
|
|
1989
|
-
registry,
|
|
1990
|
-
title
|
|
1991
|
-
} = this.props;
|
|
1992
|
-
const { fields: fields2, formContext, schemaUtils, translateString, globalFormOptions, globalUiOptions } = registry;
|
|
1993
|
-
const { OptionalDataControlsField: OptionalDataControlsField2, SchemaField: SchemaField2 } = fields2;
|
|
1994
|
-
const schema = schemaUtils.retrieveSchema(rawSchema, formData, true);
|
|
1995
|
-
const uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1996
|
-
const { properties: schemaProperties = {} } = schema;
|
|
1997
|
-
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
1998
|
-
const description = uiOptions.description ?? schema.description;
|
|
1999
|
-
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
2000
|
-
const hasFormData = utils.isFormDataAvailable(formData);
|
|
2001
|
-
let orderedProperties = [];
|
|
2002
|
-
if (!renderOptionalField || hasFormData) {
|
|
2003
|
-
try {
|
|
2004
|
-
const properties = Object.keys(schemaProperties);
|
|
2005
|
-
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
2006
|
-
} catch (err) {
|
|
2007
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2008
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "rjsf-config-error", style: { color: "red" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { options: { disableParsingRawHTML: true }, children: translateString(utils.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
2009
|
-
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: JSON.stringify(schema) })
|
|
2010
|
-
] });
|
|
1878
|
+
}, [formData, onChange, registry, fieldPathId, getAvailableKey, schema]);
|
|
1879
|
+
const handleKeyRename = react.useCallback(
|
|
1880
|
+
(oldKey, newKey) => {
|
|
1881
|
+
if (oldKey !== newKey) {
|
|
1882
|
+
const actualNewKey = getAvailableKey(newKey, formData);
|
|
1883
|
+
const newFormData = {
|
|
1884
|
+
...formData
|
|
1885
|
+
};
|
|
1886
|
+
const newKeys = { [oldKey]: actualNewKey };
|
|
1887
|
+
const keyValues = Object.keys(newFormData).map((key) => {
|
|
1888
|
+
const newKey2 = newKeys[key] || key;
|
|
1889
|
+
return { [newKey2]: newFormData[key] };
|
|
1890
|
+
});
|
|
1891
|
+
const renamedObj = Object.assign({}, ...keyValues);
|
|
1892
|
+
onChange(renamedObj, fieldPathId.path);
|
|
2011
1893
|
}
|
|
1894
|
+
},
|
|
1895
|
+
[formData, onChange, fieldPathId, getAvailableKey]
|
|
1896
|
+
);
|
|
1897
|
+
const handleRemoveProperty = react.useCallback(
|
|
1898
|
+
(key) => {
|
|
1899
|
+
const copiedFormData = { ...formData };
|
|
1900
|
+
unset(copiedFormData, key);
|
|
1901
|
+
onChange(copiedFormData, fieldPathId.path);
|
|
1902
|
+
},
|
|
1903
|
+
[onChange, fieldPathId, formData]
|
|
1904
|
+
);
|
|
1905
|
+
if (!renderOptionalField || hasFormData) {
|
|
1906
|
+
try {
|
|
1907
|
+
const properties = Object.keys(schemaProperties);
|
|
1908
|
+
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
1909
|
+
} catch (err) {
|
|
1910
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1911
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "rjsf-config-error", style: { color: "red" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { options: { disableParsingRawHTML: true }, children: translateString(utils.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
1912
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: JSON.stringify(schema) })
|
|
1913
|
+
] });
|
|
2012
1914
|
}
|
|
2013
|
-
const Template = utils.getTemplate("ObjectFieldTemplate", registry, uiOptions);
|
|
2014
|
-
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...this.props, schema }) : void 0;
|
|
2015
|
-
const templateProps = {
|
|
2016
|
-
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
2017
|
-
title: uiOptions.label === false ? "" : templateTitle,
|
|
2018
|
-
description: uiOptions.label === false ? void 0 : description,
|
|
2019
|
-
properties: orderedProperties.map((name2) => {
|
|
2020
|
-
const addedByAdditionalProperties = has(schema, [utils.PROPERTIES_KEY, name2, utils.ADDITIONAL_PROPERTY_FLAG]);
|
|
2021
|
-
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
|
|
2022
|
-
const hidden = utils.getUiOptions(fieldUiSchema).widget === "hidden";
|
|
2023
|
-
const innerFieldIdPathId = utils.toFieldPathId(name2, globalFormOptions, fieldPathId);
|
|
2024
|
-
return {
|
|
2025
|
-
content: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2026
|
-
SchemaField2,
|
|
2027
|
-
{
|
|
2028
|
-
name: name2,
|
|
2029
|
-
required: this.isRequired(name2),
|
|
2030
|
-
schema: get2(schema, [utils.PROPERTIES_KEY, name2], {}),
|
|
2031
|
-
uiSchema: fieldUiSchema,
|
|
2032
|
-
errorSchema: get2(errorSchema, name2),
|
|
2033
|
-
fieldPathId: innerFieldIdPathId,
|
|
2034
|
-
formData: get2(formData, name2),
|
|
2035
|
-
formContext,
|
|
2036
|
-
wasPropertyKeyModified: this.state.wasPropertyKeyModified,
|
|
2037
|
-
onKeyChange: this.onKeyChange(name2),
|
|
2038
|
-
onChange: this.onPropertyChange(name2, addedByAdditionalProperties),
|
|
2039
|
-
onBlur,
|
|
2040
|
-
onFocus,
|
|
2041
|
-
registry,
|
|
2042
|
-
disabled,
|
|
2043
|
-
readonly,
|
|
2044
|
-
hideError,
|
|
2045
|
-
onDropPropertyClick: this.onDropPropertyClick
|
|
2046
|
-
},
|
|
2047
|
-
name2
|
|
2048
|
-
),
|
|
2049
|
-
name: name2,
|
|
2050
|
-
readonly,
|
|
2051
|
-
disabled,
|
|
2052
|
-
required,
|
|
2053
|
-
hidden
|
|
2054
|
-
};
|
|
2055
|
-
}),
|
|
2056
|
-
readonly,
|
|
2057
|
-
disabled,
|
|
2058
|
-
required,
|
|
2059
|
-
fieldPathId,
|
|
2060
|
-
uiSchema,
|
|
2061
|
-
errorSchema,
|
|
2062
|
-
schema,
|
|
2063
|
-
formData,
|
|
2064
|
-
formContext,
|
|
2065
|
-
registry,
|
|
2066
|
-
optionalDataControl,
|
|
2067
|
-
className: renderOptionalField ? "rjsf-optional-object-field" : void 0
|
|
2068
|
-
};
|
|
2069
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...templateProps, onAddClick: this.handleAddClick });
|
|
2070
1915
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
1916
|
+
const Template = utils.getTemplate("ObjectFieldTemplate", registry, uiOptions);
|
|
1917
|
+
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsxRuntime.jsx(OptionalDataControlsField2, { ...props, schema }) : void 0;
|
|
1918
|
+
const templateProps = {
|
|
1919
|
+
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
1920
|
+
title: uiOptions.label === false ? "" : templateTitle,
|
|
1921
|
+
description: uiOptions.label === false ? void 0 : description,
|
|
1922
|
+
properties: orderedProperties.map((name2) => {
|
|
1923
|
+
const addedByAdditionalProperties = has(schema, [utils.PROPERTIES_KEY, name2, utils.ADDITIONAL_PROPERTY_FLAG]);
|
|
1924
|
+
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
|
|
1925
|
+
const hidden = utils.getUiOptions(fieldUiSchema).widget === "hidden";
|
|
1926
|
+
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1927
|
+
ObjectFieldProperty,
|
|
1928
|
+
{
|
|
1929
|
+
propertyName: name2,
|
|
1930
|
+
required: isRequired(schema, name2),
|
|
1931
|
+
schema: get(schema, [utils.PROPERTIES_KEY, name2], {}),
|
|
1932
|
+
uiSchema: fieldUiSchema,
|
|
1933
|
+
errorSchema: get(errorSchema, name2),
|
|
1934
|
+
fieldPathId,
|
|
1935
|
+
formData: get(formData, name2),
|
|
1936
|
+
handleKeyRename,
|
|
1937
|
+
handleRemoveProperty,
|
|
1938
|
+
addedByAdditionalProperties,
|
|
1939
|
+
onChange,
|
|
1940
|
+
onBlur,
|
|
1941
|
+
onFocus,
|
|
1942
|
+
registry,
|
|
1943
|
+
disabled,
|
|
1944
|
+
readonly,
|
|
1945
|
+
hideError
|
|
1946
|
+
},
|
|
1947
|
+
addedByAdditionalProperties ? `${name2}-${formDataHash}` : name2
|
|
1948
|
+
);
|
|
1949
|
+
return {
|
|
1950
|
+
content,
|
|
1951
|
+
name: name2,
|
|
1952
|
+
readonly,
|
|
1953
|
+
disabled,
|
|
1954
|
+
required,
|
|
1955
|
+
hidden
|
|
1956
|
+
};
|
|
1957
|
+
}),
|
|
1958
|
+
readonly,
|
|
1959
|
+
disabled,
|
|
1960
|
+
required,
|
|
1961
|
+
fieldPathId,
|
|
1962
|
+
uiSchema,
|
|
1963
|
+
errorSchema,
|
|
1964
|
+
schema,
|
|
1965
|
+
formData,
|
|
1966
|
+
registry,
|
|
1967
|
+
optionalDataControl,
|
|
1968
|
+
className: renderOptionalField ? "rjsf-optional-object-field" : void 0
|
|
1969
|
+
};
|
|
1970
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template, { ...templateProps, onAddProperty });
|
|
1971
|
+
}
|
|
2073
1972
|
function OptionalDataControlsField(props) {
|
|
2074
1973
|
const {
|
|
2075
1974
|
schema,
|
|
@@ -2136,9 +2035,9 @@
|
|
|
2136
2035
|
string: "StringField",
|
|
2137
2036
|
null: "NullField"
|
|
2138
2037
|
};
|
|
2139
|
-
function getFieldComponent(schema, uiOptions,
|
|
2038
|
+
function getFieldComponent(schema, uiOptions, registry) {
|
|
2140
2039
|
const field = uiOptions.field;
|
|
2141
|
-
const { fields: fields2
|
|
2040
|
+
const { fields: fields2 } = registry;
|
|
2142
2041
|
if (typeof field === "function") {
|
|
2143
2042
|
return field;
|
|
2144
2043
|
}
|
|
@@ -2155,22 +2054,7 @@
|
|
|
2155
2054
|
if (!componentName && (schema.anyOf || schema.oneOf)) {
|
|
2156
2055
|
return () => null;
|
|
2157
2056
|
}
|
|
2158
|
-
return componentName in fields2 ? fields2[componentName] :
|
|
2159
|
-
const UnsupportedFieldTemplate = utils.getTemplate(
|
|
2160
|
-
"UnsupportedFieldTemplate",
|
|
2161
|
-
registry,
|
|
2162
|
-
uiOptions
|
|
2163
|
-
);
|
|
2164
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2165
|
-
UnsupportedFieldTemplate,
|
|
2166
|
-
{
|
|
2167
|
-
schema,
|
|
2168
|
-
fieldPathId,
|
|
2169
|
-
reason: translateString(utils.TranslatableString.UnknownFieldType, [String(schema.type)]),
|
|
2170
|
-
registry
|
|
2171
|
-
}
|
|
2172
|
-
);
|
|
2173
|
-
};
|
|
2057
|
+
return componentName in fields2 ? fields2[componentName] : fields2["FallbackField"];
|
|
2174
2058
|
}
|
|
2175
2059
|
function SchemaFieldRender(props) {
|
|
2176
2060
|
const {
|
|
@@ -2181,13 +2065,15 @@
|
|
|
2181
2065
|
errorSchema,
|
|
2182
2066
|
name,
|
|
2183
2067
|
onChange,
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2068
|
+
onKeyRename,
|
|
2069
|
+
onKeyRenameBlur,
|
|
2070
|
+
onRemoveProperty,
|
|
2071
|
+
required = false,
|
|
2187
2072
|
registry,
|
|
2188
2073
|
wasPropertyKeyModified = false
|
|
2189
2074
|
} = props;
|
|
2190
|
-
const {
|
|
2075
|
+
const { schemaUtils, globalUiOptions, fields: fields2 } = registry;
|
|
2076
|
+
const { AnyOfField: _AnyOfField, OneOfField: _OneOfField } = fields2;
|
|
2191
2077
|
const uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
2192
2078
|
const FieldTemplate2 = utils.getTemplate("FieldTemplate", registry, uiOptions);
|
|
2193
2079
|
const DescriptionFieldTemplate = utils.getTemplate(
|
|
@@ -2206,7 +2092,7 @@
|
|
|
2206
2092
|
},
|
|
2207
2093
|
[fieldId, onChange]
|
|
2208
2094
|
);
|
|
2209
|
-
const FieldComponent = getFieldComponent(schema, uiOptions,
|
|
2095
|
+
const FieldComponent = getFieldComponent(schema, uiOptions, registry);
|
|
2210
2096
|
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
|
|
2211
2097
|
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
|
|
2212
2098
|
const uiSchemaHideError = uiOptions.hideError;
|
|
@@ -2215,7 +2101,26 @@
|
|
|
2215
2101
|
if (Object.keys(schema).length === 0) {
|
|
2216
2102
|
return null;
|
|
2217
2103
|
}
|
|
2218
|
-
|
|
2104
|
+
let displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
2105
|
+
const isReplacingAnyOrOneOf = uiOptions.field && uiOptions.fieldReplacesAnyOrOneOf === true;
|
|
2106
|
+
let XxxOfField;
|
|
2107
|
+
let XxxOfOptions;
|
|
2108
|
+
if ((utils.ANY_OF_KEY in schema || utils.ONE_OF_KEY in schema) && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema)) {
|
|
2109
|
+
if (schema[utils.ANY_OF_KEY]) {
|
|
2110
|
+
XxxOfField = _AnyOfField;
|
|
2111
|
+
XxxOfOptions = schema[utils.ANY_OF_KEY].map(
|
|
2112
|
+
(_schema2) => schemaUtils.retrieveSchema(isObject(_schema2) ? _schema2 : {}, formData)
|
|
2113
|
+
);
|
|
2114
|
+
} else if (schema[utils.ONE_OF_KEY]) {
|
|
2115
|
+
XxxOfField = _OneOfField;
|
|
2116
|
+
XxxOfOptions = schema[utils.ONE_OF_KEY].map(
|
|
2117
|
+
(_schema2) => schemaUtils.retrieveSchema(isObject(_schema2) ? _schema2 : {}, formData)
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
const isOptionalRender = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
2121
|
+
const hasFormData = utils.isFormDataAvailable(formData);
|
|
2122
|
+
displayLabel = displayLabel && (!isOptionalRender || hasFormData);
|
|
2123
|
+
}
|
|
2219
2124
|
const { __errors, ...fieldErrorSchema } = errorSchema || {};
|
|
2220
2125
|
const fieldUiSchema = omit3(uiSchema, ["ui:classNames", "classNames", "ui:style"]);
|
|
2221
2126
|
if (utils.UI_OPTIONS_KEY in fieldUiSchema) {
|
|
@@ -2234,7 +2139,6 @@
|
|
|
2234
2139
|
hideError,
|
|
2235
2140
|
autofocus,
|
|
2236
2141
|
errorSchema: fieldErrorSchema,
|
|
2237
|
-
formContext,
|
|
2238
2142
|
rawErrors: __errors
|
|
2239
2143
|
}
|
|
2240
2144
|
);
|
|
@@ -2266,7 +2170,7 @@
|
|
|
2266
2170
|
registry
|
|
2267
2171
|
}
|
|
2268
2172
|
);
|
|
2269
|
-
const errorsComponent = hideError ||
|
|
2173
|
+
const errorsComponent = hideError || XxxOfField && !schemaUtils.isSelect(schema) ? void 0 : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2270
2174
|
FieldErrorTemplate2,
|
|
2271
2175
|
{
|
|
2272
2176
|
errors: __errors,
|
|
@@ -2297,8 +2201,9 @@
|
|
|
2297
2201
|
label,
|
|
2298
2202
|
hidden,
|
|
2299
2203
|
onChange,
|
|
2300
|
-
|
|
2301
|
-
|
|
2204
|
+
onKeyRename,
|
|
2205
|
+
onKeyRenameBlur,
|
|
2206
|
+
onRemoveProperty,
|
|
2302
2207
|
required,
|
|
2303
2208
|
disabled,
|
|
2304
2209
|
readonly,
|
|
@@ -2311,36 +2216,10 @@
|
|
|
2311
2216
|
uiSchema,
|
|
2312
2217
|
registry
|
|
2313
2218
|
};
|
|
2314
|
-
const _AnyOfField = registry.fields.AnyOfField;
|
|
2315
|
-
const _OneOfField = registry.fields.OneOfField;
|
|
2316
|
-
const isReplacingAnyOrOneOf = uiSchema?.["ui:field"] && uiSchema?.["ui:fieldReplacesAnyOrOneOf"] === true;
|
|
2317
2219
|
return /* @__PURE__ */ jsxRuntime.jsx(FieldTemplate2, { ...fieldProps, children: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2318
2220
|
field,
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
{
|
|
2322
|
-
name,
|
|
2323
|
-
disabled,
|
|
2324
|
-
readonly,
|
|
2325
|
-
hideError,
|
|
2326
|
-
errorSchema,
|
|
2327
|
-
formData,
|
|
2328
|
-
formContext,
|
|
2329
|
-
fieldPathId,
|
|
2330
|
-
onBlur: props.onBlur,
|
|
2331
|
-
onChange: props.onChange,
|
|
2332
|
-
onFocus: props.onFocus,
|
|
2333
|
-
options: schema.anyOf.map(
|
|
2334
|
-
(_schema2) => schemaUtils.retrieveSchema(isObject(_schema2) ? _schema2 : {}, formData)
|
|
2335
|
-
),
|
|
2336
|
-
registry,
|
|
2337
|
-
required,
|
|
2338
|
-
schema,
|
|
2339
|
-
uiSchema
|
|
2340
|
-
}
|
|
2341
|
-
),
|
|
2342
|
-
schema.oneOf && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2343
|
-
_OneOfField,
|
|
2221
|
+
XxxOfField && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2222
|
+
XxxOfField,
|
|
2344
2223
|
{
|
|
2345
2224
|
name,
|
|
2346
2225
|
disabled,
|
|
@@ -2348,14 +2227,11 @@
|
|
|
2348
2227
|
hideError,
|
|
2349
2228
|
errorSchema,
|
|
2350
2229
|
formData,
|
|
2351
|
-
formContext,
|
|
2352
2230
|
fieldPathId,
|
|
2353
2231
|
onBlur: props.onBlur,
|
|
2354
2232
|
onChange: props.onChange,
|
|
2355
2233
|
onFocus: props.onFocus,
|
|
2356
|
-
options:
|
|
2357
|
-
(_schema2) => schemaUtils.retrieveSchema(isObject(_schema2) ? _schema2 : {}, formData)
|
|
2358
|
-
),
|
|
2234
|
+
options: XxxOfOptions,
|
|
2359
2235
|
registry,
|
|
2360
2236
|
required,
|
|
2361
2237
|
schema,
|
|
@@ -2396,7 +2272,7 @@
|
|
|
2396
2272
|
hideError
|
|
2397
2273
|
} = props;
|
|
2398
2274
|
const { title, format } = schema;
|
|
2399
|
-
const { widgets: widgets2,
|
|
2275
|
+
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
2400
2276
|
const enumOptions = schemaUtils.isSelect(schema) ? utils.optionsList(schema, uiSchema) : void 0;
|
|
2401
2277
|
let defaultWidget = enumOptions ? "select" : "text";
|
|
2402
2278
|
if (format && utils.hasWidget(schema, format, widgets2)) {
|
|
@@ -2430,11 +2306,11 @@
|
|
|
2430
2306
|
required,
|
|
2431
2307
|
disabled,
|
|
2432
2308
|
readonly,
|
|
2433
|
-
formContext,
|
|
2434
2309
|
autofocus,
|
|
2435
2310
|
registry,
|
|
2436
2311
|
placeholder,
|
|
2437
|
-
rawErrors
|
|
2312
|
+
rawErrors,
|
|
2313
|
+
htmlName: fieldPathId.name
|
|
2438
2314
|
}
|
|
2439
2315
|
);
|
|
2440
2316
|
}
|
|
@@ -2454,14 +2330,15 @@
|
|
|
2454
2330
|
function fields() {
|
|
2455
2331
|
return {
|
|
2456
2332
|
AnyOfField: MultiSchemaField_default,
|
|
2457
|
-
ArrayField
|
|
2333
|
+
ArrayField,
|
|
2458
2334
|
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
2459
2335
|
BooleanField: BooleanField_default,
|
|
2336
|
+
FallbackField,
|
|
2460
2337
|
LayoutGridField,
|
|
2461
2338
|
LayoutHeaderField,
|
|
2462
2339
|
LayoutMultiSchemaField,
|
|
2463
2340
|
NumberField: NumberField_default,
|
|
2464
|
-
ObjectField
|
|
2341
|
+
ObjectField,
|
|
2465
2342
|
OneOfField: MultiSchemaField_default,
|
|
2466
2343
|
OptionalDataControlsField,
|
|
2467
2344
|
SchemaField: SchemaField_default,
|
|
@@ -2530,19 +2407,15 @@
|
|
|
2530
2407
|
hasMoveUp,
|
|
2531
2408
|
hasRemove,
|
|
2532
2409
|
fieldPathId,
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2410
|
+
onCopyItem,
|
|
2411
|
+
onRemoveItem,
|
|
2412
|
+
onMoveDownItem,
|
|
2413
|
+
onMoveUpItem,
|
|
2537
2414
|
readonly,
|
|
2538
2415
|
registry,
|
|
2539
2416
|
uiSchema
|
|
2540
2417
|
} = props;
|
|
2541
2418
|
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
2542
|
-
const onCopyClick = react.useMemo(() => onCopyIndexClick(index), [index, onCopyIndexClick]);
|
|
2543
|
-
const onRemoveClick = react.useMemo(() => onDropIndexClick(index), [index, onDropIndexClick]);
|
|
2544
|
-
const onArrowUpClick = react.useMemo(() => onReorderClick(index, index - 1), [index, onReorderClick]);
|
|
2545
|
-
const onArrowDownClick = react.useMemo(() => onReorderClick(index, index + 1), [index, onReorderClick]);
|
|
2546
2419
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2547
2420
|
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2548
2421
|
MoveUpButton2,
|
|
@@ -2550,7 +2423,7 @@
|
|
|
2550
2423
|
id: utils.buttonId(fieldPathId, "moveUp"),
|
|
2551
2424
|
className: "rjsf-array-item-move-up",
|
|
2552
2425
|
disabled: disabled || readonly || !hasMoveUp,
|
|
2553
|
-
onClick:
|
|
2426
|
+
onClick: onMoveUpItem,
|
|
2554
2427
|
uiSchema,
|
|
2555
2428
|
registry
|
|
2556
2429
|
}
|
|
@@ -2561,7 +2434,7 @@
|
|
|
2561
2434
|
id: utils.buttonId(fieldPathId, "moveDown"),
|
|
2562
2435
|
className: "rjsf-array-item-move-down",
|
|
2563
2436
|
disabled: disabled || readonly || !hasMoveDown,
|
|
2564
|
-
onClick:
|
|
2437
|
+
onClick: onMoveDownItem,
|
|
2565
2438
|
uiSchema,
|
|
2566
2439
|
registry
|
|
2567
2440
|
}
|
|
@@ -2572,7 +2445,7 @@
|
|
|
2572
2445
|
id: utils.buttonId(fieldPathId, "copy"),
|
|
2573
2446
|
className: "rjsf-array-item-copy",
|
|
2574
2447
|
disabled: disabled || readonly,
|
|
2575
|
-
onClick:
|
|
2448
|
+
onClick: onCopyItem,
|
|
2576
2449
|
uiSchema,
|
|
2577
2450
|
registry
|
|
2578
2451
|
}
|
|
@@ -2583,7 +2456,7 @@
|
|
|
2583
2456
|
id: utils.buttonId(fieldPathId, "remove"),
|
|
2584
2457
|
className: "rjsf-array-item-remove",
|
|
2585
2458
|
disabled: disabled || readonly,
|
|
2586
|
-
onClick:
|
|
2459
|
+
onClick: onRemoveItem,
|
|
2587
2460
|
uiSchema,
|
|
2588
2461
|
registry
|
|
2589
2462
|
}
|
|
@@ -2612,11 +2485,6 @@
|
|
|
2612
2485
|
registry,
|
|
2613
2486
|
uiOptions
|
|
2614
2487
|
);
|
|
2615
|
-
const ArrayFieldItemTemplate2 = utils.getTemplate(
|
|
2616
|
-
"ArrayFieldItemTemplate",
|
|
2617
|
-
registry,
|
|
2618
|
-
uiOptions
|
|
2619
|
-
);
|
|
2620
2488
|
const ArrayFieldTitleTemplate2 = utils.getTemplate(
|
|
2621
2489
|
"ArrayFieldTitleTemplate",
|
|
2622
2490
|
registry,
|
|
@@ -2650,7 +2518,7 @@
|
|
|
2650
2518
|
}
|
|
2651
2519
|
),
|
|
2652
2520
|
!showOptionalDataControlInTitle ? optionalDataControl : void 0,
|
|
2653
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "row array-item-list", children: items
|
|
2521
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "row array-item-list", children: items }),
|
|
2654
2522
|
canAdd && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2655
2523
|
AddButton2,
|
|
2656
2524
|
{
|
|
@@ -2694,6 +2562,7 @@
|
|
|
2694
2562
|
id,
|
|
2695
2563
|
name,
|
|
2696
2564
|
// remove this from ...rest
|
|
2565
|
+
htmlName,
|
|
2697
2566
|
value,
|
|
2698
2567
|
readonly,
|
|
2699
2568
|
disabled,
|
|
@@ -2705,7 +2574,6 @@
|
|
|
2705
2574
|
options,
|
|
2706
2575
|
schema,
|
|
2707
2576
|
uiSchema,
|
|
2708
|
-
formContext,
|
|
2709
2577
|
registry,
|
|
2710
2578
|
rawErrors,
|
|
2711
2579
|
type,
|
|
@@ -2746,7 +2614,7 @@
|
|
|
2746
2614
|
"input",
|
|
2747
2615
|
{
|
|
2748
2616
|
id,
|
|
2749
|
-
name: id,
|
|
2617
|
+
name: htmlName || id,
|
|
2750
2618
|
className: "form-control",
|
|
2751
2619
|
readOnly: readonly,
|
|
2752
2620
|
disabled,
|
|
@@ -2864,6 +2732,22 @@
|
|
|
2864
2732
|
}) })
|
|
2865
2733
|
] });
|
|
2866
2734
|
}
|
|
2735
|
+
function FallbackFieldTemplate(props) {
|
|
2736
|
+
const { schema, registry, typeSelector, schemaField } = props;
|
|
2737
|
+
const MultiSchemaFieldTemplate2 = utils.getTemplate(
|
|
2738
|
+
"MultiSchemaFieldTemplate",
|
|
2739
|
+
registry
|
|
2740
|
+
);
|
|
2741
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2742
|
+
MultiSchemaFieldTemplate2,
|
|
2743
|
+
{
|
|
2744
|
+
selector: typeSelector,
|
|
2745
|
+
optionSchemaField: schemaField,
|
|
2746
|
+
schema,
|
|
2747
|
+
registry
|
|
2748
|
+
}
|
|
2749
|
+
);
|
|
2750
|
+
}
|
|
2867
2751
|
var REQUIRED_FIELD_SYMBOL = "*";
|
|
2868
2752
|
function Label(props) {
|
|
2869
2753
|
const { label, required, id } = props;
|
|
@@ -2936,7 +2820,7 @@
|
|
|
2936
2820
|
disabled,
|
|
2937
2821
|
formData,
|
|
2938
2822
|
fieldPathId,
|
|
2939
|
-
|
|
2823
|
+
onAddProperty,
|
|
2940
2824
|
optionalDataControl,
|
|
2941
2825
|
properties,
|
|
2942
2826
|
readonly,
|
|
@@ -2987,7 +2871,7 @@
|
|
|
2987
2871
|
{
|
|
2988
2872
|
id: utils.buttonId(fieldPathId, "add"),
|
|
2989
2873
|
className: "rjsf-object-property-expand",
|
|
2990
|
-
onClick:
|
|
2874
|
+
onClick: onAddProperty,
|
|
2991
2875
|
disabled: disabled || readonly,
|
|
2992
2876
|
uiSchema,
|
|
2993
2877
|
registry
|
|
@@ -3059,8 +2943,8 @@
|
|
|
3059
2943
|
style,
|
|
3060
2944
|
disabled,
|
|
3061
2945
|
label,
|
|
3062
|
-
|
|
3063
|
-
|
|
2946
|
+
onKeyRenameBlur,
|
|
2947
|
+
onRemoveProperty,
|
|
3064
2948
|
readonly,
|
|
3065
2949
|
required,
|
|
3066
2950
|
schema,
|
|
@@ -3091,7 +2975,7 @@
|
|
|
3091
2975
|
className: "form-control",
|
|
3092
2976
|
type: "text",
|
|
3093
2977
|
id: `${id}-key`,
|
|
3094
|
-
onBlur:
|
|
2978
|
+
onBlur: onKeyRenameBlur,
|
|
3095
2979
|
defaultValue: label
|
|
3096
2980
|
}
|
|
3097
2981
|
)
|
|
@@ -3104,7 +2988,7 @@
|
|
|
3104
2988
|
className: "rjsf-object-property-remove btn-block",
|
|
3105
2989
|
style: { border: "0" },
|
|
3106
2990
|
disabled: disabled || readonly,
|
|
3107
|
-
onClick:
|
|
2991
|
+
onClick: onRemoveProperty,
|
|
3108
2992
|
uiSchema,
|
|
3109
2993
|
registry
|
|
3110
2994
|
}
|
|
@@ -3124,6 +3008,7 @@
|
|
|
3124
3008
|
BaseInputTemplate,
|
|
3125
3009
|
DescriptionFieldTemplate: DescriptionField,
|
|
3126
3010
|
ErrorListTemplate: ErrorList,
|
|
3011
|
+
FallbackFieldTemplate,
|
|
3127
3012
|
FieldTemplate: FieldTemplate_default,
|
|
3128
3013
|
FieldErrorTemplate,
|
|
3129
3014
|
FieldHelpTemplate,
|
|
@@ -3137,109 +3022,13 @@
|
|
|
3137
3022
|
};
|
|
3138
3023
|
}
|
|
3139
3024
|
var templates_default = templates;
|
|
3140
|
-
function
|
|
3141
|
-
|
|
3142
|
-
}
|
|
3143
|
-
function DateElement({
|
|
3144
|
-
type,
|
|
3145
|
-
range,
|
|
3146
|
-
value,
|
|
3147
|
-
select,
|
|
3148
|
-
rootId,
|
|
3149
|
-
name,
|
|
3150
|
-
disabled,
|
|
3151
|
-
readonly,
|
|
3152
|
-
autofocus,
|
|
3153
|
-
registry,
|
|
3154
|
-
onBlur,
|
|
3155
|
-
onFocus
|
|
3156
|
-
}) {
|
|
3157
|
-
const id = rootId + "_" + type;
|
|
3158
|
-
const { SelectWidget: SelectWidget2 } = registry.widgets;
|
|
3159
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3160
|
-
SelectWidget2,
|
|
3161
|
-
{
|
|
3162
|
-
schema: { type: "integer" },
|
|
3163
|
-
id,
|
|
3164
|
-
name,
|
|
3165
|
-
className: "form-control",
|
|
3166
|
-
options: { enumOptions: utils.dateRangeOptions(range[0], range[1]) },
|
|
3167
|
-
placeholder: type,
|
|
3168
|
-
value,
|
|
3169
|
-
disabled,
|
|
3170
|
-
readonly,
|
|
3171
|
-
autofocus,
|
|
3172
|
-
onChange: (value2) => select(type, value2),
|
|
3173
|
-
onBlur,
|
|
3174
|
-
onFocus,
|
|
3175
|
-
registry,
|
|
3176
|
-
label: "",
|
|
3177
|
-
"aria-describedby": utils.ariaDescribedByIds(rootId)
|
|
3178
|
-
}
|
|
3179
|
-
);
|
|
3180
|
-
}
|
|
3181
|
-
function AltDateWidget({
|
|
3182
|
-
time = false,
|
|
3183
|
-
disabled = false,
|
|
3184
|
-
readonly = false,
|
|
3185
|
-
autofocus = false,
|
|
3186
|
-
options,
|
|
3187
|
-
id,
|
|
3188
|
-
name,
|
|
3189
|
-
registry,
|
|
3190
|
-
onBlur,
|
|
3191
|
-
onFocus,
|
|
3192
|
-
onChange,
|
|
3193
|
-
value
|
|
3194
|
-
}) {
|
|
3025
|
+
function AltDateWidget(props) {
|
|
3026
|
+
const { disabled = false, readonly = false, autofocus = false, options, id, name, registry, onBlur, onFocus } = props;
|
|
3195
3027
|
const { translateString } = registry;
|
|
3196
|
-
const
|
|
3197
|
-
react.useEffect(() => {
|
|
3198
|
-
setState(utils.parseDateString(value, time));
|
|
3199
|
-
}, [time, value]);
|
|
3200
|
-
const handleChange = react.useCallback(
|
|
3201
|
-
(property, value2) => {
|
|
3202
|
-
const nextState = {
|
|
3203
|
-
...state,
|
|
3204
|
-
[property]: typeof value2 === "undefined" ? -1 : value2
|
|
3205
|
-
};
|
|
3206
|
-
if (readyForChange(nextState)) {
|
|
3207
|
-
onChange(utils.toDateString(nextState, time));
|
|
3208
|
-
} else {
|
|
3209
|
-
setState(nextState);
|
|
3210
|
-
}
|
|
3211
|
-
},
|
|
3212
|
-
[state, onChange, time]
|
|
3213
|
-
);
|
|
3214
|
-
const handleSetNow = react.useCallback(
|
|
3215
|
-
(event) => {
|
|
3216
|
-
event.preventDefault();
|
|
3217
|
-
if (disabled || readonly) {
|
|
3218
|
-
return;
|
|
3219
|
-
}
|
|
3220
|
-
const nextState = utils.parseDateString((/* @__PURE__ */ new Date()).toJSON(), time);
|
|
3221
|
-
onChange(utils.toDateString(nextState, time));
|
|
3222
|
-
},
|
|
3223
|
-
[disabled, readonly, time, onChange]
|
|
3224
|
-
);
|
|
3225
|
-
const handleClear = react.useCallback(
|
|
3226
|
-
(event) => {
|
|
3227
|
-
event.preventDefault();
|
|
3228
|
-
if (disabled || readonly) {
|
|
3229
|
-
return;
|
|
3230
|
-
}
|
|
3231
|
-
onChange(void 0);
|
|
3232
|
-
},
|
|
3233
|
-
[disabled, readonly, onChange]
|
|
3234
|
-
);
|
|
3028
|
+
const { elements, handleChange, handleClear, handleSetNow } = utils.useAltDateWidgetProps(props);
|
|
3235
3029
|
return /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: "list-inline", children: [
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
time,
|
|
3239
|
-
options.yearsRange,
|
|
3240
|
-
options.format
|
|
3241
|
-
).map((elemProps, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "list-inline-item", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3242
|
-
DateElement,
|
|
3030
|
+
elements.map((elemProps, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "list-inline-item", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3031
|
+
utils.DateElement,
|
|
3243
3032
|
{
|
|
3244
3033
|
rootId: id,
|
|
3245
3034
|
name,
|
|
@@ -3280,7 +3069,8 @@
|
|
|
3280
3069
|
onBlur,
|
|
3281
3070
|
onFocus,
|
|
3282
3071
|
onChange,
|
|
3283
|
-
registry
|
|
3072
|
+
registry,
|
|
3073
|
+
htmlName
|
|
3284
3074
|
}) {
|
|
3285
3075
|
const DescriptionFieldTemplate = utils.getTemplate(
|
|
3286
3076
|
"DescriptionFieldTemplate",
|
|
@@ -3318,7 +3108,7 @@
|
|
|
3318
3108
|
{
|
|
3319
3109
|
type: "checkbox",
|
|
3320
3110
|
id,
|
|
3321
|
-
name: id,
|
|
3111
|
+
name: htmlName || id,
|
|
3322
3112
|
checked: typeof value === "undefined" ? false : value,
|
|
3323
3113
|
required,
|
|
3324
3114
|
disabled: disabled || readonly,
|
|
@@ -3343,7 +3133,8 @@
|
|
|
3343
3133
|
readonly,
|
|
3344
3134
|
onChange,
|
|
3345
3135
|
onBlur,
|
|
3346
|
-
onFocus
|
|
3136
|
+
onFocus,
|
|
3137
|
+
htmlName
|
|
3347
3138
|
}) {
|
|
3348
3139
|
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
3349
3140
|
const handleBlur = react.useCallback(
|
|
@@ -3371,7 +3162,7 @@
|
|
|
3371
3162
|
{
|
|
3372
3163
|
type: "checkbox",
|
|
3373
3164
|
id: utils.optionId(id, index),
|
|
3374
|
-
name: id,
|
|
3165
|
+
name: htmlName || id,
|
|
3375
3166
|
checked,
|
|
3376
3167
|
value: String(index),
|
|
3377
3168
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -3417,40 +3208,6 @@
|
|
|
3417
3208
|
const BaseInputTemplate2 = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3418
3209
|
return /* @__PURE__ */ jsxRuntime.jsx(BaseInputTemplate2, { type: "email", ...props });
|
|
3419
3210
|
}
|
|
3420
|
-
function addNameToDataURL(dataURL, name) {
|
|
3421
|
-
if (dataURL === null) {
|
|
3422
|
-
return null;
|
|
3423
|
-
}
|
|
3424
|
-
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
3425
|
-
}
|
|
3426
|
-
function processFile(file) {
|
|
3427
|
-
const { name, size, type } = file;
|
|
3428
|
-
return new Promise((resolve, reject) => {
|
|
3429
|
-
const reader = new window.FileReader();
|
|
3430
|
-
reader.onerror = reject;
|
|
3431
|
-
reader.onload = (event) => {
|
|
3432
|
-
if (typeof event.target?.result === "string") {
|
|
3433
|
-
resolve({
|
|
3434
|
-
dataURL: addNameToDataURL(event.target.result, name),
|
|
3435
|
-
name,
|
|
3436
|
-
size,
|
|
3437
|
-
type
|
|
3438
|
-
});
|
|
3439
|
-
} else {
|
|
3440
|
-
resolve({
|
|
3441
|
-
dataURL: null,
|
|
3442
|
-
name,
|
|
3443
|
-
size,
|
|
3444
|
-
type
|
|
3445
|
-
});
|
|
3446
|
-
}
|
|
3447
|
-
};
|
|
3448
|
-
reader.readAsDataURL(file);
|
|
3449
|
-
});
|
|
3450
|
-
}
|
|
3451
|
-
function processFiles(files) {
|
|
3452
|
-
return Promise.all(Array.from(files).map(processFile));
|
|
3453
|
-
}
|
|
3454
3211
|
function FileInfoPreview({
|
|
3455
3212
|
fileInfo,
|
|
3456
3213
|
registry
|
|
@@ -3490,58 +3247,15 @@
|
|
|
3490
3247
|
] }, key);
|
|
3491
3248
|
}) });
|
|
3492
3249
|
}
|
|
3493
|
-
function extractFileInfo(dataURLs) {
|
|
3494
|
-
return dataURLs.reduce((acc, dataURL) => {
|
|
3495
|
-
if (!dataURL) {
|
|
3496
|
-
return acc;
|
|
3497
|
-
}
|
|
3498
|
-
try {
|
|
3499
|
-
const { blob, name } = utils.dataURItoBlob(dataURL);
|
|
3500
|
-
return [
|
|
3501
|
-
...acc,
|
|
3502
|
-
{
|
|
3503
|
-
dataURL,
|
|
3504
|
-
name,
|
|
3505
|
-
size: blob.size,
|
|
3506
|
-
type: blob.type
|
|
3507
|
-
}
|
|
3508
|
-
];
|
|
3509
|
-
} catch {
|
|
3510
|
-
return acc;
|
|
3511
|
-
}
|
|
3512
|
-
}, []);
|
|
3513
|
-
}
|
|
3514
3250
|
function FileWidget(props) {
|
|
3515
3251
|
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
3252
|
+
const { filesInfo, handleChange, handleRemove } = utils.useFileWidgetProps(value, onChange, multiple);
|
|
3516
3253
|
const BaseInputTemplate2 = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3517
|
-
const
|
|
3518
|
-
(event)
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
processFiles(event.target.files).then((filesInfoEvent) => {
|
|
3523
|
-
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL);
|
|
3524
|
-
if (multiple) {
|
|
3525
|
-
onChange(value.concat(newValue));
|
|
3526
|
-
} else {
|
|
3527
|
-
onChange(newValue[0]);
|
|
3528
|
-
}
|
|
3529
|
-
});
|
|
3530
|
-
},
|
|
3531
|
-
[multiple, value, onChange]
|
|
3532
|
-
);
|
|
3533
|
-
const filesInfo = react.useMemo(() => extractFileInfo(Array.isArray(value) ? value : [value]), [value]);
|
|
3534
|
-
const rmFile = react.useCallback(
|
|
3535
|
-
(index) => {
|
|
3536
|
-
if (multiple) {
|
|
3537
|
-
const newValue = value.filter((_, i) => i !== index);
|
|
3538
|
-
onChange(newValue);
|
|
3539
|
-
} else {
|
|
3540
|
-
onChange(void 0);
|
|
3541
|
-
}
|
|
3542
|
-
},
|
|
3543
|
-
[multiple, value, onChange]
|
|
3544
|
-
);
|
|
3254
|
+
const handleOnChangeEvent = (event) => {
|
|
3255
|
+
if (event.target.files) {
|
|
3256
|
+
handleChange(event.target.files);
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3545
3259
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3546
3260
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3547
3261
|
BaseInputTemplate2,
|
|
@@ -3550,7 +3264,7 @@
|
|
|
3550
3264
|
disabled: disabled || readonly,
|
|
3551
3265
|
type: "file",
|
|
3552
3266
|
required: value ? false : required,
|
|
3553
|
-
onChangeOverride:
|
|
3267
|
+
onChangeOverride: handleOnChangeEvent,
|
|
3554
3268
|
value: "",
|
|
3555
3269
|
accept: options.accept ? String(options.accept) : void 0
|
|
3556
3270
|
}
|
|
@@ -3559,7 +3273,7 @@
|
|
|
3559
3273
|
FilesInfo,
|
|
3560
3274
|
{
|
|
3561
3275
|
filesInfo,
|
|
3562
|
-
onRemove:
|
|
3276
|
+
onRemove: handleRemove,
|
|
3563
3277
|
registry,
|
|
3564
3278
|
preview: options.filePreview,
|
|
3565
3279
|
options
|
|
@@ -3570,9 +3284,10 @@
|
|
|
3570
3284
|
var FileWidget_default = FileWidget;
|
|
3571
3285
|
function HiddenWidget({
|
|
3572
3286
|
id,
|
|
3573
|
-
value
|
|
3287
|
+
value,
|
|
3288
|
+
htmlName
|
|
3574
3289
|
}) {
|
|
3575
|
-
return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", id, name: id, value: typeof value === "undefined" ? "" : value });
|
|
3290
|
+
return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", id, name: htmlName || id, value: typeof value === "undefined" ? "" : value });
|
|
3576
3291
|
}
|
|
3577
3292
|
var HiddenWidget_default = HiddenWidget;
|
|
3578
3293
|
function PasswordWidget(props) {
|
|
@@ -3590,7 +3305,8 @@
|
|
|
3590
3305
|
onBlur,
|
|
3591
3306
|
onFocus,
|
|
3592
3307
|
onChange,
|
|
3593
|
-
id
|
|
3308
|
+
id,
|
|
3309
|
+
htmlName
|
|
3594
3310
|
}) {
|
|
3595
3311
|
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
3596
3312
|
const handleBlur = react.useCallback(
|
|
@@ -3613,7 +3329,7 @@
|
|
|
3613
3329
|
type: "radio",
|
|
3614
3330
|
id: utils.optionId(id, i),
|
|
3615
3331
|
checked,
|
|
3616
|
-
name: id,
|
|
3332
|
+
name: htmlName || id,
|
|
3617
3333
|
required,
|
|
3618
3334
|
value: String(i),
|
|
3619
3335
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -3653,7 +3369,8 @@
|
|
|
3653
3369
|
onFocus,
|
|
3654
3370
|
onBlur,
|
|
3655
3371
|
schema,
|
|
3656
|
-
options
|
|
3372
|
+
options,
|
|
3373
|
+
htmlName
|
|
3657
3374
|
}) {
|
|
3658
3375
|
const { stars = 5, shape = "star" } = options;
|
|
3659
3376
|
const numStars = schema.maximum ? Math.min(schema.maximum, 5) : Math.min(Math.max(stars, 1), 5);
|
|
@@ -3730,7 +3447,7 @@
|
|
|
3730
3447
|
{
|
|
3731
3448
|
type: "hidden",
|
|
3732
3449
|
id,
|
|
3733
|
-
name: id,
|
|
3450
|
+
name: htmlName || id,
|
|
3734
3451
|
value: value || "",
|
|
3735
3452
|
required,
|
|
3736
3453
|
disabled: disabled || readonly,
|
|
@@ -3760,7 +3477,8 @@
|
|
|
3760
3477
|
onChange,
|
|
3761
3478
|
onBlur,
|
|
3762
3479
|
onFocus,
|
|
3763
|
-
placeholder
|
|
3480
|
+
placeholder,
|
|
3481
|
+
htmlName
|
|
3764
3482
|
}) {
|
|
3765
3483
|
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
3766
3484
|
const emptyValue = multiple ? [] : "";
|
|
@@ -3791,7 +3509,7 @@
|
|
|
3791
3509
|
"select",
|
|
3792
3510
|
{
|
|
3793
3511
|
id,
|
|
3794
|
-
name: id,
|
|
3512
|
+
name: htmlName || id,
|
|
3795
3513
|
multiple,
|
|
3796
3514
|
role: "combobox",
|
|
3797
3515
|
className: "form-control",
|
|
@@ -3825,7 +3543,8 @@
|
|
|
3825
3543
|
autofocus = false,
|
|
3826
3544
|
onChange,
|
|
3827
3545
|
onBlur,
|
|
3828
|
-
onFocus
|
|
3546
|
+
onFocus,
|
|
3547
|
+
htmlName
|
|
3829
3548
|
}) {
|
|
3830
3549
|
const handleChange = react.useCallback(
|
|
3831
3550
|
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
@@ -3843,7 +3562,7 @@
|
|
|
3843
3562
|
"textarea",
|
|
3844
3563
|
{
|
|
3845
3564
|
id,
|
|
3846
|
-
name: id,
|
|
3565
|
+
name: htmlName || id,
|
|
3847
3566
|
className: "form-control",
|
|
3848
3567
|
value: value ? value : "",
|
|
3849
3568
|
placeholder,
|
|
@@ -3922,7 +3641,18 @@
|
|
|
3922
3641
|
rootSchema: {},
|
|
3923
3642
|
formContext: {},
|
|
3924
3643
|
translateString: utils.englishStringTranslator,
|
|
3925
|
-
globalFormOptions: {
|
|
3644
|
+
globalFormOptions: {
|
|
3645
|
+
idPrefix: utils.DEFAULT_ID_PREFIX,
|
|
3646
|
+
idSeparator: utils.DEFAULT_ID_SEPARATOR,
|
|
3647
|
+
useFallbackUiForUnsupportedType: false
|
|
3648
|
+
}
|
|
3649
|
+
};
|
|
3650
|
+
}
|
|
3651
|
+
var IS_RESET = Symbol("reset");
|
|
3652
|
+
function toIChangeEvent(state, status) {
|
|
3653
|
+
return {
|
|
3654
|
+
..._pick(state, ["schema", "uiSchema", "fieldPathId", "schemaUtils", "formData", "edit", "errors", "errorSchema"]),
|
|
3655
|
+
...status !== void 0 && { status }
|
|
3926
3656
|
};
|
|
3927
3657
|
}
|
|
3928
3658
|
var Form = class extends react.Component {
|
|
@@ -3944,9 +3674,11 @@
|
|
|
3944
3674
|
if (!props.validator) {
|
|
3945
3675
|
throw new Error("A validator is required for Form functionality to work");
|
|
3946
3676
|
}
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3677
|
+
const { formData: propsFormData, initialFormData, onChange } = props;
|
|
3678
|
+
const formData = propsFormData ?? initialFormData;
|
|
3679
|
+
this.state = this.getStateFromProps(props, formData, void 0, void 0, void 0, true);
|
|
3680
|
+
if (onChange && !utils.deepEquals(this.state.formData, formData)) {
|
|
3681
|
+
onChange(toIChangeEvent(this.state));
|
|
3950
3682
|
}
|
|
3951
3683
|
this.formElement = react.createRef();
|
|
3952
3684
|
}
|
|
@@ -4008,7 +3740,7 @@
|
|
|
4008
3740
|
if (snapshot.shouldUpdate) {
|
|
4009
3741
|
const { nextState } = snapshot;
|
|
4010
3742
|
if (!utils.deepEquals(nextState.formData, this.props.formData) && !utils.deepEquals(nextState.formData, prevState.formData) && this.props.onChange) {
|
|
4011
|
-
this.props.onChange(nextState);
|
|
3743
|
+
this.props.onChange(toIChangeEvent(nextState));
|
|
4012
3744
|
}
|
|
4013
3745
|
this.setState(nextState);
|
|
4014
3746
|
}
|
|
@@ -4030,6 +3762,7 @@
|
|
|
4030
3762
|
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
4031
3763
|
const validator2 = "validator" in props ? props.validator : this.props.validator;
|
|
4032
3764
|
const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
|
|
3765
|
+
const isUncontrolled = props.formData === void 0 && this.props.formData === void 0;
|
|
4033
3766
|
const edit = typeof inputFormData !== "undefined";
|
|
4034
3767
|
const liveValidate = "liveValidate" in props ? props.liveValidate : this.props.liveValidate;
|
|
4035
3768
|
const mustValidate = edit && !props.noValidate && liveValidate;
|
|
@@ -4050,9 +3783,15 @@
|
|
|
4050
3783
|
);
|
|
4051
3784
|
}
|
|
4052
3785
|
const rootSchema = schemaUtils.getRootSchema();
|
|
3786
|
+
let defaultsFormData = inputFormData;
|
|
3787
|
+
if (inputFormData === IS_RESET) {
|
|
3788
|
+
defaultsFormData = void 0;
|
|
3789
|
+
} else if (inputFormData === void 0 && isUncontrolled) {
|
|
3790
|
+
defaultsFormData = state.formData;
|
|
3791
|
+
}
|
|
4053
3792
|
const formData = schemaUtils.getDefaultFormState(
|
|
4054
3793
|
rootSchema,
|
|
4055
|
-
|
|
3794
|
+
defaultsFormData,
|
|
4056
3795
|
false,
|
|
4057
3796
|
state.initialDefaultsGenerated
|
|
4058
3797
|
);
|
|
@@ -4116,7 +3855,9 @@
|
|
|
4116
3855
|
errors = mergedErrors.errors;
|
|
4117
3856
|
errorSchema = mergedErrors.errorSchema;
|
|
4118
3857
|
}
|
|
4119
|
-
const
|
|
3858
|
+
const newRegistry = this.getRegistry(props, rootSchema, schemaUtils);
|
|
3859
|
+
const registry = utils.deepEquals(state.registry, newRegistry) ? state.registry : newRegistry;
|
|
3860
|
+
const fieldPathId = state.fieldPathId && state.fieldPathId?.[utils.ID_KEY] === registry.globalFormOptions.idPrefix ? state.fieldPathId : utils.toFieldPathId("", registry.globalFormOptions);
|
|
4120
3861
|
const nextState = {
|
|
4121
3862
|
schemaUtils,
|
|
4122
3863
|
schema: rootSchema,
|
|
@@ -4129,7 +3870,8 @@
|
|
|
4129
3870
|
schemaValidationErrors,
|
|
4130
3871
|
schemaValidationErrorSchema,
|
|
4131
3872
|
retrievedSchema: _retrievedSchema,
|
|
4132
|
-
initialDefaultsGenerated: true
|
|
3873
|
+
initialDefaultsGenerated: true,
|
|
3874
|
+
registry
|
|
4133
3875
|
};
|
|
4134
3876
|
return nextState;
|
|
4135
3877
|
}
|
|
@@ -4264,7 +4006,7 @@
|
|
|
4264
4006
|
}
|
|
4265
4007
|
} else if (key === utils.NAME_KEY && data !== "") {
|
|
4266
4008
|
paths.forEach((path) => {
|
|
4267
|
-
const formValue =
|
|
4009
|
+
const formValue = get(formData, path);
|
|
4268
4010
|
const isLeaf = objKeys.length === 1;
|
|
4269
4011
|
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
4270
4012
|
acc.push(path);
|
|
@@ -4288,6 +4030,19 @@
|
|
|
4288
4030
|
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
4289
4031
|
return this.getUsedFormData(formData, fieldNames);
|
|
4290
4032
|
};
|
|
4033
|
+
/** Allows a user to set a value for the provided `fieldPath`, which must be either a dotted path to the field OR a
|
|
4034
|
+
* `FieldPathList`. To set the root element, used either `''` or `[]` for the path. Passing undefined will clear the
|
|
4035
|
+
* value in the field.
|
|
4036
|
+
*
|
|
4037
|
+
* @param fieldPath - Either a dotted path to the field or the `FieldPathList` to the field
|
|
4038
|
+
* @param [newValue] - The new value for the field
|
|
4039
|
+
*/
|
|
4040
|
+
setFieldValue = (fieldPath, newValue) => {
|
|
4041
|
+
const { registry } = this.state;
|
|
4042
|
+
const path = Array.isArray(fieldPath) ? fieldPath : fieldPath.split(".");
|
|
4043
|
+
const fieldPathId = utils.toFieldPathId("", registry.globalFormOptions, path);
|
|
4044
|
+
this.onChange(newValue, path, void 0, fieldPathId[utils.ID_KEY]);
|
|
4045
|
+
};
|
|
4291
4046
|
/** Pushes the given change information into the `pendingChanges` array and then calls `processPendingChanges()` if
|
|
4292
4047
|
* the array only contains a single pending change.
|
|
4293
4048
|
*
|
|
@@ -4332,17 +4087,17 @@
|
|
|
4332
4087
|
formData = newState.formData;
|
|
4333
4088
|
retrievedSchema = newState.retrievedSchema;
|
|
4334
4089
|
}
|
|
4335
|
-
const mustValidate = !noValidate && liveValidate;
|
|
4090
|
+
const mustValidate = !noValidate && (liveValidate === true || liveValidate === "onChange");
|
|
4336
4091
|
let state = { formData, schema };
|
|
4337
4092
|
let newFormData = formData;
|
|
4338
|
-
if (omitExtraData === true && liveOmit === true) {
|
|
4093
|
+
if (omitExtraData === true && (liveOmit === true || liveOmit === "onChange")) {
|
|
4339
4094
|
newFormData = this.omitExtraData(formData);
|
|
4340
4095
|
state = {
|
|
4341
4096
|
formData: newFormData
|
|
4342
4097
|
};
|
|
4343
4098
|
}
|
|
4344
4099
|
if (newErrorSchema) {
|
|
4345
|
-
const oldValidationError = !isRootPath ?
|
|
4100
|
+
const oldValidationError = !isRootPath ? get(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
|
|
4346
4101
|
if (!isEmpty(oldValidationError)) {
|
|
4347
4102
|
if (!isRootPath) {
|
|
4348
4103
|
set(originalErrorSchema, path, newErrorSchema);
|
|
@@ -4354,12 +4109,15 @@
|
|
|
4354
4109
|
customErrors = new utils.ErrorSchemaBuilder();
|
|
4355
4110
|
}
|
|
4356
4111
|
if (isRootPath) {
|
|
4357
|
-
|
|
4112
|
+
const errors2 = get(newErrorSchema, utils.ERRORS_KEY);
|
|
4113
|
+
if (errors2) {
|
|
4114
|
+
customErrors.setErrors(errors2);
|
|
4115
|
+
}
|
|
4358
4116
|
} else {
|
|
4359
4117
|
set(customErrors.ErrorSchema, path, newErrorSchema);
|
|
4360
4118
|
}
|
|
4361
4119
|
}
|
|
4362
|
-
} else if (customErrors &&
|
|
4120
|
+
} else if (customErrors && get(customErrors.ErrorSchema, [...path, utils.ERRORS_KEY])) {
|
|
4363
4121
|
customErrors.clearErrors(path);
|
|
4364
4122
|
}
|
|
4365
4123
|
if (mustValidate && this.pendingChanges.length === 1) {
|
|
@@ -4383,7 +4141,7 @@
|
|
|
4383
4141
|
}
|
|
4384
4142
|
this.setState(state, () => {
|
|
4385
4143
|
if (onChange) {
|
|
4386
|
-
onChange({ ...this.state, ...state }, id);
|
|
4144
|
+
onChange(toIChangeEvent({ ...this.state, ...state }), id);
|
|
4387
4145
|
}
|
|
4388
4146
|
this.pendingChanges.shift();
|
|
4389
4147
|
this.processPendingChange();
|
|
@@ -4409,8 +4167,15 @@
|
|
|
4409
4167
|
*
|
|
4410
4168
|
*/
|
|
4411
4169
|
reset = () => {
|
|
4412
|
-
const { onChange } = this.props;
|
|
4413
|
-
const newState = this.getStateFromProps(
|
|
4170
|
+
const { formData: propsFormData, initialFormData = IS_RESET, onChange } = this.props;
|
|
4171
|
+
const newState = this.getStateFromProps(
|
|
4172
|
+
this.props,
|
|
4173
|
+
propsFormData ?? initialFormData,
|
|
4174
|
+
void 0,
|
|
4175
|
+
void 0,
|
|
4176
|
+
void 0,
|
|
4177
|
+
true
|
|
4178
|
+
);
|
|
4414
4179
|
const newFormData = newState.formData;
|
|
4415
4180
|
const state = {
|
|
4416
4181
|
formData: newFormData,
|
|
@@ -4421,19 +4186,53 @@
|
|
|
4421
4186
|
initialDefaultsGenerated: false,
|
|
4422
4187
|
customErrors: void 0
|
|
4423
4188
|
};
|
|
4424
|
-
this.setState(state, () => onChange && onChange({ ...this.state, ...state }));
|
|
4189
|
+
this.setState(state, () => onChange && onChange(toIChangeEvent({ ...this.state, ...state })));
|
|
4425
4190
|
};
|
|
4426
4191
|
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
4427
|
-
* was provided.
|
|
4192
|
+
* was provided. Also runs any live validation and/or live omit operations if the flags indicate they should happen
|
|
4193
|
+
* during `onBlur`.
|
|
4428
4194
|
*
|
|
4429
4195
|
* @param id - The unique `id` of the field that was blurred
|
|
4430
4196
|
* @param data - The data associated with the field that was blurred
|
|
4431
4197
|
*/
|
|
4432
4198
|
onBlur = (id, data) => {
|
|
4433
|
-
const { onBlur } = this.props;
|
|
4199
|
+
const { onBlur, omitExtraData, liveOmit, liveValidate } = this.props;
|
|
4434
4200
|
if (onBlur) {
|
|
4435
4201
|
onBlur(id, data);
|
|
4436
4202
|
}
|
|
4203
|
+
if (omitExtraData === true && liveOmit === "onBlur" || liveValidate === "onBlur") {
|
|
4204
|
+
const { onChange, extraErrors } = this.props;
|
|
4205
|
+
const { formData } = this.state;
|
|
4206
|
+
let newFormData = formData;
|
|
4207
|
+
let state = { formData: newFormData };
|
|
4208
|
+
if (omitExtraData === true && liveOmit === "onBlur") {
|
|
4209
|
+
newFormData = this.omitExtraData(formData);
|
|
4210
|
+
state = { formData: newFormData };
|
|
4211
|
+
}
|
|
4212
|
+
if (liveValidate === "onBlur") {
|
|
4213
|
+
const { schema, schemaUtils, errorSchema, customErrors, retrievedSchema } = this.state;
|
|
4214
|
+
const liveValidation = this.liveValidate(
|
|
4215
|
+
schema,
|
|
4216
|
+
schemaUtils,
|
|
4217
|
+
errorSchema,
|
|
4218
|
+
newFormData,
|
|
4219
|
+
extraErrors,
|
|
4220
|
+
customErrors,
|
|
4221
|
+
retrievedSchema
|
|
4222
|
+
);
|
|
4223
|
+
state = { formData: newFormData, ...liveValidation, customErrors };
|
|
4224
|
+
}
|
|
4225
|
+
const hasChanges = Object.keys(state).filter((key) => !key.startsWith("schemaValidation")).some((key) => {
|
|
4226
|
+
const oldData = get(this.state, key);
|
|
4227
|
+
const newData = get(state, key);
|
|
4228
|
+
return !utils.deepEquals(oldData, newData);
|
|
4229
|
+
});
|
|
4230
|
+
this.setState(state, () => {
|
|
4231
|
+
if (onChange && hasChanges) {
|
|
4232
|
+
onChange(toIChangeEvent({ ...this.state, ...state }), id);
|
|
4233
|
+
}
|
|
4234
|
+
});
|
|
4235
|
+
}
|
|
4437
4236
|
};
|
|
4438
4237
|
/** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
|
|
4439
4238
|
* was provided.
|
|
@@ -4479,7 +4278,7 @@
|
|
|
4479
4278
|
},
|
|
4480
4279
|
() => {
|
|
4481
4280
|
if (onSubmit) {
|
|
4482
|
-
onSubmit({ ...this.state, formData: newFormData,
|
|
4281
|
+
onSubmit(toIChangeEvent({ ...this.state, formData: newFormData }, "submitted"), event);
|
|
4483
4282
|
}
|
|
4484
4283
|
}
|
|
4485
4284
|
);
|
|
@@ -4496,33 +4295,40 @@
|
|
|
4496
4295
|
uiSchema = {},
|
|
4497
4296
|
experimental_componentUpdateStrategy,
|
|
4498
4297
|
idSeparator = utils.DEFAULT_ID_SEPARATOR,
|
|
4499
|
-
idPrefix = utils.DEFAULT_ID_PREFIX
|
|
4298
|
+
idPrefix = utils.DEFAULT_ID_PREFIX,
|
|
4299
|
+
nameGenerator,
|
|
4300
|
+
useFallbackUiForUnsupportedType = false
|
|
4500
4301
|
} = props;
|
|
4501
4302
|
const rootFieldId = uiSchema["ui:rootFieldId"];
|
|
4502
|
-
return {
|
|
4303
|
+
return {
|
|
4304
|
+
idPrefix: rootFieldId || idPrefix,
|
|
4305
|
+
idSeparator,
|
|
4306
|
+
useFallbackUiForUnsupportedType,
|
|
4307
|
+
...experimental_componentUpdateStrategy !== void 0 && { experimental_componentUpdateStrategy },
|
|
4308
|
+
...nameGenerator !== void 0 && { nameGenerator }
|
|
4309
|
+
};
|
|
4503
4310
|
}
|
|
4504
|
-
/**
|
|
4505
|
-
getRegistry() {
|
|
4506
|
-
const { translateString: customTranslateString, uiSchema = {} } =
|
|
4507
|
-
const { schema, schemaUtils } = this.state;
|
|
4311
|
+
/** Computed the registry for the form using the given `props`, `schema` and `schemaUtils` */
|
|
4312
|
+
getRegistry(props, schema, schemaUtils) {
|
|
4313
|
+
const { translateString: customTranslateString, uiSchema = {} } = props;
|
|
4508
4314
|
const { fields: fields2, templates: templates2, widgets: widgets2, formContext, translateString } = getDefaultRegistry();
|
|
4509
4315
|
return {
|
|
4510
|
-
fields: { ...fields2, ...
|
|
4316
|
+
fields: { ...fields2, ...props.fields },
|
|
4511
4317
|
templates: {
|
|
4512
4318
|
...templates2,
|
|
4513
|
-
...
|
|
4319
|
+
...props.templates,
|
|
4514
4320
|
ButtonTemplates: {
|
|
4515
4321
|
...templates2.ButtonTemplates,
|
|
4516
|
-
...
|
|
4322
|
+
...props.templates?.ButtonTemplates
|
|
4517
4323
|
}
|
|
4518
4324
|
},
|
|
4519
|
-
widgets: { ...widgets2, ...
|
|
4325
|
+
widgets: { ...widgets2, ...props.widgets },
|
|
4520
4326
|
rootSchema: schema,
|
|
4521
|
-
formContext:
|
|
4327
|
+
formContext: props.formContext || formContext,
|
|
4522
4328
|
schemaUtils,
|
|
4523
4329
|
translateString: customTranslateString || translateString,
|
|
4524
4330
|
globalUiOptions: uiSchema[utils.UI_GLOBAL_OPTIONS_KEY],
|
|
4525
|
-
globalFormOptions: this.getGlobalFormOptions(
|
|
4331
|
+
globalFormOptions: this.getGlobalFormOptions(props)
|
|
4526
4332
|
};
|
|
4527
4333
|
}
|
|
4528
4334
|
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
@@ -4652,8 +4458,7 @@
|
|
|
4652
4458
|
showErrorList = "top",
|
|
4653
4459
|
_internalFormWrapper
|
|
4654
4460
|
} = this.props;
|
|
4655
|
-
const { schema, uiSchema, formData, errorSchema, fieldPathId } = this.state;
|
|
4656
|
-
const registry = this.getRegistry();
|
|
4461
|
+
const { schema, uiSchema, formData, errorSchema, fieldPathId, registry } = this.state;
|
|
4657
4462
|
const { SchemaField: _SchemaField } = registry.fields;
|
|
4658
4463
|
const { SubmitButton: SubmitButton2 } = registry.templates.ButtonTemplates;
|
|
4659
4464
|
const as = _internalFormWrapper ? tagName : void 0;
|
|
@@ -4732,7 +4537,11 @@
|
|
|
4732
4537
|
}
|
|
4733
4538
|
);
|
|
4734
4539
|
}
|
|
4735
|
-
function getTestRegistry(rootSchema, fields2 = {}, templates2 = {}, widgets2 = {}, formContext = {}, globalFormOptions = {
|
|
4540
|
+
function getTestRegistry(rootSchema, fields2 = {}, templates2 = {}, widgets2 = {}, formContext = {}, globalFormOptions = {
|
|
4541
|
+
idPrefix: utils.DEFAULT_ID_PREFIX,
|
|
4542
|
+
idSeparator: utils.DEFAULT_ID_SEPARATOR,
|
|
4543
|
+
useFallbackUiForUnsupportedType: false
|
|
4544
|
+
}) {
|
|
4736
4545
|
const defaults = getDefaultRegistry();
|
|
4737
4546
|
const schemaUtils = utils.createSchemaUtils(validator, rootSchema);
|
|
4738
4547
|
return {
|