@rjsf/core 5.15.0 → 5.16.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 +67 -53
- package/dist/index.esm.js +70 -55
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +67 -53
- package/dist/index.js.map +3 -3
- package/lib/components/Form.d.ts +1 -1
- package/lib/components/Form.js +12 -10
- package/lib/components/Form.js.map +1 -1
- package/lib/components/fields/ArrayField.d.ts +1 -0
- package/lib/components/fields/ArrayField.js +10 -8
- package/lib/components/fields/ArrayField.js.map +1 -1
- package/lib/components/fields/BooleanField.js +5 -5
- package/lib/components/fields/BooleanField.js.map +1 -1
- package/lib/components/fields/ObjectField.js +5 -5
- package/lib/components/fields/ObjectField.js.map +1 -1
- package/lib/components/fields/SchemaField.js +4 -1
- package/lib/components/fields/SchemaField.js.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -18
- package/lib/components/widgets/AltDateWidget.js.map +1 -1
- package/lib/components/widgets/FileWidget.js +17 -8
- package/lib/components/widgets/FileWidget.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/components/Form.tsx +7 -3
- package/src/components/fields/ArrayField.tsx +11 -4
- package/src/components/fields/BooleanField.tsx +3 -2
- package/src/components/fields/ObjectField.tsx +3 -2
- package/src/components/fields/SchemaField.tsx +4 -1
- package/src/components/widgets/AltDateWidget.tsx +8 -26
- package/src/components/widgets/FileWidget.tsx +31 -8
package/dist/index.js
CHANGED
|
@@ -425,6 +425,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
425
425
|
errorSchema,
|
|
426
426
|
idSchema,
|
|
427
427
|
name,
|
|
428
|
+
title,
|
|
428
429
|
disabled = false,
|
|
429
430
|
readonly = false,
|
|
430
431
|
autofocus = false,
|
|
@@ -437,7 +438,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
437
438
|
rawErrors
|
|
438
439
|
} = this.props;
|
|
439
440
|
const { keyedFormData } = this.state;
|
|
440
|
-
const
|
|
441
|
+
const fieldTitle = schema.title || title || name;
|
|
441
442
|
const { schemaUtils, formContext } = registry;
|
|
442
443
|
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
443
444
|
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : {};
|
|
@@ -457,6 +458,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
457
458
|
key,
|
|
458
459
|
index,
|
|
459
460
|
name: name && `${name}-${index}`,
|
|
461
|
+
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
460
462
|
canAdd,
|
|
461
463
|
canMoveUp: index > 0,
|
|
462
464
|
canMoveDown: index < formData.length - 1,
|
|
@@ -480,7 +482,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
480
482
|
readonly,
|
|
481
483
|
required,
|
|
482
484
|
schema,
|
|
483
|
-
title,
|
|
485
|
+
title: fieldTitle,
|
|
484
486
|
formContext,
|
|
485
487
|
formData,
|
|
486
488
|
rawErrors,
|
|
@@ -653,6 +655,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
653
655
|
idSeparator = "_",
|
|
654
656
|
idSchema,
|
|
655
657
|
name,
|
|
658
|
+
title,
|
|
656
659
|
disabled = false,
|
|
657
660
|
readonly = false,
|
|
658
661
|
autofocus = false,
|
|
@@ -664,7 +667,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
664
667
|
} = this.props;
|
|
665
668
|
const { keyedFormData } = this.state;
|
|
666
669
|
let { formData: items = [] } = this.props;
|
|
667
|
-
const
|
|
670
|
+
const fieldTitle = schema.title || title || name;
|
|
668
671
|
const uiOptions = (0, import_utils.getUiOptions)(uiSchema);
|
|
669
672
|
const { schemaUtils, formContext } = registry;
|
|
670
673
|
const _schemaItems = (0, import_isObject.default)(schema.items) ? schema.items : [];
|
|
@@ -696,6 +699,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
696
699
|
key,
|
|
697
700
|
index,
|
|
698
701
|
name: name && `${name}-${index}`,
|
|
702
|
+
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
|
|
699
703
|
canAdd,
|
|
700
704
|
canRemove: additional,
|
|
701
705
|
canMoveUp: index >= itemSchemas.length + 1,
|
|
@@ -718,7 +722,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
718
722
|
registry,
|
|
719
723
|
schema,
|
|
720
724
|
uiSchema,
|
|
721
|
-
title,
|
|
725
|
+
title: fieldTitle,
|
|
722
726
|
formContext,
|
|
723
727
|
rawErrors
|
|
724
728
|
};
|
|
@@ -748,7 +752,8 @@ var ArrayField = class extends import_react.Component {
|
|
|
748
752
|
onBlur,
|
|
749
753
|
onFocus,
|
|
750
754
|
rawErrors,
|
|
751
|
-
totalItems
|
|
755
|
+
totalItems,
|
|
756
|
+
title
|
|
752
757
|
} = props;
|
|
753
758
|
const { disabled, hideError, idPrefix, idSeparator, readonly, uiSchema, registry, formContext } = this.props;
|
|
754
759
|
const {
|
|
@@ -770,6 +775,7 @@ var ArrayField = class extends import_react.Component {
|
|
|
770
775
|
ItemSchemaField,
|
|
771
776
|
{
|
|
772
777
|
name,
|
|
778
|
+
title,
|
|
773
779
|
index,
|
|
774
780
|
schema: itemSchema,
|
|
775
781
|
uiSchema: itemUiSchema,
|
|
@@ -832,12 +838,13 @@ function BooleanField(props) {
|
|
|
832
838
|
readonly,
|
|
833
839
|
hideError,
|
|
834
840
|
autofocus,
|
|
841
|
+
title,
|
|
835
842
|
onChange,
|
|
836
843
|
onFocus,
|
|
837
844
|
onBlur,
|
|
838
845
|
rawErrors
|
|
839
846
|
} = props;
|
|
840
|
-
const { title } = schema;
|
|
847
|
+
const { title: schemaTitle } = schema;
|
|
841
848
|
const { widgets: widgets2, formContext, translateString, globalUiOptions } = registry;
|
|
842
849
|
const {
|
|
843
850
|
widget = "checkbox",
|
|
@@ -850,7 +857,7 @@ function BooleanField(props) {
|
|
|
850
857
|
const yes = translateString(import_utils2.TranslatableString.YesLabel);
|
|
851
858
|
const no = translateString(import_utils2.TranslatableString.NoLabel);
|
|
852
859
|
let enumOptions;
|
|
853
|
-
const label = uiTitle ?? title ?? name;
|
|
860
|
+
const label = uiTitle ?? schemaTitle ?? title ?? name;
|
|
854
861
|
if (Array.isArray(schema.oneOf)) {
|
|
855
862
|
enumOptions = (0, import_utils2.optionsList)({
|
|
856
863
|
oneOf: schema.oneOf.map((option) => {
|
|
@@ -1299,14 +1306,15 @@ var ObjectField = class extends import_react4.Component {
|
|
|
1299
1306
|
idSeparator,
|
|
1300
1307
|
onBlur,
|
|
1301
1308
|
onFocus,
|
|
1302
|
-
registry
|
|
1309
|
+
registry,
|
|
1310
|
+
title
|
|
1303
1311
|
} = this.props;
|
|
1304
1312
|
const { fields: fields2, formContext, schemaUtils, translateString, globalUiOptions } = registry;
|
|
1305
1313
|
const { SchemaField: SchemaField2 } = fields2;
|
|
1306
1314
|
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1307
1315
|
const uiOptions = (0, import_utils5.getUiOptions)(uiSchema, globalUiOptions);
|
|
1308
1316
|
const { properties: schemaProperties = {} } = schema;
|
|
1309
|
-
const
|
|
1317
|
+
const templateTitle = uiOptions.title ?? schema.title ?? title ?? name;
|
|
1310
1318
|
const description = uiOptions.description ?? schema.description;
|
|
1311
1319
|
let orderedProperties;
|
|
1312
1320
|
try {
|
|
@@ -1321,7 +1329,7 @@ var ObjectField = class extends import_react4.Component {
|
|
|
1321
1329
|
const Template = (0, import_utils5.getTemplate)("ObjectFieldTemplate", registry, uiOptions);
|
|
1322
1330
|
const templateProps = {
|
|
1323
1331
|
// getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
|
|
1324
|
-
title: uiOptions.label === false ? "" :
|
|
1332
|
+
title: uiOptions.label === false ? "" : templateTitle,
|
|
1325
1333
|
description: uiOptions.label === false ? void 0 : description,
|
|
1326
1334
|
properties: orderedProperties.map((name2) => {
|
|
1327
1335
|
const addedByAdditionalProperties = (0, import_has.default)(schema, [import_utils5.PROPERTIES_KEY, name2, import_utils5.ADDITIONAL_PROPERTY_FLAG]);
|
|
@@ -1507,7 +1515,7 @@ function SchemaFieldRender(props) {
|
|
|
1507
1515
|
if (wasPropertyKeyModified) {
|
|
1508
1516
|
label = name;
|
|
1509
1517
|
} else {
|
|
1510
|
-
label = import_utils6.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
|
|
1518
|
+
label = import_utils6.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || props.title || name;
|
|
1511
1519
|
}
|
|
1512
1520
|
const description = uiOptions.description || props.schema.description || schema.description || "";
|
|
1513
1521
|
const richDescription = uiOptions.enableMarkdownInDescription ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_markdown_to_jsx2.default, { children: description }) : description;
|
|
@@ -2436,26 +2444,6 @@ function rangeOptions(start, stop) {
|
|
|
2436
2444
|
function readyForChange(state) {
|
|
2437
2445
|
return Object.values(state).every((value) => value !== -1);
|
|
2438
2446
|
}
|
|
2439
|
-
function dateElementProps(state, time, yearsRange = [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2]) {
|
|
2440
|
-
const { year, month, day, hour, minute, second } = state;
|
|
2441
|
-
const data = [
|
|
2442
|
-
{
|
|
2443
|
-
type: "year",
|
|
2444
|
-
range: yearsRange,
|
|
2445
|
-
value: year
|
|
2446
|
-
},
|
|
2447
|
-
{ type: "month", range: [1, 12], value: month },
|
|
2448
|
-
{ type: "day", range: [1, 31], value: day }
|
|
2449
|
-
];
|
|
2450
|
-
if (time) {
|
|
2451
|
-
data.push(
|
|
2452
|
-
{ type: "hour", range: [0, 23], value: hour },
|
|
2453
|
-
{ type: "minute", range: [0, 59], value: minute },
|
|
2454
|
-
{ type: "second", range: [0, 59], value: second }
|
|
2455
|
-
);
|
|
2456
|
-
}
|
|
2457
|
-
return data;
|
|
2458
|
-
}
|
|
2459
2447
|
function DateElement({
|
|
2460
2448
|
type,
|
|
2461
2449
|
range,
|
|
@@ -2547,7 +2535,12 @@ function AltDateWidget({
|
|
|
2547
2535
|
[disabled, readonly, onChange]
|
|
2548
2536
|
);
|
|
2549
2537
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("ul", { className: "list-inline", children: [
|
|
2550
|
-
|
|
2538
|
+
(0, import_utils22.getDateElementProps)(
|
|
2539
|
+
state,
|
|
2540
|
+
time,
|
|
2541
|
+
options.yearsRange,
|
|
2542
|
+
options.format
|
|
2543
|
+
).map((elemProps, i) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("li", { className: "list-inline-item", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2551
2544
|
DateElement,
|
|
2552
2545
|
{
|
|
2553
2546
|
rootId: id,
|
|
@@ -2816,17 +2809,22 @@ function FileInfoPreview({
|
|
|
2816
2809
|
function FilesInfo({
|
|
2817
2810
|
filesInfo,
|
|
2818
2811
|
registry,
|
|
2819
|
-
preview
|
|
2812
|
+
preview,
|
|
2813
|
+
onRemove,
|
|
2814
|
+
options
|
|
2820
2815
|
}) {
|
|
2821
2816
|
if (filesInfo.length === 0) {
|
|
2822
2817
|
return null;
|
|
2823
2818
|
}
|
|
2824
2819
|
const { translateString } = registry;
|
|
2820
|
+
const { RemoveButton: RemoveButton2 } = (0, import_utils29.getTemplate)("ButtonTemplates", registry, options);
|
|
2825
2821
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("ul", { className: "file-info", children: filesInfo.map((fileInfo, key) => {
|
|
2826
2822
|
const { name, size, type } = fileInfo;
|
|
2823
|
+
const handleRemove = () => onRemove(key);
|
|
2827
2824
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("li", { children: [
|
|
2828
2825
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_markdown_to_jsx4.default, { children: translateString(import_utils29.TranslatableString.FilesInfo, [name, type, String(size)]) }),
|
|
2829
|
-
preview && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FileInfoPreview, { fileInfo, registry })
|
|
2826
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(FileInfoPreview, { fileInfo, registry }),
|
|
2827
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(RemoveButton2, { onClick: handleRemove, registry })
|
|
2830
2828
|
] }, key);
|
|
2831
2829
|
}) });
|
|
2832
2830
|
}
|
|
@@ -2844,9 +2842,6 @@ function extractFileInfo(dataURLs) {
|
|
|
2844
2842
|
function FileWidget(props) {
|
|
2845
2843
|
const { disabled, readonly, required, multiple, onChange, value, options, registry } = props;
|
|
2846
2844
|
const BaseInputTemplate2 = (0, import_utils29.getTemplate)("BaseInputTemplate", registry, options);
|
|
2847
|
-
const [filesInfo, setFilesInfo] = (0, import_react12.useState)(
|
|
2848
|
-
Array.isArray(value) ? extractFileInfo(value) : extractFileInfo([value])
|
|
2849
|
-
);
|
|
2850
2845
|
const handleChange = (0, import_react12.useCallback)(
|
|
2851
2846
|
(event) => {
|
|
2852
2847
|
if (!event.target.files) {
|
|
@@ -2855,15 +2850,25 @@ function FileWidget(props) {
|
|
|
2855
2850
|
processFiles(event.target.files).then((filesInfoEvent) => {
|
|
2856
2851
|
const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL);
|
|
2857
2852
|
if (multiple) {
|
|
2858
|
-
setFilesInfo(filesInfo.concat(filesInfoEvent[0]));
|
|
2859
2853
|
onChange(value.concat(newValue[0]));
|
|
2860
2854
|
} else {
|
|
2861
|
-
setFilesInfo(filesInfoEvent);
|
|
2862
2855
|
onChange(newValue[0]);
|
|
2863
2856
|
}
|
|
2864
2857
|
});
|
|
2865
2858
|
},
|
|
2866
|
-
[multiple, value,
|
|
2859
|
+
[multiple, value, onChange]
|
|
2860
|
+
);
|
|
2861
|
+
const filesInfo = (0, import_react12.useMemo)(() => extractFileInfo(Array.isArray(value) ? value : [value]), [value]);
|
|
2862
|
+
const rmFile = (0, import_react12.useCallback)(
|
|
2863
|
+
(index) => {
|
|
2864
|
+
if (multiple) {
|
|
2865
|
+
const newValue = value.filter((_, i) => i !== index);
|
|
2866
|
+
onChange(newValue);
|
|
2867
|
+
} else {
|
|
2868
|
+
onChange(void 0);
|
|
2869
|
+
}
|
|
2870
|
+
},
|
|
2871
|
+
[multiple, value, onChange]
|
|
2867
2872
|
);
|
|
2868
2873
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { children: [
|
|
2869
2874
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
@@ -2878,7 +2883,16 @@ function FileWidget(props) {
|
|
|
2878
2883
|
accept: options.accept ? String(options.accept) : void 0
|
|
2879
2884
|
}
|
|
2880
2885
|
),
|
|
2881
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
2886
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
2887
|
+
FilesInfo,
|
|
2888
|
+
{
|
|
2889
|
+
filesInfo,
|
|
2890
|
+
onRemove: rmFile,
|
|
2891
|
+
registry,
|
|
2892
|
+
preview: options.filePreview,
|
|
2893
|
+
options
|
|
2894
|
+
}
|
|
2895
|
+
)
|
|
2882
2896
|
] });
|
|
2883
2897
|
}
|
|
2884
2898
|
var FileWidget_default = FileWidget;
|
|
@@ -3223,7 +3237,7 @@ var Form = class extends import_react17.Component {
|
|
|
3223
3237
|
} else if (key === import_utils39.NAME_KEY && _obj[key] !== "") {
|
|
3224
3238
|
paths.forEach((path) => {
|
|
3225
3239
|
const formValue = (0, import_get4.default)(formData, path);
|
|
3226
|
-
if (typeof formValue !== "object" || (0, import_isEmpty2.default)(formValue)) {
|
|
3240
|
+
if (typeof formValue !== "object" || (0, import_isEmpty2.default)(formValue) || Array.isArray(formValue) && formValue.every((val) => typeof val !== "object")) {
|
|
3227
3241
|
acc.push(path);
|
|
3228
3242
|
}
|
|
3229
3243
|
});
|
|
@@ -3380,6 +3394,17 @@ var Form = class extends import_react17.Component {
|
|
|
3380
3394
|
);
|
|
3381
3395
|
}
|
|
3382
3396
|
};
|
|
3397
|
+
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
3398
|
+
this.submit = () => {
|
|
3399
|
+
if (this.formElement.current) {
|
|
3400
|
+
this.formElement.current.dispatchEvent(
|
|
3401
|
+
new CustomEvent("submit", {
|
|
3402
|
+
cancelable: true
|
|
3403
|
+
})
|
|
3404
|
+
);
|
|
3405
|
+
this.formElement.current.requestSubmit();
|
|
3406
|
+
}
|
|
3407
|
+
};
|
|
3383
3408
|
if (!props.validator) {
|
|
3384
3409
|
throw new Error("A validator is required for Form functionality to work");
|
|
3385
3410
|
}
|
|
@@ -3588,17 +3613,6 @@ var Form = class extends import_react17.Component {
|
|
|
3588
3613
|
globalUiOptions: uiSchema[import_utils39.UI_GLOBAL_OPTIONS_KEY]
|
|
3589
3614
|
};
|
|
3590
3615
|
}
|
|
3591
|
-
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
3592
|
-
submit() {
|
|
3593
|
-
if (this.formElement.current) {
|
|
3594
|
-
this.formElement.current.dispatchEvent(
|
|
3595
|
-
new CustomEvent("submit", {
|
|
3596
|
-
cancelable: true
|
|
3597
|
-
})
|
|
3598
|
-
);
|
|
3599
|
-
this.formElement.current.requestSubmit();
|
|
3600
|
-
}
|
|
3601
|
-
}
|
|
3602
3616
|
/** Attempts to focus on the field associated with the `error`. Uses the `property` field to compute path of the error
|
|
3603
3617
|
* field, then, using the `idPrefix` and `idSeparator` converts that path into an id. Then the input element with that
|
|
3604
3618
|
* id is attempted to be found using the `formElement` ref. If it is located, then it is focused.
|