@rjsf/core 5.11.2 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.umd.js +3464 -0
- package/dist/index.esm.js +3814 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +3714 -5
- package/dist/index.js.map +7 -0
- package/{dist/index.d.ts → lib/components/Form.d.ts} +321 -337
- package/lib/components/Form.js +474 -0
- package/lib/components/Form.js.map +1 -0
- package/lib/components/fields/ArrayField.d.ts +179 -0
- package/lib/components/fields/ArrayField.js +568 -0
- package/lib/components/fields/ArrayField.js.map +1 -0
- package/lib/components/fields/BooleanField.d.ts +9 -0
- package/lib/components/fields/BooleanField.js +62 -0
- package/lib/components/fields/BooleanField.js.map +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts +47 -0
- package/lib/components/fields/MultiSchemaField.js +129 -0
- package/lib/components/fields/MultiSchemaField.js.map +1 -0
- package/lib/components/fields/NullField.d.ts +8 -0
- package/lib/components/fields/NullField.js +17 -0
- package/lib/components/fields/NullField.js.map +1 -0
- package/lib/components/fields/NumberField.d.ts +21 -0
- package/lib/components/fields/NumberField.js +70 -0
- package/lib/components/fields/NumberField.js.map +1 -0
- package/lib/components/fields/ObjectField.d.ts +73 -0
- package/lib/components/fields/ObjectField.js +222 -0
- package/lib/components/fields/ObjectField.js.map +1 -0
- package/lib/components/fields/SchemaField.d.ts +10 -0
- package/lib/components/fields/SchemaField.js +172 -0
- package/lib/components/fields/SchemaField.js.map +1 -0
- package/lib/components/fields/StringField.d.ts +8 -0
- package/lib/components/fields/StringField.js +25 -0
- package/lib/components/fields/StringField.js.map +1 -0
- package/lib/components/fields/index.d.ts +3 -0
- package/lib/components/fields/index.js +24 -0
- package/lib/components/fields/index.js.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +20 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldTemplate.js +22 -0
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +9 -0
- package/lib/components/templates/BaseInputTemplate.js +39 -0
- package/lib/components/templates/BaseInputTemplate.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +10 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +7 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +24 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +12 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.d.ts +3 -0
- package/lib/components/templates/ButtonTemplates/index.js +15 -0
- package/lib/components/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/components/templates/DescriptionField.d.ts +7 -0
- package/lib/components/templates/DescriptionField.js +18 -0
- package/lib/components/templates/DescriptionField.js.map +1 -0
- package/lib/components/templates/ErrorList.d.ts +7 -0
- package/lib/components/templates/ErrorList.js +13 -0
- package/lib/components/templates/ErrorList.js.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.d.ts +7 -0
- package/lib/components/templates/FieldErrorTemplate.js +19 -0
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.d.ts +7 -0
- package/lib/components/templates/FieldHelpTemplate.js +18 -0
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +18 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.d.ts +14 -0
- package/lib/components/templates/FieldTemplate/Label.js +14 -0
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -0
- package/lib/components/templates/FieldTemplate/index.d.ts +2 -0
- package/lib/components/templates/FieldTemplate/index.js +3 -0
- package/lib/components/templates/FieldTemplate/index.js.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +9 -0
- package/lib/components/templates/ObjectFieldTemplate.js +18 -0
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/components/templates/TitleField.d.ts +7 -0
- package/lib/components/templates/TitleField.js +11 -0
- package/lib/components/templates/TitleField.js.map +1 -0
- package/lib/components/templates/UnsupportedField.d.ts +9 -0
- package/lib/components/templates/UnsupportedField.js +28 -0
- package/lib/components/templates/UnsupportedField.js.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +21 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/components/templates/index.d.ts +3 -0
- package/lib/components/templates/index.js +36 -0
- package/lib/components/templates/index.js.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +9 -0
- package/lib/components/widgets/AltDateTimeWidget.js +14 -0
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -0
- package/lib/components/widgets/AltDateWidget.d.ts +7 -0
- package/lib/components/widgets/AltDateWidget.js +77 -0
- package/lib/components/widgets/AltDateWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxWidget.js +23 -0
- package/lib/components/widgets/CheckboxWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxesWidget.js +31 -0
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/components/widgets/ColorWidget.d.ts +8 -0
- package/lib/components/widgets/ColorWidget.js +13 -0
- package/lib/components/widgets/ColorWidget.js.map +1 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +8 -0
- package/lib/components/widgets/DateTimeWidget.js +13 -0
- package/lib/components/widgets/DateTimeWidget.js.map +1 -0
- package/lib/components/widgets/DateWidget.d.ts +8 -0
- package/lib/components/widgets/DateWidget.js +15 -0
- package/lib/components/widgets/DateWidget.js.map +1 -0
- package/lib/components/widgets/EmailWidget.d.ts +7 -0
- package/lib/components/widgets/EmailWidget.js +12 -0
- package/lib/components/widgets/EmailWidget.js.map +1 -0
- package/lib/components/widgets/FileWidget.d.ts +8 -0
- package/lib/components/widgets/FileWidget.js +105 -0
- package/lib/components/widgets/FileWidget.js.map +1 -0
- package/lib/components/widgets/HiddenWidget.d.ts +9 -0
- package/lib/components/widgets/HiddenWidget.js +11 -0
- package/lib/components/widgets/HiddenWidget.js.map +1 -0
- package/lib/components/widgets/PasswordWidget.d.ts +7 -0
- package/lib/components/widgets/PasswordWidget.js +12 -0
- package/lib/components/widgets/PasswordWidget.js.map +1 -0
- package/lib/components/widgets/RadioWidget.d.ts +9 -0
- package/lib/components/widgets/RadioWidget.js +24 -0
- package/lib/components/widgets/RadioWidget.js.map +1 -0
- package/lib/components/widgets/RangeWidget.d.ts +8 -0
- package/lib/components/widgets/RangeWidget.js +11 -0
- package/lib/components/widgets/RangeWidget.js.map +1 -0
- package/lib/components/widgets/SelectWidget.d.ts +9 -0
- package/lib/components/widgets/SelectWidget.js +41 -0
- package/lib/components/widgets/SelectWidget.js.map +1 -0
- package/lib/components/widgets/TextWidget.d.ts +7 -0
- package/lib/components/widgets/TextWidget.js +12 -0
- package/lib/components/widgets/TextWidget.js.map +1 -0
- package/lib/components/widgets/TextareaWidget.d.ts +14 -0
- package/lib/components/widgets/TextareaWidget.js +19 -0
- package/lib/components/widgets/TextareaWidget.js.map +1 -0
- package/lib/components/widgets/TimeWidget.d.ts +8 -0
- package/lib/components/widgets/TimeWidget.js +15 -0
- package/lib/components/widgets/TimeWidget.js.map +1 -0
- package/lib/components/widgets/URLWidget.d.ts +7 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/URLWidget.js.map +1 -0
- package/lib/components/widgets/UpDownWidget.d.ts +7 -0
- package/lib/components/widgets/UpDownWidget.js +12 -0
- package/lib/components/widgets/UpDownWidget.js.map +1 -0
- package/lib/components/widgets/index.d.ts +3 -0
- package/lib/components/widgets/index.js +44 -0
- package/lib/components/widgets/index.js.map +1 -0
- package/lib/getDefaultRegistry.d.ts +6 -0
- package/lib/getDefaultRegistry.js +19 -0
- package/lib/getDefaultRegistry.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/withTheme.d.ts +9 -0
- package/lib/withTheme.js +16 -0
- package/lib/withTheme.js.map +1 -0
- package/package.json +23 -16
- package/src/components/Form.tsx +853 -0
- package/src/components/fields/ArrayField.tsx +875 -0
- package/src/components/fields/BooleanField.tsx +114 -0
- package/src/components/fields/MultiSchemaField.tsx +221 -0
- package/src/components/fields/NullField.tsx +22 -0
- package/src/components/fields/NumberField.tsx +86 -0
- package/src/components/fields/ObjectField.tsx +331 -0
- package/src/components/fields/SchemaField.tsx +360 -0
- package/src/components/fields/StringField.tsx +71 -0
- package/src/components/fields/index.ts +31 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +41 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +90 -0
- package/src/components/templates/ArrayFieldTemplate.tsx +88 -0
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +43 -0
- package/src/components/templates/BaseInputTemplate.tsx +102 -0
- package/src/components/templates/ButtonTemplates/AddButton.tsx +29 -0
- package/src/components/templates/ButtonTemplates/IconButton.tsx +77 -0
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +21 -0
- package/src/components/templates/ButtonTemplates/index.ts +22 -0
- package/src/components/templates/DescriptionField.tsx +29 -0
- package/src/components/templates/ErrorList.tsx +35 -0
- package/src/components/templates/FieldErrorTemplate.tsx +33 -0
- package/src/components/templates/FieldHelpTemplate.tsx +29 -0
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +41 -0
- package/src/components/templates/FieldTemplate/Label.tsx +27 -0
- package/src/components/templates/FieldTemplate/index.ts +3 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +83 -0
- package/src/components/templates/TitleField.tsx +19 -0
- package/src/components/templates/UnsupportedField.tsx +37 -0
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +80 -0
- package/src/components/templates/index.ts +43 -0
- package/src/components/widgets/AltDateTimeWidget.tsx +16 -0
- package/src/components/widgets/AltDateWidget.tsx +198 -0
- package/src/components/widgets/CheckboxWidget.tsx +92 -0
- package/src/components/widgets/CheckboxesWidget.tsx +92 -0
- package/src/components/widgets/ColorWidget.tsx +14 -0
- package/src/components/widgets/DateTimeWidget.tsx +31 -0
- package/src/components/widgets/DateWidget.tsx +17 -0
- package/src/components/widgets/EmailWidget.tsx +13 -0
- package/src/components/widgets/FileWidget.tsx +178 -0
- package/src/components/widgets/HiddenWidget.tsx +15 -0
- package/src/components/widgets/PasswordWidget.tsx +15 -0
- package/src/components/widgets/RadioWidget.tsx +88 -0
- package/src/components/widgets/RangeWidget.tsx +23 -0
- package/src/components/widgets/SelectWidget.tsx +100 -0
- package/src/components/widgets/TextWidget.tsx +13 -0
- package/src/components/widgets/TextareaWidget.tsx +61 -0
- package/src/components/widgets/TimeWidget.tsx +17 -0
- package/src/components/widgets/URLWidget.tsx +13 -0
- package/src/components/widgets/UpDownWidget.tsx +13 -0
- package/src/components/widgets/index.ts +51 -0
- package/src/getDefaultRegistry.ts +24 -0
- package/src/index.ts +8 -0
- package/src/withTheme.tsx +42 -0
- package/dist/core.cjs.development.js +0 -4403
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -4383
- package/dist/core.esm.js.map +0 -1
- package/dist/core.umd.development.js +0 -4393
- package/dist/core.umd.development.js.map +0 -1
- package/dist/core.umd.production.min.js +0 -2
- package/dist/core.umd.production.min.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,3717 @@
|
|
|
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);
|
|
1
29
|
|
|
2
|
-
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
default: () => src_default,
|
|
34
|
+
getDefaultRegistry: () => getDefaultRegistry,
|
|
35
|
+
withTheme: () => withTheme
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
3
38
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
39
|
+
// src/components/Form.tsx
|
|
40
|
+
var import_react17 = require("react");
|
|
41
|
+
var import_utils39 = require("@rjsf/utils");
|
|
42
|
+
var import_get4 = __toESM(require("lodash/get"));
|
|
43
|
+
var import_isEmpty2 = __toESM(require("lodash/isEmpty"));
|
|
44
|
+
var import_pick = __toESM(require("lodash/pick"));
|
|
45
|
+
var import_toPath = __toESM(require("lodash/toPath"));
|
|
46
|
+
|
|
47
|
+
// src/getDefaultRegistry.ts
|
|
48
|
+
var import_utils38 = require("@rjsf/utils");
|
|
49
|
+
|
|
50
|
+
// src/components/fields/ArrayField.tsx
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_utils = require("@rjsf/utils");
|
|
53
|
+
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
54
|
+
var import_get = __toESM(require("lodash/get"));
|
|
55
|
+
var import_isObject = __toESM(require("lodash/isObject"));
|
|
56
|
+
var import_set = __toESM(require("lodash/set"));
|
|
57
|
+
var import_nanoid = require("nanoid");
|
|
58
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
59
|
+
function generateRowId() {
|
|
60
|
+
return (0, import_nanoid.nanoid)();
|
|
61
|
+
}
|
|
62
|
+
function generateKeyedFormData(formData) {
|
|
63
|
+
return !Array.isArray(formData) ? [] : formData.map((item) => {
|
|
64
|
+
return {
|
|
65
|
+
key: generateRowId(),
|
|
66
|
+
item
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function keyedToPlainFormData(keyedFormData) {
|
|
71
|
+
if (Array.isArray(keyedFormData)) {
|
|
72
|
+
return keyedFormData.map((keyedItem) => keyedItem.item);
|
|
73
|
+
}
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
var ArrayField = class extends import_react.Component {
|
|
77
|
+
/** Constructs an `ArrayField` from the `props`, generating the initial keyed data from the `formData`
|
|
78
|
+
*
|
|
79
|
+
* @param props - The `FieldProps` for this template
|
|
80
|
+
*/
|
|
81
|
+
constructor(props) {
|
|
82
|
+
super(props);
|
|
83
|
+
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
84
|
+
* that the schema is fixed and allows additional items.
|
|
85
|
+
*/
|
|
86
|
+
this._getNewFormDataRow = () => {
|
|
87
|
+
const { schema, registry } = this.props;
|
|
88
|
+
const { schemaUtils } = registry;
|
|
89
|
+
let itemSchema = schema.items;
|
|
90
|
+
if ((0, import_utils.isFixedItems)(schema) && (0, import_utils.allowAdditionalItems)(schema)) {
|
|
91
|
+
itemSchema = schema.additionalItems;
|
|
92
|
+
}
|
|
93
|
+
return schemaUtils.getDefaultFormState(itemSchema);
|
|
94
|
+
};
|
|
95
|
+
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
96
|
+
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
97
|
+
* keyed data
|
|
98
|
+
*
|
|
99
|
+
* @param event - The event for the click
|
|
100
|
+
*/
|
|
101
|
+
this.onAddClick = (event) => {
|
|
102
|
+
this._handleAddClick(event);
|
|
103
|
+
};
|
|
104
|
+
/** Callback handler for when the user clicks on the add button on an existing array element. Creates a new row of
|
|
105
|
+
* keyed form data inserted at the `index`, adding it into the state, and then returning `onChange()` with the plain
|
|
106
|
+
* form data converted from the keyed data
|
|
107
|
+
*
|
|
108
|
+
* @param index - The index at which the add button is clicked
|
|
109
|
+
*/
|
|
110
|
+
this.onAddIndexClick = (index) => {
|
|
111
|
+
return (event) => {
|
|
112
|
+
this._handleAddClick(event, index);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
116
|
+
* keyed form data at the `index` into the next position in the state, and then returning `onChange()` with the plain
|
|
117
|
+
* form data converted from the keyed data
|
|
118
|
+
*
|
|
119
|
+
* @param index - The index at which the copy button is clicked
|
|
120
|
+
*/
|
|
121
|
+
this.onCopyIndexClick = (index) => {
|
|
122
|
+
return (event) => {
|
|
123
|
+
if (event) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
}
|
|
126
|
+
const { onChange } = this.props;
|
|
127
|
+
const { keyedFormData } = this.state;
|
|
128
|
+
const newKeyedFormDataRow = {
|
|
129
|
+
key: generateRowId(),
|
|
130
|
+
item: (0, import_cloneDeep.default)(keyedFormData[index].item)
|
|
131
|
+
};
|
|
132
|
+
const newKeyedFormData = [...keyedFormData];
|
|
133
|
+
if (index !== void 0) {
|
|
134
|
+
newKeyedFormData.splice(index + 1, 0, newKeyedFormDataRow);
|
|
135
|
+
} else {
|
|
136
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
137
|
+
}
|
|
138
|
+
this.setState(
|
|
139
|
+
{
|
|
140
|
+
keyedFormData: newKeyedFormData,
|
|
141
|
+
updatedKeyedFormData: true
|
|
142
|
+
},
|
|
143
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData))
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
148
|
+
* keyed form data at the `index` in the state, and then returning `onChange()` with the plain form data converted
|
|
149
|
+
* from the keyed data
|
|
150
|
+
*
|
|
151
|
+
* @param index - The index at which the remove button is clicked
|
|
152
|
+
*/
|
|
153
|
+
this.onDropIndexClick = (index) => {
|
|
154
|
+
return (event) => {
|
|
155
|
+
if (event) {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
}
|
|
158
|
+
const { onChange, errorSchema } = this.props;
|
|
159
|
+
const { keyedFormData } = this.state;
|
|
160
|
+
let newErrorSchema;
|
|
161
|
+
if (errorSchema) {
|
|
162
|
+
newErrorSchema = {};
|
|
163
|
+
for (const idx in errorSchema) {
|
|
164
|
+
const i = parseInt(idx);
|
|
165
|
+
if (i < index) {
|
|
166
|
+
(0, import_set.default)(newErrorSchema, [i], errorSchema[idx]);
|
|
167
|
+
} else if (i > index) {
|
|
168
|
+
(0, import_set.default)(newErrorSchema, [i - 1], errorSchema[idx]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
|
|
173
|
+
this.setState(
|
|
174
|
+
{
|
|
175
|
+
keyedFormData: newKeyedFormData,
|
|
176
|
+
updatedKeyedFormData: true
|
|
177
|
+
},
|
|
178
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
183
|
+
* row of keyed form data at the `index` to the `newIndex` in the state, and then returning `onChange()` with the
|
|
184
|
+
* plain form data converted from the keyed data
|
|
185
|
+
*
|
|
186
|
+
* @param index - The index of the item to move
|
|
187
|
+
* @param newIndex - The index to where the item is to be moved
|
|
188
|
+
*/
|
|
189
|
+
this.onReorderClick = (index, newIndex) => {
|
|
190
|
+
return (event) => {
|
|
191
|
+
if (event) {
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
event.currentTarget.blur();
|
|
194
|
+
}
|
|
195
|
+
const { onChange, errorSchema } = this.props;
|
|
196
|
+
let newErrorSchema;
|
|
197
|
+
if (errorSchema) {
|
|
198
|
+
newErrorSchema = {};
|
|
199
|
+
for (const idx in errorSchema) {
|
|
200
|
+
const i = parseInt(idx);
|
|
201
|
+
if (i == index) {
|
|
202
|
+
(0, import_set.default)(newErrorSchema, [newIndex], errorSchema[index]);
|
|
203
|
+
} else if (i == newIndex) {
|
|
204
|
+
(0, import_set.default)(newErrorSchema, [index], errorSchema[newIndex]);
|
|
205
|
+
} else {
|
|
206
|
+
(0, import_set.default)(newErrorSchema, [idx], errorSchema[i]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const { keyedFormData } = this.state;
|
|
211
|
+
function reOrderArray() {
|
|
212
|
+
const _newKeyedFormData = keyedFormData.slice();
|
|
213
|
+
_newKeyedFormData.splice(index, 1);
|
|
214
|
+
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
215
|
+
return _newKeyedFormData;
|
|
216
|
+
}
|
|
217
|
+
const newKeyedFormData = reOrderArray();
|
|
218
|
+
this.setState(
|
|
219
|
+
{
|
|
220
|
+
keyedFormData: newKeyedFormData
|
|
221
|
+
},
|
|
222
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema)
|
|
223
|
+
);
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
227
|
+
* `onChange` callback with the updated form data
|
|
228
|
+
*
|
|
229
|
+
* @param index - The index of the item being changed
|
|
230
|
+
*/
|
|
231
|
+
this.onChangeForIndex = (index) => {
|
|
232
|
+
return (value, newErrorSchema, id) => {
|
|
233
|
+
const { formData, onChange, errorSchema } = this.props;
|
|
234
|
+
const arrayData = Array.isArray(formData) ? formData : [];
|
|
235
|
+
const newFormData = arrayData.map((item, i) => {
|
|
236
|
+
const jsonValue = typeof value === "undefined" ? null : value;
|
|
237
|
+
return index === i ? jsonValue : item;
|
|
238
|
+
});
|
|
239
|
+
onChange(
|
|
240
|
+
newFormData,
|
|
241
|
+
errorSchema && errorSchema && {
|
|
242
|
+
...errorSchema,
|
|
243
|
+
[index]: newErrorSchema
|
|
244
|
+
},
|
|
245
|
+
id
|
|
246
|
+
);
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
/** Callback handler used to change the value for a checkbox */
|
|
250
|
+
this.onSelectChange = (value) => {
|
|
251
|
+
const { onChange, idSchema } = this.props;
|
|
252
|
+
onChange(value, void 0, idSchema && idSchema.$id);
|
|
253
|
+
};
|
|
254
|
+
const { formData = [] } = props;
|
|
255
|
+
const keyedFormData = generateKeyedFormData(formData);
|
|
256
|
+
this.state = {
|
|
257
|
+
keyedFormData,
|
|
258
|
+
updatedKeyedFormData: false
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** React lifecycle method that is called when the props are about to change allowing the state to be updated. It
|
|
262
|
+
* regenerates the keyed form data and returns it
|
|
263
|
+
*
|
|
264
|
+
* @param nextProps - The next set of props data
|
|
265
|
+
* @param prevState - The previous set of state data
|
|
266
|
+
*/
|
|
267
|
+
static getDerivedStateFromProps(nextProps, prevState) {
|
|
268
|
+
if (prevState.updatedKeyedFormData) {
|
|
269
|
+
return {
|
|
270
|
+
updatedKeyedFormData: false
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
|
|
274
|
+
const previousKeyedFormData = prevState.keyedFormData || [];
|
|
275
|
+
const newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => {
|
|
276
|
+
return {
|
|
277
|
+
key: previousKeyedFormDatum.key,
|
|
278
|
+
item: nextFormData[index]
|
|
279
|
+
};
|
|
280
|
+
}) : generateKeyedFormData(nextFormData);
|
|
281
|
+
return {
|
|
282
|
+
keyedFormData: newKeyedFormData
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/** Returns the appropriate title for an item by getting first the title from the schema.items, then falling back to
|
|
286
|
+
* the description from the schema.items, and finally the string "Item"
|
|
287
|
+
*/
|
|
288
|
+
get itemTitle() {
|
|
289
|
+
const { schema, registry } = this.props;
|
|
290
|
+
const { translateString } = registry;
|
|
291
|
+
return (0, import_get.default)(
|
|
292
|
+
schema,
|
|
293
|
+
[import_utils.ITEMS_KEY, "title"],
|
|
294
|
+
(0, import_get.default)(schema, [import_utils.ITEMS_KEY, "description"], translateString(import_utils.TranslatableString.ArrayItemTitle))
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
/** Determines whether the item described in the schema is always required, which is determined by whether any item
|
|
298
|
+
* may be null.
|
|
299
|
+
*
|
|
300
|
+
* @param itemSchema - The schema for the item
|
|
301
|
+
* @return - True if the item schema type does not contain the "null" type
|
|
302
|
+
*/
|
|
303
|
+
isItemRequired(itemSchema) {
|
|
304
|
+
if (Array.isArray(itemSchema.type)) {
|
|
305
|
+
return !itemSchema.type.includes("null");
|
|
306
|
+
}
|
|
307
|
+
return itemSchema.type !== "null";
|
|
308
|
+
}
|
|
309
|
+
/** Determines whether more items can be added to the array. If the uiSchema indicates the array doesn't allow adding
|
|
310
|
+
* then false is returned. Otherwise, if the schema indicates that there are a maximum number of items and the
|
|
311
|
+
* `formData` matches that value, then false is returned, otherwise true is returned.
|
|
312
|
+
*
|
|
313
|
+
* @param formItems - The list of items in the form
|
|
314
|
+
* @returns - True if the item is addable otherwise false
|
|
315
|
+
*/
|
|
316
|
+
canAddItem(formItems) {
|
|
317
|
+
const { schema, uiSchema, registry } = this.props;
|
|
318
|
+
let { addable } = (0, import_utils.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
319
|
+
if (addable !== false) {
|
|
320
|
+
if (schema.maxItems !== void 0) {
|
|
321
|
+
addable = formItems.length < schema.maxItems;
|
|
322
|
+
} else {
|
|
323
|
+
addable = true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return addable;
|
|
327
|
+
}
|
|
328
|
+
/** Callback handler for when the user clicks on the add or add at index buttons. Creates a new row of keyed form data
|
|
329
|
+
* either at the end of the list (when index is not specified) or inserted at the `index` when it is, adding it into
|
|
330
|
+
* the state, and then returning `onChange()` with the plain form data converted from the keyed data
|
|
331
|
+
*
|
|
332
|
+
* @param event - The event for the click
|
|
333
|
+
* @param [index] - The optional index at which to add the new data
|
|
334
|
+
*/
|
|
335
|
+
_handleAddClick(event, index) {
|
|
336
|
+
if (event) {
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
}
|
|
339
|
+
const { onChange } = this.props;
|
|
340
|
+
const { keyedFormData } = this.state;
|
|
341
|
+
const newKeyedFormDataRow = {
|
|
342
|
+
key: generateRowId(),
|
|
343
|
+
item: this._getNewFormDataRow()
|
|
344
|
+
};
|
|
345
|
+
const newKeyedFormData = [...keyedFormData];
|
|
346
|
+
if (index !== void 0) {
|
|
347
|
+
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
348
|
+
} else {
|
|
349
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
350
|
+
}
|
|
351
|
+
this.setState(
|
|
352
|
+
{
|
|
353
|
+
keyedFormData: newKeyedFormData,
|
|
354
|
+
updatedKeyedFormData: true
|
|
355
|
+
},
|
|
356
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData))
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
360
|
+
*/
|
|
361
|
+
render() {
|
|
362
|
+
const { schema, uiSchema, idSchema, registry } = this.props;
|
|
363
|
+
const { schemaUtils, translateString } = registry;
|
|
364
|
+
if (!(import_utils.ITEMS_KEY in schema)) {
|
|
365
|
+
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
366
|
+
const UnsupportedFieldTemplate = (0, import_utils.getTemplate)(
|
|
367
|
+
"UnsupportedFieldTemplate",
|
|
368
|
+
registry,
|
|
369
|
+
uiOptions
|
|
370
|
+
);
|
|
371
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
372
|
+
UnsupportedFieldTemplate,
|
|
373
|
+
{
|
|
374
|
+
schema,
|
|
375
|
+
idSchema,
|
|
376
|
+
reason: translateString(import_utils.TranslatableString.MissingItems),
|
|
377
|
+
registry
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
if (schemaUtils.isMultiSelect(schema)) {
|
|
382
|
+
return this.renderMultiSelect();
|
|
383
|
+
}
|
|
384
|
+
if ((0, import_utils.isCustomWidget)(uiSchema)) {
|
|
385
|
+
return this.renderCustomWidget();
|
|
386
|
+
}
|
|
387
|
+
if ((0, import_utils.isFixedItems)(schema)) {
|
|
388
|
+
return this.renderFixedArray();
|
|
389
|
+
}
|
|
390
|
+
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
391
|
+
return this.renderFiles();
|
|
392
|
+
}
|
|
393
|
+
return this.renderNormalArray();
|
|
394
|
+
}
|
|
395
|
+
/** Renders a normal array without any limitations of length
|
|
396
|
+
*/
|
|
397
|
+
renderNormalArray() {
|
|
398
|
+
const {
|
|
399
|
+
schema,
|
|
400
|
+
uiSchema = {},
|
|
401
|
+
errorSchema,
|
|
402
|
+
idSchema,
|
|
403
|
+
name,
|
|
404
|
+
disabled = false,
|
|
405
|
+
readonly = false,
|
|
406
|
+
autofocus = false,
|
|
407
|
+
required = false,
|
|
408
|
+
registry,
|
|
409
|
+
onBlur,
|
|
410
|
+
onFocus,
|
|
411
|
+
idPrefix,
|
|
412
|
+
idSeparator = "_",
|
|
413
|
+
rawErrors
|
|
414
|
+
} = this.props;
|
|
415
|
+
const { keyedFormData } = this.state;
|
|
416
|
+
const title = schema.title === void 0 ? name : schema.title;
|
|
417
|
+
const { schemaUtils, formContext } = registry;
|
|
418
|
+
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
419
|
+
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : {};
|
|
420
|
+
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
421
|
+
const formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
422
|
+
const canAdd = this.canAddItem(formData);
|
|
423
|
+
const arrayProps = {
|
|
424
|
+
canAdd,
|
|
425
|
+
items: keyedFormData.map((keyedItem, index) => {
|
|
426
|
+
const { key, item } = keyedItem;
|
|
427
|
+
const itemCast = item;
|
|
428
|
+
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
429
|
+
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
430
|
+
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
431
|
+
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
432
|
+
return this.renderArrayFieldItem({
|
|
433
|
+
key,
|
|
434
|
+
index,
|
|
435
|
+
name: name && `${name}-${index}`,
|
|
436
|
+
canAdd,
|
|
437
|
+
canMoveUp: index > 0,
|
|
438
|
+
canMoveDown: index < formData.length - 1,
|
|
439
|
+
itemSchema,
|
|
440
|
+
itemIdSchema,
|
|
441
|
+
itemErrorSchema,
|
|
442
|
+
itemData: itemCast,
|
|
443
|
+
itemUiSchema: uiSchema.items,
|
|
444
|
+
autofocus: autofocus && index === 0,
|
|
445
|
+
onBlur,
|
|
446
|
+
onFocus,
|
|
447
|
+
rawErrors,
|
|
448
|
+
totalItems: keyedFormData.length
|
|
449
|
+
});
|
|
450
|
+
}),
|
|
451
|
+
className: `field field-array field-array-of-${itemsSchema.type}`,
|
|
452
|
+
disabled,
|
|
453
|
+
idSchema,
|
|
454
|
+
uiSchema,
|
|
455
|
+
onAddClick: this.onAddClick,
|
|
456
|
+
readonly,
|
|
457
|
+
required,
|
|
458
|
+
schema,
|
|
459
|
+
title,
|
|
460
|
+
formContext,
|
|
461
|
+
formData,
|
|
462
|
+
rawErrors,
|
|
463
|
+
registry
|
|
464
|
+
};
|
|
465
|
+
const Template = (0, import_utils.getTemplate)("ArrayFieldTemplate", registry, uiOptions);
|
|
466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Template, { ...arrayProps });
|
|
467
|
+
}
|
|
468
|
+
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
469
|
+
*/
|
|
470
|
+
renderCustomWidget() {
|
|
471
|
+
const {
|
|
472
|
+
schema,
|
|
473
|
+
idSchema,
|
|
474
|
+
uiSchema,
|
|
475
|
+
disabled = false,
|
|
476
|
+
readonly = false,
|
|
477
|
+
autofocus = false,
|
|
478
|
+
required = false,
|
|
479
|
+
hideError,
|
|
480
|
+
placeholder,
|
|
481
|
+
onBlur,
|
|
482
|
+
onFocus,
|
|
483
|
+
formData: items = [],
|
|
484
|
+
registry,
|
|
485
|
+
rawErrors,
|
|
486
|
+
name
|
|
487
|
+
} = this.props;
|
|
488
|
+
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
489
|
+
const { widget, title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
490
|
+
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
491
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
492
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
493
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
494
|
+
Widget,
|
|
495
|
+
{
|
|
496
|
+
id: idSchema.$id,
|
|
497
|
+
name,
|
|
498
|
+
multiple: true,
|
|
499
|
+
onChange: this.onSelectChange,
|
|
500
|
+
onBlur,
|
|
501
|
+
onFocus,
|
|
502
|
+
options,
|
|
503
|
+
schema,
|
|
504
|
+
uiSchema,
|
|
505
|
+
registry,
|
|
506
|
+
value: items,
|
|
507
|
+
disabled,
|
|
508
|
+
readonly,
|
|
509
|
+
hideError,
|
|
510
|
+
required,
|
|
511
|
+
label,
|
|
512
|
+
hideLabel: !displayLabel,
|
|
513
|
+
placeholder,
|
|
514
|
+
formContext,
|
|
515
|
+
autofocus,
|
|
516
|
+
rawErrors
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
/** Renders an array as a set of checkboxes
|
|
521
|
+
*/
|
|
522
|
+
renderMultiSelect() {
|
|
523
|
+
const {
|
|
524
|
+
schema,
|
|
525
|
+
idSchema,
|
|
526
|
+
uiSchema,
|
|
527
|
+
formData: items = [],
|
|
528
|
+
disabled = false,
|
|
529
|
+
readonly = false,
|
|
530
|
+
autofocus = false,
|
|
531
|
+
required = false,
|
|
532
|
+
placeholder,
|
|
533
|
+
onBlur,
|
|
534
|
+
onFocus,
|
|
535
|
+
registry,
|
|
536
|
+
rawErrors,
|
|
537
|
+
name
|
|
538
|
+
} = this.props;
|
|
539
|
+
const { widgets: widgets2, schemaUtils, formContext, globalUiOptions } = registry;
|
|
540
|
+
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
541
|
+
const enumOptions = (0, import_utils.optionsList)(itemsSchema);
|
|
542
|
+
const { widget = "select", title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
543
|
+
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
544
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
545
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
547
|
+
Widget,
|
|
548
|
+
{
|
|
549
|
+
id: idSchema.$id,
|
|
550
|
+
name,
|
|
551
|
+
multiple: true,
|
|
552
|
+
onChange: this.onSelectChange,
|
|
553
|
+
onBlur,
|
|
554
|
+
onFocus,
|
|
555
|
+
options: { ...options, enumOptions },
|
|
556
|
+
schema,
|
|
557
|
+
uiSchema,
|
|
558
|
+
registry,
|
|
559
|
+
value: items,
|
|
560
|
+
disabled,
|
|
561
|
+
readonly,
|
|
562
|
+
required,
|
|
563
|
+
label,
|
|
564
|
+
hideLabel: !displayLabel,
|
|
565
|
+
placeholder,
|
|
566
|
+
formContext,
|
|
567
|
+
autofocus,
|
|
568
|
+
rawErrors
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
/** Renders an array of files using the `FileWidget`
|
|
573
|
+
*/
|
|
574
|
+
renderFiles() {
|
|
575
|
+
const {
|
|
576
|
+
schema,
|
|
577
|
+
uiSchema,
|
|
578
|
+
idSchema,
|
|
579
|
+
name,
|
|
580
|
+
disabled = false,
|
|
581
|
+
readonly = false,
|
|
582
|
+
autofocus = false,
|
|
583
|
+
required = false,
|
|
584
|
+
onBlur,
|
|
585
|
+
onFocus,
|
|
586
|
+
registry,
|
|
587
|
+
formData: items = [],
|
|
588
|
+
rawErrors
|
|
589
|
+
} = this.props;
|
|
590
|
+
const { widgets: widgets2, formContext, globalUiOptions, schemaUtils } = registry;
|
|
591
|
+
const { widget = "files", title: uiTitle, ...options } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
592
|
+
const Widget = (0, import_utils.getWidget)(schema, widget, widgets2);
|
|
593
|
+
const label = uiTitle ?? schema.title ?? name;
|
|
594
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
596
|
+
Widget,
|
|
597
|
+
{
|
|
598
|
+
options,
|
|
599
|
+
id: idSchema.$id,
|
|
600
|
+
name,
|
|
601
|
+
multiple: true,
|
|
602
|
+
onChange: this.onSelectChange,
|
|
603
|
+
onBlur,
|
|
604
|
+
onFocus,
|
|
605
|
+
schema,
|
|
606
|
+
uiSchema,
|
|
607
|
+
value: items,
|
|
608
|
+
disabled,
|
|
609
|
+
readonly,
|
|
610
|
+
required,
|
|
611
|
+
registry,
|
|
612
|
+
formContext,
|
|
613
|
+
autofocus,
|
|
614
|
+
rawErrors,
|
|
615
|
+
label,
|
|
616
|
+
hideLabel: !displayLabel
|
|
617
|
+
}
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
/** Renders an array that has a maximum limit of items
|
|
621
|
+
*/
|
|
622
|
+
renderFixedArray() {
|
|
623
|
+
const {
|
|
624
|
+
schema,
|
|
625
|
+
uiSchema = {},
|
|
626
|
+
formData = [],
|
|
627
|
+
errorSchema,
|
|
628
|
+
idPrefix,
|
|
629
|
+
idSeparator = "_",
|
|
630
|
+
idSchema,
|
|
631
|
+
name,
|
|
632
|
+
disabled = false,
|
|
633
|
+
readonly = false,
|
|
634
|
+
autofocus = false,
|
|
635
|
+
required = false,
|
|
636
|
+
registry,
|
|
637
|
+
onBlur,
|
|
638
|
+
onFocus,
|
|
639
|
+
rawErrors
|
|
640
|
+
} = this.props;
|
|
641
|
+
const { keyedFormData } = this.state;
|
|
642
|
+
let { formData: items = [] } = this.props;
|
|
643
|
+
const title = schema.title || name;
|
|
644
|
+
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
645
|
+
const { schemaUtils, formContext } = registry;
|
|
646
|
+
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : [];
|
|
647
|
+
const itemSchemas = _schemaItems.map(
|
|
648
|
+
(item, index) => schemaUtils.retrieveSchema(item, formData[index])
|
|
649
|
+
);
|
|
650
|
+
const additionalSchema = (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
651
|
+
if (!items || items.length < itemSchemas.length) {
|
|
652
|
+
items = items || [];
|
|
653
|
+
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
654
|
+
}
|
|
655
|
+
const canAdd = this.canAddItem(items) && !!additionalSchema;
|
|
656
|
+
const arrayProps = {
|
|
657
|
+
canAdd,
|
|
658
|
+
className: "field field-array field-array-fixed-items",
|
|
659
|
+
disabled,
|
|
660
|
+
idSchema,
|
|
661
|
+
formData,
|
|
662
|
+
items: keyedFormData.map((keyedItem, index) => {
|
|
663
|
+
const { key, item } = keyedItem;
|
|
664
|
+
const itemCast = item;
|
|
665
|
+
const additional = index >= itemSchemas.length;
|
|
666
|
+
const itemSchema = additional && (0, import_isObject.default)(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
|
|
667
|
+
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
668
|
+
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
669
|
+
const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
|
|
670
|
+
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
|
|
671
|
+
return this.renderArrayFieldItem({
|
|
672
|
+
key,
|
|
673
|
+
index,
|
|
674
|
+
name: name && `${name}-${index}`,
|
|
675
|
+
canAdd,
|
|
676
|
+
canRemove: additional,
|
|
677
|
+
canMoveUp: index >= itemSchemas.length + 1,
|
|
678
|
+
canMoveDown: additional && index < items.length - 1,
|
|
679
|
+
itemSchema,
|
|
680
|
+
itemData: itemCast,
|
|
681
|
+
itemUiSchema,
|
|
682
|
+
itemIdSchema,
|
|
683
|
+
itemErrorSchema,
|
|
684
|
+
autofocus: autofocus && index === 0,
|
|
685
|
+
onBlur,
|
|
686
|
+
onFocus,
|
|
687
|
+
rawErrors,
|
|
688
|
+
totalItems: keyedFormData.length
|
|
689
|
+
});
|
|
690
|
+
}),
|
|
691
|
+
onAddClick: this.onAddClick,
|
|
692
|
+
readonly,
|
|
693
|
+
required,
|
|
694
|
+
registry,
|
|
695
|
+
schema,
|
|
696
|
+
uiSchema,
|
|
697
|
+
title,
|
|
698
|
+
formContext,
|
|
699
|
+
rawErrors
|
|
700
|
+
};
|
|
701
|
+
const Template = (0, import_utils.getTemplate)("ArrayFieldTemplate", registry, uiOptions);
|
|
702
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Template, { ...arrayProps });
|
|
703
|
+
}
|
|
704
|
+
/** Renders the individual array item using a `SchemaField` along with the additional properties required to be send
|
|
705
|
+
* back to the `ArrayFieldItemTemplate`.
|
|
706
|
+
*
|
|
707
|
+
* @param props - The props for the individual array item to be rendered
|
|
708
|
+
*/
|
|
709
|
+
renderArrayFieldItem(props) {
|
|
710
|
+
const {
|
|
711
|
+
key,
|
|
712
|
+
index,
|
|
713
|
+
name,
|
|
714
|
+
canAdd,
|
|
715
|
+
canRemove = true,
|
|
716
|
+
canMoveUp,
|
|
717
|
+
canMoveDown,
|
|
718
|
+
itemSchema,
|
|
719
|
+
itemData,
|
|
720
|
+
itemUiSchema,
|
|
721
|
+
itemIdSchema,
|
|
722
|
+
itemErrorSchema,
|
|
723
|
+
autofocus,
|
|
724
|
+
onBlur,
|
|
725
|
+
onFocus,
|
|
726
|
+
rawErrors,
|
|
727
|
+
totalItems
|
|
728
|
+
} = props;
|
|
729
|
+
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
|
|
730
|
+
const {
|
|
731
|
+
fields: { ArraySchemaField, SchemaField: SchemaField2 },
|
|
732
|
+
globalUiOptions
|
|
733
|
+
} = registry;
|
|
734
|
+
const ItemSchemaField = ArraySchemaField || SchemaField2;
|
|
735
|
+
const { orderable = true, removable = true, copyable = false } = (0, import_utils.getUiOptions)(uiSchema, globalUiOptions);
|
|
736
|
+
const has2 = {
|
|
737
|
+
moveUp: orderable && canMoveUp,
|
|
738
|
+
moveDown: orderable && canMoveDown,
|
|
739
|
+
copy: copyable && canAdd,
|
|
740
|
+
remove: removable && canRemove,
|
|
741
|
+
toolbar: false
|
|
742
|
+
};
|
|
743
|
+
has2.toolbar = Object.keys(has2).some((key2) => has2[key2]);
|
|
744
|
+
return {
|
|
745
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
746
|
+
ItemSchemaField,
|
|
747
|
+
{
|
|
748
|
+
name,
|
|
749
|
+
index,
|
|
750
|
+
schema: itemSchema,
|
|
751
|
+
uiSchema: itemUiSchema,
|
|
752
|
+
formData: itemData,
|
|
753
|
+
formContext,
|
|
754
|
+
errorSchema: itemErrorSchema,
|
|
755
|
+
idPrefix,
|
|
756
|
+
idSeparator,
|
|
757
|
+
idSchema: itemIdSchema,
|
|
758
|
+
required: this.isItemRequired(itemSchema),
|
|
759
|
+
onChange: this.onChangeForIndex(index),
|
|
760
|
+
onBlur,
|
|
761
|
+
onFocus,
|
|
762
|
+
registry,
|
|
763
|
+
disabled,
|
|
764
|
+
readonly,
|
|
765
|
+
hideError,
|
|
766
|
+
autofocus,
|
|
767
|
+
rawErrors
|
|
768
|
+
}
|
|
769
|
+
),
|
|
770
|
+
className: "array-item",
|
|
771
|
+
disabled,
|
|
772
|
+
canAdd,
|
|
773
|
+
hasCopy: has2.copy,
|
|
774
|
+
hasToolbar: has2.toolbar,
|
|
775
|
+
hasMoveUp: has2.moveUp,
|
|
776
|
+
hasMoveDown: has2.moveDown,
|
|
777
|
+
hasRemove: has2.remove,
|
|
778
|
+
index,
|
|
779
|
+
totalItems,
|
|
780
|
+
key,
|
|
781
|
+
onAddIndexClick: this.onAddIndexClick,
|
|
782
|
+
onCopyIndexClick: this.onCopyIndexClick,
|
|
783
|
+
onDropIndexClick: this.onDropIndexClick,
|
|
784
|
+
onReorderClick: this.onReorderClick,
|
|
785
|
+
readonly,
|
|
786
|
+
registry,
|
|
787
|
+
schema: itemSchema,
|
|
788
|
+
uiSchema: itemUiSchema
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
var ArrayField_default = ArrayField;
|
|
793
|
+
|
|
794
|
+
// src/components/fields/BooleanField.tsx
|
|
795
|
+
var import_utils2 = require("@rjsf/utils");
|
|
796
|
+
var import_isObject2 = __toESM(require("lodash/isObject"));
|
|
797
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
798
|
+
function BooleanField(props) {
|
|
799
|
+
const {
|
|
800
|
+
schema,
|
|
801
|
+
name,
|
|
802
|
+
uiSchema,
|
|
803
|
+
idSchema,
|
|
804
|
+
formData,
|
|
805
|
+
registry,
|
|
806
|
+
required,
|
|
807
|
+
disabled,
|
|
808
|
+
readonly,
|
|
809
|
+
autofocus,
|
|
810
|
+
onChange,
|
|
811
|
+
onFocus,
|
|
812
|
+
onBlur,
|
|
813
|
+
rawErrors
|
|
814
|
+
} = props;
|
|
815
|
+
const { title } = schema;
|
|
816
|
+
const { widgets: widgets2, formContext, translateString, globalUiOptions } = registry;
|
|
817
|
+
const {
|
|
818
|
+
widget = "checkbox",
|
|
819
|
+
title: uiTitle,
|
|
820
|
+
// Unlike the other fields, don't use `getDisplayLabel()` since it always returns false for the boolean type
|
|
821
|
+
label: displayLabel = true,
|
|
822
|
+
...options
|
|
823
|
+
} = (0, import_utils2.getUiOptions)(uiSchema, globalUiOptions);
|
|
824
|
+
const Widget = (0, import_utils2.getWidget)(schema, widget, widgets2);
|
|
825
|
+
const yes = translateString(import_utils2.TranslatableString.YesLabel);
|
|
826
|
+
const no = translateString(import_utils2.TranslatableString.NoLabel);
|
|
827
|
+
let enumOptions;
|
|
828
|
+
const label = uiTitle ?? title ?? name;
|
|
829
|
+
if (Array.isArray(schema.oneOf)) {
|
|
830
|
+
enumOptions = (0, import_utils2.optionsList)({
|
|
831
|
+
oneOf: schema.oneOf.map((option) => {
|
|
832
|
+
if ((0, import_isObject2.default)(option)) {
|
|
833
|
+
return {
|
|
834
|
+
...option,
|
|
835
|
+
title: option.title || (option.const === true ? yes : no)
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
return void 0;
|
|
839
|
+
}).filter((o) => o)
|
|
840
|
+
// cast away the error that typescript can't grok is fixed
|
|
841
|
+
});
|
|
842
|
+
} else {
|
|
843
|
+
const schemaWithEnumNames = schema;
|
|
844
|
+
const enums = schema.enum ?? [true, false];
|
|
845
|
+
if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every((v) => typeof v === "boolean")) {
|
|
846
|
+
enumOptions = [
|
|
847
|
+
{
|
|
848
|
+
value: enums[0],
|
|
849
|
+
label: enums[0] ? yes : no
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
value: enums[1],
|
|
853
|
+
label: enums[1] ? yes : no
|
|
854
|
+
}
|
|
855
|
+
];
|
|
856
|
+
} else {
|
|
857
|
+
enumOptions = (0, import_utils2.optionsList)({
|
|
858
|
+
enum: enums,
|
|
859
|
+
// NOTE: enumNames is deprecated, but still supported for now.
|
|
860
|
+
enumNames: schemaWithEnumNames.enumNames
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
865
|
+
Widget,
|
|
866
|
+
{
|
|
867
|
+
options: { ...options, enumOptions },
|
|
868
|
+
schema,
|
|
869
|
+
uiSchema,
|
|
870
|
+
id: idSchema.$id,
|
|
871
|
+
name,
|
|
872
|
+
onChange,
|
|
873
|
+
onFocus,
|
|
874
|
+
onBlur,
|
|
875
|
+
label,
|
|
876
|
+
hideLabel: !displayLabel,
|
|
877
|
+
value: formData,
|
|
878
|
+
required,
|
|
879
|
+
disabled,
|
|
880
|
+
readonly,
|
|
881
|
+
registry,
|
|
882
|
+
formContext,
|
|
883
|
+
autofocus,
|
|
884
|
+
rawErrors
|
|
885
|
+
}
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
var BooleanField_default = BooleanField;
|
|
889
|
+
|
|
890
|
+
// src/components/fields/MultiSchemaField.tsx
|
|
891
|
+
var import_react2 = require("react");
|
|
892
|
+
var import_get2 = __toESM(require("lodash/get"));
|
|
893
|
+
var import_isEmpty = __toESM(require("lodash/isEmpty"));
|
|
894
|
+
var import_omit = __toESM(require("lodash/omit"));
|
|
895
|
+
var import_unset = __toESM(require("lodash/unset"));
|
|
896
|
+
var import_utils3 = require("@rjsf/utils");
|
|
897
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
898
|
+
var AnyOfField = class extends import_react2.Component {
|
|
899
|
+
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
900
|
+
*
|
|
901
|
+
* @param props - The `FieldProps` for this template
|
|
902
|
+
*/
|
|
903
|
+
constructor(props) {
|
|
904
|
+
super(props);
|
|
905
|
+
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
906
|
+
* to remove properties that are not part of the newly selected option schema, and then the updated data is passed to
|
|
907
|
+
* the `onChange` handler.
|
|
908
|
+
*
|
|
909
|
+
* @param option - The new option value being selected
|
|
910
|
+
*/
|
|
911
|
+
this.onOptionChange = (option) => {
|
|
912
|
+
const { selectedOption, retrievedOptions } = this.state;
|
|
913
|
+
const { formData, onChange, registry } = this.props;
|
|
914
|
+
const { schemaUtils } = registry;
|
|
915
|
+
const intOption = option !== void 0 ? parseInt(option, 10) : -1;
|
|
916
|
+
if (intOption === selectedOption) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const newOption = intOption >= 0 ? retrievedOptions[intOption] : void 0;
|
|
920
|
+
const oldOption = selectedOption >= 0 ? retrievedOptions[selectedOption] : void 0;
|
|
921
|
+
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
|
|
922
|
+
if (newFormData && newOption) {
|
|
923
|
+
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
924
|
+
}
|
|
925
|
+
onChange(newFormData, void 0, this.getFieldId());
|
|
926
|
+
this.setState({ selectedOption: intOption });
|
|
927
|
+
};
|
|
928
|
+
const {
|
|
929
|
+
formData,
|
|
930
|
+
options,
|
|
931
|
+
registry: { schemaUtils }
|
|
932
|
+
} = this.props;
|
|
933
|
+
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
934
|
+
this.state = {
|
|
935
|
+
retrievedOptions,
|
|
936
|
+
selectedOption: this.getMatchingOption(0, formData, retrievedOptions)
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
/** React lifecycle method that is called when the props and/or state for this component is updated. It recomputes the
|
|
940
|
+
* currently selected option based on the overall `formData`
|
|
941
|
+
*
|
|
942
|
+
* @param prevProps - The previous `FieldProps` for this template
|
|
943
|
+
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
944
|
+
*/
|
|
945
|
+
componentDidUpdate(prevProps, prevState) {
|
|
946
|
+
const { formData, options, idSchema } = this.props;
|
|
947
|
+
const { selectedOption } = this.state;
|
|
948
|
+
let newState = this.state;
|
|
949
|
+
if (!(0, import_utils3.deepEquals)(prevProps.options, options)) {
|
|
950
|
+
const {
|
|
951
|
+
registry: { schemaUtils }
|
|
952
|
+
} = this.props;
|
|
953
|
+
const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
954
|
+
newState = { selectedOption, retrievedOptions };
|
|
955
|
+
}
|
|
956
|
+
if (!(0, import_utils3.deepEquals)(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
|
|
957
|
+
const { retrievedOptions } = newState;
|
|
958
|
+
const matchingOption = this.getMatchingOption(selectedOption, formData, retrievedOptions);
|
|
959
|
+
if (prevState && matchingOption !== selectedOption) {
|
|
960
|
+
newState = { selectedOption: matchingOption, retrievedOptions };
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (newState !== this.state) {
|
|
964
|
+
this.setState(newState);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
/** Determines the best matching option for the given `formData` and `options`.
|
|
968
|
+
*
|
|
969
|
+
* @param formData - The new formData
|
|
970
|
+
* @param options - The list of options to choose from
|
|
971
|
+
* @return - The index of the `option` that best matches the `formData`
|
|
972
|
+
*/
|
|
973
|
+
getMatchingOption(selectedOption, formData, options) {
|
|
974
|
+
const {
|
|
975
|
+
schema,
|
|
976
|
+
registry: { schemaUtils }
|
|
977
|
+
} = this.props;
|
|
978
|
+
const discriminator = (0, import_utils3.getDiscriminatorFieldFromSchema)(schema);
|
|
979
|
+
const option = schemaUtils.getClosestMatchingOption(formData, options, selectedOption, discriminator);
|
|
980
|
+
return option;
|
|
981
|
+
}
|
|
982
|
+
getFieldId() {
|
|
983
|
+
const { idSchema, schema } = this.props;
|
|
984
|
+
return `${idSchema.$id}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`;
|
|
985
|
+
}
|
|
986
|
+
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
987
|
+
*/
|
|
988
|
+
render() {
|
|
989
|
+
const {
|
|
990
|
+
name,
|
|
991
|
+
disabled = false,
|
|
992
|
+
errorSchema = {},
|
|
993
|
+
formContext,
|
|
994
|
+
onBlur,
|
|
995
|
+
onFocus,
|
|
996
|
+
registry,
|
|
997
|
+
schema,
|
|
998
|
+
uiSchema
|
|
999
|
+
} = this.props;
|
|
1000
|
+
const { widgets: widgets2, fields: fields2, translateString, globalUiOptions, schemaUtils } = registry;
|
|
1001
|
+
const { SchemaField: _SchemaField } = fields2;
|
|
1002
|
+
const { selectedOption, retrievedOptions } = this.state;
|
|
1003
|
+
const {
|
|
1004
|
+
widget = "select",
|
|
1005
|
+
placeholder,
|
|
1006
|
+
autofocus,
|
|
1007
|
+
autocomplete,
|
|
1008
|
+
title = schema.title,
|
|
1009
|
+
...uiOptions
|
|
1010
|
+
} = (0, import_utils3.getUiOptions)(uiSchema, globalUiOptions);
|
|
1011
|
+
const Widget = (0, import_utils3.getWidget)({ type: "number" }, widget, widgets2);
|
|
1012
|
+
const rawErrors = (0, import_get2.default)(errorSchema, import_utils3.ERRORS_KEY, []);
|
|
1013
|
+
const fieldErrorSchema = (0, import_omit.default)(errorSchema, [import_utils3.ERRORS_KEY]);
|
|
1014
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1015
|
+
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
1016
|
+
let optionSchema;
|
|
1017
|
+
if (option) {
|
|
1018
|
+
const { oneOf, anyOf, ...remaining } = schema;
|
|
1019
|
+
(0, import_unset.default)(remaining, import_utils3.ADDITIONAL_PROPERTY_FLAG);
|
|
1020
|
+
optionSchema = !(0, import_isEmpty.default)(remaining) ? (0, import_utils3.mergeSchemas)(remaining, option) : option;
|
|
1021
|
+
}
|
|
1022
|
+
const translateEnum = title ? import_utils3.TranslatableString.TitleOptionPrefix : import_utils3.TranslatableString.OptionPrefix;
|
|
1023
|
+
const translateParams = title ? [title] : [];
|
|
1024
|
+
const enumOptions = retrievedOptions.map((opt, index) => ({
|
|
1025
|
+
label: opt.title || translateString(translateEnum, translateParams.concat(String(index + 1))),
|
|
1026
|
+
value: index
|
|
1027
|
+
}));
|
|
1028
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "panel panel-default panel-body", children: [
|
|
1029
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "form-group", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1030
|
+
Widget,
|
|
1031
|
+
{
|
|
1032
|
+
id: this.getFieldId(),
|
|
1033
|
+
name: `${name}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`,
|
|
1034
|
+
schema: { type: "number", default: 0 },
|
|
1035
|
+
onChange: this.onOptionChange,
|
|
1036
|
+
onBlur,
|
|
1037
|
+
onFocus,
|
|
1038
|
+
disabled: disabled || (0, import_isEmpty.default)(enumOptions),
|
|
1039
|
+
multiple: false,
|
|
1040
|
+
rawErrors,
|
|
1041
|
+
errorSchema: fieldErrorSchema,
|
|
1042
|
+
value: selectedOption >= 0 ? selectedOption : void 0,
|
|
1043
|
+
options: { enumOptions, ...uiOptions },
|
|
1044
|
+
registry,
|
|
1045
|
+
formContext,
|
|
1046
|
+
placeholder,
|
|
1047
|
+
autocomplete,
|
|
1048
|
+
autofocus,
|
|
1049
|
+
label: title ?? name,
|
|
1050
|
+
hideLabel: !displayLabel
|
|
1051
|
+
}
|
|
1052
|
+
) }),
|
|
1053
|
+
option !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(_SchemaField, { ...this.props, schema: optionSchema })
|
|
1054
|
+
] });
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
var MultiSchemaField_default = AnyOfField;
|
|
1058
|
+
|
|
1059
|
+
// src/components/fields/NumberField.tsx
|
|
1060
|
+
var import_react3 = require("react");
|
|
1061
|
+
var import_utils4 = require("@rjsf/utils");
|
|
1062
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1063
|
+
var trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
1064
|
+
var trailingCharMatcher = /[0.]0*$/;
|
|
1065
|
+
function NumberField(props) {
|
|
1066
|
+
const { registry, onChange, formData, value: initialValue } = props;
|
|
1067
|
+
const [lastValue, setLastValue] = (0, import_react3.useState)(initialValue);
|
|
1068
|
+
const { StringField: StringField2 } = registry.fields;
|
|
1069
|
+
let value = formData;
|
|
1070
|
+
const handleChange = (0, import_react3.useCallback)(
|
|
1071
|
+
(value2) => {
|
|
1072
|
+
setLastValue(value2);
|
|
1073
|
+
if (`${value2}`.charAt(0) === ".") {
|
|
1074
|
+
value2 = `0${value2}`;
|
|
1075
|
+
}
|
|
1076
|
+
const processed = typeof value2 === "string" && value2.match(trailingCharMatcherWithPrefix) ? (0, import_utils4.asNumber)(value2.replace(trailingCharMatcher, "")) : (0, import_utils4.asNumber)(value2);
|
|
1077
|
+
onChange(processed);
|
|
1078
|
+
},
|
|
1079
|
+
[onChange]
|
|
1080
|
+
);
|
|
1081
|
+
if (typeof lastValue === "string" && typeof value === "number") {
|
|
1082
|
+
const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");
|
|
1083
|
+
if (lastValue.match(re)) {
|
|
1084
|
+
value = lastValue;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StringField2, { ...props, formData: value, onChange: handleChange });
|
|
1088
|
+
}
|
|
1089
|
+
var NumberField_default = NumberField;
|
|
1090
|
+
|
|
1091
|
+
// src/components/fields/ObjectField.tsx
|
|
1092
|
+
var import_react4 = require("react");
|
|
1093
|
+
var import_utils5 = require("@rjsf/utils");
|
|
1094
|
+
var import_markdown_to_jsx = __toESM(require("markdown-to-jsx"));
|
|
1095
|
+
var import_get3 = __toESM(require("lodash/get"));
|
|
1096
|
+
var import_has = __toESM(require("lodash/has"));
|
|
1097
|
+
var import_isObject3 = __toESM(require("lodash/isObject"));
|
|
1098
|
+
var import_set2 = __toESM(require("lodash/set"));
|
|
1099
|
+
var import_unset2 = __toESM(require("lodash/unset"));
|
|
1100
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1101
|
+
var ObjectField = class extends import_react4.Component {
|
|
1102
|
+
constructor() {
|
|
1103
|
+
super(...arguments);
|
|
1104
|
+
/** Set up the initial state */
|
|
1105
|
+
this.state = {
|
|
1106
|
+
wasPropertyKeyModified: false,
|
|
1107
|
+
additionalProperties: {}
|
|
1108
|
+
};
|
|
1109
|
+
/** Returns the `onPropertyChange` handler for the `name` field. Handles the special case where a user is attempting
|
|
1110
|
+
* to clear the data for a field added as an additional property. Calls the `onChange()` handler with the updated
|
|
1111
|
+
* formData.
|
|
1112
|
+
*
|
|
1113
|
+
* @param name - The name of the property
|
|
1114
|
+
* @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
|
|
1115
|
+
* @returns - The onPropertyChange callback for the `name` property
|
|
1116
|
+
*/
|
|
1117
|
+
this.onPropertyChange = (name, addedByAdditionalProperties = false) => {
|
|
1118
|
+
return (value, newErrorSchema, id) => {
|
|
1119
|
+
const { formData, onChange, errorSchema } = this.props;
|
|
1120
|
+
if (value === void 0 && addedByAdditionalProperties) {
|
|
1121
|
+
value = "";
|
|
1122
|
+
}
|
|
1123
|
+
const newFormData = { ...formData, [name]: value };
|
|
1124
|
+
onChange(
|
|
1125
|
+
newFormData,
|
|
1126
|
+
errorSchema && errorSchema && {
|
|
1127
|
+
...errorSchema,
|
|
1128
|
+
[name]: newErrorSchema
|
|
1129
|
+
},
|
|
1130
|
+
id
|
|
1131
|
+
);
|
|
1132
|
+
};
|
|
1133
|
+
};
|
|
1134
|
+
/** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
|
|
1135
|
+
* and calls the `onChange` callback with it
|
|
1136
|
+
*
|
|
1137
|
+
* @param key - The key for which the drop callback is desired
|
|
1138
|
+
* @returns - The drop property click callback
|
|
1139
|
+
*/
|
|
1140
|
+
this.onDropPropertyClick = (key) => {
|
|
1141
|
+
return (event) => {
|
|
1142
|
+
event.preventDefault();
|
|
1143
|
+
const { onChange, formData } = this.props;
|
|
1144
|
+
const copiedFormData = { ...formData };
|
|
1145
|
+
(0, import_unset2.default)(copiedFormData, key);
|
|
1146
|
+
onChange(copiedFormData);
|
|
1147
|
+
};
|
|
1148
|
+
};
|
|
1149
|
+
/** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
|
|
1150
|
+
* that is already not assigned is found.
|
|
1151
|
+
*
|
|
1152
|
+
* @param preferredKey - The preferred name of a new key
|
|
1153
|
+
* @param [formData] - The form data in which to check if the desired key already exists
|
|
1154
|
+
* @returns - The name of the next available key from `preferredKey`
|
|
1155
|
+
*/
|
|
1156
|
+
this.getAvailableKey = (preferredKey, formData) => {
|
|
1157
|
+
const { uiSchema, registry } = this.props;
|
|
1158
|
+
const { duplicateKeySuffixSeparator = "-" } = (0, import_utils5.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
1159
|
+
let index = 0;
|
|
1160
|
+
let newKey = preferredKey;
|
|
1161
|
+
while ((0, import_has.default)(formData, newKey)) {
|
|
1162
|
+
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
1163
|
+
}
|
|
1164
|
+
return newKey;
|
|
1165
|
+
};
|
|
1166
|
+
/** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
|
|
1167
|
+
* callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
|
|
1168
|
+
*
|
|
1169
|
+
* @param oldValue - The old value of a field
|
|
1170
|
+
* @returns - The key change callback function
|
|
1171
|
+
*/
|
|
1172
|
+
this.onKeyChange = (oldValue) => {
|
|
1173
|
+
return (value, newErrorSchema) => {
|
|
1174
|
+
if (oldValue === value) {
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
const { formData, onChange, errorSchema } = this.props;
|
|
1178
|
+
value = this.getAvailableKey(value, formData);
|
|
1179
|
+
const newFormData = {
|
|
1180
|
+
...formData
|
|
1181
|
+
};
|
|
1182
|
+
const newKeys = { [oldValue]: value };
|
|
1183
|
+
const keyValues = Object.keys(newFormData).map((key) => {
|
|
1184
|
+
const newKey = newKeys[key] || key;
|
|
1185
|
+
return { [newKey]: newFormData[key] };
|
|
1186
|
+
});
|
|
1187
|
+
const renamedObj = Object.assign({}, ...keyValues);
|
|
1188
|
+
this.setState({ wasPropertyKeyModified: true });
|
|
1189
|
+
onChange(
|
|
1190
|
+
renamedObj,
|
|
1191
|
+
errorSchema && errorSchema && {
|
|
1192
|
+
...errorSchema,
|
|
1193
|
+
[value]: newErrorSchema
|
|
1194
|
+
}
|
|
1195
|
+
);
|
|
1196
|
+
};
|
|
1197
|
+
};
|
|
1198
|
+
/** Handles the adding of a new additional property on the given `schema`. Calls the `onChange` callback once the new
|
|
1199
|
+
* default data for that field has been added to the formData.
|
|
1200
|
+
*
|
|
1201
|
+
* @param schema - The schema element to which the new property is being added
|
|
1202
|
+
*/
|
|
1203
|
+
this.handleAddClick = (schema) => () => {
|
|
1204
|
+
if (!schema.additionalProperties) {
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
const { formData, onChange, registry } = this.props;
|
|
1208
|
+
const newFormData = { ...formData };
|
|
1209
|
+
let type = void 0;
|
|
1210
|
+
if ((0, import_isObject3.default)(schema.additionalProperties)) {
|
|
1211
|
+
type = schema.additionalProperties.type;
|
|
1212
|
+
let apSchema = schema.additionalProperties;
|
|
1213
|
+
if (import_utils5.REF_KEY in apSchema) {
|
|
1214
|
+
const { schemaUtils } = registry;
|
|
1215
|
+
apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[import_utils5.REF_KEY] }, formData);
|
|
1216
|
+
type = apSchema.type;
|
|
1217
|
+
}
|
|
1218
|
+
if (!type && (import_utils5.ANY_OF_KEY in apSchema || import_utils5.ONE_OF_KEY in apSchema)) {
|
|
1219
|
+
type = "object";
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
1223
|
+
(0, import_set2.default)(newFormData, newKey, this.getDefaultValue(type));
|
|
1224
|
+
onChange(newFormData);
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
1228
|
+
*
|
|
1229
|
+
* @param name - The name of the field to check for required-ness
|
|
1230
|
+
* @returns - True if the field `name` is required, false otherwise
|
|
1231
|
+
*/
|
|
1232
|
+
isRequired(name) {
|
|
1233
|
+
const { schema } = this.props;
|
|
1234
|
+
return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
|
|
1235
|
+
}
|
|
1236
|
+
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1237
|
+
*
|
|
1238
|
+
* @param type - The type of the new additional schema property
|
|
1239
|
+
*/
|
|
1240
|
+
getDefaultValue(type) {
|
|
1241
|
+
const {
|
|
1242
|
+
registry: { translateString }
|
|
1243
|
+
} = this.props;
|
|
1244
|
+
switch (type) {
|
|
1245
|
+
case "array":
|
|
1246
|
+
return [];
|
|
1247
|
+
case "boolean":
|
|
1248
|
+
return false;
|
|
1249
|
+
case "null":
|
|
1250
|
+
return null;
|
|
1251
|
+
case "number":
|
|
1252
|
+
return 0;
|
|
1253
|
+
case "object":
|
|
1254
|
+
return {};
|
|
1255
|
+
case "string":
|
|
1256
|
+
default:
|
|
1257
|
+
return translateString(import_utils5.TranslatableString.NewStringDefault);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
/** Renders the `ObjectField` from the given props
|
|
1261
|
+
*/
|
|
1262
|
+
render() {
|
|
1263
|
+
const {
|
|
1264
|
+
schema: rawSchema,
|
|
1265
|
+
uiSchema = {},
|
|
1266
|
+
formData,
|
|
1267
|
+
errorSchema,
|
|
1268
|
+
idSchema,
|
|
1269
|
+
name,
|
|
1270
|
+
required = false,
|
|
1271
|
+
disabled = false,
|
|
1272
|
+
readonly = false,
|
|
1273
|
+
hideError,
|
|
1274
|
+
idPrefix,
|
|
1275
|
+
idSeparator,
|
|
1276
|
+
onBlur,
|
|
1277
|
+
onFocus,
|
|
1278
|
+
registry
|
|
1279
|
+
} = this.props;
|
|
1280
|
+
const { fields: fields2, formContext, schemaUtils, translateString, globalUiOptions } = registry;
|
|
1281
|
+
const { SchemaField: SchemaField2 } = fields2;
|
|
1282
|
+
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1283
|
+
const uiOptions = (0, import_utils5.getUiOptions)(uiSchema, globalUiOptions);
|
|
1284
|
+
const { properties: schemaProperties = {} } = schema;
|
|
1285
|
+
const title = uiOptions.title ?? schema.title ?? name;
|
|
1286
|
+
const description = uiOptions.description ?? schema.description;
|
|
1287
|
+
let orderedProperties;
|
|
1288
|
+
try {
|
|
1289
|
+
const properties = Object.keys(schemaProperties);
|
|
1290
|
+
orderedProperties = (0, import_utils5.orderProperties)(properties, uiOptions.order);
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1293
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "config-error", style: { color: "red" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_markdown_to_jsx.default, { children: translateString(import_utils5.TranslatableString.InvalidObjectField, [name || "root", err.message]) }) }),
|
|
1294
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { children: JSON.stringify(schema) })
|
|
1295
|
+
] });
|
|
1296
|
+
}
|
|
1297
|
+
const Template = (0, import_utils5.getTemplate)("ObjectFieldTemplate", registry, uiOptions);
|
|
1298
|
+
const templateProps = {
|
|
1299
|
+
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
1300
|
+
title: uiOptions.label === false ? "" : title,
|
|
1301
|
+
description: uiOptions.label === false ? void 0 : description,
|
|
1302
|
+
properties: orderedProperties.map((name2) => {
|
|
1303
|
+
const addedByAdditionalProperties = (0, import_has.default)(schema, [import_utils5.PROPERTIES_KEY, name2, import_utils5.ADDITIONAL_PROPERTY_FLAG]);
|
|
1304
|
+
const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name2];
|
|
1305
|
+
const hidden = (0, import_utils5.getUiOptions)(fieldUiSchema).widget === "hidden";
|
|
1306
|
+
const fieldIdSchema = (0, import_get3.default)(idSchema, [name2], {});
|
|
1307
|
+
return {
|
|
1308
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1309
|
+
SchemaField2,
|
|
1310
|
+
{
|
|
1311
|
+
name: name2,
|
|
1312
|
+
required: this.isRequired(name2),
|
|
1313
|
+
schema: (0, import_get3.default)(schema, [import_utils5.PROPERTIES_KEY, name2], {}),
|
|
1314
|
+
uiSchema: fieldUiSchema,
|
|
1315
|
+
errorSchema: (0, import_get3.default)(errorSchema, name2),
|
|
1316
|
+
idSchema: fieldIdSchema,
|
|
1317
|
+
idPrefix,
|
|
1318
|
+
idSeparator,
|
|
1319
|
+
formData: (0, import_get3.default)(formData, name2),
|
|
1320
|
+
formContext,
|
|
1321
|
+
wasPropertyKeyModified: this.state.wasPropertyKeyModified,
|
|
1322
|
+
onKeyChange: this.onKeyChange(name2),
|
|
1323
|
+
onChange: this.onPropertyChange(name2, addedByAdditionalProperties),
|
|
1324
|
+
onBlur,
|
|
1325
|
+
onFocus,
|
|
1326
|
+
registry,
|
|
1327
|
+
disabled,
|
|
1328
|
+
readonly,
|
|
1329
|
+
hideError,
|
|
1330
|
+
onDropPropertyClick: this.onDropPropertyClick
|
|
1331
|
+
},
|
|
1332
|
+
name2
|
|
1333
|
+
),
|
|
1334
|
+
name: name2,
|
|
1335
|
+
readonly,
|
|
1336
|
+
disabled,
|
|
1337
|
+
required,
|
|
1338
|
+
hidden
|
|
1339
|
+
};
|
|
1340
|
+
}),
|
|
1341
|
+
readonly,
|
|
1342
|
+
disabled,
|
|
1343
|
+
required,
|
|
1344
|
+
idSchema,
|
|
1345
|
+
uiSchema,
|
|
1346
|
+
errorSchema,
|
|
1347
|
+
schema,
|
|
1348
|
+
formData,
|
|
1349
|
+
formContext,
|
|
1350
|
+
registry
|
|
1351
|
+
};
|
|
1352
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Template, { ...templateProps, onAddClick: this.handleAddClick });
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
var ObjectField_default = ObjectField;
|
|
1356
|
+
|
|
1357
|
+
// src/components/fields/SchemaField.tsx
|
|
1358
|
+
var import_react5 = require("react");
|
|
1359
|
+
var import_utils6 = require("@rjsf/utils");
|
|
1360
|
+
var import_isObject4 = __toESM(require("lodash/isObject"));
|
|
1361
|
+
var import_omit2 = __toESM(require("lodash/omit"));
|
|
1362
|
+
var import_markdown_to_jsx2 = __toESM(require("markdown-to-jsx"));
|
|
1363
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1364
|
+
var COMPONENT_TYPES = {
|
|
1365
|
+
array: "ArrayField",
|
|
1366
|
+
boolean: "BooleanField",
|
|
1367
|
+
integer: "NumberField",
|
|
1368
|
+
number: "NumberField",
|
|
1369
|
+
object: "ObjectField",
|
|
1370
|
+
string: "StringField",
|
|
1371
|
+
null: "NullField"
|
|
1372
|
+
};
|
|
1373
|
+
function getFieldComponent(schema, uiOptions, idSchema, registry) {
|
|
1374
|
+
const field = uiOptions.field;
|
|
1375
|
+
const { fields: fields2, translateString } = registry;
|
|
1376
|
+
if (typeof field === "function") {
|
|
1377
|
+
return field;
|
|
1378
|
+
}
|
|
1379
|
+
if (typeof field === "string" && field in fields2) {
|
|
1380
|
+
return fields2[field];
|
|
1381
|
+
}
|
|
1382
|
+
const schemaType = (0, import_utils6.getSchemaType)(schema);
|
|
1383
|
+
const type = Array.isArray(schemaType) ? schemaType[0] : schemaType || "";
|
|
1384
|
+
const schemaId = schema.$id;
|
|
1385
|
+
let componentName = COMPONENT_TYPES[type];
|
|
1386
|
+
if (schemaId && schemaId in fields2) {
|
|
1387
|
+
componentName = schemaId;
|
|
1388
|
+
}
|
|
1389
|
+
if (!componentName && (schema.anyOf || schema.oneOf)) {
|
|
1390
|
+
return () => null;
|
|
1391
|
+
}
|
|
1392
|
+
return componentName in fields2 ? fields2[componentName] : () => {
|
|
1393
|
+
const UnsupportedFieldTemplate = (0, import_utils6.getTemplate)(
|
|
1394
|
+
"UnsupportedFieldTemplate",
|
|
1395
|
+
registry,
|
|
1396
|
+
uiOptions
|
|
1397
|
+
);
|
|
1398
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1399
|
+
UnsupportedFieldTemplate,
|
|
1400
|
+
{
|
|
1401
|
+
schema,
|
|
1402
|
+
idSchema,
|
|
1403
|
+
reason: translateString(import_utils6.TranslatableString.UnknownFieldType, [String(schema.type)]),
|
|
1404
|
+
registry
|
|
1405
|
+
}
|
|
1406
|
+
);
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
function SchemaFieldRender(props) {
|
|
1410
|
+
const {
|
|
1411
|
+
schema: _schema,
|
|
1412
|
+
idSchema: _idSchema,
|
|
1413
|
+
uiSchema,
|
|
1414
|
+
formData,
|
|
1415
|
+
errorSchema,
|
|
1416
|
+
idPrefix,
|
|
1417
|
+
idSeparator,
|
|
1418
|
+
name,
|
|
1419
|
+
onChange,
|
|
1420
|
+
onKeyChange,
|
|
1421
|
+
onDropPropertyClick,
|
|
1422
|
+
required,
|
|
1423
|
+
registry,
|
|
1424
|
+
wasPropertyKeyModified = false
|
|
1425
|
+
} = props;
|
|
1426
|
+
const { formContext, schemaUtils, globalUiOptions } = registry;
|
|
1427
|
+
const uiOptions = (0, import_utils6.getUiOptions)(uiSchema, globalUiOptions);
|
|
1428
|
+
const FieldTemplate2 = (0, import_utils6.getTemplate)("FieldTemplate", registry, uiOptions);
|
|
1429
|
+
const DescriptionFieldTemplate = (0, import_utils6.getTemplate)(
|
|
1430
|
+
"DescriptionFieldTemplate",
|
|
1431
|
+
registry,
|
|
1432
|
+
uiOptions
|
|
1433
|
+
);
|
|
1434
|
+
const FieldHelpTemplate2 = (0, import_utils6.getTemplate)("FieldHelpTemplate", registry, uiOptions);
|
|
1435
|
+
const FieldErrorTemplate2 = (0, import_utils6.getTemplate)("FieldErrorTemplate", registry, uiOptions);
|
|
1436
|
+
const schema = schemaUtils.retrieveSchema(_schema, formData);
|
|
1437
|
+
const fieldId = _idSchema[import_utils6.ID_KEY];
|
|
1438
|
+
const idSchema = (0, import_utils6.mergeObjects)(
|
|
1439
|
+
schemaUtils.toIdSchema(schema, fieldId, formData, idPrefix, idSeparator),
|
|
1440
|
+
_idSchema
|
|
1441
|
+
);
|
|
1442
|
+
const handleFieldComponentChange = (0, import_react5.useCallback)(
|
|
1443
|
+
(formData2, newErrorSchema, id2) => {
|
|
1444
|
+
const theId = id2 || fieldId;
|
|
1445
|
+
return onChange(formData2, newErrorSchema, theId);
|
|
1446
|
+
},
|
|
1447
|
+
[fieldId, onChange]
|
|
1448
|
+
);
|
|
1449
|
+
const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
|
|
1450
|
+
const disabled = Boolean(props.disabled || uiOptions.disabled);
|
|
1451
|
+
const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
|
|
1452
|
+
const uiSchemaHideError = uiOptions.hideError;
|
|
1453
|
+
const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
|
|
1454
|
+
const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
|
|
1455
|
+
if (Object.keys(schema).length === 0) {
|
|
1456
|
+
return null;
|
|
1457
|
+
}
|
|
1458
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1459
|
+
const { __errors, ...fieldErrorSchema } = errorSchema || {};
|
|
1460
|
+
const fieldUiSchema = (0, import_omit2.default)(uiSchema, ["ui:classNames", "classNames", "ui:style"]);
|
|
1461
|
+
if (import_utils6.UI_OPTIONS_KEY in fieldUiSchema) {
|
|
1462
|
+
fieldUiSchema[import_utils6.UI_OPTIONS_KEY] = (0, import_omit2.default)(fieldUiSchema[import_utils6.UI_OPTIONS_KEY], ["classNames", "style"]);
|
|
1463
|
+
}
|
|
1464
|
+
const field = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1465
|
+
FieldComponent,
|
|
1466
|
+
{
|
|
1467
|
+
...props,
|
|
1468
|
+
onChange: handleFieldComponentChange,
|
|
1469
|
+
idSchema,
|
|
1470
|
+
schema,
|
|
1471
|
+
uiSchema: fieldUiSchema,
|
|
1472
|
+
disabled,
|
|
1473
|
+
readonly,
|
|
1474
|
+
hideError,
|
|
1475
|
+
autofocus,
|
|
1476
|
+
errorSchema: fieldErrorSchema,
|
|
1477
|
+
formContext,
|
|
1478
|
+
rawErrors: __errors
|
|
1479
|
+
}
|
|
1480
|
+
);
|
|
1481
|
+
const id = idSchema[import_utils6.ID_KEY];
|
|
1482
|
+
let label;
|
|
1483
|
+
if (wasPropertyKeyModified) {
|
|
1484
|
+
label = name;
|
|
1485
|
+
} else {
|
|
1486
|
+
label = import_utils6.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
|
|
1487
|
+
}
|
|
1488
|
+
const description = uiOptions.description || props.schema.description || schema.description || "";
|
|
1489
|
+
const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_markdown_to_jsx2.default, { children: description }) : description;
|
|
1490
|
+
const help = uiOptions.help;
|
|
1491
|
+
const hidden = uiOptions.widget === "hidden";
|
|
1492
|
+
const classNames = ["form-group", "field", `field-${(0, import_utils6.getSchemaType)(schema)}`];
|
|
1493
|
+
if (!hideError && __errors && __errors.length > 0) {
|
|
1494
|
+
classNames.push("field-error has-error has-danger");
|
|
1495
|
+
}
|
|
1496
|
+
if (uiSchema?.classNames) {
|
|
1497
|
+
if (true) {
|
|
1498
|
+
console.warn(
|
|
1499
|
+
"'uiSchema.classNames' is deprecated and may be removed in a major release; Use 'ui:classNames' instead."
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
classNames.push(uiSchema.classNames);
|
|
1503
|
+
}
|
|
1504
|
+
if (uiOptions.classNames) {
|
|
1505
|
+
classNames.push(uiOptions.classNames);
|
|
1506
|
+
}
|
|
1507
|
+
const helpComponent = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1508
|
+
FieldHelpTemplate2,
|
|
1509
|
+
{
|
|
1510
|
+
help,
|
|
1511
|
+
idSchema,
|
|
1512
|
+
schema,
|
|
1513
|
+
uiSchema,
|
|
1514
|
+
hasErrors: !hideError && __errors && __errors.length > 0,
|
|
1515
|
+
registry
|
|
1516
|
+
}
|
|
1517
|
+
);
|
|
1518
|
+
const errorsComponent = hideError || schema.anyOf || schema.oneOf ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1519
|
+
FieldErrorTemplate2,
|
|
1520
|
+
{
|
|
1521
|
+
errors: __errors,
|
|
1522
|
+
errorSchema,
|
|
1523
|
+
idSchema,
|
|
1524
|
+
schema,
|
|
1525
|
+
uiSchema,
|
|
1526
|
+
registry
|
|
1527
|
+
}
|
|
1528
|
+
);
|
|
1529
|
+
const fieldProps = {
|
|
1530
|
+
description: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1531
|
+
DescriptionFieldTemplate,
|
|
1532
|
+
{
|
|
1533
|
+
id: (0, import_utils6.descriptionId)(id),
|
|
1534
|
+
description: richDescription,
|
|
1535
|
+
schema,
|
|
1536
|
+
uiSchema,
|
|
1537
|
+
registry
|
|
1538
|
+
}
|
|
1539
|
+
),
|
|
1540
|
+
rawDescription: description,
|
|
1541
|
+
help: helpComponent,
|
|
1542
|
+
rawHelp: typeof help === "string" ? help : void 0,
|
|
1543
|
+
errors: errorsComponent,
|
|
1544
|
+
rawErrors: hideError ? void 0 : __errors,
|
|
1545
|
+
id,
|
|
1546
|
+
label,
|
|
1547
|
+
hidden,
|
|
1548
|
+
onChange,
|
|
1549
|
+
onKeyChange,
|
|
1550
|
+
onDropPropertyClick,
|
|
1551
|
+
required,
|
|
1552
|
+
disabled,
|
|
1553
|
+
readonly,
|
|
1554
|
+
hideError,
|
|
1555
|
+
displayLabel,
|
|
1556
|
+
classNames: classNames.join(" ").trim(),
|
|
1557
|
+
style: uiOptions.style,
|
|
1558
|
+
formContext,
|
|
1559
|
+
formData,
|
|
1560
|
+
schema,
|
|
1561
|
+
uiSchema,
|
|
1562
|
+
registry
|
|
1563
|
+
};
|
|
1564
|
+
const _AnyOfField = registry.fields.AnyOfField;
|
|
1565
|
+
const _OneOfField = registry.fields.OneOfField;
|
|
1566
|
+
const isReplacingAnyOrOneOf = uiSchema?.["ui:field"] && uiSchema?.["ui:fieldReplacesAnyOrOneOf"] === true;
|
|
1567
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FieldTemplate2, { ...fieldProps, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1568
|
+
field,
|
|
1569
|
+
schema.anyOf && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1570
|
+
_AnyOfField,
|
|
1571
|
+
{
|
|
1572
|
+
name,
|
|
1573
|
+
disabled,
|
|
1574
|
+
readonly,
|
|
1575
|
+
hideError,
|
|
1576
|
+
errorSchema,
|
|
1577
|
+
formData,
|
|
1578
|
+
formContext,
|
|
1579
|
+
idPrefix,
|
|
1580
|
+
idSchema,
|
|
1581
|
+
idSeparator,
|
|
1582
|
+
onBlur: props.onBlur,
|
|
1583
|
+
onChange: props.onChange,
|
|
1584
|
+
onFocus: props.onFocus,
|
|
1585
|
+
options: schema.anyOf.map(
|
|
1586
|
+
(_schema2) => schemaUtils.retrieveSchema((0, import_isObject4.default)(_schema2) ? _schema2 : {}, formData)
|
|
1587
|
+
),
|
|
1588
|
+
registry,
|
|
1589
|
+
schema,
|
|
1590
|
+
uiSchema
|
|
1591
|
+
}
|
|
1592
|
+
),
|
|
1593
|
+
schema.oneOf && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1594
|
+
_OneOfField,
|
|
1595
|
+
{
|
|
1596
|
+
name,
|
|
1597
|
+
disabled,
|
|
1598
|
+
readonly,
|
|
1599
|
+
hideError,
|
|
1600
|
+
errorSchema,
|
|
1601
|
+
formData,
|
|
1602
|
+
formContext,
|
|
1603
|
+
idPrefix,
|
|
1604
|
+
idSchema,
|
|
1605
|
+
idSeparator,
|
|
1606
|
+
onBlur: props.onBlur,
|
|
1607
|
+
onChange: props.onChange,
|
|
1608
|
+
onFocus: props.onFocus,
|
|
1609
|
+
options: schema.oneOf.map(
|
|
1610
|
+
(_schema2) => schemaUtils.retrieveSchema((0, import_isObject4.default)(_schema2) ? _schema2 : {}, formData)
|
|
1611
|
+
),
|
|
1612
|
+
registry,
|
|
1613
|
+
schema,
|
|
1614
|
+
uiSchema
|
|
1615
|
+
}
|
|
1616
|
+
)
|
|
1617
|
+
] }) });
|
|
1618
|
+
}
|
|
1619
|
+
var SchemaField = class extends import_react5.Component {
|
|
1620
|
+
shouldComponentUpdate(nextProps) {
|
|
1621
|
+
return !(0, import_utils6.deepEquals)(this.props, nextProps);
|
|
1622
|
+
}
|
|
1623
|
+
render() {
|
|
1624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SchemaFieldRender, { ...this.props });
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
var SchemaField_default = SchemaField;
|
|
1628
|
+
|
|
1629
|
+
// src/components/fields/StringField.tsx
|
|
1630
|
+
var import_utils7 = require("@rjsf/utils");
|
|
1631
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1632
|
+
function StringField(props) {
|
|
1633
|
+
const {
|
|
1634
|
+
schema,
|
|
1635
|
+
name,
|
|
1636
|
+
uiSchema,
|
|
1637
|
+
idSchema,
|
|
1638
|
+
formData,
|
|
1639
|
+
required,
|
|
1640
|
+
disabled = false,
|
|
1641
|
+
readonly = false,
|
|
1642
|
+
autofocus = false,
|
|
1643
|
+
onChange,
|
|
1644
|
+
onBlur,
|
|
1645
|
+
onFocus,
|
|
1646
|
+
registry,
|
|
1647
|
+
rawErrors
|
|
1648
|
+
} = props;
|
|
1649
|
+
const { title, format } = schema;
|
|
1650
|
+
const { widgets: widgets2, formContext, schemaUtils, globalUiOptions } = registry;
|
|
1651
|
+
const enumOptions = schemaUtils.isSelect(schema) ? (0, import_utils7.optionsList)(schema) : void 0;
|
|
1652
|
+
let defaultWidget = enumOptions ? "select" : "text";
|
|
1653
|
+
if (format && (0, import_utils7.hasWidget)(schema, format, widgets2)) {
|
|
1654
|
+
defaultWidget = format;
|
|
1655
|
+
}
|
|
1656
|
+
const { widget = defaultWidget, placeholder = "", title: uiTitle, ...options } = (0, import_utils7.getUiOptions)(uiSchema);
|
|
1657
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1658
|
+
const label = uiTitle ?? title ?? name;
|
|
1659
|
+
const Widget = (0, import_utils7.getWidget)(schema, widget, widgets2);
|
|
1660
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1661
|
+
Widget,
|
|
1662
|
+
{
|
|
1663
|
+
options: { ...options, enumOptions },
|
|
1664
|
+
schema,
|
|
1665
|
+
uiSchema,
|
|
1666
|
+
id: idSchema.$id,
|
|
1667
|
+
name,
|
|
1668
|
+
label,
|
|
1669
|
+
hideLabel: !displayLabel,
|
|
1670
|
+
value: formData,
|
|
1671
|
+
onChange,
|
|
1672
|
+
onBlur,
|
|
1673
|
+
onFocus,
|
|
1674
|
+
required,
|
|
1675
|
+
disabled,
|
|
1676
|
+
readonly,
|
|
1677
|
+
formContext,
|
|
1678
|
+
autofocus,
|
|
1679
|
+
registry,
|
|
1680
|
+
placeholder,
|
|
1681
|
+
rawErrors
|
|
1682
|
+
}
|
|
1683
|
+
);
|
|
1684
|
+
}
|
|
1685
|
+
var StringField_default = StringField;
|
|
1686
|
+
|
|
1687
|
+
// src/components/fields/NullField.tsx
|
|
1688
|
+
var import_react6 = require("react");
|
|
1689
|
+
function NullField(props) {
|
|
1690
|
+
const { formData, onChange } = props;
|
|
1691
|
+
(0, import_react6.useEffect)(() => {
|
|
1692
|
+
if (formData === void 0) {
|
|
1693
|
+
onChange(null);
|
|
1694
|
+
}
|
|
1695
|
+
}, [formData, onChange]);
|
|
1696
|
+
return null;
|
|
1697
|
+
}
|
|
1698
|
+
var NullField_default = NullField;
|
|
1699
|
+
|
|
1700
|
+
// src/components/fields/index.ts
|
|
1701
|
+
function fields() {
|
|
1702
|
+
return {
|
|
1703
|
+
AnyOfField: MultiSchemaField_default,
|
|
1704
|
+
ArrayField: ArrayField_default,
|
|
1705
|
+
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
1706
|
+
BooleanField: BooleanField_default,
|
|
1707
|
+
NumberField: NumberField_default,
|
|
1708
|
+
ObjectField: ObjectField_default,
|
|
1709
|
+
OneOfField: MultiSchemaField_default,
|
|
1710
|
+
SchemaField: SchemaField_default,
|
|
1711
|
+
StringField: StringField_default,
|
|
1712
|
+
NullField: NullField_default
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
var fields_default = fields;
|
|
1716
|
+
|
|
1717
|
+
// src/components/templates/ArrayFieldDescriptionTemplate.tsx
|
|
1718
|
+
var import_utils8 = require("@rjsf/utils");
|
|
1719
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1720
|
+
function ArrayFieldDescriptionTemplate(props) {
|
|
1721
|
+
const { idSchema, description, registry, schema, uiSchema } = props;
|
|
1722
|
+
const options = (0, import_utils8.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
1723
|
+
const { label: displayLabel = true } = options;
|
|
1724
|
+
if (!description || !displayLabel) {
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
const DescriptionFieldTemplate = (0, import_utils8.getTemplate)(
|
|
1728
|
+
"DescriptionFieldTemplate",
|
|
1729
|
+
registry,
|
|
1730
|
+
options
|
|
1731
|
+
);
|
|
1732
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1733
|
+
DescriptionFieldTemplate,
|
|
1734
|
+
{
|
|
1735
|
+
id: (0, import_utils8.descriptionId)(idSchema),
|
|
1736
|
+
description,
|
|
1737
|
+
schema,
|
|
1738
|
+
uiSchema,
|
|
1739
|
+
registry
|
|
1740
|
+
}
|
|
1741
|
+
);
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// src/components/templates/ArrayFieldItemTemplate.tsx
|
|
1745
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1746
|
+
function ArrayFieldItemTemplate(props) {
|
|
1747
|
+
const {
|
|
1748
|
+
children,
|
|
1749
|
+
className,
|
|
1750
|
+
disabled,
|
|
1751
|
+
hasToolbar,
|
|
1752
|
+
hasMoveDown,
|
|
1753
|
+
hasMoveUp,
|
|
1754
|
+
hasRemove,
|
|
1755
|
+
hasCopy,
|
|
1756
|
+
index,
|
|
1757
|
+
onCopyIndexClick,
|
|
1758
|
+
onDropIndexClick,
|
|
1759
|
+
onReorderClick,
|
|
1760
|
+
readonly,
|
|
1761
|
+
registry,
|
|
1762
|
+
uiSchema
|
|
1763
|
+
} = props;
|
|
1764
|
+
const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates;
|
|
1765
|
+
const btnStyle = {
|
|
1766
|
+
flex: 1,
|
|
1767
|
+
paddingLeft: 6,
|
|
1768
|
+
paddingRight: 6,
|
|
1769
|
+
fontWeight: "bold"
|
|
1770
|
+
};
|
|
1771
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className, children: [
|
|
1772
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: hasToolbar ? "col-xs-9" : "col-xs-12", children }),
|
|
1773
|
+
hasToolbar && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "col-xs-3 array-item-toolbox", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1774
|
+
"div",
|
|
1775
|
+
{
|
|
1776
|
+
className: "btn-group",
|
|
1777
|
+
style: {
|
|
1778
|
+
display: "flex",
|
|
1779
|
+
justifyContent: "space-around"
|
|
1780
|
+
},
|
|
1781
|
+
children: [
|
|
1782
|
+
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1783
|
+
MoveUpButton2,
|
|
1784
|
+
{
|
|
1785
|
+
style: btnStyle,
|
|
1786
|
+
disabled: disabled || readonly || !hasMoveUp,
|
|
1787
|
+
onClick: onReorderClick(index, index - 1),
|
|
1788
|
+
uiSchema,
|
|
1789
|
+
registry
|
|
1790
|
+
}
|
|
1791
|
+
),
|
|
1792
|
+
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1793
|
+
MoveDownButton2,
|
|
1794
|
+
{
|
|
1795
|
+
style: btnStyle,
|
|
1796
|
+
disabled: disabled || readonly || !hasMoveDown,
|
|
1797
|
+
onClick: onReorderClick(index, index + 1),
|
|
1798
|
+
uiSchema,
|
|
1799
|
+
registry
|
|
1800
|
+
}
|
|
1801
|
+
),
|
|
1802
|
+
hasCopy && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1803
|
+
CopyButton2,
|
|
1804
|
+
{
|
|
1805
|
+
style: btnStyle,
|
|
1806
|
+
disabled: disabled || readonly,
|
|
1807
|
+
onClick: onCopyIndexClick(index),
|
|
1808
|
+
uiSchema,
|
|
1809
|
+
registry
|
|
1810
|
+
}
|
|
1811
|
+
),
|
|
1812
|
+
hasRemove && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1813
|
+
RemoveButton2,
|
|
1814
|
+
{
|
|
1815
|
+
style: btnStyle,
|
|
1816
|
+
disabled: disabled || readonly,
|
|
1817
|
+
onClick: onDropIndexClick(index),
|
|
1818
|
+
uiSchema,
|
|
1819
|
+
registry
|
|
1820
|
+
}
|
|
1821
|
+
)
|
|
1822
|
+
]
|
|
1823
|
+
}
|
|
1824
|
+
) })
|
|
1825
|
+
] });
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
// src/components/templates/ArrayFieldTemplate.tsx
|
|
1829
|
+
var import_utils9 = require("@rjsf/utils");
|
|
1830
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1831
|
+
function ArrayFieldTemplate(props) {
|
|
1832
|
+
const {
|
|
1833
|
+
canAdd,
|
|
1834
|
+
className,
|
|
1835
|
+
disabled,
|
|
1836
|
+
idSchema,
|
|
1837
|
+
uiSchema,
|
|
1838
|
+
items,
|
|
1839
|
+
onAddClick,
|
|
1840
|
+
readonly,
|
|
1841
|
+
registry,
|
|
1842
|
+
required,
|
|
1843
|
+
schema,
|
|
1844
|
+
title
|
|
1845
|
+
} = props;
|
|
1846
|
+
const uiOptions = (0, import_utils9.getUiOptions)(uiSchema);
|
|
1847
|
+
const ArrayFieldDescriptionTemplate2 = (0, import_utils9.getTemplate)(
|
|
1848
|
+
"ArrayFieldDescriptionTemplate",
|
|
1849
|
+
registry,
|
|
1850
|
+
uiOptions
|
|
1851
|
+
);
|
|
1852
|
+
const ArrayFieldItemTemplate2 = (0, import_utils9.getTemplate)(
|
|
1853
|
+
"ArrayFieldItemTemplate",
|
|
1854
|
+
registry,
|
|
1855
|
+
uiOptions
|
|
1856
|
+
);
|
|
1857
|
+
const ArrayFieldTitleTemplate2 = (0, import_utils9.getTemplate)(
|
|
1858
|
+
"ArrayFieldTitleTemplate",
|
|
1859
|
+
registry,
|
|
1860
|
+
uiOptions
|
|
1861
|
+
);
|
|
1862
|
+
const {
|
|
1863
|
+
ButtonTemplates: { AddButton: AddButton2 }
|
|
1864
|
+
} = registry.templates;
|
|
1865
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("fieldset", { className, id: idSchema.$id, children: [
|
|
1866
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1867
|
+
ArrayFieldTitleTemplate2,
|
|
1868
|
+
{
|
|
1869
|
+
idSchema,
|
|
1870
|
+
title: uiOptions.title || title,
|
|
1871
|
+
required,
|
|
1872
|
+
schema,
|
|
1873
|
+
uiSchema,
|
|
1874
|
+
registry
|
|
1875
|
+
}
|
|
1876
|
+
),
|
|
1877
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1878
|
+
ArrayFieldDescriptionTemplate2,
|
|
1879
|
+
{
|
|
1880
|
+
idSchema,
|
|
1881
|
+
description: uiOptions.description || schema.description,
|
|
1882
|
+
schema,
|
|
1883
|
+
uiSchema,
|
|
1884
|
+
registry
|
|
1885
|
+
}
|
|
1886
|
+
),
|
|
1887
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "row array-item-list", children: items && items.map(({ key, ...itemProps }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ArrayFieldItemTemplate2, { ...itemProps }, key)) }),
|
|
1888
|
+
canAdd && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1889
|
+
AddButton2,
|
|
1890
|
+
{
|
|
1891
|
+
className: "array-item-add",
|
|
1892
|
+
onClick: onAddClick,
|
|
1893
|
+
disabled: disabled || readonly,
|
|
1894
|
+
uiSchema,
|
|
1895
|
+
registry
|
|
1896
|
+
}
|
|
1897
|
+
)
|
|
1898
|
+
] });
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// src/components/templates/ArrayFieldTitleTemplate.tsx
|
|
1902
|
+
var import_utils10 = require("@rjsf/utils");
|
|
1903
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1904
|
+
function ArrayFieldTitleTemplate(props) {
|
|
1905
|
+
const { idSchema, title, schema, uiSchema, required, registry } = props;
|
|
1906
|
+
const options = (0, import_utils10.getUiOptions)(uiSchema, registry.globalUiOptions);
|
|
1907
|
+
const { label: displayLabel = true } = options;
|
|
1908
|
+
if (!title || !displayLabel) {
|
|
1909
|
+
return null;
|
|
1910
|
+
}
|
|
1911
|
+
const TitleFieldTemplate = (0, import_utils10.getTemplate)(
|
|
1912
|
+
"TitleFieldTemplate",
|
|
1913
|
+
registry,
|
|
1914
|
+
options
|
|
1915
|
+
);
|
|
1916
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1917
|
+
TitleFieldTemplate,
|
|
1918
|
+
{
|
|
1919
|
+
id: (0, import_utils10.titleId)(idSchema),
|
|
1920
|
+
title,
|
|
1921
|
+
required,
|
|
1922
|
+
schema,
|
|
1923
|
+
uiSchema,
|
|
1924
|
+
registry
|
|
1925
|
+
}
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
// src/components/templates/BaseInputTemplate.tsx
|
|
1930
|
+
var import_react7 = require("react");
|
|
1931
|
+
var import_utils11 = require("@rjsf/utils");
|
|
1932
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1933
|
+
function BaseInputTemplate(props) {
|
|
1934
|
+
const {
|
|
1935
|
+
id,
|
|
1936
|
+
name,
|
|
1937
|
+
// remove this from ...rest
|
|
1938
|
+
value,
|
|
1939
|
+
readonly,
|
|
1940
|
+
disabled,
|
|
1941
|
+
autofocus,
|
|
1942
|
+
onBlur,
|
|
1943
|
+
onFocus,
|
|
1944
|
+
onChange,
|
|
1945
|
+
onChangeOverride,
|
|
1946
|
+
options,
|
|
1947
|
+
schema,
|
|
1948
|
+
uiSchema,
|
|
1949
|
+
formContext,
|
|
1950
|
+
registry,
|
|
1951
|
+
rawErrors,
|
|
1952
|
+
type,
|
|
1953
|
+
hideLabel,
|
|
1954
|
+
// remove this from ...rest
|
|
1955
|
+
hideError,
|
|
1956
|
+
// remove this from ...rest
|
|
1957
|
+
...rest
|
|
1958
|
+
} = props;
|
|
1959
|
+
if (!id) {
|
|
1960
|
+
console.log("No id for", props);
|
|
1961
|
+
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
1962
|
+
}
|
|
1963
|
+
const inputProps = {
|
|
1964
|
+
...rest,
|
|
1965
|
+
...(0, import_utils11.getInputProps)(schema, type, options)
|
|
1966
|
+
};
|
|
1967
|
+
let inputValue;
|
|
1968
|
+
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
1969
|
+
inputValue = value || value === 0 ? value : "";
|
|
1970
|
+
} else {
|
|
1971
|
+
inputValue = value == null ? "" : value;
|
|
1972
|
+
}
|
|
1973
|
+
const _onChange = (0, import_react7.useCallback)(
|
|
1974
|
+
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
1975
|
+
[onChange, options]
|
|
1976
|
+
);
|
|
1977
|
+
const _onBlur = (0, import_react7.useCallback)(({ target: { value: value2 } }) => onBlur(id, value2), [onBlur, id]);
|
|
1978
|
+
const _onFocus = (0, import_react7.useCallback)(
|
|
1979
|
+
({ target: { value: value2 } }) => onFocus(id, value2),
|
|
1980
|
+
[onFocus, id]
|
|
1981
|
+
);
|
|
1982
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
|
|
1983
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1984
|
+
"input",
|
|
1985
|
+
{
|
|
1986
|
+
id,
|
|
1987
|
+
name: id,
|
|
1988
|
+
className: "form-control",
|
|
1989
|
+
readOnly: readonly,
|
|
1990
|
+
disabled,
|
|
1991
|
+
autoFocus: autofocus,
|
|
1992
|
+
value: inputValue,
|
|
1993
|
+
...inputProps,
|
|
1994
|
+
list: schema.examples ? (0, import_utils11.examplesId)(id) : void 0,
|
|
1995
|
+
onChange: onChangeOverride || _onChange,
|
|
1996
|
+
onBlur: _onBlur,
|
|
1997
|
+
onFocus: _onFocus,
|
|
1998
|
+
"aria-describedby": (0, import_utils11.ariaDescribedByIds)(id, !!schema.examples)
|
|
1999
|
+
}
|
|
2000
|
+
),
|
|
2001
|
+
Array.isArray(schema.examples) && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("datalist", { id: (0, import_utils11.examplesId)(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
|
|
2002
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: example }, example);
|
|
2003
|
+
}) }, `datalist_${id}`)
|
|
2004
|
+
] });
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// src/components/templates/ButtonTemplates/SubmitButton.tsx
|
|
2008
|
+
var import_utils12 = require("@rjsf/utils");
|
|
2009
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2010
|
+
function SubmitButton({ uiSchema }) {
|
|
2011
|
+
const { submitText, norender, props: submitButtonProps = {} } = (0, import_utils12.getSubmitButtonOptions)(uiSchema);
|
|
2012
|
+
if (norender) {
|
|
2013
|
+
return null;
|
|
2014
|
+
}
|
|
2015
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "submit", ...submitButtonProps, className: `btn btn-info ${submitButtonProps.className || ""}`, children: submitText }) });
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
// src/components/templates/ButtonTemplates/AddButton.tsx
|
|
2019
|
+
var import_utils14 = require("@rjsf/utils");
|
|
2020
|
+
|
|
2021
|
+
// src/components/templates/ButtonTemplates/IconButton.tsx
|
|
2022
|
+
var import_utils13 = require("@rjsf/utils");
|
|
2023
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2024
|
+
function IconButton(props) {
|
|
2025
|
+
const { iconType = "default", icon, className, uiSchema, registry, ...otherProps } = props;
|
|
2026
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "button", className: `btn btn-${iconType} ${className}`, ...otherProps, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("i", { className: `glyphicon glyphicon-${icon}` }) });
|
|
2027
|
+
}
|
|
2028
|
+
function CopyButton(props) {
|
|
2029
|
+
const {
|
|
2030
|
+
registry: { translateString }
|
|
2031
|
+
} = props;
|
|
2032
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2033
|
+
IconButton,
|
|
2034
|
+
{
|
|
2035
|
+
title: translateString(import_utils13.TranslatableString.CopyButton),
|
|
2036
|
+
className: "array-item-copy",
|
|
2037
|
+
...props,
|
|
2038
|
+
icon: "copy"
|
|
2039
|
+
}
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
function MoveDownButton(props) {
|
|
2043
|
+
const {
|
|
2044
|
+
registry: { translateString }
|
|
2045
|
+
} = props;
|
|
2046
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2047
|
+
IconButton,
|
|
2048
|
+
{
|
|
2049
|
+
title: translateString(import_utils13.TranslatableString.MoveDownButton),
|
|
2050
|
+
className: "array-item-move-down",
|
|
2051
|
+
...props,
|
|
2052
|
+
icon: "arrow-down"
|
|
2053
|
+
}
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
function MoveUpButton(props) {
|
|
2057
|
+
const {
|
|
2058
|
+
registry: { translateString }
|
|
2059
|
+
} = props;
|
|
2060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2061
|
+
IconButton,
|
|
2062
|
+
{
|
|
2063
|
+
title: translateString(import_utils13.TranslatableString.MoveUpButton),
|
|
2064
|
+
className: "array-item-move-up",
|
|
2065
|
+
...props,
|
|
2066
|
+
icon: "arrow-up"
|
|
2067
|
+
}
|
|
2068
|
+
);
|
|
2069
|
+
}
|
|
2070
|
+
function RemoveButton(props) {
|
|
2071
|
+
const {
|
|
2072
|
+
registry: { translateString }
|
|
2073
|
+
} = props;
|
|
2074
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2075
|
+
IconButton,
|
|
2076
|
+
{
|
|
2077
|
+
title: translateString(import_utils13.TranslatableString.RemoveButton),
|
|
2078
|
+
className: "array-item-remove",
|
|
2079
|
+
...props,
|
|
2080
|
+
iconType: "danger",
|
|
2081
|
+
icon: "remove"
|
|
2082
|
+
}
|
|
2083
|
+
);
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
// src/components/templates/ButtonTemplates/AddButton.tsx
|
|
2087
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2088
|
+
function AddButton({
|
|
2089
|
+
className,
|
|
2090
|
+
onClick,
|
|
2091
|
+
disabled,
|
|
2092
|
+
registry
|
|
2093
|
+
}) {
|
|
2094
|
+
const { translateString } = registry;
|
|
2095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "row", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: `col-xs-3 col-xs-offset-9 text-right ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
2096
|
+
IconButton,
|
|
2097
|
+
{
|
|
2098
|
+
iconType: "info",
|
|
2099
|
+
icon: "plus",
|
|
2100
|
+
className: "btn-add col-xs-12",
|
|
2101
|
+
title: translateString(import_utils14.TranslatableString.AddButton),
|
|
2102
|
+
onClick,
|
|
2103
|
+
disabled,
|
|
2104
|
+
registry
|
|
2105
|
+
}
|
|
2106
|
+
) }) });
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
// src/components/templates/ButtonTemplates/index.ts
|
|
2110
|
+
function buttonTemplates() {
|
|
2111
|
+
return {
|
|
2112
|
+
SubmitButton,
|
|
2113
|
+
AddButton,
|
|
2114
|
+
CopyButton,
|
|
2115
|
+
MoveDownButton,
|
|
2116
|
+
MoveUpButton,
|
|
2117
|
+
RemoveButton
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
var ButtonTemplates_default = buttonTemplates;
|
|
2121
|
+
|
|
2122
|
+
// src/components/templates/DescriptionField.tsx
|
|
2123
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2124
|
+
function DescriptionField(props) {
|
|
2125
|
+
const { id, description } = props;
|
|
2126
|
+
if (!description) {
|
|
2127
|
+
return null;
|
|
2128
|
+
}
|
|
2129
|
+
if (typeof description === "string") {
|
|
2130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("p", { id, className: "field-description", children: description });
|
|
2131
|
+
} else {
|
|
2132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { id, className: "field-description", children: description });
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
// src/components/templates/ErrorList.tsx
|
|
2137
|
+
var import_utils15 = require("@rjsf/utils");
|
|
2138
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2139
|
+
function ErrorList({
|
|
2140
|
+
errors,
|
|
2141
|
+
registry
|
|
2142
|
+
}) {
|
|
2143
|
+
const { translateString } = registry;
|
|
2144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "panel panel-danger errors", children: [
|
|
2145
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "panel-heading", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("h3", { className: "panel-title", children: translateString(import_utils15.TranslatableString.ErrorsLabel) }) }),
|
|
2146
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("ul", { className: "list-group", children: errors.map((error, i) => {
|
|
2147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("li", { className: "list-group-item text-danger", children: error.stack }, i);
|
|
2148
|
+
}) })
|
|
2149
|
+
] });
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
// src/components/templates/FieldTemplate/FieldTemplate.tsx
|
|
2153
|
+
var import_utils16 = require("@rjsf/utils");
|
|
2154
|
+
|
|
2155
|
+
// src/components/templates/FieldTemplate/Label.tsx
|
|
2156
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2157
|
+
var REQUIRED_FIELD_SYMBOL = "*";
|
|
2158
|
+
function Label(props) {
|
|
2159
|
+
const { label, required, id } = props;
|
|
2160
|
+
if (!label) {
|
|
2161
|
+
return null;
|
|
2162
|
+
}
|
|
2163
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("label", { className: "control-label", htmlFor: id, children: [
|
|
2164
|
+
label,
|
|
2165
|
+
required && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "required", children: REQUIRED_FIELD_SYMBOL })
|
|
2166
|
+
] });
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
// src/components/templates/FieldTemplate/FieldTemplate.tsx
|
|
2170
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2171
|
+
function FieldTemplate(props) {
|
|
2172
|
+
const { id, label, children, errors, help, description, hidden, required, displayLabel, registry, uiSchema } = props;
|
|
2173
|
+
const uiOptions = (0, import_utils16.getUiOptions)(uiSchema);
|
|
2174
|
+
const WrapIfAdditionalTemplate2 = (0, import_utils16.getTemplate)(
|
|
2175
|
+
"WrapIfAdditionalTemplate",
|
|
2176
|
+
registry,
|
|
2177
|
+
uiOptions
|
|
2178
|
+
);
|
|
2179
|
+
if (hidden) {
|
|
2180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "hidden", children });
|
|
2181
|
+
}
|
|
2182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(WrapIfAdditionalTemplate2, { ...props, children: [
|
|
2183
|
+
displayLabel && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Label, { label, required, id }),
|
|
2184
|
+
displayLabel && description ? description : null,
|
|
2185
|
+
children,
|
|
2186
|
+
errors,
|
|
2187
|
+
help
|
|
2188
|
+
] });
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/components/templates/FieldTemplate/index.ts
|
|
2192
|
+
var FieldTemplate_default = FieldTemplate;
|
|
2193
|
+
|
|
2194
|
+
// src/components/templates/FieldErrorTemplate.tsx
|
|
2195
|
+
var import_utils17 = require("@rjsf/utils");
|
|
2196
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2197
|
+
function FieldErrorTemplate(props) {
|
|
2198
|
+
const { errors = [], idSchema } = props;
|
|
2199
|
+
if (errors.length === 0) {
|
|
2200
|
+
return null;
|
|
2201
|
+
}
|
|
2202
|
+
const id = (0, import_utils17.errorId)(idSchema);
|
|
2203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ul", { id, className: "error-detail bs-callout bs-callout-info", children: errors.filter((elem) => !!elem).map((error, index) => {
|
|
2204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("li", { className: "text-danger", children: error }, index);
|
|
2205
|
+
}) }) });
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
// src/components/templates/FieldHelpTemplate.tsx
|
|
2209
|
+
var import_utils18 = require("@rjsf/utils");
|
|
2210
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2211
|
+
function FieldHelpTemplate(props) {
|
|
2212
|
+
const { idSchema, help } = props;
|
|
2213
|
+
if (!help) {
|
|
2214
|
+
return null;
|
|
2215
|
+
}
|
|
2216
|
+
const id = (0, import_utils18.helpId)(idSchema);
|
|
2217
|
+
if (typeof help === "string") {
|
|
2218
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { id, className: "help-block", children: help });
|
|
2219
|
+
}
|
|
2220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { id, className: "help-block", children: help });
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// src/components/templates/ObjectFieldTemplate.tsx
|
|
2224
|
+
var import_utils19 = require("@rjsf/utils");
|
|
2225
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2226
|
+
function ObjectFieldTemplate(props) {
|
|
2227
|
+
const {
|
|
2228
|
+
description,
|
|
2229
|
+
disabled,
|
|
2230
|
+
formData,
|
|
2231
|
+
idSchema,
|
|
2232
|
+
onAddClick,
|
|
2233
|
+
properties,
|
|
2234
|
+
readonly,
|
|
2235
|
+
registry,
|
|
2236
|
+
required,
|
|
2237
|
+
schema,
|
|
2238
|
+
title,
|
|
2239
|
+
uiSchema
|
|
2240
|
+
} = props;
|
|
2241
|
+
const options = (0, import_utils19.getUiOptions)(uiSchema);
|
|
2242
|
+
const TitleFieldTemplate = (0, import_utils19.getTemplate)("TitleFieldTemplate", registry, options);
|
|
2243
|
+
const DescriptionFieldTemplate = (0, import_utils19.getTemplate)(
|
|
2244
|
+
"DescriptionFieldTemplate",
|
|
2245
|
+
registry,
|
|
2246
|
+
options
|
|
2247
|
+
);
|
|
2248
|
+
const {
|
|
2249
|
+
ButtonTemplates: { AddButton: AddButton2 }
|
|
2250
|
+
} = registry.templates;
|
|
2251
|
+
return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("fieldset", { id: idSchema.$id, children: [
|
|
2252
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2253
|
+
TitleFieldTemplate,
|
|
2254
|
+
{
|
|
2255
|
+
id: (0, import_utils19.titleId)(idSchema),
|
|
2256
|
+
title,
|
|
2257
|
+
required,
|
|
2258
|
+
schema,
|
|
2259
|
+
uiSchema,
|
|
2260
|
+
registry
|
|
2261
|
+
}
|
|
2262
|
+
),
|
|
2263
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2264
|
+
DescriptionFieldTemplate,
|
|
2265
|
+
{
|
|
2266
|
+
id: (0, import_utils19.descriptionId)(idSchema),
|
|
2267
|
+
description,
|
|
2268
|
+
schema,
|
|
2269
|
+
uiSchema,
|
|
2270
|
+
registry
|
|
2271
|
+
}
|
|
2272
|
+
),
|
|
2273
|
+
properties.map((prop) => prop.content),
|
|
2274
|
+
(0, import_utils19.canExpand)(schema, uiSchema, formData) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
2275
|
+
AddButton2,
|
|
2276
|
+
{
|
|
2277
|
+
className: "object-property-expand",
|
|
2278
|
+
onClick: onAddClick(schema),
|
|
2279
|
+
disabled: disabled || readonly,
|
|
2280
|
+
uiSchema,
|
|
2281
|
+
registry
|
|
2282
|
+
}
|
|
2283
|
+
)
|
|
2284
|
+
] });
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// src/components/templates/TitleField.tsx
|
|
2288
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2289
|
+
var REQUIRED_FIELD_SYMBOL2 = "*";
|
|
2290
|
+
function TitleField(props) {
|
|
2291
|
+
const { id, title, required } = props;
|
|
2292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("legend", { id, children: [
|
|
2293
|
+
title,
|
|
2294
|
+
required && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "required", children: REQUIRED_FIELD_SYMBOL2 })
|
|
2295
|
+
] });
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
// src/components/templates/UnsupportedField.tsx
|
|
2299
|
+
var import_utils20 = require("@rjsf/utils");
|
|
2300
|
+
var import_markdown_to_jsx3 = __toESM(require("markdown-to-jsx"));
|
|
2301
|
+
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2302
|
+
function UnsupportedField(props) {
|
|
2303
|
+
const { schema, idSchema, reason, registry } = props;
|
|
2304
|
+
const { translateString } = registry;
|
|
2305
|
+
let translateEnum = import_utils20.TranslatableString.UnsupportedField;
|
|
2306
|
+
const translateParams = [];
|
|
2307
|
+
if (idSchema && idSchema.$id) {
|
|
2308
|
+
translateEnum = import_utils20.TranslatableString.UnsupportedFieldWithId;
|
|
2309
|
+
translateParams.push(idSchema.$id);
|
|
2310
|
+
}
|
|
2311
|
+
if (reason) {
|
|
2312
|
+
translateEnum = translateEnum === import_utils20.TranslatableString.UnsupportedField ? import_utils20.TranslatableString.UnsupportedFieldWithReason : import_utils20.TranslatableString.UnsupportedFieldWithIdAndReason;
|
|
2313
|
+
translateParams.push(reason);
|
|
2314
|
+
}
|
|
2315
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: "unsupported-field", children: [
|
|
2316
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_markdown_to_jsx3.default, { children: translateString(translateEnum, translateParams) }) }),
|
|
2317
|
+
schema && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("pre", { children: JSON.stringify(schema, null, 2) })
|
|
2318
|
+
] });
|
|
8
2319
|
}
|
|
2320
|
+
var UnsupportedField_default = UnsupportedField;
|
|
2321
|
+
|
|
2322
|
+
// src/components/templates/WrapIfAdditionalTemplate.tsx
|
|
2323
|
+
var import_utils21 = require("@rjsf/utils");
|
|
2324
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2325
|
+
function WrapIfAdditionalTemplate(props) {
|
|
2326
|
+
const {
|
|
2327
|
+
id,
|
|
2328
|
+
classNames,
|
|
2329
|
+
style,
|
|
2330
|
+
disabled,
|
|
2331
|
+
label,
|
|
2332
|
+
onKeyChange,
|
|
2333
|
+
onDropPropertyClick,
|
|
2334
|
+
readonly,
|
|
2335
|
+
required,
|
|
2336
|
+
schema,
|
|
2337
|
+
children,
|
|
2338
|
+
uiSchema,
|
|
2339
|
+
registry
|
|
2340
|
+
} = props;
|
|
2341
|
+
const { templates: templates2, translateString } = registry;
|
|
2342
|
+
const { RemoveButton: RemoveButton2 } = templates2.ButtonTemplates;
|
|
2343
|
+
const keyLabel = translateString(import_utils21.TranslatableString.KeyLabel, [label]);
|
|
2344
|
+
const additional = import_utils21.ADDITIONAL_PROPERTY_FLAG in schema;
|
|
2345
|
+
if (!additional) {
|
|
2346
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: classNames, style, children });
|
|
2347
|
+
}
|
|
2348
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: classNames, style, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "row", children: [
|
|
2349
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "col-xs-5 form-additional", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "form-group", children: [
|
|
2350
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Label, { label: keyLabel, required, id: `${id}-key` }),
|
|
2351
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2352
|
+
"input",
|
|
2353
|
+
{
|
|
2354
|
+
className: "form-control",
|
|
2355
|
+
type: "text",
|
|
2356
|
+
id: `${id}-key`,
|
|
2357
|
+
onBlur: (event) => onKeyChange(event.target.value),
|
|
2358
|
+
defaultValue: label
|
|
2359
|
+
}
|
|
2360
|
+
)
|
|
2361
|
+
] }) }),
|
|
2362
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "form-additional form-group col-xs-5", children }),
|
|
2363
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "col-xs-2", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
2364
|
+
RemoveButton2,
|
|
2365
|
+
{
|
|
2366
|
+
className: "array-item-remove btn-block",
|
|
2367
|
+
style: { border: "0" },
|
|
2368
|
+
disabled: disabled || readonly,
|
|
2369
|
+
onClick: onDropPropertyClick(label),
|
|
2370
|
+
uiSchema,
|
|
2371
|
+
registry
|
|
2372
|
+
}
|
|
2373
|
+
) })
|
|
2374
|
+
] }) });
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
// src/components/templates/index.ts
|
|
2378
|
+
function templates() {
|
|
2379
|
+
return {
|
|
2380
|
+
ArrayFieldDescriptionTemplate,
|
|
2381
|
+
ArrayFieldItemTemplate,
|
|
2382
|
+
ArrayFieldTemplate,
|
|
2383
|
+
ArrayFieldTitleTemplate,
|
|
2384
|
+
ButtonTemplates: ButtonTemplates_default(),
|
|
2385
|
+
BaseInputTemplate,
|
|
2386
|
+
DescriptionFieldTemplate: DescriptionField,
|
|
2387
|
+
ErrorListTemplate: ErrorList,
|
|
2388
|
+
FieldTemplate: FieldTemplate_default,
|
|
2389
|
+
FieldErrorTemplate,
|
|
2390
|
+
FieldHelpTemplate,
|
|
2391
|
+
ObjectFieldTemplate,
|
|
2392
|
+
TitleFieldTemplate: TitleField,
|
|
2393
|
+
UnsupportedFieldTemplate: UnsupportedField_default,
|
|
2394
|
+
WrapIfAdditionalTemplate
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
var templates_default = templates;
|
|
2398
|
+
|
|
2399
|
+
// src/components/widgets/AltDateWidget.tsx
|
|
2400
|
+
var import_react8 = require("react");
|
|
2401
|
+
var import_utils22 = require("@rjsf/utils");
|
|
2402
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2403
|
+
function rangeOptions(start, stop) {
|
|
2404
|
+
const options = [];
|
|
2405
|
+
for (let i = start; i <= stop; i++) {
|
|
2406
|
+
options.push({ value: i, label: (0, import_utils22.pad)(i, 2) });
|
|
2407
|
+
}
|
|
2408
|
+
return options;
|
|
2409
|
+
}
|
|
2410
|
+
function readyForChange(state) {
|
|
2411
|
+
return Object.values(state).every((value) => value !== -1);
|
|
2412
|
+
}
|
|
2413
|
+
function dateElementProps(state, time, yearsRange = [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2]) {
|
|
2414
|
+
const { year, month, day, hour, minute, second } = state;
|
|
2415
|
+
const data = [
|
|
2416
|
+
{
|
|
2417
|
+
type: "year",
|
|
2418
|
+
range: yearsRange,
|
|
2419
|
+
value: year
|
|
2420
|
+
},
|
|
2421
|
+
{ type: "month", range: [1, 12], value: month },
|
|
2422
|
+
{ type: "day", range: [1, 31], value: day }
|
|
2423
|
+
];
|
|
2424
|
+
if (time) {
|
|
2425
|
+
data.push(
|
|
2426
|
+
{ type: "hour", range: [0, 23], value: hour },
|
|
2427
|
+
{ type: "minute", range: [0, 59], value: minute },
|
|
2428
|
+
{ type: "second", range: [0, 59], value: second }
|
|
2429
|
+
);
|
|
2430
|
+
}
|
|
2431
|
+
return data;
|
|
2432
|
+
}
|
|
2433
|
+
function DateElement({
|
|
2434
|
+
type,
|
|
2435
|
+
range,
|
|
2436
|
+
value,
|
|
2437
|
+
select,
|
|
2438
|
+
rootId,
|
|
2439
|
+
name,
|
|
2440
|
+
disabled,
|
|
2441
|
+
readonly,
|
|
2442
|
+
autofocus,
|
|
2443
|
+
registry,
|
|
2444
|
+
onBlur,
|
|
2445
|
+
onFocus
|
|
2446
|
+
}) {
|
|
2447
|
+
const id = rootId + "_" + type;
|
|
2448
|
+
const { SelectWidget: SelectWidget2 } = registry.widgets;
|
|
2449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2450
|
+
SelectWidget2,
|
|
2451
|
+
{
|
|
2452
|
+
schema: { type: "integer" },
|
|
2453
|
+
id,
|
|
2454
|
+
name,
|
|
2455
|
+
className: "form-control",
|
|
2456
|
+
options: { enumOptions: rangeOptions(range[0], range[1]) },
|
|
2457
|
+
placeholder: type,
|
|
2458
|
+
value,
|
|
2459
|
+
disabled,
|
|
2460
|
+
readonly,
|
|
2461
|
+
autofocus,
|
|
2462
|
+
onChange: (value2) => select(type, value2),
|
|
2463
|
+
onBlur,
|
|
2464
|
+
onFocus,
|
|
2465
|
+
registry,
|
|
2466
|
+
label: "",
|
|
2467
|
+
"aria-describedby": (0, import_utils22.ariaDescribedByIds)(rootId)
|
|
2468
|
+
}
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
function AltDateWidget({
|
|
2472
|
+
time = false,
|
|
2473
|
+
disabled = false,
|
|
2474
|
+
readonly = false,
|
|
2475
|
+
autofocus = false,
|
|
2476
|
+
options,
|
|
2477
|
+
id,
|
|
2478
|
+
name,
|
|
2479
|
+
registry,
|
|
2480
|
+
onBlur,
|
|
2481
|
+
onFocus,
|
|
2482
|
+
onChange,
|
|
2483
|
+
value
|
|
2484
|
+
}) {
|
|
2485
|
+
const { translateString } = registry;
|
|
2486
|
+
const [lastValue, setLastValue] = (0, import_react8.useState)(value);
|
|
2487
|
+
const [state, setState] = (0, import_react8.useReducer)((state2, action) => {
|
|
2488
|
+
return { ...state2, ...action };
|
|
2489
|
+
}, (0, import_utils22.parseDateString)(value, time));
|
|
2490
|
+
(0, import_react8.useEffect)(() => {
|
|
2491
|
+
const stateValue = (0, import_utils22.toDateString)(state, time);
|
|
2492
|
+
if (readyForChange(state) && stateValue !== value) {
|
|
2493
|
+
onChange(stateValue);
|
|
2494
|
+
} else if (lastValue !== value) {
|
|
2495
|
+
setLastValue(value);
|
|
2496
|
+
setState((0, import_utils22.parseDateString)(value, time));
|
|
2497
|
+
}
|
|
2498
|
+
}, [time, value, onChange, state, lastValue]);
|
|
2499
|
+
const handleChange = (0, import_react8.useCallback)((property, value2) => {
|
|
2500
|
+
setState({ [property]: value2 });
|
|
2501
|
+
}, []);
|
|
2502
|
+
const handleSetNow = (0, import_react8.useCallback)(
|
|
2503
|
+
(event) => {
|
|
2504
|
+
event.preventDefault();
|
|
2505
|
+
if (disabled || readonly) {
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
const nextState = (0, import_utils22.parseDateString)((/* @__PURE__ */ new Date()).toJSON(), time);
|
|
2509
|
+
onChange((0, import_utils22.toDateString)(nextState, time));
|
|
2510
|
+
},
|
|
2511
|
+
[disabled, readonly, time]
|
|
2512
|
+
);
|
|
2513
|
+
const handleClear = (0, import_react8.useCallback)(
|
|
2514
|
+
(event) => {
|
|
2515
|
+
event.preventDefault();
|
|
2516
|
+
if (disabled || readonly) {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
onChange(void 0);
|
|
2520
|
+
},
|
|
2521
|
+
[disabled, readonly, onChange]
|
|
2522
|
+
);
|
|
2523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("ul", { className: "list-inline", children: [
|
|
2524
|
+
dateElementProps(state, time, options.yearsRange).map((elemProps, i) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2525
|
+
DateElement,
|
|
2526
|
+
{
|
|
2527
|
+
rootId: id,
|
|
2528
|
+
name,
|
|
2529
|
+
select: handleChange,
|
|
2530
|
+
...elemProps,
|
|
2531
|
+
disabled,
|
|
2532
|
+
readonly,
|
|
2533
|
+
registry,
|
|
2534
|
+
onBlur,
|
|
2535
|
+
onFocus,
|
|
2536
|
+
autofocus: autofocus && i === 0
|
|
2537
|
+
}
|
|
2538
|
+
) }, i)),
|
|
2539
|
+
(options.hideNowButton !== "undefined" ? !options.hideNowButton : true) && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: "#", className: "btn btn-info btn-now", onClick: handleSetNow, children: translateString(import_utils22.TranslatableString.NowLabel) }) }),
|
|
2540
|
+
(options.hideClearButton !== "undefined" ? !options.hideClearButton : true) && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: "#", className: "btn btn-warning btn-clear", onClick: handleClear, children: translateString(import_utils22.TranslatableString.ClearLabel) }) })
|
|
2541
|
+
] });
|
|
2542
|
+
}
|
|
2543
|
+
var AltDateWidget_default = AltDateWidget;
|
|
2544
|
+
|
|
2545
|
+
// src/components/widgets/AltDateTimeWidget.tsx
|
|
2546
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2547
|
+
function AltDateTimeWidget({
|
|
2548
|
+
time = true,
|
|
2549
|
+
...props
|
|
2550
|
+
}) {
|
|
2551
|
+
const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
|
|
2552
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(AltDateWidget2, { time, ...props });
|
|
2553
|
+
}
|
|
2554
|
+
var AltDateTimeWidget_default = AltDateTimeWidget;
|
|
2555
|
+
|
|
2556
|
+
// src/components/widgets/CheckboxWidget.tsx
|
|
2557
|
+
var import_react9 = require("react");
|
|
2558
|
+
var import_utils23 = require("@rjsf/utils");
|
|
2559
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2560
|
+
function CheckboxWidget({
|
|
2561
|
+
schema,
|
|
2562
|
+
uiSchema,
|
|
2563
|
+
options,
|
|
2564
|
+
id,
|
|
2565
|
+
value,
|
|
2566
|
+
disabled,
|
|
2567
|
+
readonly,
|
|
2568
|
+
label,
|
|
2569
|
+
hideLabel,
|
|
2570
|
+
autofocus = false,
|
|
2571
|
+
onBlur,
|
|
2572
|
+
onFocus,
|
|
2573
|
+
onChange,
|
|
2574
|
+
registry
|
|
2575
|
+
}) {
|
|
2576
|
+
const DescriptionFieldTemplate = (0, import_utils23.getTemplate)(
|
|
2577
|
+
"DescriptionFieldTemplate",
|
|
2578
|
+
registry,
|
|
2579
|
+
options
|
|
2580
|
+
);
|
|
2581
|
+
const required = (0, import_utils23.schemaRequiresTrueValue)(schema);
|
|
2582
|
+
const handleChange = (0, import_react9.useCallback)(
|
|
2583
|
+
(event) => onChange(event.target.checked),
|
|
2584
|
+
[onChange]
|
|
2585
|
+
);
|
|
2586
|
+
const handleBlur = (0, import_react9.useCallback)(
|
|
2587
|
+
(event) => onBlur(id, event.target.checked),
|
|
2588
|
+
[onBlur, id]
|
|
2589
|
+
);
|
|
2590
|
+
const handleFocus = (0, import_react9.useCallback)(
|
|
2591
|
+
(event) => onFocus(id, event.target.checked),
|
|
2592
|
+
[onFocus, id]
|
|
2593
|
+
);
|
|
2594
|
+
const description = options.description ?? schema.description;
|
|
2595
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: `checkbox ${disabled || readonly ? "disabled" : ""}`, children: [
|
|
2596
|
+
!hideLabel && !!description && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2597
|
+
DescriptionFieldTemplate,
|
|
2598
|
+
{
|
|
2599
|
+
id: (0, import_utils23.descriptionId)(id),
|
|
2600
|
+
description,
|
|
2601
|
+
schema,
|
|
2602
|
+
uiSchema,
|
|
2603
|
+
registry
|
|
2604
|
+
}
|
|
2605
|
+
),
|
|
2606
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("label", { children: [
|
|
2607
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2608
|
+
"input",
|
|
2609
|
+
{
|
|
2610
|
+
type: "checkbox",
|
|
2611
|
+
id,
|
|
2612
|
+
name: id,
|
|
2613
|
+
checked: typeof value === "undefined" ? false : value,
|
|
2614
|
+
required,
|
|
2615
|
+
disabled: disabled || readonly,
|
|
2616
|
+
autoFocus: autofocus,
|
|
2617
|
+
onChange: handleChange,
|
|
2618
|
+
onBlur: handleBlur,
|
|
2619
|
+
onFocus: handleFocus,
|
|
2620
|
+
"aria-describedby": (0, import_utils23.ariaDescribedByIds)(id)
|
|
2621
|
+
}
|
|
2622
|
+
),
|
|
2623
|
+
(0, import_utils23.labelValue)(/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: label }), hideLabel)
|
|
2624
|
+
] })
|
|
2625
|
+
] });
|
|
2626
|
+
}
|
|
2627
|
+
var CheckboxWidget_default = CheckboxWidget;
|
|
2628
|
+
|
|
2629
|
+
// src/components/widgets/CheckboxesWidget.tsx
|
|
2630
|
+
var import_react10 = require("react");
|
|
2631
|
+
var import_utils24 = require("@rjsf/utils");
|
|
2632
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
2633
|
+
function CheckboxesWidget({
|
|
2634
|
+
id,
|
|
2635
|
+
disabled,
|
|
2636
|
+
options: { inline = false, enumOptions, enumDisabled, emptyValue },
|
|
2637
|
+
value,
|
|
2638
|
+
autofocus = false,
|
|
2639
|
+
readonly,
|
|
2640
|
+
onChange,
|
|
2641
|
+
onBlur,
|
|
2642
|
+
onFocus
|
|
2643
|
+
}) {
|
|
2644
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
2645
|
+
const handleBlur = (0, import_react10.useCallback)(
|
|
2646
|
+
({ target: { value: value2 } }) => onBlur(id, (0, import_utils24.enumOptionsValueForIndex)(value2, enumOptions, emptyValue)),
|
|
2647
|
+
[onBlur, id]
|
|
2648
|
+
);
|
|
2649
|
+
const handleFocus = (0, import_react10.useCallback)(
|
|
2650
|
+
({ target: { value: value2 } }) => onFocus(id, (0, import_utils24.enumOptionsValueForIndex)(value2, enumOptions, emptyValue)),
|
|
2651
|
+
[onFocus, id]
|
|
2652
|
+
);
|
|
2653
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "checkboxes", id, children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
|
|
2654
|
+
const checked = (0, import_utils24.enumOptionsIsSelected)(option.value, checkboxesValues);
|
|
2655
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
2656
|
+
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
2657
|
+
const handleChange = (event) => {
|
|
2658
|
+
if (event.target.checked) {
|
|
2659
|
+
onChange((0, import_utils24.enumOptionsSelectValue)(index, checkboxesValues, enumOptions));
|
|
2660
|
+
} else {
|
|
2661
|
+
onChange((0, import_utils24.enumOptionsDeselectValue)(index, checkboxesValues, enumOptions));
|
|
2662
|
+
}
|
|
2663
|
+
};
|
|
2664
|
+
const checkbox = /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("span", { children: [
|
|
2665
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
2666
|
+
"input",
|
|
2667
|
+
{
|
|
2668
|
+
type: "checkbox",
|
|
2669
|
+
id: (0, import_utils24.optionId)(id, index),
|
|
2670
|
+
name: id,
|
|
2671
|
+
checked,
|
|
2672
|
+
value: String(index),
|
|
2673
|
+
disabled: disabled || itemDisabled || readonly,
|
|
2674
|
+
autoFocus: autofocus && index === 0,
|
|
2675
|
+
onChange: handleChange,
|
|
2676
|
+
onBlur: handleBlur,
|
|
2677
|
+
onFocus: handleFocus,
|
|
2678
|
+
"aria-describedby": (0, import_utils24.ariaDescribedByIds)(id)
|
|
2679
|
+
}
|
|
2680
|
+
),
|
|
2681
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { children: option.label })
|
|
2682
|
+
] });
|
|
2683
|
+
return inline ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("label", { className: `checkbox-inline ${disabledCls}`, children: checkbox }, index) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: `checkbox ${disabledCls}`, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("label", { children: checkbox }) }, index);
|
|
2684
|
+
}) });
|
|
2685
|
+
}
|
|
2686
|
+
var CheckboxesWidget_default = CheckboxesWidget;
|
|
2687
|
+
|
|
2688
|
+
// src/components/widgets/ColorWidget.tsx
|
|
2689
|
+
var import_utils25 = require("@rjsf/utils");
|
|
2690
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
2691
|
+
function ColorWidget(props) {
|
|
2692
|
+
const { disabled, readonly, options, registry } = props;
|
|
2693
|
+
const BaseInputTemplate2 = (0, import_utils25.getTemplate)("BaseInputTemplate", registry, options);
|
|
2694
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(BaseInputTemplate2, { type: "color", ...props, disabled: disabled || readonly });
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
// src/components/widgets/DateWidget.tsx
|
|
2698
|
+
var import_react11 = require("react");
|
|
2699
|
+
var import_utils26 = require("@rjsf/utils");
|
|
2700
|
+
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
2701
|
+
function DateWidget(props) {
|
|
2702
|
+
const { onChange, options, registry } = props;
|
|
2703
|
+
const BaseInputTemplate2 = (0, import_utils26.getTemplate)("BaseInputTemplate", registry, options);
|
|
2704
|
+
const handleChange = (0, import_react11.useCallback)((value) => onChange(value || void 0), [onChange]);
|
|
2705
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(BaseInputTemplate2, { type: "date", ...props, onChange: handleChange });
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// src/components/widgets/DateTimeWidget.tsx
|
|
2709
|
+
var import_utils27 = require("@rjsf/utils");
|
|
2710
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
2711
|
+
function DateTimeWidget(props) {
|
|
2712
|
+
const { onChange, value, options, registry } = props;
|
|
2713
|
+
const BaseInputTemplate2 = (0, import_utils27.getTemplate)("BaseInputTemplate", registry, options);
|
|
2714
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
2715
|
+
BaseInputTemplate2,
|
|
2716
|
+
{
|
|
2717
|
+
type: "datetime-local",
|
|
2718
|
+
...props,
|
|
2719
|
+
value: (0, import_utils27.utcToLocal)(value),
|
|
2720
|
+
onChange: (value2) => onChange((0, import_utils27.localToUTC)(value2))
|
|
2721
|
+
}
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
// src/components/widgets/EmailWidget.tsx
|
|
2726
|
+
var import_utils28 = require("@rjsf/utils");
|
|
2727
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
2728
|
+
function EmailWidget(props) {
|
|
2729
|
+
const { options, registry } = props;
|
|
2730
|
+
const BaseInputTemplate2 = (0, import_utils28.getTemplate)("BaseInputTemplate", registry, options);
|
|
2731
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BaseInputTemplate2, { type: "email", ...props });
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
// src/components/widgets/FileWidget.tsx
|
|
2735
|
+
var import_react12 = require("react");
|
|
2736
|
+
var import_utils29 = require("@rjsf/utils");
|
|
2737
|
+
var import_markdown_to_jsx4 = __toESM(require("markdown-to-jsx"));
|
|
2738
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
2739
|
+
function addNameToDataURL(dataURL, name) {
|
|
2740
|
+
if (dataURL === null) {
|
|
2741
|
+
return null;
|
|
2742
|
+
}
|
|
2743
|
+
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
2744
|
+
}
|
|
2745
|
+
function processFile(file) {
|
|
2746
|
+
const { name, size, type } = file;
|
|
2747
|
+
return new Promise((resolve, reject) => {
|
|
2748
|
+
const reader = new window.FileReader();
|
|
2749
|
+
reader.onerror = reject;
|
|
2750
|
+
reader.onload = (event) => {
|
|
2751
|
+
if (typeof event.target?.result === "string") {
|
|
2752
|
+
resolve({
|
|
2753
|
+
dataURL: addNameToDataURL(event.target.result, name),
|
|
2754
|
+
name,
|
|
2755
|
+
size,
|
|
2756
|
+
type
|
|
2757
|
+
});
|
|
2758
|
+
} else {
|
|
2759
|
+
resolve({
|
|
2760
|
+
dataURL: null,
|
|
2761
|
+
name,
|
|
2762
|
+
size,
|
|
2763
|
+
type
|
|
2764
|
+
});
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
reader.readAsDataURL(file);
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
function processFiles(files) {
|
|
2771
|
+
return Promise.all(Array.from(files).map(processFile));
|
|
2772
|
+
}
|
|
2773
|
+
function FileInfoPreview({
|
|
2774
|
+
fileInfo,
|
|
2775
|
+
registry
|
|
2776
|
+
}) {
|
|
2777
|
+
const { translateString } = registry;
|
|
2778
|
+
const { dataURL, type, name } = fileInfo;
|
|
2779
|
+
if (!dataURL) {
|
|
2780
|
+
return null;
|
|
2781
|
+
}
|
|
2782
|
+
if (type.indexOf("image") !== -1) {
|
|
2783
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("img", { src: dataURL, style: { maxWidth: "100%" }, className: "file-preview" });
|
|
2784
|
+
}
|
|
2785
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
|
2786
|
+
" ",
|
|
2787
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("a", { download: `preview-${name}`, href: dataURL, className: "file-download", children: translateString(import_utils29.TranslatableString.PreviewLabel) })
|
|
2788
|
+
] });
|
|
2789
|
+
}
|
|
2790
|
+
function FilesInfo({
|
|
2791
|
+
filesInfo,
|
|
2792
|
+
registry,
|
|
2793
|
+
preview
|
|
2794
|
+
}) {
|
|
2795
|
+
if (filesInfo.length === 0) {
|
|
2796
|
+
return null;
|
|
2797
|
+
}
|
|
2798
|
+
const { translateString } = registry;
|
|
2799
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("ul", { className: "file-info", children: filesInfo.map((fileInfo, key) => {
|
|
2800
|
+
const { name, size, type } = fileInfo;
|
|
2801
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("li", { children: [
|
|
2802
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_markdown_to_jsx4.default, { children: translateString(import_utils29.TranslatableString.FilesInfo, [name, type, String(size)]) }),
|
|
2803
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FileInfoPreview, { fileInfo, registry })
|
|
2804
|
+
] }, key);
|
|
2805
|
+
}) });
|
|
2806
|
+
}
|
|
2807
|
+
function extractFileInfo(dataURLs) {
|
|
2808
|
+
return dataURLs.filter((dataURL) => dataURL).map((dataURL) => {
|
|
2809
|
+
const { blob, name } = (0, import_utils29.dataURItoBlob)(dataURL);
|
|
2810
|
+
return {
|
|
2811
|
+
dataURL,
|
|
2812
|
+
name,
|
|
2813
|
+
size: blob.size,
|
|
2814
|
+
type: blob.type
|
|
2815
|
+
};
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
function FileWidget(props) {
|
|
2819
|
+
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
2820
|
+
const BaseInputTemplate2 = (0, import_utils29.getTemplate)("BaseInputTemplate", registry, options);
|
|
2821
|
+
const [filesInfo, setFilesInfo] = (0, import_react12.useState)(
|
|
2822
|
+
Array.isArray(value) ? extractFileInfo(value) : extractFileInfo([value])
|
|
2823
|
+
);
|
|
2824
|
+
const handleChange = (0, import_react12.useCallback)(
|
|
2825
|
+
(event) => {
|
|
2826
|
+
if (!event.target.files) {
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
processFiles(event.target.files).then((filesInfoEvent) => {
|
|
2830
|
+
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL);
|
|
2831
|
+
if (multiple) {
|
|
2832
|
+
setFilesInfo(filesInfo.concat(filesInfoEvent[0]));
|
|
2833
|
+
onChange(value.concat(newValue[0]));
|
|
2834
|
+
} else {
|
|
2835
|
+
setFilesInfo(filesInfoEvent);
|
|
2836
|
+
onChange(newValue[0]);
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
},
|
|
2840
|
+
[multiple, value, filesInfo, onChange]
|
|
2841
|
+
);
|
|
2842
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { children: [
|
|
2843
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
2844
|
+
BaseInputTemplate2,
|
|
2845
|
+
{
|
|
2846
|
+
...props,
|
|
2847
|
+
disabled: disabled || readonly,
|
|
2848
|
+
type: "file",
|
|
2849
|
+
required: value ? false : required,
|
|
2850
|
+
onChangeOverride: handleChange,
|
|
2851
|
+
value: "",
|
|
2852
|
+
accept: options.accept ? String(options.accept) : void 0
|
|
2853
|
+
}
|
|
2854
|
+
),
|
|
2855
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FilesInfo, { filesInfo, registry, preview: options.filePreview })
|
|
2856
|
+
] });
|
|
2857
|
+
}
|
|
2858
|
+
var FileWidget_default = FileWidget;
|
|
2859
|
+
|
|
2860
|
+
// src/components/widgets/HiddenWidget.tsx
|
|
2861
|
+
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
2862
|
+
function HiddenWidget({
|
|
2863
|
+
id,
|
|
2864
|
+
value
|
|
2865
|
+
}) {
|
|
2866
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("input", { type: "hidden", id, name: id, value: typeof value === "undefined" ? "" : value });
|
|
2867
|
+
}
|
|
2868
|
+
var HiddenWidget_default = HiddenWidget;
|
|
2869
|
+
|
|
2870
|
+
// src/components/widgets/PasswordWidget.tsx
|
|
2871
|
+
var import_utils30 = require("@rjsf/utils");
|
|
2872
|
+
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
2873
|
+
function PasswordWidget(props) {
|
|
2874
|
+
const { options, registry } = props;
|
|
2875
|
+
const BaseInputTemplate2 = (0, import_utils30.getTemplate)("BaseInputTemplate", registry, options);
|
|
2876
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(BaseInputTemplate2, { type: "password", ...props });
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
// src/components/widgets/RadioWidget.tsx
|
|
2880
|
+
var import_react13 = require("react");
|
|
2881
|
+
var import_utils31 = require("@rjsf/utils");
|
|
2882
|
+
var import_jsx_runtime37 = require("react/jsx-runtime");
|
|
2883
|
+
function RadioWidget({
|
|
2884
|
+
options,
|
|
2885
|
+
value,
|
|
2886
|
+
required,
|
|
2887
|
+
disabled,
|
|
2888
|
+
readonly,
|
|
2889
|
+
autofocus = false,
|
|
2890
|
+
onBlur,
|
|
2891
|
+
onFocus,
|
|
2892
|
+
onChange,
|
|
2893
|
+
id
|
|
2894
|
+
}) {
|
|
2895
|
+
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
2896
|
+
const handleBlur = (0, import_react13.useCallback)(
|
|
2897
|
+
({ target: { value: value2 } }) => onBlur(id, (0, import_utils31.enumOptionsValueForIndex)(value2, enumOptions, emptyValue)),
|
|
2898
|
+
[onBlur, id]
|
|
2899
|
+
);
|
|
2900
|
+
const handleFocus = (0, import_react13.useCallback)(
|
|
2901
|
+
({ target: { value: value2 } }) => onFocus(id, (0, import_utils31.enumOptionsValueForIndex)(value2, enumOptions, emptyValue)),
|
|
2902
|
+
[onFocus, id]
|
|
2903
|
+
);
|
|
2904
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "field-radio-group", id, children: Array.isArray(enumOptions) && enumOptions.map((option, i) => {
|
|
2905
|
+
const checked = (0, import_utils31.enumOptionsIsSelected)(option.value, value);
|
|
2906
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
2907
|
+
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
2908
|
+
const handleChange = () => onChange(option.value);
|
|
2909
|
+
const radio = /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("span", { children: [
|
|
2910
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
|
|
2911
|
+
"input",
|
|
2912
|
+
{
|
|
2913
|
+
type: "radio",
|
|
2914
|
+
id: (0, import_utils31.optionId)(id, i),
|
|
2915
|
+
checked,
|
|
2916
|
+
name: id,
|
|
2917
|
+
required,
|
|
2918
|
+
value: String(i),
|
|
2919
|
+
disabled: disabled || itemDisabled || readonly,
|
|
2920
|
+
autoFocus: autofocus && i === 0,
|
|
2921
|
+
onChange: handleChange,
|
|
2922
|
+
onBlur: handleBlur,
|
|
2923
|
+
onFocus: handleFocus,
|
|
2924
|
+
"aria-describedby": (0, import_utils31.ariaDescribedByIds)(id)
|
|
2925
|
+
}
|
|
2926
|
+
),
|
|
2927
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { children: option.label })
|
|
2928
|
+
] });
|
|
2929
|
+
return inline ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("label", { className: `radio-inline ${disabledCls}`, children: radio }, i) : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: `radio ${disabledCls}`, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("label", { children: radio }) }, i);
|
|
2930
|
+
}) });
|
|
2931
|
+
}
|
|
2932
|
+
var RadioWidget_default = RadioWidget;
|
|
2933
|
+
|
|
2934
|
+
// src/components/widgets/RangeWidget.tsx
|
|
2935
|
+
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
2936
|
+
function RangeWidget(props) {
|
|
2937
|
+
const {
|
|
2938
|
+
value,
|
|
2939
|
+
registry: {
|
|
2940
|
+
templates: { BaseInputTemplate: BaseInputTemplate2 }
|
|
2941
|
+
}
|
|
2942
|
+
} = props;
|
|
2943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: "field-range-wrapper", children: [
|
|
2944
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)(BaseInputTemplate2, { type: "range", ...props }),
|
|
2945
|
+
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "range-view", children: value })
|
|
2946
|
+
] });
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
// src/components/widgets/SelectWidget.tsx
|
|
2950
|
+
var import_react14 = require("react");
|
|
2951
|
+
var import_utils32 = require("@rjsf/utils");
|
|
2952
|
+
var import_jsx_runtime39 = require("react/jsx-runtime");
|
|
2953
|
+
function getValue(event, multiple) {
|
|
2954
|
+
if (multiple) {
|
|
2955
|
+
return Array.from(event.target.options).slice().filter((o) => o.selected).map((o) => o.value);
|
|
2956
|
+
}
|
|
2957
|
+
return event.target.value;
|
|
2958
|
+
}
|
|
2959
|
+
function SelectWidget({
|
|
2960
|
+
schema,
|
|
2961
|
+
id,
|
|
2962
|
+
options,
|
|
2963
|
+
value,
|
|
2964
|
+
required,
|
|
2965
|
+
disabled,
|
|
2966
|
+
readonly,
|
|
2967
|
+
multiple = false,
|
|
2968
|
+
autofocus = false,
|
|
2969
|
+
onChange,
|
|
2970
|
+
onBlur,
|
|
2971
|
+
onFocus,
|
|
2972
|
+
placeholder
|
|
2973
|
+
}) {
|
|
2974
|
+
const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
|
|
2975
|
+
const emptyValue = multiple ? [] : "";
|
|
2976
|
+
const handleFocus = (0, import_react14.useCallback)(
|
|
2977
|
+
(event) => {
|
|
2978
|
+
const newValue = getValue(event, multiple);
|
|
2979
|
+
return onFocus(id, (0, import_utils32.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
2980
|
+
},
|
|
2981
|
+
[onFocus, id, schema, multiple, options]
|
|
2982
|
+
);
|
|
2983
|
+
const handleBlur = (0, import_react14.useCallback)(
|
|
2984
|
+
(event) => {
|
|
2985
|
+
const newValue = getValue(event, multiple);
|
|
2986
|
+
return onBlur(id, (0, import_utils32.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
2987
|
+
},
|
|
2988
|
+
[onBlur, id, schema, multiple, options]
|
|
2989
|
+
);
|
|
2990
|
+
const handleChange = (0, import_react14.useCallback)(
|
|
2991
|
+
(event) => {
|
|
2992
|
+
const newValue = getValue(event, multiple);
|
|
2993
|
+
return onChange((0, import_utils32.enumOptionsValueForIndex)(newValue, enumOptions, optEmptyVal));
|
|
2994
|
+
},
|
|
2995
|
+
[onChange, schema, multiple, options]
|
|
2996
|
+
);
|
|
2997
|
+
const selectedIndexes = (0, import_utils32.enumOptionsIndexForValue)(value, enumOptions, multiple);
|
|
2998
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
|
|
2999
|
+
"select",
|
|
3000
|
+
{
|
|
3001
|
+
id,
|
|
3002
|
+
name: id,
|
|
3003
|
+
multiple,
|
|
3004
|
+
className: "form-control",
|
|
3005
|
+
value: typeof selectedIndexes === "undefined" ? emptyValue : selectedIndexes,
|
|
3006
|
+
required,
|
|
3007
|
+
disabled: disabled || readonly,
|
|
3008
|
+
autoFocus: autofocus,
|
|
3009
|
+
onBlur: handleBlur,
|
|
3010
|
+
onFocus: handleFocus,
|
|
3011
|
+
onChange: handleChange,
|
|
3012
|
+
"aria-describedby": (0, import_utils32.ariaDescribedByIds)(id),
|
|
3013
|
+
children: [
|
|
3014
|
+
!multiple && schema.default === void 0 && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("option", { value: "", children: placeholder }),
|
|
3015
|
+
Array.isArray(enumOptions) && enumOptions.map(({ value: value2, label }, i) => {
|
|
3016
|
+
const disabled2 = enumDisabled && enumDisabled.indexOf(value2) !== -1;
|
|
3017
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("option", { value: String(i), disabled: disabled2, children: label }, i);
|
|
3018
|
+
})
|
|
3019
|
+
]
|
|
3020
|
+
}
|
|
3021
|
+
);
|
|
3022
|
+
}
|
|
3023
|
+
var SelectWidget_default = SelectWidget;
|
|
3024
|
+
|
|
3025
|
+
// src/components/widgets/TextareaWidget.tsx
|
|
3026
|
+
var import_react15 = require("react");
|
|
3027
|
+
var import_utils33 = require("@rjsf/utils");
|
|
3028
|
+
var import_jsx_runtime40 = require("react/jsx-runtime");
|
|
3029
|
+
function TextareaWidget({
|
|
3030
|
+
id,
|
|
3031
|
+
options = {},
|
|
3032
|
+
placeholder,
|
|
3033
|
+
value,
|
|
3034
|
+
required,
|
|
3035
|
+
disabled,
|
|
3036
|
+
readonly,
|
|
3037
|
+
autofocus = false,
|
|
3038
|
+
onChange,
|
|
3039
|
+
onBlur,
|
|
3040
|
+
onFocus
|
|
3041
|
+
}) {
|
|
3042
|
+
const handleChange = (0, import_react15.useCallback)(
|
|
3043
|
+
({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2),
|
|
3044
|
+
[onChange, options.emptyValue]
|
|
3045
|
+
);
|
|
3046
|
+
const handleBlur = (0, import_react15.useCallback)(
|
|
3047
|
+
({ target: { value: value2 } }) => onBlur(id, value2),
|
|
3048
|
+
[onBlur, id]
|
|
3049
|
+
);
|
|
3050
|
+
const handleFocus = (0, import_react15.useCallback)(
|
|
3051
|
+
({ target: { value: value2 } }) => onFocus(id, value2),
|
|
3052
|
+
[id, onFocus]
|
|
3053
|
+
);
|
|
3054
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
3055
|
+
"textarea",
|
|
3056
|
+
{
|
|
3057
|
+
id,
|
|
3058
|
+
name: id,
|
|
3059
|
+
className: "form-control",
|
|
3060
|
+
value: value ? value : "",
|
|
3061
|
+
placeholder,
|
|
3062
|
+
required,
|
|
3063
|
+
disabled,
|
|
3064
|
+
readOnly: readonly,
|
|
3065
|
+
autoFocus: autofocus,
|
|
3066
|
+
rows: options.rows,
|
|
3067
|
+
onBlur: handleBlur,
|
|
3068
|
+
onFocus: handleFocus,
|
|
3069
|
+
onChange: handleChange,
|
|
3070
|
+
"aria-describedby": (0, import_utils33.ariaDescribedByIds)(id)
|
|
3071
|
+
}
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
TextareaWidget.defaultProps = {
|
|
3075
|
+
autofocus: false,
|
|
3076
|
+
options: {}
|
|
3077
|
+
};
|
|
3078
|
+
var TextareaWidget_default = TextareaWidget;
|
|
3079
|
+
|
|
3080
|
+
// src/components/widgets/TextWidget.tsx
|
|
3081
|
+
var import_utils34 = require("@rjsf/utils");
|
|
3082
|
+
var import_jsx_runtime41 = require("react/jsx-runtime");
|
|
3083
|
+
function TextWidget(props) {
|
|
3084
|
+
const { options, registry } = props;
|
|
3085
|
+
const BaseInputTemplate2 = (0, import_utils34.getTemplate)("BaseInputTemplate", registry, options);
|
|
3086
|
+
return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(BaseInputTemplate2, { ...props });
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3089
|
+
// src/components/widgets/TimeWidget.tsx
|
|
3090
|
+
var import_react16 = require("react");
|
|
3091
|
+
var import_utils35 = require("@rjsf/utils");
|
|
3092
|
+
var import_jsx_runtime42 = require("react/jsx-runtime");
|
|
3093
|
+
function TimeWidget(props) {
|
|
3094
|
+
const { onChange, options, registry } = props;
|
|
3095
|
+
const BaseInputTemplate2 = (0, import_utils35.getTemplate)("BaseInputTemplate", registry, options);
|
|
3096
|
+
const handleChange = (0, import_react16.useCallback)((value) => onChange(value ? `${value}:00` : void 0), [onChange]);
|
|
3097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(BaseInputTemplate2, { type: "time", ...props, onChange: handleChange });
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
// src/components/widgets/URLWidget.tsx
|
|
3101
|
+
var import_utils36 = require("@rjsf/utils");
|
|
3102
|
+
var import_jsx_runtime43 = require("react/jsx-runtime");
|
|
3103
|
+
function URLWidget(props) {
|
|
3104
|
+
const { options, registry } = props;
|
|
3105
|
+
const BaseInputTemplate2 = (0, import_utils36.getTemplate)("BaseInputTemplate", registry, options);
|
|
3106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(BaseInputTemplate2, { type: "url", ...props });
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
// src/components/widgets/UpDownWidget.tsx
|
|
3110
|
+
var import_utils37 = require("@rjsf/utils");
|
|
3111
|
+
var import_jsx_runtime44 = require("react/jsx-runtime");
|
|
3112
|
+
function UpDownWidget(props) {
|
|
3113
|
+
const { options, registry } = props;
|
|
3114
|
+
const BaseInputTemplate2 = (0, import_utils37.getTemplate)("BaseInputTemplate", registry, options);
|
|
3115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(BaseInputTemplate2, { type: "number", ...props });
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
// src/components/widgets/index.ts
|
|
3119
|
+
function widgets() {
|
|
3120
|
+
return {
|
|
3121
|
+
AltDateWidget: AltDateWidget_default,
|
|
3122
|
+
AltDateTimeWidget: AltDateTimeWidget_default,
|
|
3123
|
+
CheckboxWidget: CheckboxWidget_default,
|
|
3124
|
+
CheckboxesWidget: CheckboxesWidget_default,
|
|
3125
|
+
ColorWidget,
|
|
3126
|
+
DateWidget,
|
|
3127
|
+
DateTimeWidget,
|
|
3128
|
+
EmailWidget,
|
|
3129
|
+
FileWidget: FileWidget_default,
|
|
3130
|
+
HiddenWidget: HiddenWidget_default,
|
|
3131
|
+
PasswordWidget,
|
|
3132
|
+
RadioWidget: RadioWidget_default,
|
|
3133
|
+
RangeWidget,
|
|
3134
|
+
SelectWidget: SelectWidget_default,
|
|
3135
|
+
TextWidget,
|
|
3136
|
+
TextareaWidget: TextareaWidget_default,
|
|
3137
|
+
TimeWidget,
|
|
3138
|
+
UpDownWidget,
|
|
3139
|
+
URLWidget
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
var widgets_default = widgets;
|
|
3143
|
+
|
|
3144
|
+
// src/getDefaultRegistry.ts
|
|
3145
|
+
function getDefaultRegistry() {
|
|
3146
|
+
return {
|
|
3147
|
+
fields: fields_default(),
|
|
3148
|
+
templates: templates_default(),
|
|
3149
|
+
widgets: widgets_default(),
|
|
3150
|
+
rootSchema: {},
|
|
3151
|
+
formContext: {},
|
|
3152
|
+
translateString: import_utils38.englishStringTranslator
|
|
3153
|
+
};
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
// src/components/Form.tsx
|
|
3157
|
+
var import_jsx_runtime45 = require("react/jsx-runtime");
|
|
3158
|
+
var Form = class extends import_react17.Component {
|
|
3159
|
+
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
|
|
3160
|
+
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
|
|
3161
|
+
* state construction.
|
|
3162
|
+
*
|
|
3163
|
+
* @param props - The initial props for the `Form`
|
|
3164
|
+
*/
|
|
3165
|
+
constructor(props) {
|
|
3166
|
+
super(props);
|
|
3167
|
+
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
3168
|
+
*
|
|
3169
|
+
* @param formData - The data for the `Form`
|
|
3170
|
+
* @param fields - The fields to keep while filtering
|
|
3171
|
+
*/
|
|
3172
|
+
this.getUsedFormData = (formData, fields2) => {
|
|
3173
|
+
if (fields2.length === 0 && typeof formData !== "object") {
|
|
3174
|
+
return formData;
|
|
3175
|
+
}
|
|
3176
|
+
const data = (0, import_pick.default)(formData, fields2);
|
|
3177
|
+
if (Array.isArray(formData)) {
|
|
3178
|
+
return Object.keys(data).map((key) => data[key]);
|
|
3179
|
+
}
|
|
3180
|
+
return data;
|
|
3181
|
+
};
|
|
3182
|
+
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
|
|
3183
|
+
*
|
|
3184
|
+
* @param pathSchema - The `PathSchema` object for the form
|
|
3185
|
+
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
3186
|
+
*/
|
|
3187
|
+
this.getFieldNames = (pathSchema, formData) => {
|
|
3188
|
+
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
3189
|
+
Object.keys(_obj).forEach((key) => {
|
|
3190
|
+
if (typeof _obj[key] === "object") {
|
|
3191
|
+
const newPaths = paths.map((path) => [...path, key]);
|
|
3192
|
+
if (_obj[key][import_utils39.RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][import_utils39.NAME_KEY] !== "") {
|
|
3193
|
+
acc.push(_obj[key][import_utils39.NAME_KEY]);
|
|
3194
|
+
} else {
|
|
3195
|
+
getAllPaths(_obj[key], acc, newPaths);
|
|
3196
|
+
}
|
|
3197
|
+
} else if (key === import_utils39.NAME_KEY && _obj[key] !== "") {
|
|
3198
|
+
paths.forEach((path) => {
|
|
3199
|
+
const formValue = (0, import_get4.default)(formData, path);
|
|
3200
|
+
if (typeof formValue !== "object" || (0, import_isEmpty2.default)(formValue)) {
|
|
3201
|
+
acc.push(path);
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
}
|
|
3205
|
+
});
|
|
3206
|
+
return acc;
|
|
3207
|
+
};
|
|
3208
|
+
return getAllPaths(pathSchema);
|
|
3209
|
+
};
|
|
3210
|
+
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
3211
|
+
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
3212
|
+
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filterer to remove any extra data not
|
|
3213
|
+
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
3214
|
+
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
3215
|
+
* callback will be called if specified with the updated state.
|
|
3216
|
+
*
|
|
3217
|
+
* @param formData - The new form data from a change to a field
|
|
3218
|
+
* @param newErrorSchema - The new `ErrorSchema` based on the field change
|
|
3219
|
+
* @param id - The id of the field that caused the change
|
|
3220
|
+
*/
|
|
3221
|
+
this.onChange = (formData, newErrorSchema, id) => {
|
|
3222
|
+
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
|
|
3223
|
+
const { schemaUtils, schema } = this.state;
|
|
3224
|
+
if ((0, import_utils39.isObject)(formData) || Array.isArray(formData)) {
|
|
3225
|
+
const newState = this.getStateFromProps(this.props, formData);
|
|
3226
|
+
formData = newState.formData;
|
|
3227
|
+
}
|
|
3228
|
+
const mustValidate = !noValidate && liveValidate;
|
|
3229
|
+
let state = { formData, schema };
|
|
3230
|
+
let newFormData = formData;
|
|
3231
|
+
if (omitExtraData === true && liveOmit === true) {
|
|
3232
|
+
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3233
|
+
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
3234
|
+
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
3235
|
+
newFormData = this.getUsedFormData(formData, fieldNames);
|
|
3236
|
+
state = {
|
|
3237
|
+
formData: newFormData
|
|
3238
|
+
};
|
|
3239
|
+
}
|
|
3240
|
+
if (mustValidate) {
|
|
3241
|
+
const schemaValidation = this.validate(newFormData);
|
|
3242
|
+
let errors = schemaValidation.errors;
|
|
3243
|
+
let errorSchema = schemaValidation.errorSchema;
|
|
3244
|
+
const schemaValidationErrors = errors;
|
|
3245
|
+
const schemaValidationErrorSchema = errorSchema;
|
|
3246
|
+
if (extraErrors) {
|
|
3247
|
+
const merged = (0, import_utils39.validationDataMerge)(schemaValidation, extraErrors);
|
|
3248
|
+
errorSchema = merged.errorSchema;
|
|
3249
|
+
errors = merged.errors;
|
|
3250
|
+
}
|
|
3251
|
+
state = {
|
|
3252
|
+
formData: newFormData,
|
|
3253
|
+
errors,
|
|
3254
|
+
errorSchema,
|
|
3255
|
+
schemaValidationErrors,
|
|
3256
|
+
schemaValidationErrorSchema
|
|
3257
|
+
};
|
|
3258
|
+
} else if (!noValidate && newErrorSchema) {
|
|
3259
|
+
const errorSchema = extraErrors ? (0, import_utils39.mergeObjects)(newErrorSchema, extraErrors, "preventDuplicates") : newErrorSchema;
|
|
3260
|
+
state = {
|
|
3261
|
+
formData: newFormData,
|
|
3262
|
+
errorSchema,
|
|
3263
|
+
errors: (0, import_utils39.toErrorList)(errorSchema)
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
this.setState(state, () => onChange && onChange({ ...this.state, ...state }, id));
|
|
3267
|
+
};
|
|
3268
|
+
/**
|
|
3269
|
+
* Callback function to handle reset form data.
|
|
3270
|
+
* - Reset all fields with default values.
|
|
3271
|
+
* - Reset validations and errors
|
|
3272
|
+
*
|
|
3273
|
+
*/
|
|
3274
|
+
this.reset = () => {
|
|
3275
|
+
const { onChange } = this.props;
|
|
3276
|
+
const newState = this.getStateFromProps(this.props, void 0);
|
|
3277
|
+
const newFormData = newState.formData;
|
|
3278
|
+
const state = {
|
|
3279
|
+
formData: newFormData,
|
|
3280
|
+
errorSchema: {},
|
|
3281
|
+
errors: [],
|
|
3282
|
+
schemaValidationErrors: [],
|
|
3283
|
+
schemaValidationErrorSchema: {}
|
|
3284
|
+
};
|
|
3285
|
+
this.setState(state, () => onChange && onChange({ ...this.state, ...state }));
|
|
3286
|
+
};
|
|
3287
|
+
/** Callback function to handle when a field on the form is blurred. Calls the `onBlur` callback for the `Form` if it
|
|
3288
|
+
* was provided.
|
|
3289
|
+
*
|
|
3290
|
+
* @param id - The unique `id` of the field that was blurred
|
|
3291
|
+
* @param data - The data associated with the field that was blurred
|
|
3292
|
+
*/
|
|
3293
|
+
this.onBlur = (id, data) => {
|
|
3294
|
+
const { onBlur } = this.props;
|
|
3295
|
+
if (onBlur) {
|
|
3296
|
+
onBlur(id, data);
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
/** Callback function to handle when a field on the form is focused. Calls the `onFocus` callback for the `Form` if it
|
|
3300
|
+
* was provided.
|
|
3301
|
+
*
|
|
3302
|
+
* @param id - The unique `id` of the field that was focused
|
|
3303
|
+
* @param data - The data associated with the field that was focused
|
|
3304
|
+
*/
|
|
3305
|
+
this.onFocus = (id, data) => {
|
|
3306
|
+
const { onFocus } = this.props;
|
|
3307
|
+
if (onFocus) {
|
|
3308
|
+
onFocus(id, data);
|
|
3309
|
+
}
|
|
3310
|
+
};
|
|
3311
|
+
/** Callback function to handle when the form is submitted. First, it prevents the default event behavior. Nothing
|
|
3312
|
+
* happens if the target and currentTarget of the event are not the same. It will omit any extra data in the
|
|
3313
|
+
* `formData` in the state if `omitExtraData` is true. It will validate the resulting `formData`, reporting errors
|
|
3314
|
+
* via the `onError()` callback unless validation is disabled. Finally, it will add in any `extraErrors` and then call
|
|
3315
|
+
* back the `onSubmit` callback if it was provided.
|
|
3316
|
+
*
|
|
3317
|
+
* @param event - The submit HTML form event
|
|
3318
|
+
*/
|
|
3319
|
+
this.onSubmit = (event) => {
|
|
3320
|
+
event.preventDefault();
|
|
3321
|
+
if (event.target !== event.currentTarget) {
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
event.persist();
|
|
3325
|
+
const { omitExtraData, extraErrors, noValidate, onSubmit } = this.props;
|
|
3326
|
+
let { formData: newFormData } = this.state;
|
|
3327
|
+
const { schema, schemaUtils } = this.state;
|
|
3328
|
+
if (omitExtraData === true) {
|
|
3329
|
+
const retrievedSchema = schemaUtils.retrieveSchema(schema, newFormData);
|
|
3330
|
+
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", newFormData);
|
|
3331
|
+
const fieldNames = this.getFieldNames(pathSchema, newFormData);
|
|
3332
|
+
newFormData = this.getUsedFormData(newFormData, fieldNames);
|
|
3333
|
+
}
|
|
3334
|
+
if (noValidate || this.validateForm()) {
|
|
3335
|
+
const errorSchema = extraErrors || {};
|
|
3336
|
+
const errors = extraErrors ? (0, import_utils39.toErrorList)(extraErrors) : [];
|
|
3337
|
+
this.setState(
|
|
3338
|
+
{
|
|
3339
|
+
formData: newFormData,
|
|
3340
|
+
errors,
|
|
3341
|
+
errorSchema,
|
|
3342
|
+
schemaValidationErrors: [],
|
|
3343
|
+
schemaValidationErrorSchema: {}
|
|
3344
|
+
},
|
|
3345
|
+
() => {
|
|
3346
|
+
if (onSubmit) {
|
|
3347
|
+
onSubmit({ ...this.state, formData: newFormData, status: "submitted" }, event);
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
);
|
|
3351
|
+
}
|
|
3352
|
+
};
|
|
3353
|
+
if (!props.validator) {
|
|
3354
|
+
throw new Error("A validator is required for Form functionality to work");
|
|
3355
|
+
}
|
|
3356
|
+
this.state = this.getStateFromProps(props, props.formData);
|
|
3357
|
+
if (this.props.onChange && !(0, import_utils39.deepEquals)(this.state.formData, this.props.formData)) {
|
|
3358
|
+
this.props.onChange(this.state);
|
|
3359
|
+
}
|
|
3360
|
+
this.formElement = (0, import_react17.createRef)();
|
|
3361
|
+
}
|
|
3362
|
+
/** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
|
|
3363
|
+
* will also call the`onChange` handler if the `formData` is modified to add missing default values as part of the
|
|
3364
|
+
* state construction.
|
|
3365
|
+
*
|
|
3366
|
+
* @param nextProps - The new set of props about to be applied to the `Form`
|
|
3367
|
+
*/
|
|
3368
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
3369
|
+
const nextState = this.getStateFromProps(nextProps, nextProps.formData);
|
|
3370
|
+
if (!(0, import_utils39.deepEquals)(nextState.formData, nextProps.formData) && !(0, import_utils39.deepEquals)(nextState.formData, this.state.formData) && nextProps.onChange) {
|
|
3371
|
+
nextProps.onChange(nextState);
|
|
3372
|
+
}
|
|
3373
|
+
this.setState(nextState);
|
|
3374
|
+
}
|
|
3375
|
+
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
3376
|
+
* `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the
|
|
3377
|
+
* validation process IF required by the `props`.
|
|
3378
|
+
*
|
|
3379
|
+
* @param props - The props passed to the `Form`
|
|
3380
|
+
* @param inputFormData - The new or current data for the `Form`
|
|
3381
|
+
* @returns - The new state for the `Form`
|
|
3382
|
+
*/
|
|
3383
|
+
getStateFromProps(props, inputFormData) {
|
|
3384
|
+
const state = this.state || {};
|
|
3385
|
+
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
3386
|
+
const uiSchema = ("uiSchema" in props ? props.uiSchema : this.props.uiSchema) || {};
|
|
3387
|
+
const edit = typeof inputFormData !== "undefined";
|
|
3388
|
+
const liveValidate = "liveValidate" in props ? props.liveValidate : this.props.liveValidate;
|
|
3389
|
+
const mustValidate = edit && !props.noValidate && liveValidate;
|
|
3390
|
+
const rootSchema = schema;
|
|
3391
|
+
const experimental_defaultFormStateBehavior = "experimental_defaultFormStateBehavior" in props ? props.experimental_defaultFormStateBehavior : this.props.experimental_defaultFormStateBehavior;
|
|
3392
|
+
let schemaUtils = state.schemaUtils;
|
|
3393
|
+
if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema, experimental_defaultFormStateBehavior)) {
|
|
3394
|
+
schemaUtils = (0, import_utils39.createSchemaUtils)(props.validator, rootSchema, experimental_defaultFormStateBehavior);
|
|
3395
|
+
}
|
|
3396
|
+
const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
|
|
3397
|
+
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3398
|
+
const getCurrentErrors = () => {
|
|
3399
|
+
if (props.noValidate) {
|
|
3400
|
+
return { errors: [], errorSchema: {} };
|
|
3401
|
+
} else if (!props.liveValidate) {
|
|
3402
|
+
return {
|
|
3403
|
+
errors: state.schemaValidationErrors || [],
|
|
3404
|
+
errorSchema: state.schemaValidationErrorSchema || {}
|
|
3405
|
+
};
|
|
3406
|
+
}
|
|
3407
|
+
return {
|
|
3408
|
+
errors: state.errors || [],
|
|
3409
|
+
errorSchema: state.errorSchema || {}
|
|
3410
|
+
};
|
|
3411
|
+
};
|
|
3412
|
+
let errors;
|
|
3413
|
+
let errorSchema;
|
|
3414
|
+
let schemaValidationErrors = state.schemaValidationErrors;
|
|
3415
|
+
let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
|
|
3416
|
+
if (mustValidate) {
|
|
3417
|
+
const schemaValidation = this.validate(formData, schema, schemaUtils);
|
|
3418
|
+
errors = schemaValidation.errors;
|
|
3419
|
+
errorSchema = schemaValidation.errorSchema;
|
|
3420
|
+
schemaValidationErrors = errors;
|
|
3421
|
+
schemaValidationErrorSchema = errorSchema;
|
|
3422
|
+
} else {
|
|
3423
|
+
const currentErrors = getCurrentErrors();
|
|
3424
|
+
errors = currentErrors.errors;
|
|
3425
|
+
errorSchema = currentErrors.errorSchema;
|
|
3426
|
+
}
|
|
3427
|
+
if (props.extraErrors) {
|
|
3428
|
+
const merged = (0, import_utils39.validationDataMerge)({ errorSchema, errors }, props.extraErrors);
|
|
3429
|
+
errorSchema = merged.errorSchema;
|
|
3430
|
+
errors = merged.errors;
|
|
3431
|
+
}
|
|
3432
|
+
const idSchema = schemaUtils.toIdSchema(
|
|
3433
|
+
retrievedSchema,
|
|
3434
|
+
uiSchema["ui:rootFieldId"],
|
|
3435
|
+
formData,
|
|
3436
|
+
props.idPrefix,
|
|
3437
|
+
props.idSeparator
|
|
3438
|
+
);
|
|
3439
|
+
const nextState = {
|
|
3440
|
+
schemaUtils,
|
|
3441
|
+
schema,
|
|
3442
|
+
uiSchema,
|
|
3443
|
+
idSchema,
|
|
3444
|
+
formData,
|
|
3445
|
+
edit,
|
|
3446
|
+
errors,
|
|
3447
|
+
errorSchema,
|
|
3448
|
+
schemaValidationErrors,
|
|
3449
|
+
schemaValidationErrorSchema
|
|
3450
|
+
};
|
|
3451
|
+
return nextState;
|
|
3452
|
+
}
|
|
3453
|
+
/** React lifecycle method that is used to determine whether component should be updated.
|
|
3454
|
+
*
|
|
3455
|
+
* @param nextProps - The next version of the props
|
|
3456
|
+
* @param nextState - The next version of the state
|
|
3457
|
+
* @returns - True if the component should be updated, false otherwise
|
|
3458
|
+
*/
|
|
3459
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
3460
|
+
return (0, import_utils39.shouldRender)(this, nextProps, nextState);
|
|
3461
|
+
}
|
|
3462
|
+
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
|
|
3463
|
+
* `schemaUtils` in the state), returning the results.
|
|
3464
|
+
*
|
|
3465
|
+
* @param formData - The new form data to validate
|
|
3466
|
+
* @param schema - The schema used to validate against
|
|
3467
|
+
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
3468
|
+
*/
|
|
3469
|
+
validate(formData, schema = this.props.schema, altSchemaUtils) {
|
|
3470
|
+
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
3471
|
+
const { customValidate, transformErrors, uiSchema } = this.props;
|
|
3472
|
+
const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3473
|
+
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
|
|
3474
|
+
}
|
|
3475
|
+
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
|
|
3476
|
+
renderErrors(registry) {
|
|
3477
|
+
const { errors, errorSchema, schema, uiSchema } = this.state;
|
|
3478
|
+
const { formContext } = this.props;
|
|
3479
|
+
const options = (0, import_utils39.getUiOptions)(uiSchema);
|
|
3480
|
+
const ErrorListTemplate = (0, import_utils39.getTemplate)("ErrorListTemplate", registry, options);
|
|
3481
|
+
if (errors && errors.length) {
|
|
3482
|
+
return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
|
|
3483
|
+
ErrorListTemplate,
|
|
3484
|
+
{
|
|
3485
|
+
errors,
|
|
3486
|
+
errorSchema: errorSchema || {},
|
|
3487
|
+
schema,
|
|
3488
|
+
uiSchema,
|
|
3489
|
+
formContext,
|
|
3490
|
+
registry
|
|
3491
|
+
}
|
|
3492
|
+
);
|
|
3493
|
+
}
|
|
3494
|
+
return null;
|
|
3495
|
+
}
|
|
3496
|
+
/** Returns the registry for the form */
|
|
3497
|
+
getRegistry() {
|
|
3498
|
+
const { translateString: customTranslateString, uiSchema = {} } = this.props;
|
|
3499
|
+
const { schemaUtils } = this.state;
|
|
3500
|
+
const { fields: fields2, templates: templates2, widgets: widgets2, formContext, translateString } = getDefaultRegistry();
|
|
3501
|
+
return {
|
|
3502
|
+
fields: { ...fields2, ...this.props.fields },
|
|
3503
|
+
templates: {
|
|
3504
|
+
...templates2,
|
|
3505
|
+
...this.props.templates,
|
|
3506
|
+
ButtonTemplates: {
|
|
3507
|
+
...templates2.ButtonTemplates,
|
|
3508
|
+
...this.props.templates?.ButtonTemplates
|
|
3509
|
+
}
|
|
3510
|
+
},
|
|
3511
|
+
widgets: { ...widgets2, ...this.props.widgets },
|
|
3512
|
+
rootSchema: this.props.schema,
|
|
3513
|
+
formContext: this.props.formContext || formContext,
|
|
3514
|
+
schemaUtils,
|
|
3515
|
+
translateString: customTranslateString || translateString,
|
|
3516
|
+
globalUiOptions: uiSchema[import_utils39.UI_GLOBAL_OPTIONS_KEY]
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
3520
|
+
submit() {
|
|
3521
|
+
if (this.formElement.current) {
|
|
3522
|
+
this.formElement.current.dispatchEvent(
|
|
3523
|
+
new CustomEvent("submit", {
|
|
3524
|
+
cancelable: true
|
|
3525
|
+
})
|
|
3526
|
+
);
|
|
3527
|
+
this.formElement.current.requestSubmit();
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
/** Attempts to focus on the field associated with the `error`. Uses the `property` field to compute path of the error
|
|
3531
|
+
* field, then, using the `idPrefix` and `idSeparator` converts that path into an id. Then the input element with that
|
|
3532
|
+
* id is attempted to be found using the `formElement` ref. If it is located, then it is focused.
|
|
3533
|
+
*
|
|
3534
|
+
* @param error - The error on which to focus
|
|
3535
|
+
*/
|
|
3536
|
+
focusOnError(error) {
|
|
3537
|
+
const { idPrefix = "root", idSeparator = "_" } = this.props;
|
|
3538
|
+
const { property } = error;
|
|
3539
|
+
const path = (0, import_toPath.default)(property);
|
|
3540
|
+
if (path[0] === "") {
|
|
3541
|
+
path[0] = idPrefix;
|
|
3542
|
+
} else {
|
|
3543
|
+
path.unshift(idPrefix);
|
|
3544
|
+
}
|
|
3545
|
+
const elementId = path.join(idSeparator);
|
|
3546
|
+
let field = this.formElement.current.elements[elementId];
|
|
3547
|
+
if (!field) {
|
|
3548
|
+
field = this.formElement.current.querySelector(`input[id^=${elementId}`);
|
|
3549
|
+
}
|
|
3550
|
+
if (field && field.length) {
|
|
3551
|
+
field = field[0];
|
|
3552
|
+
}
|
|
3553
|
+
if (field) {
|
|
3554
|
+
field.focus();
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
/** Programmatically validate the form. If `onError` is provided, then it will be called with the list of errors the
|
|
3558
|
+
* same way as would happen on form submission.
|
|
3559
|
+
*
|
|
3560
|
+
* @returns - True if the form is valid, false otherwise.
|
|
3561
|
+
*/
|
|
3562
|
+
validateForm() {
|
|
3563
|
+
const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
|
|
3564
|
+
const { formData } = this.state;
|
|
3565
|
+
const schemaValidation = this.validate(formData);
|
|
3566
|
+
let errors = schemaValidation.errors;
|
|
3567
|
+
let errorSchema = schemaValidation.errorSchema;
|
|
3568
|
+
const schemaValidationErrors = errors;
|
|
3569
|
+
const schemaValidationErrorSchema = errorSchema;
|
|
3570
|
+
if (errors.length > 0 || extraErrors && extraErrorsBlockSubmit) {
|
|
3571
|
+
if (extraErrors) {
|
|
3572
|
+
const merged = (0, import_utils39.validationDataMerge)(schemaValidation, extraErrors);
|
|
3573
|
+
errorSchema = merged.errorSchema;
|
|
3574
|
+
errors = merged.errors;
|
|
3575
|
+
}
|
|
3576
|
+
if (focusOnFirstError) {
|
|
3577
|
+
if (typeof focusOnFirstError === "function") {
|
|
3578
|
+
focusOnFirstError(errors[0]);
|
|
3579
|
+
} else {
|
|
3580
|
+
this.focusOnError(errors[0]);
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
this.setState(
|
|
3584
|
+
{
|
|
3585
|
+
errors,
|
|
3586
|
+
errorSchema,
|
|
3587
|
+
schemaValidationErrors,
|
|
3588
|
+
schemaValidationErrorSchema
|
|
3589
|
+
},
|
|
3590
|
+
() => {
|
|
3591
|
+
if (onError) {
|
|
3592
|
+
onError(errors);
|
|
3593
|
+
} else {
|
|
3594
|
+
console.error("Form validation failed", errors);
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
);
|
|
3598
|
+
return false;
|
|
3599
|
+
}
|
|
3600
|
+
return true;
|
|
3601
|
+
}
|
|
3602
|
+
/** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
|
|
3603
|
+
* needed along with the submit button or any children of the form.
|
|
3604
|
+
*/
|
|
3605
|
+
render() {
|
|
3606
|
+
const {
|
|
3607
|
+
children,
|
|
3608
|
+
id,
|
|
3609
|
+
idPrefix,
|
|
3610
|
+
idSeparator,
|
|
3611
|
+
className = "",
|
|
3612
|
+
tagName,
|
|
3613
|
+
name,
|
|
3614
|
+
method,
|
|
3615
|
+
target,
|
|
3616
|
+
action,
|
|
3617
|
+
autoComplete,
|
|
3618
|
+
enctype,
|
|
3619
|
+
acceptcharset,
|
|
3620
|
+
noHtml5Validate = false,
|
|
3621
|
+
disabled = false,
|
|
3622
|
+
readonly = false,
|
|
3623
|
+
formContext,
|
|
3624
|
+
showErrorList = "top",
|
|
3625
|
+
_internalFormWrapper
|
|
3626
|
+
} = this.props;
|
|
3627
|
+
const { schema, uiSchema, formData, errorSchema, idSchema } = this.state;
|
|
3628
|
+
const registry = this.getRegistry();
|
|
3629
|
+
const { SchemaField: _SchemaField } = registry.fields;
|
|
3630
|
+
const { SubmitButton: SubmitButton2 } = registry.templates.ButtonTemplates;
|
|
3631
|
+
const as = _internalFormWrapper ? tagName : void 0;
|
|
3632
|
+
const FormTag = _internalFormWrapper || tagName || "form";
|
|
3633
|
+
let { [import_utils39.SUBMIT_BTN_OPTIONS_KEY]: submitOptions = {} } = (0, import_utils39.getUiOptions)(uiSchema);
|
|
3634
|
+
if (disabled) {
|
|
3635
|
+
submitOptions = { ...submitOptions, props: { ...submitOptions.props, disabled: true } };
|
|
3636
|
+
}
|
|
3637
|
+
const submitUiSchema = { [import_utils39.UI_OPTIONS_KEY]: { [import_utils39.SUBMIT_BTN_OPTIONS_KEY]: submitOptions } };
|
|
3638
|
+
return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
|
|
3639
|
+
FormTag,
|
|
3640
|
+
{
|
|
3641
|
+
className: className ? className : "rjsf",
|
|
3642
|
+
id,
|
|
3643
|
+
name,
|
|
3644
|
+
method,
|
|
3645
|
+
target,
|
|
3646
|
+
action,
|
|
3647
|
+
autoComplete,
|
|
3648
|
+
encType: enctype,
|
|
3649
|
+
acceptCharset: acceptcharset,
|
|
3650
|
+
noValidate: noHtml5Validate,
|
|
3651
|
+
onSubmit: this.onSubmit,
|
|
3652
|
+
as,
|
|
3653
|
+
ref: this.formElement,
|
|
3654
|
+
children: [
|
|
3655
|
+
showErrorList === "top" && this.renderErrors(registry),
|
|
3656
|
+
/* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
|
|
3657
|
+
_SchemaField,
|
|
3658
|
+
{
|
|
3659
|
+
name: "",
|
|
3660
|
+
schema,
|
|
3661
|
+
uiSchema,
|
|
3662
|
+
errorSchema,
|
|
3663
|
+
idSchema,
|
|
3664
|
+
idPrefix,
|
|
3665
|
+
idSeparator,
|
|
3666
|
+
formContext,
|
|
3667
|
+
formData,
|
|
3668
|
+
onChange: this.onChange,
|
|
3669
|
+
onBlur: this.onBlur,
|
|
3670
|
+
onFocus: this.onFocus,
|
|
3671
|
+
registry,
|
|
3672
|
+
disabled,
|
|
3673
|
+
readonly
|
|
3674
|
+
}
|
|
3675
|
+
),
|
|
3676
|
+
children ? children : /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(SubmitButton2, { uiSchema: submitUiSchema, registry }),
|
|
3677
|
+
showErrorList === "bottom" && this.renderErrors(registry)
|
|
3678
|
+
]
|
|
3679
|
+
}
|
|
3680
|
+
);
|
|
3681
|
+
}
|
|
3682
|
+
};
|
|
3683
|
+
|
|
3684
|
+
// src/withTheme.tsx
|
|
3685
|
+
var import_react18 = require("react");
|
|
3686
|
+
var import_jsx_runtime46 = require("react/jsx-runtime");
|
|
3687
|
+
function withTheme(themeProps) {
|
|
3688
|
+
return (0, import_react18.forwardRef)(
|
|
3689
|
+
({ fields: fields2, widgets: widgets2, templates: templates2, ...directProps }, ref) => {
|
|
3690
|
+
fields2 = { ...themeProps?.fields, ...fields2 };
|
|
3691
|
+
widgets2 = { ...themeProps?.widgets, ...widgets2 };
|
|
3692
|
+
templates2 = {
|
|
3693
|
+
...themeProps?.templates,
|
|
3694
|
+
...templates2,
|
|
3695
|
+
ButtonTemplates: {
|
|
3696
|
+
...themeProps?.templates?.ButtonTemplates,
|
|
3697
|
+
...templates2?.ButtonTemplates
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
|
|
3701
|
+
Form,
|
|
3702
|
+
{
|
|
3703
|
+
...themeProps,
|
|
3704
|
+
...directProps,
|
|
3705
|
+
fields: fields2,
|
|
3706
|
+
widgets: widgets2,
|
|
3707
|
+
templates: templates2,
|
|
3708
|
+
ref
|
|
3709
|
+
}
|
|
3710
|
+
);
|
|
3711
|
+
}
|
|
3712
|
+
);
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
// src/index.ts
|
|
3716
|
+
var src_default = Form;
|
|
3717
|
+
//# sourceMappingURL=index.js.map
|