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