@rjsf/utils 6.0.0-beta.8 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.js → index.cjs} +563 -200
- package/dist/index.cjs.map +7 -0
- package/dist/utils.esm.js +562 -199
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +533 -193
- package/lib/ErrorSchemaBuilder.d.ts +2 -2
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +3 -0
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js +25 -18
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enums.d.ts +13 -3
- package/lib/enums.js +13 -3
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +6 -0
- package/lib/findSchemaDefinition.js +44 -3
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getDateElementProps.d.ts +1 -2
- package/lib/getTestIds.js +2 -2
- package/lib/getTestIds.js.map +1 -1
- package/lib/getUiOptions.js +4 -0
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/idGenerators.d.ts +22 -15
- package/lib/idGenerators.js +17 -8
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +16 -6
- package/lib/index.js +13 -4
- package/lib/index.js.map +1 -1
- package/lib/isFormDataAvailable.d.ts +7 -0
- package/lib/isFormDataAvailable.js +13 -0
- package/lib/isFormDataAvailable.js.map +1 -0
- package/lib/isRootSchema.d.ts +13 -0
- package/lib/isRootSchema.js +25 -0
- package/lib/isRootSchema.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.js +14 -2
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/nameGenerators.d.ts +13 -0
- package/lib/nameGenerators.js +30 -0
- package/lib/nameGenerators.js.map +1 -0
- package/lib/schema/getDefaultFormState.d.ts +17 -3
- package/lib/schema/getDefaultFormState.js +66 -26
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.js +2 -2
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/index.d.ts +1 -2
- package/lib/schema/index.js +1 -2
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +10 -5
- package/lib/schema/retrieveSchema.js +40 -17
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/shallowEquals.d.ts +8 -0
- package/lib/shallowEquals.js +36 -0
- package/lib/shallowEquals.js.map +1 -0
- package/lib/shouldRender.d.ts +8 -2
- package/lib/shouldRender.js +17 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +18 -0
- package/lib/shouldRenderOptionalField.js +47 -0
- package/lib/shouldRenderOptionalField.js.map +1 -0
- package/lib/toFieldPathId.d.ts +14 -0
- package/lib/toFieldPathId.js +26 -0
- package/lib/toFieldPathId.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +196 -105
- package/lib/useAltDateWidgetProps.d.ts +39 -0
- package/lib/useAltDateWidgetProps.js +71 -0
- package/lib/useAltDateWidgetProps.js.map +1 -0
- package/lib/useDeepCompareMemo.d.ts +8 -0
- package/lib/useDeepCompareMemo.js +17 -0
- package/lib/useDeepCompareMemo.js.map +1 -0
- package/lib/useFileWidgetProps.d.ts +29 -0
- package/lib/useFileWidgetProps.js +119 -0
- package/lib/useFileWidgetProps.js.map +1 -0
- package/lib/validationDataMerge.d.ts +2 -1
- package/lib/validationDataMerge.js +3 -2
- package/lib/validationDataMerge.js.map +1 -1
- package/package.json +13 -14
- package/src/ErrorSchemaBuilder.ts +2 -2
- package/src/constants.ts +3 -0
- package/src/createSchemaUtils.ts +25 -26
- package/src/enums.ts +13 -3
- package/src/findSchemaDefinition.ts +51 -3
- package/src/getDateElementProps.ts +1 -1
- package/src/getTestIds.ts +2 -2
- package/src/getUiOptions.ts +4 -0
- package/src/getWidget.tsx +3 -3
- package/src/idGenerators.ts +35 -25
- package/src/index.ts +36 -5
- package/src/isFormDataAvailable.ts +13 -0
- package/src/isRootSchema.ts +30 -0
- package/src/mergeDefaultsWithFormData.ts +16 -2
- package/src/nameGenerators.ts +43 -0
- package/src/schema/getDefaultFormState.ts +87 -31
- package/src/schema/getDisplayLabel.ts +2 -2
- package/src/schema/index.ts +0 -2
- package/src/schema/retrieveSchema.ts +43 -7
- package/src/shallowEquals.ts +41 -0
- package/src/shouldRender.ts +27 -2
- package/src/shouldRenderOptionalField.ts +56 -0
- package/src/toFieldPathId.ts +34 -0
- package/src/types.ts +229 -113
- package/src/useAltDateWidgetProps.tsx +163 -0
- package/src/useDeepCompareMemo.ts +17 -0
- package/src/useFileWidgetProps.ts +155 -0
- package/src/validationDataMerge.ts +7 -1
- package/dist/index.js.map +0 -7
- package/lib/schema/toIdSchema.d.ts +0 -14
- package/lib/schema/toIdSchema.js +0 -62
- package/lib/schema/toIdSchema.js.map +0 -1
- package/src/schema/toIdSchema.ts +0 -131
package/dist/utils.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/has'), require('lodash/isEqual'), require('lodash/set'), require('lodash/times'), require('lodash/transform'), require('lodash/merge'), require('lodash/flattenDeep'), require('lodash/uniq'), require('json-schema-merge-allof'), require('jsonpointer'), require('lodash/omit'), require('lodash/isObject'), require('lodash/isEmpty'), require('fast-uri'), require('lodash/isString'), require('lodash/union'), require('lodash/isNumber'), require('lodash/reduce'), require('lodash/isNil'), require('lodash/cloneDeep'), require('lodash/setWith'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/has', 'lodash/isEqual', 'lodash/set', 'lodash/times', 'lodash/transform', 'lodash/merge', 'lodash/flattenDeep', 'lodash/uniq', 'json-schema-merge-allof', 'jsonpointer', 'lodash/omit', 'lodash/isObject', 'lodash/isEmpty', 'fast-uri', 'lodash/isString', 'lodash/union', 'lodash/isNumber', 'lodash/reduce', 'lodash/isNil', 'lodash/cloneDeep', 'lodash/setWith', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/has'), require('lodash/isEqual'), require('lodash/set'), require('lodash/times'), require('lodash/transform'), require('lodash/merge'), require('lodash/flattenDeep'), require('lodash/uniq'), require('json-schema-merge-allof'), require('jsonpointer'), require('lodash/omit'), require('lodash/isObject'), require('lodash/isEmpty'), require('fast-uri'), require('lodash/isString'), require('lodash/union'), require('lodash/isNumber'), require('lodash/reduce'), require('lodash/isNil'), require('lodash/cloneDeep'), require('lodash/setWith'), require('lodash/keys'), require('lodash/pickBy'), require('lodash/difference'), require('lodash/uniqueId'), require('react'), require('react-is'), require('react/jsx-runtime'), require('lodash/toPath'), require('lodash/forEach')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/has', 'lodash/isEqual', 'lodash/set', 'lodash/times', 'lodash/transform', 'lodash/merge', 'lodash/flattenDeep', 'lodash/uniq', 'json-schema-merge-allof', 'jsonpointer', 'lodash/omit', 'lodash/isObject', 'lodash/isEmpty', 'fast-uri', 'lodash/isString', 'lodash/union', 'lodash/isNumber', 'lodash/reduce', 'lodash/isNil', 'lodash/cloneDeep', 'lodash/setWith', 'lodash/keys', 'lodash/pickBy', 'lodash/difference', 'lodash/uniqueId', 'react', 'react-is', 'react/jsx-runtime', 'lodash/toPath', 'lodash/forEach'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject2, global.isEqualWith, global.get13, global.has5, global.isEqual2, global.set, global.times, global.transform, global.merge, global.flattenDeep, global.uniq, global.mergeAllOf, global.jsonpointer, global.omit, global.isObject2, global.isEmpty4, global.UriResolver, global.isString, global.union, global.isNumber, global.reduce, global.isNil, global.cloneDeep, global.setWith, global.keys, global.pickBy, global.difference, global.uniqueId, global.react, global.ReactIs, global.jsxRuntime, global.toPath, global.forEach));
|
|
5
|
+
})(this, (function (exports, isPlainObject2, isEqualWith, get13, has5, isEqual2, set, times, transform, merge, flattenDeep, uniq, mergeAllOf, jsonpointer, omit, isObject2, isEmpty4, UriResolver, isString, union, isNumber, reduce, isNil, cloneDeep, setWith, keys, pickBy, difference, uniqueId, react, ReactIs, jsxRuntime, toPath, forEach) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/isObject.ts
|
|
8
8
|
function isObject(thing) {
|
|
@@ -72,6 +72,8 @@
|
|
|
72
72
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
73
73
|
var REF_KEY = "$ref";
|
|
74
74
|
var SCHEMA_KEY = "$schema";
|
|
75
|
+
var DEFAULT_ID_PREFIX = "root";
|
|
76
|
+
var DEFAULT_ID_SEPARATOR = "_";
|
|
75
77
|
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
76
78
|
var FORM_CONTEXT_NAME = "formContext";
|
|
77
79
|
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
@@ -81,10 +83,14 @@
|
|
|
81
83
|
var UI_WIDGET_KEY = "ui:widget";
|
|
82
84
|
var UI_OPTIONS_KEY = "ui:options";
|
|
83
85
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
86
|
+
var JSON_SCHEMA_DRAFT_2019_09 = "https://json-schema.org/draft/2019-09/schema";
|
|
84
87
|
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
85
88
|
|
|
86
89
|
// src/getUiOptions.ts
|
|
87
90
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
91
|
+
if (!uiSchema) {
|
|
92
|
+
return { ...globalOptions };
|
|
93
|
+
}
|
|
88
94
|
return Object.keys(uiSchema).filter((key) => key.indexOf("ui:") === 0).reduce(
|
|
89
95
|
(options, key) => {
|
|
90
96
|
const value = uiSchema[key];
|
|
@@ -130,7 +136,7 @@
|
|
|
130
136
|
return { ...acc, [key]: createErrorHandler(value) };
|
|
131
137
|
}, handler);
|
|
132
138
|
}
|
|
133
|
-
if (
|
|
139
|
+
if (isPlainObject2(formData)) {
|
|
134
140
|
const formObject = formData;
|
|
135
141
|
return Object.keys(formObject).reduce((acc, key) => {
|
|
136
142
|
return { ...acc, [key]: createErrorHandler(formObject[key]) };
|
|
@@ -151,7 +157,16 @@
|
|
|
151
157
|
return schema;
|
|
152
158
|
}
|
|
153
159
|
for (const subSchema of Object.values(schema)) {
|
|
154
|
-
if (
|
|
160
|
+
if (Array.isArray(subSchema)) {
|
|
161
|
+
for (const item of subSchema) {
|
|
162
|
+
if (isObject2(item)) {
|
|
163
|
+
const result = findEmbeddedSchemaRecursive(item, ref);
|
|
164
|
+
if (result !== void 0) {
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} else if (isObject2(subSchema)) {
|
|
155
170
|
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
156
171
|
if (result !== void 0) {
|
|
157
172
|
return result;
|
|
@@ -160,6 +175,23 @@
|
|
|
160
175
|
}
|
|
161
176
|
return void 0;
|
|
162
177
|
}
|
|
178
|
+
function makeAllReferencesAbsolute(schema, baseURI) {
|
|
179
|
+
const currentURI = get13(schema, ID_KEY, baseURI);
|
|
180
|
+
if (REF_KEY in schema) {
|
|
181
|
+
schema = { ...schema, [REF_KEY]: UriResolver.resolve(currentURI, schema[REF_KEY]) };
|
|
182
|
+
}
|
|
183
|
+
for (const [key, subSchema] of Object.entries(schema)) {
|
|
184
|
+
if (Array.isArray(subSchema)) {
|
|
185
|
+
schema = {
|
|
186
|
+
...schema,
|
|
187
|
+
[key]: subSchema.map((item) => isObject2(item) ? makeAllReferencesAbsolute(item, currentURI) : item)
|
|
188
|
+
};
|
|
189
|
+
} else if (isObject2(subSchema)) {
|
|
190
|
+
schema = { ...schema, [key]: makeAllReferencesAbsolute(subSchema, currentURI) };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return schema;
|
|
194
|
+
}
|
|
163
195
|
function splitKeyElementFromObject(key, object) {
|
|
164
196
|
const value = object[key];
|
|
165
197
|
const remaining = omit(object, [key]);
|
|
@@ -184,7 +216,7 @@
|
|
|
184
216
|
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
185
217
|
if (current !== void 0) {
|
|
186
218
|
baseURI = current[ID_KEY];
|
|
187
|
-
if (!
|
|
219
|
+
if (!isEmpty4(refAnchor)) {
|
|
188
220
|
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
189
221
|
}
|
|
190
222
|
}
|
|
@@ -205,7 +237,11 @@
|
|
|
205
237
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
206
238
|
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
207
239
|
if (Object.keys(remaining).length > 0) {
|
|
208
|
-
|
|
240
|
+
if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2019_09 || rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
241
|
+
return { [ALL_OF_KEY]: [remaining, subSchema] };
|
|
242
|
+
} else {
|
|
243
|
+
return { ...remaining, ...subSchema };
|
|
244
|
+
}
|
|
209
245
|
}
|
|
210
246
|
return subSchema;
|
|
211
247
|
}
|
|
@@ -355,7 +391,7 @@
|
|
|
355
391
|
}
|
|
356
392
|
return 0;
|
|
357
393
|
}
|
|
358
|
-
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
394
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs = false) {
|
|
359
395
|
return retrieveSchemaInternal(
|
|
360
396
|
validator,
|
|
361
397
|
schema,
|
|
@@ -363,7 +399,8 @@
|
|
|
363
399
|
rawFormData,
|
|
364
400
|
void 0,
|
|
365
401
|
void 0,
|
|
366
|
-
experimental_customMergeAllOf
|
|
402
|
+
experimental_customMergeAllOf,
|
|
403
|
+
resolveAnyOfOrOneOfRefs
|
|
367
404
|
)[0];
|
|
368
405
|
}
|
|
369
406
|
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
@@ -452,14 +489,16 @@
|
|
|
452
489
|
{}
|
|
453
490
|
);
|
|
454
491
|
}
|
|
455
|
-
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
492
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
456
493
|
const updatedSchemas = resolveReference(
|
|
457
494
|
validator,
|
|
458
495
|
schema,
|
|
459
496
|
rootSchema,
|
|
460
497
|
expandAllBranches,
|
|
461
498
|
recurseList,
|
|
462
|
-
formData
|
|
499
|
+
formData,
|
|
500
|
+
experimental_customMergeAllOf,
|
|
501
|
+
resolveAnyOfOrOneOfRefs
|
|
463
502
|
);
|
|
464
503
|
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) {
|
|
465
504
|
return updatedSchemas;
|
|
@@ -471,7 +510,8 @@
|
|
|
471
510
|
rootSchema,
|
|
472
511
|
expandAllBranches,
|
|
473
512
|
recurseList,
|
|
474
|
-
formData
|
|
513
|
+
formData,
|
|
514
|
+
experimental_customMergeAllOf
|
|
475
515
|
);
|
|
476
516
|
return resolvedSchemas.flatMap((s) => {
|
|
477
517
|
return retrieveSchemaInternal(
|
|
@@ -485,7 +525,7 @@
|
|
|
485
525
|
);
|
|
486
526
|
});
|
|
487
527
|
}
|
|
488
|
-
if (ALL_OF_KEY in schema && Array.isArray(schema
|
|
528
|
+
if (ALL_OF_KEY in schema && Array.isArray(schema[ALL_OF_KEY])) {
|
|
489
529
|
const allOfSchemaElements = schema.allOf.map(
|
|
490
530
|
(allOfSubschema) => retrieveSchemaInternal(
|
|
491
531
|
validator,
|
|
@@ -505,8 +545,8 @@
|
|
|
505
545
|
}
|
|
506
546
|
return [schema];
|
|
507
547
|
}
|
|
508
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
509
|
-
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
548
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
549
|
+
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList, void 0, resolveAnyOfOrOneOfRefs);
|
|
510
550
|
if (updatedSchema !== schema) {
|
|
511
551
|
return retrieveSchemaInternal(
|
|
512
552
|
validator,
|
|
@@ -515,12 +555,13 @@
|
|
|
515
555
|
formData,
|
|
516
556
|
expandAllBranches,
|
|
517
557
|
recurseList,
|
|
518
|
-
experimental_customMergeAllOf
|
|
558
|
+
experimental_customMergeAllOf,
|
|
559
|
+
resolveAnyOfOrOneOfRefs
|
|
519
560
|
);
|
|
520
561
|
}
|
|
521
562
|
return [schema];
|
|
522
563
|
}
|
|
523
|
-
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
564
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveAnyOfOrOneOfRefs) {
|
|
524
565
|
if (!isObject(schema)) {
|
|
525
566
|
return schema;
|
|
526
567
|
}
|
|
@@ -543,7 +584,7 @@
|
|
|
543
584
|
resolvedSchema[PROPERTIES_KEY],
|
|
544
585
|
(result, value, key) => {
|
|
545
586
|
const childList = [...recurseList];
|
|
546
|
-
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
587
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI, resolveAnyOfOrOneOfRefs);
|
|
547
588
|
childrenLists.push(childList);
|
|
548
589
|
},
|
|
549
590
|
{}
|
|
@@ -554,9 +595,28 @@
|
|
|
554
595
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
555
596
|
resolvedSchema = {
|
|
556
597
|
...resolvedSchema,
|
|
557
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
598
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI, resolveAnyOfOrOneOfRefs)
|
|
558
599
|
};
|
|
559
600
|
}
|
|
601
|
+
if (resolveAnyOfOrOneOfRefs) {
|
|
602
|
+
let key;
|
|
603
|
+
let schemas;
|
|
604
|
+
if (ANY_OF_KEY in schema && Array.isArray(schema[ANY_OF_KEY])) {
|
|
605
|
+
key = ANY_OF_KEY;
|
|
606
|
+
schemas = resolvedSchema[ANY_OF_KEY];
|
|
607
|
+
} else if (ONE_OF_KEY in schema && Array.isArray(schema[ONE_OF_KEY])) {
|
|
608
|
+
key = ONE_OF_KEY;
|
|
609
|
+
schemas = resolvedSchema[ONE_OF_KEY];
|
|
610
|
+
}
|
|
611
|
+
if (key && schemas) {
|
|
612
|
+
resolvedSchema = {
|
|
613
|
+
...resolvedSchema,
|
|
614
|
+
[key]: schemas.map(
|
|
615
|
+
(s) => resolveAllReferences(s, rootSchema, recurseList, baseURI, resolveAnyOfOrOneOfRefs)
|
|
616
|
+
)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}
|
|
560
620
|
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
561
621
|
}
|
|
562
622
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
@@ -571,10 +631,10 @@
|
|
|
571
631
|
}
|
|
572
632
|
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
573
633
|
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
574
|
-
if (!
|
|
634
|
+
if (!isEmpty4(matchingProperties)) {
|
|
575
635
|
schema.properties[key] = retrieveSchema(
|
|
576
636
|
validator,
|
|
577
|
-
{
|
|
637
|
+
{ [ALL_OF_KEY]: Object.values(matchingProperties) },
|
|
578
638
|
rootSchema,
|
|
579
639
|
get13(formData, [key]),
|
|
580
640
|
experimental_customMergeAllOf
|
|
@@ -584,12 +644,12 @@
|
|
|
584
644
|
}
|
|
585
645
|
}
|
|
586
646
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
587
|
-
let additionalProperties
|
|
647
|
+
let additionalProperties;
|
|
588
648
|
if (typeof schema.additionalProperties !== "boolean") {
|
|
589
649
|
if (REF_KEY in schema.additionalProperties) {
|
|
590
650
|
additionalProperties = retrieveSchema(
|
|
591
651
|
validator,
|
|
592
|
-
{
|
|
652
|
+
{ [REF_KEY]: get13(schema.additionalProperties, [REF_KEY]) },
|
|
593
653
|
rootSchema,
|
|
594
654
|
formData,
|
|
595
655
|
experimental_customMergeAllOf
|
|
@@ -616,7 +676,7 @@
|
|
|
616
676
|
});
|
|
617
677
|
return schema;
|
|
618
678
|
}
|
|
619
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
679
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
620
680
|
if (!isObject(schema)) {
|
|
621
681
|
return [{}];
|
|
622
682
|
}
|
|
@@ -627,7 +687,8 @@
|
|
|
627
687
|
expandAllBranches,
|
|
628
688
|
recurseList,
|
|
629
689
|
rawFormData,
|
|
630
|
-
experimental_customMergeAllOf
|
|
690
|
+
experimental_customMergeAllOf,
|
|
691
|
+
resolveAnyOfOrOneOfRefs
|
|
631
692
|
);
|
|
632
693
|
return resolvedSchemas.flatMap((s) => {
|
|
633
694
|
let resolvedSchema = s;
|
|
@@ -679,7 +740,7 @@
|
|
|
679
740
|
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
680
741
|
(schema2, key) => {
|
|
681
742
|
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
682
|
-
if (!
|
|
743
|
+
if (!isEmpty4(matchingProperties)) {
|
|
683
744
|
schema2.properties[key] = retrieveSchema(
|
|
684
745
|
validator,
|
|
685
746
|
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
@@ -890,7 +951,7 @@
|
|
|
890
951
|
const data = get13(formData, selectorField);
|
|
891
952
|
if (data !== void 0) {
|
|
892
953
|
return xxxOfs.find((xxx2) => {
|
|
893
|
-
return
|
|
954
|
+
return isEqual2(
|
|
894
955
|
get13(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get13(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
895
956
|
data
|
|
896
957
|
);
|
|
@@ -904,7 +965,7 @@
|
|
|
904
965
|
if (has5(schema, REF_KEY)) {
|
|
905
966
|
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
906
967
|
}
|
|
907
|
-
if (
|
|
968
|
+
if (isEmpty4(path)) {
|
|
908
969
|
return fieldSchema;
|
|
909
970
|
}
|
|
910
971
|
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
@@ -1026,7 +1087,7 @@
|
|
|
1026
1087
|
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
1027
1088
|
let totalScore = 0;
|
|
1028
1089
|
if (schema) {
|
|
1029
|
-
if (
|
|
1090
|
+
if (isObject2(schema.properties)) {
|
|
1030
1091
|
totalScore += reduce(
|
|
1031
1092
|
schema.properties,
|
|
1032
1093
|
(score, value, key) => {
|
|
@@ -1064,7 +1125,7 @@
|
|
|
1064
1125
|
);
|
|
1065
1126
|
}
|
|
1066
1127
|
if (value.type === "object") {
|
|
1067
|
-
if (
|
|
1128
|
+
if (isObject2(formValue)) {
|
|
1068
1129
|
score += 1;
|
|
1069
1130
|
}
|
|
1070
1131
|
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
@@ -1162,8 +1223,19 @@
|
|
|
1162
1223
|
const keyValue = get13(formData, key);
|
|
1163
1224
|
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1164
1225
|
const keyExistsInFormData = key in formData;
|
|
1226
|
+
const keyDefault = get13(defaults, key) ?? {};
|
|
1227
|
+
const defaultValueIsNestedObject = keyExistsInDefaults && Object.entries(keyDefault).some(([, v]) => isObject(v));
|
|
1228
|
+
const keyDefaultIsObject = keyExistsInDefaults && isObject(get13(defaults, key));
|
|
1229
|
+
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1230
|
+
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
1231
|
+
acc2[key] = {
|
|
1232
|
+
...get13(defaults, key),
|
|
1233
|
+
...keyValue
|
|
1234
|
+
};
|
|
1235
|
+
return acc2;
|
|
1236
|
+
}
|
|
1165
1237
|
acc2[key] = mergeDefaultsWithFormData(
|
|
1166
|
-
|
|
1238
|
+
get13(defaults, key),
|
|
1167
1239
|
keyValue,
|
|
1168
1240
|
mergeExtraArrayDefaults,
|
|
1169
1241
|
defaultSupercedesUndefined,
|
|
@@ -1174,7 +1246,7 @@
|
|
|
1174
1246
|
return acc2;
|
|
1175
1247
|
}, acc);
|
|
1176
1248
|
}
|
|
1177
|
-
if (defaultSupercedesUndefined && (!
|
|
1249
|
+
if (defaultSupercedesUndefined && (!(defaults === void 0) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
1178
1250
|
return defaults;
|
|
1179
1251
|
}
|
|
1180
1252
|
return formData;
|
|
@@ -1315,18 +1387,27 @@
|
|
|
1315
1387
|
}
|
|
1316
1388
|
return {};
|
|
1317
1389
|
}
|
|
1390
|
+
function computeDefaultBasedOnSchemaTypeAndDefaults(schema, computedDefault) {
|
|
1391
|
+
const { default: schemaDefault, type } = schema;
|
|
1392
|
+
const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && isEmpty4(computedDefault) && schemaDefault === null;
|
|
1393
|
+
return shouldReturnNullAsDefault ? null : computedDefault;
|
|
1394
|
+
}
|
|
1318
1395
|
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
1319
1396
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
1320
|
-
if (includeUndefinedValues || isConst) {
|
|
1397
|
+
if (includeUndefinedValues === true || isConst) {
|
|
1321
1398
|
obj[key] = computedDefault;
|
|
1399
|
+
} else if (includeUndefinedValues === "excludeObjectChildren") {
|
|
1400
|
+
if (!isObject(computedDefault) || !isEmpty4(computedDefault)) {
|
|
1401
|
+
obj[key] = computedDefault;
|
|
1402
|
+
}
|
|
1322
1403
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1323
1404
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1324
1405
|
if (isObject(computedDefault)) {
|
|
1325
1406
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1326
|
-
if (!
|
|
1407
|
+
if (!isEmpty4(computedDefault)) {
|
|
1327
1408
|
obj[key] = computedDefault;
|
|
1328
1409
|
}
|
|
1329
|
-
} else if ((!
|
|
1410
|
+
} else if ((!isEmpty4(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1330
1411
|
obj[key] = computedDefault;
|
|
1331
1412
|
}
|
|
1332
1413
|
} else if (
|
|
@@ -1350,7 +1431,8 @@
|
|
|
1350
1431
|
experimental_defaultFormStateBehavior = void 0,
|
|
1351
1432
|
experimental_customMergeAllOf = void 0,
|
|
1352
1433
|
required,
|
|
1353
|
-
shouldMergeDefaultsIntoFormData = false
|
|
1434
|
+
shouldMergeDefaultsIntoFormData = false,
|
|
1435
|
+
initialDefaultsGenerated
|
|
1354
1436
|
} = computeDefaultsProps;
|
|
1355
1437
|
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1356
1438
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
@@ -1358,7 +1440,7 @@
|
|
|
1358
1440
|
let schemaToCompute = null;
|
|
1359
1441
|
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1360
1442
|
let updatedRecurseList = _recurseList;
|
|
1361
|
-
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1443
|
+
if (schema[CONST_KEY] !== void 0 && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1362
1444
|
defaults = schema[CONST_KEY];
|
|
1363
1445
|
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1364
1446
|
defaults = mergeObjects(defaults, schema.default);
|
|
@@ -1453,9 +1535,10 @@
|
|
|
1453
1535
|
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1454
1536
|
experimental_customMergeAllOf,
|
|
1455
1537
|
parentDefaults: defaults,
|
|
1456
|
-
rawFormData: formData,
|
|
1538
|
+
rawFormData: rawFormData ?? formData,
|
|
1457
1539
|
required,
|
|
1458
|
-
shouldMergeDefaultsIntoFormData
|
|
1540
|
+
shouldMergeDefaultsIntoFormData,
|
|
1541
|
+
initialDefaultsGenerated
|
|
1459
1542
|
});
|
|
1460
1543
|
}
|
|
1461
1544
|
if (defaults === void 0) {
|
|
@@ -1507,7 +1590,8 @@
|
|
|
1507
1590
|
experimental_defaultFormStateBehavior = void 0,
|
|
1508
1591
|
experimental_customMergeAllOf = void 0,
|
|
1509
1592
|
required,
|
|
1510
|
-
shouldMergeDefaultsIntoFormData
|
|
1593
|
+
shouldMergeDefaultsIntoFormData,
|
|
1594
|
+
initialDefaultsGenerated
|
|
1511
1595
|
} = {}, defaults) {
|
|
1512
1596
|
{
|
|
1513
1597
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
@@ -1528,7 +1612,8 @@
|
|
|
1528
1612
|
parentDefaults: get13(defaults, [key]),
|
|
1529
1613
|
rawFormData: get13(formData, [key]),
|
|
1530
1614
|
required: retrievedSchema.required?.includes(key),
|
|
1531
|
-
shouldMergeDefaultsIntoFormData
|
|
1615
|
+
shouldMergeDefaultsIntoFormData,
|
|
1616
|
+
initialDefaultsGenerated
|
|
1532
1617
|
});
|
|
1533
1618
|
maybeAddDefaultToObject(
|
|
1534
1619
|
acc,
|
|
@@ -1544,7 +1629,7 @@
|
|
|
1544
1629
|
},
|
|
1545
1630
|
{}
|
|
1546
1631
|
);
|
|
1547
|
-
if (retrievedSchema.additionalProperties) {
|
|
1632
|
+
if (retrievedSchema.additionalProperties && !initialDefaultsGenerated) {
|
|
1548
1633
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1549
1634
|
const keys2 = /* @__PURE__ */ new Set();
|
|
1550
1635
|
if (isObject(defaults)) {
|
|
@@ -1565,7 +1650,8 @@
|
|
|
1565
1650
|
parentDefaults: get13(defaults, [key]),
|
|
1566
1651
|
rawFormData: get13(formData, [key]),
|
|
1567
1652
|
required: retrievedSchema.required?.includes(key),
|
|
1568
|
-
shouldMergeDefaultsIntoFormData
|
|
1653
|
+
shouldMergeDefaultsIntoFormData,
|
|
1654
|
+
initialDefaultsGenerated
|
|
1569
1655
|
});
|
|
1570
1656
|
maybeAddDefaultToObject(
|
|
1571
1657
|
objectDefaults,
|
|
@@ -1577,7 +1663,7 @@
|
|
|
1577
1663
|
);
|
|
1578
1664
|
});
|
|
1579
1665
|
}
|
|
1580
|
-
return objectDefaults;
|
|
1666
|
+
return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, objectDefaults);
|
|
1581
1667
|
}
|
|
1582
1668
|
}
|
|
1583
1669
|
function getArrayDefaults(validator, rawSchema, {
|
|
@@ -1587,7 +1673,9 @@
|
|
|
1587
1673
|
experimental_defaultFormStateBehavior = void 0,
|
|
1588
1674
|
experimental_customMergeAllOf = void 0,
|
|
1589
1675
|
required,
|
|
1590
|
-
|
|
1676
|
+
requiredAsRoot = false,
|
|
1677
|
+
shouldMergeDefaultsIntoFormData,
|
|
1678
|
+
initialDefaultsGenerated
|
|
1591
1679
|
} = {}, defaults) {
|
|
1592
1680
|
const schema = rawSchema;
|
|
1593
1681
|
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
@@ -1608,7 +1696,8 @@
|
|
|
1608
1696
|
experimental_customMergeAllOf,
|
|
1609
1697
|
parentDefaults: item,
|
|
1610
1698
|
required,
|
|
1611
|
-
shouldMergeDefaultsIntoFormData
|
|
1699
|
+
shouldMergeDefaultsIntoFormData,
|
|
1700
|
+
initialDefaultsGenerated
|
|
1612
1701
|
});
|
|
1613
1702
|
});
|
|
1614
1703
|
}
|
|
@@ -1626,7 +1715,8 @@
|
|
|
1626
1715
|
rawFormData: item,
|
|
1627
1716
|
parentDefaults: get13(defaults, [idx]),
|
|
1628
1717
|
required,
|
|
1629
|
-
shouldMergeDefaultsIntoFormData
|
|
1718
|
+
shouldMergeDefaultsIntoFormData,
|
|
1719
|
+
initialDefaultsGenerated
|
|
1630
1720
|
});
|
|
1631
1721
|
});
|
|
1632
1722
|
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
@@ -1642,25 +1732,29 @@
|
|
|
1642
1732
|
return defaults ? defaults : void 0;
|
|
1643
1733
|
}
|
|
1644
1734
|
}
|
|
1735
|
+
let arrayDefault;
|
|
1645
1736
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1646
1737
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1738
|
+
arrayDefault = defaults || !required && !requiredAsRoot ? defaults : emptyDefault;
|
|
1739
|
+
} else {
|
|
1740
|
+
const defaultEntries = defaults || [];
|
|
1741
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1742
|
+
const fillerDefault = fillerSchema.default;
|
|
1743
|
+
const fillerEntries = Array.from(
|
|
1744
|
+
{ length: schema.minItems - defaultsLength },
|
|
1745
|
+
() => computeDefaults(validator, fillerSchema, {
|
|
1746
|
+
parentDefaults: fillerDefault,
|
|
1747
|
+
rootSchema,
|
|
1748
|
+
_recurseList,
|
|
1749
|
+
experimental_defaultFormStateBehavior,
|
|
1750
|
+
experimental_customMergeAllOf,
|
|
1751
|
+
required,
|
|
1752
|
+
shouldMergeDefaultsIntoFormData
|
|
1753
|
+
})
|
|
1754
|
+
);
|
|
1755
|
+
arrayDefault = defaultEntries.concat(fillerEntries);
|
|
1756
|
+
}
|
|
1757
|
+
return computeDefaultBasedOnSchemaTypeAndDefaults(rawSchema, arrayDefault);
|
|
1664
1758
|
}
|
|
1665
1759
|
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1666
1760
|
switch (getSchemaType(rawSchema)) {
|
|
@@ -1673,7 +1767,7 @@
|
|
|
1673
1767
|
}
|
|
1674
1768
|
}
|
|
1675
1769
|
}
|
|
1676
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1770
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf, initialDefaultsGenerated) {
|
|
1677
1771
|
if (!isObject(theSchema)) {
|
|
1678
1772
|
throw new Error("Invalid schema: " + theSchema);
|
|
1679
1773
|
}
|
|
@@ -1684,8 +1778,16 @@
|
|
|
1684
1778
|
experimental_defaultFormStateBehavior,
|
|
1685
1779
|
experimental_customMergeAllOf,
|
|
1686
1780
|
rawFormData: formData,
|
|
1687
|
-
shouldMergeDefaultsIntoFormData: true
|
|
1781
|
+
shouldMergeDefaultsIntoFormData: true,
|
|
1782
|
+
initialDefaultsGenerated,
|
|
1783
|
+
requiredAsRoot: true
|
|
1688
1784
|
});
|
|
1785
|
+
if (schema.type !== "object" && isObject(schema.default)) {
|
|
1786
|
+
return {
|
|
1787
|
+
...defaults,
|
|
1788
|
+
...formData
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1689
1791
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
1690
1792
|
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1691
1793
|
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
@@ -1742,10 +1844,10 @@
|
|
|
1742
1844
|
if (schemaType === "object") {
|
|
1743
1845
|
displayLabel = false;
|
|
1744
1846
|
}
|
|
1745
|
-
if (schemaType === "boolean" && !uiSchema[UI_WIDGET_KEY]) {
|
|
1847
|
+
if (schemaType === "boolean" && uiSchema && !uiSchema[UI_WIDGET_KEY]) {
|
|
1746
1848
|
displayLabel = false;
|
|
1747
1849
|
}
|
|
1748
|
-
if (uiSchema[UI_FIELD_KEY]) {
|
|
1850
|
+
if (uiSchema && uiSchema[UI_FIELD_KEY]) {
|
|
1749
1851
|
displayLabel = false;
|
|
1750
1852
|
}
|
|
1751
1853
|
return displayLabel;
|
|
@@ -1879,75 +1981,6 @@
|
|
|
1879
1981
|
}
|
|
1880
1982
|
return newFormData;
|
|
1881
1983
|
}
|
|
1882
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1883
|
-
const $id = id || idPrefix;
|
|
1884
|
-
const idSchema = { $id };
|
|
1885
|
-
if (typeof schema === "object") {
|
|
1886
|
-
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1887
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1888
|
-
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1889
|
-
if (sameSchemaIndex === -1) {
|
|
1890
|
-
return toIdSchemaInternal(
|
|
1891
|
-
validator,
|
|
1892
|
-
_schema,
|
|
1893
|
-
idPrefix,
|
|
1894
|
-
idSeparator,
|
|
1895
|
-
id,
|
|
1896
|
-
rootSchema,
|
|
1897
|
-
formData,
|
|
1898
|
-
_recurseList.concat(_schema),
|
|
1899
|
-
experimental_customMergeAllOf
|
|
1900
|
-
);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1904
|
-
return toIdSchemaInternal(
|
|
1905
|
-
validator,
|
|
1906
|
-
get13(schema, ITEMS_KEY),
|
|
1907
|
-
idPrefix,
|
|
1908
|
-
idSeparator,
|
|
1909
|
-
id,
|
|
1910
|
-
rootSchema,
|
|
1911
|
-
formData,
|
|
1912
|
-
_recurseList,
|
|
1913
|
-
experimental_customMergeAllOf
|
|
1914
|
-
);
|
|
1915
|
-
}
|
|
1916
|
-
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1917
|
-
for (const name in schema.properties) {
|
|
1918
|
-
const field = schema[PROPERTIES_KEY][name];
|
|
1919
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1920
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1921
|
-
validator,
|
|
1922
|
-
field,
|
|
1923
|
-
idPrefix,
|
|
1924
|
-
idSeparator,
|
|
1925
|
-
fieldId,
|
|
1926
|
-
rootSchema,
|
|
1927
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
1928
|
-
// array item has just been added, but not populated with data yet
|
|
1929
|
-
get13(formData, [name]),
|
|
1930
|
-
_recurseList,
|
|
1931
|
-
experimental_customMergeAllOf
|
|
1932
|
-
);
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
return idSchema;
|
|
1937
|
-
}
|
|
1938
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1939
|
-
return toIdSchemaInternal(
|
|
1940
|
-
validator,
|
|
1941
|
-
schema,
|
|
1942
|
-
idPrefix,
|
|
1943
|
-
idSeparator,
|
|
1944
|
-
id,
|
|
1945
|
-
rootSchema,
|
|
1946
|
-
formData,
|
|
1947
|
-
void 0,
|
|
1948
|
-
experimental_customMergeAllOf
|
|
1949
|
-
);
|
|
1950
|
-
}
|
|
1951
1984
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1952
1985
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1953
1986
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
@@ -2058,8 +2091,6 @@
|
|
|
2058
2091
|
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2059
2092
|
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
2060
2093
|
}
|
|
2061
|
-
|
|
2062
|
-
// src/createSchemaUtils.ts
|
|
2063
2094
|
var SchemaUtils = class {
|
|
2064
2095
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2065
2096
|
*
|
|
@@ -2069,11 +2100,22 @@
|
|
|
2069
2100
|
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
2070
2101
|
*/
|
|
2071
2102
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2072
|
-
|
|
2103
|
+
if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2104
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get13(rootSchema, ID_KEY, "#"));
|
|
2105
|
+
} else {
|
|
2106
|
+
this.rootSchema = rootSchema;
|
|
2107
|
+
}
|
|
2073
2108
|
this.validator = validator;
|
|
2074
2109
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2075
2110
|
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
2076
2111
|
}
|
|
2112
|
+
/** Returns the `rootSchema` in the `SchemaUtilsType`
|
|
2113
|
+
*
|
|
2114
|
+
* @returns - The `rootSchema`
|
|
2115
|
+
*/
|
|
2116
|
+
getRootSchema() {
|
|
2117
|
+
return this.rootSchema;
|
|
2118
|
+
}
|
|
2077
2119
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
2078
2120
|
*
|
|
2079
2121
|
* @returns - The `ValidatorType`
|
|
@@ -2146,9 +2188,10 @@
|
|
|
2146
2188
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
2147
2189
|
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
2148
2190
|
* object properties.
|
|
2191
|
+
* @param initialDefaultsGenerated - Indicates whether or not initial defaults have been generated
|
|
2149
2192
|
* @returns - The resulting `formData` with all the defaults provided
|
|
2150
2193
|
*/
|
|
2151
|
-
getDefaultFormState(schema, formData, includeUndefinedValues = false) {
|
|
2194
|
+
getDefaultFormState(schema, formData, includeUndefinedValues = false, initialDefaultsGenerated) {
|
|
2152
2195
|
return getDefaultFormState(
|
|
2153
2196
|
this.validator,
|
|
2154
2197
|
schema,
|
|
@@ -2156,7 +2199,8 @@
|
|
|
2156
2199
|
this.rootSchema,
|
|
2157
2200
|
includeUndefinedValues,
|
|
2158
2201
|
this.experimental_defaultFormStateBehavior,
|
|
2159
|
-
this.experimental_customMergeAllOf
|
|
2202
|
+
this.experimental_customMergeAllOf,
|
|
2203
|
+
initialDefaultsGenerated
|
|
2160
2204
|
);
|
|
2161
2205
|
}
|
|
2162
2206
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -2255,15 +2299,17 @@
|
|
|
2255
2299
|
*
|
|
2256
2300
|
* @param schema - The schema for which retrieving a schema is desired
|
|
2257
2301
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
2302
|
+
* @param [resolveAnyOfOrOneOfRefs] - Optional flag indicating whether to resolved refs in anyOf/oneOf lists
|
|
2258
2303
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
2259
2304
|
*/
|
|
2260
|
-
retrieveSchema(schema, rawFormData) {
|
|
2305
|
+
retrieveSchema(schema, rawFormData, resolveAnyOfOrOneOfRefs) {
|
|
2261
2306
|
return retrieveSchema(
|
|
2262
2307
|
this.validator,
|
|
2263
2308
|
schema,
|
|
2264
2309
|
this.rootSchema,
|
|
2265
2310
|
rawFormData,
|
|
2266
|
-
this.experimental_customMergeAllOf
|
|
2311
|
+
this.experimental_customMergeAllOf,
|
|
2312
|
+
resolveAnyOfOrOneOfRefs
|
|
2267
2313
|
);
|
|
2268
2314
|
}
|
|
2269
2315
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
@@ -2287,27 +2333,6 @@
|
|
|
2287
2333
|
this.experimental_customMergeAllOf
|
|
2288
2334
|
);
|
|
2289
2335
|
}
|
|
2290
|
-
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
2291
|
-
*
|
|
2292
|
-
* @param schema - The schema for which the display label flag is desired
|
|
2293
|
-
* @param [id] - The base id for the schema
|
|
2294
|
-
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
2295
|
-
* @param [idPrefix='root'] - The prefix to use for the id
|
|
2296
|
-
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
2297
|
-
* @returns - The `IdSchema` object for the `schema`
|
|
2298
|
-
*/
|
|
2299
|
-
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
2300
|
-
return toIdSchema(
|
|
2301
|
-
this.validator,
|
|
2302
|
-
schema,
|
|
2303
|
-
id,
|
|
2304
|
-
this.rootSchema,
|
|
2305
|
-
formData,
|
|
2306
|
-
idPrefix,
|
|
2307
|
-
idSeparator,
|
|
2308
|
-
this.experimental_customMergeAllOf
|
|
2309
|
-
);
|
|
2310
|
-
}
|
|
2311
2336
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
2312
2337
|
*
|
|
2313
2338
|
* @param schema - The schema for which the display label flag is desired
|
|
@@ -2393,6 +2418,31 @@
|
|
|
2393
2418
|
return options;
|
|
2394
2419
|
}
|
|
2395
2420
|
|
|
2421
|
+
// src/shallowEquals.ts
|
|
2422
|
+
function shallowEquals(a, b) {
|
|
2423
|
+
if (Object.is(a, b)) {
|
|
2424
|
+
return true;
|
|
2425
|
+
}
|
|
2426
|
+
if (a == null || b == null) {
|
|
2427
|
+
return false;
|
|
2428
|
+
}
|
|
2429
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
2430
|
+
return false;
|
|
2431
|
+
}
|
|
2432
|
+
const keysA = Object.keys(a);
|
|
2433
|
+
const keysB = Object.keys(b);
|
|
2434
|
+
if (keysA.length !== keysB.length) {
|
|
2435
|
+
return false;
|
|
2436
|
+
}
|
|
2437
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
2438
|
+
const key = keysA[i];
|
|
2439
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
2440
|
+
return false;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
return true;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2396
2446
|
// src/replaceStringParameters.ts
|
|
2397
2447
|
function replaceStringParameters(inputString, params) {
|
|
2398
2448
|
let output = inputString;
|
|
@@ -2550,6 +2600,22 @@
|
|
|
2550
2600
|
return this;
|
|
2551
2601
|
}
|
|
2552
2602
|
};
|
|
2603
|
+
function getChangedFields(a, b) {
|
|
2604
|
+
const aIsPlainObject = isPlainObject2(a);
|
|
2605
|
+
const bIsPlainObject = isPlainObject2(b);
|
|
2606
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
2607
|
+
return [];
|
|
2608
|
+
}
|
|
2609
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
2610
|
+
return keys(a);
|
|
2611
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
2612
|
+
return keys(b);
|
|
2613
|
+
} else {
|
|
2614
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get13(b, key))));
|
|
2615
|
+
const diffFields = difference(keys(b), keys(a));
|
|
2616
|
+
return [...unequalFields, ...diffFields];
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2553
2619
|
|
|
2554
2620
|
// src/getDateElementProps.ts
|
|
2555
2621
|
function getDateElementProps(date, time, yearRange = [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2], format = "YMD") {
|
|
@@ -2667,7 +2733,7 @@
|
|
|
2667
2733
|
{
|
|
2668
2734
|
get(_obj, prop) {
|
|
2669
2735
|
if (!ids.has(prop)) {
|
|
2670
|
-
ids.set(prop,
|
|
2736
|
+
ids.set(prop, uniqueId("test-id-"));
|
|
2671
2737
|
}
|
|
2672
2738
|
return ids.get(prop);
|
|
2673
2739
|
}
|
|
@@ -2743,7 +2809,7 @@
|
|
|
2743
2809
|
return mergeWidgetOptions(widget);
|
|
2744
2810
|
}
|
|
2745
2811
|
if (typeof widget !== "string") {
|
|
2746
|
-
throw new Error(`Unsupported widget definition: ${typeof widget}`);
|
|
2812
|
+
throw new Error(`Unsupported widget definition: ${typeof widget} in schema: ${JSON.stringify(schema)}`);
|
|
2747
2813
|
}
|
|
2748
2814
|
if (widget in registeredWidgets) {
|
|
2749
2815
|
const registeredWidget = registeredWidgets[widget];
|
|
@@ -2751,14 +2817,14 @@
|
|
|
2751
2817
|
}
|
|
2752
2818
|
if (typeof type === "string") {
|
|
2753
2819
|
if (!(type in widgetMap)) {
|
|
2754
|
-
throw new Error(`No widget for type '${type}'`);
|
|
2820
|
+
throw new Error(`No widget for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
2755
2821
|
}
|
|
2756
2822
|
if (widget in widgetMap[type]) {
|
|
2757
2823
|
const registeredWidget = registeredWidgets[widgetMap[type][widget]];
|
|
2758
2824
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2759
2825
|
}
|
|
2760
2826
|
}
|
|
2761
|
-
throw new Error(`No widget '${widget}' for type '${type}'`);
|
|
2827
|
+
throw new Error(`No widget '${widget}' for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
2762
2828
|
}
|
|
2763
2829
|
|
|
2764
2830
|
// src/hashForSchema.ts
|
|
@@ -2825,6 +2891,23 @@
|
|
|
2825
2891
|
function buttonId(id, btn) {
|
|
2826
2892
|
return idGenerator(id, btn);
|
|
2827
2893
|
}
|
|
2894
|
+
function optionalControlsId(id, element) {
|
|
2895
|
+
return idGenerator(id, `optional${element}`);
|
|
2896
|
+
}
|
|
2897
|
+
function isFormDataAvailable(formData) {
|
|
2898
|
+
return !isNil(formData) && (!isObject2(formData) || Array.isArray(formData) || !isEmpty4(formData));
|
|
2899
|
+
}
|
|
2900
|
+
function isRootSchema(registry, schemaToCompare) {
|
|
2901
|
+
const { rootSchema, schemaUtils } = registry;
|
|
2902
|
+
if (isEqual2(schemaToCompare, rootSchema)) {
|
|
2903
|
+
return true;
|
|
2904
|
+
}
|
|
2905
|
+
if (REF_KEY in rootSchema) {
|
|
2906
|
+
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
2907
|
+
return isEqual2(schemaToCompare, resolvedSchema);
|
|
2908
|
+
}
|
|
2909
|
+
return false;
|
|
2910
|
+
}
|
|
2828
2911
|
|
|
2829
2912
|
// src/labelValue.ts
|
|
2830
2913
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2921,10 +3004,35 @@
|
|
|
2921
3004
|
}
|
|
2922
3005
|
|
|
2923
3006
|
// src/shouldRender.ts
|
|
2924
|
-
function shouldRender(component, nextProps, nextState) {
|
|
3007
|
+
function shouldRender(component, nextProps, nextState, updateStrategy = "customDeep") {
|
|
3008
|
+
if (updateStrategy === "always") {
|
|
3009
|
+
return true;
|
|
3010
|
+
}
|
|
3011
|
+
if (updateStrategy === "shallow") {
|
|
3012
|
+
const { props: props2, state: state2 } = component;
|
|
3013
|
+
return !shallowEquals(props2, nextProps) || !shallowEquals(state2, nextState);
|
|
3014
|
+
}
|
|
2925
3015
|
const { props, state } = component;
|
|
2926
3016
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
2927
3017
|
}
|
|
3018
|
+
function getSchemaTypesForXxxOf(schemas) {
|
|
3019
|
+
const allTypes = uniq(
|
|
3020
|
+
schemas.map((s) => isObject2(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
|
|
3021
|
+
);
|
|
3022
|
+
return allTypes.length === 1 ? allTypes[0] : allTypes;
|
|
3023
|
+
}
|
|
3024
|
+
function shouldRenderOptionalField(registry, schema, required, uiSchema) {
|
|
3025
|
+
const { enableOptionalDataFieldForType = [] } = getUiOptions(uiSchema, registry.globalUiOptions);
|
|
3026
|
+
let schemaType;
|
|
3027
|
+
if (ANY_OF_KEY in schema && Array.isArray(schema[ANY_OF_KEY])) {
|
|
3028
|
+
schemaType = getSchemaTypesForXxxOf(schema[ANY_OF_KEY]);
|
|
3029
|
+
} else if (ONE_OF_KEY in schema && Array.isArray(schema[ONE_OF_KEY])) {
|
|
3030
|
+
schemaType = getSchemaTypesForXxxOf(schema[ONE_OF_KEY]);
|
|
3031
|
+
} else {
|
|
3032
|
+
schemaType = getSchemaType(schema);
|
|
3033
|
+
}
|
|
3034
|
+
return !isRootSchema(registry, schema) && !required && !!schemaType && !Array.isArray(schemaType) && !!enableOptionalDataFieldForType.find((val) => val === schemaType);
|
|
3035
|
+
}
|
|
2928
3036
|
|
|
2929
3037
|
// src/toDateString.ts
|
|
2930
3038
|
function toDateString(dateObject, time = true) {
|
|
@@ -2953,7 +3061,7 @@
|
|
|
2953
3061
|
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
2954
3062
|
if (key !== ERRORS_KEY) {
|
|
2955
3063
|
const childSchema = errorSchema[key];
|
|
2956
|
-
if (
|
|
3064
|
+
if (isPlainObject2(childSchema)) {
|
|
2957
3065
|
acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
2958
3066
|
}
|
|
2959
3067
|
}
|
|
@@ -2976,13 +3084,26 @@
|
|
|
2976
3084
|
}
|
|
2977
3085
|
return builder.ErrorSchema;
|
|
2978
3086
|
}
|
|
3087
|
+
|
|
3088
|
+
// src/toFieldPathId.ts
|
|
3089
|
+
function toFieldPathId(fieldPath, globalFormOptions, parentPath, isMultiValue) {
|
|
3090
|
+
const basePath = Array.isArray(parentPath) ? parentPath : parentPath?.path;
|
|
3091
|
+
const childPath = fieldPath === "" ? [] : [fieldPath];
|
|
3092
|
+
const path = basePath ? basePath.concat(...childPath) : childPath;
|
|
3093
|
+
const id = [globalFormOptions.idPrefix, ...path].join(globalFormOptions.idSeparator);
|
|
3094
|
+
let name;
|
|
3095
|
+
if (globalFormOptions.nameGenerator && path.length > 0) {
|
|
3096
|
+
name = globalFormOptions.nameGenerator(path, globalFormOptions.idPrefix, isMultiValue);
|
|
3097
|
+
}
|
|
3098
|
+
return { path, [ID_KEY]: id, ...name !== void 0 && { name } };
|
|
3099
|
+
}
|
|
2979
3100
|
function unwrapErrorHandler(errorHandler) {
|
|
2980
3101
|
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
2981
3102
|
if (key === "addError") {
|
|
2982
3103
|
return acc;
|
|
2983
3104
|
} else {
|
|
2984
3105
|
const childSchema = errorHandler[key];
|
|
2985
|
-
if (
|
|
3106
|
+
if (isPlainObject2(childSchema)) {
|
|
2986
3107
|
return {
|
|
2987
3108
|
...acc,
|
|
2988
3109
|
[key]: unwrapErrorHandler(childSchema)
|
|
@@ -2992,6 +3113,198 @@
|
|
|
2992
3113
|
}
|
|
2993
3114
|
}, {});
|
|
2994
3115
|
}
|
|
3116
|
+
function readyForChange(state) {
|
|
3117
|
+
return Object.values(state).every((value) => value !== -1);
|
|
3118
|
+
}
|
|
3119
|
+
function DateElement(props) {
|
|
3120
|
+
const {
|
|
3121
|
+
className = "form-control",
|
|
3122
|
+
type,
|
|
3123
|
+
range,
|
|
3124
|
+
value,
|
|
3125
|
+
select,
|
|
3126
|
+
rootId,
|
|
3127
|
+
name,
|
|
3128
|
+
disabled,
|
|
3129
|
+
readonly,
|
|
3130
|
+
autofocus,
|
|
3131
|
+
registry,
|
|
3132
|
+
onBlur,
|
|
3133
|
+
onFocus
|
|
3134
|
+
} = props;
|
|
3135
|
+
const id = `${rootId}_${type}`;
|
|
3136
|
+
const { SelectWidget } = registry.widgets;
|
|
3137
|
+
const onChange = react.useCallback((value2) => select(type, value2), [select, type]);
|
|
3138
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3139
|
+
SelectWidget,
|
|
3140
|
+
{
|
|
3141
|
+
schema: { type: "integer" },
|
|
3142
|
+
id,
|
|
3143
|
+
name,
|
|
3144
|
+
className,
|
|
3145
|
+
options: { enumOptions: dateRangeOptions(range[0], range[1]) },
|
|
3146
|
+
placeholder: type,
|
|
3147
|
+
value,
|
|
3148
|
+
disabled,
|
|
3149
|
+
readonly,
|
|
3150
|
+
autofocus,
|
|
3151
|
+
onChange,
|
|
3152
|
+
onBlur,
|
|
3153
|
+
onFocus,
|
|
3154
|
+
registry,
|
|
3155
|
+
label: "",
|
|
3156
|
+
"aria-describedby": ariaDescribedByIds(rootId)
|
|
3157
|
+
}
|
|
3158
|
+
);
|
|
3159
|
+
}
|
|
3160
|
+
function useAltDateWidgetProps(props) {
|
|
3161
|
+
const { time = false, disabled = false, readonly = false, options, onChange, value } = props;
|
|
3162
|
+
const [state, setState] = react.useState(parseDateString(value, time));
|
|
3163
|
+
react.useEffect(() => {
|
|
3164
|
+
setState(parseDateString(value, time));
|
|
3165
|
+
}, [time, value]);
|
|
3166
|
+
const handleChange = react.useCallback(
|
|
3167
|
+
(property, value2) => {
|
|
3168
|
+
const nextState = {
|
|
3169
|
+
...state,
|
|
3170
|
+
[property]: typeof value2 === "undefined" ? -1 : value2
|
|
3171
|
+
};
|
|
3172
|
+
if (readyForChange(nextState)) {
|
|
3173
|
+
onChange(toDateString(nextState, time));
|
|
3174
|
+
} else {
|
|
3175
|
+
setState(nextState);
|
|
3176
|
+
}
|
|
3177
|
+
},
|
|
3178
|
+
[state, onChange, time]
|
|
3179
|
+
);
|
|
3180
|
+
const handleClear = react.useCallback(
|
|
3181
|
+
(event) => {
|
|
3182
|
+
event.preventDefault();
|
|
3183
|
+
if (disabled || readonly) {
|
|
3184
|
+
return;
|
|
3185
|
+
}
|
|
3186
|
+
onChange(void 0);
|
|
3187
|
+
},
|
|
3188
|
+
[disabled, readonly, onChange]
|
|
3189
|
+
);
|
|
3190
|
+
const handleSetNow = react.useCallback(
|
|
3191
|
+
(event) => {
|
|
3192
|
+
event.preventDefault();
|
|
3193
|
+
if (disabled || readonly) {
|
|
3194
|
+
return;
|
|
3195
|
+
}
|
|
3196
|
+
const nextState = parseDateString((/* @__PURE__ */ new Date()).toJSON(), time);
|
|
3197
|
+
onChange(toDateString(nextState, time));
|
|
3198
|
+
},
|
|
3199
|
+
[disabled, readonly, time, onChange]
|
|
3200
|
+
);
|
|
3201
|
+
const elements = react.useMemo(
|
|
3202
|
+
() => getDateElementProps(
|
|
3203
|
+
state,
|
|
3204
|
+
time,
|
|
3205
|
+
options.yearsRange,
|
|
3206
|
+
options.format
|
|
3207
|
+
),
|
|
3208
|
+
[state, time, options.yearsRange, options.format]
|
|
3209
|
+
);
|
|
3210
|
+
return { elements, handleChange, handleClear, handleSetNow };
|
|
3211
|
+
}
|
|
3212
|
+
function useDeepCompareMemo(newValue) {
|
|
3213
|
+
const valueRef = react.useRef(newValue);
|
|
3214
|
+
if (!isEqual2(newValue, valueRef.current)) {
|
|
3215
|
+
valueRef.current = newValue;
|
|
3216
|
+
}
|
|
3217
|
+
return valueRef.current;
|
|
3218
|
+
}
|
|
3219
|
+
function addNameToDataURL(dataURL, name) {
|
|
3220
|
+
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
3221
|
+
}
|
|
3222
|
+
function processFile(file) {
|
|
3223
|
+
const { name, size, type } = file;
|
|
3224
|
+
return new Promise((resolve, reject) => {
|
|
3225
|
+
const reader = new window.FileReader();
|
|
3226
|
+
reader.onerror = reject;
|
|
3227
|
+
reader.onload = (event) => {
|
|
3228
|
+
if (typeof event.target?.result === "string") {
|
|
3229
|
+
resolve({
|
|
3230
|
+
dataURL: addNameToDataURL(event.target.result, name),
|
|
3231
|
+
name,
|
|
3232
|
+
size,
|
|
3233
|
+
type
|
|
3234
|
+
});
|
|
3235
|
+
} else {
|
|
3236
|
+
resolve({
|
|
3237
|
+
dataURL: null,
|
|
3238
|
+
name,
|
|
3239
|
+
size,
|
|
3240
|
+
type
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3243
|
+
};
|
|
3244
|
+
reader.readAsDataURL(file);
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
function processFiles(files) {
|
|
3248
|
+
return Promise.all(Array.from(files).map(processFile));
|
|
3249
|
+
}
|
|
3250
|
+
function extractFileInfo(dataURLs) {
|
|
3251
|
+
return dataURLs.reduce((acc, dataURL) => {
|
|
3252
|
+
if (!dataURL) {
|
|
3253
|
+
return acc;
|
|
3254
|
+
}
|
|
3255
|
+
try {
|
|
3256
|
+
const { blob, name } = dataURItoBlob(dataURL);
|
|
3257
|
+
return [
|
|
3258
|
+
...acc,
|
|
3259
|
+
{
|
|
3260
|
+
dataURL,
|
|
3261
|
+
name,
|
|
3262
|
+
size: blob.size,
|
|
3263
|
+
type: blob.type
|
|
3264
|
+
}
|
|
3265
|
+
];
|
|
3266
|
+
} catch {
|
|
3267
|
+
return acc;
|
|
3268
|
+
}
|
|
3269
|
+
}, []);
|
|
3270
|
+
}
|
|
3271
|
+
function useFileWidgetProps(value, onChange, multiple = false) {
|
|
3272
|
+
const values = react.useMemo(() => {
|
|
3273
|
+
if (multiple && value) {
|
|
3274
|
+
return Array.isArray(value) ? value : [value];
|
|
3275
|
+
}
|
|
3276
|
+
return [];
|
|
3277
|
+
}, [value, multiple]);
|
|
3278
|
+
const filesInfo = react.useMemo(
|
|
3279
|
+
() => Array.isArray(value) ? extractFileInfo(value) : extractFileInfo([value || ""]),
|
|
3280
|
+
[value]
|
|
3281
|
+
);
|
|
3282
|
+
const handleChange = react.useCallback(
|
|
3283
|
+
(files) => {
|
|
3284
|
+
processFiles(files).then((filesInfoEvent) => {
|
|
3285
|
+
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
|
|
3286
|
+
if (multiple) {
|
|
3287
|
+
onChange(values.concat(...newValue));
|
|
3288
|
+
} else {
|
|
3289
|
+
onChange(newValue[0]);
|
|
3290
|
+
}
|
|
3291
|
+
});
|
|
3292
|
+
},
|
|
3293
|
+
[values, multiple, onChange]
|
|
3294
|
+
);
|
|
3295
|
+
const handleRemove = react.useCallback(
|
|
3296
|
+
(index) => {
|
|
3297
|
+
if (multiple) {
|
|
3298
|
+
const newValue = values.filter((_, i) => i !== index);
|
|
3299
|
+
onChange(newValue);
|
|
3300
|
+
} else {
|
|
3301
|
+
onChange(void 0);
|
|
3302
|
+
}
|
|
3303
|
+
},
|
|
3304
|
+
[values, multiple, onChange]
|
|
3305
|
+
);
|
|
3306
|
+
return { filesInfo, handleChange, handleRemove };
|
|
3307
|
+
}
|
|
2995
3308
|
|
|
2996
3309
|
// src/utcToLocal.ts
|
|
2997
3310
|
function utcToLocal(jsonDate) {
|
|
@@ -3008,15 +3321,19 @@
|
|
|
3008
3321
|
const SSS = pad(date.getMilliseconds(), 3);
|
|
3009
3322
|
return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
|
|
3010
3323
|
}
|
|
3011
|
-
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
3324
|
+
function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
|
|
3012
3325
|
if (!additionalErrorSchema) {
|
|
3013
3326
|
return validationData;
|
|
3014
3327
|
}
|
|
3015
3328
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
3016
3329
|
let errors = toErrorList(additionalErrorSchema);
|
|
3017
3330
|
let errorSchema = additionalErrorSchema;
|
|
3018
|
-
if (!
|
|
3019
|
-
errorSchema = mergeObjects(
|
|
3331
|
+
if (!isEmpty4(oldErrorSchema)) {
|
|
3332
|
+
errorSchema = mergeObjects(
|
|
3333
|
+
oldErrorSchema,
|
|
3334
|
+
additionalErrorSchema,
|
|
3335
|
+
preventDuplicates ? "preventDuplicates" : true
|
|
3336
|
+
);
|
|
3020
3337
|
errors = [...oldErrors].concat(errors);
|
|
3021
3338
|
}
|
|
3022
3339
|
return { errorSchema, errors };
|
|
@@ -3043,27 +3360,31 @@
|
|
|
3043
3360
|
if (Array.isArray(schemaNode)) {
|
|
3044
3361
|
return withIdRefPrefixArray([...schemaNode]);
|
|
3045
3362
|
}
|
|
3046
|
-
if (
|
|
3363
|
+
if (isObject2(schemaNode)) {
|
|
3047
3364
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
3048
3365
|
}
|
|
3049
3366
|
return schemaNode;
|
|
3050
3367
|
}
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
if (
|
|
3055
|
-
return
|
|
3056
|
-
}
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3368
|
+
|
|
3369
|
+
// src/nameGenerators.ts
|
|
3370
|
+
var bracketNameGenerator = (path, idPrefix, isMultiValue) => {
|
|
3371
|
+
if (!path || path.length === 0) {
|
|
3372
|
+
return idPrefix;
|
|
3373
|
+
}
|
|
3374
|
+
const baseName = path.reduce((acc, pathUnit, index) => {
|
|
3375
|
+
if (index === 0) {
|
|
3376
|
+
return `${idPrefix}[${String(pathUnit)}]`;
|
|
3377
|
+
}
|
|
3378
|
+
return `${acc}[${String(pathUnit)}]`;
|
|
3379
|
+
}, "");
|
|
3380
|
+
return isMultiValue ? `${baseName}[]` : baseName;
|
|
3381
|
+
};
|
|
3382
|
+
var dotNotationNameGenerator = (path, idPrefix, _isMultiValue) => {
|
|
3383
|
+
if (!path || path.length === 0) {
|
|
3384
|
+
return idPrefix;
|
|
3065
3385
|
}
|
|
3066
|
-
|
|
3386
|
+
return `${idPrefix}.${path.map(String).join(".")}`;
|
|
3387
|
+
};
|
|
3067
3388
|
|
|
3068
3389
|
// src/enums.ts
|
|
3069
3390
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
@@ -3087,6 +3408,11 @@
|
|
|
3087
3408
|
TranslatableString2["PreviewLabel"] = "Preview";
|
|
3088
3409
|
TranslatableString2["DecrementAriaLabel"] = "Decrease value by 1";
|
|
3089
3410
|
TranslatableString2["IncrementAriaLabel"] = "Increase value by 1";
|
|
3411
|
+
TranslatableString2["OptionalObjectAdd"] = "Add data for optional field";
|
|
3412
|
+
TranslatableString2["OptionalObjectRemove"] = "Remove data for optional field";
|
|
3413
|
+
TranslatableString2["OptionalObjectEmptyMsg"] = "No data for optional field";
|
|
3414
|
+
TranslatableString2["Type"] = "Type";
|
|
3415
|
+
TranslatableString2["Value"] = "Value";
|
|
3090
3416
|
TranslatableString2["UnknownFieldType"] = "Unknown field type %1";
|
|
3091
3417
|
TranslatableString2["OptionPrefix"] = "Option %1";
|
|
3092
3418
|
TranslatableString2["TitleOptionPrefix"] = "%1 option %2";
|
|
@@ -3220,10 +3546,13 @@
|
|
|
3220
3546
|
exports.ALL_OF_KEY = ALL_OF_KEY;
|
|
3221
3547
|
exports.ANY_OF_KEY = ANY_OF_KEY;
|
|
3222
3548
|
exports.CONST_KEY = CONST_KEY;
|
|
3549
|
+
exports.DEFAULT_ID_PREFIX = DEFAULT_ID_PREFIX;
|
|
3550
|
+
exports.DEFAULT_ID_SEPARATOR = DEFAULT_ID_SEPARATOR;
|
|
3223
3551
|
exports.DEFAULT_KEY = DEFAULT_KEY;
|
|
3224
3552
|
exports.DEFINITIONS_KEY = DEFINITIONS_KEY;
|
|
3225
3553
|
exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
|
|
3226
3554
|
exports.DISCRIMINATOR_PATH = DISCRIMINATOR_PATH;
|
|
3555
|
+
exports.DateElement = DateElement;
|
|
3227
3556
|
exports.ENUM_KEY = ENUM_KEY;
|
|
3228
3557
|
exports.ERRORS_KEY = ERRORS_KEY;
|
|
3229
3558
|
exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
|
|
@@ -3231,6 +3560,7 @@
|
|
|
3231
3560
|
exports.ID_KEY = ID_KEY;
|
|
3232
3561
|
exports.IF_KEY = IF_KEY;
|
|
3233
3562
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
3563
|
+
exports.JSON_SCHEMA_DRAFT_2019_09 = JSON_SCHEMA_DRAFT_2019_09;
|
|
3234
3564
|
exports.JSON_SCHEMA_DRAFT_2020_12 = JSON_SCHEMA_DRAFT_2020_12;
|
|
3235
3565
|
exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
|
|
3236
3566
|
exports.LOOKUP_MAP_NAME = LOOKUP_MAP_NAME;
|
|
@@ -3253,6 +3583,7 @@
|
|
|
3253
3583
|
exports.allowAdditionalItems = allowAdditionalItems;
|
|
3254
3584
|
exports.ariaDescribedByIds = ariaDescribedByIds;
|
|
3255
3585
|
exports.asNumber = asNumber;
|
|
3586
|
+
exports.bracketNameGenerator = bracketNameGenerator;
|
|
3256
3587
|
exports.buttonId = buttonId;
|
|
3257
3588
|
exports.canExpand = canExpand;
|
|
3258
3589
|
exports.createErrorHandler = createErrorHandler;
|
|
@@ -3261,6 +3592,7 @@
|
|
|
3261
3592
|
exports.dateRangeOptions = dateRangeOptions;
|
|
3262
3593
|
exports.deepEquals = deepEquals;
|
|
3263
3594
|
exports.descriptionId = descriptionId;
|
|
3595
|
+
exports.dotNotationNameGenerator = dotNotationNameGenerator;
|
|
3264
3596
|
exports.englishStringTranslator = englishStringTranslator;
|
|
3265
3597
|
exports.enumOptionsDeselectValue = enumOptionsDeselectValue;
|
|
3266
3598
|
exports.enumOptionsIndexForValue = enumOptionsIndexForValue;
|
|
@@ -3298,8 +3630,10 @@
|
|
|
3298
3630
|
exports.isCustomWidget = isCustomWidget;
|
|
3299
3631
|
exports.isFilesArray = isFilesArray;
|
|
3300
3632
|
exports.isFixedItems = isFixedItems;
|
|
3633
|
+
exports.isFormDataAvailable = isFormDataAvailable;
|
|
3301
3634
|
exports.isMultiSelect = isMultiSelect;
|
|
3302
3635
|
exports.isObject = isObject;
|
|
3636
|
+
exports.isRootSchema = isRootSchema;
|
|
3303
3637
|
exports.isSelect = isSelect;
|
|
3304
3638
|
exports.labelValue = labelValue;
|
|
3305
3639
|
exports.localToUTC = localToUTC;
|
|
@@ -3308,6 +3642,7 @@
|
|
|
3308
3642
|
exports.mergeObjects = mergeObjects;
|
|
3309
3643
|
exports.mergeSchemas = mergeSchemas;
|
|
3310
3644
|
exports.optionId = optionId;
|
|
3645
|
+
exports.optionalControlsId = optionalControlsId;
|
|
3311
3646
|
exports.optionsList = optionsList;
|
|
3312
3647
|
exports.orderProperties = orderProperties;
|
|
3313
3648
|
exports.pad = pad;
|
|
@@ -3318,16 +3653,21 @@
|
|
|
3318
3653
|
exports.sanitizeDataForNewSchema = sanitizeDataForNewSchema;
|
|
3319
3654
|
exports.schemaParser = schemaParser;
|
|
3320
3655
|
exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
|
|
3656
|
+
exports.shallowEquals = shallowEquals;
|
|
3321
3657
|
exports.shouldRender = shouldRender;
|
|
3658
|
+
exports.shouldRenderOptionalField = shouldRenderOptionalField;
|
|
3322
3659
|
exports.sortedJSONStringify = sortedJSONStringify;
|
|
3323
3660
|
exports.titleId = titleId;
|
|
3324
3661
|
exports.toConstant = toConstant;
|
|
3325
3662
|
exports.toDateString = toDateString;
|
|
3326
3663
|
exports.toErrorList = toErrorList;
|
|
3327
3664
|
exports.toErrorSchema = toErrorSchema;
|
|
3328
|
-
exports.
|
|
3665
|
+
exports.toFieldPathId = toFieldPathId;
|
|
3329
3666
|
exports.toPathSchema = toPathSchema;
|
|
3330
3667
|
exports.unwrapErrorHandler = unwrapErrorHandler;
|
|
3668
|
+
exports.useAltDateWidgetProps = useAltDateWidgetProps;
|
|
3669
|
+
exports.useDeepCompareMemo = useDeepCompareMemo;
|
|
3670
|
+
exports.useFileWidgetProps = useFileWidgetProps;
|
|
3331
3671
|
exports.utcToLocal = utcToLocal;
|
|
3332
3672
|
exports.validationDataMerge = validationDataMerge;
|
|
3333
3673
|
exports.withIdRefPrefix = withIdRefPrefix;
|