@rjsf/core 6.0.0-beta.9 → 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/README.md +2 -0
- package/dist/core.umd.js +2042 -1987
- package/dist/index.cjs +4909 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +2509 -2389
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +137 -34
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +318 -173
- package/lib/components/fields/ArrayField.d.ts +2 -187
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +526 -492
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +8 -3
- package/lib/components/fields/FallbackField.d.ts +7 -0
- package/lib/components/fields/FallbackField.d.ts.map +1 -0
- package/lib/components/fields/FallbackField.js +72 -0
- package/lib/components/fields/LayoutGridField.d.ts +109 -186
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +426 -426
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -6
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +16 -10
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +2 -68
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +163 -163
- package/lib/components/fields/OptionalDataControlsField.d.ts +8 -0
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -0
- package/lib/components/fields/OptionalDataControlsField.js +43 -0
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +52 -30
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +8 -3
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/fields/index.js +4 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +4 -5
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/BaseInputTemplate.js +2 -2
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js +2 -2
- package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +12 -0
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +3 -2
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +11 -0
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -0
- package/lib/components/templates/OptionalDataControlsTemplate.js +20 -0
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/TitleField.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +6 -0
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +5 -46
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +2 -2
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +4 -4
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +7 -87
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/HiddenWidget.js +2 -2
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -2
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +2 -2
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +6 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +23 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -20
- package/src/components/Form.tsx +468 -206
- package/src/components/fields/ArrayField.tsx +871 -723
- package/src/components/fields/BooleanField.tsx +14 -5
- package/src/components/fields/FallbackField.tsx +157 -0
- package/src/components/fields/LayoutGridField.tsx +626 -603
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +9 -10
- package/src/components/fields/MultiSchemaField.tsx +57 -36
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +308 -239
- package/src/components/fields/OptionalDataControlsField.tsx +84 -0
- package/src/components/fields/SchemaField.tsx +75 -94
- package/src/components/fields/StringField.tsx +14 -5
- package/src/components/fields/index.ts +4 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +16 -21
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldTemplate.tsx +11 -18
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +4 -3
- package/src/components/templates/BaseInputTemplate.tsx +5 -5
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -0
- package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +12 -7
- package/src/components/templates/OptionalDataControlsTemplate.tsx +43 -0
- package/src/components/templates/TitleField.tsx +6 -1
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +5 -5
- package/src/components/templates/index.ts +6 -0
- package/src/components/widgets/AltDateWidget.tsx +8 -126
- package/src/components/widgets/CheckboxWidget.tsx +4 -3
- package/src/components/widgets/CheckboxesWidget.tsx +5 -4
- package/src/components/widgets/FileWidget.tsx +11 -102
- package/src/components/widgets/HiddenWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +3 -2
- package/src/components/widgets/RatingWidget.tsx +2 -1
- package/src/components/widgets/SelectWidget.tsx +3 -2
- package/src/components/widgets/TextareaWidget.tsx +3 -2
- package/src/getDefaultRegistry.ts +14 -1
- package/src/getTestRegistry.tsx +38 -0
- package/src/index.ts +2 -1
- package/dist/index.js +0 -4834
- package/dist/index.js.map +0 -7
package/dist/index.js
DELETED
|
@@ -1,4834 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
RichDescription: () => RichDescription,
|
|
34
|
-
default: () => index_default,
|
|
35
|
-
getDefaultRegistry: () => getDefaultRegistry,
|
|
36
|
-
withTheme: () => withTheme
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
|
|
40
|
-
// src/components/Form.tsx
|
|
41
|
-
var import_react22 = require("react");
|
|
42
|
-
var import_utils45 = require("@rjsf/utils");
|
|
43
|
-
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
44
|
-
var import_get6 = __toESM(require("lodash/get"), 1);
|
|
45
|
-
var import_isEmpty4 = __toESM(require("lodash/isEmpty"), 1);
|
|
46
|
-
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
47
|
-
var import_pick = __toESM(require("lodash/pick"), 1);
|
|
48
|
-
var import_toPath = __toESM(require("lodash/toPath"), 1);
|
|
49
|
-
|
|
50
|
-
// src/getDefaultRegistry.ts
|
|
51
|
-
var import_utils44 = require("@rjsf/utils");
|
|
52
|
-
|
|
53
|
-
// src/components/fields/ArrayField.tsx
|
|
54
|
-
var import_react = require("react");
|
|
55
|
-
var import_utils = require("@rjsf/utils");
|
|
56
|
-
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
57
|
-
var import_get = __toESM(require("lodash/get"), 1);
|
|
58
|
-
var import_isObject = __toESM(require("lodash/isObject"), 1);
|
|
59
|
-
var import_set = __toESM(require("lodash/set"), 1);
|
|
60
|
-
var import_nanoid = require("nanoid");
|
|
61
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
62
|
-
function generateRowId() {
|
|
63
|
-
return (0, import_nanoid.nanoid)();
|
|
64
|
-
}
|
|
65
|
-
function generateKeyedFormData(formData) {
|
|
66
|
-
return !Array.isArray(formData) ? [] : formData.map((item) => {
|
|
67
|
-
return {
|
|
68
|
-
key: generateRowId(),
|
|
69
|
-
item
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function keyedToPlainFormData(keyedFormData) {
|
|
74
|
-
if (Array.isArray(keyedFormData)) {
|
|
75
|
-
return keyedFormData.map((keyedItem) => keyedItem.item);
|
|
76
|
-
}
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
var ArrayField = class extends import_react.Component {
|
|
80
|
-
/** Constructs an `ArrayField` from the `props`, generating the initial keyed data from the `formData`
|
|
81
|
-
*
|
|
82
|
-
* @param props - The `FieldProps` for this template
|
|
83
|
-
*/
|
|
84
|
-
constructor(props) {
|
|
85
|
-
super(props);
|
|
86
|
-
const { formData = [] } = props;
|
|
87
|
-
const keyedFormData = generateKeyedFormData(formData);
|
|
88
|
-
this.state = {
|
|
89
|
-
keyedFormData,
|
|
90
|
-
updatedKeyedFormData: false
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/** React lifecycle method that is called when the props are about to change allowing the state to be updated. It
|
|
94
|
-
* regenerates the keyed form data and returns it
|
|
95
|
-
*
|
|
96
|
-
* @param nextProps - The next set of props data
|
|
97
|
-
* @param prevState - The previous set of state data
|
|
98
|
-
*/
|
|
99
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
100
|
-
if (prevState.updatedKeyedFormData) {
|
|
101
|
-
return {
|
|
102
|
-
updatedKeyedFormData: false
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
|
|
106
|
-
const previousKeyedFormData = prevState.keyedFormData || [];
|
|
107
|
-
const newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => {
|
|
108
|
-
return {
|
|
109
|
-
key: previousKeyedFormDatum.key,
|
|
110
|
-
item: nextFormData[index]
|
|
111
|
-
};
|
|
112
|
-
}) : generateKeyedFormData(nextFormData);
|
|
113
|
-
return {
|
|
114
|
-
keyedFormData: newKeyedFormData
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/** Returns the appropriate title for an item by getting first the title from the schema.items, then falling back to
|
|
118
|
-
* the description from the schema.items, and finally the string "Item"
|
|
119
|
-
*/
|
|
120
|
-
get itemTitle() {
|
|
121
|
-
const { schema, registry } = this.props;
|
|
122
|
-
const { translateString } = registry;
|
|
123
|
-
return (0, import_get.default)(
|
|
124
|
-
schema,
|
|
125
|
-
[import_utils.ITEMS_KEY, "title"],
|
|
126
|
-
(0, import_get.default)(schema, [import_utils.ITEMS_KEY, "description"], translateString(import_utils.TranslatableString.ArrayItemTitle))
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
/** Determines whether the item described in the schema is always required, which is determined by whether any item
|
|
130
|
-
* may be null.
|
|
131
|
-
*
|
|
132
|
-
* @param itemSchema - The schema for the item
|
|
133
|
-
* @return - True if the item schema type does not contain the "null" type
|
|
134
|
-
*/
|
|
135
|
-
isItemRequired(itemSchema) {
|
|
136
|
-
if (Array.isArray(itemSchema.type)) {
|
|
137
|
-
return !itemSchema.type.includes("null");
|
|
138
|
-
}
|
|
139
|
-
return itemSchema.type !== "null";
|
|
140
|
-
}
|
|
141
|
-
/** Determines whether more items can be added to the array. If the uiSchema indicates the array doesn't allow adding
|
|
142
|
-
* then false is returned. Otherwise, if the schema indicates that there are a maximum number of items and the
|
|
143
|
-
* `formData` matches that value, then false is returned, otherwise true is returned.
|
|
144
|
-
*
|
|
145
|
-
* @param formItems - The list of items in the form
|
|
146
|
-
* @returns - True if the item is addable otherwise false
|
|
147
|
-
*/
|
|
148
|
-
canAddItem(formItems) {
|
|
149
|
-
const { schema, uiSchema, registry } = this.props;
|
|
150
|
-
let { addable } = (0, import_utils.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
151
|
-
if (addable !== false) {
|
|
152
|
-
if (schema.maxItems !== void 0) {
|
|
153
|
-
addable = formItems.length < schema.maxItems;
|
|
154
|
-
} else {
|
|
155
|
-
addable = true;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return addable;
|
|
159
|
-
}
|
|
160
|
-
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
161
|
-
* that the schema is fixed and allows additional items.
|
|
162
|
-
*/
|
|
163
|
-
_getNewFormDataRow = () => {
|
|
164
|
-
const { schema, registry } = this.props;
|
|
165
|
-
const { schemaUtils } = registry;
|
|
166
|
-
let itemSchema = schema.items;
|
|
167
|
-
if ((0, import_utils.isFixedItems)(schema) && (0, import_utils.allowAdditionalItems)(schema)) {
|
|
168
|
-
itemSchema = schema.additionalItems;
|
|
169
|
-
}
|
|
170
|
-
return schemaUtils.getDefaultFormState(itemSchema);
|
|
171
|
-
};
|
|
172
|
-
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
173
|
-
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
174
|
-
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
175
|
-
*
|
|
176
|
-
* @param event - The event for the click
|
|
177
|
-
* @param [index] - The optional index at which to add the new data
|
|
178
|
-
*/
|
|
179
|
-
_handleAddClick(event, index) {
|
|
180
|
-
if (event) {
|
|
181
|
-
event.preventDefault();
|
|
182
|
-
}
|
|
183
|
-
const { onChange, errorSchema } = this.props;
|
|
184
|
-
const { keyedFormData } = this.state;
|
|
185
|
-
let newErrorSchema;
|
|
186
|
-
if (errorSchema) {
|
|
187
|
-
newErrorSchema = {};
|
|
188
|
-
for (const idx in errorSchema) {
|
|
189
|
-
const i = parseInt(idx);
|
|
190
|
-
if (index === void 0 || i < index) {
|
|
191
|
-
(0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
|
|
192
|
-
} else if (i >= index) {
|
|
193
|
-
(0, import_set.default)(newErrorSchema, [i + 1], errorSchema[idx]);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const newKeyedFormDataRow = {
|
|
198
|
-
key: generateRowId(),
|
|
199
|
-
item: this._getNewFormDataRow()
|
|
200
|
-
};
|
|
201
|
-
const newKeyedFormData = [...keyedFormData];
|
|
202
|
-
if (index !== void 0) {
|
|
203
|
-
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
204
|
-
} else {
|
|
205
|
-
newKeyedFormData.push(newKeyedFormDataRow);
|
|
206
|
-
}
|
|
207
|
-
this.setState(
|
|
208
|
-
{
|
|
209
|
-
keyedFormData: newKeyedFormData,
|
|
210
|
-
updatedKeyedFormData: true
|
|
211
|
-
},
|
|
212
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
216
|
-
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
217
|
-
* keyed data
|
|
218
|
-
*
|
|
219
|
-
* @param event - The event for the click
|
|
220
|
-
*/
|
|
221
|
-
onAddClick = (event) => {
|
|
222
|
-
this._handleAddClick(event);
|
|
223
|
-
};
|
|
224
|
-
/** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
|
|
225
|
-
* keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
|
|
226
|
-
* form data converted from the keyed data
|
|
227
|
-
*
|
|
228
|
-
* @param index - The index at which the add button is clicked
|
|
229
|
-
*/
|
|
230
|
-
onAddIndexClick = (index) => {
|
|
231
|
-
return (event) => {
|
|
232
|
-
this._handleAddClick(event, index);
|
|
233
|
-
};
|
|
234
|
-
};
|
|
235
|
-
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
236
|
-
* keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
|
|
237
|
-
* form data converted from the keyed data
|
|
238
|
-
*
|
|
239
|
-
* @param index - The index at which the copy button is clicked
|
|
240
|
-
*/
|
|
241
|
-
onCopyIndexClick = (index) => {
|
|
242
|
-
return (event) => {
|
|
243
|
-
if (event) {
|
|
244
|
-
event.preventDefault();
|
|
245
|
-
}
|
|
246
|
-
const { onChange, errorSchema } = this.props;
|
|
247
|
-
const { keyedFormData } = this.state;
|
|
248
|
-
let newErrorSchema;
|
|
249
|
-
if (errorSchema) {
|
|
250
|
-
newErrorSchema = {};
|
|
251
|
-
for (const idx in errorSchema) {
|
|
252
|
-
const i = parseInt(idx);
|
|
253
|
-
if (i <= index) {
|
|
254
|
-
(0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
|
|
255
|
-
} else if (i > index) {
|
|
256
|
-
(0, import_set.default)(newErrorSchema, [i + 1], errorSchema[idx]);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const newKeyedFormDataRow = {
|
|
261
|
-
key: generateRowId(),
|
|
262
|
-
item: (0, import_cloneDeep.default)(keyedFormData[index].item)
|
|
263
|
-
};
|
|
264
|
-
const newKeyedFormData = [...keyedFormData];
|
|
265
|
-
if (index !== void 0) {
|
|
266
|
-
newKeyedFormData.splice(index + 1, 0, newKeyedFormDataRow);
|
|
267
|
-
} else {
|
|
268
|
-
newKeyedFormData.push(newKeyedFormDataRow);
|
|
269
|
-
}
|
|
270
|
-
this.setState(
|
|
271
|
-
{
|
|
272
|
-
keyedFormData: newKeyedFormData,
|
|
273
|
-
updatedKeyedFormData: true
|
|
274
|
-
},
|
|
275
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
276
|
-
);
|
|
277
|
-
};
|
|
278
|
-
};
|
|
279
|
-
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
280
|
-
* keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
|
|
281
|
-
* from the keyed data
|
|
282
|
-
*
|
|
283
|
-
* @param index - The index at which the remove button is clicked
|
|
284
|
-
*/
|
|
285
|
-
onDropIndexClick = (index) => {
|
|
286
|
-
return (event) => {
|
|
287
|
-
if (event) {
|
|
288
|
-
event.preventDefault();
|
|
289
|
-
}
|
|
290
|
-
const { onChange, errorSchema } = this.props;
|
|
291
|
-
const { keyedFormData } = this.state;
|
|
292
|
-
let newErrorSchema;
|
|
293
|
-
if (errorSchema) {
|
|
294
|
-
newErrorSchema = {};
|
|
295
|
-
for (const idx in errorSchema) {
|
|
296
|
-
const i = parseInt(idx);
|
|
297
|
-
if (i < index) {
|
|
298
|
-
(0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
|
|
299
|
-
} else if (i > index) {
|
|
300
|
-
(0, import_set.default)(newErrorSchema, [i - 1], errorSchema[idx]);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
|
|
305
|
-
this.setState(
|
|
306
|
-
{
|
|
307
|
-
keyedFormData: newKeyedFormData,
|
|
308
|
-
updatedKeyedFormData: true
|
|
309
|
-
},
|
|
310
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
311
|
-
);
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
315
|
-
* row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
|
|
316
|
-
* plain form data converted from the keyed data
|
|
317
|
-
*
|
|
318
|
-
* @param index - The index of the item to move
|
|
319
|
-
* @param newIndex - The index to where the item is to be moved
|
|
320
|
-
*/
|
|
321
|
-
onReorderClick = (index, newIndex) => {
|
|
322
|
-
return (event) => {
|
|
323
|
-
if (event) {
|
|
324
|
-
event.preventDefault();
|
|
325
|
-
event.currentTarget.blur();
|
|
326
|
-
}
|
|
327
|
-
const { onChange, errorSchema } = this.props;
|
|
328
|
-
let newErrorSchema;
|
|
329
|
-
if (errorSchema) {
|
|
330
|
-
newErrorSchema = {};
|
|
331
|
-
for (const idx in errorSchema) {
|
|
332
|
-
const i = parseInt(idx);
|
|
333
|
-
if (i == index) {
|
|
334
|
-
(0, import_set.default)(newErrorSchema, [newIndex], errorSchema[index]);
|
|
335
|
-
} else if (i == newIndex) {
|
|
336
|
-
(0, import_set.default)(newErrorSchema, [index], errorSchema[newIndex]);
|
|
337
|
-
} else {
|
|
338
|
-
(0, import_set.default)(newErrorSchema, [idx], errorSchema[i]);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
const { keyedFormData } = this.state;
|
|
343
|
-
function reOrderArray() {
|
|
344
|
-
const _newKeyedFormData = keyedFormData.slice();
|
|
345
|
-
_newKeyedFormData.splice(index, 1);
|
|
346
|
-
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
347
|
-
return _newKeyedFormData;
|
|
348
|
-
}
|
|
349
|
-
const newKeyedFormData = reOrderArray();
|
|
350
|
-
this.setState(
|
|
351
|
-
{
|
|
352
|
-
keyedFormData: newKeyedFormData
|
|
353
|
-
},
|
|
354
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
355
|
-
);
|
|
356
|
-
};
|
|
357
|
-
};
|
|
358
|
-
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
359
|
-
* `onChange` callback with the updated form data
|
|
360
|
-
*
|
|
361
|
-
* @param index - The index of the item being changed
|
|
362
|
-
*/
|
|
363
|
-
onChangeForIndex = (index) => {
|
|
364
|
-
return (value, newErrorSchema, id) => {
|
|
365
|
-
const { formData, onChange, errorSchema } = this.props;
|
|
366
|
-
const arrayData = Array.isArray(formData) ? formData : [];
|
|
367
|
-
const newFormData = arrayData.map((item, i) => {
|
|
368
|
-
const jsonValue = typeof value === "undefined" ? null : value;
|
|
369
|
-
return index === i ? jsonValue : item;
|
|
370
|
-
});
|
|
371
|
-
onChange(
|
|
372
|
-
newFormData,
|
|
373
|
-
errorSchema && errorSchema && {
|
|
374
|
-
...errorSchema,
|
|
375
|
-
[index]: newErrorSchema
|
|
376
|
-
},
|
|
377
|
-
id
|
|
378
|
-
);
|
|
379
|
-
};
|
|
380
|
-
};
|
|
381
|
-
/** Callback handler used to change the value for a checkbox */
|
|
382
|
-
onSelectChange = (value) => {
|
|
383
|
-
const { onChange, idSchema } = this.props;
|
|
384
|
-
onChange(value, void 0, idSchema && idSchema.$id);
|
|
385
|
-
};
|
|
386
|
-
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
387
|
-
*/
|
|
388
|
-
render() {
|
|
389
|
-
const { schema, uiSchema, idSchema, registry } = this.props;
|
|
390
|
-
const { schemaUtils, translateString } = registry;
|
|
391
|
-
if (!(import_utils.ITEMS_KEY in schema)) {
|
|
392
|
-
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
393
|
-
const UnsupportedFieldTemplate = (0, import_utils.getTemplate)(
|
|
394
|
-
"UnsupportedFieldTemplate",
|
|
395
|
-
registry,
|
|
396
|
-
uiOptions
|
|
397
|
-
);
|
|
398
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
399
|
-
UnsupportedFieldTemplate,
|
|
400
|
-
{
|
|
401
|
-
schema,
|
|
402
|
-
idSchema,
|
|
403
|
-
reason: translateString(import_utils.TranslatableString.MissingItems),
|
|
404
|
-
registry
|
|
405
|
-
}
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
if (schemaUtils.isMultiSelect(schema)) {
|
|
409
|
-
return this.renderMultiSelect();
|
|
410
|
-
}
|
|
411
|
-
if ((0, import_utils.isCustomWidget)(uiSchema)) {
|
|
412
|
-
return this.renderCustomWidget();
|
|
413
|
-
}
|
|
414
|
-
if ((0, import_utils.isFixedItems)(schema)) {
|
|
415
|
-
return this.renderFixedArray();
|
|
416
|
-
}
|
|
417
|
-
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
418
|
-
return this.renderFiles();
|
|
419
|
-
}
|
|
420
|
-
return this.renderNormalArray();
|
|
421
|
-
}
|
|
422
|
-
/** Renders a normal array without any limitations of length
|
|
423
|
-
*/
|
|
424
|
-
renderNormalArray() {
|
|
425
|
-
const {
|
|
426
|
-
schema,
|
|
427
|
-
uiSchema = {},
|
|
428
|
-
errorSchema,
|
|
429
|
-
idSchema,
|
|
430
|
-
name,
|
|
431
|
-
title,
|
|
432
|
-
disabled = false,
|
|
433
|
-
readonly = false,
|
|
434
|
-
autofocus = false,
|
|
435
|
-
required = false,
|
|
436
|
-
registry,
|
|
437
|
-
onBlur,
|
|
438
|
-
onFocus,
|
|
439
|
-
idPrefix,
|
|
440
|
-
idSeparator = "_",
|
|
441
|
-
rawErrors
|
|
442
|
-
} = this.props;
|
|
443
|
-
const { keyedFormData } = this.state;
|
|
444
|
-
const fieldTitle = schema.title || title || name;
|
|
445
|
-
const { schemaUtils, formContext } = registry;
|
|
446
|
-
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
447
|
-
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : {};
|
|
448
|
-
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
449
|
-
const formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
450
|
-
const canAdd = this.canAddItem(formData);
|
|
451
|
-
const arrayProps = {
|
|
452
|
-
canAdd,
|
|
453
|
-
items: keyedFormData.map((keyedItem, index) => {
|
|
454
|
-
const { key, item } = keyedItem;
|
|
455
|
-
const itemCast = item;
|
|
456
|
-
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
457
|
-
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
458
|
-
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
459
|
-
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
460
|
-
return this.renderArrayFieldItem({
|
|
461
|
-
key,
|
|
462
|
-
index,
|
|
463
|
-
name: name && `${name}-${index}`,
|
|
464
|
-
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
465
|
-
canAdd,
|
|
466
|
-
canMoveUp: index > 0,
|
|
467
|
-
canMoveDown: index < formData.length - 1,
|
|
468
|
-
itemSchema,
|
|
469
|
-
itemIdSchema,
|
|
470
|
-
itemErrorSchema,
|
|
471
|
-
itemData: itemCast,
|
|
472
|
-
itemUiSchema: uiSchema.items,
|
|
473
|
-
autofocus: autofocus && index === 0,
|
|
474
|
-
onBlur,
|
|
475
|
-
onFocus,
|
|
476
|
-
rawErrors,
|
|
477
|
-
totalItems: keyedFormData.length
|
|
478
|
-
});
|
|
479
|
-
}),
|
|
480
|
-
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}`,
|
|
481
|
-
disabled,
|
|
482
|
-
idSchema,
|
|
483
|
-
uiSchema,
|
|
484
|
-
onAddClick: this.onAddClick,
|
|
485
|
-
readonly,
|
|
486
|
-
required,
|
|
487
|
-
schema,
|
|
488
|
-
title: fieldTitle,
|
|
489
|
-
formContext,
|
|
490
|
-
formData,
|
|
491
|
-
rawErrors,
|
|
492
|
-
registry
|
|
493
|
-
};
|
|
494
|
-
const Template = (0, import_utils.getTemplate)("ArrayFieldTemplate", registry, uiOptions);
|
|
495
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Template, { ...arrayProps });
|
|
496
|
-
}
|
|
497
|
-
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
498
|
-
*/
|
|
499
|
-
renderCustomWidget() {
|
|
500
|
-
const {
|
|
501
|
-
schema,
|
|
502
|
-
idSchema,
|
|
503
|
-
uiSchema,
|
|
504
|
-
disabled = false,
|
|
505
|
-
readonly = false,
|
|
506
|
-
autofocus = false,
|
|
507
|
-
required = false,
|
|
508
|
-
hideError,
|
|
509
|
-
placeholder,
|
|
510
|
-
onBlur,
|
|
511
|
-
onFocus,
|
|
512
|
-
formData: items = [],
|
|
513
|
-
registry,
|
|
514
|
-
rawErrors,
|
|
515
|
-
name
|
|
516
|
-
} = this.props;
|
|
517
|
-
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
518
|
-
const { widget, title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
519
|
-
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
520
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
521
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
522
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
523
|
-
Widget,
|
|
524
|
-
{
|
|
525
|
-
id: idSchema.$id,
|
|
526
|
-
name,
|
|
527
|
-
multiple: true,
|
|
528
|
-
onChange: this.onSelectChange,
|
|
529
|
-
onBlur,
|
|
530
|
-
onFocus,
|
|
531
|
-
options,
|
|
532
|
-
schema,
|
|
533
|
-
uiSchema,
|
|
534
|
-
registry,
|
|
535
|
-
value: items,
|
|
536
|
-
disabled,
|
|
537
|
-
readonly,
|
|
538
|
-
hideError,
|
|
539
|
-
required,
|
|
540
|
-
label,
|
|
541
|
-
hideLabel: !displayLabel,
|
|
542
|
-
placeholder,
|
|
543
|
-
formContext,
|
|
544
|
-
autofocus,
|
|
545
|
-
rawErrors
|
|
546
|
-
}
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
/** Renders an array as a set of checkboxes
|
|
550
|
-
*/
|
|
551
|
-
renderMultiSelect() {
|
|
552
|
-
const {
|
|
553
|
-
schema,
|
|
554
|
-
idSchema,
|
|
555
|
-
uiSchema,
|
|
556
|
-
formData: items = [],
|
|
557
|
-
disabled = false,
|
|
558
|
-
readonly = false,
|
|
559
|
-
autofocus = false,
|
|
560
|
-
required = false,
|
|
561
|
-
placeholder,
|
|
562
|
-
onBlur,
|
|
563
|
-
onFocus,
|
|
564
|
-
registry,
|
|
565
|
-
rawErrors,
|
|
566
|
-
name
|
|
567
|
-
} = this.props;
|
|
568
|
-
const { widgets: widgets2, schemaUtils, formContext, globalUiOptions } = registry;
|
|
569
|
-
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
570
|
-
const enumOptions = (0, import_utils.optionsList)(itemsSchema, uiSchema);
|
|
571
|
-
const { widget = "select", title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
572
|
-
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
573
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
574
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
575
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
576
|
-
Widget,
|
|
577
|
-
{
|
|
578
|
-
id: idSchema.$id,
|
|
579
|
-
name,
|
|
580
|
-
multiple: true,
|
|
581
|
-
onChange: this.onSelectChange,
|
|
582
|
-
onBlur,
|
|
583
|
-
onFocus,
|
|
584
|
-
options: { ...options, enumOptions },
|
|
585
|
-
schema,
|
|
586
|
-
uiSchema,
|
|
587
|
-
registry,
|
|
588
|
-
value: items,
|
|
589
|
-
disabled,
|
|
590
|
-
readonly,
|
|
591
|
-
required,
|
|
592
|
-
label,
|
|
593
|
-
hideLabel: !displayLabel,
|
|
594
|
-
placeholder,
|
|
595
|
-
formContext,
|
|
596
|
-
autofocus,
|
|
597
|
-
rawErrors
|
|
598
|
-
}
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
/** Renders an array of files using the `FileWidget`
|
|
602
|
-
*/
|
|
603
|
-
renderFiles() {
|
|
604
|
-
const {
|
|
605
|
-
schema,
|
|
606
|
-
uiSchema,
|
|
607
|
-
idSchema,
|
|
608
|
-
name,
|
|
609
|
-
disabled = false,
|
|
610
|
-
readonly = false,
|
|
611
|
-
autofocus = false,
|
|
612
|
-
required = false,
|
|
613
|
-
onBlur,
|
|
614
|
-
onFocus,
|
|
615
|
-
registry,
|
|
616
|
-
formData: items = [],
|
|
617
|
-
rawErrors
|
|
618
|
-
} = this.props;
|
|
619
|
-
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
620
|
-
const { widget = "files", title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
621
|
-
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
622
|
-
const label = uiTitle ?? schema.title ?? name;
|
|
623
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
624
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
625
|
-
Widget,
|
|
626
|
-
{
|
|
627
|
-
options,
|
|
628
|
-
id: idSchema.$id,
|
|
629
|
-
name,
|
|
630
|
-
multiple: true,
|
|
631
|
-
onChange: this.onSelectChange,
|
|
632
|
-
onBlur,
|
|
633
|
-
onFocus,
|
|
634
|
-
schema,
|
|
635
|
-
uiSchema,
|
|
636
|
-
value: items,
|
|
637
|
-
disabled,
|
|
638
|
-
readonly,
|
|
639
|
-
required,
|
|
640
|
-
registry,
|
|
641
|
-
formContext,
|
|
642
|
-
autofocus,
|
|
643
|
-
rawErrors,
|
|
644
|
-
label,
|
|
645
|
-
hideLabel: !displayLabel
|
|
646
|
-
}
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
/** Renders an array that has a maximum limit of items
|
|
650
|
-
*/
|
|
651
|
-
renderFixedArray() {
|
|
652
|
-
const {
|
|
653
|
-
schema,
|
|
654
|
-
uiSchema = {},
|
|
655
|
-
formData = [],
|
|
656
|
-
errorSchema,
|
|
657
|
-
idPrefix,
|
|
658
|
-
idSeparator = "_",
|
|
659
|
-
idSchema,
|
|
660
|
-
name,
|
|
661
|
-
title,
|
|
662
|
-
disabled = false,
|
|
663
|
-
readonly = false,
|
|
664
|
-
autofocus = false,
|
|
665
|
-
required = false,
|
|
666
|
-
registry,
|
|
667
|
-
onBlur,
|
|
668
|
-
onFocus,
|
|
669
|
-
rawErrors
|
|
670
|
-
} = this.props;
|
|
671
|
-
const { keyedFormData } = this.state;
|
|
672
|
-
let { formData: items = [] } = this.props;
|
|
673
|
-
const fieldTitle = schema.title || title || name;
|
|
674
|
-
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
675
|
-
const { schemaUtils, formContext } = registry;
|
|
676
|
-
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : [];
|
|
677
|
-
const itemSchemas = _schemaItems.map(
|
|
678
|
-
(item, index) => schemaUtils.retrieveSchema(item, formData[index])
|
|
679
|
-
);
|
|
680
|
-
const additionalSchema = (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
681
|
-
if (!items || items.length < itemSchemas.length) {
|
|
682
|
-
items = items || [];
|
|
683
|
-
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
684
|
-
}
|
|
685
|
-
const canAdd = this.canAddItem(items) && !!additionalSchema;
|
|
686
|
-
const arrayProps = {
|
|
687
|
-
canAdd,
|
|
688
|
-
className: "rjsf-field rjsf-field-array rjsf-field-array-fixed-items",
|
|
689
|
-
disabled,
|
|
690
|
-
idSchema,
|
|
691
|
-
formData,
|
|
692
|
-
items: keyedFormData.map((keyedItem, index) => {
|
|
693
|
-
const { key, item } = keyedItem;
|
|
694
|
-
const itemCast = item;
|
|
695
|
-
const additional = index >= itemSchemas.length;
|
|
696
|
-
const itemSchema = (additional && (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
697
|
-
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
698
|
-
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
699
|
-
const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
|
|
700
|
-
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
701
|
-
return this.renderArrayFieldItem({
|
|
702
|
-
key,
|
|
703
|
-
index,
|
|
704
|
-
name: name && `${name}-${index}`,
|
|
705
|
-
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
706
|
-
canAdd,
|
|
707
|
-
canRemove: additional,
|
|
708
|
-
canMoveUp: index >= itemSchemas.length + 1,
|
|
709
|
-
canMoveDown: additional && index < items.length - 1,
|
|
710
|
-
itemSchema,
|
|
711
|
-
itemData: itemCast,
|
|
712
|
-
itemUiSchema,
|
|
713
|
-
itemIdSchema,
|
|
714
|
-
itemErrorSchema,
|
|
715
|
-
autofocus: autofocus && index === 0,
|
|
716
|
-
onBlur,
|
|
717
|
-
onFocus,
|
|
718
|
-
rawErrors,
|
|
719
|
-
totalItems: keyedFormData.length
|
|
720
|
-
});
|
|
721
|
-
}),
|
|
722
|
-
onAddClick: this.onAddClick,
|
|
723
|
-
readonly,
|
|
724
|
-
required,
|
|
725
|
-
registry,
|
|
726
|
-
schema,
|
|
727
|
-
uiSchema,
|
|
728
|
-
title: fieldTitle,
|
|
729
|
-
formContext,
|
|
730
|
-
errorSchema,
|
|
731
|
-
rawErrors
|
|
732
|
-
};
|
|
733
|
-
const Template = (0, import_utils.getTemplate)("ArrayFieldTemplate", registry, uiOptions);
|
|
734
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Template, { ...arrayProps });
|
|
735
|
-
}
|
|
736
|
-
/** Renders the individual array item using a `SchemaField` along with the additional properties required to be send
|
|
737
|
-
* back to the `ArrayFieldItemTemplate`.
|
|
738
|
-
*
|
|
739
|
-
* @param props - The props for the individual array item to be rendered
|
|
740
|
-
*/
|
|
741
|
-
renderArrayFieldItem(props) {
|
|
742
|
-
const {
|
|
743
|
-
key,
|
|
744
|
-
index,
|
|
745
|
-
name,
|
|
746
|
-
canAdd,
|
|
747
|
-
canRemove = true,
|
|
748
|
-
canMoveUp,
|
|
749
|
-
canMoveDown,
|
|
750
|
-
itemSchema,
|
|
751
|
-
itemData,
|
|
752
|
-
itemUiSchema,
|
|
753
|
-
itemIdSchema,
|
|
754
|
-
itemErrorSchema,
|
|
755
|
-
autofocus,
|
|
756
|
-
onBlur,
|
|
757
|
-
onFocus,
|
|
758
|
-
rawErrors,
|
|
759
|
-
totalItems,
|
|
760
|
-
title
|
|
761
|
-
} = props;
|
|
762
|
-
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
|
|
763
|
-
const {
|
|
764
|
-
fields: { ArraySchemaField, SchemaField: SchemaField2 },
|
|
765
|
-
globalUiOptions
|
|
766
|
-
} = registry;
|
|
767
|
-
const ItemSchemaField = ArraySchemaField || SchemaField2;
|
|
768
|
-
const { orderable = true, removable = true, copyable = false } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
769
|
-
const has4 = {
|
|
770
|
-
moveUp: orderable && canMoveUp,
|
|
771
|
-
moveDown: orderable && canMoveDown,
|
|
772
|
-
copy: copyable && canAdd,
|
|
773
|
-
remove: removable && canRemove,
|
|
774
|
-
toolbar: false
|
|
775
|
-
};
|
|
776
|
-
has4.toolbar = Object.keys(has4).some((key2) => has4[key2]);
|
|
777
|
-
return {
|
|
778
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
779
|
-
ItemSchemaField,
|
|
780
|
-
{
|
|
781
|
-
name,
|
|
782
|
-
title,
|
|
783
|
-
index,
|
|
784
|
-
schema: itemSchema,
|
|
785
|
-
uiSchema: itemUiSchema,
|
|
786
|
-
formData: itemData,
|
|
787
|
-
formContext,
|
|
788
|
-
errorSchema: itemErrorSchema,
|
|
789
|
-
idPrefix,
|
|
790
|
-
idSeparator,
|
|
791
|
-
idSchema: itemIdSchema,
|
|
792
|
-
required: this.isItemRequired(itemSchema),
|
|
793
|
-
onChange: this.onChangeForIndex(index),
|
|
794
|
-
onBlur,
|
|
795
|
-
onFocus,
|
|
796
|
-
registry,
|
|
797
|
-
disabled,
|
|
798
|
-
readonly,
|
|
799
|
-
hideError,
|
|
800
|
-
autofocus,
|
|
801
|
-
rawErrors
|
|
802
|
-
}
|
|
803
|
-
),
|
|
804
|
-
buttonsProps: {
|
|
805
|
-
idSchema: itemIdSchema,
|
|
806
|
-
disabled,
|
|
807
|
-
readonly,
|
|
808
|
-
canAdd,
|
|
809
|
-
hasCopy: has4.copy,
|
|
810
|
-
hasMoveUp: has4.moveUp,
|
|
811
|
-
hasMoveDown: has4.moveDown,
|
|
812
|
-
hasRemove: has4.remove,
|
|
813
|
-
index,
|
|
814
|
-
totalItems,
|
|
815
|
-
onAddIndexClick: this.onAddIndexClick,
|
|
816
|
-
onCopyIndexClick: this.onCopyIndexClick,
|
|
817
|
-
onDropIndexClick: this.onDropIndexClick,
|
|
818
|
-
onReorderClick: this.onReorderClick,
|
|
819
|
-
registry,
|
|
820
|
-
schema: itemSchema,
|
|
821
|
-
uiSchema: itemUiSchema
|
|
822
|
-
},
|
|
823
|
-
className: "rjsf-array-item",
|
|
824
|
-
disabled,
|
|
825
|
-
hasToolbar: has4.toolbar,
|
|
826
|
-
index,
|
|
827
|
-
totalItems,
|
|
828
|
-
key,
|
|
829
|
-
readonly,
|
|
830
|
-
registry,
|
|
831
|
-
schema: itemSchema,
|
|
832
|
-
uiSchema: itemUiSchema
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
var ArrayField_default = ArrayField;
|
|
837
|
-
|
|
838
|
-
// src/components/fields/BooleanField.tsx
|
|
839
|
-
var import_utils2 = require("@rjsf/utils");
|
|
840
|
-
var import_isObject2 = __toESM(require("lodash/isObject"), 1);
|
|
841
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
842
|
-
function BooleanField(props) {
|
|
843
|
-
const {
|
|
844
|
-
schema,
|
|
845
|
-
name,
|
|
846
|
-
uiSchema,
|
|
847
|
-
idSchema,
|
|
848
|
-
formData,
|
|
849
|
-
registry,
|
|
850
|
-
required,
|
|
851
|
-
disabled,
|
|
852
|
-
readonly,
|
|
853
|
-
hideError,
|
|
854
|
-
autofocus,
|
|
855
|
-
title,
|
|
856
|
-
onChange,
|
|
857
|
-
onFocus,
|
|
858
|
-
onBlur,
|
|
859
|
-
rawErrors
|
|
860
|
-
} = props;
|
|
861
|
-
const { title: schemaTitle } = schema;
|
|
862
|
-
const { widgets: widgets2, formContext, translateString, globalUiOptions } = registry;
|
|
863
|
-
const {
|
|
864
|
-
widget = "checkbox",
|
|
865
|
-
title: uiTitle,
|
|
866
|
-
// Unlike the other fields, don't use `getDisplayLabel()` since it always returns false for the boolean type
|
|
867
|
-
label: displayLabel = true,
|
|
868
|
-
enumNames,
|
|
869
|
-
...options
|
|
870
|
-
} = (0, import_utils2.getUiOptions)(uiSchema, globalUiOptions);
|
|
871
|
-
const Widget = (0, import_utils2.getWidget)(schema, widget, widgets2);
|
|
872
|
-
const yes = translateString(import_utils2.TranslatableString.YesLabel);
|
|
873
|
-
const no = translateString(import_utils2.TranslatableString.NoLabel);
|
|
874
|
-
let enumOptions;
|
|
875
|
-
const label = uiTitle ?? schemaTitle ?? title ?? name;
|
|
876
|
-
if (Array.isArray(schema.oneOf)) {
|
|
877
|
-
enumOptions = (0, import_utils2.optionsList)(
|
|
878
|
-
{
|
|
879
|
-
oneOf: schema.oneOf.map((option) => {
|
|
880
|
-
if ((0, import_isObject2.default)(option)) {
|
|
881
|
-
return {
|
|
882
|
-
...option,
|
|
883
|
-
title: option.title || (option.const === true ? yes : no)
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
return void 0;
|
|
887
|
-
}).filter((o) => o)
|
|
888
|
-
// cast away the error that typescript can't grok is fixed
|
|
889
|
-
},
|
|
890
|
-
uiSchema
|
|
891
|
-
);
|
|
892
|
-
} else {
|
|
893
|
-
const enums = schema.enum ?? [true, false];
|
|
894
|
-
if (!enumNames && enums.length === 2 && enums.every((v) => typeof v === "boolean")) {
|
|
895
|
-
enumOptions = [
|
|
896
|
-
{
|
|
897
|
-
value: enums[0],
|
|
898
|
-
label: enums[0] ? yes : no
|
|
899
|
-
},
|
|
900
|
-
{
|
|
901
|
-
value: enums[1],
|
|
902
|
-
label: enums[1] ? yes : no
|
|
903
|
-
}
|
|
904
|
-
];
|
|
905
|
-
} else {
|
|
906
|
-
enumOptions = (0, import_utils2.optionsList)({ enum: enums }, uiSchema);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
910
|
-
Widget,
|
|
911
|
-
{
|
|
912
|
-
options: { ...options, enumOptions },
|
|
913
|
-
schema,
|
|
914
|
-
uiSchema,
|
|
915
|
-
id: idSchema.$id,
|
|
916
|
-
name,
|
|
917
|
-
onChange,
|
|
918
|
-
onFocus,
|
|
919
|
-
onBlur,
|
|
920
|
-
label,
|
|
921
|
-
hideLabel: !displayLabel,
|
|
922
|
-
value: formData,
|
|
923
|
-
required,
|
|
924
|
-
disabled,
|
|
925
|
-
readonly,
|
|
926
|
-
hideError,
|
|
927
|
-
registry,
|
|
928
|
-
formContext,
|
|
929
|
-
autofocus,
|
|
930
|
-
rawErrors
|
|
931
|
-
}
|
|
932
|
-
);
|
|
933
|
-
}
|
|
934
|
-
var BooleanField_default = BooleanField;
|
|
935
|
-
|
|
936
|
-
// src/components/fields/LayoutGridField.tsx
|
|
937
|
-
var import_react2 = require("react");
|
|
938
|
-
var import_utils3 = require("@rjsf/utils");
|
|
939
|
-
var import_cloneDeep2 = __toESM(require("lodash/cloneDeep"), 1);
|
|
940
|
-
var import_each = __toESM(require("lodash/each"), 1);
|
|
941
|
-
var import_flatten = __toESM(require("lodash/flatten"), 1);
|
|
942
|
-
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
943
|
-
var import_has = __toESM(require("lodash/has"), 1);
|
|
944
|
-
var import_includes = __toESM(require("lodash/includes"), 1);
|
|
945
|
-
var import_intersection = __toESM(require("lodash/intersection"), 1);
|
|
946
|
-
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
947
|
-
var import_isFunction = __toESM(require("lodash/isFunction"), 1);
|
|
948
|
-
var import_isEqual = __toESM(require("lodash/isEqual"), 1);
|
|
949
|
-
var import_isObject3 = __toESM(require("lodash/isObject"), 1);
|
|
950
|
-
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
951
|
-
var import_isString = __toESM(require("lodash/isString"), 1);
|
|
952
|
-
var import_isUndefined = __toESM(require("lodash/isUndefined"), 1);
|
|
953
|
-
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
954
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
955
|
-
var import_react3 = require("react");
|
|
956
|
-
var LOOKUP_REGEX = /^\$lookup=(.+)/;
|
|
957
|
-
var LAYOUT_GRID_UI_OPTION = "layoutGrid";
|
|
958
|
-
var LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
|
|
959
|
-
function getNonNullishValue(value, fallback) {
|
|
960
|
-
return value ?? fallback;
|
|
961
|
-
}
|
|
962
|
-
var LayoutGridField = class _LayoutGridField extends import_react2.PureComponent {
|
|
963
|
-
static defaultProps = {
|
|
964
|
-
layoutGridSchema: void 0
|
|
965
|
-
};
|
|
966
|
-
static TEST_IDS = (0, import_utils3.getTestIds)();
|
|
967
|
-
/** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
|
|
968
|
-
* will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
|
|
969
|
-
* copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
|
|
970
|
-
* updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
|
|
971
|
-
* the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
|
|
972
|
-
* field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
|
|
973
|
-
*
|
|
974
|
-
* @param field - The name of the field to pull the existing UI Schema for
|
|
975
|
-
* @param uiProps - Any props that should be put into the field's uiSchema
|
|
976
|
-
* @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
|
|
977
|
-
* @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
|
|
978
|
-
* @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
|
|
979
|
-
*/
|
|
980
|
-
static computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
|
|
981
|
-
const globalUiOptions = (0, import_get2.default)(uiSchema, [import_utils3.UI_GLOBAL_OPTIONS_KEY], {});
|
|
982
|
-
const localUiSchema = (0, import_get2.default)(uiSchema, field);
|
|
983
|
-
const localUiOptions = { ...(0, import_get2.default)(localUiSchema, [import_utils3.UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
|
|
984
|
-
const fieldUiSchema = { ...localUiSchema };
|
|
985
|
-
if (!(0, import_isEmpty.default)(localUiOptions)) {
|
|
986
|
-
(0, import_set2.default)(fieldUiSchema, [import_utils3.UI_OPTIONS_KEY], localUiOptions);
|
|
987
|
-
}
|
|
988
|
-
if (!(0, import_isEmpty.default)(globalUiOptions)) {
|
|
989
|
-
(0, import_set2.default)(fieldUiSchema, [import_utils3.UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
|
|
990
|
-
}
|
|
991
|
-
let { readonly: uiReadonly } = (0, import_utils3.getUiOptions)(fieldUiSchema);
|
|
992
|
-
if (forceReadonly === true || (0, import_isUndefined.default)(uiReadonly) && schemaReadonly === true) {
|
|
993
|
-
uiReadonly = true;
|
|
994
|
-
if ((0, import_has.default)(localUiOptions, import_utils3.READONLY_KEY)) {
|
|
995
|
-
(0, import_set2.default)(fieldUiSchema, [import_utils3.UI_OPTIONS_KEY, import_utils3.READONLY_KEY], true);
|
|
996
|
-
} else {
|
|
997
|
-
(0, import_set2.default)(fieldUiSchema, `ui:${import_utils3.READONLY_KEY}`, true);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
return { fieldUiSchema, uiReadonly };
|
|
1001
|
-
}
|
|
1002
|
-
/** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
|
|
1003
|
-
* depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
|
|
1004
|
-
* contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
|
|
1005
|
-
* equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
|
|
1006
|
-
* common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
|
|
1007
|
-
* to match.
|
|
1008
|
-
*
|
|
1009
|
-
* @param [operator] - The optional operator for the condition
|
|
1010
|
-
* @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
|
|
1011
|
-
* @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
|
|
1012
|
-
* to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
|
|
1013
|
-
* This can be an item or a list of items of type unknown
|
|
1014
|
-
* @returns - True if the condition matches, false otherwise
|
|
1015
|
-
*/
|
|
1016
|
-
static conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
|
|
1017
|
-
const data = (0, import_flatten.default)([datum]).sort();
|
|
1018
|
-
const values = (0, import_flatten.default)([value]).sort();
|
|
1019
|
-
switch (operator) {
|
|
1020
|
-
case "all" /* ALL */:
|
|
1021
|
-
return (0, import_isEqual.default)(data, values);
|
|
1022
|
-
case "some" /* SOME */:
|
|
1023
|
-
return (0, import_intersection.default)(data, values).length > 0;
|
|
1024
|
-
case "none" /* NONE */:
|
|
1025
|
-
return (0, import_intersection.default)(data, values).length === 0;
|
|
1026
|
-
default:
|
|
1027
|
-
return false;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
/** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
|
|
1031
|
-
* `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
|
|
1032
|
-
* lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
|
|
1033
|
-
* When the `className` value contains multiple classNames separated by a space, the lookup will look for a
|
|
1034
|
-
* replacement value for each `className` and combine them into one.
|
|
1035
|
-
*
|
|
1036
|
-
* @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
|
|
1037
|
-
* @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
|
|
1038
|
-
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
1039
|
-
* @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
|
|
1040
|
-
* @throws - A `TypeError` when the `children` is not an array
|
|
1041
|
-
*/
|
|
1042
|
-
static findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
|
|
1043
|
-
let gridProps = {};
|
|
1044
|
-
let children = layoutGridSchema[schemaKey];
|
|
1045
|
-
if ((0, import_isPlainObject.default)(children)) {
|
|
1046
|
-
const { children: elements, className: toMapClassNames, ...otherProps } = children;
|
|
1047
|
-
children = elements;
|
|
1048
|
-
if (toMapClassNames) {
|
|
1049
|
-
const classes = toMapClassNames.split(" ");
|
|
1050
|
-
const className = classes.map((ele) => (0, import_utils3.lookupFromFormContext)(registry, ele, ele)).join(" ");
|
|
1051
|
-
gridProps = { ...otherProps, className };
|
|
1052
|
-
} else {
|
|
1053
|
-
gridProps = otherProps;
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
if (!Array.isArray(children)) {
|
|
1057
|
-
throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
|
|
1058
|
-
}
|
|
1059
|
-
return { children, gridProps };
|
|
1060
|
-
}
|
|
1061
|
-
/** Generates an idSchema for the `schema` using `@rjsf`'s `toIdSchema` util, passing the `baseIdSchema`'s `$id` value
|
|
1062
|
-
* as the id prefix.
|
|
1063
|
-
*
|
|
1064
|
-
* @param schemaUtils - The `SchemaUtilsType` used to call `toIdSchema`
|
|
1065
|
-
* @param schema - The schema to generate the idSchema for
|
|
1066
|
-
* @param baseIdSchema - The IdSchema for the base
|
|
1067
|
-
* @param formData - The formData to pass the `toIdSchema`
|
|
1068
|
-
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
1069
|
-
* @returns - The generated `idSchema` for the `schema`
|
|
1070
|
-
*/
|
|
1071
|
-
static getIdSchema(schemaUtils, baseIdSchema, formData, schema = {}, idSeparator) {
|
|
1072
|
-
const baseId = (0, import_get2.default)(baseIdSchema, import_utils3.ID_KEY);
|
|
1073
|
-
return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
|
|
1074
|
-
}
|
|
1075
|
-
/** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
|
|
1076
|
-
* the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
|
|
1077
|
-
* element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
|
|
1078
|
-
* `options`.
|
|
1079
|
-
*
|
|
1080
|
-
* @param schemaUtils - The `SchemaUtilsType` used to call `retrieveSchema`
|
|
1081
|
-
* @param dottedPath - The dotted-path to the field for which to get the schema
|
|
1082
|
-
* @param initialSchema - The initial schema to start the search from
|
|
1083
|
-
* @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
|
|
1084
|
-
* @param initialIdSchema - The initial idSchema to start the search from
|
|
1085
|
-
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
1086
|
-
* @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
|
|
1087
|
-
* info if a oneOf/anyOf
|
|
1088
|
-
*/
|
|
1089
|
-
static getSchemaDetailsForField(schemaUtils, dottedPath, initialSchema, formData, initialIdSchema, idSeparator) {
|
|
1090
|
-
let rawSchema = initialSchema;
|
|
1091
|
-
let idSchema = initialIdSchema;
|
|
1092
|
-
const parts = dottedPath.split(".");
|
|
1093
|
-
const leafPath = parts.pop();
|
|
1094
|
-
let schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1095
|
-
let innerData = formData;
|
|
1096
|
-
let isReadonly = schema.readOnly;
|
|
1097
|
-
parts.forEach((part) => {
|
|
1098
|
-
if ((0, import_has.default)(schema, import_utils3.PROPERTIES_KEY)) {
|
|
1099
|
-
rawSchema = (0, import_get2.default)(schema, [import_utils3.PROPERTIES_KEY, part], {});
|
|
1100
|
-
idSchema = (0, import_get2.default)(idSchema, part, {});
|
|
1101
|
-
} else if (schema && ((0, import_has.default)(schema, import_utils3.ONE_OF_KEY) || (0, import_has.default)(schema, import_utils3.ANY_OF_KEY))) {
|
|
1102
|
-
const xxx = (0, import_has.default)(schema, import_utils3.ONE_OF_KEY) ? import_utils3.ONE_OF_KEY : import_utils3.ANY_OF_KEY;
|
|
1103
|
-
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
|
|
1104
|
-
const selectedIdSchema = _LayoutGridField.getIdSchema(
|
|
1105
|
-
schemaUtils,
|
|
1106
|
-
idSchema,
|
|
1107
|
-
formData,
|
|
1108
|
-
selectedSchema,
|
|
1109
|
-
idSeparator
|
|
1110
|
-
);
|
|
1111
|
-
rawSchema = (0, import_get2.default)(selectedSchema, [import_utils3.PROPERTIES_KEY, part], {});
|
|
1112
|
-
idSchema = (0, import_get2.default)(selectedIdSchema, part, {});
|
|
1113
|
-
} else {
|
|
1114
|
-
rawSchema = {};
|
|
1115
|
-
}
|
|
1116
|
-
innerData = (0, import_get2.default)(innerData, part, {});
|
|
1117
|
-
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
1118
|
-
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
|
|
1119
|
-
});
|
|
1120
|
-
let optionsInfo;
|
|
1121
|
-
let isRequired = false;
|
|
1122
|
-
if ((0, import_isEmpty.default)(schema)) {
|
|
1123
|
-
schema = void 0;
|
|
1124
|
-
}
|
|
1125
|
-
if (schema && leafPath) {
|
|
1126
|
-
if (schema && ((0, import_has.default)(schema, import_utils3.ONE_OF_KEY) || (0, import_has.default)(schema, import_utils3.ANY_OF_KEY))) {
|
|
1127
|
-
const xxx = (0, import_has.default)(schema, import_utils3.ONE_OF_KEY) ? import_utils3.ONE_OF_KEY : import_utils3.ANY_OF_KEY;
|
|
1128
|
-
schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
|
|
1129
|
-
const rawIdSchema = _LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, schema, idSeparator);
|
|
1130
|
-
idSchema = (0, import_utils3.mergeObjects)(rawIdSchema, idSchema);
|
|
1131
|
-
}
|
|
1132
|
-
isRequired = schema !== void 0 && Array.isArray(schema.required) && (0, import_includes.default)(schema.required, leafPath);
|
|
1133
|
-
schema = (0, import_get2.default)(schema, [import_utils3.PROPERTIES_KEY, leafPath]);
|
|
1134
|
-
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1135
|
-
idSchema = (0, import_get2.default)(idSchema, leafPath, {});
|
|
1136
|
-
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1137
|
-
if (schema && ((0, import_has.default)(schema, import_utils3.ONE_OF_KEY) || (0, import_has.default)(schema, import_utils3.ANY_OF_KEY))) {
|
|
1138
|
-
const xxx = (0, import_has.default)(schema, import_utils3.ONE_OF_KEY) ? import_utils3.ONE_OF_KEY : import_utils3.ANY_OF_KEY;
|
|
1139
|
-
const discriminator = (0, import_utils3.getDiscriminatorFieldFromSchema)(schema);
|
|
1140
|
-
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
return { schema, isRequired, isReadonly, optionsInfo, idSchema };
|
|
1144
|
-
}
|
|
1145
|
-
/** Gets the custom render component from the `render`, by either determining that it is either already a function or
|
|
1146
|
-
* it is a non-function value that can be used to look up the function in the registry. If no function can be found,
|
|
1147
|
-
* null is returned.
|
|
1148
|
-
*
|
|
1149
|
-
* @param render - The potential render function or lookup name to one
|
|
1150
|
-
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
1151
|
-
* @returns - Either a render function if available, or null if not
|
|
1152
|
-
*/
|
|
1153
|
-
static getCustomRenderComponent(render, registry) {
|
|
1154
|
-
let customRenderer = render;
|
|
1155
|
-
if ((0, import_isString.default)(customRenderer)) {
|
|
1156
|
-
customRenderer = (0, import_utils3.lookupFromFormContext)(registry, customRenderer);
|
|
1157
|
-
}
|
|
1158
|
-
if ((0, import_isFunction.default)(customRenderer)) {
|
|
1159
|
-
return customRenderer;
|
|
1160
|
-
}
|
|
1161
|
-
return null;
|
|
1162
|
-
}
|
|
1163
|
-
/** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
|
|
1164
|
-
* see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
|
|
1165
|
-
* set the `rendered` component with only specified props for that component in the object.
|
|
1166
|
-
*
|
|
1167
|
-
* @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
|
|
1168
|
-
* @param gridSchema - The string or object that represents the configuration for the grid field
|
|
1169
|
-
* @returns - The UIComponentPropsType computed from the gridSchema
|
|
1170
|
-
*/
|
|
1171
|
-
static computeUIComponentPropsFromGridSchema(registry, gridSchema) {
|
|
1172
|
-
let name;
|
|
1173
|
-
let UIComponent = null;
|
|
1174
|
-
let uiProps = {};
|
|
1175
|
-
let rendered;
|
|
1176
|
-
if ((0, import_isString.default)(gridSchema) || (0, import_isUndefined.default)(gridSchema)) {
|
|
1177
|
-
name = gridSchema ?? "";
|
|
1178
|
-
} else {
|
|
1179
|
-
const { name: innerName = "", render, ...innerProps } = gridSchema;
|
|
1180
|
-
name = innerName;
|
|
1181
|
-
uiProps = innerProps;
|
|
1182
|
-
if (!(0, import_isEmpty.default)(uiProps)) {
|
|
1183
|
-
(0, import_each.default)(uiProps, (prop, key) => {
|
|
1184
|
-
if ((0, import_isString.default)(prop)) {
|
|
1185
|
-
const match = LOOKUP_REGEX.exec(prop);
|
|
1186
|
-
if (Array.isArray(match) && match.length > 1) {
|
|
1187
|
-
const name2 = match[1];
|
|
1188
|
-
uiProps[key] = (0, import_utils3.lookupFromFormContext)(registry, name2, name2);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1193
|
-
UIComponent = _LayoutGridField.getCustomRenderComponent(render, registry);
|
|
1194
|
-
if (!innerName && UIComponent) {
|
|
1195
|
-
rendered = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UIComponent, { ...innerProps, "data-testid": _LayoutGridField.TEST_IDS.uiComponent });
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
return { name, UIComponent, uiProps, rendered };
|
|
1199
|
-
}
|
|
1200
|
-
/** Constructs an `LayoutGridField` with the given `props`
|
|
1201
|
-
*
|
|
1202
|
-
* @param props - The `LayoutGridField` for this template
|
|
1203
|
-
*/
|
|
1204
|
-
constructor(props) {
|
|
1205
|
-
super(props);
|
|
1206
|
-
}
|
|
1207
|
-
/** Generates an `onChange` handler for the field associated with the `dottedPath`. This handler will clone and update
|
|
1208
|
-
* the `formData` with the new `value` and the `errorSchema` if an `errSchema` is provided. After updating those two
|
|
1209
|
-
* elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
|
|
1210
|
-
*
|
|
1211
|
-
* @param dottedPath - The dotted-path to the field for which to generate the onChange handler
|
|
1212
|
-
* @returns - The `onChange` handling function for the `dottedPath` field
|
|
1213
|
-
*/
|
|
1214
|
-
onFieldChange = (dottedPath) => {
|
|
1215
|
-
return (value, errSchema, id) => {
|
|
1216
|
-
const { onChange, errorSchema, formData } = this.props;
|
|
1217
|
-
const newFormData = (0, import_cloneDeep2.default)(formData || {});
|
|
1218
|
-
let newErrorSchema = errorSchema;
|
|
1219
|
-
if (errSchema && errorSchema) {
|
|
1220
|
-
newErrorSchema = (0, import_cloneDeep2.default)(errorSchema);
|
|
1221
|
-
(0, import_set2.default)(newErrorSchema, dottedPath, errSchema);
|
|
1222
|
-
}
|
|
1223
|
-
(0, import_set2.default)(newFormData, dottedPath, value);
|
|
1224
|
-
onChange(newFormData, newErrorSchema, id);
|
|
1225
|
-
};
|
|
1226
|
-
};
|
|
1227
|
-
/** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
|
|
1228
|
-
* `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
|
|
1229
|
-
* the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
|
|
1230
|
-
* rendered, otherwise null is returned.
|
|
1231
|
-
*
|
|
1232
|
-
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1233
|
-
* @returns - The rendered the children for the `GridType.CONDITION` or null
|
|
1234
|
-
*/
|
|
1235
|
-
renderCondition(layoutGridSchema) {
|
|
1236
|
-
const { formData, registry } = this.props;
|
|
1237
|
-
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1238
|
-
layoutGridSchema,
|
|
1239
|
-
"ui:condition" /* CONDITION */,
|
|
1240
|
-
registry
|
|
1241
|
-
);
|
|
1242
|
-
const { operator, field = "", value } = gridProps;
|
|
1243
|
-
const fieldData = (0, import_get2.default)(formData, field, null);
|
|
1244
|
-
if (_LayoutGridField.conditionMatches(operator, fieldData, value)) {
|
|
1245
|
-
return this.renderChildren(children);
|
|
1246
|
-
}
|
|
1247
|
-
return null;
|
|
1248
|
-
}
|
|
1249
|
-
/** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated
|
|
1250
|
-
* into the `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside
|
|
1251
|
-
* the `GridTemplate` all the `children` are rendered.
|
|
1252
|
-
*
|
|
1253
|
-
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1254
|
-
* @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
|
|
1255
|
-
*/
|
|
1256
|
-
renderCol(layoutGridSchema) {
|
|
1257
|
-
const { registry, uiSchema } = this.props;
|
|
1258
|
-
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1259
|
-
layoutGridSchema,
|
|
1260
|
-
"ui:col" /* COLUMN */,
|
|
1261
|
-
registry
|
|
1262
|
-
);
|
|
1263
|
-
const uiOptions = (0, import_utils3.getUiOptions)(uiSchema);
|
|
1264
|
-
const GridTemplate2 = (0, import_utils3.getTemplate)("GridTemplate", registry, uiOptions);
|
|
1265
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(GridTemplate2, { column: true, "data-testid": _LayoutGridField.TEST_IDS.col, ...gridProps, children: this.renderChildren(children) });
|
|
1266
|
-
}
|
|
1267
|
-
/** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated
|
|
1268
|
-
* into the `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the
|
|
1269
|
-
* outer `GridTemplate`. Each child will have their own rendered `GridTemplate`.
|
|
1270
|
-
*
|
|
1271
|
-
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1272
|
-
* @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
|
|
1273
|
-
*/
|
|
1274
|
-
renderColumns(layoutGridSchema) {
|
|
1275
|
-
const { registry, uiSchema } = this.props;
|
|
1276
|
-
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1277
|
-
layoutGridSchema,
|
|
1278
|
-
"ui:columns" /* COLUMNS */,
|
|
1279
|
-
registry
|
|
1280
|
-
);
|
|
1281
|
-
const uiOptions = (0, import_utils3.getUiOptions)(uiSchema);
|
|
1282
|
-
const GridTemplate2 = (0, import_utils3.getTemplate)("GridTemplate", registry, uiOptions);
|
|
1283
|
-
return children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1284
|
-
GridTemplate2,
|
|
1285
|
-
{
|
|
1286
|
-
column: true,
|
|
1287
|
-
"data-testid": _LayoutGridField.TEST_IDS.col,
|
|
1288
|
-
...gridProps,
|
|
1289
|
-
children: this.renderChildren([child])
|
|
1290
|
-
},
|
|
1291
|
-
`column-${(0, import_utils3.hashObject)(child)}`
|
|
1292
|
-
));
|
|
1293
|
-
}
|
|
1294
|
-
/** Renders a material-ui `GridTemplate` as a container. The
|
|
1295
|
-
* `layoutGridSchema` for the `GridType.ROW` is separated into the `children` and other `gridProps`. The `gridProps`
|
|
1296
|
-
* will be spread onto the outer `GridTemplate`. Inside of the `GridTemplate` all of the `children` are rendered.
|
|
1297
|
-
*
|
|
1298
|
-
* @param layoutGridSchema - The string or object that represents the configuration for the grid field
|
|
1299
|
-
* @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
|
|
1300
|
-
*/
|
|
1301
|
-
renderRow(layoutGridSchema) {
|
|
1302
|
-
const { registry, uiSchema } = this.props;
|
|
1303
|
-
const { children, gridProps } = _LayoutGridField.findChildrenAndProps(
|
|
1304
|
-
layoutGridSchema,
|
|
1305
|
-
"ui:row" /* ROW */,
|
|
1306
|
-
registry
|
|
1307
|
-
);
|
|
1308
|
-
const uiOptions = (0, import_utils3.getUiOptions)(uiSchema);
|
|
1309
|
-
const GridTemplate2 = (0, import_utils3.getTemplate)("GridTemplate", registry, uiOptions);
|
|
1310
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(GridTemplate2, { ...gridProps, "data-testid": _LayoutGridField.TEST_IDS.row, children: this.renderChildren(children) });
|
|
1311
|
-
}
|
|
1312
|
-
/** Iterates through all the `childrenLayoutGridSchema`, rendering a nested `LayoutGridField` for each item in the
|
|
1313
|
-
* list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
|
|
1314
|
-
* `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
|
|
1315
|
-
* `childrenLayoutGridSchema` is passed as `layoutGridSchema`.
|
|
1316
|
-
*
|
|
1317
|
-
* @param childrenLayoutGridSchema - The list of strings or objects that represents the configurations for the
|
|
1318
|
-
* children fields
|
|
1319
|
-
* @returns - The nested `LayoutGridField`s
|
|
1320
|
-
*/
|
|
1321
|
-
renderChildren(childrenLayoutGridSchema) {
|
|
1322
|
-
const { registry, schema: rawSchema, formData } = this.props;
|
|
1323
|
-
const { schemaUtils } = registry;
|
|
1324
|
-
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1325
|
-
return childrenLayoutGridSchema.map((layoutGridSchema) => /* @__PURE__ */ (0, import_react3.createElement)(
|
|
1326
|
-
_LayoutGridField,
|
|
1327
|
-
{
|
|
1328
|
-
...this.props,
|
|
1329
|
-
key: `layoutGrid-${(0, import_utils3.hashObject)(layoutGridSchema)}`,
|
|
1330
|
-
schema,
|
|
1331
|
-
layoutGridSchema
|
|
1332
|
-
}
|
|
1333
|
-
));
|
|
1334
|
-
}
|
|
1335
|
-
/** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
|
|
1336
|
-
* to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
|
|
1337
|
-
* other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
|
|
1338
|
-
* specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
|
|
1339
|
-
* and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
|
|
1340
|
-
* schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
|
|
1341
|
-
* `uiSchema`, `errorSchema`, `idSchema` and `formData` drilled down to the dotted-path field, spreading any other
|
|
1342
|
-
* props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
|
|
1343
|
-
* then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
|
|
1344
|
-
* schema was located, but a custom render component was found, then it will be rendered with many of the non-event
|
|
1345
|
-
* handling props. If none of the previous render paths are valid, then a null is returned.
|
|
1346
|
-
*
|
|
1347
|
-
* @param gridSchema - The string or object that represents the configuration for the grid field
|
|
1348
|
-
* @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
|
|
1349
|
-
*/
|
|
1350
|
-
renderField(gridSchema) {
|
|
1351
|
-
const {
|
|
1352
|
-
schema: initialSchema,
|
|
1353
|
-
uiSchema,
|
|
1354
|
-
errorSchema,
|
|
1355
|
-
idSchema,
|
|
1356
|
-
onBlur,
|
|
1357
|
-
onFocus,
|
|
1358
|
-
formData,
|
|
1359
|
-
readonly,
|
|
1360
|
-
registry,
|
|
1361
|
-
idSeparator,
|
|
1362
|
-
layoutGridSchema,
|
|
1363
|
-
// Used to pull this out of otherProps since we don't want to pass it through
|
|
1364
|
-
...otherProps
|
|
1365
|
-
} = this.props;
|
|
1366
|
-
const { fields: fields2, schemaUtils } = registry;
|
|
1367
|
-
const { SchemaField: SchemaField2, LayoutMultiSchemaField: LayoutMultiSchemaField2 } = fields2;
|
|
1368
|
-
const uiComponentProps = _LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
|
|
1369
|
-
if (uiComponentProps.rendered) {
|
|
1370
|
-
return uiComponentProps.rendered;
|
|
1371
|
-
}
|
|
1372
|
-
const { name, UIComponent, uiProps } = uiComponentProps;
|
|
1373
|
-
const {
|
|
1374
|
-
schema,
|
|
1375
|
-
isRequired,
|
|
1376
|
-
isReadonly,
|
|
1377
|
-
optionsInfo,
|
|
1378
|
-
idSchema: fieldIdSchema
|
|
1379
|
-
} = _LayoutGridField.getSchemaDetailsForField(
|
|
1380
|
-
schemaUtils,
|
|
1381
|
-
name,
|
|
1382
|
-
initialSchema,
|
|
1383
|
-
formData,
|
|
1384
|
-
idSchema,
|
|
1385
|
-
idSeparator
|
|
1386
|
-
);
|
|
1387
|
-
if (schema) {
|
|
1388
|
-
const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
|
|
1389
|
-
const { fieldUiSchema, uiReadonly } = _LayoutGridField.computeFieldUiSchema(
|
|
1390
|
-
name,
|
|
1391
|
-
uiProps,
|
|
1392
|
-
uiSchema,
|
|
1393
|
-
isReadonly,
|
|
1394
|
-
readonly
|
|
1395
|
-
);
|
|
1396
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1397
|
-
Field,
|
|
1398
|
-
{
|
|
1399
|
-
"data-testid": optionsInfo?.hasDiscriminator ? _LayoutGridField.TEST_IDS.layoutMultiSchemaField : _LayoutGridField.TEST_IDS.field,
|
|
1400
|
-
...otherProps,
|
|
1401
|
-
name,
|
|
1402
|
-
required: isRequired,
|
|
1403
|
-
readonly: uiReadonly,
|
|
1404
|
-
schema,
|
|
1405
|
-
uiSchema: fieldUiSchema,
|
|
1406
|
-
errorSchema: (0, import_get2.default)(errorSchema, name),
|
|
1407
|
-
idSchema: fieldIdSchema,
|
|
1408
|
-
idSeparator,
|
|
1409
|
-
formData: (0, import_get2.default)(formData, name),
|
|
1410
|
-
onChange: this.onFieldChange(name),
|
|
1411
|
-
onBlur,
|
|
1412
|
-
onFocus,
|
|
1413
|
-
options: optionsInfo?.options,
|
|
1414
|
-
registry
|
|
1415
|
-
}
|
|
1416
|
-
);
|
|
1417
|
-
}
|
|
1418
|
-
if (UIComponent) {
|
|
1419
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1420
|
-
UIComponent,
|
|
1421
|
-
{
|
|
1422
|
-
"data-testid": _LayoutGridField.TEST_IDS.uiComponent,
|
|
1423
|
-
...otherProps,
|
|
1424
|
-
name,
|
|
1425
|
-
required: isRequired,
|
|
1426
|
-
formData,
|
|
1427
|
-
readOnly: !!isReadonly || readonly,
|
|
1428
|
-
errorSchema,
|
|
1429
|
-
uiSchema,
|
|
1430
|
-
schema: initialSchema,
|
|
1431
|
-
idSchema,
|
|
1432
|
-
idSeparator,
|
|
1433
|
-
onBlur,
|
|
1434
|
-
onFocus,
|
|
1435
|
-
registry,
|
|
1436
|
-
...uiProps
|
|
1437
|
-
}
|
|
1438
|
-
);
|
|
1439
|
-
}
|
|
1440
|
-
return null;
|
|
1441
|
-
}
|
|
1442
|
-
/** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
|
|
1443
|
-
* `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
|
|
1444
|
-
* match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
|
|
1445
|
-
* generic `renderField()` function with the `layoutGridSchema`.
|
|
1446
|
-
*
|
|
1447
|
-
* @returns - the rendered `LayoutGridField`
|
|
1448
|
-
*/
|
|
1449
|
-
render() {
|
|
1450
|
-
const { uiSchema } = this.props;
|
|
1451
|
-
let { layoutGridSchema } = this.props;
|
|
1452
|
-
const uiOptions = (0, import_utils3.getUiOptions)(uiSchema);
|
|
1453
|
-
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && (0, import_isObject3.default)(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1454
|
-
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
|
|
1455
|
-
}
|
|
1456
|
-
if ((0, import_isObject3.default)(layoutGridSchema)) {
|
|
1457
|
-
if ("ui:row" /* ROW */ in layoutGridSchema) {
|
|
1458
|
-
return this.renderRow(layoutGridSchema);
|
|
1459
|
-
}
|
|
1460
|
-
if ("ui:col" /* COLUMN */ in layoutGridSchema) {
|
|
1461
|
-
return this.renderCol(layoutGridSchema);
|
|
1462
|
-
}
|
|
1463
|
-
if ("ui:columns" /* COLUMNS */ in layoutGridSchema) {
|
|
1464
|
-
return this.renderColumns(layoutGridSchema);
|
|
1465
|
-
}
|
|
1466
|
-
if ("ui:condition" /* CONDITION */ in layoutGridSchema) {
|
|
1467
|
-
return this.renderCondition(layoutGridSchema);
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
return this.renderField(layoutGridSchema);
|
|
1471
|
-
}
|
|
1472
|
-
};
|
|
1473
|
-
|
|
1474
|
-
// src/components/fields/LayoutHeaderField.tsx
|
|
1475
|
-
var import_utils4 = require("@rjsf/utils");
|
|
1476
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1477
|
-
function LayoutHeaderField(props) {
|
|
1478
|
-
const { idSchema, title, schema, uiSchema, required, registry, name } = props;
|
|
1479
|
-
const options = (0, import_utils4.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
1480
|
-
const { title: uiTitle } = options;
|
|
1481
|
-
const { title: schemaTitle } = schema;
|
|
1482
|
-
const fieldTitle = uiTitle || title || schemaTitle || name;
|
|
1483
|
-
if (!fieldTitle) {
|
|
1484
|
-
return null;
|
|
1485
|
-
}
|
|
1486
|
-
const TitleFieldTemplate = (0, import_utils4.getTemplate)(
|
|
1487
|
-
"TitleFieldTemplate",
|
|
1488
|
-
registry,
|
|
1489
|
-
options
|
|
1490
|
-
);
|
|
1491
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1492
|
-
TitleFieldTemplate,
|
|
1493
|
-
{
|
|
1494
|
-
id: (0, import_utils4.titleId)(idSchema),
|
|
1495
|
-
title: fieldTitle,
|
|
1496
|
-
required,
|
|
1497
|
-
schema,
|
|
1498
|
-
uiSchema,
|
|
1499
|
-
registry
|
|
1500
|
-
}
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
// src/components/fields/LayoutMultiSchemaField.tsx
|
|
1505
|
-
var import_react4 = require("react");
|
|
1506
|
-
var import_utils5 = require("@rjsf/utils");
|
|
1507
|
-
var import_get3 = __toESM(require("lodash/get"), 1);
|
|
1508
|
-
var import_has2 = __toESM(require("lodash/has"), 1);
|
|
1509
|
-
var import_isEmpty2 = __toESM(require("lodash/isEmpty"), 1);
|
|
1510
|
-
var import_noop = __toESM(require("lodash/noop"), 1);
|
|
1511
|
-
var import_omit = __toESM(require("lodash/omit"), 1);
|
|
1512
|
-
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
1513
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1514
|
-
function getSelectedOption(options, selectorField, value) {
|
|
1515
|
-
const defaultValue = "!@#!@$@#$!@$#";
|
|
1516
|
-
const schemaOptions = options.map(({ schema }) => schema);
|
|
1517
|
-
return schemaOptions.find((option) => {
|
|
1518
|
-
const selector = (0, import_get3.default)(option, [import_utils5.PROPERTIES_KEY, selectorField]);
|
|
1519
|
-
const result = (0, import_get3.default)(selector, import_utils5.DEFAULT_KEY, (0, import_get3.default)(selector, import_utils5.CONST_KEY, defaultValue));
|
|
1520
|
-
return result === value;
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
function computeEnumOptions(schema, options, schemaUtils, uiSchema, formData) {
|
|
1524
|
-
const realOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
1525
|
-
let tempSchema = schema;
|
|
1526
|
-
if ((0, import_has2.default)(schema, import_utils5.ONE_OF_KEY)) {
|
|
1527
|
-
tempSchema = { ...schema, [import_utils5.ONE_OF_KEY]: realOptions };
|
|
1528
|
-
} else if ((0, import_has2.default)(schema, import_utils5.ANY_OF_KEY)) {
|
|
1529
|
-
tempSchema = { ...schema, [import_utils5.ANY_OF_KEY]: realOptions };
|
|
1530
|
-
}
|
|
1531
|
-
const enumOptions = (0, import_utils5.optionsList)(tempSchema, uiSchema);
|
|
1532
|
-
if (!enumOptions) {
|
|
1533
|
-
throw new Error(`No enumOptions were computed from the schema ${JSON.stringify(tempSchema)}`);
|
|
1534
|
-
}
|
|
1535
|
-
return enumOptions;
|
|
1536
|
-
}
|
|
1537
|
-
function LayoutMultiSchemaField(props) {
|
|
1538
|
-
const {
|
|
1539
|
-
name,
|
|
1540
|
-
baseType,
|
|
1541
|
-
disabled = false,
|
|
1542
|
-
formData,
|
|
1543
|
-
idSchema,
|
|
1544
|
-
onBlur,
|
|
1545
|
-
onChange,
|
|
1546
|
-
options,
|
|
1547
|
-
onFocus,
|
|
1548
|
-
registry,
|
|
1549
|
-
uiSchema,
|
|
1550
|
-
schema,
|
|
1551
|
-
formContext,
|
|
1552
|
-
autofocus,
|
|
1553
|
-
readonly,
|
|
1554
|
-
required,
|
|
1555
|
-
errorSchema,
|
|
1556
|
-
hideError = false
|
|
1557
|
-
} = props;
|
|
1558
|
-
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
1559
|
-
const [enumOptions, setEnumOptions] = (0, import_react4.useState)(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1560
|
-
const id = (0, import_get3.default)(idSchema, import_utils5.ID_KEY);
|
|
1561
|
-
const discriminator = (0, import_utils5.getDiscriminatorFieldFromSchema)(schema);
|
|
1562
|
-
const FieldErrorTemplate2 = (0, import_utils5.getTemplate)("FieldErrorTemplate", registry, options);
|
|
1563
|
-
const FieldTemplate2 = (0, import_utils5.getTemplate)("FieldTemplate", registry, options);
|
|
1564
|
-
const schemaHash = (0, import_utils5.hashObject)(schema);
|
|
1565
|
-
const optionsHash = (0, import_utils5.hashObject)(options);
|
|
1566
|
-
const uiSchemaHash = uiSchema ? (0, import_utils5.hashObject)(uiSchema) : "";
|
|
1567
|
-
const formDataHash = formData ? (0, import_utils5.hashObject)(formData) : "";
|
|
1568
|
-
(0, import_react4.useEffect)(() => {
|
|
1569
|
-
setEnumOptions(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1570
|
-
}, [schemaHash, optionsHash, schemaUtils, uiSchemaHash, formDataHash]);
|
|
1571
|
-
const {
|
|
1572
|
-
widget = discriminator ? "radio" : "select",
|
|
1573
|
-
title = "",
|
|
1574
|
-
placeholder = "",
|
|
1575
|
-
optionsSchemaSelector: selectorField = discriminator,
|
|
1576
|
-
hideError: uiSchemaHideError,
|
|
1577
|
-
...uiOptions
|
|
1578
|
-
} = (0, import_utils5.getUiOptions)(uiSchema);
|
|
1579
|
-
if (!selectorField) {
|
|
1580
|
-
throw new Error("No selector field provided for the LayoutMultiSchemaField");
|
|
1581
|
-
}
|
|
1582
|
-
const selectedOption = (0, import_get3.default)(formData, selectorField);
|
|
1583
|
-
let optionSchema = (0, import_get3.default)(enumOptions[0]?.schema, [import_utils5.PROPERTIES_KEY, selectorField], {});
|
|
1584
|
-
const option = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1585
|
-
optionSchema = optionSchema?.type ? optionSchema : { ...optionSchema, type: option?.type || baseType };
|
|
1586
|
-
const Widget = (0, import_utils5.getWidget)(optionSchema, widget, widgets2);
|
|
1587
|
-
const hideFieldError = uiSchemaHideError === void 0 ? hideError : Boolean(uiSchemaHideError);
|
|
1588
|
-
const rawErrors = (0, import_get3.default)(errorSchema, [import_utils5.ERRORS_KEY], []);
|
|
1589
|
-
const fieldErrorSchema = (0, import_omit.default)(errorSchema, [import_utils5.ERRORS_KEY]);
|
|
1590
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1591
|
-
const onOptionChange = (opt) => {
|
|
1592
|
-
const newOption = getSelectedOption(enumOptions, selectorField, opt);
|
|
1593
|
-
const oldOption = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1594
|
-
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
1595
|
-
if (newFormData && newOption) {
|
|
1596
|
-
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
1597
|
-
}
|
|
1598
|
-
if (newFormData) {
|
|
1599
|
-
(0, import_set3.default)(newFormData, selectorField, opt);
|
|
1600
|
-
}
|
|
1601
|
-
onChange(newFormData, void 0, id);
|
|
1602
|
-
};
|
|
1603
|
-
const widgetOptions = { enumOptions, ...uiOptions };
|
|
1604
|
-
const errors = !hideFieldError && rawErrors.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldErrorTemplate2, { idSchema, schema, errors: rawErrors, registry }) : void 0;
|
|
1605
|
-
const ignored = (value) => import_noop.default;
|
|
1606
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1607
|
-
FieldTemplate2,
|
|
1608
|
-
{
|
|
1609
|
-
id,
|
|
1610
|
-
schema,
|
|
1611
|
-
label: (title || schema.title) ?? "",
|
|
1612
|
-
disabled: disabled || Array.isArray(enumOptions) && (0, import_isEmpty2.default)(enumOptions),
|
|
1613
|
-
uiSchema,
|
|
1614
|
-
formContext,
|
|
1615
|
-
required,
|
|
1616
|
-
readonly: !!readonly,
|
|
1617
|
-
registry,
|
|
1618
|
-
displayLabel,
|
|
1619
|
-
errors,
|
|
1620
|
-
onChange,
|
|
1621
|
-
onDropPropertyClick: ignored,
|
|
1622
|
-
onKeyChange: ignored,
|
|
1623
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1624
|
-
Widget,
|
|
1625
|
-
{
|
|
1626
|
-
id,
|
|
1627
|
-
name,
|
|
1628
|
-
schema,
|
|
1629
|
-
label: (title || schema.title) ?? "",
|
|
1630
|
-
disabled: disabled || Array.isArray(enumOptions) && (0, import_isEmpty2.default)(enumOptions),
|
|
1631
|
-
uiSchema,
|
|
1632
|
-
formContext,
|
|
1633
|
-
autofocus,
|
|
1634
|
-
readonly,
|
|
1635
|
-
required,
|
|
1636
|
-
registry,
|
|
1637
|
-
multiple: false,
|
|
1638
|
-
rawErrors,
|
|
1639
|
-
hideError: hideFieldError,
|
|
1640
|
-
hideLabel: !displayLabel,
|
|
1641
|
-
errorSchema: fieldErrorSchema,
|
|
1642
|
-
placeholder,
|
|
1643
|
-
onChange: onOptionChange,
|
|
1644
|
-
onBlur,
|
|
1645
|
-
onFocus,
|
|
1646
|
-
value: selectedOption,
|
|
1647
|
-
options: widgetOptions
|
|
1648
|
-
}
|
|
1649
|
-
)
|
|
1650
|
-
}
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
// src/components/fields/MultiSchemaField.tsx
|
|
1655
|
-
var import_react5 = require("react");
|
|
1656
|
-
var import_get4 = __toESM(require("lodash/get"), 1);
|
|
1657
|
-
var import_isEmpty3 = __toESM(require("lodash/isEmpty"), 1);
|
|
1658
|
-
var import_omit2 = __toESM(require("lodash/omit"), 1);
|
|
1659
|
-
var import_utils6 = require("@rjsf/utils");
|
|
1660
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1661
|
-
var AnyOfField = class extends import_react5.Component {
|
|
1662
|
-
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
1663
|
-
*
|
|
1664
|
-
* @param props - The `FieldProps` for this template
|
|
1665
|
-
*/
|
|
1666
|
-
constructor(props) {
|
|
1667
|
-
super(props);
|
|
1668
|
-
const {
|
|
1669
|
-
formData,
|
|
1670
|
-
options,
|
|
1671
|
-
registry: { schemaUtils }
|
|
1672
|
-
} = this.props;
|
|
1673
|
-
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
1674
|
-
this.state = {
|
|
1675
|
-
retrievedOptions,
|
|
1676
|
-
selectedOption: this.getMatchingOption(0, formData, retrievedOptions)
|
|
1677
|
-
};
|
|
1678
|
-
}
|
|
1679
|
-
/** React lifecycle method that is called when the props and/or state for this component is updated. It recomputes the
|
|
1680
|
-
* currently selected option based on the overall `formData`
|
|
1681
|
-
*
|
|
1682
|
-
* @param prevProps - The previous `FieldProps` for this template
|
|
1683
|
-
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
1684
|
-
*/
|
|
1685
|
-
componentDidUpdate(prevProps, prevState) {
|
|
1686
|
-
const { formData, options, idSchema } = this.props;
|
|
1687
|
-
const { selectedOption } = this.state;
|
|
1688
|
-
let newState = this.state;
|
|
1689
|
-
if (!(0, import_utils6.deepEquals)(prevProps.options, options)) {
|
|
1690
|
-
const {
|
|
1691
|
-
registry: { schemaUtils }
|
|
1692
|
-
} = this.props;
|
|
1693
|
-
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
1694
|
-
newState = { selectedOption, retrievedOptions };
|
|
1695
|
-
}
|
|
1696
|
-
if (!(0, import_utils6.deepEquals)(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
|
|
1697
|
-
const { retrievedOptions } = newState;
|
|
1698
|
-
const matchingOption = this.getMatchingOption(selectedOption, formData, retrievedOptions);
|
|
1699
|
-
if (prevState && matchingOption !== selectedOption) {
|
|
1700
|
-
newState = { selectedOption: matchingOption, retrievedOptions };
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
if (newState !== this.state) {
|
|
1704
|
-
this.setState(newState);
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
/** Determines the best matching option for the given `formData` and `options`.
|
|
1708
|
-
*
|
|
1709
|
-
* @param formData - The new formData
|
|
1710
|
-
* @param options - The list of options to choose from
|
|
1711
|
-
* @return - The index of the `option` that best matches the `formData`
|
|
1712
|
-
*/
|
|
1713
|
-
getMatchingOption(selectedOption, formData, options) {
|
|
1714
|
-
const {
|
|
1715
|
-
schema,
|
|
1716
|
-
registry: { schemaUtils }
|
|
1717
|
-
} = this.props;
|
|
1718
|
-
const discriminator = (0, import_utils6.getDiscriminatorFieldFromSchema)(schema);
|
|
1719
|
-
const option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption, discriminator);
|
|
1720
|
-
return option;
|
|
1721
|
-
}
|
|
1722
|
-
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
1723
|
-
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
1724
|
-
* the `onChange` handler.
|
|
1725
|
-
*
|
|
1726
|
-
* @param option - The new option value being selected
|
|
1727
|
-
*/
|
|
1728
|
-
onOptionChange = (option) => {
|
|
1729
|
-
const { selectedOption, retrievedOptions } = this.state;
|
|
1730
|
-
const { formData, onChange, registry } = this.props;
|
|
1731
|
-
const { schemaUtils } = registry;
|
|
1732
|
-
const intOption = option !== void 0 ? parseInt(option, 10) : -1;
|
|
1733
|
-
if (intOption === selectedOption) {
|
|
1734
|
-
return;
|
|
1735
|
-
}
|
|
1736
|
-
const newOption = intOption >= 0 ? retrievedOptions[intOption] : void 0;
|
|
1737
|
-
const oldOption = selectedOption >= 0 ? retrievedOptions[selectedOption] : void 0;
|
|
1738
|
-
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
1739
|
-
if (newOption) {
|
|
1740
|
-
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
1741
|
-
}
|
|
1742
|
-
this.setState({ selectedOption: intOption }, () => {
|
|
1743
|
-
onChange(newFormData, void 0, this.getFieldId());
|
|
1744
|
-
});
|
|
1745
|
-
};
|
|
1746
|
-
getFieldId() {
|
|
1747
|
-
const { idSchema, schema } = this.props;
|
|
1748
|
-
return `${idSchema.$id}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`;
|
|
1749
|
-
}
|
|
1750
|
-
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
1751
|
-
*/
|
|
1752
|
-
render() {
|
|
1753
|
-
const {
|
|
1754
|
-
name,
|
|
1755
|
-
disabled = false,
|
|
1756
|
-
errorSchema = {},
|
|
1757
|
-
formContext,
|
|
1758
|
-
onBlur,
|
|
1759
|
-
onFocus,
|
|
1760
|
-
readonly,
|
|
1761
|
-
registry,
|
|
1762
|
-
schema,
|
|
1763
|
-
uiSchema
|
|
1764
|
-
} = this.props;
|
|
1765
|
-
const { widgets: widgets2, fields: fields2, translateString, globalUiOptions, schemaUtils } = registry;
|
|
1766
|
-
const { SchemaField: _SchemaField } = fields2;
|
|
1767
|
-
const { selectedOption, retrievedOptions } = this.state;
|
|
1768
|
-
const {
|
|
1769
|
-
widget = "select",
|
|
1770
|
-
placeholder,
|
|
1771
|
-
autofocus,
|
|
1772
|
-
autocomplete,
|
|
1773
|
-
title = schema.title,
|
|
1774
|
-
...uiOptions
|
|
1775
|
-
} = (0, import_utils6.getUiOptions)(uiSchema, globalUiOptions);
|
|
1776
|
-
const Widget = (0, import_utils6.getWidget)({ type: "number" }, widget, widgets2);
|
|
1777
|
-
const rawErrors = (0, import_get4.default)(errorSchema, import_utils6.ERRORS_KEY, []);
|
|
1778
|
-
const fieldErrorSchema = (0, import_omit2.default)(errorSchema, [import_utils6.ERRORS_KEY]);
|
|
1779
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1780
|
-
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
1781
|
-
let optionSchema;
|
|
1782
|
-
if (option) {
|
|
1783
|
-
const { required } = schema;
|
|
1784
|
-
optionSchema = required ? (0, import_utils6.mergeSchemas)({ required }, option) : option;
|
|
1785
|
-
}
|
|
1786
|
-
let optionsUiSchema = [];
|
|
1787
|
-
if (import_utils6.ONE_OF_KEY in schema && uiSchema && import_utils6.ONE_OF_KEY in uiSchema) {
|
|
1788
|
-
if (Array.isArray(uiSchema[import_utils6.ONE_OF_KEY])) {
|
|
1789
|
-
optionsUiSchema = uiSchema[import_utils6.ONE_OF_KEY];
|
|
1790
|
-
} else {
|
|
1791
|
-
console.warn(`uiSchema.oneOf is not an array for "${title || name}"`);
|
|
1792
|
-
}
|
|
1793
|
-
} else if (import_utils6.ANY_OF_KEY in schema && uiSchema && import_utils6.ANY_OF_KEY in uiSchema) {
|
|
1794
|
-
if (Array.isArray(uiSchema[import_utils6.ANY_OF_KEY])) {
|
|
1795
|
-
optionsUiSchema = uiSchema[import_utils6.ANY_OF_KEY];
|
|
1796
|
-
} else {
|
|
1797
|
-
console.warn(`uiSchema.anyOf is not an array for "${title || name}"`);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
let optionUiSchema = uiSchema;
|
|
1801
|
-
if (selectedOption >= 0 && optionsUiSchema.length > selectedOption) {
|
|
1802
|
-
optionUiSchema = optionsUiSchema[selectedOption];
|
|
1803
|
-
}
|
|
1804
|
-
const translateEnum = title ? import_utils6.TranslatableString.TitleOptionPrefix : import_utils6.TranslatableString.OptionPrefix;
|
|
1805
|
-
const translateParams = title ? [title] : [];
|
|
1806
|
-
const enumOptions = retrievedOptions.map((opt, index) => {
|
|
1807
|
-
const { title: uiTitle = opt.title } = (0, import_utils6.getUiOptions)(optionsUiSchema[index]);
|
|
1808
|
-
return {
|
|
1809
|
-
label: uiTitle || translateString(translateEnum, translateParams.concat(String(index + 1))),
|
|
1810
|
-
value: index
|
|
1811
|
-
};
|
|
1812
|
-
});
|
|
1813
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "panel panel-default panel-body", children: [
|
|
1814
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "form-group", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1815
|
-
Widget,
|
|
1816
|
-
{
|
|
1817
|
-
id: this.getFieldId(),
|
|
1818
|
-
name: `${name}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`,
|
|
1819
|
-
schema: { type: "number", default: 0 },
|
|
1820
|
-
onChange: this.onOptionChange,
|
|
1821
|
-
onBlur,
|
|
1822
|
-
onFocus,
|
|
1823
|
-
disabled: disabled || (0, import_isEmpty3.default)(enumOptions),
|
|
1824
|
-
multiple: false,
|
|
1825
|
-
rawErrors,
|
|
1826
|
-
errorSchema: fieldErrorSchema,
|
|
1827
|
-
value: selectedOption >= 0 ? selectedOption : void 0,
|
|
1828
|
-
options: { enumOptions, ...uiOptions },
|
|
1829
|
-
registry,
|
|
1830
|
-
formContext,
|
|
1831
|
-
placeholder,
|
|
1832
|
-
autocomplete,
|
|
1833
|
-
autofocus,
|
|
1834
|
-
label: title ?? name,
|
|
1835
|
-
hideLabel: !displayLabel,
|
|
1836
|
-
readonly
|
|
1837
|
-
}
|
|
1838
|
-
) }),
|
|
1839
|
-
optionSchema && optionSchema.type !== "null" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema })
|
|
1840
|
-
] });
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
var MultiSchemaField_default = AnyOfField;
|
|
1844
|
-
|
|
1845
|
-
// src/components/fields/NumberField.tsx
|
|
1846
|
-
var import_react6 = require("react");
|
|
1847
|
-
var import_utils7 = require("@rjsf/utils");
|
|
1848
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1849
|
-
var trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
1850
|
-
var trailingCharMatcher = /[0.]0*$/;
|
|
1851
|
-
function NumberField(props) {
|
|
1852
|
-
const { registry, onChange, formData, value: initialValue } = props;
|
|
1853
|
-
const [lastValue, setLastValue] = (0, import_react6.useState)(initialValue);
|
|
1854
|
-
const { StringField: StringField2 } = registry.fields;
|
|
1855
|
-
let value = formData;
|
|
1856
|
-
const handleChange = (0, import_react6.useCallback)(
|
|
1857
|
-
(value2, errorSchema, id) => {
|
|
1858
|
-
setLastValue(value2);
|
|
1859
|
-
if (`${value2}`.charAt(0) === ".") {
|
|
1860
|
-
value2 = `0${value2}`;
|
|
1861
|
-
}
|
|
1862
|
-
const processed = typeof value2 === "string" && value2.match(trailingCharMatcherWithPrefix) ? (0, import_utils7.asNumber)(value2.replace(trailingCharMatcher, "")) : (0, import_utils7.asNumber)(value2);
|
|
1863
|
-
onChange(processed, errorSchema, id);
|
|
1864
|
-
},
|
|
1865
|
-
[onChange]
|
|
1866
|
-
);
|
|
1867
|
-
if (typeof lastValue === "string" && typeof value === "number") {
|
|
1868
|
-
const re = new RegExp(`^(${String(value).replace(".", "\\.")})?\\.?0*$`);
|
|
1869
|
-
if (lastValue.match(re)) {
|
|
1870
|
-
value = lastValue;
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(StringField2, { ...props, formData: value, onChange: handleChange });
|
|
1874
|
-
}
|
|
1875
|
-
var NumberField_default = NumberField;
|
|
1876
|
-
|
|
1877
|
-
// src/components/fields/ObjectField.tsx
|
|
1878
|
-
var import_react7 = require("react");
|
|
1879
|
-
var import_utils8 = require("@rjsf/utils");
|
|
1880
|
-
var import_markdown_to_jsx = __toESM(require("markdown-to-jsx"), 1);
|
|
1881
|
-
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
1882
|
-
var import_has3 = __toESM(require("lodash/has"), 1);
|
|
1883
|
-
var import_isObject4 = __toESM(require("lodash/isObject"), 1);
|
|
1884
|
-
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
1885
|
-
var import_unset = __toESM(require("lodash/unset"), 1);
|
|
1886
|
-
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1887
|
-
var ObjectField = class extends import_react7.Component {
|
|
1888
|
-
/** Set up the initial state */
|
|
1889
|
-
state = {
|
|
1890
|
-
wasPropertyKeyModified: false,
|
|
1891
|
-
additionalProperties: {}
|
|
1892
|
-
};
|
|
1893
|
-
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
1894
|
-
*
|
|
1895
|
-
* @param name - The name of the field to check for required-ness
|
|
1896
|
-
* @returns - True if the field `name` is required, false otherwise
|
|
1897
|
-
*/
|
|
1898
|
-
isRequired(name) {
|
|
1899
|
-
const { schema } = this.props;
|
|
1900
|
-
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1901
|
-
}
|
|
1902
|
-
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1903
|
-
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1904
|
-
* formData.
|
|
1905
|
-
*
|
|
1906
|
-
* @param name - The name of the property
|
|
1907
|
-
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1908
|
-
* @returns - The onPropertyChange callback for the `name` property
|
|
1909
|
-
*/
|
|
1910
|
-
onPropertyChange = (name, addedByAdditionalProperties = false) => {
|
|
1911
|
-
return (value, newErrorSchema, id) => {
|
|
1912
|
-
const { formData, onChange, errorSchema } = this.props;
|
|
1913
|
-
if (value === void 0 && addedByAdditionalProperties) {
|
|
1914
|
-
value = "";
|
|
1915
|
-
}
|
|
1916
|
-
const newFormData = { ...formData, [name]: value };
|
|
1917
|
-
onChange(
|
|
1918
|
-
newFormData,
|
|
1919
|
-
errorSchema && errorSchema && {
|
|
1920
|
-
...errorSchema,
|
|
1921
|
-
[name]: newErrorSchema
|
|
1922
|
-
},
|
|
1923
|
-
id
|
|
1924
|
-
);
|
|
1925
|
-
};
|
|
1926
|
-
};
|
|
1927
|
-
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
1928
|
-
* and calls the `onChange` callback with it
|
|
1929
|
-
*
|
|
1930
|
-
* @param key - The key for which the drop callback is desired
|
|
1931
|
-
* @returns - The drop property click callback
|
|
1932
|
-
*/
|
|
1933
|
-
onDropPropertyClick = (key) => {
|
|
1934
|
-
return (event) => {
|
|
1935
|
-
event.preventDefault();
|
|
1936
|
-
const { onChange, formData } = this.props;
|
|
1937
|
-
const copiedFormData = { ...formData };
|
|
1938
|
-
(0, import_unset.default)(copiedFormData, key);
|
|
1939
|
-
onChange(copiedFormData);
|
|
1940
|
-
};
|
|
1941
|
-
};
|
|
1942
|
-
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
1943
|
-
* that is already not assigned is found.
|
|
1944
|
-
*
|
|
1945
|
-
* @param preferredKey - The preferred name of a new key
|
|
1946
|
-
* @param [formData] - The form data in which to check if the desired key already exists
|
|
1947
|
-
* @returns - The name of the next available key from `preferredKey`
|
|
1948
|
-
*/
|
|
1949
|
-
getAvailableKey = (preferredKey, formData) => {
|
|
1950
|
-
const { uiSchema, registry } = this.props;
|
|
1951
|
-
const { duplicateKeySuffixSeparator = "-" } = (0, import_utils8.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
1952
|
-
let index = 0;
|
|
1953
|
-
let newKey = preferredKey;
|
|
1954
|
-
while ((0, import_has3.default)(formData, newKey)) {
|
|
1955
|
-
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
1956
|
-
}
|
|
1957
|
-
return newKey;
|
|
1958
|
-
};
|
|
1959
|
-
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
1960
|
-
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
1961
|
-
*
|
|
1962
|
-
* @param oldValue - The old value of a field
|
|
1963
|
-
* @returns - The key change callback function
|
|
1964
|
-
*/
|
|
1965
|
-
onKeyChange = (oldValue) => {
|
|
1966
|
-
return (value, newErrorSchema) => {
|
|
1967
|
-
if (oldValue === value) {
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1970
|
-
const { formData, onChange, errorSchema } = this.props;
|
|
1971
|
-
value = this.getAvailableKey(value, formData);
|
|
1972
|
-
const newFormData = {
|
|
1973
|
-
...formData
|
|
1974
|
-
};
|
|
1975
|
-
const newKeys = { [oldValue]: value };
|
|
1976
|
-
const keyValues = Object.keys(newFormData).map((key) => {
|
|
1977
|
-
const newKey = newKeys[key] || key;
|
|
1978
|
-
return { [newKey]: newFormData[key] };
|
|
1979
|
-
});
|
|
1980
|
-
const renamedObj = Object.assign({}, ...keyValues);
|
|
1981
|
-
this.setState({ wasPropertyKeyModified: true });
|
|
1982
|
-
onChange(
|
|
1983
|
-
renamedObj,
|
|
1984
|
-
errorSchema && errorSchema && {
|
|
1985
|
-
...errorSchema,
|
|
1986
|
-
[value]: newErrorSchema
|
|
1987
|
-
}
|
|
1988
|
-
);
|
|
1989
|
-
};
|
|
1990
|
-
};
|
|
1991
|
-
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1992
|
-
*
|
|
1993
|
-
* @param type - The type of the new additional schema property
|
|
1994
|
-
*/
|
|
1995
|
-
getDefaultValue(type) {
|
|
1996
|
-
const {
|
|
1997
|
-
registry: { translateString }
|
|
1998
|
-
} = this.props;
|
|
1999
|
-
switch (type) {
|
|
2000
|
-
case "array":
|
|
2001
|
-
return [];
|
|
2002
|
-
case "boolean":
|
|
2003
|
-
return false;
|
|
2004
|
-
case "null":
|
|
2005
|
-
return null;
|
|
2006
|
-
case "number":
|
|
2007
|
-
return 0;
|
|
2008
|
-
case "object":
|
|
2009
|
-
return {};
|
|
2010
|
-
case "string":
|
|
2011
|
-
default:
|
|
2012
|
-
return translateString(import_utils8.TranslatableString.NewStringDefault);
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
2016
|
-
* default data for that field has been added to the formData.
|
|
2017
|
-
*
|
|
2018
|
-
* @param schema - The schema element to which the new property is being added
|
|
2019
|
-
*/
|
|
2020
|
-
handleAddClick = (schema) => () => {
|
|
2021
|
-
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
2022
|
-
return;
|
|
2023
|
-
}
|
|
2024
|
-
const { formData, onChange, registry } = this.props;
|
|
2025
|
-
const newFormData = { ...formData };
|
|
2026
|
-
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
2027
|
-
if (schema.patternProperties) {
|
|
2028
|
-
(0, import_set4.default)(newFormData, newKey, null);
|
|
2029
|
-
} else {
|
|
2030
|
-
let type = void 0;
|
|
2031
|
-
let constValue = void 0;
|
|
2032
|
-
let defaultValue = void 0;
|
|
2033
|
-
if ((0, import_isObject4.default)(schema.additionalProperties)) {
|
|
2034
|
-
type = schema.additionalProperties.type;
|
|
2035
|
-
constValue = schema.additionalProperties.const;
|
|
2036
|
-
defaultValue = schema.additionalProperties.default;
|
|
2037
|
-
let apSchema = schema.additionalProperties;
|
|
2038
|
-
if (import_utils8.REF_KEY in apSchema) {
|
|
2039
|
-
const { schemaUtils } = registry;
|
|
2040
|
-
apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[import_utils8.REF_KEY] }, formData);
|
|
2041
|
-
type = apSchema.type;
|
|
2042
|
-
constValue = apSchema.const;
|
|
2043
|
-
defaultValue = apSchema.default;
|
|
2044
|
-
}
|
|
2045
|
-
if (!type && (import_utils8.ANY_OF_KEY in apSchema || import_utils8.ONE_OF_KEY in apSchema)) {
|
|
2046
|
-
type = "object";
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
const newValue = constValue ?? defaultValue ?? this.getDefaultValue(type);
|
|
2050
|
-
(0, import_set4.default)(newFormData, newKey, newValue);
|
|
2051
|
-
}
|
|
2052
|
-
onChange(newFormData);
|
|
2053
|
-
};
|
|
2054
|
-
/** Renders the `ObjectField` from the given props
|
|
2055
|
-
*/
|
|
2056
|
-
render() {
|
|
2057
|
-
const {
|
|
2058
|
-
schema: rawSchema,
|
|
2059
|
-
uiSchema = {},
|
|
2060
|
-
formData,
|
|
2061
|
-
errorSchema,
|
|
2062
|
-
idSchema,
|
|
2063
|
-
name,
|
|
2064
|
-
required = false,
|
|
2065
|
-
disabled,
|
|
2066
|
-
readonly,
|
|
2067
|
-
hideError,
|
|
2068
|
-
idPrefix,
|
|
2069
|
-
idSeparator,
|
|
2070
|
-
onBlur,
|
|
2071
|
-
onFocus,
|
|
2072
|
-
registry,
|
|
2073
|
-
title
|
|
2074
|
-
} = this.props;
|
|
2075
|
-
const { fields: fields2, formContext, schemaUtils, translateString, globalUiOptions } = registry;
|
|
2076
|
-
const { SchemaField: SchemaField2 } = fields2;
|
|
2077
|
-
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
2078
|
-
const uiOptions = (0, import_utils8.getUiOptions)(uiSchema, globalUiOptions);
|
|
2079
|
-
const { properties: schemaProperties = {} } = schema;
|
|
2080
|
-
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
2081
|
-
const description = uiOptions.description ?? schema.description;
|
|
2082
|
-
let orderedProperties;
|
|
2083
|
-
try {
|
|
2084
|
-
const properties = Object.keys(schemaProperties);
|
|
2085
|
-
orderedProperties = (0, import_utils8.orderProperties)(properties, uiOptions.order);
|
|
2086
|
-
} catch (err) {
|
|
2087
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
2088
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "rjsf-config-error", style: { color: "red" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_markdown_to_jsx.default, { options: { disableParsingRawHTML: true }, children: translateString(import_utils8.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
2089
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("pre", { children: JSON.stringify(schema) })
|
|
2090
|
-
] });
|
|
2091
|
-
}
|
|
2092
|
-
const Template = (0, import_utils8.getTemplate)("ObjectFieldTemplate", registry, uiOptions);
|
|
2093
|
-
const templateProps = {
|
|
2094
|
-
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
2095
|
-
title: uiOptions.label === false ? "" : templateTitle,
|
|
2096
|
-
description: uiOptions.label === false ? void 0 : description,
|
|
2097
|
-
properties: orderedProperties.map((name2) => {
|
|
2098
|
-
const addedByAdditionalProperties = (0, import_has3.default)(schema, [import_utils8.PROPERTIES_KEY, name2, import_utils8.ADDITIONAL_PROPERTY_FLAG]);
|
|
2099
|
-
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
|
|
2100
|
-
const hidden = (0, import_utils8.getUiOptions)(fieldUiSchema).widget === "hidden";
|
|
2101
|
-
const fieldIdSchema = (0, import_get5.default)(idSchema, [name2], {});
|
|
2102
|
-
return {
|
|
2103
|
-
content: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2104
|
-
SchemaField2,
|
|
2105
|
-
{
|
|
2106
|
-
name: name2,
|
|
2107
|
-
required: this.isRequired(name2),
|
|
2108
|
-
schema: (0, import_get5.default)(schema, [import_utils8.PROPERTIES_KEY, name2], {}),
|
|
2109
|
-
uiSchema: fieldUiSchema,
|
|
2110
|
-
errorSchema: (0, import_get5.default)(errorSchema, name2),
|
|
2111
|
-
idSchema: fieldIdSchema,
|
|
2112
|
-
idPrefix,
|
|
2113
|
-
idSeparator,
|
|
2114
|
-
formData: (0, import_get5.default)(formData, name2),
|
|
2115
|
-
formContext,
|
|
2116
|
-
wasPropertyKeyModified: this.state.wasPropertyKeyModified,
|
|
2117
|
-
onKeyChange: this.onKeyChange(name2),
|
|
2118
|
-
onChange: this.onPropertyChange(name2, addedByAdditionalProperties),
|
|
2119
|
-
onBlur,
|
|
2120
|
-
onFocus,
|
|
2121
|
-
registry,
|
|
2122
|
-
disabled,
|
|
2123
|
-
readonly,
|
|
2124
|
-
hideError,
|
|
2125
|
-
onDropPropertyClick: this.onDropPropertyClick
|
|
2126
|
-
},
|
|
2127
|
-
name2
|
|
2128
|
-
),
|
|
2129
|
-
name: name2,
|
|
2130
|
-
readonly,
|
|
2131
|
-
disabled,
|
|
2132
|
-
required,
|
|
2133
|
-
hidden
|
|
2134
|
-
};
|
|
2135
|
-
}),
|
|
2136
|
-
readonly,
|
|
2137
|
-
disabled,
|
|
2138
|
-
required,
|
|
2139
|
-
idSchema,
|
|
2140
|
-
uiSchema,
|
|
2141
|
-
errorSchema,
|
|
2142
|
-
schema,
|
|
2143
|
-
formData,
|
|
2144
|
-
formContext,
|
|
2145
|
-
registry
|
|
2146
|
-
};
|
|
2147
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Template, { ...templateProps, onAddClick: this.handleAddClick });
|
|
2148
|
-
}
|
|
2149
|
-
};
|
|
2150
|
-
var ObjectField_default = ObjectField;
|
|
2151
|
-
|
|
2152
|
-
// src/components/fields/SchemaField.tsx
|
|
2153
|
-
var import_react8 = require("react");
|
|
2154
|
-
var import_utils9 = require("@rjsf/utils");
|
|
2155
|
-
var import_isObject5 = __toESM(require("lodash/isObject"), 1);
|
|
2156
|
-
var import_omit3 = __toESM(require("lodash/omit"), 1);
|
|
2157
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2158
|
-
var COMPONENT_TYPES = {
|
|
2159
|
-
array: "ArrayField",
|
|
2160
|
-
boolean: "BooleanField",
|
|
2161
|
-
integer: "NumberField",
|
|
2162
|
-
number: "NumberField",
|
|
2163
|
-
object: "ObjectField",
|
|
2164
|
-
string: "StringField",
|
|
2165
|
-
null: "NullField"
|
|
2166
|
-
};
|
|
2167
|
-
function getFieldComponent(schema, uiOptions, idSchema, registry) {
|
|
2168
|
-
const field = uiOptions.field;
|
|
2169
|
-
const { fields: fields2, translateString } = registry;
|
|
2170
|
-
if (typeof field === "function") {
|
|
2171
|
-
return field;
|
|
2172
|
-
}
|
|
2173
|
-
if (typeof field === "string" && field in fields2) {
|
|
2174
|
-
return fields2[field];
|
|
2175
|
-
}
|
|
2176
|
-
const schemaType = (0, import_utils9.getSchemaType)(schema);
|
|
2177
|
-
const type = Array.isArray(schemaType) ? schemaType[0] : schemaType || "";
|
|
2178
|
-
const schemaId = schema.$id;
|
|
2179
|
-
let componentName = COMPONENT_TYPES[type];
|
|
2180
|
-
if (schemaId && schemaId in fields2) {
|
|
2181
|
-
componentName = schemaId;
|
|
2182
|
-
}
|
|
2183
|
-
if (!componentName && (schema.anyOf || schema.oneOf)) {
|
|
2184
|
-
return () => null;
|
|
2185
|
-
}
|
|
2186
|
-
return componentName in fields2 ? fields2[componentName] : () => {
|
|
2187
|
-
const UnsupportedFieldTemplate = (0, import_utils9.getTemplate)(
|
|
2188
|
-
"UnsupportedFieldTemplate",
|
|
2189
|
-
registry,
|
|
2190
|
-
uiOptions
|
|
2191
|
-
);
|
|
2192
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2193
|
-
UnsupportedFieldTemplate,
|
|
2194
|
-
{
|
|
2195
|
-
schema,
|
|
2196
|
-
idSchema,
|
|
2197
|
-
reason: translateString(import_utils9.TranslatableString.UnknownFieldType, [String(schema.type)]),
|
|
2198
|
-
registry
|
|
2199
|
-
}
|
|
2200
|
-
);
|
|
2201
|
-
};
|
|
2202
|
-
}
|
|
2203
|
-
function SchemaFieldRender(props) {
|
|
2204
|
-
const {
|
|
2205
|
-
schema: _schema,
|
|
2206
|
-
idSchema: _idSchema,
|
|
2207
|
-
uiSchema,
|
|
2208
|
-
formData,
|
|
2209
|
-
errorSchema,
|
|
2210
|
-
idPrefix,
|
|
2211
|
-
idSeparator,
|
|
2212
|
-
name,
|
|
2213
|
-
onChange,
|
|
2214
|
-
onKeyChange,
|
|
2215
|
-
onDropPropertyClick,
|
|
2216
|
-
required,
|
|
2217
|
-
registry,
|
|
2218
|
-
wasPropertyKeyModified = false
|
|
2219
|
-
} = props;
|
|
2220
|
-
const { formContext, schemaUtils, globalUiOptions } = registry;
|
|
2221
|
-
const uiOptions = (0, import_utils9.getUiOptions)(uiSchema, globalUiOptions);
|
|
2222
|
-
const FieldTemplate2 = (0, import_utils9.getTemplate)("FieldTemplate", registry, uiOptions);
|
|
2223
|
-
const DescriptionFieldTemplate = (0, import_utils9.getTemplate)(
|
|
2224
|
-
"DescriptionFieldTemplate",
|
|
2225
|
-
registry,
|
|
2226
|
-
uiOptions
|
|
2227
|
-
);
|
|
2228
|
-
const FieldHelpTemplate2 = (0, import_utils9.getTemplate)("FieldHelpTemplate", registry, uiOptions);
|
|
2229
|
-
const FieldErrorTemplate2 = (0, import_utils9.getTemplate)("FieldErrorTemplate", registry, uiOptions);
|
|
2230
|
-
const schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
2231
|
-
const fieldId = _idSchema[import_utils9.ID_KEY];
|
|
2232
|
-
const idSchema = (0, import_utils9.mergeObjects)(
|
|
2233
|
-
schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator),
|
|
2234
|
-
_idSchema
|
|
2235
|
-
);
|
|
2236
|
-
const handleFieldComponentChange = (0, import_react8.useCallback)(
|
|
2237
|
-
(formData2, newErrorSchema, id2) => {
|
|
2238
|
-
const theId = id2 || fieldId;
|
|
2239
|
-
return onChange(formData2, newErrorSchema, theId);
|
|
2240
|
-
},
|
|
2241
|
-
[fieldId, onChange]
|
|
2242
|
-
);
|
|
2243
|
-
const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
|
|
2244
|
-
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
|
|
2245
|
-
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
|
|
2246
|
-
const uiSchemaHideError = uiOptions.hideError;
|
|
2247
|
-
const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
|
|
2248
|
-
const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
|
|
2249
|
-
if (Object.keys(schema).length === 0) {
|
|
2250
|
-
return null;
|
|
2251
|
-
}
|
|
2252
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
2253
|
-
const { __errors, ...fieldErrorSchema } = errorSchema || {};
|
|
2254
|
-
const fieldUiSchema = (0, import_omit3.default)(uiSchema, ["ui:classNames", "classNames", "ui:style"]);
|
|
2255
|
-
if (import_utils9.UI_OPTIONS_KEY in fieldUiSchema) {
|
|
2256
|
-
fieldUiSchema[import_utils9.UI_OPTIONS_KEY] = (0, import_omit3.default)(fieldUiSchema[import_utils9.UI_OPTIONS_KEY], ["classNames", "style"]);
|
|
2257
|
-
}
|
|
2258
|
-
const field = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2259
|
-
FieldComponent,
|
|
2260
|
-
{
|
|
2261
|
-
...props,
|
|
2262
|
-
onChange: handleFieldComponentChange,
|
|
2263
|
-
idSchema,
|
|
2264
|
-
schema,
|
|
2265
|
-
uiSchema: fieldUiSchema,
|
|
2266
|
-
disabled,
|
|
2267
|
-
readonly,
|
|
2268
|
-
hideError,
|
|
2269
|
-
autofocus,
|
|
2270
|
-
errorSchema: fieldErrorSchema,
|
|
2271
|
-
formContext,
|
|
2272
|
-
rawErrors: __errors
|
|
2273
|
-
}
|
|
2274
|
-
);
|
|
2275
|
-
const id = idSchema[import_utils9.ID_KEY];
|
|
2276
|
-
let label;
|
|
2277
|
-
if (wasPropertyKeyModified) {
|
|
2278
|
-
label = name;
|
|
2279
|
-
} else {
|
|
2280
|
-
label = import_utils9.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || props.title || name;
|
|
2281
|
-
}
|
|
2282
|
-
const description = uiOptions.description || props.schema.description || schema.description || "";
|
|
2283
|
-
const help = uiOptions.help;
|
|
2284
|
-
const hidden = uiOptions.widget === "hidden";
|
|
2285
|
-
const classNames = ["rjsf-field", `rjsf-field-${(0, import_utils9.getSchemaType)(schema)}`];
|
|
2286
|
-
if (!hideError && __errors && __errors.length > 0) {
|
|
2287
|
-
classNames.push("rjsf-field-error");
|
|
2288
|
-
}
|
|
2289
|
-
if (uiOptions.classNames) {
|
|
2290
|
-
classNames.push(uiOptions.classNames);
|
|
2291
|
-
}
|
|
2292
|
-
const helpComponent = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2293
|
-
FieldHelpTemplate2,
|
|
2294
|
-
{
|
|
2295
|
-
help,
|
|
2296
|
-
idSchema,
|
|
2297
|
-
schema,
|
|
2298
|
-
uiSchema,
|
|
2299
|
-
hasErrors: !hideError && __errors && __errors.length > 0,
|
|
2300
|
-
registry
|
|
2301
|
-
}
|
|
2302
|
-
);
|
|
2303
|
-
const errorsComponent = hideError || (schema.anyOf || schema.oneOf) && !schemaUtils.isSelect(schema) ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2304
|
-
FieldErrorTemplate2,
|
|
2305
|
-
{
|
|
2306
|
-
errors: __errors,
|
|
2307
|
-
errorSchema,
|
|
2308
|
-
idSchema,
|
|
2309
|
-
schema,
|
|
2310
|
-
uiSchema,
|
|
2311
|
-
registry
|
|
2312
|
-
}
|
|
2313
|
-
);
|
|
2314
|
-
const fieldProps = {
|
|
2315
|
-
description: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2316
|
-
DescriptionFieldTemplate,
|
|
2317
|
-
{
|
|
2318
|
-
id: (0, import_utils9.descriptionId)(id),
|
|
2319
|
-
description,
|
|
2320
|
-
schema,
|
|
2321
|
-
uiSchema,
|
|
2322
|
-
registry
|
|
2323
|
-
}
|
|
2324
|
-
),
|
|
2325
|
-
rawDescription: description,
|
|
2326
|
-
help: helpComponent,
|
|
2327
|
-
rawHelp: typeof help === "string" ? help : void 0,
|
|
2328
|
-
errors: errorsComponent,
|
|
2329
|
-
rawErrors: hideError ? void 0 : __errors,
|
|
2330
|
-
id,
|
|
2331
|
-
label,
|
|
2332
|
-
hidden,
|
|
2333
|
-
onChange,
|
|
2334
|
-
onKeyChange,
|
|
2335
|
-
onDropPropertyClick,
|
|
2336
|
-
required,
|
|
2337
|
-
disabled,
|
|
2338
|
-
readonly,
|
|
2339
|
-
hideError,
|
|
2340
|
-
displayLabel,
|
|
2341
|
-
classNames: classNames.join(" ").trim(),
|
|
2342
|
-
style: uiOptions.style,
|
|
2343
|
-
formContext,
|
|
2344
|
-
formData,
|
|
2345
|
-
schema,
|
|
2346
|
-
uiSchema,
|
|
2347
|
-
registry
|
|
2348
|
-
};
|
|
2349
|
-
const _AnyOfField = registry.fields.AnyOfField;
|
|
2350
|
-
const _OneOfField = registry.fields.OneOfField;
|
|
2351
|
-
const isReplacingAnyOrOneOf = uiSchema?.["ui:field"] && uiSchema?.["ui:fieldReplacesAnyOrOneOf"] === true;
|
|
2352
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FieldTemplate2, { ...fieldProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
2353
|
-
field,
|
|
2354
|
-
schema.anyOf && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2355
|
-
_AnyOfField,
|
|
2356
|
-
{
|
|
2357
|
-
name,
|
|
2358
|
-
disabled,
|
|
2359
|
-
readonly,
|
|
2360
|
-
hideError,
|
|
2361
|
-
errorSchema,
|
|
2362
|
-
formData,
|
|
2363
|
-
formContext,
|
|
2364
|
-
idPrefix,
|
|
2365
|
-
idSchema,
|
|
2366
|
-
idSeparator,
|
|
2367
|
-
onBlur: props.onBlur,
|
|
2368
|
-
onChange: props.onChange,
|
|
2369
|
-
onFocus: props.onFocus,
|
|
2370
|
-
options: schema.anyOf.map(
|
|
2371
|
-
(_schema2) => schemaUtils.retrieveSchema((0, import_isObject5.default)(_schema2) ? _schema2 : {}, formData)
|
|
2372
|
-
),
|
|
2373
|
-
registry,
|
|
2374
|
-
required,
|
|
2375
|
-
schema,
|
|
2376
|
-
uiSchema
|
|
2377
|
-
}
|
|
2378
|
-
),
|
|
2379
|
-
schema.oneOf && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2380
|
-
_OneOfField,
|
|
2381
|
-
{
|
|
2382
|
-
name,
|
|
2383
|
-
disabled,
|
|
2384
|
-
readonly,
|
|
2385
|
-
hideError,
|
|
2386
|
-
errorSchema,
|
|
2387
|
-
formData,
|
|
2388
|
-
formContext,
|
|
2389
|
-
idPrefix,
|
|
2390
|
-
idSchema,
|
|
2391
|
-
idSeparator,
|
|
2392
|
-
onBlur: props.onBlur,
|
|
2393
|
-
onChange: props.onChange,
|
|
2394
|
-
onFocus: props.onFocus,
|
|
2395
|
-
options: schema.oneOf.map(
|
|
2396
|
-
(_schema2) => schemaUtils.retrieveSchema((0, import_isObject5.default)(_schema2) ? _schema2 : {}, formData)
|
|
2397
|
-
),
|
|
2398
|
-
registry,
|
|
2399
|
-
required,
|
|
2400
|
-
schema,
|
|
2401
|
-
uiSchema
|
|
2402
|
-
}
|
|
2403
|
-
)
|
|
2404
|
-
] }) });
|
|
2405
|
-
}
|
|
2406
|
-
var SchemaField = class extends import_react8.Component {
|
|
2407
|
-
shouldComponentUpdate(nextProps) {
|
|
2408
|
-
return !(0, import_utils9.deepEquals)(this.props, nextProps);
|
|
2409
|
-
}
|
|
2410
|
-
render() {
|
|
2411
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SchemaFieldRender, { ...this.props });
|
|
2412
|
-
}
|
|
2413
|
-
};
|
|
2414
|
-
var SchemaField_default = SchemaField;
|
|
2415
|
-
|
|
2416
|
-
// src/components/fields/StringField.tsx
|
|
2417
|
-
var import_utils10 = require("@rjsf/utils");
|
|
2418
|
-
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2419
|
-
function StringField(props) {
|
|
2420
|
-
const {
|
|
2421
|
-
schema,
|
|
2422
|
-
name,
|
|
2423
|
-
uiSchema,
|
|
2424
|
-
idSchema,
|
|
2425
|
-
formData,
|
|
2426
|
-
required,
|
|
2427
|
-
disabled = false,
|
|
2428
|
-
readonly = false,
|
|
2429
|
-
autofocus = false,
|
|
2430
|
-
onChange,
|
|
2431
|
-
onBlur,
|
|
2432
|
-
onFocus,
|
|
2433
|
-
registry,
|
|
2434
|
-
rawErrors,
|
|
2435
|
-
hideError
|
|
2436
|
-
} = props;
|
|
2437
|
-
const { title, format } = schema;
|
|
2438
|
-
const { widgets: widgets2, formContext, schemaUtils, globalUiOptions } = registry;
|
|
2439
|
-
const enumOptions = schemaUtils.isSelect(schema) ? (0, import_utils10.optionsList)(schema, uiSchema) : void 0;
|
|
2440
|
-
let defaultWidget = enumOptions ? "select" : "text";
|
|
2441
|
-
if (format && (0, import_utils10.hasWidget)(schema, format, widgets2)) {
|
|
2442
|
-
defaultWidget = format;
|
|
2443
|
-
}
|
|
2444
|
-
const { widget = defaultWidget, placeholder = "", title: uiTitle, ...options } = (0, import_utils10.getUiOptions)(uiSchema);
|
|
2445
|
-
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
2446
|
-
const label = uiTitle ?? title ?? name;
|
|
2447
|
-
const Widget = (0, import_utils10.getWidget)(schema, widget, widgets2);
|
|
2448
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2449
|
-
Widget,
|
|
2450
|
-
{
|
|
2451
|
-
options: { ...options, enumOptions },
|
|
2452
|
-
schema,
|
|
2453
|
-
uiSchema,
|
|
2454
|
-
id: idSchema.$id,
|
|
2455
|
-
name,
|
|
2456
|
-
label,
|
|
2457
|
-
hideLabel: !displayLabel,
|
|
2458
|
-
hideError,
|
|
2459
|
-
value: formData,
|
|
2460
|
-
onChange,
|
|
2461
|
-
onBlur,
|
|
2462
|
-
onFocus,
|
|
2463
|
-
required,
|
|
2464
|
-
disabled,
|
|
2465
|
-
readonly,
|
|
2466
|
-
formContext,
|
|
2467
|
-
autofocus,
|
|
2468
|
-
registry,
|
|
2469
|
-
placeholder,
|
|
2470
|
-
rawErrors
|
|
2471
|
-
}
|
|
2472
|
-
);
|
|
2473
|
-
}
|
|
2474
|
-
var StringField_default = StringField;
|
|
2475
|
-
|
|
2476
|
-
// src/components/fields/NullField.tsx
|
|
2477
|
-
var import_react9 = require("react");
|
|
2478
|
-
function NullField(props) {
|
|
2479
|
-
const { formData, onChange } = props;
|
|
2480
|
-
(0, import_react9.useEffect)(() => {
|
|
2481
|
-
if (formData === void 0) {
|
|
2482
|
-
onChange(null);
|
|
2483
|
-
}
|
|
2484
|
-
}, [formData, onChange]);
|
|
2485
|
-
return null;
|
|
2486
|
-
}
|
|
2487
|
-
var NullField_default = NullField;
|
|
2488
|
-
|
|
2489
|
-
// src/components/fields/index.ts
|
|
2490
|
-
function fields() {
|
|
2491
|
-
return {
|
|
2492
|
-
AnyOfField: MultiSchemaField_default,
|
|
2493
|
-
ArrayField: ArrayField_default,
|
|
2494
|
-
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
2495
|
-
BooleanField: BooleanField_default,
|
|
2496
|
-
LayoutGridField,
|
|
2497
|
-
LayoutHeaderField,
|
|
2498
|
-
LayoutMultiSchemaField,
|
|
2499
|
-
NumberField: NumberField_default,
|
|
2500
|
-
ObjectField: ObjectField_default,
|
|
2501
|
-
OneOfField: MultiSchemaField_default,
|
|
2502
|
-
SchemaField: SchemaField_default,
|
|
2503
|
-
StringField: StringField_default,
|
|
2504
|
-
NullField: NullField_default
|
|
2505
|
-
};
|
|
2506
|
-
}
|
|
2507
|
-
var fields_default = fields;
|
|
2508
|
-
|
|
2509
|
-
// src/components/templates/ArrayFieldDescriptionTemplate.tsx
|
|
2510
|
-
var import_utils11 = require("@rjsf/utils");
|
|
2511
|
-
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2512
|
-
function ArrayFieldDescriptionTemplate(props) {
|
|
2513
|
-
const { idSchema, description, registry, schema, uiSchema } = props;
|
|
2514
|
-
const options = (0, import_utils11.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
2515
|
-
const { label: displayLabel = true } = options;
|
|
2516
|
-
if (!description || !displayLabel) {
|
|
2517
|
-
return null;
|
|
2518
|
-
}
|
|
2519
|
-
const DescriptionFieldTemplate = (0, import_utils11.getTemplate)(
|
|
2520
|
-
"DescriptionFieldTemplate",
|
|
2521
|
-
registry,
|
|
2522
|
-
options
|
|
2523
|
-
);
|
|
2524
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2525
|
-
DescriptionFieldTemplate,
|
|
2526
|
-
{
|
|
2527
|
-
id: (0, import_utils11.descriptionId)(idSchema),
|
|
2528
|
-
description,
|
|
2529
|
-
schema,
|
|
2530
|
-
uiSchema,
|
|
2531
|
-
registry
|
|
2532
|
-
}
|
|
2533
|
-
);
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
// src/components/templates/ArrayFieldItemTemplate.tsx
|
|
2537
|
-
var import_utils12 = require("@rjsf/utils");
|
|
2538
|
-
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2539
|
-
function ArrayFieldItemTemplate(props) {
|
|
2540
|
-
const { children, className, buttonsProps, hasToolbar, registry, uiSchema } = props;
|
|
2541
|
-
const uiOptions = (0, import_utils12.getUiOptions)(uiSchema);
|
|
2542
|
-
const ArrayFieldItemButtonsTemplate2 = (0, import_utils12.getTemplate)(
|
|
2543
|
-
"ArrayFieldItemButtonsTemplate",
|
|
2544
|
-
registry,
|
|
2545
|
-
uiOptions
|
|
2546
|
-
);
|
|
2547
|
-
const btnStyle = {
|
|
2548
|
-
flex: 1,
|
|
2549
|
-
paddingLeft: 6,
|
|
2550
|
-
paddingRight: 6,
|
|
2551
|
-
fontWeight: "bold"
|
|
2552
|
-
};
|
|
2553
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className, children: [
|
|
2554
|
-
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: hasToolbar ? "col-xs-9" : "col-xs-12", children }),
|
|
2555
|
-
hasToolbar && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "col-xs-3 array-item-toolbox", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2556
|
-
"div",
|
|
2557
|
-
{
|
|
2558
|
-
className: "btn-group",
|
|
2559
|
-
style: {
|
|
2560
|
-
display: "flex",
|
|
2561
|
-
justifyContent: "space-around"
|
|
2562
|
-
},
|
|
2563
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ArrayFieldItemButtonsTemplate2, { ...buttonsProps, style: btnStyle })
|
|
2564
|
-
}
|
|
2565
|
-
) })
|
|
2566
|
-
] });
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
// src/components/templates/ArrayFieldItemButtonsTemplate.tsx
|
|
2570
|
-
var import_react10 = require("react");
|
|
2571
|
-
var import_utils13 = require("@rjsf/utils");
|
|
2572
|
-
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2573
|
-
function ArrayFieldItemButtonsTemplate(props) {
|
|
2574
|
-
const {
|
|
2575
|
-
disabled,
|
|
2576
|
-
hasCopy,
|
|
2577
|
-
hasMoveDown,
|
|
2578
|
-
hasMoveUp,
|
|
2579
|
-
hasRemove,
|
|
2580
|
-
idSchema,
|
|
2581
|
-
index,
|
|
2582
|
-
onCopyIndexClick,
|
|
2583
|
-
onDropIndexClick,
|
|
2584
|
-
onReorderClick,
|
|
2585
|
-
readonly,
|
|
2586
|
-
registry,
|
|
2587
|
-
uiSchema
|
|
2588
|
-
} = props;
|
|
2589
|
-
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
2590
|
-
const onCopyClick = (0, import_react10.useMemo)(() => onCopyIndexClick(index), [index, onCopyIndexClick]);
|
|
2591
|
-
const onRemoveClick = (0, import_react10.useMemo)(() => onDropIndexClick(index), [index, onDropIndexClick]);
|
|
2592
|
-
const onArrowUpClick = (0, import_react10.useMemo)(() => onReorderClick(index, index - 1), [index, onReorderClick]);
|
|
2593
|
-
const onArrowDownClick = (0, import_react10.useMemo)(() => onReorderClick(index, index + 1), [index, onReorderClick]);
|
|
2594
|
-
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
2595
|
-
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2596
|
-
MoveUpButton2,
|
|
2597
|
-
{
|
|
2598
|
-
id: (0, import_utils13.buttonId)(idSchema, "moveUp"),
|
|
2599
|
-
className: "rjsf-array-item-move-up",
|
|
2600
|
-
disabled: disabled || readonly || !hasMoveUp,
|
|
2601
|
-
onClick: onArrowUpClick,
|
|
2602
|
-
uiSchema,
|
|
2603
|
-
registry
|
|
2604
|
-
}
|
|
2605
|
-
),
|
|
2606
|
-
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2607
|
-
MoveDownButton2,
|
|
2608
|
-
{
|
|
2609
|
-
id: (0, import_utils13.buttonId)(idSchema, "moveDown"),
|
|
2610
|
-
className: "rjsf-array-item-move-down",
|
|
2611
|
-
disabled: disabled || readonly || !hasMoveDown,
|
|
2612
|
-
onClick: onArrowDownClick,
|
|
2613
|
-
uiSchema,
|
|
2614
|
-
registry
|
|
2615
|
-
}
|
|
2616
|
-
),
|
|
2617
|
-
hasCopy && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2618
|
-
CopyButton2,
|
|
2619
|
-
{
|
|
2620
|
-
id: (0, import_utils13.buttonId)(idSchema, "copy"),
|
|
2621
|
-
className: "rjsf-array-item-copy",
|
|
2622
|
-
disabled: disabled || readonly,
|
|
2623
|
-
onClick: onCopyClick,
|
|
2624
|
-
uiSchema,
|
|
2625
|
-
registry
|
|
2626
|
-
}
|
|
2627
|
-
),
|
|
2628
|
-
hasRemove && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2629
|
-
RemoveButton2,
|
|
2630
|
-
{
|
|
2631
|
-
id: (0, import_utils13.buttonId)(idSchema, "remove"),
|
|
2632
|
-
className: "rjsf-array-item-remove",
|
|
2633
|
-
disabled: disabled || readonly,
|
|
2634
|
-
onClick: onRemoveClick,
|
|
2635
|
-
uiSchema,
|
|
2636
|
-
registry
|
|
2637
|
-
}
|
|
2638
|
-
)
|
|
2639
|
-
] });
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
// src/components/templates/ArrayFieldTemplate.tsx
|
|
2643
|
-
var import_utils14 = require("@rjsf/utils");
|
|
2644
|
-
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2645
|
-
function ArrayFieldTemplate(props) {
|
|
2646
|
-
const {
|
|
2647
|
-
canAdd,
|
|
2648
|
-
className,
|
|
2649
|
-
disabled,
|
|
2650
|
-
idSchema,
|
|
2651
|
-
uiSchema,
|
|
2652
|
-
items,
|
|
2653
|
-
onAddClick,
|
|
2654
|
-
readonly,
|
|
2655
|
-
registry,
|
|
2656
|
-
required,
|
|
2657
|
-
schema,
|
|
2658
|
-
title
|
|
2659
|
-
} = props;
|
|
2660
|
-
const uiOptions = (0, import_utils14.getUiOptions)(uiSchema);
|
|
2661
|
-
const ArrayFieldDescriptionTemplate2 = (0, import_utils14.getTemplate)(
|
|
2662
|
-
"ArrayFieldDescriptionTemplate",
|
|
2663
|
-
registry,
|
|
2664
|
-
uiOptions
|
|
2665
|
-
);
|
|
2666
|
-
const ArrayFieldItemTemplate2 = (0, import_utils14.getTemplate)(
|
|
2667
|
-
"ArrayFieldItemTemplate",
|
|
2668
|
-
registry,
|
|
2669
|
-
uiOptions
|
|
2670
|
-
);
|
|
2671
|
-
const ArrayFieldTitleTemplate2 = (0, import_utils14.getTemplate)(
|
|
2672
|
-
"ArrayFieldTitleTemplate",
|
|
2673
|
-
registry,
|
|
2674
|
-
uiOptions
|
|
2675
|
-
);
|
|
2676
|
-
const {
|
|
2677
|
-
ButtonTemplates: { AddButton: AddButton2 }
|
|
2678
|
-
} = registry.templates;
|
|
2679
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("fieldset", { className, id: idSchema.$id, children: [
|
|
2680
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2681
|
-
ArrayFieldTitleTemplate2,
|
|
2682
|
-
{
|
|
2683
|
-
idSchema,
|
|
2684
|
-
title: uiOptions.title || title,
|
|
2685
|
-
required,
|
|
2686
|
-
schema,
|
|
2687
|
-
uiSchema,
|
|
2688
|
-
registry
|
|
2689
|
-
}
|
|
2690
|
-
),
|
|
2691
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2692
|
-
ArrayFieldDescriptionTemplate2,
|
|
2693
|
-
{
|
|
2694
|
-
idSchema,
|
|
2695
|
-
description: uiOptions.description || schema.description,
|
|
2696
|
-
schema,
|
|
2697
|
-
uiSchema,
|
|
2698
|
-
registry
|
|
2699
|
-
}
|
|
2700
|
-
),
|
|
2701
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "row array-item-list", children: items && items.map(({ key, ...itemProps }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ArrayFieldItemTemplate2, { ...itemProps }, key)) }),
|
|
2702
|
-
canAdd && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2703
|
-
AddButton2,
|
|
2704
|
-
{
|
|
2705
|
-
id: (0, import_utils14.buttonId)(idSchema, "add"),
|
|
2706
|
-
className: "rjsf-array-item-add",
|
|
2707
|
-
onClick: onAddClick,
|
|
2708
|
-
disabled: disabled || readonly,
|
|
2709
|
-
uiSchema,
|
|
2710
|
-
registry
|
|
2711
|
-
}
|
|
2712
|
-
)
|
|
2713
|
-
] });
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
// src/components/templates/ArrayFieldTitleTemplate.tsx
|
|
2717
|
-
var import_utils15 = require("@rjsf/utils");
|
|
2718
|
-
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2719
|
-
function ArrayFieldTitleTemplate(props) {
|
|
2720
|
-
const { idSchema, title, schema, uiSchema, required, registry } = props;
|
|
2721
|
-
const options = (0, import_utils15.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
2722
|
-
const { label: displayLabel = true } = options;
|
|
2723
|
-
if (!title || !displayLabel) {
|
|
2724
|
-
return null;
|
|
2725
|
-
}
|
|
2726
|
-
const TitleFieldTemplate = (0, import_utils15.getTemplate)(
|
|
2727
|
-
"TitleFieldTemplate",
|
|
2728
|
-
registry,
|
|
2729
|
-
options
|
|
2730
|
-
);
|
|
2731
|
-
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
2732
|
-
TitleFieldTemplate,
|
|
2733
|
-
{
|
|
2734
|
-
id: (0, import_utils15.titleId)(idSchema),
|
|
2735
|
-
title,
|
|
2736
|
-
required,
|
|
2737
|
-
schema,
|
|
2738
|
-
uiSchema,
|
|
2739
|
-
registry
|
|
2740
|
-
}
|
|
2741
|
-
);
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
// src/components/templates/BaseInputTemplate.tsx
|
|
2745
|
-
var import_react11 = require("react");
|
|
2746
|
-
var import_utils16 = require("@rjsf/utils");
|
|
2747
|
-
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2748
|
-
function BaseInputTemplate(props) {
|
|
2749
|
-
const {
|
|
2750
|
-
id,
|
|
2751
|
-
name,
|
|
2752
|
-
// remove this from ...rest
|
|
2753
|
-
value,
|
|
2754
|
-
readonly,
|
|
2755
|
-
disabled,
|
|
2756
|
-
autofocus,
|
|
2757
|
-
onBlur,
|
|
2758
|
-
onFocus,
|
|
2759
|
-
onChange,
|
|
2760
|
-
onChangeOverride,
|
|
2761
|
-
options,
|
|
2762
|
-
schema,
|
|
2763
|
-
uiSchema,
|
|
2764
|
-
formContext,
|
|
2765
|
-
registry,
|
|
2766
|
-
rawErrors,
|
|
2767
|
-
type,
|
|
2768
|
-
hideLabel,
|
|
2769
|
-
// remove this from ...rest
|
|
2770
|
-
hideError,
|
|
2771
|
-
// remove this from ...rest
|
|
2772
|
-
...rest
|
|
2773
|
-
} = props;
|
|
2774
|
-
if (!id) {
|
|
2775
|
-
console.log("No id for", props);
|
|
2776
|
-
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
2777
|
-
}
|
|
2778
|
-
const inputProps = {
|
|
2779
|
-
...rest,
|
|
2780
|
-
...(0, import_utils16.getInputProps)(schema, type, options)
|
|
2781
|
-
};
|
|
2782
|
-
let inputValue;
|
|
2783
|
-
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
2784
|
-
inputValue = value || value === 0 ? value : "";
|
|
2785
|
-
} else {
|
|
2786
|
-
inputValue = value == null ? "" : value;
|
|
2787
|
-
}
|
|
2788
|
-
const _onChange = (0, import_react11.useCallback)(
|
|
2789
|
-
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
2790
|
-
[onChange, options]
|
|
2791
|
-
);
|
|
2792
|
-
const _onBlur = (0, import_react11.useCallback)(
|
|
2793
|
-
({ target }) => onBlur(id, target && target.value),
|
|
2794
|
-
[onBlur, id]
|
|
2795
|
-
);
|
|
2796
|
-
const _onFocus = (0, import_react11.useCallback)(
|
|
2797
|
-
({ target }) => onFocus(id, target && target.value),
|
|
2798
|
-
[onFocus, id]
|
|
2799
|
-
);
|
|
2800
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
|
|
2801
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2802
|
-
"input",
|
|
2803
|
-
{
|
|
2804
|
-
id,
|
|
2805
|
-
name: id,
|
|
2806
|
-
className: "form-control",
|
|
2807
|
-
readOnly: readonly,
|
|
2808
|
-
disabled,
|
|
2809
|
-
autoFocus: autofocus,
|
|
2810
|
-
value: inputValue,
|
|
2811
|
-
...inputProps,
|
|
2812
|
-
list: schema.examples ? (0, import_utils16.examplesId)(id) : void 0,
|
|
2813
|
-
onChange: onChangeOverride || _onChange,
|
|
2814
|
-
onBlur: _onBlur,
|
|
2815
|
-
onFocus: _onFocus,
|
|
2816
|
-
"aria-describedby": (0, import_utils16.ariaDescribedByIds)(id, !!schema.examples)
|
|
2817
|
-
}
|
|
2818
|
-
),
|
|
2819
|
-
Array.isArray(schema.examples) && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("datalist", { id: (0, import_utils16.examplesId)(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
|
|
2820
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("option", { value: example }, example);
|
|
2821
|
-
}) }, `datalist_${id}`)
|
|
2822
|
-
] });
|
|
2823
|
-
}
|
|
2824
|
-
|
|
2825
|
-
// src/components/templates/ButtonTemplates/SubmitButton.tsx
|
|
2826
|
-
var import_utils17 = require("@rjsf/utils");
|
|
2827
|
-
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2828
|
-
function SubmitButton({ uiSchema }) {
|
|
2829
|
-
const { submitText, norender, props: submitButtonProps = {} } = (0, import_utils17.getSubmitButtonOptions)(uiSchema);
|
|
2830
|
-
if (norender) {
|
|
2831
|
-
return null;
|
|
2832
|
-
}
|
|
2833
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "submit", ...submitButtonProps, className: `btn btn-info ${submitButtonProps.className || ""}`, children: submitText }) });
|
|
2834
|
-
}
|
|
2835
|
-
|
|
2836
|
-
// src/components/templates/ButtonTemplates/AddButton.tsx
|
|
2837
|
-
var import_utils19 = require("@rjsf/utils");
|
|
2838
|
-
|
|
2839
|
-
// src/components/templates/ButtonTemplates/IconButton.tsx
|
|
2840
|
-
var import_utils18 = require("@rjsf/utils");
|
|
2841
|
-
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2842
|
-
function IconButton(props) {
|
|
2843
|
-
const { iconType = "default", icon, className, uiSchema, registry, ...otherProps } = props;
|
|
2844
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", className: `btn btn-${iconType} ${className}`, ...otherProps, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("i", { className: `glyphicon glyphicon-${icon}` }) });
|
|
2845
|
-
}
|
|
2846
|
-
function CopyButton(props) {
|
|
2847
|
-
const {
|
|
2848
|
-
registry: { translateString }
|
|
2849
|
-
} = props;
|
|
2850
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IconButton, { title: translateString(import_utils18.TranslatableString.CopyButton), ...props, icon: "copy" });
|
|
2851
|
-
}
|
|
2852
|
-
function MoveDownButton(props) {
|
|
2853
|
-
const {
|
|
2854
|
-
registry: { translateString }
|
|
2855
|
-
} = props;
|
|
2856
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IconButton, { title: translateString(import_utils18.TranslatableString.MoveDownButton), ...props, icon: "arrow-down" });
|
|
2857
|
-
}
|
|
2858
|
-
function MoveUpButton(props) {
|
|
2859
|
-
const {
|
|
2860
|
-
registry: { translateString }
|
|
2861
|
-
} = props;
|
|
2862
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IconButton, { title: translateString(import_utils18.TranslatableString.MoveUpButton), ...props, icon: "arrow-up" });
|
|
2863
|
-
}
|
|
2864
|
-
function RemoveButton(props) {
|
|
2865
|
-
const {
|
|
2866
|
-
registry: { translateString }
|
|
2867
|
-
} = props;
|
|
2868
|
-
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IconButton, { title: translateString(import_utils18.TranslatableString.RemoveButton), ...props, iconType: "danger", icon: "remove" });
|
|
2869
|
-
}
|
|
2870
|
-
|
|
2871
|
-
// src/components/templates/ButtonTemplates/AddButton.tsx
|
|
2872
|
-
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2873
|
-
function AddButton({
|
|
2874
|
-
className,
|
|
2875
|
-
onClick,
|
|
2876
|
-
disabled,
|
|
2877
|
-
registry
|
|
2878
|
-
}) {
|
|
2879
|
-
const { translateString } = registry;
|
|
2880
|
-
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "row", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: `col-xs-3 col-xs-offset-9 text-right ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2881
|
-
IconButton,
|
|
2882
|
-
{
|
|
2883
|
-
iconType: "info",
|
|
2884
|
-
icon: "plus",
|
|
2885
|
-
className: "btn-add col-xs-12",
|
|
2886
|
-
title: translateString(import_utils19.TranslatableString.AddButton),
|
|
2887
|
-
onClick,
|
|
2888
|
-
disabled,
|
|
2889
|
-
registry
|
|
2890
|
-
}
|
|
2891
|
-
) }) });
|
|
2892
|
-
}
|
|
2893
|
-
|
|
2894
|
-
// src/components/templates/ButtonTemplates/index.ts
|
|
2895
|
-
function buttonTemplates() {
|
|
2896
|
-
return {
|
|
2897
|
-
SubmitButton,
|
|
2898
|
-
AddButton,
|
|
2899
|
-
CopyButton,
|
|
2900
|
-
MoveDownButton,
|
|
2901
|
-
MoveUpButton,
|
|
2902
|
-
RemoveButton
|
|
2903
|
-
};
|
|
2904
|
-
}
|
|
2905
|
-
var ButtonTemplates_default = buttonTemplates;
|
|
2906
|
-
|
|
2907
|
-
// src/components/RichDescription.tsx
|
|
2908
|
-
var import_utils20 = require("@rjsf/utils");
|
|
2909
|
-
var import_markdown_to_jsx2 = __toESM(require("markdown-to-jsx"), 1);
|
|
2910
|
-
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2911
|
-
var TEST_IDS = (0, import_utils20.getTestIds)();
|
|
2912
|
-
function RichDescription({ description, registry, uiSchema = {} }) {
|
|
2913
|
-
const { globalUiOptions } = registry;
|
|
2914
|
-
const uiOptions = (0, import_utils20.getUiOptions)(uiSchema, globalUiOptions);
|
|
2915
|
-
if (uiOptions.enableMarkdownInDescription && typeof description === "string") {
|
|
2916
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_markdown_to_jsx2.default, { options: { disableParsingRawHTML: true }, "data-testid": TEST_IDS.markdown, children: description });
|
|
2917
|
-
}
|
|
2918
|
-
return description;
|
|
2919
|
-
}
|
|
2920
|
-
RichDescription.TEST_IDS = TEST_IDS;
|
|
2921
|
-
|
|
2922
|
-
// src/components/templates/DescriptionField.tsx
|
|
2923
|
-
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2924
|
-
function DescriptionField(props) {
|
|
2925
|
-
const { id, description, registry, uiSchema } = props;
|
|
2926
|
-
if (!description) {
|
|
2927
|
-
return null;
|
|
2928
|
-
}
|
|
2929
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { id, className: "field-description", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(RichDescription, { description, registry, uiSchema }) });
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
// src/components/templates/ErrorList.tsx
|
|
2933
|
-
var import_utils21 = require("@rjsf/utils");
|
|
2934
|
-
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2935
|
-
function ErrorList({
|
|
2936
|
-
errors,
|
|
2937
|
-
registry
|
|
2938
|
-
}) {
|
|
2939
|
-
const { translateString } = registry;
|
|
2940
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "panel panel-danger errors", children: [
|
|
2941
|
-
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "panel-heading", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("h3", { className: "panel-title", children: translateString(import_utils21.TranslatableString.ErrorsLabel) }) }),
|
|
2942
|
-
/* @__PURE__ */ (0, import_jsx_runtime22.jsx)("ul", { className: "list-group", children: errors.map((error, i) => {
|
|
2943
|
-
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("li", { className: "list-group-item text-danger", children: error.stack }, i);
|
|
2944
|
-
}) })
|
|
2945
|
-
] });
|
|
2946
|
-
}
|
|
2947
|
-
|
|
2948
|
-
// src/components/templates/FieldTemplate/FieldTemplate.tsx
|
|
2949
|
-
var import_utils22 = require("@rjsf/utils");
|
|
2950
|
-
|
|
2951
|
-
// src/components/templates/FieldTemplate/Label.tsx
|
|
2952
|
-
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2953
|
-
var REQUIRED_FIELD_SYMBOL = "*";
|
|
2954
|
-
function Label(props) {
|
|
2955
|
-
const { label, required, id } = props;
|
|
2956
|
-
if (!label) {
|
|
2957
|
-
return null;
|
|
2958
|
-
}
|
|
2959
|
-
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("label", { className: "control-label", htmlFor: id, children: [
|
|
2960
|
-
label,
|
|
2961
|
-
required && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "required", children: REQUIRED_FIELD_SYMBOL })
|
|
2962
|
-
] });
|
|
2963
|
-
}
|
|
2964
|
-
|
|
2965
|
-
// src/components/templates/FieldTemplate/FieldTemplate.tsx
|
|
2966
|
-
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2967
|
-
function FieldTemplate(props) {
|
|
2968
|
-
const { id, label, children, errors, help, description, hidden, required, displayLabel, registry, uiSchema } = props;
|
|
2969
|
-
const uiOptions = (0, import_utils22.getUiOptions)(uiSchema);
|
|
2970
|
-
const WrapIfAdditionalTemplate2 = (0, import_utils22.getTemplate)(
|
|
2971
|
-
"WrapIfAdditionalTemplate",
|
|
2972
|
-
registry,
|
|
2973
|
-
uiOptions
|
|
2974
|
-
);
|
|
2975
|
-
if (hidden) {
|
|
2976
|
-
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "hidden", children });
|
|
2977
|
-
}
|
|
2978
|
-
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(WrapIfAdditionalTemplate2, { ...props, children: [
|
|
2979
|
-
displayLabel && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Label, { label, required, id }),
|
|
2980
|
-
displayLabel && description ? description : null,
|
|
2981
|
-
children,
|
|
2982
|
-
errors,
|
|
2983
|
-
help
|
|
2984
|
-
] });
|
|
2985
|
-
}
|
|
2986
|
-
|
|
2987
|
-
// src/components/templates/FieldTemplate/index.ts
|
|
2988
|
-
var FieldTemplate_default = FieldTemplate;
|
|
2989
|
-
|
|
2990
|
-
// src/components/templates/FieldErrorTemplate.tsx
|
|
2991
|
-
var import_utils23 = require("@rjsf/utils");
|
|
2992
|
-
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2993
|
-
function FieldErrorTemplate(props) {
|
|
2994
|
-
const { errors = [], idSchema } = props;
|
|
2995
|
-
if (errors.length === 0) {
|
|
2996
|
-
return null;
|
|
2997
|
-
}
|
|
2998
|
-
const id = (0, import_utils23.errorId)(idSchema);
|
|
2999
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("ul", { id, className: "error-detail bs-callout bs-callout-info", children: errors.filter((elem) => !!elem).map((error, index) => {
|
|
3000
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("li", { className: "text-danger", children: error }, index);
|
|
3001
|
-
}) }) });
|
|
3002
|
-
}
|
|
3003
|
-
|
|
3004
|
-
// src/components/templates/FieldHelpTemplate.tsx
|
|
3005
|
-
var import_utils24 = require("@rjsf/utils");
|
|
3006
|
-
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
3007
|
-
function FieldHelpTemplate(props) {
|
|
3008
|
-
const { idSchema, help } = props;
|
|
3009
|
-
if (!help) {
|
|
3010
|
-
return null;
|
|
3011
|
-
}
|
|
3012
|
-
const id = (0, import_utils24.helpId)(idSchema);
|
|
3013
|
-
if (typeof help === "string") {
|
|
3014
|
-
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("p", { id, className: "help-block", children: help });
|
|
3015
|
-
}
|
|
3016
|
-
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { id, className: "help-block", children: help });
|
|
3017
|
-
}
|
|
3018
|
-
|
|
3019
|
-
// src/components/templates/GridTemplate.tsx
|
|
3020
|
-
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
3021
|
-
function GridTemplate(props) {
|
|
3022
|
-
const { children, column, className, ...rest } = props;
|
|
3023
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className, ...rest, children });
|
|
3024
|
-
}
|
|
3025
|
-
|
|
3026
|
-
// src/components/templates/ObjectFieldTemplate.tsx
|
|
3027
|
-
var import_utils25 = require("@rjsf/utils");
|
|
3028
|
-
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
3029
|
-
function ObjectFieldTemplate(props) {
|
|
3030
|
-
const {
|
|
3031
|
-
description,
|
|
3032
|
-
disabled,
|
|
3033
|
-
formData,
|
|
3034
|
-
idSchema,
|
|
3035
|
-
onAddClick,
|
|
3036
|
-
properties,
|
|
3037
|
-
readonly,
|
|
3038
|
-
registry,
|
|
3039
|
-
required,
|
|
3040
|
-
schema,
|
|
3041
|
-
title,
|
|
3042
|
-
uiSchema
|
|
3043
|
-
} = props;
|
|
3044
|
-
const options = (0, import_utils25.getUiOptions)(uiSchema);
|
|
3045
|
-
const TitleFieldTemplate = (0, import_utils25.getTemplate)("TitleFieldTemplate", registry, options);
|
|
3046
|
-
const DescriptionFieldTemplate = (0, import_utils25.getTemplate)(
|
|
3047
|
-
"DescriptionFieldTemplate",
|
|
3048
|
-
registry,
|
|
3049
|
-
options
|
|
3050
|
-
);
|
|
3051
|
-
const {
|
|
3052
|
-
ButtonTemplates: { AddButton: AddButton2 }
|
|
3053
|
-
} = registry.templates;
|
|
3054
|
-
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("fieldset", { id: idSchema.$id, children: [
|
|
3055
|
-
title && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3056
|
-
TitleFieldTemplate,
|
|
3057
|
-
{
|
|
3058
|
-
id: (0, import_utils25.titleId)(idSchema),
|
|
3059
|
-
title,
|
|
3060
|
-
required,
|
|
3061
|
-
schema,
|
|
3062
|
-
uiSchema,
|
|
3063
|
-
registry
|
|
3064
|
-
}
|
|
3065
|
-
),
|
|
3066
|
-
description && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3067
|
-
DescriptionFieldTemplate,
|
|
3068
|
-
{
|
|
3069
|
-
id: (0, import_utils25.descriptionId)(idSchema),
|
|
3070
|
-
description,
|
|
3071
|
-
schema,
|
|
3072
|
-
uiSchema,
|
|
3073
|
-
registry
|
|
3074
|
-
}
|
|
3075
|
-
),
|
|
3076
|
-
properties.map((prop) => prop.content),
|
|
3077
|
-
(0, import_utils25.canExpand)(schema, uiSchema, formData) && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3078
|
-
AddButton2,
|
|
3079
|
-
{
|
|
3080
|
-
id: (0, import_utils25.buttonId)(idSchema, "add"),
|
|
3081
|
-
className: "rjsf-object-property-expand",
|
|
3082
|
-
onClick: onAddClick(schema),
|
|
3083
|
-
disabled: disabled || readonly,
|
|
3084
|
-
uiSchema,
|
|
3085
|
-
registry
|
|
3086
|
-
}
|
|
3087
|
-
)
|
|
3088
|
-
] });
|
|
3089
|
-
}
|
|
3090
|
-
|
|
3091
|
-
// src/components/templates/TitleField.tsx
|
|
3092
|
-
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
3093
|
-
var REQUIRED_FIELD_SYMBOL2 = "*";
|
|
3094
|
-
function TitleField(props) {
|
|
3095
|
-
const { id, title, required } = props;
|
|
3096
|
-
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("legend", { id, children: [
|
|
3097
|
-
title,
|
|
3098
|
-
required && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "required", children: REQUIRED_FIELD_SYMBOL2 })
|
|
3099
|
-
] });
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
// src/components/templates/UnsupportedField.tsx
|
|
3103
|
-
var import_utils26 = require("@rjsf/utils");
|
|
3104
|
-
var import_markdown_to_jsx3 = __toESM(require("markdown-to-jsx"), 1);
|
|
3105
|
-
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
3106
|
-
function UnsupportedField(props) {
|
|
3107
|
-
const { schema, idSchema, reason, registry } = props;
|
|
3108
|
-
const { translateString } = registry;
|
|
3109
|
-
let translateEnum = import_utils26.TranslatableString.UnsupportedField;
|
|
3110
|
-
const translateParams = [];
|
|
3111
|
-
if (idSchema && idSchema.$id) {
|
|
3112
|
-
translateEnum = import_utils26.TranslatableString.UnsupportedFieldWithId;
|
|
3113
|
-
translateParams.push(idSchema.$id);
|
|
3114
|
-
}
|
|
3115
|
-
if (reason) {
|
|
3116
|
-
translateEnum = translateEnum === import_utils26.TranslatableString.UnsupportedField ? import_utils26.TranslatableString.UnsupportedFieldWithReason : import_utils26.TranslatableString.UnsupportedFieldWithIdAndReason;
|
|
3117
|
-
translateParams.push(reason);
|
|
3118
|
-
}
|
|
3119
|
-
return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "unsupported-field", children: [
|
|
3120
|
-
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_markdown_to_jsx3.default, { options: { disableParsingRawHTML: true }, children: translateString(translateEnum, translateParams) }) }),
|
|
3121
|
-
schema && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("pre", { children: JSON.stringify(schema, null, 2) })
|
|
3122
|
-
] });
|
|
3123
|
-
}
|
|
3124
|
-
var UnsupportedField_default = UnsupportedField;
|
|
3125
|
-
|
|
3126
|
-
// src/components/templates/WrapIfAdditionalTemplate.tsx
|
|
3127
|
-
var import_utils27 = require("@rjsf/utils");
|
|
3128
|
-
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
3129
|
-
function WrapIfAdditionalTemplate(props) {
|
|
3130
|
-
const {
|
|
3131
|
-
id,
|
|
3132
|
-
classNames,
|
|
3133
|
-
style,
|
|
3134
|
-
disabled,
|
|
3135
|
-
label,
|
|
3136
|
-
onKeyChange,
|
|
3137
|
-
onDropPropertyClick,
|
|
3138
|
-
readonly,
|
|
3139
|
-
required,
|
|
3140
|
-
schema,
|
|
3141
|
-
hideError,
|
|
3142
|
-
rawErrors,
|
|
3143
|
-
children,
|
|
3144
|
-
uiSchema,
|
|
3145
|
-
registry
|
|
3146
|
-
} = props;
|
|
3147
|
-
const { templates: templates2, translateString } = registry;
|
|
3148
|
-
const { RemoveButton: RemoveButton2 } = templates2.ButtonTemplates;
|
|
3149
|
-
const keyLabel = translateString(import_utils27.TranslatableString.KeyLabel, [label]);
|
|
3150
|
-
const additional = import_utils27.ADDITIONAL_PROPERTY_FLAG in schema;
|
|
3151
|
-
const classNamesList = ["form-group", classNames];
|
|
3152
|
-
if (!hideError && rawErrors && rawErrors.length > 0) {
|
|
3153
|
-
classNamesList.push("has-error has-danger");
|
|
3154
|
-
}
|
|
3155
|
-
const uiClassNames = classNamesList.join(" ").trim();
|
|
3156
|
-
if (!additional) {
|
|
3157
|
-
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: uiClassNames, style, children });
|
|
3158
|
-
}
|
|
3159
|
-
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: uiClassNames, style, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "row", children: [
|
|
3160
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "col-xs-5 form-additional", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", { className: "form-group", children: [
|
|
3161
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Label, { label: keyLabel, required, id: `${id}-key` }),
|
|
3162
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
3163
|
-
"input",
|
|
3164
|
-
{
|
|
3165
|
-
className: "form-control",
|
|
3166
|
-
type: "text",
|
|
3167
|
-
id: `${id}-key`,
|
|
3168
|
-
onBlur: ({ target }) => onKeyChange(target && target.value),
|
|
3169
|
-
defaultValue: label
|
|
3170
|
-
}
|
|
3171
|
-
)
|
|
3172
|
-
] }) }),
|
|
3173
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "form-additional form-group col-xs-5", children }),
|
|
3174
|
-
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { className: "col-xs-2", children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
3175
|
-
RemoveButton2,
|
|
3176
|
-
{
|
|
3177
|
-
id: (0, import_utils27.buttonId)(id, "remove"),
|
|
3178
|
-
className: "rjsf-object-property-remove btn-block",
|
|
3179
|
-
style: { border: "0" },
|
|
3180
|
-
disabled: disabled || readonly,
|
|
3181
|
-
onClick: onDropPropertyClick(label),
|
|
3182
|
-
uiSchema,
|
|
3183
|
-
registry
|
|
3184
|
-
}
|
|
3185
|
-
) })
|
|
3186
|
-
] }) });
|
|
3187
|
-
}
|
|
3188
|
-
|
|
3189
|
-
// src/components/templates/index.ts
|
|
3190
|
-
function templates() {
|
|
3191
|
-
return {
|
|
3192
|
-
ArrayFieldDescriptionTemplate,
|
|
3193
|
-
ArrayFieldItemTemplate,
|
|
3194
|
-
ArrayFieldItemButtonsTemplate,
|
|
3195
|
-
ArrayFieldTemplate,
|
|
3196
|
-
ArrayFieldTitleTemplate,
|
|
3197
|
-
ButtonTemplates: ButtonTemplates_default(),
|
|
3198
|
-
BaseInputTemplate,
|
|
3199
|
-
DescriptionFieldTemplate: DescriptionField,
|
|
3200
|
-
ErrorListTemplate: ErrorList,
|
|
3201
|
-
FieldTemplate: FieldTemplate_default,
|
|
3202
|
-
FieldErrorTemplate,
|
|
3203
|
-
FieldHelpTemplate,
|
|
3204
|
-
GridTemplate,
|
|
3205
|
-
ObjectFieldTemplate,
|
|
3206
|
-
TitleFieldTemplate: TitleField,
|
|
3207
|
-
UnsupportedFieldTemplate: UnsupportedField_default,
|
|
3208
|
-
WrapIfAdditionalTemplate
|
|
3209
|
-
};
|
|
3210
|
-
}
|
|
3211
|
-
var templates_default = templates;
|
|
3212
|
-
|
|
3213
|
-
// src/components/widgets/AltDateWidget.tsx
|
|
3214
|
-
var import_react12 = require("react");
|
|
3215
|
-
var import_utils28 = require("@rjsf/utils");
|
|
3216
|
-
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
3217
|
-
function readyForChange(state) {
|
|
3218
|
-
return Object.values(state).every((value) => value !== -1);
|
|
3219
|
-
}
|
|
3220
|
-
function DateElement({
|
|
3221
|
-
type,
|
|
3222
|
-
range,
|
|
3223
|
-
value,
|
|
3224
|
-
select,
|
|
3225
|
-
rootId,
|
|
3226
|
-
name,
|
|
3227
|
-
disabled,
|
|
3228
|
-
readonly,
|
|
3229
|
-
autofocus,
|
|
3230
|
-
registry,
|
|
3231
|
-
onBlur,
|
|
3232
|
-
onFocus
|
|
3233
|
-
}) {
|
|
3234
|
-
const id = rootId + "_" + type;
|
|
3235
|
-
const { SelectWidget: SelectWidget2 } = registry.widgets;
|
|
3236
|
-
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
3237
|
-
SelectWidget2,
|
|
3238
|
-
{
|
|
3239
|
-
schema: { type: "integer" },
|
|
3240
|
-
id,
|
|
3241
|
-
name,
|
|
3242
|
-
className: "form-control",
|
|
3243
|
-
options: { enumOptions: (0, import_utils28.dateRangeOptions)(range[0], range[1]) },
|
|
3244
|
-
placeholder: type,
|
|
3245
|
-
value,
|
|
3246
|
-
disabled,
|
|
3247
|
-
readonly,
|
|
3248
|
-
autofocus,
|
|
3249
|
-
onChange: (value2) => select(type, value2),
|
|
3250
|
-
onBlur,
|
|
3251
|
-
onFocus,
|
|
3252
|
-
registry,
|
|
3253
|
-
label: "",
|
|
3254
|
-
"aria-describedby": (0, import_utils28.ariaDescribedByIds)(rootId)
|
|
3255
|
-
}
|
|
3256
|
-
);
|
|
3257
|
-
}
|
|
3258
|
-
function AltDateWidget({
|
|
3259
|
-
time = false,
|
|
3260
|
-
disabled = false,
|
|
3261
|
-
readonly = false,
|
|
3262
|
-
autofocus = false,
|
|
3263
|
-
options,
|
|
3264
|
-
id,
|
|
3265
|
-
name,
|
|
3266
|
-
registry,
|
|
3267
|
-
onBlur,
|
|
3268
|
-
onFocus,
|
|
3269
|
-
onChange,
|
|
3270
|
-
value
|
|
3271
|
-
}) {
|
|
3272
|
-
const { translateString } = registry;
|
|
3273
|
-
const [lastValue, setLastValue] = (0, import_react12.useState)(value);
|
|
3274
|
-
const [state, setState] = (0, import_react12.useReducer)(
|
|
3275
|
-
(state2, action) => {
|
|
3276
|
-
return { ...state2, ...action };
|
|
3277
|
-
},
|
|
3278
|
-
(0, import_utils28.parseDateString)(value, time)
|
|
3279
|
-
);
|
|
3280
|
-
(0, import_react12.useEffect)(() => {
|
|
3281
|
-
const stateValue = (0, import_utils28.toDateString)(state, time);
|
|
3282
|
-
if (readyForChange(state) && stateValue !== value) {
|
|
3283
|
-
onChange(stateValue);
|
|
3284
|
-
} else if (lastValue !== value) {
|
|
3285
|
-
setLastValue(value);
|
|
3286
|
-
setState((0, import_utils28.parseDateString)(value, time));
|
|
3287
|
-
}
|
|
3288
|
-
}, [time, value, onChange, state, lastValue]);
|
|
3289
|
-
const handleChange = (0, import_react12.useCallback)((property, value2) => {
|
|
3290
|
-
setState({ [property]: value2 });
|
|
3291
|
-
}, []);
|
|
3292
|
-
const handleSetNow = (0, import_react12.useCallback)(
|
|
3293
|
-
(event) => {
|
|
3294
|
-
event.preventDefault();
|
|
3295
|
-
if (disabled || readonly) {
|
|
3296
|
-
return;
|
|
3297
|
-
}
|
|
3298
|
-
const nextState = (0, import_utils28.parseDateString)((/* @__PURE__ */ new Date()).toJSON(), time);
|
|
3299
|
-
onChange((0, import_utils28.toDateString)(nextState, time));
|
|
3300
|
-
},
|
|
3301
|
-
[disabled, readonly, time]
|
|
3302
|
-
);
|
|
3303
|
-
const handleClear = (0, import_react12.useCallback)(
|
|
3304
|
-
(event) => {
|
|
3305
|
-
event.preventDefault();
|
|
3306
|
-
if (disabled || readonly) {
|
|
3307
|
-
return;
|
|
3308
|
-
}
|
|
3309
|
-
onChange(void 0);
|
|
3310
|
-
},
|
|
3311
|
-
[disabled, readonly, onChange]
|
|
3312
|
-
);
|
|
3313
|
-
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("ul", { className: "list-inline", children: [
|
|
3314
|
-
(0, import_utils28.getDateElementProps)(
|
|
3315
|
-
state,
|
|
3316
|
-
time,
|
|
3317
|
-
options.yearsRange,
|
|
3318
|
-
options.format
|
|
3319
|
-
).map((elemProps, i) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
3320
|
-
DateElement,
|
|
3321
|
-
{
|
|
3322
|
-
rootId: id,
|
|
3323
|
-
name,
|
|
3324
|
-
select: handleChange,
|
|
3325
|
-
...elemProps,
|
|
3326
|
-
disabled,
|
|
3327
|
-
readonly,
|
|
3328
|
-
registry,
|
|
3329
|
-
onBlur,
|
|
3330
|
-
onFocus,
|
|
3331
|
-
autofocus: autofocus && i === 0
|
|
3332
|
-
}
|
|
3333
|
-
) }, i)),
|
|
3334
|
-
(options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("a", { href: "#", className: "btn btn-info btn-now", onClick: handleSetNow, children: translateString(import_utils28.TranslatableString.NowLabel) }) }),
|
|
3335
|
-
(options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("a", { href: "#", className: "btn btn-warning btn-clear", onClick: handleClear, children: translateString(import_utils28.TranslatableString.ClearLabel) }) })
|
|
3336
|
-
] });
|
|
3337
|
-
}
|
|
3338
|
-
var AltDateWidget_default = AltDateWidget;
|
|
3339
|
-
|
|
3340
|
-
// src/components/widgets/AltDateTimeWidget.tsx
|
|
3341
|
-
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
3342
|
-
function AltDateTimeWidget({
|
|
3343
|
-
time = true,
|
|
3344
|
-
...props
|
|
3345
|
-
}) {
|
|
3346
|
-
const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
|
|
3347
|
-
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(AltDateWidget2, { time, ...props });
|
|
3348
|
-
}
|
|
3349
|
-
var AltDateTimeWidget_default = AltDateTimeWidget;
|
|
3350
|
-
|
|
3351
|
-
// src/components/widgets/CheckboxWidget.tsx
|
|
3352
|
-
var import_react13 = require("react");
|
|
3353
|
-
var import_utils29 = require("@rjsf/utils");
|
|
3354
|
-
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
3355
|
-
function CheckboxWidget({
|
|
3356
|
-
schema,
|
|
3357
|
-
uiSchema,
|
|
3358
|
-
options,
|
|
3359
|
-
id,
|
|
3360
|
-
value,
|
|
3361
|
-
disabled,
|
|
3362
|
-
readonly,
|
|
3363
|
-
label,
|
|
3364
|
-
hideLabel,
|
|
3365
|
-
autofocus = false,
|
|
3366
|
-
onBlur,
|
|
3367
|
-
onFocus,
|
|
3368
|
-
onChange,
|
|
3369
|
-
registry
|
|
3370
|
-
}) {
|
|
3371
|
-
const DescriptionFieldTemplate = (0, import_utils29.getTemplate)(
|
|
3372
|
-
"DescriptionFieldTemplate",
|
|
3373
|
-
registry,
|
|
3374
|
-
options
|
|
3375
|
-
);
|
|
3376
|
-
const required = (0, import_utils29.schemaRequiresTrueValue)(schema);
|
|
3377
|
-
const handleChange = (0, import_react13.useCallback)(
|
|
3378
|
-
(event) => onChange(event.target.checked),
|
|
3379
|
-
[onChange]
|
|
3380
|
-
);
|
|
3381
|
-
const handleBlur = (0, import_react13.useCallback)(
|
|
3382
|
-
(event) => onBlur(id, event.target.checked),
|
|
3383
|
-
[onBlur, id]
|
|
3384
|
-
);
|
|
3385
|
-
const handleFocus = (0, import_react13.useCallback)(
|
|
3386
|
-
(event) => onFocus(id, event.target.checked),
|
|
3387
|
-
[onFocus, id]
|
|
3388
|
-
);
|
|
3389
|
-
const description = options.description ?? schema.description;
|
|
3390
|
-
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: `checkbox ${disabled || readonly ? "disabled" : ""}`, children: [
|
|
3391
|
-
!hideLabel && description && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3392
|
-
DescriptionFieldTemplate,
|
|
3393
|
-
{
|
|
3394
|
-
id: (0, import_utils29.descriptionId)(id),
|
|
3395
|
-
description,
|
|
3396
|
-
schema,
|
|
3397
|
-
uiSchema,
|
|
3398
|
-
registry
|
|
3399
|
-
}
|
|
3400
|
-
),
|
|
3401
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("label", { children: [
|
|
3402
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3403
|
-
"input",
|
|
3404
|
-
{
|
|
3405
|
-
type: "checkbox",
|
|
3406
|
-
id,
|
|
3407
|
-
name: id,
|
|
3408
|
-
checked: typeof value === "undefined" ? false : value,
|
|
3409
|
-
required,
|
|
3410
|
-
disabled: disabled || readonly,
|
|
3411
|
-
autoFocus: autofocus,
|
|
3412
|
-
onChange: handleChange,
|
|
3413
|
-
onBlur: handleBlur,
|
|
3414
|
-
onFocus: handleFocus,
|
|
3415
|
-
"aria-describedby": (0, import_utils29.ariaDescribedByIds)(id)
|
|
3416
|
-
}
|
|
3417
|
-
),
|
|
3418
|
-
(0, import_utils29.labelValue)(/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { children: label }), hideLabel)
|
|
3419
|
-
] })
|
|
3420
|
-
] });
|
|
3421
|
-
}
|
|
3422
|
-
var CheckboxWidget_default = CheckboxWidget;
|
|
3423
|
-
|
|
3424
|
-
// src/components/widgets/CheckboxesWidget.tsx
|
|
3425
|
-
var import_react14 = require("react");
|
|
3426
|
-
var import_utils30 = require("@rjsf/utils");
|
|
3427
|
-
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
3428
|
-
function CheckboxesWidget({
|
|
3429
|
-
id,
|
|
3430
|
-
disabled,
|
|
3431
|
-
options: { inline = false, enumOptions, enumDisabled, emptyValue },
|
|
3432
|
-
value,
|
|
3433
|
-
autofocus = false,
|
|
3434
|
-
readonly,
|
|
3435
|
-
onChange,
|
|
3436
|
-
onBlur,
|
|
3437
|
-
onFocus
|
|
3438
|
-
}) {
|
|
3439
|
-
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
3440
|
-
const handleBlur = (0, import_react14.useCallback)(
|
|
3441
|
-
({ target }) => onBlur(id, (0, import_utils30.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3442
|
-
[onBlur, id]
|
|
3443
|
-
);
|
|
3444
|
-
const handleFocus = (0, import_react14.useCallback)(
|
|
3445
|
-
({ target }) => onFocus(id, (0, import_utils30.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3446
|
-
[onFocus, id]
|
|
3447
|
-
);
|
|
3448
|
-
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "checkboxes", id, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
|
|
3449
|
-
const checked = (0, import_utils30.enumOptionsIsSelected)(option.value, checkboxesValues);
|
|
3450
|
-
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
3451
|
-
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
3452
|
-
const handleChange = (event) => {
|
|
3453
|
-
if (event.target.checked) {
|
|
3454
|
-
onChange((0, import_utils30.enumOptionsSelectValue)(index, checkboxesValues, enumOptions));
|
|
3455
|
-
} else {
|
|
3456
|
-
onChange((0, import_utils30.enumOptionsDeselectValue)(index, checkboxesValues, enumOptions));
|
|
3457
|
-
}
|
|
3458
|
-
};
|
|
3459
|
-
const checkbox = /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("span", { children: [
|
|
3460
|
-
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
3461
|
-
"input",
|
|
3462
|
-
{
|
|
3463
|
-
type: "checkbox",
|
|
3464
|
-
id: (0, import_utils30.optionId)(id, index),
|
|
3465
|
-
name: id,
|
|
3466
|
-
checked,
|
|
3467
|
-
value: String(index),
|
|
3468
|
-
disabled: disabled || itemDisabled || readonly,
|
|
3469
|
-
autoFocus: autofocus && index === 0,
|
|
3470
|
-
onChange: handleChange,
|
|
3471
|
-
onBlur: handleBlur,
|
|
3472
|
-
onFocus: handleFocus,
|
|
3473
|
-
"aria-describedby": (0, import_utils30.ariaDescribedByIds)(id)
|
|
3474
|
-
}
|
|
3475
|
-
),
|
|
3476
|
-
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { children: option.label })
|
|
3477
|
-
] });
|
|
3478
|
-
return inline ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("label", { className: `checkbox-inline ${disabledCls}`, children: checkbox }, index) : /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: `checkbox ${disabledCls}`, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("label", { children: checkbox }) }, index);
|
|
3479
|
-
}) });
|
|
3480
|
-
}
|
|
3481
|
-
var CheckboxesWidget_default = CheckboxesWidget;
|
|
3482
|
-
|
|
3483
|
-
// src/components/widgets/ColorWidget.tsx
|
|
3484
|
-
var import_utils31 = require("@rjsf/utils");
|
|
3485
|
-
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
3486
|
-
function ColorWidget(props) {
|
|
3487
|
-
const { disabled, readonly, options, registry } = props;
|
|
3488
|
-
const BaseInputTemplate2 = (0, import_utils31.getTemplate)("BaseInputTemplate", registry, options);
|
|
3489
|
-
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BaseInputTemplate2, { type: "color", ...props, disabled: disabled || readonly });
|
|
3490
|
-
}
|
|
3491
|
-
|
|
3492
|
-
// src/components/widgets/DateWidget.tsx
|
|
3493
|
-
var import_react15 = require("react");
|
|
3494
|
-
var import_utils32 = require("@rjsf/utils");
|
|
3495
|
-
var import_jsx_runtime37 = require("react/jsx-runtime");
|
|
3496
|
-
function DateWidget(props) {
|
|
3497
|
-
const { onChange, options, registry } = props;
|
|
3498
|
-
const BaseInputTemplate2 = (0, import_utils32.getTemplate)("BaseInputTemplate", registry, options);
|
|
3499
|
-
const handleChange = (0, import_react15.useCallback)((value) => onChange(value || void 0), [onChange]);
|
|
3500
|
-
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(BaseInputTemplate2, { type: "date", ...props, onChange: handleChange });
|
|
3501
|
-
}
|
|
3502
|
-
|
|
3503
|
-
// src/components/widgets/DateTimeWidget.tsx
|
|
3504
|
-
var import_utils33 = require("@rjsf/utils");
|
|
3505
|
-
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
3506
|
-
function DateTimeWidget(props) {
|
|
3507
|
-
const { onChange, value, options, registry } = props;
|
|
3508
|
-
const BaseInputTemplate2 = (0, import_utils33.getTemplate)("BaseInputTemplate", registry, options);
|
|
3509
|
-
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
|
|
3510
|
-
BaseInputTemplate2,
|
|
3511
|
-
{
|
|
3512
|
-
type: "datetime-local",
|
|
3513
|
-
...props,
|
|
3514
|
-
value: (0, import_utils33.utcToLocal)(value),
|
|
3515
|
-
onChange: (value2) => onChange((0, import_utils33.localToUTC)(value2))
|
|
3516
|
-
}
|
|
3517
|
-
);
|
|
3518
|
-
}
|
|
3519
|
-
|
|
3520
|
-
// src/components/widgets/EmailWidget.tsx
|
|
3521
|
-
var import_utils34 = require("@rjsf/utils");
|
|
3522
|
-
var import_jsx_runtime39 = require("react/jsx-runtime");
|
|
3523
|
-
function EmailWidget(props) {
|
|
3524
|
-
const { options, registry } = props;
|
|
3525
|
-
const BaseInputTemplate2 = (0, import_utils34.getTemplate)("BaseInputTemplate", registry, options);
|
|
3526
|
-
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(BaseInputTemplate2, { type: "email", ...props });
|
|
3527
|
-
}
|
|
3528
|
-
|
|
3529
|
-
// src/components/widgets/FileWidget.tsx
|
|
3530
|
-
var import_react16 = require("react");
|
|
3531
|
-
var import_utils35 = require("@rjsf/utils");
|
|
3532
|
-
var import_markdown_to_jsx4 = __toESM(require("markdown-to-jsx"), 1);
|
|
3533
|
-
var import_jsx_runtime40 = require("react/jsx-runtime");
|
|
3534
|
-
function addNameToDataURL(dataURL, name) {
|
|
3535
|
-
if (dataURL === null) {
|
|
3536
|
-
return null;
|
|
3537
|
-
}
|
|
3538
|
-
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
3539
|
-
}
|
|
3540
|
-
function processFile(file) {
|
|
3541
|
-
const { name, size, type } = file;
|
|
3542
|
-
return new Promise((resolve, reject) => {
|
|
3543
|
-
const reader = new window.FileReader();
|
|
3544
|
-
reader.onerror = reject;
|
|
3545
|
-
reader.onload = (event) => {
|
|
3546
|
-
if (typeof event.target?.result === "string") {
|
|
3547
|
-
resolve({
|
|
3548
|
-
dataURL: addNameToDataURL(event.target.result, name),
|
|
3549
|
-
name,
|
|
3550
|
-
size,
|
|
3551
|
-
type
|
|
3552
|
-
});
|
|
3553
|
-
} else {
|
|
3554
|
-
resolve({
|
|
3555
|
-
dataURL: null,
|
|
3556
|
-
name,
|
|
3557
|
-
size,
|
|
3558
|
-
type
|
|
3559
|
-
});
|
|
3560
|
-
}
|
|
3561
|
-
};
|
|
3562
|
-
reader.readAsDataURL(file);
|
|
3563
|
-
});
|
|
3564
|
-
}
|
|
3565
|
-
function processFiles(files) {
|
|
3566
|
-
return Promise.all(Array.from(files).map(processFile));
|
|
3567
|
-
}
|
|
3568
|
-
function FileInfoPreview({
|
|
3569
|
-
fileInfo,
|
|
3570
|
-
registry
|
|
3571
|
-
}) {
|
|
3572
|
-
const { translateString } = registry;
|
|
3573
|
-
const { dataURL, type, name } = fileInfo;
|
|
3574
|
-
if (!dataURL) {
|
|
3575
|
-
return null;
|
|
3576
|
-
}
|
|
3577
|
-
if (["image/jpeg", "image/png"].includes(type)) {
|
|
3578
|
-
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("img", { src: dataURL, style: { maxWidth: "100%" }, className: "file-preview" });
|
|
3579
|
-
}
|
|
3580
|
-
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
|
|
3581
|
-
" ",
|
|
3582
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("a", { download: `preview-${name}`, href: dataURL, className: "file-download", children: translateString(import_utils35.TranslatableString.PreviewLabel) })
|
|
3583
|
-
] });
|
|
3584
|
-
}
|
|
3585
|
-
function FilesInfo({
|
|
3586
|
-
filesInfo,
|
|
3587
|
-
registry,
|
|
3588
|
-
preview,
|
|
3589
|
-
onRemove,
|
|
3590
|
-
options
|
|
3591
|
-
}) {
|
|
3592
|
-
if (filesInfo.length === 0) {
|
|
3593
|
-
return null;
|
|
3594
|
-
}
|
|
3595
|
-
const { translateString } = registry;
|
|
3596
|
-
const { RemoveButton: RemoveButton2 } = (0, import_utils35.getTemplate)("ButtonTemplates", registry, options);
|
|
3597
|
-
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("ul", { className: "file-info", children: filesInfo.map((fileInfo, key) => {
|
|
3598
|
-
const { name, size, type } = fileInfo;
|
|
3599
|
-
const handleRemove = () => onRemove(key);
|
|
3600
|
-
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("li", { children: [
|
|
3601
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_markdown_to_jsx4.default, { children: translateString(import_utils35.TranslatableString.FilesInfo, [name, type, String(size)]) }),
|
|
3602
|
-
preview && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(FileInfoPreview, { fileInfo, registry }),
|
|
3603
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(RemoveButton2, { onClick: handleRemove, registry })
|
|
3604
|
-
] }, key);
|
|
3605
|
-
}) });
|
|
3606
|
-
}
|
|
3607
|
-
function extractFileInfo(dataURLs) {
|
|
3608
|
-
return dataURLs.reduce((acc, dataURL) => {
|
|
3609
|
-
if (!dataURL) {
|
|
3610
|
-
return acc;
|
|
3611
|
-
}
|
|
3612
|
-
try {
|
|
3613
|
-
const { blob, name } = (0, import_utils35.dataURItoBlob)(dataURL);
|
|
3614
|
-
return [
|
|
3615
|
-
...acc,
|
|
3616
|
-
{
|
|
3617
|
-
dataURL,
|
|
3618
|
-
name,
|
|
3619
|
-
size: blob.size,
|
|
3620
|
-
type: blob.type
|
|
3621
|
-
}
|
|
3622
|
-
];
|
|
3623
|
-
} catch {
|
|
3624
|
-
return acc;
|
|
3625
|
-
}
|
|
3626
|
-
}, []);
|
|
3627
|
-
}
|
|
3628
|
-
function FileWidget(props) {
|
|
3629
|
-
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
3630
|
-
const BaseInputTemplate2 = (0, import_utils35.getTemplate)("BaseInputTemplate", registry, options);
|
|
3631
|
-
const handleChange = (0, import_react16.useCallback)(
|
|
3632
|
-
(event) => {
|
|
3633
|
-
if (!event.target.files) {
|
|
3634
|
-
return;
|
|
3635
|
-
}
|
|
3636
|
-
processFiles(event.target.files).then((filesInfoEvent) => {
|
|
3637
|
-
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL);
|
|
3638
|
-
if (multiple) {
|
|
3639
|
-
onChange(value.concat(newValue));
|
|
3640
|
-
} else {
|
|
3641
|
-
onChange(newValue[0]);
|
|
3642
|
-
}
|
|
3643
|
-
});
|
|
3644
|
-
},
|
|
3645
|
-
[multiple, value, onChange]
|
|
3646
|
-
);
|
|
3647
|
-
const filesInfo = (0, import_react16.useMemo)(() => extractFileInfo(Array.isArray(value) ? value : [value]), [value]);
|
|
3648
|
-
const rmFile = (0, import_react16.useCallback)(
|
|
3649
|
-
(index) => {
|
|
3650
|
-
if (multiple) {
|
|
3651
|
-
const newValue = value.filter((_, i) => i !== index);
|
|
3652
|
-
onChange(newValue);
|
|
3653
|
-
} else {
|
|
3654
|
-
onChange(void 0);
|
|
3655
|
-
}
|
|
3656
|
-
},
|
|
3657
|
-
[multiple, value, onChange]
|
|
3658
|
-
);
|
|
3659
|
-
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { children: [
|
|
3660
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
3661
|
-
BaseInputTemplate2,
|
|
3662
|
-
{
|
|
3663
|
-
...props,
|
|
3664
|
-
disabled: disabled || readonly,
|
|
3665
|
-
type: "file",
|
|
3666
|
-
required: value ? false : required,
|
|
3667
|
-
onChangeOverride: handleChange,
|
|
3668
|
-
value: "",
|
|
3669
|
-
accept: options.accept ? String(options.accept) : void 0
|
|
3670
|
-
}
|
|
3671
|
-
),
|
|
3672
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
3673
|
-
FilesInfo,
|
|
3674
|
-
{
|
|
3675
|
-
filesInfo,
|
|
3676
|
-
onRemove: rmFile,
|
|
3677
|
-
registry,
|
|
3678
|
-
preview: options.filePreview,
|
|
3679
|
-
options
|
|
3680
|
-
}
|
|
3681
|
-
)
|
|
3682
|
-
] });
|
|
3683
|
-
}
|
|
3684
|
-
var FileWidget_default = FileWidget;
|
|
3685
|
-
|
|
3686
|
-
// src/components/widgets/HiddenWidget.tsx
|
|
3687
|
-
var import_jsx_runtime41 = require("react/jsx-runtime");
|
|
3688
|
-
function HiddenWidget({
|
|
3689
|
-
id,
|
|
3690
|
-
value
|
|
3691
|
-
}) {
|
|
3692
|
-
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("input", { type: "hidden", id, name: id, value: typeof value === "undefined" ? "" : value });
|
|
3693
|
-
}
|
|
3694
|
-
var HiddenWidget_default = HiddenWidget;
|
|
3695
|
-
|
|
3696
|
-
// src/components/widgets/PasswordWidget.tsx
|
|
3697
|
-
var import_utils36 = require("@rjsf/utils");
|
|
3698
|
-
var import_jsx_runtime42 = require("react/jsx-runtime");
|
|
3699
|
-
function PasswordWidget(props) {
|
|
3700
|
-
const { options, registry } = props;
|
|
3701
|
-
const BaseInputTemplate2 = (0, import_utils36.getTemplate)("BaseInputTemplate", registry, options);
|
|
3702
|
-
return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(BaseInputTemplate2, { type: "password", ...props });
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
// src/components/widgets/RadioWidget.tsx
|
|
3706
|
-
var import_react17 = require("react");
|
|
3707
|
-
var import_utils37 = require("@rjsf/utils");
|
|
3708
|
-
var import_jsx_runtime43 = require("react/jsx-runtime");
|
|
3709
|
-
function RadioWidget({
|
|
3710
|
-
options,
|
|
3711
|
-
value,
|
|
3712
|
-
required,
|
|
3713
|
-
disabled,
|
|
3714
|
-
readonly,
|
|
3715
|
-
autofocus = false,
|
|
3716
|
-
onBlur,
|
|
3717
|
-
onFocus,
|
|
3718
|
-
onChange,
|
|
3719
|
-
id
|
|
3720
|
-
}) {
|
|
3721
|
-
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
3722
|
-
const handleBlur = (0, import_react17.useCallback)(
|
|
3723
|
-
({ target }) => onBlur(id, (0, import_utils37.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3724
|
-
[onBlur, enumOptions, emptyValue, id]
|
|
3725
|
-
);
|
|
3726
|
-
const handleFocus = (0, import_react17.useCallback)(
|
|
3727
|
-
({ target }) => onFocus(id, (0, import_utils37.enumOptionsValueForIndex)(target && target.value, enumOptions, emptyValue)),
|
|
3728
|
-
[onFocus, enumOptions, emptyValue, id]
|
|
3729
|
-
);
|
|
3730
|
-
return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "field-radio-group", id, role: "radiogroup", children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
|
|
3731
|
-
const checked = (0, import_utils37.enumOptionsIsSelected)(option.value, value);
|
|
3732
|
-
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
3733
|
-
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
3734
|
-
const handleChange = () => onChange(option.value);
|
|
3735
|
-
const radio = /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("span", { children: [
|
|
3736
|
-
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
3737
|
-
"input",
|
|
3738
|
-
{
|
|
3739
|
-
type: "radio",
|
|
3740
|
-
id: (0, import_utils37.optionId)(id, i),
|
|
3741
|
-
checked,
|
|
3742
|
-
name: id,
|
|
3743
|
-
required,
|
|
3744
|
-
value: String(i),
|
|
3745
|
-
disabled: disabled || itemDisabled || readonly,
|
|
3746
|
-
autoFocus: autofocus && i === 0,
|
|
3747
|
-
onChange: handleChange,
|
|
3748
|
-
onBlur: handleBlur,
|
|
3749
|
-
onFocus: handleFocus,
|
|
3750
|
-
"aria-describedby": (0, import_utils37.ariaDescribedByIds)(id)
|
|
3751
|
-
}
|
|
3752
|
-
),
|
|
3753
|
-
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { children: option.label })
|
|
3754
|
-
] });
|
|
3755
|
-
return inline ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("label", { className: `radio-inline ${disabledCls}`, children: radio }, i) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: `radio ${disabledCls}`, children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("label", { children: radio }) }, i);
|
|
3756
|
-
}) });
|
|
3757
|
-
}
|
|
3758
|
-
var RadioWidget_default = RadioWidget;
|
|
3759
|
-
|
|
3760
|
-
// src/components/widgets/RangeWidget.tsx
|
|
3761
|
-
var import_jsx_runtime44 = require("react/jsx-runtime");
|
|
3762
|
-
function RangeWidget(props) {
|
|
3763
|
-
const {
|
|
3764
|
-
value,
|
|
3765
|
-
registry: {
|
|
3766
|
-
templates: { BaseInputTemplate: BaseInputTemplate2 }
|
|
3767
|
-
}
|
|
3768
|
-
} = props;
|
|
3769
|
-
return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "field-range-wrapper", children: [
|
|
3770
|
-
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(BaseInputTemplate2, { type: "range", ...props }),
|
|
3771
|
-
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "range-view", children: value })
|
|
3772
|
-
] });
|
|
3773
|
-
}
|
|
3774
|
-
|
|
3775
|
-
// src/components/widgets/RatingWidget.tsx
|
|
3776
|
-
var import_react18 = require("react");
|
|
3777
|
-
var import_jsx_runtime45 = require("react/jsx-runtime");
|
|
3778
|
-
function RatingWidget({
|
|
3779
|
-
id,
|
|
3780
|
-
value,
|
|
3781
|
-
required,
|
|
3782
|
-
disabled,
|
|
3783
|
-
readonly,
|
|
3784
|
-
autofocus,
|
|
3785
|
-
onChange,
|
|
3786
|
-
onFocus,
|
|
3787
|
-
onBlur,
|
|
3788
|
-
schema,
|
|
3789
|
-
options
|
|
3790
|
-
}) {
|
|
3791
|
-
const { stars = 5, shape = "star" } = options;
|
|
3792
|
-
const numStars = schema.maximum ? Math.min(schema.maximum, 5) : Math.min(Math.max(stars, 1), 5);
|
|
3793
|
-
const min = schema.minimum || 0;
|
|
3794
|
-
const handleStarClick = (0, import_react18.useCallback)(
|
|
3795
|
-
(starValue) => {
|
|
3796
|
-
if (!disabled && !readonly) {
|
|
3797
|
-
onChange(starValue);
|
|
3798
|
-
}
|
|
3799
|
-
},
|
|
3800
|
-
[onChange, disabled, readonly]
|
|
3801
|
-
);
|
|
3802
|
-
const handleFocus = (0, import_react18.useCallback)(
|
|
3803
|
-
(event) => {
|
|
3804
|
-
if (onFocus) {
|
|
3805
|
-
const starValue = Number(event.target.dataset.value);
|
|
3806
|
-
onFocus(id, starValue);
|
|
3807
|
-
}
|
|
3808
|
-
},
|
|
3809
|
-
[onFocus, id]
|
|
3810
|
-
);
|
|
3811
|
-
const handleBlur = (0, import_react18.useCallback)(
|
|
3812
|
-
(event) => {
|
|
3813
|
-
if (onBlur) {
|
|
3814
|
-
const starValue = Number(event.target.dataset.value);
|
|
3815
|
-
onBlur(id, starValue);
|
|
3816
|
-
}
|
|
3817
|
-
},
|
|
3818
|
-
[onBlur, id]
|
|
3819
|
-
);
|
|
3820
|
-
const getSymbol = (isFilled) => {
|
|
3821
|
-
if (shape === "heart") {
|
|
3822
|
-
return isFilled ? "\u2665" : "\u2661";
|
|
3823
|
-
}
|
|
3824
|
-
return isFilled ? "\u2605" : "\u2606";
|
|
3825
|
-
};
|
|
3826
|
-
return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_jsx_runtime45.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
|
|
3827
|
-
"div",
|
|
3828
|
-
{
|
|
3829
|
-
className: "rating-widget",
|
|
3830
|
-
style: {
|
|
3831
|
-
display: "inline-flex",
|
|
3832
|
-
fontSize: "1.5rem",
|
|
3833
|
-
cursor: disabled || readonly ? "default" : "pointer"
|
|
3834
|
-
},
|
|
3835
|
-
children: [
|
|
3836
|
-
[...Array(numStars)].map((_, index) => {
|
|
3837
|
-
const starValue = min + index;
|
|
3838
|
-
const isFilled = starValue <= value;
|
|
3839
|
-
return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
|
|
3840
|
-
"span",
|
|
3841
|
-
{
|
|
3842
|
-
onClick: () => handleStarClick(starValue),
|
|
3843
|
-
onFocus: handleFocus,
|
|
3844
|
-
onBlur: handleBlur,
|
|
3845
|
-
"data-value": starValue,
|
|
3846
|
-
tabIndex: disabled || readonly ? -1 : 0,
|
|
3847
|
-
role: "radio",
|
|
3848
|
-
"aria-checked": starValue === value,
|
|
3849
|
-
"aria-label": `${starValue} ${shape === "heart" ? "heart" : "star"}${starValue === 1 ? "" : "s"}`,
|
|
3850
|
-
style: {
|
|
3851
|
-
color: isFilled ? "#FFD700" : "#ccc",
|
|
3852
|
-
padding: "0 0.2rem",
|
|
3853
|
-
transition: "color 0.2s",
|
|
3854
|
-
userSelect: "none"
|
|
3855
|
-
},
|
|
3856
|
-
children: getSymbol(isFilled)
|
|
3857
|
-
},
|
|
3858
|
-
index
|
|
3859
|
-
);
|
|
3860
|
-
}),
|
|
3861
|
-
/* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
|
|
3862
|
-
"input",
|
|
3863
|
-
{
|
|
3864
|
-
type: "hidden",
|
|
3865
|
-
id,
|
|
3866
|
-
name: id,
|
|
3867
|
-
value: value || "",
|
|
3868
|
-
required,
|
|
3869
|
-
disabled: disabled || readonly,
|
|
3870
|
-
"aria-hidden": "true"
|
|
3871
|
-
}
|
|
3872
|
-
)
|
|
3873
|
-
]
|
|
3874
|
-
}
|
|
3875
|
-
) });
|
|
3876
|
-
}
|
|
3877
|
-
|
|
3878
|
-
// src/components/widgets/SelectWidget.tsx
|
|
3879
|
-
var import_react19 = require("react");
|
|
3880
|
-
var import_utils38 = require("@rjsf/utils");
|
|
3881
|
-
var import_jsx_runtime46 = require("react/jsx-runtime");
|
|
3882
|
-
function getValue(event, multiple) {
|
|
3883
|
-
if (multiple) {
|
|
3884
|
-
return Array.from(event.target.options).slice().filter((o) => o.selected).map((o) => o.value);
|
|
3885
|
-
}
|
|
3886
|
-
return event.target.value;
|
|
3887
|
-
}
|
|
3888
|
-
function SelectWidget({
|
|
3889
|
-
schema,
|
|
3890
|
-
id,
|
|
3891
|
-
options,
|
|
3892
|
-
value,
|
|
3893
|
-
required,
|
|
3894
|
-
disabled,
|
|
3895
|
-
readonly,
|
|
3896
|
-
multiple = false,
|
|
3897
|
-
autofocus = false,
|
|
3898
|
-
onChange,
|
|
3899
|
-
onBlur,
|
|
3900
|
-
onFocus,
|
|
3901
|
-
placeholder
|
|
3902
|
-
}) {
|
|
3903
|
-
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
3904
|
-
const emptyValue = multiple ? [] : "";
|
|
3905
|
-
const handleFocus = (0, import_react19.useCallback)(
|
|
3906
|
-
(event) => {
|
|
3907
|
-
const newValue = getValue(event, multiple);
|
|
3908
|
-
return onFocus(id, (0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
3909
|
-
},
|
|
3910
|
-
[onFocus, id, multiple, enumOptions, optEmptyVal]
|
|
3911
|
-
);
|
|
3912
|
-
const handleBlur = (0, import_react19.useCallback)(
|
|
3913
|
-
(event) => {
|
|
3914
|
-
const newValue = getValue(event, multiple);
|
|
3915
|
-
return onBlur(id, (0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
3916
|
-
},
|
|
3917
|
-
[onBlur, id, multiple, enumOptions, optEmptyVal]
|
|
3918
|
-
);
|
|
3919
|
-
const handleChange = (0, import_react19.useCallback)(
|
|
3920
|
-
(event) => {
|
|
3921
|
-
const newValue = getValue(event, multiple);
|
|
3922
|
-
return onChange((0, import_utils38.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
3923
|
-
},
|
|
3924
|
-
[onChange, multiple, enumOptions, optEmptyVal]
|
|
3925
|
-
);
|
|
3926
|
-
const selectedIndexes = (0, import_utils38.enumOptionsIndexForValue)(value, enumOptions, multiple);
|
|
3927
|
-
const showPlaceholderOption = !multiple && schema.default === void 0;
|
|
3928
|
-
return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
|
|
3929
|
-
"select",
|
|
3930
|
-
{
|
|
3931
|
-
id,
|
|
3932
|
-
name: id,
|
|
3933
|
-
multiple,
|
|
3934
|
-
role: "combobox",
|
|
3935
|
-
className: "form-control",
|
|
3936
|
-
value: typeof selectedIndexes === "undefined" ? emptyValue : selectedIndexes,
|
|
3937
|
-
required,
|
|
3938
|
-
disabled: disabled || readonly,
|
|
3939
|
-
autoFocus: autofocus,
|
|
3940
|
-
onBlur: handleBlur,
|
|
3941
|
-
onFocus: handleFocus,
|
|
3942
|
-
onChange: handleChange,
|
|
3943
|
-
"aria-describedby": (0, import_utils38.ariaDescribedByIds)(id),
|
|
3944
|
-
children: [
|
|
3945
|
-
showPlaceholderOption && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("option", { value: "", children: placeholder }),
|
|
3946
|
-
Array.isArray(enumOptions) && enumOptions.map(({ value: value2, label }, i) => {
|
|
3947
|
-
const disabled2 = enumDisabled && enumDisabled.indexOf(value2) !== -1;
|
|
3948
|
-
return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("option", { value: String(i), disabled: disabled2, children: label }, i);
|
|
3949
|
-
})
|
|
3950
|
-
]
|
|
3951
|
-
}
|
|
3952
|
-
);
|
|
3953
|
-
}
|
|
3954
|
-
var SelectWidget_default = SelectWidget;
|
|
3955
|
-
|
|
3956
|
-
// src/components/widgets/TextareaWidget.tsx
|
|
3957
|
-
var import_react20 = require("react");
|
|
3958
|
-
var import_utils39 = require("@rjsf/utils");
|
|
3959
|
-
var import_jsx_runtime47 = require("react/jsx-runtime");
|
|
3960
|
-
function TextareaWidget({
|
|
3961
|
-
id,
|
|
3962
|
-
options = {},
|
|
3963
|
-
placeholder,
|
|
3964
|
-
value,
|
|
3965
|
-
required,
|
|
3966
|
-
disabled,
|
|
3967
|
-
readonly,
|
|
3968
|
-
autofocus = false,
|
|
3969
|
-
onChange,
|
|
3970
|
-
onBlur,
|
|
3971
|
-
onFocus
|
|
3972
|
-
}) {
|
|
3973
|
-
const handleChange = (0, import_react20.useCallback)(
|
|
3974
|
-
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
3975
|
-
[onChange, options.emptyValue]
|
|
3976
|
-
);
|
|
3977
|
-
const handleBlur = (0, import_react20.useCallback)(
|
|
3978
|
-
({ target }) => onBlur(id, target && target.value),
|
|
3979
|
-
[onBlur, id]
|
|
3980
|
-
);
|
|
3981
|
-
const handleFocus = (0, import_react20.useCallback)(
|
|
3982
|
-
({ target }) => onFocus(id, target && target.value),
|
|
3983
|
-
[id, onFocus]
|
|
3984
|
-
);
|
|
3985
|
-
return /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
|
|
3986
|
-
"textarea",
|
|
3987
|
-
{
|
|
3988
|
-
id,
|
|
3989
|
-
name: id,
|
|
3990
|
-
className: "form-control",
|
|
3991
|
-
value: value ? value : "",
|
|
3992
|
-
placeholder,
|
|
3993
|
-
required,
|
|
3994
|
-
disabled,
|
|
3995
|
-
readOnly: readonly,
|
|
3996
|
-
autoFocus: autofocus,
|
|
3997
|
-
rows: options.rows,
|
|
3998
|
-
onBlur: handleBlur,
|
|
3999
|
-
onFocus: handleFocus,
|
|
4000
|
-
onChange: handleChange,
|
|
4001
|
-
"aria-describedby": (0, import_utils39.ariaDescribedByIds)(id)
|
|
4002
|
-
}
|
|
4003
|
-
);
|
|
4004
|
-
}
|
|
4005
|
-
TextareaWidget.defaultProps = {
|
|
4006
|
-
autofocus: false,
|
|
4007
|
-
options: {}
|
|
4008
|
-
};
|
|
4009
|
-
var TextareaWidget_default = TextareaWidget;
|
|
4010
|
-
|
|
4011
|
-
// src/components/widgets/TextWidget.tsx
|
|
4012
|
-
var import_utils40 = require("@rjsf/utils");
|
|
4013
|
-
var import_jsx_runtime48 = require("react/jsx-runtime");
|
|
4014
|
-
function TextWidget(props) {
|
|
4015
|
-
const { options, registry } = props;
|
|
4016
|
-
const BaseInputTemplate2 = (0, import_utils40.getTemplate)("BaseInputTemplate", registry, options);
|
|
4017
|
-
return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(BaseInputTemplate2, { ...props });
|
|
4018
|
-
}
|
|
4019
|
-
|
|
4020
|
-
// src/components/widgets/TimeWidget.tsx
|
|
4021
|
-
var import_react21 = require("react");
|
|
4022
|
-
var import_utils41 = require("@rjsf/utils");
|
|
4023
|
-
var import_jsx_runtime49 = require("react/jsx-runtime");
|
|
4024
|
-
function TimeWidget(props) {
|
|
4025
|
-
const { onChange, options, registry } = props;
|
|
4026
|
-
const BaseInputTemplate2 = (0, import_utils41.getTemplate)("BaseInputTemplate", registry, options);
|
|
4027
|
-
const handleChange = (0, import_react21.useCallback)((value) => onChange(value ? `${value}:00` : void 0), [onChange]);
|
|
4028
|
-
return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(BaseInputTemplate2, { type: "time", ...props, onChange: handleChange });
|
|
4029
|
-
}
|
|
4030
|
-
|
|
4031
|
-
// src/components/widgets/URLWidget.tsx
|
|
4032
|
-
var import_utils42 = require("@rjsf/utils");
|
|
4033
|
-
var import_jsx_runtime50 = require("react/jsx-runtime");
|
|
4034
|
-
function URLWidget(props) {
|
|
4035
|
-
const { options, registry } = props;
|
|
4036
|
-
const BaseInputTemplate2 = (0, import_utils42.getTemplate)("BaseInputTemplate", registry, options);
|
|
4037
|
-
return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(BaseInputTemplate2, { type: "url", ...props });
|
|
4038
|
-
}
|
|
4039
|
-
|
|
4040
|
-
// src/components/widgets/UpDownWidget.tsx
|
|
4041
|
-
var import_utils43 = require("@rjsf/utils");
|
|
4042
|
-
var import_jsx_runtime51 = require("react/jsx-runtime");
|
|
4043
|
-
function UpDownWidget(props) {
|
|
4044
|
-
const { options, registry } = props;
|
|
4045
|
-
const BaseInputTemplate2 = (0, import_utils43.getTemplate)("BaseInputTemplate", registry, options);
|
|
4046
|
-
return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(BaseInputTemplate2, { type: "number", ...props });
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
|
-
// src/components/widgets/index.ts
|
|
4050
|
-
function widgets() {
|
|
4051
|
-
return {
|
|
4052
|
-
AltDateWidget: AltDateWidget_default,
|
|
4053
|
-
AltDateTimeWidget: AltDateTimeWidget_default,
|
|
4054
|
-
CheckboxWidget: CheckboxWidget_default,
|
|
4055
|
-
CheckboxesWidget: CheckboxesWidget_default,
|
|
4056
|
-
ColorWidget,
|
|
4057
|
-
DateWidget,
|
|
4058
|
-
DateTimeWidget,
|
|
4059
|
-
EmailWidget,
|
|
4060
|
-
FileWidget: FileWidget_default,
|
|
4061
|
-
HiddenWidget: HiddenWidget_default,
|
|
4062
|
-
PasswordWidget,
|
|
4063
|
-
RadioWidget: RadioWidget_default,
|
|
4064
|
-
RangeWidget,
|
|
4065
|
-
RatingWidget,
|
|
4066
|
-
SelectWidget: SelectWidget_default,
|
|
4067
|
-
TextWidget,
|
|
4068
|
-
TextareaWidget: TextareaWidget_default,
|
|
4069
|
-
TimeWidget,
|
|
4070
|
-
UpDownWidget,
|
|
4071
|
-
URLWidget
|
|
4072
|
-
};
|
|
4073
|
-
}
|
|
4074
|
-
var widgets_default = widgets;
|
|
4075
|
-
|
|
4076
|
-
// src/getDefaultRegistry.ts
|
|
4077
|
-
function getDefaultRegistry() {
|
|
4078
|
-
return {
|
|
4079
|
-
fields: fields_default(),
|
|
4080
|
-
templates: templates_default(),
|
|
4081
|
-
widgets: widgets_default(),
|
|
4082
|
-
rootSchema: {},
|
|
4083
|
-
formContext: {},
|
|
4084
|
-
translateString: import_utils44.englishStringTranslator
|
|
4085
|
-
};
|
|
4086
|
-
}
|
|
4087
|
-
|
|
4088
|
-
// src/components/Form.tsx
|
|
4089
|
-
var import_jsx_runtime52 = require("react/jsx-runtime");
|
|
4090
|
-
var Form = class extends import_react22.Component {
|
|
4091
|
-
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
4092
|
-
* provide any possible type here
|
|
4093
|
-
*/
|
|
4094
|
-
formElement;
|
|
4095
|
-
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
|
|
4096
|
-
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
|
|
4097
|
-
* state construction.
|
|
4098
|
-
*
|
|
4099
|
-
* @param props - The initial props for the `Form`
|
|
4100
|
-
*/
|
|
4101
|
-
constructor(props) {
|
|
4102
|
-
super(props);
|
|
4103
|
-
if (!props.validator) {
|
|
4104
|
-
throw new Error("A validator is required for Form functionality to work");
|
|
4105
|
-
}
|
|
4106
|
-
this.state = this.getStateFromProps(props, props.formData);
|
|
4107
|
-
if (this.props.onChange && !(0, import_utils45.deepEquals)(this.state.formData, this.props.formData)) {
|
|
4108
|
-
this.props.onChange(this.state);
|
|
4109
|
-
}
|
|
4110
|
-
this.formElement = (0, import_react22.createRef)();
|
|
4111
|
-
}
|
|
4112
|
-
/**
|
|
4113
|
-
* `getSnapshotBeforeUpdate` is a React lifecycle method that is invoked right before the most recently rendered
|
|
4114
|
-
* output is committed to the DOM. It enables your component to capture current values (e.g., scroll position) before
|
|
4115
|
-
* they are potentially changed.
|
|
4116
|
-
*
|
|
4117
|
-
* In this case, it checks if the props have changed since the last render. If they have, it computes the next state
|
|
4118
|
-
* of the component using `getStateFromProps` method and returns it along with a `shouldUpdate` flag set to `true` IF
|
|
4119
|
-
* the `nextState` and `prevState` are different, otherwise `false`. This ensures that we have the most up-to-date
|
|
4120
|
-
* state ready to be applied in `componentDidUpdate`.
|
|
4121
|
-
*
|
|
4122
|
-
* If `formData` hasn't changed, it simply returns an object with `shouldUpdate` set to `false`, indicating that a
|
|
4123
|
-
* state update is not necessary.
|
|
4124
|
-
*
|
|
4125
|
-
* @param prevProps - The previous set of props before the update.
|
|
4126
|
-
* @param prevState - The previous state before the update.
|
|
4127
|
-
* @returns Either an object containing the next state and a flag indicating that an update should occur, or an object
|
|
4128
|
-
* with a flag indicating that an update is not necessary.
|
|
4129
|
-
*/
|
|
4130
|
-
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
4131
|
-
if (!(0, import_utils45.deepEquals)(this.props, prevProps)) {
|
|
4132
|
-
const formDataChangedFields = (0, import_utils45.getChangedFields)(this.props.formData, prevProps.formData);
|
|
4133
|
-
const isSchemaChanged = !(0, import_utils45.deepEquals)(prevProps.schema, this.props.schema);
|
|
4134
|
-
const isFormDataChanged = formDataChangedFields.length > 0 || !(0, import_utils45.deepEquals)(prevProps.formData, this.props.formData);
|
|
4135
|
-
const nextState = this.getStateFromProps(
|
|
4136
|
-
this.props,
|
|
4137
|
-
this.props.formData,
|
|
4138
|
-
// If the `schema` has changed, we need to update the retrieved schema.
|
|
4139
|
-
// Or if the `formData` changes, for example in the case of a schema with dependencies that need to
|
|
4140
|
-
// match one of the subSchemas, the retrieved schema must be updated.
|
|
4141
|
-
isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
|
|
4142
|
-
isSchemaChanged,
|
|
4143
|
-
formDataChangedFields
|
|
4144
|
-
);
|
|
4145
|
-
const shouldUpdate = !(0, import_utils45.deepEquals)(nextState, prevState);
|
|
4146
|
-
return { nextState, shouldUpdate };
|
|
4147
|
-
}
|
|
4148
|
-
return { shouldUpdate: false };
|
|
4149
|
-
}
|
|
4150
|
-
/**
|
|
4151
|
-
* `componentDidUpdate` is a React lifecycle method that is invoked immediately after updating occurs. This method is
|
|
4152
|
-
* not called for the initial render.
|
|
4153
|
-
*
|
|
4154
|
-
* Here, it checks if an update is necessary based on the `shouldUpdate` flag received from `getSnapshotBeforeUpdate`.
|
|
4155
|
-
* If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
|
|
4156
|
-
* changes.
|
|
4157
|
-
*
|
|
4158
|
-
* @param _ - The previous set of props.
|
|
4159
|
-
* @param prevState - The previous state of the component before the update.
|
|
4160
|
-
* @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
|
|
4161
|
-
*/
|
|
4162
|
-
componentDidUpdate(_, prevState, snapshot) {
|
|
4163
|
-
if (snapshot.shouldUpdate) {
|
|
4164
|
-
const { nextState } = snapshot;
|
|
4165
|
-
if (!(0, import_utils45.deepEquals)(nextState.formData, this.props.formData) && !(0, import_utils45.deepEquals)(nextState.formData, prevState.formData) && this.props.onChange) {
|
|
4166
|
-
this.props.onChange(nextState);
|
|
4167
|
-
}
|
|
4168
|
-
this.setState(nextState);
|
|
4169
|
-
}
|
|
4170
|
-
}
|
|
4171
|
-
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
4172
|
-
* `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the
|
|
4173
|
-
* validation process IF required by the `props`.
|
|
4174
|
-
*
|
|
4175
|
-
* @param props - The props passed to the `Form`
|
|
4176
|
-
* @param inputFormData - The new or current data for the `Form`
|
|
4177
|
-
* @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
|
|
4178
|
-
* @param isSchemaChanged - A flag indicating whether the schema has changed.
|
|
4179
|
-
* @param formDataChangedFields - The changed fields of `formData`
|
|
4180
|
-
* @returns - The new state for the `Form`
|
|
4181
|
-
*/
|
|
4182
|
-
getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false, formDataChangedFields = []) {
|
|
4183
|
-
const state = this.state || {};
|
|
4184
|
-
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
4185
|
-
const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
|
|
4186
|
-
const edit = typeof inputFormData !== "undefined";
|
|
4187
|
-
const liveValidate = "liveValidate" in props ? props.liveValidate : this.props.liveValidate;
|
|
4188
|
-
const mustValidate = edit && !props.noValidate && liveValidate;
|
|
4189
|
-
const rootSchema = schema;
|
|
4190
|
-
const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
|
|
4191
|
-
const experimental_customMergeAllOf = "experimental_customMergeAllOf" in props ? props.experimental_customMergeAllOf : this.props.experimental_customMergeAllOf;
|
|
4192
|
-
let schemaUtils = state.schemaUtils;
|
|
4193
|
-
if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(
|
|
4194
|
-
props.validator,
|
|
4195
|
-
rootSchema,
|
|
4196
|
-
experimental_defaultFormStateBehavior,
|
|
4197
|
-
experimental_customMergeAllOf
|
|
4198
|
-
)) {
|
|
4199
|
-
schemaUtils = (0, import_utils45.createSchemaUtils)(
|
|
4200
|
-
props.validator,
|
|
4201
|
-
rootSchema,
|
|
4202
|
-
experimental_defaultFormStateBehavior,
|
|
4203
|
-
experimental_customMergeAllOf
|
|
4204
|
-
);
|
|
4205
|
-
}
|
|
4206
|
-
const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
|
|
4207
|
-
const _retrievedSchema = this.updateRetrievedSchema(
|
|
4208
|
-
retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData)
|
|
4209
|
-
);
|
|
4210
|
-
const getCurrentErrors = () => {
|
|
4211
|
-
if (props.noValidate || isSchemaChanged) {
|
|
4212
|
-
return { errors: [], errorSchema: {} };
|
|
4213
|
-
} else if (!props.liveValidate) {
|
|
4214
|
-
return {
|
|
4215
|
-
errors: state.schemaValidationErrors || [],
|
|
4216
|
-
errorSchema: state.schemaValidationErrorSchema || {}
|
|
4217
|
-
};
|
|
4218
|
-
}
|
|
4219
|
-
return {
|
|
4220
|
-
errors: state.errors || [],
|
|
4221
|
-
errorSchema: state.errorSchema || {}
|
|
4222
|
-
};
|
|
4223
|
-
};
|
|
4224
|
-
let errors;
|
|
4225
|
-
let errorSchema;
|
|
4226
|
-
let schemaValidationErrors = state.schemaValidationErrors;
|
|
4227
|
-
let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
|
|
4228
|
-
if (mustValidate) {
|
|
4229
|
-
const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
|
|
4230
|
-
errors = schemaValidation.errors;
|
|
4231
|
-
if (retrievedSchema === void 0) {
|
|
4232
|
-
errorSchema = schemaValidation.errorSchema;
|
|
4233
|
-
} else {
|
|
4234
|
-
errorSchema = (0, import_utils45.mergeObjects)(
|
|
4235
|
-
this.state?.errorSchema,
|
|
4236
|
-
schemaValidation.errorSchema,
|
|
4237
|
-
"preventDuplicates"
|
|
4238
|
-
);
|
|
4239
|
-
}
|
|
4240
|
-
schemaValidationErrors = errors;
|
|
4241
|
-
schemaValidationErrorSchema = errorSchema;
|
|
4242
|
-
} else {
|
|
4243
|
-
const currentErrors = getCurrentErrors();
|
|
4244
|
-
errors = currentErrors.errors;
|
|
4245
|
-
errorSchema = currentErrors.errorSchema;
|
|
4246
|
-
if (formDataChangedFields.length > 0) {
|
|
4247
|
-
const newErrorSchema = formDataChangedFields.reduce(
|
|
4248
|
-
(acc, key) => {
|
|
4249
|
-
acc[key] = void 0;
|
|
4250
|
-
return acc;
|
|
4251
|
-
},
|
|
4252
|
-
{}
|
|
4253
|
-
);
|
|
4254
|
-
errorSchema = schemaValidationErrorSchema = (0, import_utils45.mergeObjects)(
|
|
4255
|
-
currentErrors.errorSchema,
|
|
4256
|
-
newErrorSchema,
|
|
4257
|
-
"preventDuplicates"
|
|
4258
|
-
);
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
|
-
if (props.extraErrors) {
|
|
4262
|
-
const merged = (0, import_utils45.validationDataMerge)({ errorSchema, errors }, props.extraErrors);
|
|
4263
|
-
errorSchema = merged.errorSchema;
|
|
4264
|
-
errors = merged.errors;
|
|
4265
|
-
}
|
|
4266
|
-
const idSchema = schemaUtils.toIdSchema(
|
|
4267
|
-
_retrievedSchema,
|
|
4268
|
-
uiSchema["ui:rootFieldId"],
|
|
4269
|
-
formData,
|
|
4270
|
-
props.idPrefix,
|
|
4271
|
-
props.idSeparator
|
|
4272
|
-
);
|
|
4273
|
-
const nextState = {
|
|
4274
|
-
schemaUtils,
|
|
4275
|
-
schema,
|
|
4276
|
-
uiSchema,
|
|
4277
|
-
idSchema,
|
|
4278
|
-
formData,
|
|
4279
|
-
edit,
|
|
4280
|
-
errors,
|
|
4281
|
-
errorSchema,
|
|
4282
|
-
schemaValidationErrors,
|
|
4283
|
-
schemaValidationErrorSchema,
|
|
4284
|
-
retrievedSchema: _retrievedSchema
|
|
4285
|
-
};
|
|
4286
|
-
return nextState;
|
|
4287
|
-
}
|
|
4288
|
-
/** React lifecycle method that is used to determine whether component should be updated.
|
|
4289
|
-
*
|
|
4290
|
-
* @param nextProps - The next version of the props
|
|
4291
|
-
* @param nextState - The next version of the state
|
|
4292
|
-
* @returns - True if the component should be updated, false otherwise
|
|
4293
|
-
*/
|
|
4294
|
-
shouldComponentUpdate(nextProps, nextState) {
|
|
4295
|
-
return (0, import_utils45.shouldRender)(this, nextProps, nextState);
|
|
4296
|
-
}
|
|
4297
|
-
/** Gets the previously raised customValidate errors.
|
|
4298
|
-
*
|
|
4299
|
-
* @returns the previous customValidate errors
|
|
4300
|
-
*/
|
|
4301
|
-
getPreviousCustomValidateErrors() {
|
|
4302
|
-
const { customValidate, uiSchema } = this.props;
|
|
4303
|
-
const prevFormData = this.state.formData;
|
|
4304
|
-
let customValidateErrors = {};
|
|
4305
|
-
if (typeof customValidate === "function") {
|
|
4306
|
-
const errorHandler = customValidate(prevFormData, (0, import_utils45.createErrorHandler)(prevFormData), uiSchema);
|
|
4307
|
-
const userErrorSchema = (0, import_utils45.unwrapErrorHandler)(errorHandler);
|
|
4308
|
-
customValidateErrors = userErrorSchema;
|
|
4309
|
-
}
|
|
4310
|
-
return customValidateErrors;
|
|
4311
|
-
}
|
|
4312
|
-
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
4313
|
-
* `schemaUtils` in the state), returning the results.
|
|
4314
|
-
*
|
|
4315
|
-
* @param formData - The new form data to validate
|
|
4316
|
-
* @param schema - The schema used to validate against
|
|
4317
|
-
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
4318
|
-
*/
|
|
4319
|
-
validate(formData, schema = this.props.schema, altSchemaUtils, retrievedSchema) {
|
|
4320
|
-
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
4321
|
-
const { customValidate, transformErrors, uiSchema } = this.props;
|
|
4322
|
-
const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
|
|
4323
|
-
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
|
|
4324
|
-
}
|
|
4325
|
-
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
|
|
4326
|
-
renderErrors(registry) {
|
|
4327
|
-
const { errors, errorSchema, schema, uiSchema } = this.state;
|
|
4328
|
-
const { formContext } = this.props;
|
|
4329
|
-
const options = (0, import_utils45.getUiOptions)(uiSchema);
|
|
4330
|
-
const ErrorListTemplate = (0, import_utils45.getTemplate)("ErrorListTemplate", registry, options);
|
|
4331
|
-
if (errors && errors.length) {
|
|
4332
|
-
return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
|
|
4333
|
-
ErrorListTemplate,
|
|
4334
|
-
{
|
|
4335
|
-
errors,
|
|
4336
|
-
errorSchema: errorSchema || {},
|
|
4337
|
-
schema,
|
|
4338
|
-
uiSchema,
|
|
4339
|
-
formContext,
|
|
4340
|
-
registry
|
|
4341
|
-
}
|
|
4342
|
-
);
|
|
4343
|
-
}
|
|
4344
|
-
return null;
|
|
4345
|
-
}
|
|
4346
|
-
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
4347
|
-
*
|
|
4348
|
-
* @param formData - The data for the `Form`
|
|
4349
|
-
* @param fields - The fields to keep while filtering
|
|
4350
|
-
*/
|
|
4351
|
-
getUsedFormData = (formData, fields2) => {
|
|
4352
|
-
if (fields2.length === 0 && typeof formData !== "object") {
|
|
4353
|
-
return formData;
|
|
4354
|
-
}
|
|
4355
|
-
const data = (0, import_pick.default)(formData, fields2);
|
|
4356
|
-
if (Array.isArray(formData)) {
|
|
4357
|
-
return Object.keys(data).map((key) => data[key]);
|
|
4358
|
-
}
|
|
4359
|
-
return data;
|
|
4360
|
-
};
|
|
4361
|
-
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
|
|
4362
|
-
*
|
|
4363
|
-
* @param pathSchema - The `PathSchema` object for the form
|
|
4364
|
-
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
4365
|
-
*/
|
|
4366
|
-
getFieldNames = (pathSchema, formData) => {
|
|
4367
|
-
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
4368
|
-
Object.keys(_obj).forEach((key) => {
|
|
4369
|
-
if (typeof _obj[key] === "object") {
|
|
4370
|
-
const newPaths = paths.map((path) => [...path, key]);
|
|
4371
|
-
if (_obj[key][import_utils45.RJSF_ADDITIONAL_PROPERTIES_FLAG] && _obj[key][import_utils45.NAME_KEY] !== "") {
|
|
4372
|
-
acc.push(_obj[key][import_utils45.NAME_KEY]);
|
|
4373
|
-
} else {
|
|
4374
|
-
getAllPaths(_obj[key], acc, newPaths);
|
|
4375
|
-
}
|
|
4376
|
-
} else if (key === import_utils45.NAME_KEY && _obj[key] !== "") {
|
|
4377
|
-
paths.forEach((path) => {
|
|
4378
|
-
const formValue = (0, import_get6.default)(formData, path);
|
|
4379
|
-
if (typeof formValue !== "object" || (0, import_isEmpty4.default)(formValue) || Array.isArray(formValue) && formValue.every((val) => typeof val !== "object")) {
|
|
4380
|
-
acc.push(path);
|
|
4381
|
-
}
|
|
4382
|
-
});
|
|
4383
|
-
}
|
|
4384
|
-
});
|
|
4385
|
-
return acc;
|
|
4386
|
-
};
|
|
4387
|
-
return getAllPaths(pathSchema);
|
|
4388
|
-
};
|
|
4389
|
-
/** Returns the `formData` after filtering to remove any extra data not in a form field
|
|
4390
|
-
*
|
|
4391
|
-
* @param formData - The data for the `Form`
|
|
4392
|
-
* @returns The `formData` after omitting extra data
|
|
4393
|
-
*/
|
|
4394
|
-
omitExtraData = (formData) => {
|
|
4395
|
-
const { schema, schemaUtils } = this.state;
|
|
4396
|
-
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
4397
|
-
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
4398
|
-
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
4399
|
-
const newFormData = this.getUsedFormData(formData, fieldNames);
|
|
4400
|
-
return newFormData;
|
|
4401
|
-
};
|
|
4402
|
-
// Filtering errors based on your retrieved schema to only show errors for properties in the selected branch.
|
|
4403
|
-
filterErrorsBasedOnSchema(schemaErrors, resolvedSchema, formData) {
|
|
4404
|
-
const { retrievedSchema, schemaUtils } = this.state;
|
|
4405
|
-
const _retrievedSchema = resolvedSchema ?? retrievedSchema;
|
|
4406
|
-
const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, "", formData);
|
|
4407
|
-
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
4408
|
-
const filteredErrors = (0, import_pick.default)(schemaErrors, fieldNames);
|
|
4409
|
-
if (resolvedSchema?.type !== "object" && resolvedSchema?.type !== "array") {
|
|
4410
|
-
filteredErrors.__errors = schemaErrors.__errors;
|
|
4411
|
-
}
|
|
4412
|
-
const prevCustomValidateErrors = this.getPreviousCustomValidateErrors();
|
|
4413
|
-
const filterPreviousCustomErrors = (errors = [], prevCustomErrors) => {
|
|
4414
|
-
if (errors.length === 0) {
|
|
4415
|
-
return errors;
|
|
4416
|
-
}
|
|
4417
|
-
return errors.filter((error) => {
|
|
4418
|
-
return !prevCustomErrors.includes(error);
|
|
4419
|
-
});
|
|
4420
|
-
};
|
|
4421
|
-
const filterNilOrEmptyErrors = (errors, previousCustomValidateErrors = {}) => {
|
|
4422
|
-
(0, import_forEach.default)(errors, (errorAtKey, errorKey) => {
|
|
4423
|
-
const prevCustomValidateErrorAtKey = previousCustomValidateErrors[errorKey];
|
|
4424
|
-
if ((0, import_isNil.default)(errorAtKey) || Array.isArray(errorAtKey) && errorAtKey.length === 0) {
|
|
4425
|
-
delete errors[errorKey];
|
|
4426
|
-
} else if ((0, import_utils45.isObject)(errorAtKey) && (0, import_utils45.isObject)(prevCustomValidateErrorAtKey) && Array.isArray(prevCustomValidateErrorAtKey?.__errors)) {
|
|
4427
|
-
errors[errorKey] = filterPreviousCustomErrors(errorAtKey.__errors, prevCustomValidateErrorAtKey.__errors);
|
|
4428
|
-
} else if (typeof errorAtKey === "object" && !Array.isArray(errorAtKey.__errors)) {
|
|
4429
|
-
filterNilOrEmptyErrors(errorAtKey, previousCustomValidateErrors[errorKey]);
|
|
4430
|
-
}
|
|
4431
|
-
});
|
|
4432
|
-
return errors;
|
|
4433
|
-
};
|
|
4434
|
-
return filterNilOrEmptyErrors(filteredErrors, prevCustomValidateErrors);
|
|
4435
|
-
}
|
|
4436
|
-
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
4437
|
-
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
4438
|
-
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filtered to remove any extra data not
|
|
4439
|
-
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
4440
|
-
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
4441
|
-
* callback will be called if specified with the updated state.
|
|
4442
|
-
*
|
|
4443
|
-
* @param formData - The new form data from a change to a field
|
|
4444
|
-
* @param newErrorSchema - The new `ErrorSchema` based on the field change
|
|
4445
|
-
* @param id - The id of the field that caused the change
|
|
4446
|
-
*/
|
|
4447
|
-
onChange = (formData, newErrorSchema, id) => {
|
|
4448
|
-
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
|
|
4449
|
-
const { schemaUtils, schema } = this.state;
|
|
4450
|
-
let retrievedSchema = this.state.retrievedSchema;
|
|
4451
|
-
if ((0, import_utils45.isObject)(formData) || Array.isArray(formData)) {
|
|
4452
|
-
const newState = this.getStateFromProps(this.props, formData);
|
|
4453
|
-
formData = newState.formData;
|
|
4454
|
-
retrievedSchema = newState.retrievedSchema;
|
|
4455
|
-
}
|
|
4456
|
-
const mustValidate = !noValidate && liveValidate;
|
|
4457
|
-
let state = { formData, schema };
|
|
4458
|
-
let newFormData = formData;
|
|
4459
|
-
if (omitExtraData === true && liveOmit === true) {
|
|
4460
|
-
newFormData = this.omitExtraData(formData);
|
|
4461
|
-
state = {
|
|
4462
|
-
formData: newFormData
|
|
4463
|
-
};
|
|
4464
|
-
}
|
|
4465
|
-
if (mustValidate) {
|
|
4466
|
-
const schemaValidation = this.validate(newFormData, schema, schemaUtils, retrievedSchema);
|
|
4467
|
-
let errors = schemaValidation.errors;
|
|
4468
|
-
let errorSchema = schemaValidation.errorSchema;
|
|
4469
|
-
const schemaValidationErrors = errors;
|
|
4470
|
-
const schemaValidationErrorSchema = errorSchema;
|
|
4471
|
-
if (extraErrors) {
|
|
4472
|
-
const merged = (0, import_utils45.validationDataMerge)(schemaValidation, extraErrors);
|
|
4473
|
-
errorSchema = merged.errorSchema;
|
|
4474
|
-
errors = merged.errors;
|
|
4475
|
-
}
|
|
4476
|
-
if (newErrorSchema) {
|
|
4477
|
-
const filteredErrors = this.filterErrorsBasedOnSchema(newErrorSchema, retrievedSchema, newFormData);
|
|
4478
|
-
errorSchema = (0, import_utils45.mergeObjects)(errorSchema, filteredErrors, "preventDuplicates");
|
|
4479
|
-
}
|
|
4480
|
-
state = {
|
|
4481
|
-
formData: newFormData,
|
|
4482
|
-
errors,
|
|
4483
|
-
errorSchema,
|
|
4484
|
-
schemaValidationErrors,
|
|
4485
|
-
schemaValidationErrorSchema
|
|
4486
|
-
};
|
|
4487
|
-
} else if (!noValidate && newErrorSchema) {
|
|
4488
|
-
const errorSchema = extraErrors ? (0, import_utils45.mergeObjects)(newErrorSchema, extraErrors, "preventDuplicates") : newErrorSchema;
|
|
4489
|
-
state = {
|
|
4490
|
-
formData: newFormData,
|
|
4491
|
-
errorSchema,
|
|
4492
|
-
errors: (0, import_utils45.toErrorList)(errorSchema)
|
|
4493
|
-
};
|
|
4494
|
-
}
|
|
4495
|
-
this.setState(state, () => onChange && onChange({ ...this.state, ...state }, id));
|
|
4496
|
-
};
|
|
4497
|
-
/**
|
|
4498
|
-
* If the retrievedSchema has changed the new retrievedSchema is returned.
|
|
4499
|
-
* Otherwise, the old retrievedSchema is returned to persist reference.
|
|
4500
|
-
* - This ensures that AJV retrieves the schema from the cache when it has not changed,
|
|
4501
|
-
* avoiding the performance cost of recompiling the schema.
|
|
4502
|
-
*
|
|
4503
|
-
* @param retrievedSchema The new retrieved schema.
|
|
4504
|
-
* @returns The new retrieved schema if it has changed, else the old retrieved schema.
|
|
4505
|
-
*/
|
|
4506
|
-
updateRetrievedSchema(retrievedSchema) {
|
|
4507
|
-
const isTheSame = (0, import_utils45.deepEquals)(retrievedSchema, this.state?.retrievedSchema);
|
|
4508
|
-
return isTheSame ? this.state.retrievedSchema : retrievedSchema;
|
|
4509
|
-
}
|
|
4510
|
-
/**
|
|
4511
|
-
* Callback function to handle reset form data.
|
|
4512
|
-
* - Reset all fields with default values.
|
|
4513
|
-
* - Reset validations and errors
|
|
4514
|
-
*
|
|
4515
|
-
*/
|
|
4516
|
-
reset = () => {
|
|
4517
|
-
const { onChange } = this.props;
|
|
4518
|
-
const newState = this.getStateFromProps(this.props, void 0);
|
|
4519
|
-
const newFormData = newState.formData;
|
|
4520
|
-
const state = {
|
|
4521
|
-
formData: newFormData,
|
|
4522
|
-
errorSchema: {},
|
|
4523
|
-
errors: [],
|
|
4524
|
-
schemaValidationErrors: [],
|
|
4525
|
-
schemaValidationErrorSchema: {}
|
|
4526
|
-
};
|
|
4527
|
-
this.setState(state, () => onChange && onChange({ ...this.state, ...state }));
|
|
4528
|
-
};
|
|
4529
|
-
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
4530
|
-
* was provided.
|
|
4531
|
-
*
|
|
4532
|
-
* @param id - The unique `id` of the field that was blurred
|
|
4533
|
-
* @param data - The data associated with the field that was blurred
|
|
4534
|
-
*/
|
|
4535
|
-
onBlur = (id, data) => {
|
|
4536
|
-
const { onBlur } = this.props;
|
|
4537
|
-
if (onBlur) {
|
|
4538
|
-
onBlur(id, data);
|
|
4539
|
-
}
|
|
4540
|
-
};
|
|
4541
|
-
/** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
|
|
4542
|
-
* was provided.
|
|
4543
|
-
*
|
|
4544
|
-
* @param id - The unique `id` of the field that was focused
|
|
4545
|
-
* @param data - The data associated with the field that was focused
|
|
4546
|
-
*/
|
|
4547
|
-
onFocus = (id, data) => {
|
|
4548
|
-
const { onFocus } = this.props;
|
|
4549
|
-
if (onFocus) {
|
|
4550
|
-
onFocus(id, data);
|
|
4551
|
-
}
|
|
4552
|
-
};
|
|
4553
|
-
/** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
|
|
4554
|
-
* happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
|
|
4555
|
-
* `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
|
|
4556
|
-
* via the `onError()` callback unless validation is disabled. Finally, it will add in any `extraErrors` and then call
|
|
4557
|
-
* back the `onSubmit` callback if it was provided.
|
|
4558
|
-
*
|
|
4559
|
-
* @param event - The submit HTML form event
|
|
4560
|
-
*/
|
|
4561
|
-
onSubmit = (event) => {
|
|
4562
|
-
event.preventDefault();
|
|
4563
|
-
if (event.target !== event.currentTarget) {
|
|
4564
|
-
return;
|
|
4565
|
-
}
|
|
4566
|
-
event.persist();
|
|
4567
|
-
const { omitExtraData, extraErrors, noValidate, onSubmit } = this.props;
|
|
4568
|
-
let { formData: newFormData } = this.state;
|
|
4569
|
-
if (omitExtraData === true) {
|
|
4570
|
-
newFormData = this.omitExtraData(newFormData);
|
|
4571
|
-
}
|
|
4572
|
-
if (noValidate || this.validateFormWithFormData(newFormData)) {
|
|
4573
|
-
const errorSchema = extraErrors || {};
|
|
4574
|
-
const errors = extraErrors ? (0, import_utils45.toErrorList)(extraErrors) : [];
|
|
4575
|
-
this.setState(
|
|
4576
|
-
{
|
|
4577
|
-
formData: newFormData,
|
|
4578
|
-
errors,
|
|
4579
|
-
errorSchema,
|
|
4580
|
-
schemaValidationErrors: [],
|
|
4581
|
-
schemaValidationErrorSchema: {}
|
|
4582
|
-
},
|
|
4583
|
-
() => {
|
|
4584
|
-
if (onSubmit) {
|
|
4585
|
-
onSubmit({ ...this.state, formData: newFormData, status: "submitted" }, event);
|
|
4586
|
-
}
|
|
4587
|
-
}
|
|
4588
|
-
);
|
|
4589
|
-
}
|
|
4590
|
-
};
|
|
4591
|
-
/** Returns the registry for the form */
|
|
4592
|
-
getRegistry() {
|
|
4593
|
-
const { translateString: customTranslateString, uiSchema = {} } = this.props;
|
|
4594
|
-
const { schemaUtils } = this.state;
|
|
4595
|
-
const { fields: fields2, templates: templates2, widgets: widgets2, formContext, translateString } = getDefaultRegistry();
|
|
4596
|
-
return {
|
|
4597
|
-
fields: { ...fields2, ...this.props.fields },
|
|
4598
|
-
templates: {
|
|
4599
|
-
...templates2,
|
|
4600
|
-
...this.props.templates,
|
|
4601
|
-
ButtonTemplates: {
|
|
4602
|
-
...templates2.ButtonTemplates,
|
|
4603
|
-
...this.props.templates?.ButtonTemplates
|
|
4604
|
-
}
|
|
4605
|
-
},
|
|
4606
|
-
widgets: { ...widgets2, ...this.props.widgets },
|
|
4607
|
-
rootSchema: this.props.schema,
|
|
4608
|
-
formContext: this.props.formContext || formContext,
|
|
4609
|
-
schemaUtils,
|
|
4610
|
-
translateString: customTranslateString || translateString,
|
|
4611
|
-
globalUiOptions: uiSchema[import_utils45.UI_GLOBAL_OPTIONS_KEY]
|
|
4612
|
-
};
|
|
4613
|
-
}
|
|
4614
|
-
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
4615
|
-
submit = () => {
|
|
4616
|
-
if (this.formElement.current) {
|
|
4617
|
-
const submitCustomEvent = new CustomEvent("submit", {
|
|
4618
|
-
cancelable: true
|
|
4619
|
-
});
|
|
4620
|
-
submitCustomEvent.preventDefault();
|
|
4621
|
-
this.formElement.current.dispatchEvent(submitCustomEvent);
|
|
4622
|
-
this.formElement.current.requestSubmit();
|
|
4623
|
-
}
|
|
4624
|
-
};
|
|
4625
|
-
/** Attempts to focus on the field associated with the `error`. Uses the `property` field to compute path of the error
|
|
4626
|
-
* field, then, using the `idPrefix` and `idSeparator` converts that path into an id. Then the input element with that
|
|
4627
|
-
* id is attempted to be found using the `formElement` ref. If it is located, then it is focused.
|
|
4628
|
-
*
|
|
4629
|
-
* @param error - The error on which to focus
|
|
4630
|
-
*/
|
|
4631
|
-
focusOnError(error) {
|
|
4632
|
-
const { idPrefix = "root", idSeparator = "_" } = this.props;
|
|
4633
|
-
const { property } = error;
|
|
4634
|
-
const path = (0, import_toPath.default)(property);
|
|
4635
|
-
if (path[0] === "") {
|
|
4636
|
-
path[0] = idPrefix;
|
|
4637
|
-
} else {
|
|
4638
|
-
path.unshift(idPrefix);
|
|
4639
|
-
}
|
|
4640
|
-
const elementId = path.join(idSeparator);
|
|
4641
|
-
let field = this.formElement.current.elements[elementId];
|
|
4642
|
-
if (!field) {
|
|
4643
|
-
field = this.formElement.current.querySelector(`input[id^="${elementId}"`);
|
|
4644
|
-
}
|
|
4645
|
-
if (field && field.length) {
|
|
4646
|
-
field = field[0];
|
|
4647
|
-
}
|
|
4648
|
-
if (field) {
|
|
4649
|
-
field.focus();
|
|
4650
|
-
}
|
|
4651
|
-
}
|
|
4652
|
-
/** Validates the form using the given `formData`. For use on form submission or on programmatic validation.
|
|
4653
|
-
* If `onError` is provided, then it will be called with the list of errors.
|
|
4654
|
-
*
|
|
4655
|
-
* @param formData - The form data to validate
|
|
4656
|
-
* @returns - True if the form is valid, false otherwise.
|
|
4657
|
-
*/
|
|
4658
|
-
validateFormWithFormData = (formData) => {
|
|
4659
|
-
const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
|
|
4660
|
-
const { errors: prevErrors } = this.state;
|
|
4661
|
-
const schemaValidation = this.validate(formData);
|
|
4662
|
-
let errors = schemaValidation.errors;
|
|
4663
|
-
let errorSchema = schemaValidation.errorSchema;
|
|
4664
|
-
const schemaValidationErrors = errors;
|
|
4665
|
-
const schemaValidationErrorSchema = errorSchema;
|
|
4666
|
-
const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
|
|
4667
|
-
if (hasError) {
|
|
4668
|
-
if (extraErrors) {
|
|
4669
|
-
const merged = (0, import_utils45.validationDataMerge)(schemaValidation, extraErrors);
|
|
4670
|
-
errorSchema = merged.errorSchema;
|
|
4671
|
-
errors = merged.errors;
|
|
4672
|
-
}
|
|
4673
|
-
if (focusOnFirstError) {
|
|
4674
|
-
if (typeof focusOnFirstError === "function") {
|
|
4675
|
-
focusOnFirstError(errors[0]);
|
|
4676
|
-
} else {
|
|
4677
|
-
this.focusOnError(errors[0]);
|
|
4678
|
-
}
|
|
4679
|
-
}
|
|
4680
|
-
this.setState(
|
|
4681
|
-
{
|
|
4682
|
-
errors,
|
|
4683
|
-
errorSchema,
|
|
4684
|
-
schemaValidationErrors,
|
|
4685
|
-
schemaValidationErrorSchema
|
|
4686
|
-
},
|
|
4687
|
-
() => {
|
|
4688
|
-
if (onError) {
|
|
4689
|
-
onError(errors);
|
|
4690
|
-
} else {
|
|
4691
|
-
console.error("Form validation failed", errors);
|
|
4692
|
-
}
|
|
4693
|
-
}
|
|
4694
|
-
);
|
|
4695
|
-
} else if (prevErrors.length > 0) {
|
|
4696
|
-
this.setState({
|
|
4697
|
-
errors: [],
|
|
4698
|
-
errorSchema: {},
|
|
4699
|
-
schemaValidationErrors: [],
|
|
4700
|
-
schemaValidationErrorSchema: {}
|
|
4701
|
-
});
|
|
4702
|
-
}
|
|
4703
|
-
return !hasError;
|
|
4704
|
-
};
|
|
4705
|
-
/** Programmatically validate the form. If `omitExtraData` is true, the `formData` will first be filtered to remove
|
|
4706
|
-
* any extra data not in a form field. If `onError` is provided, then it will be called with the list of errors the
|
|
4707
|
-
* same way as would happen on form submission.
|
|
4708
|
-
*
|
|
4709
|
-
* @returns - True if the form is valid, false otherwise.
|
|
4710
|
-
*/
|
|
4711
|
-
validateForm() {
|
|
4712
|
-
const { omitExtraData } = this.props;
|
|
4713
|
-
let { formData: newFormData } = this.state;
|
|
4714
|
-
if (omitExtraData === true) {
|
|
4715
|
-
newFormData = this.omitExtraData(newFormData);
|
|
4716
|
-
}
|
|
4717
|
-
return this.validateFormWithFormData(newFormData);
|
|
4718
|
-
}
|
|
4719
|
-
/** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
|
|
4720
|
-
* needed along with the submit button or any children of the form.
|
|
4721
|
-
*/
|
|
4722
|
-
render() {
|
|
4723
|
-
const {
|
|
4724
|
-
children,
|
|
4725
|
-
id,
|
|
4726
|
-
idPrefix,
|
|
4727
|
-
idSeparator,
|
|
4728
|
-
className = "",
|
|
4729
|
-
tagName,
|
|
4730
|
-
name,
|
|
4731
|
-
method,
|
|
4732
|
-
target,
|
|
4733
|
-
action,
|
|
4734
|
-
autoComplete,
|
|
4735
|
-
enctype,
|
|
4736
|
-
acceptCharset,
|
|
4737
|
-
noHtml5Validate = false,
|
|
4738
|
-
disabled,
|
|
4739
|
-
readonly,
|
|
4740
|
-
formContext,
|
|
4741
|
-
showErrorList = "top",
|
|
4742
|
-
_internalFormWrapper
|
|
4743
|
-
} = this.props;
|
|
4744
|
-
const { schema, uiSchema, formData, errorSchema, idSchema } = this.state;
|
|
4745
|
-
const registry = this.getRegistry();
|
|
4746
|
-
const { SchemaField: _SchemaField } = registry.fields;
|
|
4747
|
-
const { SubmitButton: SubmitButton2 } = registry.templates.ButtonTemplates;
|
|
4748
|
-
const as = _internalFormWrapper ? tagName : void 0;
|
|
4749
|
-
const FormTag = _internalFormWrapper || tagName || "form";
|
|
4750
|
-
let { [import_utils45.SUBMIT_BTN_OPTIONS_KEY]: submitOptions = {} } = (0, import_utils45.getUiOptions)(uiSchema);
|
|
4751
|
-
if (disabled) {
|
|
4752
|
-
submitOptions = { ...submitOptions, props: { ...submitOptions.props, disabled: true } };
|
|
4753
|
-
}
|
|
4754
|
-
const submitUiSchema = { [import_utils45.UI_OPTIONS_KEY]: { [import_utils45.SUBMIT_BTN_OPTIONS_KEY]: submitOptions } };
|
|
4755
|
-
return /* @__PURE__ */ (0, import_jsx_runtime52.jsxs)(
|
|
4756
|
-
FormTag,
|
|
4757
|
-
{
|
|
4758
|
-
className: className ? className : "rjsf",
|
|
4759
|
-
id,
|
|
4760
|
-
name,
|
|
4761
|
-
method,
|
|
4762
|
-
target,
|
|
4763
|
-
action,
|
|
4764
|
-
autoComplete,
|
|
4765
|
-
encType: enctype,
|
|
4766
|
-
acceptCharset,
|
|
4767
|
-
noValidate: noHtml5Validate,
|
|
4768
|
-
onSubmit: this.onSubmit,
|
|
4769
|
-
as,
|
|
4770
|
-
ref: this.formElement,
|
|
4771
|
-
children: [
|
|
4772
|
-
showErrorList === "top" && this.renderErrors(registry),
|
|
4773
|
-
/* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
|
|
4774
|
-
_SchemaField,
|
|
4775
|
-
{
|
|
4776
|
-
name: "",
|
|
4777
|
-
schema,
|
|
4778
|
-
uiSchema,
|
|
4779
|
-
errorSchema,
|
|
4780
|
-
idSchema,
|
|
4781
|
-
idPrefix,
|
|
4782
|
-
idSeparator,
|
|
4783
|
-
formContext,
|
|
4784
|
-
formData,
|
|
4785
|
-
onChange: this.onChange,
|
|
4786
|
-
onBlur: this.onBlur,
|
|
4787
|
-
onFocus: this.onFocus,
|
|
4788
|
-
registry,
|
|
4789
|
-
disabled,
|
|
4790
|
-
readonly
|
|
4791
|
-
}
|
|
4792
|
-
),
|
|
4793
|
-
children ? children : /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(SubmitButton2, { uiSchema: submitUiSchema, registry }),
|
|
4794
|
-
showErrorList === "bottom" && this.renderErrors(registry)
|
|
4795
|
-
]
|
|
4796
|
-
}
|
|
4797
|
-
);
|
|
4798
|
-
}
|
|
4799
|
-
};
|
|
4800
|
-
|
|
4801
|
-
// src/withTheme.tsx
|
|
4802
|
-
var import_react23 = require("react");
|
|
4803
|
-
var import_jsx_runtime53 = require("react/jsx-runtime");
|
|
4804
|
-
function withTheme(themeProps) {
|
|
4805
|
-
return (0, import_react23.forwardRef)(
|
|
4806
|
-
({ fields: fields2, widgets: widgets2, templates: templates2, ...directProps }, ref) => {
|
|
4807
|
-
fields2 = { ...themeProps?.fields, ...fields2 };
|
|
4808
|
-
widgets2 = { ...themeProps?.widgets, ...widgets2 };
|
|
4809
|
-
templates2 = {
|
|
4810
|
-
...themeProps?.templates,
|
|
4811
|
-
...templates2,
|
|
4812
|
-
ButtonTemplates: {
|
|
4813
|
-
...themeProps?.templates?.ButtonTemplates,
|
|
4814
|
-
...templates2?.ButtonTemplates
|
|
4815
|
-
}
|
|
4816
|
-
};
|
|
4817
|
-
return /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
|
|
4818
|
-
Form,
|
|
4819
|
-
{
|
|
4820
|
-
...themeProps,
|
|
4821
|
-
...directProps,
|
|
4822
|
-
fields: fields2,
|
|
4823
|
-
widgets: widgets2,
|
|
4824
|
-
templates: templates2,
|
|
4825
|
-
ref
|
|
4826
|
-
}
|
|
4827
|
-
);
|
|
4828
|
-
}
|
|
4829
|
-
);
|
|
4830
|
-
}
|
|
4831
|
-
|
|
4832
|
-
// src/index.ts
|
|
4833
|
-
var index_default = Form;
|
|
4834
|
-
//# sourceMappingURL=index.js.map
|