@rjsf/core 6.0.0-beta.13 → 6.0.0-beta.15
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 +243 -125
- package/dist/index.esm.js +285 -161
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +309 -186
- package/dist/index.js.map +3 -3
- package/lib/components/Form.d.ts +44 -13
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +84 -27
- package/lib/components/fields/ArrayField.d.ts +14 -4
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +73 -27
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +6 -1
- package/lib/components/fields/LayoutGridField.d.ts +19 -1
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +62 -12
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +2 -1
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +2 -1
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.js +2 -2
- package/lib/components/fields/ObjectField.d.ts +2 -2
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +16 -19
- package/lib/components/fields/SchemaField.js +2 -2
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +6 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -12
- package/src/components/Form.tsx +99 -25
- package/src/components/fields/ArrayField.tsx +74 -28
- package/src/components/fields/BooleanField.tsx +10 -1
- package/src/components/fields/LayoutGridField.tsx +69 -11
- package/src/components/fields/LayoutMultiSchemaField.tsx +2 -1
- package/src/components/fields/MultiSchemaField.tsx +2 -1
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +2 -2
- package/src/components/fields/ObjectField.tsx +16 -26
- package/src/components/fields/SchemaField.tsx +2 -2
- package/src/components/fields/StringField.tsx +10 -1
- package/src/components/widgets/AltDateWidget.tsx +20 -22
- package/src/components/widgets/CheckboxesWidget.tsx +2 -2
package/dist/index.js
CHANGED
|
@@ -38,13 +38,15 @@ __export(index_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(index_exports);
|
|
39
39
|
|
|
40
40
|
// src/components/Form.tsx
|
|
41
|
-
var
|
|
41
|
+
var import_react24 = require("react");
|
|
42
42
|
var import_utils45 = require("@rjsf/utils");
|
|
43
|
+
var import_cloneDeep3 = __toESM(require("lodash/cloneDeep"), 1);
|
|
43
44
|
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
44
45
|
var import_get6 = __toESM(require("lodash/get"), 1);
|
|
45
46
|
var import_isEmpty4 = __toESM(require("lodash/isEmpty"), 1);
|
|
46
47
|
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
47
48
|
var import_pick = __toESM(require("lodash/pick"), 1);
|
|
49
|
+
var import_set5 = __toESM(require("lodash/set"), 1);
|
|
48
50
|
var import_toPath = __toESM(require("lodash/toPath"), 1);
|
|
49
51
|
|
|
50
52
|
// src/getDefaultRegistry.ts
|
|
@@ -57,10 +59,10 @@ var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
|
57
59
|
var import_get = __toESM(require("lodash/get"), 1);
|
|
58
60
|
var import_isObject = __toESM(require("lodash/isObject"), 1);
|
|
59
61
|
var import_set = __toESM(require("lodash/set"), 1);
|
|
60
|
-
var
|
|
62
|
+
var import_uniqueId = __toESM(require("lodash/uniqueId"), 1);
|
|
61
63
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
62
64
|
function generateRowId() {
|
|
63
|
-
return (0,
|
|
65
|
+
return (0, import_uniqueId.default)("rjsf-array-item-");
|
|
64
66
|
}
|
|
65
67
|
function generateKeyedFormData(formData) {
|
|
66
68
|
return !Array.isArray(formData) ? [] : formData.map((item) => {
|
|
@@ -209,7 +211,8 @@ var ArrayField = class extends import_react.Component {
|
|
|
209
211
|
keyedFormData: newKeyedFormData,
|
|
210
212
|
updatedKeyedFormData: true
|
|
211
213
|
},
|
|
212
|
-
|
|
214
|
+
// add click will pass the empty `path` array to the onChange which adds the appropriate path
|
|
215
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), [], newErrorSchema)
|
|
213
216
|
);
|
|
214
217
|
}
|
|
215
218
|
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
@@ -272,7 +275,8 @@ var ArrayField = class extends import_react.Component {
|
|
|
272
275
|
keyedFormData: newKeyedFormData,
|
|
273
276
|
updatedKeyedFormData: true
|
|
274
277
|
},
|
|
275
|
-
|
|
278
|
+
// Copy index will pass the empty `path` array to the onChange which adds the appropriate path
|
|
279
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), [], newErrorSchema)
|
|
276
280
|
);
|
|
277
281
|
};
|
|
278
282
|
};
|
|
@@ -307,7 +311,8 @@ var ArrayField = class extends import_react.Component {
|
|
|
307
311
|
keyedFormData: newKeyedFormData,
|
|
308
312
|
updatedKeyedFormData: true
|
|
309
313
|
},
|
|
310
|
-
|
|
314
|
+
// drop index will pass the empty `path` array to the onChange which adds the appropriate path
|
|
315
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), [], newErrorSchema)
|
|
311
316
|
);
|
|
312
317
|
};
|
|
313
318
|
};
|
|
@@ -351,7 +356,8 @@ var ArrayField = class extends import_react.Component {
|
|
|
351
356
|
{
|
|
352
357
|
keyedFormData: newKeyedFormData
|
|
353
358
|
},
|
|
354
|
-
|
|
359
|
+
// reorder click will pass the empty `path` array to the onChange which adds the appropriate path
|
|
360
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), [], newErrorSchema)
|
|
355
361
|
);
|
|
356
362
|
};
|
|
357
363
|
};
|
|
@@ -361,19 +367,16 @@ var ArrayField = class extends import_react.Component {
|
|
|
361
367
|
* @param index - The index of the item being changed
|
|
362
368
|
*/
|
|
363
369
|
onChangeForIndex = (index) => {
|
|
364
|
-
return (value, newErrorSchema, id) => {
|
|
365
|
-
const {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
const jsonValue = typeof value === "undefined" ? null : value;
|
|
369
|
-
return index === i ? jsonValue : item;
|
|
370
|
-
});
|
|
370
|
+
return (value, path, newErrorSchema, id) => {
|
|
371
|
+
const { onChange } = this.props;
|
|
372
|
+
const changePath = Array.isArray(path) ? path.slice() : [];
|
|
373
|
+
changePath.unshift(index);
|
|
371
374
|
onChange(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
// We need to treat undefined items as nulls to have validation.
|
|
376
|
+
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
377
|
+
value === void 0 ? null : value,
|
|
378
|
+
changePath,
|
|
379
|
+
newErrorSchema,
|
|
377
380
|
id
|
|
378
381
|
);
|
|
379
382
|
};
|
|
@@ -381,8 +384,30 @@ var ArrayField = class extends import_react.Component {
|
|
|
381
384
|
/** Callback handler used to change the value for a checkbox */
|
|
382
385
|
onSelectChange = (value) => {
|
|
383
386
|
const { onChange, idSchema } = this.props;
|
|
384
|
-
onChange(value, void 0, idSchema && idSchema.$id);
|
|
387
|
+
onChange(value, [], void 0, idSchema && idSchema.$id);
|
|
385
388
|
};
|
|
389
|
+
/** Helper method to compute item UI schema for both normal and fixed arrays
|
|
390
|
+
* Handles both static object and dynamic function cases
|
|
391
|
+
*
|
|
392
|
+
* @param uiSchema - The parent UI schema containing items definition
|
|
393
|
+
* @param item - The item data
|
|
394
|
+
* @param index - The index of the item
|
|
395
|
+
* @param formContext - The form context
|
|
396
|
+
* @returns The computed UI schema for the item
|
|
397
|
+
*/
|
|
398
|
+
computeItemUiSchema(uiSchema, item, index, formContext) {
|
|
399
|
+
if (typeof uiSchema.items === "function") {
|
|
400
|
+
try {
|
|
401
|
+
const result = uiSchema.items(item, index, formContext);
|
|
402
|
+
return result;
|
|
403
|
+
} catch (e) {
|
|
404
|
+
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
405
|
+
return void 0;
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
return uiSchema.items;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
386
411
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
387
412
|
*/
|
|
388
413
|
render() {
|
|
@@ -457,6 +482,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
457
482
|
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
458
483
|
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
459
484
|
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
485
|
+
const itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
460
486
|
return this.renderArrayFieldItem({
|
|
461
487
|
key,
|
|
462
488
|
index,
|
|
@@ -469,7 +495,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
469
495
|
itemIdSchema,
|
|
470
496
|
itemErrorSchema,
|
|
471
497
|
itemData: itemCast,
|
|
472
|
-
itemUiSchema
|
|
498
|
+
itemUiSchema,
|
|
473
499
|
autofocus: autofocus && index === 0,
|
|
474
500
|
onBlur,
|
|
475
501
|
onFocus,
|
|
@@ -696,7 +722,16 @@ var ArrayField = class extends import_react.Component {
|
|
|
696
722
|
const itemSchema = (additional && (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
697
723
|
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
698
724
|
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
699
|
-
|
|
725
|
+
let itemUiSchema;
|
|
726
|
+
if (additional) {
|
|
727
|
+
itemUiSchema = uiSchema.additionalItems;
|
|
728
|
+
} else {
|
|
729
|
+
if (Array.isArray(uiSchema.items)) {
|
|
730
|
+
itemUiSchema = uiSchema.items[index];
|
|
731
|
+
} else {
|
|
732
|
+
itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
700
735
|
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
701
736
|
return this.renderArrayFieldItem({
|
|
702
737
|
key,
|
|
@@ -836,6 +871,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
836
871
|
var ArrayField_default = ArrayField;
|
|
837
872
|
|
|
838
873
|
// src/components/fields/BooleanField.tsx
|
|
874
|
+
var import_react2 = require("react");
|
|
839
875
|
var import_utils2 = require("@rjsf/utils");
|
|
840
876
|
var import_isObject2 = __toESM(require("lodash/isObject"), 1);
|
|
841
877
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -906,6 +942,12 @@ function BooleanField(props) {
|
|
|
906
942
|
enumOptions = (0, import_utils2.optionsList)({ enum: enums }, uiSchema);
|
|
907
943
|
}
|
|
908
944
|
}
|
|
945
|
+
const onWidgetChange = (0, import_react2.useCallback)(
|
|
946
|
+
(value, errorSchema, id) => {
|
|
947
|
+
return onChange(value, [], errorSchema, id);
|
|
948
|
+
},
|
|
949
|
+
[onChange]
|
|
950
|
+
);
|
|
909
951
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
910
952
|
Widget,
|
|
911
953
|
{
|
|
@@ -914,7 +956,7 @@ function BooleanField(props) {
|
|
|
914
956
|
uiSchema,
|
|
915
957
|
id: idSchema.$id,
|
|
916
958
|
name,
|
|
917
|
-
onChange,
|
|
959
|
+
onChange: onWidgetChange,
|
|
918
960
|
onFocus,
|
|
919
961
|
onBlur,
|
|
920
962
|
label,
|
|
@@ -934,7 +976,7 @@ function BooleanField(props) {
|
|
|
934
976
|
var BooleanField_default = BooleanField;
|
|
935
977
|
|
|
936
978
|
// src/components/fields/LayoutGridField.tsx
|
|
937
|
-
var
|
|
979
|
+
var import_react3 = require("react");
|
|
938
980
|
var import_utils3 = require("@rjsf/utils");
|
|
939
981
|
var import_cloneDeep2 = __toESM(require("lodash/cloneDeep"), 1);
|
|
940
982
|
var import_each = __toESM(require("lodash/each"), 1);
|
|
@@ -950,16 +992,20 @@ var import_isObject3 = __toESM(require("lodash/isObject"), 1);
|
|
|
950
992
|
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
951
993
|
var import_isString = __toESM(require("lodash/isString"), 1);
|
|
952
994
|
var import_isUndefined = __toESM(require("lodash/isUndefined"), 1);
|
|
995
|
+
var import_last = __toESM(require("lodash/last"), 1);
|
|
953
996
|
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
954
997
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
955
|
-
var
|
|
998
|
+
var import_react4 = require("react");
|
|
956
999
|
var LOOKUP_REGEX = /^\$lookup=(.+)/;
|
|
957
1000
|
var LAYOUT_GRID_UI_OPTION = "layoutGrid";
|
|
958
1001
|
var LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
|
|
959
1002
|
function getNonNullishValue(value, fallback) {
|
|
960
1003
|
return value ?? fallback;
|
|
961
1004
|
}
|
|
962
|
-
|
|
1005
|
+
function isNumericIndex(str) {
|
|
1006
|
+
return /^\d+?$/.test(str);
|
|
1007
|
+
}
|
|
1008
|
+
var LayoutGridField = class _LayoutGridField extends import_react3.PureComponent {
|
|
963
1009
|
static defaultProps = {
|
|
964
1010
|
layoutGridSchema: void 0
|
|
965
1011
|
};
|
|
@@ -1072,6 +1118,38 @@ var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent
|
|
|
1072
1118
|
const baseId = (0, import_get2.default)(baseIdSchema, import_utils3.ID_KEY);
|
|
1073
1119
|
return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
|
|
1074
1120
|
}
|
|
1121
|
+
/** Computes the `rawSchema` and `idSchema` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
|
|
1122
|
+
* has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
|
|
1123
|
+
* to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
|
|
1124
|
+
* otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
|
|
1125
|
+
* either case, an `idSchema` is computed for the array index. If the `schema` does not represent an array or the
|
|
1126
|
+
* `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `idSchema` is returned
|
|
1127
|
+
* as is.
|
|
1128
|
+
*
|
|
1129
|
+
* @param schema - The schema to generate the idSchema for
|
|
1130
|
+
* @param idSchema - The IdSchema for the schema
|
|
1131
|
+
* @param potentialIndex - A string containing a potential index
|
|
1132
|
+
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
1133
|
+
* @returns - An object containing the `rawSchema` and `idSchema` of an array item, otherwise an undefined `rawSchema`
|
|
1134
|
+
*/
|
|
1135
|
+
static computeArraySchemasIfPresent(schema, idSchema, potentialIndex, idSeparator) {
|
|
1136
|
+
let rawSchema;
|
|
1137
|
+
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" && (0, import_has.default)(schema, import_utils3.ITEMS_KEY)) {
|
|
1138
|
+
const index = Number(potentialIndex);
|
|
1139
|
+
const items = schema[import_utils3.ITEMS_KEY];
|
|
1140
|
+
if (Array.isArray(items)) {
|
|
1141
|
+
if (index > items.length) {
|
|
1142
|
+
rawSchema = (0, import_last.default)(items);
|
|
1143
|
+
} else {
|
|
1144
|
+
rawSchema = items[index];
|
|
1145
|
+
}
|
|
1146
|
+
} else {
|
|
1147
|
+
rawSchema = items;
|
|
1148
|
+
}
|
|
1149
|
+
idSchema = { [import_utils3.ID_KEY]: `${idSchema[import_utils3.ID_KEY]}${idSeparator ?? "_"}${index}` };
|
|
1150
|
+
}
|
|
1151
|
+
return { rawSchema, idSchema };
|
|
1152
|
+
}
|
|
1075
1153
|
/** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
|
|
1076
1154
|
* the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
|
|
1077
1155
|
* element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
|
|
@@ -1111,7 +1189,9 @@ var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent
|
|
|
1111
1189
|
rawSchema = (0, import_get2.default)(selectedSchema, [import_utils3.PROPERTIES_KEY, part], {});
|
|
1112
1190
|
idSchema = (0, import_get2.default)(selectedIdSchema, part, {});
|
|
1113
1191
|
} else {
|
|
1114
|
-
|
|
1192
|
+
const result = _LayoutGridField.computeArraySchemasIfPresent(schema, idSchema, part, idSeparator);
|
|
1193
|
+
rawSchema = result.rawSchema ?? {};
|
|
1194
|
+
idSchema = result.idSchema;
|
|
1115
1195
|
}
|
|
1116
1196
|
innerData = (0, import_get2.default)(innerData, part, {});
|
|
1117
1197
|
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
@@ -1130,9 +1210,15 @@ var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent
|
|
|
1130
1210
|
idSchema = (0, import_utils3.mergeObjects)(rawIdSchema, idSchema);
|
|
1131
1211
|
}
|
|
1132
1212
|
isRequired = schema !== void 0 && Array.isArray(schema.required) && (0, import_includes.default)(schema.required, leafPath);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1213
|
+
const result = _LayoutGridField.computeArraySchemasIfPresent(schema, idSchema, leafPath, idSeparator);
|
|
1214
|
+
if (result.rawSchema) {
|
|
1215
|
+
schema = result.rawSchema;
|
|
1216
|
+
idSchema = result.idSchema;
|
|
1217
|
+
} else {
|
|
1218
|
+
schema = (0, import_get2.default)(schema, [import_utils3.PROPERTIES_KEY, leafPath]);
|
|
1219
|
+
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1220
|
+
idSchema = (0, import_get2.default)(idSchema, leafPath, {});
|
|
1221
|
+
}
|
|
1136
1222
|
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1137
1223
|
if (schema && ((0, import_has.default)(schema, import_utils3.ONE_OF_KEY) || (0, import_has.default)(schema, import_utils3.ANY_OF_KEY))) {
|
|
1138
1224
|
const xxx = (0, import_has.default)(schema, import_utils3.ONE_OF_KEY) ? import_utils3.ONE_OF_KEY : import_utils3.ANY_OF_KEY;
|
|
@@ -1212,16 +1298,14 @@ var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent
|
|
|
1212
1298
|
* @returns - The `onChange` handling function for the `dottedPath` field
|
|
1213
1299
|
*/
|
|
1214
1300
|
onFieldChange = (dottedPath) => {
|
|
1215
|
-
return (value, errSchema, id) => {
|
|
1216
|
-
const { onChange, errorSchema
|
|
1217
|
-
const newFormData = (0, import_cloneDeep2.default)(formData || {});
|
|
1301
|
+
return (value, path, errSchema, id) => {
|
|
1302
|
+
const { onChange, errorSchema } = this.props;
|
|
1218
1303
|
let newErrorSchema = errorSchema;
|
|
1219
1304
|
if (errSchema && errorSchema) {
|
|
1220
1305
|
newErrorSchema = (0, import_cloneDeep2.default)(errorSchema);
|
|
1221
1306
|
(0, import_set2.default)(newErrorSchema, dottedPath, errSchema);
|
|
1222
1307
|
}
|
|
1223
|
-
(
|
|
1224
|
-
onChange(newFormData, newErrorSchema, id);
|
|
1308
|
+
onChange(value, dottedPath.split("."), newErrorSchema, id);
|
|
1225
1309
|
};
|
|
1226
1310
|
};
|
|
1227
1311
|
/** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
|
|
@@ -1322,7 +1406,7 @@ var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent
|
|
|
1322
1406
|
const { registry, schema: rawSchema, formData } = this.props;
|
|
1323
1407
|
const { schemaUtils } = registry;
|
|
1324
1408
|
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1325
|
-
return childrenLayoutGridSchema.map((layoutGridSchema) => /* @__PURE__ */ (0,
|
|
1409
|
+
return childrenLayoutGridSchema.map((layoutGridSchema) => /* @__PURE__ */ (0, import_react4.createElement)(
|
|
1326
1410
|
_LayoutGridField,
|
|
1327
1411
|
{
|
|
1328
1412
|
...this.props,
|
|
@@ -1502,7 +1586,7 @@ function LayoutHeaderField(props) {
|
|
|
1502
1586
|
}
|
|
1503
1587
|
|
|
1504
1588
|
// src/components/fields/LayoutMultiSchemaField.tsx
|
|
1505
|
-
var
|
|
1589
|
+
var import_react5 = require("react");
|
|
1506
1590
|
var import_utils5 = require("@rjsf/utils");
|
|
1507
1591
|
var import_get3 = __toESM(require("lodash/get"), 1);
|
|
1508
1592
|
var import_has2 = __toESM(require("lodash/has"), 1);
|
|
@@ -1556,7 +1640,7 @@ function LayoutMultiSchemaField(props) {
|
|
|
1556
1640
|
hideError = false
|
|
1557
1641
|
} = props;
|
|
1558
1642
|
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
1559
|
-
const [enumOptions, setEnumOptions] = (0,
|
|
1643
|
+
const [enumOptions, setEnumOptions] = (0, import_react5.useState)(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1560
1644
|
const id = (0, import_get3.default)(idSchema, import_utils5.ID_KEY);
|
|
1561
1645
|
const discriminator = (0, import_utils5.getDiscriminatorFieldFromSchema)(schema);
|
|
1562
1646
|
const FieldErrorTemplate2 = (0, import_utils5.getTemplate)("FieldErrorTemplate", registry, options);
|
|
@@ -1565,7 +1649,7 @@ function LayoutMultiSchemaField(props) {
|
|
|
1565
1649
|
const optionsHash = (0, import_utils5.hashObject)(options);
|
|
1566
1650
|
const uiSchemaHash = uiSchema ? (0, import_utils5.hashObject)(uiSchema) : "";
|
|
1567
1651
|
const formDataHash = formData ? (0, import_utils5.hashObject)(formData) : "";
|
|
1568
|
-
(0,
|
|
1652
|
+
(0, import_react5.useEffect)(() => {
|
|
1569
1653
|
setEnumOptions(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1570
1654
|
}, [schemaHash, optionsHash, schemaUtils, uiSchemaHash, formDataHash]);
|
|
1571
1655
|
const {
|
|
@@ -1598,7 +1682,7 @@ function LayoutMultiSchemaField(props) {
|
|
|
1598
1682
|
if (newFormData) {
|
|
1599
1683
|
(0, import_set3.default)(newFormData, selectorField, opt);
|
|
1600
1684
|
}
|
|
1601
|
-
onChange(newFormData, void 0, id);
|
|
1685
|
+
onChange(newFormData, [name], void 0, id);
|
|
1602
1686
|
};
|
|
1603
1687
|
const widgetOptions = { enumOptions, ...uiOptions };
|
|
1604
1688
|
const errors = !hideFieldError && rawErrors.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldErrorTemplate2, { idSchema, schema, errors: rawErrors, registry }) : void 0;
|
|
@@ -1652,13 +1736,13 @@ function LayoutMultiSchemaField(props) {
|
|
|
1652
1736
|
}
|
|
1653
1737
|
|
|
1654
1738
|
// src/components/fields/MultiSchemaField.tsx
|
|
1655
|
-
var
|
|
1739
|
+
var import_react6 = require("react");
|
|
1656
1740
|
var import_get4 = __toESM(require("lodash/get"), 1);
|
|
1657
1741
|
var import_isEmpty3 = __toESM(require("lodash/isEmpty"), 1);
|
|
1658
1742
|
var import_omit2 = __toESM(require("lodash/omit"), 1);
|
|
1659
1743
|
var import_utils6 = require("@rjsf/utils");
|
|
1660
1744
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1661
|
-
var AnyOfField = class extends
|
|
1745
|
+
var AnyOfField = class extends import_react6.Component {
|
|
1662
1746
|
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
1663
1747
|
*
|
|
1664
1748
|
* @param props - The `FieldProps` for this template
|
|
@@ -1740,7 +1824,7 @@ var AnyOfField = class extends import_react5.Component {
|
|
|
1740
1824
|
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
1741
1825
|
}
|
|
1742
1826
|
this.setState({ selectedOption: intOption }, () => {
|
|
1743
|
-
onChange(newFormData, void 0, this.getFieldId());
|
|
1827
|
+
onChange(newFormData, [], void 0, this.getFieldId());
|
|
1744
1828
|
});
|
|
1745
1829
|
};
|
|
1746
1830
|
getFieldId() {
|
|
@@ -1856,24 +1940,24 @@ var AnyOfField = class extends import_react5.Component {
|
|
|
1856
1940
|
var MultiSchemaField_default = AnyOfField;
|
|
1857
1941
|
|
|
1858
1942
|
// src/components/fields/NumberField.tsx
|
|
1859
|
-
var
|
|
1943
|
+
var import_react7 = require("react");
|
|
1860
1944
|
var import_utils7 = require("@rjsf/utils");
|
|
1861
1945
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1862
1946
|
var trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
1863
1947
|
var trailingCharMatcher = /[0.]0*$/;
|
|
1864
1948
|
function NumberField(props) {
|
|
1865
1949
|
const { registry, onChange, formData, value: initialValue } = props;
|
|
1866
|
-
const [lastValue, setLastValue] = (0,
|
|
1950
|
+
const [lastValue, setLastValue] = (0, import_react7.useState)(initialValue);
|
|
1867
1951
|
const { StringField: StringField2 } = registry.fields;
|
|
1868
1952
|
let value = formData;
|
|
1869
|
-
const handleChange = (0,
|
|
1870
|
-
(value2, errorSchema, id) => {
|
|
1953
|
+
const handleChange = (0, import_react7.useCallback)(
|
|
1954
|
+
(value2, path, errorSchema, id) => {
|
|
1871
1955
|
setLastValue(value2);
|
|
1872
1956
|
if (`${value2}`.charAt(0) === ".") {
|
|
1873
1957
|
value2 = `0${value2}`;
|
|
1874
1958
|
}
|
|
1875
1959
|
const processed = typeof value2 === "string" && value2.match(trailingCharMatcherWithPrefix) ? (0, import_utils7.asNumber)(value2.replace(trailingCharMatcher, "")) : (0, import_utils7.asNumber)(value2);
|
|
1876
|
-
onChange(processed, errorSchema, id);
|
|
1960
|
+
onChange(processed, path, errorSchema, id);
|
|
1877
1961
|
},
|
|
1878
1962
|
[onChange]
|
|
1879
1963
|
);
|
|
@@ -1888,7 +1972,7 @@ function NumberField(props) {
|
|
|
1888
1972
|
var NumberField_default = NumberField;
|
|
1889
1973
|
|
|
1890
1974
|
// src/components/fields/ObjectField.tsx
|
|
1891
|
-
var
|
|
1975
|
+
var import_react8 = require("react");
|
|
1892
1976
|
var import_utils8 = require("@rjsf/utils");
|
|
1893
1977
|
var import_markdown_to_jsx = __toESM(require("markdown-to-jsx"), 1);
|
|
1894
1978
|
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
@@ -1897,7 +1981,7 @@ var import_isObject4 = __toESM(require("lodash/isObject"), 1);
|
|
|
1897
1981
|
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
1898
1982
|
var import_unset = __toESM(require("lodash/unset"), 1);
|
|
1899
1983
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1900
|
-
var ObjectField = class extends
|
|
1984
|
+
var ObjectField = class extends import_react8.Component {
|
|
1901
1985
|
/** Set up the initial state */
|
|
1902
1986
|
state = {
|
|
1903
1987
|
wasPropertyKeyModified: false,
|
|
@@ -1921,20 +2005,14 @@ var ObjectField = class extends import_react7.Component {
|
|
|
1921
2005
|
* @returns - The onPropertyChange callback for the `name` property
|
|
1922
2006
|
*/
|
|
1923
2007
|
onPropertyChange = (name, addedByAdditionalProperties = false) => {
|
|
1924
|
-
return (value, newErrorSchema, id) => {
|
|
1925
|
-
const {
|
|
2008
|
+
return (value, path, newErrorSchema, id) => {
|
|
2009
|
+
const { onChange } = this.props;
|
|
1926
2010
|
if (value === void 0 && addedByAdditionalProperties) {
|
|
1927
2011
|
value = "";
|
|
1928
2012
|
}
|
|
1929
|
-
const
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
errorSchema && errorSchema && {
|
|
1933
|
-
...errorSchema,
|
|
1934
|
-
[name]: newErrorSchema
|
|
1935
|
-
},
|
|
1936
|
-
id
|
|
1937
|
-
);
|
|
2013
|
+
const changePath = Array.isArray(path) ? path.slice() : [];
|
|
2014
|
+
changePath.unshift(name);
|
|
2015
|
+
onChange(value, changePath, newErrorSchema, id);
|
|
1938
2016
|
};
|
|
1939
2017
|
};
|
|
1940
2018
|
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
@@ -1946,10 +2024,10 @@ var ObjectField = class extends import_react7.Component {
|
|
|
1946
2024
|
onDropPropertyClick = (key) => {
|
|
1947
2025
|
return (event) => {
|
|
1948
2026
|
event.preventDefault();
|
|
1949
|
-
const { onChange, formData } = this.props;
|
|
2027
|
+
const { onChange, formData, name } = this.props;
|
|
1950
2028
|
const copiedFormData = { ...formData };
|
|
1951
2029
|
(0, import_unset.default)(copiedFormData, key);
|
|
1952
|
-
onChange(copiedFormData);
|
|
2030
|
+
onChange(copiedFormData, [name]);
|
|
1953
2031
|
};
|
|
1954
2032
|
};
|
|
1955
2033
|
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
@@ -1976,11 +2054,11 @@ var ObjectField = class extends import_react7.Component {
|
|
|
1976
2054
|
* @returns - The key change callback function
|
|
1977
2055
|
*/
|
|
1978
2056
|
onKeyChange = (oldValue) => {
|
|
1979
|
-
return (value
|
|
2057
|
+
return (value) => {
|
|
1980
2058
|
if (oldValue === value) {
|
|
1981
2059
|
return;
|
|
1982
2060
|
}
|
|
1983
|
-
const { formData, onChange
|
|
2061
|
+
const { formData, onChange } = this.props;
|
|
1984
2062
|
value = this.getAvailableKey(value, formData);
|
|
1985
2063
|
const newFormData = {
|
|
1986
2064
|
...formData
|
|
@@ -1992,13 +2070,7 @@ var ObjectField = class extends import_react7.Component {
|
|
|
1992
2070
|
});
|
|
1993
2071
|
const renamedObj = Object.assign({}, ...keyValues);
|
|
1994
2072
|
this.setState({ wasPropertyKeyModified: true });
|
|
1995
|
-
onChange(
|
|
1996
|
-
renamedObj,
|
|
1997
|
-
errorSchema && errorSchema && {
|
|
1998
|
-
...errorSchema,
|
|
1999
|
-
[value]: newErrorSchema
|
|
2000
|
-
}
|
|
2001
|
-
);
|
|
2073
|
+
onChange(renamedObj, []);
|
|
2002
2074
|
};
|
|
2003
2075
|
};
|
|
2004
2076
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
@@ -2034,7 +2106,7 @@ var ObjectField = class extends import_react7.Component {
|
|
|
2034
2106
|
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
2035
2107
|
return;
|
|
2036
2108
|
}
|
|
2037
|
-
const { formData, onChange, registry } = this.props;
|
|
2109
|
+
const { formData, name, onChange, registry } = this.props;
|
|
2038
2110
|
const newFormData = { ...formData };
|
|
2039
2111
|
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
2040
2112
|
if (schema.patternProperties) {
|
|
@@ -2062,7 +2134,7 @@ var ObjectField = class extends import_react7.Component {
|
|
|
2062
2134
|
const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
|
|
2063
2135
|
(0, import_set4.default)(newFormData, newKey, newValue);
|
|
2064
2136
|
}
|
|
2065
|
-
onChange(newFormData);
|
|
2137
|
+
onChange(newFormData, [name]);
|
|
2066
2138
|
};
|
|
2067
2139
|
/** Renders the `ObjectField` from the given props
|
|
2068
2140
|
*/
|
|
@@ -2163,7 +2235,7 @@ var ObjectField = class extends import_react7.Component {
|
|
|
2163
2235
|
var ObjectField_default = ObjectField;
|
|
2164
2236
|
|
|
2165
2237
|
// src/components/fields/SchemaField.tsx
|
|
2166
|
-
var
|
|
2238
|
+
var import_react9 = require("react");
|
|
2167
2239
|
var import_utils9 = require("@rjsf/utils");
|
|
2168
2240
|
var import_isObject5 = __toESM(require("lodash/isObject"), 1);
|
|
2169
2241
|
var import_omit3 = __toESM(require("lodash/omit"), 1);
|
|
@@ -2246,10 +2318,10 @@ function SchemaFieldRender(props) {
|
|
|
2246
2318
|
schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator),
|
|
2247
2319
|
_idSchema
|
|
2248
2320
|
);
|
|
2249
|
-
const handleFieldComponentChange = (0,
|
|
2250
|
-
(formData2, newErrorSchema, id2) => {
|
|
2321
|
+
const handleFieldComponentChange = (0, import_react9.useCallback)(
|
|
2322
|
+
(formData2, path, newErrorSchema, id2) => {
|
|
2251
2323
|
const theId = id2 || fieldId;
|
|
2252
|
-
return onChange(formData2, newErrorSchema, theId);
|
|
2324
|
+
return onChange(formData2, path, newErrorSchema, theId);
|
|
2253
2325
|
},
|
|
2254
2326
|
[fieldId, onChange]
|
|
2255
2327
|
);
|
|
@@ -2416,7 +2488,7 @@ function SchemaFieldRender(props) {
|
|
|
2416
2488
|
)
|
|
2417
2489
|
] }) });
|
|
2418
2490
|
}
|
|
2419
|
-
var SchemaField = class extends
|
|
2491
|
+
var SchemaField = class extends import_react9.Component {
|
|
2420
2492
|
shouldComponentUpdate(nextProps) {
|
|
2421
2493
|
const { experimental_componentUpdateStrategy = "customDeep" } = this.props.registry;
|
|
2422
2494
|
return (0, import_utils9.shouldRender)(this, nextProps, this.state, experimental_componentUpdateStrategy);
|
|
@@ -2428,6 +2500,7 @@ var SchemaField = class extends import_react8.Component {
|
|
|
2428
2500
|
var SchemaField_default = SchemaField;
|
|
2429
2501
|
|
|
2430
2502
|
// src/components/fields/StringField.tsx
|
|
2503
|
+
var import_react10 = require("react");
|
|
2431
2504
|
var import_utils10 = require("@rjsf/utils");
|
|
2432
2505
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2433
2506
|
function StringField(props) {
|
|
@@ -2459,6 +2532,12 @@ function StringField(props) {
|
|
|
2459
2532
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
2460
2533
|
const label = uiTitle ?? title ?? name;
|
|
2461
2534
|
const Widget = (0, import_utils10.getWidget)(schema, widget, widgets2);
|
|
2535
|
+
const onWidgetChange = (0, import_react10.useCallback)(
|
|
2536
|
+
(value, errorSchema, id) => {
|
|
2537
|
+
return onChange(value, [], errorSchema, id);
|
|
2538
|
+
},
|
|
2539
|
+
[onChange]
|
|
2540
|
+
);
|
|
2462
2541
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2463
2542
|
Widget,
|
|
2464
2543
|
{
|
|
@@ -2471,7 +2550,7 @@ function StringField(props) {
|
|
|
2471
2550
|
hideLabel: !displayLabel,
|
|
2472
2551
|
hideError,
|
|
2473
2552
|
value: formData,
|
|
2474
|
-
onChange,
|
|
2553
|
+
onChange: onWidgetChange,
|
|
2475
2554
|
onBlur,
|
|
2476
2555
|
onFocus,
|
|
2477
2556
|
required,
|
|
@@ -2488,14 +2567,14 @@ function StringField(props) {
|
|
|
2488
2567
|
var StringField_default = StringField;
|
|
2489
2568
|
|
|
2490
2569
|
// src/components/fields/NullField.tsx
|
|
2491
|
-
var
|
|
2570
|
+
var import_react11 = require("react");
|
|
2492
2571
|
function NullField(props) {
|
|
2493
|
-
const { formData, onChange } = props;
|
|
2494
|
-
(0,
|
|
2572
|
+
const { name, formData, onChange } = props;
|
|
2573
|
+
(0, import_react11.useEffect)(() => {
|
|
2495
2574
|
if (formData === void 0) {
|
|
2496
|
-
onChange(null);
|
|
2575
|
+
onChange(null, [name]);
|
|
2497
2576
|
}
|
|
2498
|
-
}, [formData, onChange]);
|
|
2577
|
+
}, [name, formData, onChange]);
|
|
2499
2578
|
return null;
|
|
2500
2579
|
}
|
|
2501
2580
|
var NullField_default = NullField;
|
|
@@ -2581,7 +2660,7 @@ function ArrayFieldItemTemplate(props) {
|
|
|
2581
2660
|
}
|
|
2582
2661
|
|
|
2583
2662
|
// src/components/templates/ArrayFieldItemButtonsTemplate.tsx
|
|
2584
|
-
var
|
|
2663
|
+
var import_react12 = require("react");
|
|
2585
2664
|
var import_utils13 = require("@rjsf/utils");
|
|
2586
2665
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2587
2666
|
function ArrayFieldItemButtonsTemplate(props) {
|
|
@@ -2601,10 +2680,10 @@ function ArrayFieldItemButtonsTemplate(props) {
|
|
|
2601
2680
|
uiSchema
|
|
2602
2681
|
} = props;
|
|
2603
2682
|
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
2604
|
-
const onCopyClick = (0,
|
|
2605
|
-
const onRemoveClick = (0,
|
|
2606
|
-
const onArrowUpClick = (0,
|
|
2607
|
-
const onArrowDownClick = (0,
|
|
2683
|
+
const onCopyClick = (0, import_react12.useMemo)(() => onCopyIndexClick(index), [index, onCopyIndexClick]);
|
|
2684
|
+
const onRemoveClick = (0, import_react12.useMemo)(() => onDropIndexClick(index), [index, onDropIndexClick]);
|
|
2685
|
+
const onArrowUpClick = (0, import_react12.useMemo)(() => onReorderClick(index, index - 1), [index, onReorderClick]);
|
|
2686
|
+
const onArrowDownClick = (0, import_react12.useMemo)(() => onReorderClick(index, index + 1), [index, onReorderClick]);
|
|
2608
2687
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
2609
2688
|
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2610
2689
|
MoveUpButton2,
|
|
@@ -2756,7 +2835,7 @@ function ArrayFieldTitleTemplate(props) {
|
|
|
2756
2835
|
}
|
|
2757
2836
|
|
|
2758
2837
|
// src/components/templates/BaseInputTemplate.tsx
|
|
2759
|
-
var
|
|
2838
|
+
var import_react13 = require("react");
|
|
2760
2839
|
var import_utils16 = require("@rjsf/utils");
|
|
2761
2840
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2762
2841
|
function BaseInputTemplate(props) {
|
|
@@ -2799,15 +2878,15 @@ function BaseInputTemplate(props) {
|
|
|
2799
2878
|
} else {
|
|
2800
2879
|
inputValue = value == null ? "" : value;
|
|
2801
2880
|
}
|
|
2802
|
-
const _onChange = (0,
|
|
2881
|
+
const _onChange = (0, import_react13.useCallback)(
|
|
2803
2882
|
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
2804
2883
|
[onChange, options]
|
|
2805
2884
|
);
|
|
2806
|
-
const _onBlur = (0,
|
|
2885
|
+
const _onBlur = (0, import_react13.useCallback)(
|
|
2807
2886
|
({ target }) => onBlur(id, target && target.value),
|
|
2808
2887
|
[onBlur, id]
|
|
2809
2888
|
);
|
|
2810
|
-
const _onFocus = (0,
|
|
2889
|
+
const _onFocus = (0, import_react13.useCallback)(
|
|
2811
2890
|
({ target }) => onFocus(id, target && target.value),
|
|
2812
2891
|
[onFocus, id]
|
|
2813
2892
|
);
|
|
@@ -3236,7 +3315,7 @@ function templates() {
|
|
|
3236
3315
|
var templates_default = templates;
|
|
3237
3316
|
|
|
3238
3317
|
// src/components/widgets/AltDateWidget.tsx
|
|
3239
|
-
var
|
|
3318
|
+
var import_react14 = require("react");
|
|
3240
3319
|
var import_utils28 = require("@rjsf/utils");
|
|
3241
3320
|
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
3242
3321
|
function readyForChange(state) {
|
|
@@ -3295,26 +3374,25 @@ function AltDateWidget({
|
|
|
3295
3374
|
value
|
|
3296
3375
|
}) {
|
|
3297
3376
|
const { translateString } = registry;
|
|
3298
|
-
const [
|
|
3299
|
-
|
|
3300
|
-
(
|
|
3301
|
-
|
|
3377
|
+
const [state, setState] = (0, import_react14.useState)((0, import_utils28.parseDateString)(value, time));
|
|
3378
|
+
(0, import_react14.useEffect)(() => {
|
|
3379
|
+
setState((0, import_utils28.parseDateString)(value, time));
|
|
3380
|
+
}, [time, value]);
|
|
3381
|
+
const handleChange = (0, import_react14.useCallback)(
|
|
3382
|
+
(property, value2) => {
|
|
3383
|
+
const nextState = {
|
|
3384
|
+
...state,
|
|
3385
|
+
[property]: typeof value2 === "undefined" ? -1 : value2
|
|
3386
|
+
};
|
|
3387
|
+
if (readyForChange(nextState)) {
|
|
3388
|
+
onChange((0, import_utils28.toDateString)(nextState, time));
|
|
3389
|
+
} else {
|
|
3390
|
+
setState(nextState);
|
|
3391
|
+
}
|
|
3302
3392
|
},
|
|
3303
|
-
|
|
3393
|
+
[state, onChange, time]
|
|
3304
3394
|
);
|
|
3305
|
-
(0,
|
|
3306
|
-
const stateValue = (0, import_utils28.toDateString)(state, time);
|
|
3307
|
-
if (readyForChange(state) && stateValue !== value) {
|
|
3308
|
-
onChange(stateValue);
|
|
3309
|
-
} else if (lastValue !== value) {
|
|
3310
|
-
setLastValue(value);
|
|
3311
|
-
setState((0, import_utils28.parseDateString)(value, time));
|
|
3312
|
-
}
|
|
3313
|
-
}, [time, value, onChange, state, lastValue]);
|
|
3314
|
-
const handleChange = (0, import_react12.useCallback)((property, value2) => {
|
|
3315
|
-
setState({ [property]: value2 });
|
|
3316
|
-
}, []);
|
|
3317
|
-
const handleSetNow = (0, import_react12.useCallback)(
|
|
3395
|
+
const handleSetNow = (0, import_react14.useCallback)(
|
|
3318
3396
|
(event) => {
|
|
3319
3397
|
event.preventDefault();
|
|
3320
3398
|
if (disabled || readonly) {
|
|
@@ -3323,9 +3401,9 @@ function AltDateWidget({
|
|
|
3323
3401
|
const nextState = (0, import_utils28.parseDateString)((/* @__PURE__ */ new Date()).toJSON(), time);
|
|
3324
3402
|
onChange((0, import_utils28.toDateString)(nextState, time));
|
|
3325
3403
|
},
|
|
3326
|
-
[disabled, readonly, time]
|
|
3404
|
+
[disabled, readonly, time, onChange]
|
|
3327
3405
|
);
|
|
3328
|
-
const handleClear = (0,
|
|
3406
|
+
const handleClear = (0, import_react14.useCallback)(
|
|
3329
3407
|
(event) => {
|
|
3330
3408
|
event.preventDefault();
|
|
3331
3409
|
if (disabled || readonly) {
|
|
@@ -3374,7 +3452,7 @@ function AltDateTimeWidget({
|
|
|
3374
3452
|
var AltDateTimeWidget_default = AltDateTimeWidget;
|
|
3375
3453
|
|
|
3376
3454
|
// src/components/widgets/CheckboxWidget.tsx
|
|
3377
|
-
var
|
|
3455
|
+
var import_react15 = require("react");
|
|
3378
3456
|
var import_utils29 = require("@rjsf/utils");
|
|
3379
3457
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
3380
3458
|
function CheckboxWidget({
|
|
@@ -3399,15 +3477,15 @@ function CheckboxWidget({
|
|
|
3399
3477
|
options
|
|
3400
3478
|
);
|
|
3401
3479
|
const required = (0, import_utils29.schemaRequiresTrueValue)(schema);
|
|
3402
|
-
const handleChange = (0,
|
|
3480
|
+
const handleChange = (0, import_react15.useCallback)(
|
|
3403
3481
|
(event) => onChange(event.target.checked),
|
|
3404
3482
|
[onChange]
|
|
3405
3483
|
);
|
|
3406
|
-
const handleBlur = (0,
|
|
3484
|
+
const handleBlur = (0, import_react15.useCallback)(
|
|
3407
3485
|
(event) => onBlur(id, event.target.checked),
|
|
3408
3486
|
[onBlur, id]
|
|
3409
3487
|
);
|
|
3410
|
-
const handleFocus = (0,
|
|
3488
|
+
const handleFocus = (0, import_react15.useCallback)(
|
|
3411
3489
|
(event) => onFocus(id, event.target.checked),
|
|
3412
3490
|
[onFocus, id]
|
|
3413
3491
|
);
|
|
@@ -3447,7 +3525,7 @@ function CheckboxWidget({
|
|
|
3447
3525
|
var CheckboxWidget_default = CheckboxWidget;
|
|
3448
3526
|
|
|
3449
3527
|
// src/components/widgets/CheckboxesWidget.tsx
|
|
3450
|
-
var
|
|
3528
|
+
var import_react16 = require("react");
|
|
3451
3529
|
var import_utils30 = require("@rjsf/utils");
|
|
3452
3530
|
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
3453
3531
|
function CheckboxesWidget({
|
|
@@ -3462,13 +3540,13 @@ function CheckboxesWidget({
|
|
|
3462
3540
|
onFocus
|
|
3463
3541
|
}) {
|
|
3464
3542
|
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
3465
|
-
const handleBlur = (0,
|
|
3543
|
+
const handleBlur = (0, import_react16.useCallback)(
|
|
3466
3544
|
({ target }) => onBlur(id, (0, import_utils30.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3467
|
-
[onBlur, id]
|
|
3545
|
+
[onBlur, id, enumOptions, emptyValue]
|
|
3468
3546
|
);
|
|
3469
|
-
const handleFocus = (0,
|
|
3547
|
+
const handleFocus = (0, import_react16.useCallback)(
|
|
3470
3548
|
({ target }) => onFocus(id, (0, import_utils30.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3471
|
-
[onFocus, id]
|
|
3549
|
+
[onFocus, id, enumOptions, emptyValue]
|
|
3472
3550
|
);
|
|
3473
3551
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "checkboxes", id, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
|
|
3474
3552
|
const checked = (0, import_utils30.enumOptionsIsSelected)(option.value, checkboxesValues);
|
|
@@ -3515,13 +3593,13 @@ function ColorWidget(props) {
|
|
|
3515
3593
|
}
|
|
3516
3594
|
|
|
3517
3595
|
// src/components/widgets/DateWidget.tsx
|
|
3518
|
-
var
|
|
3596
|
+
var import_react17 = require("react");
|
|
3519
3597
|
var import_utils32 = require("@rjsf/utils");
|
|
3520
3598
|
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
3521
3599
|
function DateWidget(props) {
|
|
3522
3600
|
const { onChange, options, registry } = props;
|
|
3523
3601
|
const BaseInputTemplate2 = (0, import_utils32.getTemplate)("BaseInputTemplate", registry, options);
|
|
3524
|
-
const handleChange = (0,
|
|
3602
|
+
const handleChange = (0, import_react17.useCallback)((value) => onChange(value || void 0), [onChange]);
|
|
3525
3603
|
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(BaseInputTemplate2, { type: "date", ...props, onChange: handleChange });
|
|
3526
3604
|
}
|
|
3527
3605
|
|
|
@@ -3552,7 +3630,7 @@ function EmailWidget(props) {
|
|
|
3552
3630
|
}
|
|
3553
3631
|
|
|
3554
3632
|
// src/components/widgets/FileWidget.tsx
|
|
3555
|
-
var
|
|
3633
|
+
var import_react18 = require("react");
|
|
3556
3634
|
var import_utils35 = require("@rjsf/utils");
|
|
3557
3635
|
var import_markdown_to_jsx4 = __toESM(require("markdown-to-jsx"), 1);
|
|
3558
3636
|
var import_jsx_runtime41 = require("react/jsx-runtime");
|
|
@@ -3653,7 +3731,7 @@ function extractFileInfo(dataURLs) {
|
|
|
3653
3731
|
function FileWidget(props) {
|
|
3654
3732
|
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
3655
3733
|
const BaseInputTemplate2 = (0, import_utils35.getTemplate)("BaseInputTemplate", registry, options);
|
|
3656
|
-
const handleChange = (0,
|
|
3734
|
+
const handleChange = (0, import_react18.useCallback)(
|
|
3657
3735
|
(event) => {
|
|
3658
3736
|
if (!event.target.files) {
|
|
3659
3737
|
return;
|
|
@@ -3669,8 +3747,8 @@ function FileWidget(props) {
|
|
|
3669
3747
|
},
|
|
3670
3748
|
[multiple, value, onChange]
|
|
3671
3749
|
);
|
|
3672
|
-
const filesInfo = (0,
|
|
3673
|
-
const rmFile = (0,
|
|
3750
|
+
const filesInfo = (0, import_react18.useMemo)(() => extractFileInfo(Array.isArray(value) ? value : [value]), [value]);
|
|
3751
|
+
const rmFile = (0, import_react18.useCallback)(
|
|
3674
3752
|
(index) => {
|
|
3675
3753
|
if (multiple) {
|
|
3676
3754
|
const newValue = value.filter((_, i) => i !== index);
|
|
@@ -3728,7 +3806,7 @@ function PasswordWidget(props) {
|
|
|
3728
3806
|
}
|
|
3729
3807
|
|
|
3730
3808
|
// src/components/widgets/RadioWidget.tsx
|
|
3731
|
-
var
|
|
3809
|
+
var import_react19 = require("react");
|
|
3732
3810
|
var import_utils37 = require("@rjsf/utils");
|
|
3733
3811
|
var import_jsx_runtime44 = require("react/jsx-runtime");
|
|
3734
3812
|
function RadioWidget({
|
|
@@ -3744,11 +3822,11 @@ function RadioWidget({
|
|
|
3744
3822
|
id
|
|
3745
3823
|
}) {
|
|
3746
3824
|
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
3747
|
-
const handleBlur = (0,
|
|
3825
|
+
const handleBlur = (0, import_react19.useCallback)(
|
|
3748
3826
|
({ target }) => onBlur(id, (0, import_utils37.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3749
3827
|
[onBlur, enumOptions, emptyValue, id]
|
|
3750
3828
|
);
|
|
3751
|
-
const handleFocus = (0,
|
|
3829
|
+
const handleFocus = (0, import_react19.useCallback)(
|
|
3752
3830
|
({ target }) => onFocus(id, (0, import_utils37.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3753
3831
|
[onFocus, enumOptions, emptyValue, id]
|
|
3754
3832
|
);
|
|
@@ -3798,7 +3876,7 @@ function RangeWidget(props) {
|
|
|
3798
3876
|
}
|
|
3799
3877
|
|
|
3800
3878
|
// src/components/widgets/RatingWidget.tsx
|
|
3801
|
-
var
|
|
3879
|
+
var import_react20 = require("react");
|
|
3802
3880
|
var import_jsx_runtime46 = require("react/jsx-runtime");
|
|
3803
3881
|
function RatingWidget({
|
|
3804
3882
|
id,
|
|
@@ -3816,7 +3894,7 @@ function RatingWidget({
|
|
|
3816
3894
|
const { stars = 5, shape = "star" } = options;
|
|
3817
3895
|
const numStars = schema.maximum ? Math.min(schema.maximum, 5) : Math.min(Math.max(stars, 1), 5);
|
|
3818
3896
|
const min = schema.minimum || 0;
|
|
3819
|
-
const handleStarClick = (0,
|
|
3897
|
+
const handleStarClick = (0, import_react20.useCallback)(
|
|
3820
3898
|
(starValue) => {
|
|
3821
3899
|
if (!disabled && !readonly) {
|
|
3822
3900
|
onChange(starValue);
|
|
@@ -3824,7 +3902,7 @@ function RatingWidget({
|
|
|
3824
3902
|
},
|
|
3825
3903
|
[onChange, disabled, readonly]
|
|
3826
3904
|
);
|
|
3827
|
-
const handleFocus = (0,
|
|
3905
|
+
const handleFocus = (0, import_react20.useCallback)(
|
|
3828
3906
|
(event) => {
|
|
3829
3907
|
if (onFocus) {
|
|
3830
3908
|
const starValue = Number(event.target.dataset.value);
|
|
@@ -3833,7 +3911,7 @@ function RatingWidget({
|
|
|
3833
3911
|
},
|
|
3834
3912
|
[onFocus, id]
|
|
3835
3913
|
);
|
|
3836
|
-
const handleBlur = (0,
|
|
3914
|
+
const handleBlur = (0, import_react20.useCallback)(
|
|
3837
3915
|
(event) => {
|
|
3838
3916
|
if (onBlur) {
|
|
3839
3917
|
const starValue = Number(event.target.dataset.value);
|
|
@@ -3901,7 +3979,7 @@ function RatingWidget({
|
|
|
3901
3979
|
}
|
|
3902
3980
|
|
|
3903
3981
|
// src/components/widgets/SelectWidget.tsx
|
|
3904
|
-
var
|
|
3982
|
+
var import_react21 = require("react");
|
|
3905
3983
|
var import_utils38 = require("@rjsf/utils");
|
|
3906
3984
|
var import_jsx_runtime47 = require("react/jsx-runtime");
|
|
3907
3985
|
function getValue(event, multiple) {
|
|
@@ -3927,21 +4005,21 @@ function SelectWidget({
|
|
|
3927
4005
|
}) {
|
|
3928
4006
|
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
3929
4007
|
const emptyValue = multiple ? [] : "";
|
|
3930
|
-
const handleFocus = (0,
|
|
4008
|
+
const handleFocus = (0, import_react21.useCallback)(
|
|
3931
4009
|
(event) => {
|
|
3932
4010
|
const newValue = getValue(event, multiple);
|
|
3933
4011
|
return onFocus(id, (0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
3934
4012
|
},
|
|
3935
4013
|
[onFocus, id, multiple, enumOptions, optEmptyVal]
|
|
3936
4014
|
);
|
|
3937
|
-
const handleBlur = (0,
|
|
4015
|
+
const handleBlur = (0, import_react21.useCallback)(
|
|
3938
4016
|
(event) => {
|
|
3939
4017
|
const newValue = getValue(event, multiple);
|
|
3940
4018
|
return onBlur(id, (0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
3941
4019
|
},
|
|
3942
4020
|
[onBlur, id, multiple, enumOptions, optEmptyVal]
|
|
3943
4021
|
);
|
|
3944
|
-
const handleChange = (0,
|
|
4022
|
+
const handleChange = (0, import_react21.useCallback)(
|
|
3945
4023
|
(event) => {
|
|
3946
4024
|
const newValue = getValue(event, multiple);
|
|
3947
4025
|
return onChange((0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
@@ -3979,7 +4057,7 @@ function SelectWidget({
|
|
|
3979
4057
|
var SelectWidget_default = SelectWidget;
|
|
3980
4058
|
|
|
3981
4059
|
// src/components/widgets/TextareaWidget.tsx
|
|
3982
|
-
var
|
|
4060
|
+
var import_react22 = require("react");
|
|
3983
4061
|
var import_utils39 = require("@rjsf/utils");
|
|
3984
4062
|
var import_jsx_runtime48 = require("react/jsx-runtime");
|
|
3985
4063
|
function TextareaWidget({
|
|
@@ -3995,15 +4073,15 @@ function TextareaWidget({
|
|
|
3995
4073
|
onBlur,
|
|
3996
4074
|
onFocus
|
|
3997
4075
|
}) {
|
|
3998
|
-
const handleChange = (0,
|
|
4076
|
+
const handleChange = (0, import_react22.useCallback)(
|
|
3999
4077
|
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
4000
4078
|
[onChange, options.emptyValue]
|
|
4001
4079
|
);
|
|
4002
|
-
const handleBlur = (0,
|
|
4080
|
+
const handleBlur = (0, import_react22.useCallback)(
|
|
4003
4081
|
({ target }) => onBlur(id, target && target.value),
|
|
4004
4082
|
[onBlur, id]
|
|
4005
4083
|
);
|
|
4006
|
-
const handleFocus = (0,
|
|
4084
|
+
const handleFocus = (0, import_react22.useCallback)(
|
|
4007
4085
|
({ target }) => onFocus(id, target && target.value),
|
|
4008
4086
|
[id, onFocus]
|
|
4009
4087
|
);
|
|
@@ -4043,13 +4121,13 @@ function TextWidget(props) {
|
|
|
4043
4121
|
}
|
|
4044
4122
|
|
|
4045
4123
|
// src/components/widgets/TimeWidget.tsx
|
|
4046
|
-
var
|
|
4124
|
+
var import_react23 = require("react");
|
|
4047
4125
|
var import_utils41 = require("@rjsf/utils");
|
|
4048
4126
|
var import_jsx_runtime50 = require("react/jsx-runtime");
|
|
4049
4127
|
function TimeWidget(props) {
|
|
4050
4128
|
const { onChange, options, registry } = props;
|
|
4051
4129
|
const BaseInputTemplate2 = (0, import_utils41.getTemplate)("BaseInputTemplate", registry, options);
|
|
4052
|
-
const handleChange = (0,
|
|
4130
|
+
const handleChange = (0, import_react23.useCallback)((value) => onChange(value ? `${value}:00` : void 0), [onChange]);
|
|
4053
4131
|
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(BaseInputTemplate2, { type: "time", ...props, onChange: handleChange });
|
|
4054
4132
|
}
|
|
4055
4133
|
|
|
@@ -4112,11 +4190,14 @@ function getDefaultRegistry() {
|
|
|
4112
4190
|
|
|
4113
4191
|
// src/components/Form.tsx
|
|
4114
4192
|
var import_jsx_runtime53 = require("react/jsx-runtime");
|
|
4115
|
-
var Form = class extends
|
|
4193
|
+
var Form = class extends import_react24.Component {
|
|
4116
4194
|
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
4117
4195
|
* provide any possible type here
|
|
4118
4196
|
*/
|
|
4119
4197
|
formElement;
|
|
4198
|
+
/** The list of pending changes
|
|
4199
|
+
*/
|
|
4200
|
+
pendingChanges = [];
|
|
4120
4201
|
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
|
|
4121
4202
|
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
|
|
4122
4203
|
* state construction.
|
|
@@ -4132,7 +4213,7 @@ var Form = class extends import_react22.Component {
|
|
|
4132
4213
|
if (this.props.onChange && !(0, import_utils45.deepEquals)(this.state.formData, this.props.formData)) {
|
|
4133
4214
|
this.props.onChange(this.state);
|
|
4134
4215
|
}
|
|
4135
|
-
this.formElement = (0,
|
|
4216
|
+
this.formElement = (0, import_react24.createRef)();
|
|
4136
4217
|
}
|
|
4137
4218
|
/**
|
|
4138
4219
|
* `getSnapshotBeforeUpdate` is a React lifecycle method that is invoked right before the most recently rendered
|
|
@@ -4155,8 +4236,10 @@ var Form = class extends import_react22.Component {
|
|
|
4155
4236
|
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
4156
4237
|
if (!(0, import_utils45.deepEquals)(this.props, prevProps)) {
|
|
4157
4238
|
const formDataChangedFields = (0, import_utils45.getChangedFields)(this.props.formData, prevProps.formData);
|
|
4239
|
+
const stateDataChangedFields = (0, import_utils45.getChangedFields)(this.props.formData, this.state.formData);
|
|
4158
4240
|
const isSchemaChanged = !(0, import_utils45.deepEquals)(prevProps.schema, this.props.schema);
|
|
4159
4241
|
const isFormDataChanged = formDataChangedFields.length > 0 || !(0, import_utils45.deepEquals)(prevProps.formData, this.props.formData);
|
|
4242
|
+
const isStateDataChanged = stateDataChangedFields.length > 0 || !(0, import_utils45.deepEquals)(this.state.formData, this.props.formData);
|
|
4160
4243
|
const nextState = this.getStateFromProps(
|
|
4161
4244
|
this.props,
|
|
4162
4245
|
this.props.formData,
|
|
@@ -4165,7 +4248,9 @@ var Form = class extends import_react22.Component {
|
|
|
4165
4248
|
// match one of the subSchemas, the retrieved schema must be updated.
|
|
4166
4249
|
isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
|
|
4167
4250
|
isSchemaChanged,
|
|
4168
|
-
formDataChangedFields
|
|
4251
|
+
formDataChangedFields,
|
|
4252
|
+
// Skip live validation for this request if no form data has changed from the last state
|
|
4253
|
+
!isStateDataChanged
|
|
4169
4254
|
);
|
|
4170
4255
|
const shouldUpdate = !(0, import_utils45.deepEquals)(nextState, prevState);
|
|
4171
4256
|
return { nextState, shouldUpdate };
|
|
@@ -4204,14 +4289,14 @@ var Form = class extends import_react22.Component {
|
|
|
4204
4289
|
* @param formDataChangedFields - The changed fields of `formData`
|
|
4205
4290
|
* @returns - The new state for the `Form`
|
|
4206
4291
|
*/
|
|
4207
|
-
getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false, formDataChangedFields = []) {
|
|
4292
|
+
getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false, formDataChangedFields = [], skipLiveValidate = false) {
|
|
4208
4293
|
const state = this.state || {};
|
|
4209
4294
|
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
4210
4295
|
const validator = "validator" in props ? props.validator : this.props.validator;
|
|
4211
4296
|
const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
|
|
4212
4297
|
const edit = typeof inputFormData !== "undefined";
|
|
4213
4298
|
const liveValidate = "liveValidate" in props ? props.liveValidate : this.props.liveValidate;
|
|
4214
|
-
const mustValidate = edit && !props.noValidate && liveValidate;
|
|
4299
|
+
const mustValidate = edit && !props.noValidate && liveValidate && !skipLiveValidate;
|
|
4215
4300
|
const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
|
|
4216
4301
|
const experimental_customMergeAllOf = "experimental_customMergeAllOf" in props ? props.experimental_customMergeAllOf : this.props.experimental_customMergeAllOf;
|
|
4217
4302
|
let schemaUtils = state.schemaUtils;
|
|
@@ -4331,8 +4416,7 @@ var Form = class extends import_react22.Component {
|
|
|
4331
4416
|
let customValidateErrors = {};
|
|
4332
4417
|
if (typeof customValidate === "function") {
|
|
4333
4418
|
const errorHandler = customValidate(prevFormData, (0, import_utils45.createErrorHandler)(prevFormData), uiSchema);
|
|
4334
|
-
|
|
4335
|
-
customValidateErrors = userErrorSchema;
|
|
4419
|
+
customValidateErrors = (0, import_utils45.unwrapErrorHandler)(errorHandler);
|
|
4336
4420
|
}
|
|
4337
4421
|
return customValidateErrors;
|
|
4338
4422
|
}
|
|
@@ -4341,7 +4425,8 @@ var Form = class extends import_react22.Component {
|
|
|
4341
4425
|
*
|
|
4342
4426
|
* @param formData - The new form data to validate
|
|
4343
4427
|
* @param schema - The schema used to validate against
|
|
4344
|
-
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
4428
|
+
* @param [altSchemaUtils] - The alternate schemaUtils to use for validation
|
|
4429
|
+
* @param [retrievedSchema] - An optionally retrieved schema for per
|
|
4345
4430
|
*/
|
|
4346
4431
|
validate(formData, schema = this.state.schema, altSchemaUtils, retrievedSchema) {
|
|
4347
4432
|
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
@@ -4423,10 +4508,15 @@ var Form = class extends import_react22.Component {
|
|
|
4423
4508
|
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
4424
4509
|
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
4425
4510
|
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
4426
|
-
|
|
4427
|
-
return newFormData;
|
|
4511
|
+
return this.getUsedFormData(formData, fieldNames);
|
|
4428
4512
|
};
|
|
4429
|
-
|
|
4513
|
+
/** Filtering errors based on your retrieved schema to only show errors for properties in the selected branch.
|
|
4514
|
+
*
|
|
4515
|
+
* @param schemaErrors - The schema errors to filter
|
|
4516
|
+
* @param [resolvedSchema] - An optionally resolved schema to use for performance reasons
|
|
4517
|
+
* @param [formData] - The formData to help filter errors
|
|
4518
|
+
* @private
|
|
4519
|
+
*/
|
|
4430
4520
|
filterErrorsBasedOnSchema(schemaErrors, resolvedSchema, formData) {
|
|
4431
4521
|
const { retrievedSchema, schemaUtils } = this.state;
|
|
4432
4522
|
const _retrievedSchema = resolvedSchema ?? retrievedSchema;
|
|
@@ -4460,23 +4550,45 @@ var Form = class extends import_react22.Component {
|
|
|
4460
4550
|
};
|
|
4461
4551
|
return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
|
|
4462
4552
|
}
|
|
4463
|
-
/**
|
|
4464
|
-
*
|
|
4465
|
-
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filtered to remove any extra data not
|
|
4466
|
-
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
4467
|
-
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
4468
|
-
* callback will be called if specified with the updated state.
|
|
4553
|
+
/** Pushes the given change information into the `pendingChanges` array and then calls `processPendingChanges()` if
|
|
4554
|
+
* the array only contains a single pending change.
|
|
4469
4555
|
*
|
|
4470
|
-
* @param
|
|
4471
|
-
* @param
|
|
4472
|
-
* @param
|
|
4556
|
+
* @param newValue - The new form data from a change to a field
|
|
4557
|
+
* @param [path] - The path to the change into which to set the formData
|
|
4558
|
+
* @param [newErrorSchema] - The new `ErrorSchema` based on the field change
|
|
4559
|
+
* @param [id] - The id of the field that caused the change
|
|
4560
|
+
*/
|
|
4561
|
+
onChange = (newValue, path, newErrorSchema, id) => {
|
|
4562
|
+
this.pendingChanges.push({ newValue, path, newErrorSchema, id });
|
|
4563
|
+
if (this.pendingChanges.length === 1) {
|
|
4564
|
+
this.processPendingChange();
|
|
4565
|
+
}
|
|
4566
|
+
};
|
|
4567
|
+
/** Function to handle changes made to a field in the `Form`. This handler gets the first change from the
|
|
4568
|
+
* `pendingChanges` list, containing the `newValue` for the `formData` and the `path` at which the `newValue` is to be
|
|
4569
|
+
* updated, along with a new, optional `ErrorSchema` for that same `path` and potentially the `id` of the field being
|
|
4570
|
+
* changed. It will first update the `formData` with any missing default fields and then, if `omitExtraData` and
|
|
4571
|
+
* `liveOmit` are turned on, the `formData` will be filtered to remove any extra data not in a form field. Then, the
|
|
4572
|
+
* resulting `formData` will be validated if required. The state will be updated with the new updated (potentially
|
|
4573
|
+
* filtered) `formData`, any errors that resulted from validation. Finally the `onChange` callback will be called, if
|
|
4574
|
+
* specified, with the updated state and the `processPendingChange()` function is called again.
|
|
4473
4575
|
*/
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4576
|
+
processPendingChange() {
|
|
4577
|
+
if (this.pendingChanges.length === 0) {
|
|
4578
|
+
return;
|
|
4579
|
+
}
|
|
4580
|
+
const { newValue, path, id } = this.pendingChanges[0];
|
|
4581
|
+
let { newErrorSchema } = this.pendingChanges[0];
|
|
4582
|
+
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange, idPrefix = "" } = this.props;
|
|
4583
|
+
const { formData: oldFormData, schemaUtils, schema, errorSchema } = this.state;
|
|
4584
|
+
const isRootPath = !path || path.length === 0 || path.length === 1 && path[0] === idPrefix;
|
|
4477
4585
|
let retrievedSchema = this.state.retrievedSchema;
|
|
4586
|
+
let formData = isRootPath ? newValue : (0, import_cloneDeep3.default)(oldFormData);
|
|
4478
4587
|
if ((0, import_utils45.isObject)(formData) || Array.isArray(formData)) {
|
|
4479
|
-
|
|
4588
|
+
if (!isRootPath) {
|
|
4589
|
+
(0, import_set5.default)(formData, path, newValue);
|
|
4590
|
+
}
|
|
4591
|
+
const newState = this.getStateFromProps(this.props, formData, void 0, void 0, void 0, true);
|
|
4480
4592
|
formData = newState.formData;
|
|
4481
4593
|
retrievedSchema = newState.retrievedSchema;
|
|
4482
4594
|
}
|
|
@@ -4489,38 +4601,49 @@ var Form = class extends import_react22.Component {
|
|
|
4489
4601
|
formData: newFormData
|
|
4490
4602
|
};
|
|
4491
4603
|
}
|
|
4492
|
-
if (
|
|
4604
|
+
if (newErrorSchema && !isRootPath) {
|
|
4605
|
+
const errorSchemaCopy = (0, import_cloneDeep3.default)(errorSchema);
|
|
4606
|
+
(0, import_set5.default)(errorSchemaCopy, path, newErrorSchema);
|
|
4607
|
+
newErrorSchema = errorSchemaCopy;
|
|
4608
|
+
}
|
|
4609
|
+
if (mustValidate && this.pendingChanges.length === 1) {
|
|
4493
4610
|
const schemaValidation = this.validate(newFormData, schema, schemaUtils, retrievedSchema);
|
|
4494
4611
|
let errors = schemaValidation.errors;
|
|
4495
|
-
let
|
|
4612
|
+
let errorSchema2 = schemaValidation.errorSchema;
|
|
4496
4613
|
const schemaValidationErrors = errors;
|
|
4497
|
-
const schemaValidationErrorSchema =
|
|
4614
|
+
const schemaValidationErrorSchema = errorSchema2;
|
|
4498
4615
|
if (extraErrors) {
|
|
4499
4616
|
const merged = (0, import_utils45.validationDataMerge)(schemaValidation, extraErrors);
|
|
4500
|
-
|
|
4617
|
+
errorSchema2 = merged.errorSchema;
|
|
4501
4618
|
errors = merged.errors;
|
|
4502
4619
|
}
|
|
4503
4620
|
if (newErrorSchema) {
|
|
4504
4621
|
const filteredErrors = this.filterErrorsBasedOnSchema(newErrorSchema, retrievedSchema, newFormData);
|
|
4505
|
-
|
|
4622
|
+
errorSchema2 = (0, import_utils45.mergeObjects)(errorSchema2, filteredErrors, "preventDuplicates");
|
|
4506
4623
|
}
|
|
4507
4624
|
state = {
|
|
4508
4625
|
formData: newFormData,
|
|
4509
4626
|
errors,
|
|
4510
|
-
errorSchema,
|
|
4627
|
+
errorSchema: errorSchema2,
|
|
4511
4628
|
schemaValidationErrors,
|
|
4512
4629
|
schemaValidationErrorSchema
|
|
4513
4630
|
};
|
|
4514
4631
|
} else if (!noValidate && newErrorSchema) {
|
|
4515
|
-
const
|
|
4632
|
+
const errorSchema2 = extraErrors ? (0, import_utils45.mergeObjects)(newErrorSchema, extraErrors, "preventDuplicates") : newErrorSchema;
|
|
4516
4633
|
state = {
|
|
4517
4634
|
formData: newFormData,
|
|
4518
|
-
errorSchema,
|
|
4519
|
-
errors: (0, import_utils45.toErrorList)(
|
|
4635
|
+
errorSchema: errorSchema2,
|
|
4636
|
+
errors: (0, import_utils45.toErrorList)(errorSchema2)
|
|
4520
4637
|
};
|
|
4521
4638
|
}
|
|
4522
|
-
this.setState(state, () =>
|
|
4523
|
-
|
|
4639
|
+
this.setState(state, () => {
|
|
4640
|
+
if (onChange) {
|
|
4641
|
+
onChange({ ...this.state, ...state }, id);
|
|
4642
|
+
}
|
|
4643
|
+
this.pendingChanges.shift();
|
|
4644
|
+
this.processPendingChange();
|
|
4645
|
+
});
|
|
4646
|
+
}
|
|
4524
4647
|
/**
|
|
4525
4648
|
* If the retrievedSchema has changed the new retrievedSchema is returned.
|
|
4526
4649
|
* Otherwise, the old retrievedSchema is returned to persist reference.
|
|
@@ -4755,7 +4878,7 @@ var Form = class extends import_react22.Component {
|
|
|
4755
4878
|
const {
|
|
4756
4879
|
children,
|
|
4757
4880
|
id,
|
|
4758
|
-
idPrefix,
|
|
4881
|
+
idPrefix = "",
|
|
4759
4882
|
idSeparator,
|
|
4760
4883
|
className = "",
|
|
4761
4884
|
tagName,
|
|
@@ -4805,7 +4928,7 @@ var Form = class extends import_react22.Component {
|
|
|
4805
4928
|
/* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
|
|
4806
4929
|
_SchemaField,
|
|
4807
4930
|
{
|
|
4808
|
-
name:
|
|
4931
|
+
name: idPrefix,
|
|
4809
4932
|
schema,
|
|
4810
4933
|
uiSchema,
|
|
4811
4934
|
errorSchema,
|
|
@@ -4831,10 +4954,10 @@ var Form = class extends import_react22.Component {
|
|
|
4831
4954
|
};
|
|
4832
4955
|
|
|
4833
4956
|
// src/withTheme.tsx
|
|
4834
|
-
var
|
|
4957
|
+
var import_react25 = require("react");
|
|
4835
4958
|
var import_jsx_runtime54 = require("react/jsx-runtime");
|
|
4836
4959
|
function withTheme(themeProps) {
|
|
4837
|
-
return (0,
|
|
4960
|
+
return (0, import_react25.forwardRef)(
|
|
4838
4961
|
({ fields: fields2, widgets: widgets2, templates: templates2, ...directProps }, ref) => {
|
|
4839
4962
|
fields2 = { ...themeProps?.fields, ...fields2 };
|
|
4840
4963
|
widgets2 = { ...themeProps?.widgets, ...widgets2 };
|