@rjsf/core 5.24.10 → 6.0.0-beta.1
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 +982 -196
- package/dist/index.esm.js +1366 -490
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +1452 -616
- package/dist/index.js.map +4 -4
- package/lib/components/Form.d.ts +0 -7
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +2 -5
- package/lib/components/fields/ArrayField.d.ts +19 -9
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +22 -12
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +3 -9
- package/lib/components/fields/LayoutGridField.d.ts +480 -0
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -0
- package/lib/components/fields/LayoutGridField.js +711 -0
- package/lib/components/fields/LayoutHeaderField.d.ts +12 -0
- package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -0
- package/lib/components/fields/LayoutHeaderField.js +23 -0
- package/lib/components/fields/LayoutMultiSchemaField.d.ts +28 -0
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -0
- package/lib/components/fields/LayoutMultiSchemaField.js +114 -0
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +29 -23
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +2 -8
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +6 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +17 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +7 -5
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +3 -3
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js +4 -4
- package/lib/components/templates/GridTemplate.d.ts +8 -0
- package/lib/components/templates/GridTemplate.d.ts.map +1 -0
- package/lib/components/templates/GridTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js +9 -4
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +4 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +1 -1
- package/lib/components/widgets/RadioWidget.js +3 -3
- package/lib/components/widgets/RatingWidget.d.ts +15 -0
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -0
- package/lib/components/widgets/RatingWidget.js +63 -0
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +4 -4
- package/lib/components/widgets/index.d.ts.map +1 -1
- package/lib/components/widgets/index.js +2 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.d.ts.map +1 -1
- package/lib/withTheme.js +1 -0
- package/package.json +44 -35
- package/src/components/Form.tsx +24 -30
- package/src/components/fields/ArrayField.tsx +34 -24
- package/src/components/fields/BooleanField.tsx +6 -14
- package/src/components/fields/LayoutGridField.tsx +967 -0
- package/src/components/fields/LayoutHeaderField.tsx +49 -0
- package/src/components/fields/LayoutMultiSchemaField.tsx +228 -0
- package/src/components/fields/NullField.tsx +1 -1
- package/src/components/fields/NumberField.tsx +2 -2
- package/src/components/fields/ObjectField.tsx +32 -28
- package/src/components/fields/SchemaField.tsx +14 -22
- package/src/components/fields/StringField.tsx +2 -2
- package/src/components/fields/index.ts +7 -1
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -2
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +85 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +18 -57
- package/src/components/templates/ArrayFieldTemplate.tsx +10 -8
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -2
- package/src/components/templates/BaseInputTemplate.tsx +4 -4
- package/src/components/templates/ButtonTemplates/IconButton.tsx +9 -36
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +1 -1
- package/src/components/templates/ButtonTemplates/index.ts +1 -1
- package/src/components/templates/DescriptionField.tsx +1 -1
- package/src/components/templates/FieldErrorTemplate.tsx +1 -1
- package/src/components/templates/FieldHelpTemplate.tsx +1 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -2
- package/src/components/templates/GridTemplate.tsx +15 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -3
- package/src/components/templates/TitleField.tsx +1 -1
- package/src/components/templates/UnsupportedField.tsx +1 -1
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +14 -4
- package/src/components/templates/index.ts +4 -0
- package/src/components/widgets/AltDateWidget.tsx +9 -6
- package/src/components/widgets/CheckboxWidget.tsx +4 -4
- package/src/components/widgets/CheckboxesWidget.tsx +2 -2
- package/src/components/widgets/ColorWidget.tsx +1 -1
- package/src/components/widgets/DateTimeWidget.tsx +1 -1
- package/src/components/widgets/DateWidget.tsx +1 -1
- package/src/components/widgets/EmailWidget.tsx +1 -1
- package/src/components/widgets/FileWidget.tsx +4 -4
- package/src/components/widgets/PasswordWidget.tsx +1 -1
- package/src/components/widgets/RadioWidget.tsx +3 -3
- package/src/components/widgets/RangeWidget.tsx +1 -1
- package/src/components/widgets/RatingWidget.tsx +129 -0
- package/src/components/widgets/SelectWidget.tsx +4 -3
- package/src/components/widgets/TextWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +3 -3
- package/src/components/widgets/TimeWidget.tsx +1 -1
- package/src/components/widgets/URLWidget.tsx +1 -1
- package/src/components/widgets/UpDownWidget.tsx +1 -1
- package/src/components/widgets/index.ts +3 -1
- package/src/getDefaultRegistry.ts +1 -1
- package/src/tsconfig.json +0 -3
- package/src/withTheme.tsx +4 -3
- package/LICENSE.md +0 -201
package/dist/core.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/forEach'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/isNil'), require('lodash/pick'), require('lodash/toPath'), require('lodash/cloneDeep'), require('lodash/isObject'), require('lodash/set'), require('nanoid'), require('react/jsx-runtime'), require('lodash/
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/forEach', 'lodash/get', 'lodash/isEmpty', 'lodash/isNil', 'lodash/pick', 'lodash/toPath', 'lodash/cloneDeep', 'lodash/isObject', 'lodash/set', 'nanoid', 'react/jsx-runtime', 'lodash/
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global._forEach, global.
|
|
5
|
-
})(this, (function (exports, react, utils, _forEach,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('lodash/forEach'), require('lodash/get'), require('lodash/isEmpty'), require('lodash/isNil'), require('lodash/pick'), require('lodash/toPath'), require('lodash/cloneDeep'), require('lodash/isObject'), require('lodash/set'), require('nanoid'), require('react/jsx-runtime'), require('lodash/each'), require('lodash/flatten'), require('lodash/has'), require('lodash/includes'), require('lodash/intersection'), require('lodash/isFunction'), require('lodash/isEqual'), require('lodash/isPlainObject'), require('lodash/isString'), require('lodash/isUndefined'), require('lodash/noop'), require('lodash/omit'), require('markdown-to-jsx'), require('lodash/unset')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'lodash/forEach', 'lodash/get', 'lodash/isEmpty', 'lodash/isNil', 'lodash/pick', 'lodash/toPath', 'lodash/cloneDeep', 'lodash/isObject', 'lodash/set', 'nanoid', 'react/jsx-runtime', 'lodash/each', 'lodash/flatten', 'lodash/has', 'lodash/includes', 'lodash/intersection', 'lodash/isFunction', 'lodash/isEqual', 'lodash/isPlainObject', 'lodash/isString', 'lodash/isUndefined', 'lodash/noop', 'lodash/omit', 'markdown-to-jsx', 'lodash/unset'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global._forEach, global.get2, global.isEmpty, global._isNil, global._pick, global._toPath, global.cloneDeep2, global.isObject, global.set, global.nanoid, global.jsxRuntime, global.each, global.flatten, global.has, global.includes, global.intersection, global.isFunction, global.isEqual, global.isPlainObject, global.isString, global.isUndefined, global.noop, global.omit3, global.Markdown, global.unset));
|
|
5
|
+
})(this, (function (exports, react, utils, _forEach, get2, isEmpty, _isNil, _pick, _toPath, cloneDeep2, isObject, set, nanoid, jsxRuntime, each, flatten, has, includes, intersection, isFunction, isEqual, isPlainObject, isString, isUndefined, noop, omit3, Markdown, unset) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/components/Form.tsx
|
|
8
8
|
function generateRowId() {
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
get itemTitle() {
|
|
67
67
|
const { schema, registry } = this.props;
|
|
68
68
|
const { translateString } = registry;
|
|
69
|
-
return
|
|
69
|
+
return get2(
|
|
70
70
|
schema,
|
|
71
71
|
[utils.ITEMS_KEY, "title"],
|
|
72
|
-
|
|
72
|
+
get2(schema, [utils.ITEMS_KEY, "description"], translateString(utils.TranslatableString.ArrayItemTitle))
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
/** Determines whether the item described in the schema is always required, which is determined by whether any item
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
}
|
|
206
206
|
const newKeyedFormDataRow = {
|
|
207
207
|
key: generateRowId(),
|
|
208
|
-
item:
|
|
208
|
+
item: cloneDeep2(keyedFormData[index].item)
|
|
209
209
|
};
|
|
210
210
|
const newKeyedFormData = [...keyedFormData];
|
|
211
211
|
if (index !== void 0) {
|
|
@@ -423,7 +423,7 @@
|
|
|
423
423
|
totalItems: keyedFormData.length
|
|
424
424
|
});
|
|
425
425
|
}),
|
|
426
|
-
className: `field field-array field-array-of-${itemsSchema.type}`,
|
|
426
|
+
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}`,
|
|
427
427
|
disabled,
|
|
428
428
|
idSchema,
|
|
429
429
|
uiSchema,
|
|
@@ -631,7 +631,7 @@
|
|
|
631
631
|
const canAdd = this.canAddItem(items) && !!additionalSchema;
|
|
632
632
|
const arrayProps = {
|
|
633
633
|
canAdd,
|
|
634
|
-
className: "field field-array field-array-fixed-items",
|
|
634
|
+
className: "rjsf-field rjsf-field-array rjsf-field-array-fixed-items",
|
|
635
635
|
disabled,
|
|
636
636
|
idSchema,
|
|
637
637
|
formData,
|
|
@@ -712,14 +712,14 @@
|
|
|
712
712
|
} = registry;
|
|
713
713
|
const ItemSchemaField = ArraySchemaField || SchemaField2;
|
|
714
714
|
const { orderable = true, removable = true, copyable = false } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
715
|
-
const
|
|
715
|
+
const has4 = {
|
|
716
716
|
moveUp: orderable && canMoveUp,
|
|
717
717
|
moveDown: orderable && canMoveDown,
|
|
718
718
|
copy: copyable && canAdd,
|
|
719
719
|
remove: removable && canRemove,
|
|
720
720
|
toolbar: false
|
|
721
721
|
};
|
|
722
|
-
|
|
722
|
+
has4.toolbar = Object.keys(has4).some((key2) => has4[key2]);
|
|
723
723
|
return {
|
|
724
724
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
725
725
|
ItemSchemaField,
|
|
@@ -747,21 +747,31 @@
|
|
|
747
747
|
rawErrors
|
|
748
748
|
}
|
|
749
749
|
),
|
|
750
|
-
|
|
750
|
+
buttonsProps: {
|
|
751
|
+
idSchema: itemIdSchema,
|
|
752
|
+
disabled,
|
|
753
|
+
readonly,
|
|
754
|
+
canAdd,
|
|
755
|
+
hasCopy: has4.copy,
|
|
756
|
+
hasMoveUp: has4.moveUp,
|
|
757
|
+
hasMoveDown: has4.moveDown,
|
|
758
|
+
hasRemove: has4.remove,
|
|
759
|
+
index,
|
|
760
|
+
totalItems,
|
|
761
|
+
onAddIndexClick: this.onAddIndexClick,
|
|
762
|
+
onCopyIndexClick: this.onCopyIndexClick,
|
|
763
|
+
onDropIndexClick: this.onDropIndexClick,
|
|
764
|
+
onReorderClick: this.onReorderClick,
|
|
765
|
+
registry,
|
|
766
|
+
schema: itemSchema,
|
|
767
|
+
uiSchema: itemUiSchema
|
|
768
|
+
},
|
|
769
|
+
className: "rjsf-array-item",
|
|
751
770
|
disabled,
|
|
752
|
-
|
|
753
|
-
hasCopy: has2.copy,
|
|
754
|
-
hasToolbar: has2.toolbar,
|
|
755
|
-
hasMoveUp: has2.moveUp,
|
|
756
|
-
hasMoveDown: has2.moveDown,
|
|
757
|
-
hasRemove: has2.remove,
|
|
771
|
+
hasToolbar: has4.toolbar,
|
|
758
772
|
index,
|
|
759
773
|
totalItems,
|
|
760
774
|
key,
|
|
761
|
-
onAddIndexClick: this.onAddIndexClick,
|
|
762
|
-
onCopyIndexClick: this.onCopyIndexClick,
|
|
763
|
-
onDropIndexClick: this.onDropIndexClick,
|
|
764
|
-
onReorderClick: this.onReorderClick,
|
|
765
775
|
readonly,
|
|
766
776
|
registry,
|
|
767
777
|
schema: itemSchema,
|
|
@@ -796,6 +806,7 @@
|
|
|
796
806
|
title: uiTitle,
|
|
797
807
|
// Unlike the other fields, don't use `getDisplayLabel()` since it always returns false for the boolean type
|
|
798
808
|
label: displayLabel = true,
|
|
809
|
+
enumNames,
|
|
799
810
|
...options
|
|
800
811
|
} = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
801
812
|
const Widget = utils.getWidget(schema, widget, widgets2);
|
|
@@ -820,9 +831,8 @@
|
|
|
820
831
|
uiSchema
|
|
821
832
|
);
|
|
822
833
|
} else {
|
|
823
|
-
const schemaWithEnumNames = schema;
|
|
824
834
|
const enums = schema.enum ?? [true, false];
|
|
825
|
-
if (!
|
|
835
|
+
if (!enumNames && enums.length === 2 && enums.every((v) => typeof v === "boolean")) {
|
|
826
836
|
enumOptions = [
|
|
827
837
|
{
|
|
828
838
|
value: enums[0],
|
|
@@ -834,14 +844,7 @@
|
|
|
834
844
|
}
|
|
835
845
|
];
|
|
836
846
|
} else {
|
|
837
|
-
enumOptions = utils.optionsList(
|
|
838
|
-
{
|
|
839
|
-
enum: enums,
|
|
840
|
-
// NOTE: enumNames is deprecated, but still supported for now.
|
|
841
|
-
enumNames: schemaWithEnumNames.enumNames
|
|
842
|
-
},
|
|
843
|
-
uiSchema
|
|
844
|
-
);
|
|
847
|
+
enumOptions = utils.optionsList({ enum: enums }, uiSchema);
|
|
845
848
|
}
|
|
846
849
|
}
|
|
847
850
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -870,6 +873,688 @@
|
|
|
870
873
|
);
|
|
871
874
|
}
|
|
872
875
|
var BooleanField_default = BooleanField;
|
|
876
|
+
var LOOKUP_REGEX = /^\$lookup=(.+)/;
|
|
877
|
+
var LAYOUT_GRID_UI_OPTION = "layoutGrid";
|
|
878
|
+
var UI_GLOBAL_OPTIONS = "ui:global_options";
|
|
879
|
+
function getNonNullishValue(value, fallback) {
|
|
880
|
+
return value ?? fallback;
|
|
881
|
+
}
|
|
882
|
+
var LayoutGridField = class _LayoutGridField extends react.PureComponent {
|
|
883
|
+
static defaultProps = {
|
|
884
|
+
layoutGridSchema: void 0
|
|
885
|
+
};
|
|
886
|
+
static TEST_IDS = utils.getTestIds();
|
|
887
|
+
/** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
|
|
888
|
+
* will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
|
|
889
|
+
* copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
|
|
890
|
+
* updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
|
|
891
|
+
* the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
|
|
892
|
+
* field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
|
|
893
|
+
*
|
|
894
|
+
* @param field - The name of the field to pull the existing UI Schema for
|
|
895
|
+
* @param uiProps - Any props that should be put into the field's uiSchema
|
|
896
|
+
* @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
|
|
897
|
+
* @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
|
|
898
|
+
* @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
|
|
899
|
+
*/
|
|
900
|
+
static computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
|
|
901
|
+
const globalUiOptions = get2(uiSchema, [UI_GLOBAL_OPTIONS], {});
|
|
902
|
+
const localUiSchema = get2(uiSchema, field);
|
|
903
|
+
const localUiOptions = { ...get2(localUiSchema, [utils.UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
|
|
904
|
+
const fieldUiSchema = { ...localUiSchema };
|
|
905
|
+
if (!isEmpty(localUiOptions)) {
|
|
906
|
+
set(fieldUiSchema, [utils.UI_OPTIONS_KEY], localUiOptions);
|
|
907
|
+
}
|
|
908
|
+
if (!isEmpty(globalUiOptions)) {
|
|
909
|
+
set(fieldUiSchema, [UI_GLOBAL_OPTIONS], globalUiOptions);
|
|
910
|
+
}
|
|
911
|
+
let { readonly: uiReadonly } = utils.getUiOptions(fieldUiSchema);
|
|
912
|
+
if (forceReadonly === true || isUndefined(uiReadonly) && schemaReadonly === true) {
|
|
913
|
+
uiReadonly = true;
|
|
914
|
+
if (has(localUiOptions, utils.READONLY_KEY)) {
|
|
915
|
+
set(fieldUiSchema, [utils.UI_OPTIONS_KEY, utils.READONLY_KEY], true);
|
|
916
|
+
} else {
|
|
917
|
+
set(fieldUiSchema, `ui:${utils.READONLY_KEY}`, true);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return { fieldUiSchema, uiReadonly };
|
|
921
|
+
}
|
|
922
|
+
/** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
|
|
923
|
+
* depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
|
|
924
|
+
* contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
|
|
925
|
+
* equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
|
|
926
|
+
* common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
|
|
927
|
+
* to match.
|
|
928
|
+
*
|
|
929
|
+
* @param [operator] - The optional operator for the condition
|
|
930
|
+
* @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
|
|
931
|
+
* @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
|
|
932
|
+
* to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
|
|
933
|
+
* This can be an item or a list of items of type unknown
|
|
934
|
+
* @returns - True if the condition matches, false otherwise
|
|
935
|
+
*/
|
|
936
|
+
static conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
|
|
937
|
+
const data = flatten([datum]).sort();
|
|
938
|
+
const values = flatten([value]).sort();
|
|
939
|
+
switch (operator) {
|
|
940
|
+
case "all" /* ALL */:
|
|
941
|
+
return isEqual(data, values);
|
|
942
|
+
case "some" /* SOME */:
|
|
943
|
+
return intersection(data, values).length > 0;
|
|
944
|
+
case "none" /* NONE */:
|
|
945
|
+
return intersection(data, values).length === 0;
|
|
946
|
+
default:
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
/** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
|
|
951
|
+
* `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
|
|
952
|
+
* lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
|
|
953
|
+
* When the `className` value contains multiple classNames separated by a space, the lookup will look for a
|
|
954
|
+
* replacement value for each `className` and combine them into one.
|
|
955
|
+
*
|
|
956
|
+
* @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
|
|
957
|
+
* @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
|
|
958
|
+
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
959
|
+
* @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
|
|
960
|
+
* @throws - A `TypeError` when the `children` is not an array
|
|
961
|
+
*/
|
|
962
|
+
static findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
|
|
963
|
+
let gridProps = {};
|
|
964
|
+
let children = layoutGridSchema[schemaKey];
|
|
965
|
+
if (isPlainObject(children)) {
|
|
966
|
+
const { children: elements, className: toMapClassNames, ...otherProps } = children;
|
|
967
|
+
children = elements;
|
|
968
|
+
if (toMapClassNames) {
|
|
969
|
+
const classes = toMapClassNames.split(" ");
|
|
970
|
+
const className = classes.map((ele) => utils.lookupFromFormContext(registry, ele, ele)).join(" ");
|
|
971
|
+
gridProps = { ...otherProps, className };
|
|
972
|
+
} else {
|
|
973
|
+
gridProps = otherProps;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (!Array.isArray(children)) {
|
|
977
|
+
throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
|
|
978
|
+
}
|
|
979
|
+
return { children, gridProps };
|
|
980
|
+
}
|
|
981
|
+
/** Generates an idSchema for the `schema` using `@rjsf`'s `toIdSchema` util, passing the `baseIdSchema`'s `$id` value
|
|
982
|
+
* as the id prefix.
|
|
983
|
+
*
|
|
984
|
+
* @param schemaUtils - The `SchemaUtilsType` used to call `toIdSchema`
|
|
985
|
+
* @param schema - The schema to generate the idSchema for
|
|
986
|
+
* @param baseIdSchema - The IdSchema for the base
|
|
987
|
+
* @param formData - The formData to pass the `toIdSchema`
|
|
988
|
+
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
989
|
+
* @returns - The generated `idSchema` for the `schema`
|
|
990
|
+
*/
|
|
991
|
+
static getIdSchema(schemaUtils, baseIdSchema, formData, schema = {}, idSeparator) {
|
|
992
|
+
const baseId = get2(baseIdSchema, utils.ID_KEY);
|
|
993
|
+
return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
|
|
994
|
+
}
|
|
995
|
+
/** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
|
|
996
|
+
* the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
|
|
997
|
+
* element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
|
|
998
|
+
* `options`.
|
|
999
|
+
*
|
|
1000
|
+
* @param schemaUtils - The `SchemaUtilsType` used to call `retrieveSchema`
|
|
1001
|
+
* @param dottedPath - The dotted-path to the field for which to get the schema
|
|
1002
|
+
* @param initialSchema - The initial schema to start the search from
|
|
1003
|
+
* @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
|
|
1004
|
+
* @param initialIdSchema - The initial idSchema to start the search from
|
|
1005
|
+
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
1006
|
+
* @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
|
|
1007
|
+
* info if a oneOf/anyOf
|
|
1008
|
+
*/
|
|
1009
|
+
static getSchemaDetailsForField(schemaUtils, dottedPath, initialSchema, formData, initialIdSchema, idSeparator) {
|
|
1010
|
+
let rawSchema = initialSchema;
|
|
1011
|
+
let idSchema = initialIdSchema;
|
|
1012
|
+
const parts = dottedPath.split(".");
|
|
1013
|
+
const leafPath = parts.pop();
|
|
1014
|
+
let schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1015
|
+
let innerData = formData;
|
|
1016
|
+
let isReadonly = schema.readOnly;
|
|
1017
|
+
parts.forEach((part) => {
|
|
1018
|
+
if (has(schema, utils.PROPERTIES_KEY)) {
|
|
1019
|
+
rawSchema = get2(schema, [utils.PROPERTIES_KEY, part], {});
|
|
1020
|
+
idSchema = get2(idSchema, part, {});
|
|
1021
|
+
} else if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1022
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1023
|
+
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
|
|
1024
|
+
const selectedIdSchema = _LayoutGridField.getIdSchema(
|
|
1025
|
+
schemaUtils,
|
|
1026
|
+
idSchema,
|
|
1027
|
+
formData,
|
|
1028
|
+
selectedSchema,
|
|
1029
|
+
idSeparator
|
|
1030
|
+
);
|
|
1031
|
+
rawSchema = get2(selectedSchema, [utils.PROPERTIES_KEY, part], {});
|
|
1032
|
+
idSchema = get2(selectedIdSchema, part, {});
|
|
1033
|
+
} else {
|
|
1034
|
+
rawSchema = {};
|
|
1035
|
+
}
|
|
1036
|
+
innerData = get2(innerData, part, {});
|
|
1037
|
+
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
1038
|
+
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
|
|
1039
|
+
});
|
|
1040
|
+
let optionsInfo;
|
|
1041
|
+
let isRequired = false;
|
|
1042
|
+
if (isEmpty(schema)) {
|
|
1043
|
+
schema = void 0;
|
|
1044
|
+
}
|
|
1045
|
+
if (schema && leafPath) {
|
|
1046
|
+
if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1047
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1048
|
+
schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
|
|
1049
|
+
const rawIdSchema = _LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, schema, idSeparator);
|
|
1050
|
+
idSchema = utils.mergeObjects(rawIdSchema, idSchema);
|
|
1051
|
+
}
|
|
1052
|
+
isRequired = schema !== void 0 && Array.isArray(schema.required) && includes(schema.required, leafPath);
|
|
1053
|
+
schema = get2(schema, [utils.PROPERTIES_KEY, leafPath]);
|
|
1054
|
+
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1055
|
+
idSchema = get2(idSchema, leafPath, {});
|
|
1056
|
+
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1057
|
+
if (schema && (has(schema, utils.ONE_OF_KEY) || has(schema, utils.ANY_OF_KEY))) {
|
|
1058
|
+
const xxx = has(schema, utils.ONE_OF_KEY) ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1059
|
+
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1060
|
+
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return { schema, isRequired, isReadonly, optionsInfo, idSchema };
|
|
1064
|
+
}
|
|
1065
|
+
/** Gets the custom render component from the `render`, by either determining that it is either already a function or
|
|
1066
|
+
* it is a non-function value that can be used to look up the function in the registry. If no function can be found,
|
|
1067
|
+
* null is returned.
|
|
1068
|
+
*
|
|
1069
|
+
* @param render - The potential render function or lookup name to one
|
|
1070
|
+
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
1071
|
+
* @returns - Either a render function if available, or null if not
|
|
1072
|
+
*/
|
|
1073
|
+
static getCustomRenderComponent(render, registry) {
|
|
1074
|
+
let customRenderer = render;
|
|
1075
|
+
if (isString(customRenderer)) {
|
|
1076
|
+
customRenderer = utils.lookupFromFormContext(registry, customRenderer);
|
|
1077
|
+
}
|
|
1078
|
+
if (isFunction(customRenderer)) {
|
|
1079
|
+
return customRenderer;
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
/** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
|
|
1084
|
+
* see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
|
|
1085
|
+
* set the `rendered` component with only specified props for that component in the object.
|
|
1086
|
+
*
|
|
1087
|
+
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
1088
|
+
* @param gridSchema - The string or object that represents the configuration for the grid field
|
|
1089
|
+
* @returns - The UIComponentPropsType computed from the gridSchema
|
|
1090
|
+
*/
|
|
1091
|
+
static computeUIComponentPropsFromGridSchema(registry, gridSchema) {
|
|
1092
|
+
let name;
|
|
1093
|
+
let UIComponent = null;
|
|
1094
|
+
let uiProps = {};
|
|
1095
|
+
let rendered;
|
|
1096
|
+
if (isString(gridSchema) || isUndefined(gridSchema)) {
|
|
1097
|
+
name = gridSchema ?? "";
|
|
1098
|
+
} else {
|
|
1099
|
+
const { name: innerName, render, ...innerProps } = gridSchema;
|
|
1100
|
+
name = innerName;
|
|
1101
|
+
uiProps = innerProps;
|
|
1102
|
+
if (!isEmpty(uiProps)) {
|
|
1103
|
+
each(uiProps, (prop, key) => {
|
|
1104
|
+
if (isString(prop)) {
|
|
1105
|
+
const match = LOOKUP_REGEX.exec(prop);
|
|
1106
|
+
if (Array.isArray(match) && match.length > 1) {
|
|
1107
|
+
const name2 = match[1];
|
|
1108
|
+
uiProps[key] = utils.lookupFromFormContext(registry, name2, name2);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
UIComponent = _LayoutGridField.getCustomRenderComponent(render, registry);
|
|
1114
|
+
if (!innerName && UIComponent) {
|
|
1115
|
+
rendered = /* @__PURE__ */ jsxRuntime.jsx(UIComponent, { ...innerProps, "data-testid": _LayoutGridField.TEST_IDS.uiComponent });
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return { name, UIComponent, uiProps, rendered };
|
|
1119
|
+
}
|
|
1120
|
+
/** Constructs an `LayoutGridField` with the given `props`
|
|
1121
|
+
*
|
|
1122
|
+
* @param props - The `LayoutGridField` for this template
|
|
1123
|
+
*/
|
|
1124
|
+
constructor(props) {
|
|
1125
|
+
super(props);
|
|
1126
|
+
}
|
|
1127
|
+
/** Generates an `onChange` handler for the field associated with the `dottedPath`. This handler will clone and update
|
|
1128
|
+
* the `formData` with the new `value` and the `errorSchema` if an `errSchema` is provided. After updating those two
|
|
1129
|
+
* elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
|
|
1130
|
+
*
|
|
1131
|
+
* @param dottedPath - The dotted-path to the field for which to generate the onChange handler
|
|
1132
|
+
* @returns - The `onChange` handling function for the `dottedPath` field
|
|
1133
|
+
*/
|
|
1134
|
+
onFieldChange = (dottedPath) => {
|
|
1135
|
+
return (value, errSchema, id) => {
|
|
1136
|
+
const { onChange, errorSchema, formData } = this.props;
|
|
1137
|
+
const newFormData = cloneDeep2(formData || {});
|
|
1138
|
+
let newErrorSchema = errorSchema;
|
|
1139
|
+
if (errSchema && errorSchema) {
|
|
1140
|
+
newErrorSchema = cloneDeep2(errorSchema);
|
|
1141
|
+
set(newErrorSchema, dottedPath, errSchema);
|
|
1142
|
+
}
|
|
1143
|
+
set(newFormData, dottedPath, value);
|
|
1144
|
+
onChange(newFormData, newErrorSchema, id);
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1147
|
+
/** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
|
|
1148
|
+
* `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
|
|
1149
|
+
* the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
|
|
1150
|
+
* rendered, otherwise null is returned.
|
|
1151
|
+
*
|
|
1152
|
+
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1153
|
+
* @returns - The rendered the children for the `GridType.CONDITION` or null
|
|
1154
|
+
*/
|
|
1155
|
+
renderCondition(layoutGridSchema) {
|
|
1156
|
+
const { formData, registry } = this.props;
|
|
1157
|
+
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1158
|
+
layoutGridSchema,
|
|
1159
|
+
"ui:condition" /* CONDITION */,
|
|
1160
|
+
registry
|
|
1161
|
+
);
|
|
1162
|
+
const { operator, field = "", value } = gridProps;
|
|
1163
|
+
const fieldData = get2(formData, field, null);
|
|
1164
|
+
if (_LayoutGridField.conditionMatches(operator, fieldData, value)) {
|
|
1165
|
+
return this.renderChildren(children);
|
|
1166
|
+
}
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
/** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated
|
|
1170
|
+
* into the `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside
|
|
1171
|
+
* the `GridTemplate` all the `children` are rendered.
|
|
1172
|
+
*
|
|
1173
|
+
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1174
|
+
* @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
|
|
1175
|
+
*/
|
|
1176
|
+
renderCol(layoutGridSchema) {
|
|
1177
|
+
const { registry, uiSchema } = this.props;
|
|
1178
|
+
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1179
|
+
layoutGridSchema,
|
|
1180
|
+
"ui:col" /* COLUMN */,
|
|
1181
|
+
registry
|
|
1182
|
+
);
|
|
1183
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1184
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1185
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GridTemplate2, { column: true, "data-testid": _LayoutGridField.TEST_IDS.col, ...gridProps, children: this.renderChildren(children) });
|
|
1186
|
+
}
|
|
1187
|
+
/** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated
|
|
1188
|
+
* into the `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the
|
|
1189
|
+
* outer `GridTemplate`. Each child will have their own rendered `GridTemplate`.
|
|
1190
|
+
*
|
|
1191
|
+
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1192
|
+
* @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
|
|
1193
|
+
*/
|
|
1194
|
+
renderColumns(layoutGridSchema) {
|
|
1195
|
+
const { registry, uiSchema } = this.props;
|
|
1196
|
+
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1197
|
+
layoutGridSchema,
|
|
1198
|
+
"ui:columns" /* COLUMNS */,
|
|
1199
|
+
registry
|
|
1200
|
+
);
|
|
1201
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1202
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1203
|
+
return children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1204
|
+
GridTemplate2,
|
|
1205
|
+
{
|
|
1206
|
+
column: true,
|
|
1207
|
+
"data-testid": _LayoutGridField.TEST_IDS.col,
|
|
1208
|
+
...gridProps,
|
|
1209
|
+
children: this.renderChildren([child])
|
|
1210
|
+
},
|
|
1211
|
+
`column-${utils.hashObject(child)}`
|
|
1212
|
+
));
|
|
1213
|
+
}
|
|
1214
|
+
/** Renders a material-ui `GridTemplate` as a container. The
|
|
1215
|
+
* `layoutGridSchema` for the `GridType.ROW` is separated into the `children` and other `gridProps`. The `gridProps`
|
|
1216
|
+
* will be spread onto the outer `GridTemplate`. Inside of the `GridTemplate` all of the `children` are rendered.
|
|
1217
|
+
*
|
|
1218
|
+
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1219
|
+
* @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
|
|
1220
|
+
*/
|
|
1221
|
+
renderRow(layoutGridSchema) {
|
|
1222
|
+
const { registry, uiSchema } = this.props;
|
|
1223
|
+
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1224
|
+
layoutGridSchema,
|
|
1225
|
+
"ui:row" /* ROW */,
|
|
1226
|
+
registry
|
|
1227
|
+
);
|
|
1228
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1229
|
+
const GridTemplate2 = utils.getTemplate("GridTemplate", registry, uiOptions);
|
|
1230
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GridTemplate2, { ...gridProps, "data-testid": _LayoutGridField.TEST_IDS.row, children: this.renderChildren(children) });
|
|
1231
|
+
}
|
|
1232
|
+
/** Iterates through all the `childrenLayoutGridSchema`, rendering a nested `LayoutGridField` for each item in the
|
|
1233
|
+
* list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
|
|
1234
|
+
* `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
|
|
1235
|
+
* `childrenLayoutGridSchema` is passed as `layoutGridSchema`.
|
|
1236
|
+
*
|
|
1237
|
+
* @param childrenLayoutGridSchema - The list of strings or objects that represents the configurations for the
|
|
1238
|
+
* children fields
|
|
1239
|
+
* @returns - The nested `LayoutGridField`s
|
|
1240
|
+
*/
|
|
1241
|
+
renderChildren(childrenLayoutGridSchema) {
|
|
1242
|
+
const { registry, schema: rawSchema, formData } = this.props;
|
|
1243
|
+
const { schemaUtils } = registry;
|
|
1244
|
+
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1245
|
+
return childrenLayoutGridSchema.map((layoutGridSchema) => /* @__PURE__ */ react.createElement(
|
|
1246
|
+
_LayoutGridField,
|
|
1247
|
+
{
|
|
1248
|
+
...this.props,
|
|
1249
|
+
key: `layoutGrid-${utils.hashObject(layoutGridSchema)}`,
|
|
1250
|
+
schema,
|
|
1251
|
+
layoutGridSchema
|
|
1252
|
+
}
|
|
1253
|
+
));
|
|
1254
|
+
}
|
|
1255
|
+
/** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
|
|
1256
|
+
* to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
|
|
1257
|
+
* other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
|
|
1258
|
+
* specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
|
|
1259
|
+
* and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
|
|
1260
|
+
* schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
|
|
1261
|
+
* `uiSchema`, `errorSchema`, `idSchema` and `formData` drilled down to the dotted-path field, spreading any other
|
|
1262
|
+
* props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
|
|
1263
|
+
* then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
|
|
1264
|
+
* schema was located, but a custom render component was found, then it will be rendered with many of the non-event
|
|
1265
|
+
* handling props. If none of the previous render paths are valid, then a null is returned.
|
|
1266
|
+
*
|
|
1267
|
+
* @param gridSchema - The string or object that represents the configuration for the grid field
|
|
1268
|
+
* @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
|
|
1269
|
+
*/
|
|
1270
|
+
renderField(gridSchema) {
|
|
1271
|
+
const {
|
|
1272
|
+
schema: initialSchema,
|
|
1273
|
+
uiSchema,
|
|
1274
|
+
errorSchema,
|
|
1275
|
+
idSchema,
|
|
1276
|
+
onBlur,
|
|
1277
|
+
onFocus,
|
|
1278
|
+
formData,
|
|
1279
|
+
readonly,
|
|
1280
|
+
registry,
|
|
1281
|
+
idSeparator,
|
|
1282
|
+
layoutGridSchema,
|
|
1283
|
+
// Used to pull this out of otherProps since we don't want to pass it through
|
|
1284
|
+
...otherProps
|
|
1285
|
+
} = this.props;
|
|
1286
|
+
const { fields: fields2, schemaUtils } = registry;
|
|
1287
|
+
const { SchemaField: SchemaField2, LayoutMultiSchemaField: LayoutMultiSchemaField2 } = fields2;
|
|
1288
|
+
const uiComponentProps = _LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
|
|
1289
|
+
if (uiComponentProps.rendered) {
|
|
1290
|
+
return uiComponentProps.rendered;
|
|
1291
|
+
}
|
|
1292
|
+
const { name, UIComponent, uiProps } = uiComponentProps;
|
|
1293
|
+
const {
|
|
1294
|
+
schema,
|
|
1295
|
+
isRequired,
|
|
1296
|
+
isReadonly,
|
|
1297
|
+
optionsInfo,
|
|
1298
|
+
idSchema: fieldIdSchema
|
|
1299
|
+
} = _LayoutGridField.getSchemaDetailsForField(
|
|
1300
|
+
schemaUtils,
|
|
1301
|
+
name,
|
|
1302
|
+
initialSchema,
|
|
1303
|
+
formData,
|
|
1304
|
+
idSchema,
|
|
1305
|
+
idSeparator
|
|
1306
|
+
);
|
|
1307
|
+
if (schema) {
|
|
1308
|
+
const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
|
|
1309
|
+
const { fieldUiSchema, uiReadonly } = _LayoutGridField.computeFieldUiSchema(
|
|
1310
|
+
name,
|
|
1311
|
+
uiProps,
|
|
1312
|
+
uiSchema,
|
|
1313
|
+
isReadonly,
|
|
1314
|
+
readonly
|
|
1315
|
+
);
|
|
1316
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1317
|
+
Field,
|
|
1318
|
+
{
|
|
1319
|
+
"data-testid": optionsInfo?.hasDiscriminator ? _LayoutGridField.TEST_IDS.layoutMultiSchemaField : _LayoutGridField.TEST_IDS.field,
|
|
1320
|
+
...otherProps,
|
|
1321
|
+
name,
|
|
1322
|
+
required: isRequired,
|
|
1323
|
+
readonly: uiReadonly,
|
|
1324
|
+
schema,
|
|
1325
|
+
uiSchema: fieldUiSchema,
|
|
1326
|
+
errorSchema: get2(errorSchema, name),
|
|
1327
|
+
idSchema: fieldIdSchema,
|
|
1328
|
+
idSeparator,
|
|
1329
|
+
formData: get2(formData, name),
|
|
1330
|
+
onChange: this.onFieldChange(name),
|
|
1331
|
+
onBlur,
|
|
1332
|
+
onFocus,
|
|
1333
|
+
options: optionsInfo?.options,
|
|
1334
|
+
registry
|
|
1335
|
+
}
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
if (UIComponent) {
|
|
1339
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1340
|
+
UIComponent,
|
|
1341
|
+
{
|
|
1342
|
+
"data-testid": _LayoutGridField.TEST_IDS.uiComponent,
|
|
1343
|
+
...otherProps,
|
|
1344
|
+
name,
|
|
1345
|
+
required: isRequired,
|
|
1346
|
+
formData,
|
|
1347
|
+
readOnly: !!isReadonly || readonly,
|
|
1348
|
+
errorSchema,
|
|
1349
|
+
uiSchema,
|
|
1350
|
+
schema: initialSchema,
|
|
1351
|
+
idSchema,
|
|
1352
|
+
idSeparator,
|
|
1353
|
+
onBlur,
|
|
1354
|
+
onFocus,
|
|
1355
|
+
registry,
|
|
1356
|
+
...uiProps
|
|
1357
|
+
}
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1362
|
+
/** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
|
|
1363
|
+
* `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
|
|
1364
|
+
* match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
|
|
1365
|
+
* generic `renderField()` function with the `layoutGridSchema`.
|
|
1366
|
+
*
|
|
1367
|
+
* @returns - the rendered `LayoutGridField`
|
|
1368
|
+
*/
|
|
1369
|
+
render() {
|
|
1370
|
+
const { uiSchema } = this.props;
|
|
1371
|
+
let { layoutGridSchema } = this.props;
|
|
1372
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1373
|
+
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1374
|
+
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
|
|
1375
|
+
}
|
|
1376
|
+
if (isObject(layoutGridSchema)) {
|
|
1377
|
+
if ("ui:row" /* ROW */ in layoutGridSchema) {
|
|
1378
|
+
return this.renderRow(layoutGridSchema);
|
|
1379
|
+
}
|
|
1380
|
+
if ("ui:col" /* COLUMN */ in layoutGridSchema) {
|
|
1381
|
+
return this.renderCol(layoutGridSchema);
|
|
1382
|
+
}
|
|
1383
|
+
if ("ui:columns" /* COLUMNS */ in layoutGridSchema) {
|
|
1384
|
+
return this.renderColumns(layoutGridSchema);
|
|
1385
|
+
}
|
|
1386
|
+
if ("ui:condition" /* CONDITION */ in layoutGridSchema) {
|
|
1387
|
+
return this.renderCondition(layoutGridSchema);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return this.renderField(layoutGridSchema);
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
function LayoutHeaderField(props) {
|
|
1394
|
+
const { idSchema, title, schema, uiSchema, required, registry, name } = props;
|
|
1395
|
+
const options = utils.getUiOptions(uiSchema, registry.globalUiOptions);
|
|
1396
|
+
const { title: uiTitle } = options;
|
|
1397
|
+
const { title: schemaTitle } = schema;
|
|
1398
|
+
const fieldTitle = uiTitle || title || schemaTitle || name;
|
|
1399
|
+
if (!fieldTitle) {
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
const TitleFieldTemplate = utils.getTemplate(
|
|
1403
|
+
"TitleFieldTemplate",
|
|
1404
|
+
registry,
|
|
1405
|
+
options
|
|
1406
|
+
);
|
|
1407
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1408
|
+
TitleFieldTemplate,
|
|
1409
|
+
{
|
|
1410
|
+
id: utils.titleId(idSchema),
|
|
1411
|
+
title: fieldTitle,
|
|
1412
|
+
required,
|
|
1413
|
+
schema,
|
|
1414
|
+
uiSchema,
|
|
1415
|
+
registry
|
|
1416
|
+
}
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
function getSelectedOption(options, selectorField, value) {
|
|
1420
|
+
const defaultValue = "!@#!@$@#$!@$#";
|
|
1421
|
+
const schemaOptions = options.map(({ schema }) => schema);
|
|
1422
|
+
return schemaOptions.find((option) => {
|
|
1423
|
+
const selector = get2(option, [utils.PROPERTIES_KEY, selectorField]);
|
|
1424
|
+
const result = get2(selector, utils.DEFAULT_KEY, get2(selector, utils.CONST_KEY, defaultValue));
|
|
1425
|
+
return result === value;
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
function computeEnumOptions(schema, options, schemaUtils, uiSchema, formData) {
|
|
1429
|
+
const realOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
1430
|
+
let tempSchema = schema;
|
|
1431
|
+
if (has(schema, utils.ONE_OF_KEY)) {
|
|
1432
|
+
tempSchema = { ...schema, [utils.ONE_OF_KEY]: realOptions };
|
|
1433
|
+
} else if (has(schema, utils.ANY_OF_KEY)) {
|
|
1434
|
+
tempSchema = { ...schema, [utils.ANY_OF_KEY]: realOptions };
|
|
1435
|
+
}
|
|
1436
|
+
const enumOptions = utils.optionsList(tempSchema, uiSchema);
|
|
1437
|
+
if (!enumOptions) {
|
|
1438
|
+
throw new Error(`No enumOptions were computed from the schema ${JSON.stringify(tempSchema)}`);
|
|
1439
|
+
}
|
|
1440
|
+
return enumOptions;
|
|
1441
|
+
}
|
|
1442
|
+
function LayoutMultiSchemaField(props) {
|
|
1443
|
+
const {
|
|
1444
|
+
name,
|
|
1445
|
+
baseType,
|
|
1446
|
+
disabled = false,
|
|
1447
|
+
formData,
|
|
1448
|
+
idSchema,
|
|
1449
|
+
onBlur,
|
|
1450
|
+
onChange,
|
|
1451
|
+
options,
|
|
1452
|
+
onFocus,
|
|
1453
|
+
registry,
|
|
1454
|
+
uiSchema,
|
|
1455
|
+
schema,
|
|
1456
|
+
formContext,
|
|
1457
|
+
autofocus,
|
|
1458
|
+
readonly,
|
|
1459
|
+
required,
|
|
1460
|
+
errorSchema,
|
|
1461
|
+
hideError = false
|
|
1462
|
+
} = props;
|
|
1463
|
+
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
1464
|
+
const [enumOptions, setEnumOptions] = react.useState(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1465
|
+
const id = get2(idSchema, utils.ID_KEY);
|
|
1466
|
+
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1467
|
+
const FieldErrorTemplate2 = utils.getTemplate("FieldErrorTemplate", registry, options);
|
|
1468
|
+
const FieldTemplate2 = utils.getTemplate("FieldTemplate", registry, options);
|
|
1469
|
+
const schemaHash = utils.hashObject(schema);
|
|
1470
|
+
const optionsHash = utils.hashObject(options);
|
|
1471
|
+
const uiSchemaHash = uiSchema ? utils.hashObject(uiSchema) : "";
|
|
1472
|
+
const formDataHash = formData ? utils.hashObject(formData) : "";
|
|
1473
|
+
react.useEffect(() => {
|
|
1474
|
+
setEnumOptions(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1475
|
+
}, [schemaHash, optionsHash, schemaUtils, uiSchemaHash, formDataHash]);
|
|
1476
|
+
const {
|
|
1477
|
+
widget = discriminator ? "radio" : "select",
|
|
1478
|
+
title = "",
|
|
1479
|
+
placeholder = "",
|
|
1480
|
+
optionsSchemaSelector: selectorField = discriminator,
|
|
1481
|
+
hideError: uiSchemaHideError,
|
|
1482
|
+
...uiOptions
|
|
1483
|
+
} = utils.getUiOptions(uiSchema);
|
|
1484
|
+
if (!selectorField) {
|
|
1485
|
+
throw new Error("No selector field provided for the LayoutMultiSchemaField");
|
|
1486
|
+
}
|
|
1487
|
+
const selectedOption = get2(formData, selectorField);
|
|
1488
|
+
let optionSchema = get2(enumOptions[0]?.schema, [utils.PROPERTIES_KEY, selectorField], {});
|
|
1489
|
+
const option = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1490
|
+
optionSchema = optionSchema?.type ? optionSchema : { ...optionSchema, type: option?.type || baseType };
|
|
1491
|
+
const Widget = utils.getWidget(optionSchema, widget, widgets2);
|
|
1492
|
+
const hideFieldError = uiSchemaHideError === void 0 ? hideError : Boolean(uiSchemaHideError);
|
|
1493
|
+
const rawErrors = get2(errorSchema, [utils.ERRORS_KEY], []);
|
|
1494
|
+
const fieldErrorSchema = omit3(errorSchema, [utils.ERRORS_KEY]);
|
|
1495
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1496
|
+
const onOptionChange = (opt) => {
|
|
1497
|
+
const newOption = getSelectedOption(enumOptions, selectorField, opt);
|
|
1498
|
+
const oldOption = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1499
|
+
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
1500
|
+
if (newFormData && newOption) {
|
|
1501
|
+
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
1502
|
+
}
|
|
1503
|
+
if (newFormData) {
|
|
1504
|
+
set(newFormData, selectorField, opt);
|
|
1505
|
+
}
|
|
1506
|
+
onChange(newFormData, void 0, id);
|
|
1507
|
+
};
|
|
1508
|
+
const widgetOptions = { enumOptions, ...uiOptions };
|
|
1509
|
+
const errors = !hideFieldError && rawErrors.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(FieldErrorTemplate2, { idSchema, schema, errors: rawErrors, registry }) : void 0;
|
|
1510
|
+
const ignored = (value) => noop;
|
|
1511
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1512
|
+
FieldTemplate2,
|
|
1513
|
+
{
|
|
1514
|
+
id,
|
|
1515
|
+
schema,
|
|
1516
|
+
label: (title || schema.title) ?? "",
|
|
1517
|
+
disabled: disabled || Array.isArray(enumOptions) && isEmpty(enumOptions),
|
|
1518
|
+
uiSchema,
|
|
1519
|
+
formContext,
|
|
1520
|
+
required,
|
|
1521
|
+
readonly: !!readonly,
|
|
1522
|
+
registry,
|
|
1523
|
+
displayLabel,
|
|
1524
|
+
errors,
|
|
1525
|
+
onChange,
|
|
1526
|
+
onDropPropertyClick: ignored,
|
|
1527
|
+
onKeyChange: ignored,
|
|
1528
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1529
|
+
Widget,
|
|
1530
|
+
{
|
|
1531
|
+
id,
|
|
1532
|
+
name,
|
|
1533
|
+
schema,
|
|
1534
|
+
label: (title || schema.title) ?? "",
|
|
1535
|
+
disabled: disabled || Array.isArray(enumOptions) && isEmpty(enumOptions),
|
|
1536
|
+
uiSchema,
|
|
1537
|
+
formContext,
|
|
1538
|
+
autofocus,
|
|
1539
|
+
readonly,
|
|
1540
|
+
required,
|
|
1541
|
+
registry,
|
|
1542
|
+
multiple: false,
|
|
1543
|
+
rawErrors,
|
|
1544
|
+
hideError: hideFieldError,
|
|
1545
|
+
hideLabel: !displayLabel,
|
|
1546
|
+
errorSchema: fieldErrorSchema,
|
|
1547
|
+
placeholder,
|
|
1548
|
+
onChange: onOptionChange,
|
|
1549
|
+
onBlur,
|
|
1550
|
+
onFocus,
|
|
1551
|
+
value: selectedOption,
|
|
1552
|
+
options: widgetOptions
|
|
1553
|
+
}
|
|
1554
|
+
)
|
|
1555
|
+
}
|
|
1556
|
+
);
|
|
1557
|
+
}
|
|
873
1558
|
var AnyOfField = class extends react.Component {
|
|
874
1559
|
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
875
1560
|
*
|
|
@@ -986,8 +1671,8 @@
|
|
|
986
1671
|
...uiOptions
|
|
987
1672
|
} = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
988
1673
|
const Widget = utils.getWidget({ type: "number" }, widget, widgets2);
|
|
989
|
-
const rawErrors =
|
|
990
|
-
const fieldErrorSchema =
|
|
1674
|
+
const rawErrors = get2(errorSchema, utils.ERRORS_KEY, []);
|
|
1675
|
+
const fieldErrorSchema = omit3(errorSchema, [utils.ERRORS_KEY]);
|
|
991
1676
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
992
1677
|
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
993
1678
|
let optionSchema;
|
|
@@ -1214,33 +1899,37 @@
|
|
|
1214
1899
|
* @param schema - The schema element to which the new property is being added
|
|
1215
1900
|
*/
|
|
1216
1901
|
handleAddClick = (schema) => () => {
|
|
1217
|
-
if (!schema.additionalProperties) {
|
|
1902
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
1218
1903
|
return;
|
|
1219
1904
|
}
|
|
1220
1905
|
const { formData, onChange, registry } = this.props;
|
|
1221
1906
|
const newFormData = { ...formData };
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
type =
|
|
1227
|
-
constValue =
|
|
1228
|
-
defaultValue =
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1907
|
+
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
1908
|
+
if (schema.patternProperties) {
|
|
1909
|
+
set(newFormData, newKey, null);
|
|
1910
|
+
} else {
|
|
1911
|
+
let type = void 0;
|
|
1912
|
+
let constValue = void 0;
|
|
1913
|
+
let defaultValue = void 0;
|
|
1914
|
+
if (isObject(schema.additionalProperties)) {
|
|
1915
|
+
type = schema.additionalProperties.type;
|
|
1916
|
+
constValue = schema.additionalProperties.const;
|
|
1917
|
+
defaultValue = schema.additionalProperties.default;
|
|
1918
|
+
let apSchema = schema.additionalProperties;
|
|
1919
|
+
if (utils.REF_KEY in apSchema) {
|
|
1920
|
+
const { schemaUtils } = registry;
|
|
1921
|
+
apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[utils.REF_KEY] }, formData);
|
|
1922
|
+
type = apSchema.type;
|
|
1923
|
+
constValue = apSchema.const;
|
|
1924
|
+
defaultValue = apSchema.default;
|
|
1925
|
+
}
|
|
1926
|
+
if (!type && (utils.ANY_OF_KEY in apSchema || utils.ONE_OF_KEY in apSchema)) {
|
|
1927
|
+
type = "object";
|
|
1928
|
+
}
|
|
1239
1929
|
}
|
|
1930
|
+
const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
|
|
1931
|
+
set(newFormData, newKey, newValue);
|
|
1240
1932
|
}
|
|
1241
|
-
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
1242
|
-
const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
|
|
1243
|
-
set(newFormData, newKey, newValue);
|
|
1244
1933
|
onChange(newFormData);
|
|
1245
1934
|
};
|
|
1246
1935
|
/** Renders the `ObjectField` from the given props
|
|
@@ -1277,7 +1966,7 @@
|
|
|
1277
1966
|
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
1278
1967
|
} catch (err) {
|
|
1279
1968
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1280
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "config-error", style: { color: "red" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { options: { disableParsingRawHTML: true }, children: translateString(utils.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
1969
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "rjsf-config-error", style: { color: "red" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { options: { disableParsingRawHTML: true }, children: translateString(utils.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
1281
1970
|
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: JSON.stringify(schema) })
|
|
1282
1971
|
] });
|
|
1283
1972
|
}
|
|
@@ -1290,20 +1979,20 @@
|
|
|
1290
1979
|
const addedByAdditionalProperties = has(schema, [utils.PROPERTIES_KEY, name2, utils.ADDITIONAL_PROPERTY_FLAG]);
|
|
1291
1980
|
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
|
|
1292
1981
|
const hidden = utils.getUiOptions(fieldUiSchema).widget === "hidden";
|
|
1293
|
-
const fieldIdSchema =
|
|
1982
|
+
const fieldIdSchema = get2(idSchema, [name2], {});
|
|
1294
1983
|
return {
|
|
1295
1984
|
content: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1296
1985
|
SchemaField2,
|
|
1297
1986
|
{
|
|
1298
1987
|
name: name2,
|
|
1299
1988
|
required: this.isRequired(name2),
|
|
1300
|
-
schema:
|
|
1989
|
+
schema: get2(schema, [utils.PROPERTIES_KEY, name2], {}),
|
|
1301
1990
|
uiSchema: fieldUiSchema,
|
|
1302
|
-
errorSchema:
|
|
1991
|
+
errorSchema: get2(errorSchema, name2),
|
|
1303
1992
|
idSchema: fieldIdSchema,
|
|
1304
1993
|
idPrefix,
|
|
1305
1994
|
idSeparator,
|
|
1306
|
-
formData:
|
|
1995
|
+
formData: get2(formData, name2),
|
|
1307
1996
|
formContext,
|
|
1308
1997
|
wasPropertyKeyModified: this.state.wasPropertyKeyModified,
|
|
1309
1998
|
onKeyChange: this.onKeyChange(name2),
|
|
@@ -1436,9 +2125,9 @@
|
|
|
1436
2125
|
}
|
|
1437
2126
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1438
2127
|
const { __errors, ...fieldErrorSchema } = errorSchema || {};
|
|
1439
|
-
const fieldUiSchema =
|
|
2128
|
+
const fieldUiSchema = omit3(uiSchema, ["ui:classNames", "classNames", "ui:style"]);
|
|
1440
2129
|
if (utils.UI_OPTIONS_KEY in fieldUiSchema) {
|
|
1441
|
-
fieldUiSchema[utils.UI_OPTIONS_KEY] =
|
|
2130
|
+
fieldUiSchema[utils.UI_OPTIONS_KEY] = omit3(fieldUiSchema[utils.UI_OPTIONS_KEY], ["classNames", "style"]);
|
|
1442
2131
|
}
|
|
1443
2132
|
const field = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1444
2133
|
FieldComponent,
|
|
@@ -1468,17 +2157,9 @@
|
|
|
1468
2157
|
const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { options: { disableParsingRawHTML: true }, children: description }) : description;
|
|
1469
2158
|
const help = uiOptions.help;
|
|
1470
2159
|
const hidden = uiOptions.widget === "hidden";
|
|
1471
|
-
const classNames = ["
|
|
2160
|
+
const classNames = ["rjsf-field", `rjsf-field-${utils.getSchemaType(schema)}`];
|
|
1472
2161
|
if (!hideError && __errors && __errors.length > 0) {
|
|
1473
|
-
classNames.push("field-error
|
|
1474
|
-
}
|
|
1475
|
-
if (uiSchema?.classNames) {
|
|
1476
|
-
{
|
|
1477
|
-
console.warn(
|
|
1478
|
-
"'uiSchema.classNames' is deprecated and may be removed in a major release; Use 'ui:classNames' instead."
|
|
1479
|
-
);
|
|
1480
|
-
}
|
|
1481
|
-
classNames.push(uiSchema.classNames);
|
|
2162
|
+
classNames.push("rjsf-field-error");
|
|
1482
2163
|
}
|
|
1483
2164
|
if (uiOptions.classNames) {
|
|
1484
2165
|
classNames.push(uiOptions.classNames);
|
|
@@ -1680,6 +2361,9 @@
|
|
|
1680
2361
|
ArrayField: ArrayField_default,
|
|
1681
2362
|
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
1682
2363
|
BooleanField: BooleanField_default,
|
|
2364
|
+
LayoutGridField,
|
|
2365
|
+
LayoutHeaderField,
|
|
2366
|
+
LayoutMultiSchemaField,
|
|
1683
2367
|
NumberField: NumberField_default,
|
|
1684
2368
|
ObjectField: ObjectField_default,
|
|
1685
2369
|
OneOfField: MultiSchemaField_default,
|
|
@@ -1713,24 +2397,13 @@
|
|
|
1713
2397
|
);
|
|
1714
2398
|
}
|
|
1715
2399
|
function ArrayFieldItemTemplate(props) {
|
|
1716
|
-
const {
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
hasToolbar,
|
|
1721
|
-
hasMoveDown,
|
|
1722
|
-
hasMoveUp,
|
|
1723
|
-
hasRemove,
|
|
1724
|
-
hasCopy,
|
|
1725
|
-
index,
|
|
1726
|
-
onCopyIndexClick,
|
|
1727
|
-
onDropIndexClick,
|
|
1728
|
-
onReorderClick,
|
|
1729
|
-
readonly,
|
|
2400
|
+
const { children, className, buttonsProps, hasToolbar, registry, uiSchema } = props;
|
|
2401
|
+
const uiOptions = utils.getUiOptions(uiSchema);
|
|
2402
|
+
const ArrayFieldItemButtonsTemplate2 = utils.getTemplate(
|
|
2403
|
+
"ArrayFieldItemButtonsTemplate",
|
|
1730
2404
|
registry,
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
2405
|
+
uiOptions
|
|
2406
|
+
);
|
|
1734
2407
|
const btnStyle = {
|
|
1735
2408
|
flex: 1,
|
|
1736
2409
|
paddingLeft: 6,
|
|
@@ -1739,7 +2412,7 @@
|
|
|
1739
2412
|
};
|
|
1740
2413
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
|
|
1741
2414
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: hasToolbar ? "col-xs-9" : "col-xs-12", children }),
|
|
1742
|
-
hasToolbar && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-xs-3 array-item-toolbox", children: /* @__PURE__ */ jsxRuntime.
|
|
2415
|
+
hasToolbar && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-xs-3 array-item-toolbox", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1743
2416
|
"div",
|
|
1744
2417
|
{
|
|
1745
2418
|
className: "btn-group",
|
|
@@ -1747,52 +2420,79 @@
|
|
|
1747
2420
|
display: "flex",
|
|
1748
2421
|
justifyContent: "space-around"
|
|
1749
2422
|
},
|
|
1750
|
-
children:
|
|
1751
|
-
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1752
|
-
MoveUpButton2,
|
|
1753
|
-
{
|
|
1754
|
-
style: btnStyle,
|
|
1755
|
-
disabled: disabled || readonly || !hasMoveUp,
|
|
1756
|
-
onClick: onReorderClick(index, index - 1),
|
|
1757
|
-
uiSchema,
|
|
1758
|
-
registry
|
|
1759
|
-
}
|
|
1760
|
-
),
|
|
1761
|
-
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1762
|
-
MoveDownButton2,
|
|
1763
|
-
{
|
|
1764
|
-
style: btnStyle,
|
|
1765
|
-
disabled: disabled || readonly || !hasMoveDown,
|
|
1766
|
-
onClick: onReorderClick(index, index + 1),
|
|
1767
|
-
uiSchema,
|
|
1768
|
-
registry
|
|
1769
|
-
}
|
|
1770
|
-
),
|
|
1771
|
-
hasCopy && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1772
|
-
CopyButton2,
|
|
1773
|
-
{
|
|
1774
|
-
style: btnStyle,
|
|
1775
|
-
disabled: disabled || readonly,
|
|
1776
|
-
onClick: onCopyIndexClick(index),
|
|
1777
|
-
uiSchema,
|
|
1778
|
-
registry
|
|
1779
|
-
}
|
|
1780
|
-
),
|
|
1781
|
-
hasRemove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1782
|
-
RemoveButton2,
|
|
1783
|
-
{
|
|
1784
|
-
style: btnStyle,
|
|
1785
|
-
disabled: disabled || readonly,
|
|
1786
|
-
onClick: onDropIndexClick(index),
|
|
1787
|
-
uiSchema,
|
|
1788
|
-
registry
|
|
1789
|
-
}
|
|
1790
|
-
)
|
|
1791
|
-
]
|
|
2423
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItemButtonsTemplate2, { ...buttonsProps, style: btnStyle })
|
|
1792
2424
|
}
|
|
1793
2425
|
) })
|
|
1794
2426
|
] });
|
|
1795
2427
|
}
|
|
2428
|
+
function ArrayFieldItemButtonsTemplate(props) {
|
|
2429
|
+
const {
|
|
2430
|
+
disabled,
|
|
2431
|
+
hasCopy,
|
|
2432
|
+
hasMoveDown,
|
|
2433
|
+
hasMoveUp,
|
|
2434
|
+
hasRemove,
|
|
2435
|
+
idSchema,
|
|
2436
|
+
index,
|
|
2437
|
+
onCopyIndexClick,
|
|
2438
|
+
onDropIndexClick,
|
|
2439
|
+
onReorderClick,
|
|
2440
|
+
readonly,
|
|
2441
|
+
registry,
|
|
2442
|
+
uiSchema
|
|
2443
|
+
} = props;
|
|
2444
|
+
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
2445
|
+
const onCopyClick = react.useMemo(() => onCopyIndexClick(index), [index, onCopyIndexClick]);
|
|
2446
|
+
const onRemoveClick = react.useMemo(() => onDropIndexClick(index), [index, onDropIndexClick]);
|
|
2447
|
+
const onArrowUpClick = react.useMemo(() => onReorderClick(index, index - 1), [index, onReorderClick]);
|
|
2448
|
+
const onArrowDownClick = react.useMemo(() => onReorderClick(index, index + 1), [index, onReorderClick]);
|
|
2449
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2450
|
+
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2451
|
+
MoveUpButton2,
|
|
2452
|
+
{
|
|
2453
|
+
id: utils.buttonId(idSchema, "moveUp"),
|
|
2454
|
+
className: "rjsf-array-item-move-up",
|
|
2455
|
+
disabled: disabled || readonly || !hasMoveUp,
|
|
2456
|
+
onClick: onArrowUpClick,
|
|
2457
|
+
uiSchema,
|
|
2458
|
+
registry
|
|
2459
|
+
}
|
|
2460
|
+
),
|
|
2461
|
+
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2462
|
+
MoveDownButton2,
|
|
2463
|
+
{
|
|
2464
|
+
id: utils.buttonId(idSchema, "moveDown"),
|
|
2465
|
+
className: "rjsf-array-item-move-down",
|
|
2466
|
+
disabled: disabled || readonly || !hasMoveDown,
|
|
2467
|
+
onClick: onArrowDownClick,
|
|
2468
|
+
uiSchema,
|
|
2469
|
+
registry
|
|
2470
|
+
}
|
|
2471
|
+
),
|
|
2472
|
+
hasCopy && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2473
|
+
CopyButton2,
|
|
2474
|
+
{
|
|
2475
|
+
id: utils.buttonId(idSchema, "copy"),
|
|
2476
|
+
className: "rjsf-array-item-copy",
|
|
2477
|
+
disabled: disabled || readonly,
|
|
2478
|
+
onClick: onCopyClick,
|
|
2479
|
+
uiSchema,
|
|
2480
|
+
registry
|
|
2481
|
+
}
|
|
2482
|
+
),
|
|
2483
|
+
hasRemove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2484
|
+
RemoveButton2,
|
|
2485
|
+
{
|
|
2486
|
+
id: utils.buttonId(idSchema, "remove"),
|
|
2487
|
+
className: "rjsf-array-item-remove",
|
|
2488
|
+
disabled: disabled || readonly,
|
|
2489
|
+
onClick: onRemoveClick,
|
|
2490
|
+
uiSchema,
|
|
2491
|
+
registry
|
|
2492
|
+
}
|
|
2493
|
+
)
|
|
2494
|
+
] });
|
|
2495
|
+
}
|
|
1796
2496
|
function ArrayFieldTemplate(props) {
|
|
1797
2497
|
const {
|
|
1798
2498
|
canAdd,
|
|
@@ -1853,7 +2553,8 @@
|
|
|
1853
2553
|
canAdd && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1854
2554
|
AddButton2,
|
|
1855
2555
|
{
|
|
1856
|
-
|
|
2556
|
+
id: utils.buttonId(idSchema, "add"),
|
|
2557
|
+
className: "rjsf-array-item-add",
|
|
1857
2558
|
onClick: onAddClick,
|
|
1858
2559
|
disabled: disabled || readonly,
|
|
1859
2560
|
uiSchema,
|
|
@@ -1977,58 +2678,25 @@
|
|
|
1977
2678
|
const {
|
|
1978
2679
|
registry: { translateString }
|
|
1979
2680
|
} = props;
|
|
1980
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1981
|
-
IconButton,
|
|
1982
|
-
{
|
|
1983
|
-
title: translateString(utils.TranslatableString.CopyButton),
|
|
1984
|
-
className: "array-item-copy",
|
|
1985
|
-
...props,
|
|
1986
|
-
icon: "copy"
|
|
1987
|
-
}
|
|
1988
|
-
);
|
|
2681
|
+
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { title: translateString(utils.TranslatableString.CopyButton), ...props, icon: "copy" });
|
|
1989
2682
|
}
|
|
1990
2683
|
function MoveDownButton(props) {
|
|
1991
2684
|
const {
|
|
1992
2685
|
registry: { translateString }
|
|
1993
2686
|
} = props;
|
|
1994
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1995
|
-
IconButton,
|
|
1996
|
-
{
|
|
1997
|
-
title: translateString(utils.TranslatableString.MoveDownButton),
|
|
1998
|
-
className: "array-item-move-down",
|
|
1999
|
-
...props,
|
|
2000
|
-
icon: "arrow-down"
|
|
2001
|
-
}
|
|
2002
|
-
);
|
|
2687
|
+
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { title: translateString(utils.TranslatableString.MoveDownButton), ...props, icon: "arrow-down" });
|
|
2003
2688
|
}
|
|
2004
2689
|
function MoveUpButton(props) {
|
|
2005
2690
|
const {
|
|
2006
2691
|
registry: { translateString }
|
|
2007
2692
|
} = props;
|
|
2008
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2009
|
-
IconButton,
|
|
2010
|
-
{
|
|
2011
|
-
title: translateString(utils.TranslatableString.MoveUpButton),
|
|
2012
|
-
className: "array-item-move-up",
|
|
2013
|
-
...props,
|
|
2014
|
-
icon: "arrow-up"
|
|
2015
|
-
}
|
|
2016
|
-
);
|
|
2693
|
+
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { title: translateString(utils.TranslatableString.MoveUpButton), ...props, icon: "arrow-up" });
|
|
2017
2694
|
}
|
|
2018
2695
|
function RemoveButton(props) {
|
|
2019
2696
|
const {
|
|
2020
2697
|
registry: { translateString }
|
|
2021
2698
|
} = props;
|
|
2022
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2023
|
-
IconButton,
|
|
2024
|
-
{
|
|
2025
|
-
title: translateString(utils.TranslatableString.RemoveButton),
|
|
2026
|
-
className: "array-item-remove",
|
|
2027
|
-
...props,
|
|
2028
|
-
iconType: "danger",
|
|
2029
|
-
icon: "remove"
|
|
2030
|
-
}
|
|
2031
|
-
);
|
|
2699
|
+
return /* @__PURE__ */ jsxRuntime.jsx(IconButton, { title: translateString(utils.TranslatableString.RemoveButton), ...props, iconType: "danger", icon: "remove" });
|
|
2032
2700
|
}
|
|
2033
2701
|
function AddButton({
|
|
2034
2702
|
className,
|
|
@@ -2140,6 +2808,10 @@
|
|
|
2140
2808
|
}
|
|
2141
2809
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { id, className: "help-block", children: help });
|
|
2142
2810
|
}
|
|
2811
|
+
function GridTemplate(props) {
|
|
2812
|
+
const { children, column, className, ...rest } = props;
|
|
2813
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, ...rest, children });
|
|
2814
|
+
}
|
|
2143
2815
|
function ObjectFieldTemplate(props) {
|
|
2144
2816
|
const {
|
|
2145
2817
|
description,
|
|
@@ -2191,7 +2863,8 @@
|
|
|
2191
2863
|
utils.canExpand(schema, uiSchema, formData) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2192
2864
|
AddButton2,
|
|
2193
2865
|
{
|
|
2194
|
-
|
|
2866
|
+
id: utils.buttonId(idSchema, "add"),
|
|
2867
|
+
className: "rjsf-object-property-expand",
|
|
2195
2868
|
onClick: onAddClick(schema),
|
|
2196
2869
|
disabled: disabled || readonly,
|
|
2197
2870
|
uiSchema,
|
|
@@ -2239,6 +2912,8 @@
|
|
|
2239
2912
|
readonly,
|
|
2240
2913
|
required,
|
|
2241
2914
|
schema,
|
|
2915
|
+
hideError,
|
|
2916
|
+
rawErrors,
|
|
2242
2917
|
children,
|
|
2243
2918
|
uiSchema,
|
|
2244
2919
|
registry
|
|
@@ -2247,10 +2922,15 @@
|
|
|
2247
2922
|
const { RemoveButton: RemoveButton2 } = templates2.ButtonTemplates;
|
|
2248
2923
|
const keyLabel = translateString(utils.TranslatableString.KeyLabel, [label]);
|
|
2249
2924
|
const additional = utils.ADDITIONAL_PROPERTY_FLAG in schema;
|
|
2925
|
+
const classNamesList = ["form-group", classNames];
|
|
2926
|
+
if (!hideError && rawErrors && rawErrors.length > 0) {
|
|
2927
|
+
classNamesList.push("has-error has-danger");
|
|
2928
|
+
}
|
|
2929
|
+
const uiClassNames = classNamesList.join(" ").trim();
|
|
2250
2930
|
if (!additional) {
|
|
2251
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className:
|
|
2931
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: uiClassNames, style, children });
|
|
2252
2932
|
}
|
|
2253
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className:
|
|
2933
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: uiClassNames, style, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "row", children: [
|
|
2254
2934
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-xs-5 form-additional", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "form-group", children: [
|
|
2255
2935
|
/* @__PURE__ */ jsxRuntime.jsx(Label, { label: keyLabel, required, id: `${id}-key` }),
|
|
2256
2936
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2268,7 +2948,8 @@
|
|
|
2268
2948
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-xs-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2269
2949
|
RemoveButton2,
|
|
2270
2950
|
{
|
|
2271
|
-
|
|
2951
|
+
id: utils.buttonId(id, "remove"),
|
|
2952
|
+
className: "rjsf-object-property-remove btn-block",
|
|
2272
2953
|
style: { border: "0" },
|
|
2273
2954
|
disabled: disabled || readonly,
|
|
2274
2955
|
onClick: onDropPropertyClick(label),
|
|
@@ -2284,6 +2965,7 @@
|
|
|
2284
2965
|
return {
|
|
2285
2966
|
ArrayFieldDescriptionTemplate,
|
|
2286
2967
|
ArrayFieldItemTemplate,
|
|
2968
|
+
ArrayFieldItemButtonsTemplate,
|
|
2287
2969
|
ArrayFieldTemplate,
|
|
2288
2970
|
ArrayFieldTitleTemplate,
|
|
2289
2971
|
ButtonTemplates: ButtonTemplates_default(),
|
|
@@ -2293,6 +2975,7 @@
|
|
|
2293
2975
|
FieldTemplate: FieldTemplate_default,
|
|
2294
2976
|
FieldErrorTemplate,
|
|
2295
2977
|
FieldHelpTemplate,
|
|
2978
|
+
GridTemplate,
|
|
2296
2979
|
ObjectFieldTemplate,
|
|
2297
2980
|
TitleFieldTemplate: TitleField,
|
|
2298
2981
|
UnsupportedFieldTemplate: UnsupportedField_default,
|
|
@@ -2357,9 +3040,12 @@
|
|
|
2357
3040
|
}) {
|
|
2358
3041
|
const { translateString } = registry;
|
|
2359
3042
|
const [lastValue, setLastValue] = react.useState(value);
|
|
2360
|
-
const [state, setState] = react.useReducer(
|
|
2361
|
-
|
|
2362
|
-
|
|
3043
|
+
const [state, setState] = react.useReducer(
|
|
3044
|
+
(state2, action) => {
|
|
3045
|
+
return { ...state2, ...action };
|
|
3046
|
+
},
|
|
3047
|
+
utils.parseDateString(value, time)
|
|
3048
|
+
);
|
|
2363
3049
|
react.useEffect(() => {
|
|
2364
3050
|
const stateValue = utils.toDateString(state, time);
|
|
2365
3051
|
if (readyForChange(state) && stateValue !== value) {
|
|
@@ -2667,7 +3353,7 @@
|
|
|
2667
3353
|
type: blob.type
|
|
2668
3354
|
}
|
|
2669
3355
|
];
|
|
2670
|
-
} catch
|
|
3356
|
+
} catch {
|
|
2671
3357
|
return acc;
|
|
2672
3358
|
}
|
|
2673
3359
|
}, []);
|
|
@@ -2756,13 +3442,13 @@
|
|
|
2756
3442
|
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
2757
3443
|
const handleBlur = react.useCallback(
|
|
2758
3444
|
({ target }) => onBlur(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
|
|
2759
|
-
[onBlur, id]
|
|
3445
|
+
[onBlur, enumOptions, emptyValue, id]
|
|
2760
3446
|
);
|
|
2761
3447
|
const handleFocus = react.useCallback(
|
|
2762
3448
|
({ target }) => onFocus(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)),
|
|
2763
|
-
[onFocus, id]
|
|
3449
|
+
[onFocus, enumOptions, emptyValue, id]
|
|
2764
3450
|
);
|
|
2765
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "field-radio-group", id, children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
|
|
3451
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "field-radio-group", id, role: "radiogroup", children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
|
|
2766
3452
|
const checked = utils.enumOptionsIsSelected(option.value, value);
|
|
2767
3453
|
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
2768
3454
|
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
@@ -2803,6 +3489,105 @@
|
|
|
2803
3489
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "range-view", children: value })
|
|
2804
3490
|
] });
|
|
2805
3491
|
}
|
|
3492
|
+
function RatingWidget({
|
|
3493
|
+
id,
|
|
3494
|
+
value,
|
|
3495
|
+
required,
|
|
3496
|
+
disabled,
|
|
3497
|
+
readonly,
|
|
3498
|
+
autofocus,
|
|
3499
|
+
onChange,
|
|
3500
|
+
onFocus,
|
|
3501
|
+
onBlur,
|
|
3502
|
+
schema,
|
|
3503
|
+
options
|
|
3504
|
+
}) {
|
|
3505
|
+
const { stars = 5, shape = "star" } = options;
|
|
3506
|
+
const numStars = schema.maximum ? Math.min(schema.maximum, 5) : Math.min(Math.max(stars, 1), 5);
|
|
3507
|
+
const min = schema.minimum || 0;
|
|
3508
|
+
const handleStarClick = react.useCallback(
|
|
3509
|
+
(starValue) => {
|
|
3510
|
+
if (!disabled && !readonly) {
|
|
3511
|
+
onChange(starValue);
|
|
3512
|
+
}
|
|
3513
|
+
},
|
|
3514
|
+
[onChange, disabled, readonly]
|
|
3515
|
+
);
|
|
3516
|
+
const handleFocus = react.useCallback(
|
|
3517
|
+
(event) => {
|
|
3518
|
+
if (onFocus) {
|
|
3519
|
+
const starValue = Number(event.target.dataset.value);
|
|
3520
|
+
onFocus(id, starValue);
|
|
3521
|
+
}
|
|
3522
|
+
},
|
|
3523
|
+
[onFocus, id]
|
|
3524
|
+
);
|
|
3525
|
+
const handleBlur = react.useCallback(
|
|
3526
|
+
(event) => {
|
|
3527
|
+
if (onBlur) {
|
|
3528
|
+
const starValue = Number(event.target.dataset.value);
|
|
3529
|
+
onBlur(id, starValue);
|
|
3530
|
+
}
|
|
3531
|
+
},
|
|
3532
|
+
[onBlur, id]
|
|
3533
|
+
);
|
|
3534
|
+
const getSymbol = (isFilled) => {
|
|
3535
|
+
if (shape === "heart") {
|
|
3536
|
+
return isFilled ? "\u2665" : "\u2661";
|
|
3537
|
+
}
|
|
3538
|
+
return isFilled ? "\u2605" : "\u2606";
|
|
3539
|
+
};
|
|
3540
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3541
|
+
"div",
|
|
3542
|
+
{
|
|
3543
|
+
className: "rating-widget",
|
|
3544
|
+
style: {
|
|
3545
|
+
display: "inline-flex",
|
|
3546
|
+
fontSize: "1.5rem",
|
|
3547
|
+
cursor: disabled || readonly ? "default" : "pointer"
|
|
3548
|
+
},
|
|
3549
|
+
children: [
|
|
3550
|
+
[...Array(numStars)].map((_, index) => {
|
|
3551
|
+
const starValue = min + index;
|
|
3552
|
+
const isFilled = starValue <= value;
|
|
3553
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3554
|
+
"span",
|
|
3555
|
+
{
|
|
3556
|
+
onClick: () => handleStarClick(starValue),
|
|
3557
|
+
onFocus: handleFocus,
|
|
3558
|
+
onBlur: handleBlur,
|
|
3559
|
+
"data-value": starValue,
|
|
3560
|
+
tabIndex: disabled || readonly ? -1 : 0,
|
|
3561
|
+
role: "radio",
|
|
3562
|
+
"aria-checked": starValue === value,
|
|
3563
|
+
"aria-label": `${starValue} ${shape === "heart" ? "heart" : "star"}${starValue === 1 ? "" : "s"}`,
|
|
3564
|
+
style: {
|
|
3565
|
+
color: isFilled ? "#FFD700" : "#ccc",
|
|
3566
|
+
padding: "0 0.2rem",
|
|
3567
|
+
transition: "color 0.2s",
|
|
3568
|
+
userSelect: "none"
|
|
3569
|
+
},
|
|
3570
|
+
children: getSymbol(isFilled)
|
|
3571
|
+
},
|
|
3572
|
+
index
|
|
3573
|
+
);
|
|
3574
|
+
}),
|
|
3575
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3576
|
+
"input",
|
|
3577
|
+
{
|
|
3578
|
+
type: "hidden",
|
|
3579
|
+
id,
|
|
3580
|
+
name: id,
|
|
3581
|
+
value: value || "",
|
|
3582
|
+
required,
|
|
3583
|
+
disabled: disabled || readonly,
|
|
3584
|
+
"aria-hidden": "true"
|
|
3585
|
+
}
|
|
3586
|
+
)
|
|
3587
|
+
]
|
|
3588
|
+
}
|
|
3589
|
+
) });
|
|
3590
|
+
}
|
|
2806
3591
|
function getValue(event, multiple) {
|
|
2807
3592
|
if (multiple) {
|
|
2808
3593
|
return Array.from(event.target.options).slice().filter((o) => o.selected).map((o) => o.value);
|
|
@@ -2831,21 +3616,21 @@
|
|
|
2831
3616
|
const newValue = getValue(event, multiple);
|
|
2832
3617
|
return onFocus(id, utils.enumOptionsValueForIndex(newValue, enumOptions, optEmptyVal));
|
|
2833
3618
|
},
|
|
2834
|
-
[onFocus, id,
|
|
3619
|
+
[onFocus, id, multiple, enumOptions, optEmptyVal]
|
|
2835
3620
|
);
|
|
2836
3621
|
const handleBlur = react.useCallback(
|
|
2837
3622
|
(event) => {
|
|
2838
3623
|
const newValue = getValue(event, multiple);
|
|
2839
3624
|
return onBlur(id, utils.enumOptionsValueForIndex(newValue, enumOptions, optEmptyVal));
|
|
2840
3625
|
},
|
|
2841
|
-
[onBlur, id,
|
|
3626
|
+
[onBlur, id, multiple, enumOptions, optEmptyVal]
|
|
2842
3627
|
);
|
|
2843
3628
|
const handleChange = react.useCallback(
|
|
2844
3629
|
(event) => {
|
|
2845
3630
|
const newValue = getValue(event, multiple);
|
|
2846
3631
|
return onChange(utils.enumOptionsValueForIndex(newValue, enumOptions, optEmptyVal));
|
|
2847
3632
|
},
|
|
2848
|
-
[onChange,
|
|
3633
|
+
[onChange, multiple, enumOptions, optEmptyVal]
|
|
2849
3634
|
);
|
|
2850
3635
|
const selectedIndexes = utils.enumOptionsIndexForValue(value, enumOptions, multiple);
|
|
2851
3636
|
const showPlaceholderOption = !multiple && schema.default === void 0;
|
|
@@ -2855,6 +3640,7 @@
|
|
|
2855
3640
|
id,
|
|
2856
3641
|
name: id,
|
|
2857
3642
|
multiple,
|
|
3643
|
+
role: "combobox",
|
|
2858
3644
|
className: "form-control",
|
|
2859
3645
|
value: typeof selectedIndexes === "undefined" ? emptyValue : selectedIndexes,
|
|
2860
3646
|
required,
|
|
@@ -2963,6 +3749,7 @@
|
|
|
2963
3749
|
PasswordWidget,
|
|
2964
3750
|
RadioWidget: RadioWidget_default,
|
|
2965
3751
|
RangeWidget,
|
|
3752
|
+
RatingWidget,
|
|
2966
3753
|
SelectWidget: SelectWidget_default,
|
|
2967
3754
|
TextWidget,
|
|
2968
3755
|
TextareaWidget: TextareaWidget_default,
|
|
@@ -3052,9 +3839,6 @@
|
|
|
3052
3839
|
* If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
|
|
3053
3840
|
* changes.
|
|
3054
3841
|
*
|
|
3055
|
-
* This method effectively replaces the deprecated `UNSAFE_componentWillReceiveProps`, providing a safer alternative
|
|
3056
|
-
* to handle prop changes and state updates.
|
|
3057
|
-
*
|
|
3058
3842
|
* @param _ - The previous set of props.
|
|
3059
3843
|
* @param prevState - The previous state of the component before the update.
|
|
3060
3844
|
* @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
|
|
@@ -3144,10 +3928,13 @@
|
|
|
3144
3928
|
errors = currentErrors.errors;
|
|
3145
3929
|
errorSchema = currentErrors.errorSchema;
|
|
3146
3930
|
if (formDataChangedFields.length > 0) {
|
|
3147
|
-
const newErrorSchema = formDataChangedFields.reduce(
|
|
3148
|
-
acc
|
|
3149
|
-
|
|
3150
|
-
|
|
3931
|
+
const newErrorSchema = formDataChangedFields.reduce(
|
|
3932
|
+
(acc, key) => {
|
|
3933
|
+
acc[key] = void 0;
|
|
3934
|
+
return acc;
|
|
3935
|
+
},
|
|
3936
|
+
{}
|
|
3937
|
+
);
|
|
3151
3938
|
errorSchema = schemaValidationErrorSchema = utils.mergeObjects(
|
|
3152
3939
|
currentErrors.errorSchema,
|
|
3153
3940
|
newErrorSchema,
|
|
@@ -3272,7 +4059,7 @@
|
|
|
3272
4059
|
}
|
|
3273
4060
|
} else if (key === utils.NAME_KEY && _obj[key] !== "") {
|
|
3274
4061
|
paths.forEach((path) => {
|
|
3275
|
-
const formValue =
|
|
4062
|
+
const formValue = get2(formData, path);
|
|
3276
4063
|
if (typeof formValue !== "object" || isEmpty(formValue) || Array.isArray(formValue) && formValue.every((val) => typeof val !== "object")) {
|
|
3277
4064
|
acc.push(path);
|
|
3278
4065
|
}
|
|
@@ -3630,7 +4417,6 @@
|
|
|
3630
4417
|
action,
|
|
3631
4418
|
autoComplete,
|
|
3632
4419
|
enctype,
|
|
3633
|
-
acceptcharset,
|
|
3634
4420
|
acceptCharset,
|
|
3635
4421
|
noHtml5Validate = false,
|
|
3636
4422
|
disabled,
|
|
@@ -3661,7 +4447,7 @@
|
|
|
3661
4447
|
action,
|
|
3662
4448
|
autoComplete,
|
|
3663
4449
|
encType: enctype,
|
|
3664
|
-
acceptCharset
|
|
4450
|
+
acceptCharset,
|
|
3665
4451
|
noValidate: noHtml5Validate,
|
|
3666
4452
|
onSubmit: this.onSubmit,
|
|
3667
4453
|
as,
|
|
@@ -3724,9 +4510,9 @@
|
|
|
3724
4510
|
}
|
|
3725
4511
|
|
|
3726
4512
|
// src/index.ts
|
|
3727
|
-
var
|
|
4513
|
+
var index_default = Form;
|
|
3728
4514
|
|
|
3729
|
-
exports.default =
|
|
4515
|
+
exports.default = index_default;
|
|
3730
4516
|
exports.getDefaultRegistry = getDefaultRegistry;
|
|
3731
4517
|
exports.withTheme = withTheme;
|
|
3732
4518
|
|