@rjsf/core 5.2.1 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs.development.js +208 -111
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +207 -111
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +210 -114
- package/dist/core.umd.development.js.map +1 -1
- package/dist/core.umd.production.min.js +1 -1
- package/dist/core.umd.production.min.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/package.json +12 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/toPath'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/omit'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/toPath', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/unset'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.jsxRuntime, global.React, global.utils, global.get, global.isEmpty, global._pick, global._toPath, global.isObject, global.set, global.nanoid, global.omit, global.
|
|
5
|
-
})(this, (function (exports, jsxRuntime, react, utils, get, isEmpty, _pick, _toPath, isObject, set, nanoid, omit, has, unset
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@rjsf/utils'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('lodash-es/pick'), require('lodash-es/toPath'), require('lodash-es/cloneDeep'), require('lodash-es/isObject'), require('lodash-es/set'), require('nanoid'), require('lodash-es/omit'), require('markdown-to-jsx'), require('lodash-es/has'), require('lodash-es/unset')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@rjsf/utils', 'lodash-es/get', 'lodash-es/isEmpty', 'lodash-es/pick', 'lodash-es/toPath', 'lodash-es/cloneDeep', 'lodash-es/isObject', 'lodash-es/set', 'nanoid', 'lodash-es/omit', 'markdown-to-jsx', 'lodash-es/has', 'lodash-es/unset'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.jsxRuntime, global.React, global.utils, global.get, global.isEmpty, global._pick, global._toPath, global.cloneDeep, global.isObject, global.set, global.nanoid, global.omit, global.Markdown, global.has, global.unset));
|
|
5
|
+
})(this, (function (exports, jsxRuntime, react, utils, get, isEmpty, _pick, _toPath, cloneDeep, isObject, set, nanoid, omit, Markdown, has, unset) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
11
11
|
var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
|
|
12
12
|
var _toPath__default = /*#__PURE__*/_interopDefaultLegacy(_toPath);
|
|
13
|
+
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
13
14
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
14
15
|
var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
|
|
15
16
|
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
17
|
+
var Markdown__default = /*#__PURE__*/_interopDefaultLegacy(Markdown);
|
|
16
18
|
var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
|
|
17
19
|
var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
|
|
18
|
-
var Markdown__default = /*#__PURE__*/_interopDefaultLegacy(Markdown);
|
|
19
20
|
|
|
20
21
|
function _defineProperties(target, props) {
|
|
21
22
|
for (var i = 0; i < props.length; i++) {
|
|
@@ -152,6 +153,31 @@
|
|
|
152
153
|
_this._handleAddClick(event, index);
|
|
153
154
|
};
|
|
154
155
|
};
|
|
156
|
+
_this.onCopyIndexClick = function (index) {
|
|
157
|
+
return function (event) {
|
|
158
|
+
if (event) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
}
|
|
161
|
+
var onChange = _this.props.onChange;
|
|
162
|
+
var keyedFormData = _this.state.keyedFormData;
|
|
163
|
+
var newKeyedFormDataRow = {
|
|
164
|
+
key: generateRowId(),
|
|
165
|
+
item: cloneDeep__default["default"](keyedFormData[index].item)
|
|
166
|
+
};
|
|
167
|
+
var newKeyedFormData = [].concat(keyedFormData);
|
|
168
|
+
if (index !== undefined) {
|
|
169
|
+
newKeyedFormData.splice(index + 1, 0, newKeyedFormDataRow);
|
|
170
|
+
} else {
|
|
171
|
+
newKeyedFormData.push(newKeyedFormDataRow);
|
|
172
|
+
}
|
|
173
|
+
_this.setState({
|
|
174
|
+
keyedFormData: newKeyedFormData,
|
|
175
|
+
updatedKeyedFormData: true
|
|
176
|
+
}, function () {
|
|
177
|
+
return onChange(keyedToPlainFormData(newKeyedFormData));
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
};
|
|
155
181
|
_this.onDropIndexClick = function (index) {
|
|
156
182
|
return function (event) {
|
|
157
183
|
if (event) {
|
|
@@ -311,8 +337,9 @@
|
|
|
311
337
|
_proto.canAddItem = function canAddItem(formItems) {
|
|
312
338
|
var _this$props6 = this.props,
|
|
313
339
|
schema = _this$props6.schema,
|
|
314
|
-
uiSchema = _this$props6.uiSchema
|
|
315
|
-
|
|
340
|
+
uiSchema = _this$props6.uiSchema,
|
|
341
|
+
registry = _this$props6.registry;
|
|
342
|
+
var _getUiOptions = utils.getUiOptions(uiSchema, registry.globalUiOptions),
|
|
316
343
|
addable = _getUiOptions.addable;
|
|
317
344
|
if (addable !== false) {
|
|
318
345
|
// if ui:options.addable was not explicitly set to false, we can add
|
|
@@ -754,10 +781,8 @@
|
|
|
754
781
|
canAdd = props.canAdd,
|
|
755
782
|
_props$canRemove = props.canRemove,
|
|
756
783
|
canRemove = _props$canRemove === void 0 ? true : _props$canRemove,
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
_props$canMoveDown = props.canMoveDown,
|
|
760
|
-
canMoveDown = _props$canMoveDown === void 0 ? true : _props$canMoveDown,
|
|
784
|
+
canMoveUp = props.canMoveUp,
|
|
785
|
+
canMoveDown = props.canMoveDown,
|
|
761
786
|
itemSchema = props.itemSchema,
|
|
762
787
|
itemData = props.itemData,
|
|
763
788
|
itemUiSchema = props.itemUiSchema,
|
|
@@ -779,16 +804,20 @@
|
|
|
779
804
|
formContext = _this$props13.formContext;
|
|
780
805
|
var _registry$fields = registry.fields,
|
|
781
806
|
ArraySchemaField = _registry$fields.ArraySchemaField,
|
|
782
|
-
SchemaField = _registry$fields.SchemaField
|
|
807
|
+
SchemaField = _registry$fields.SchemaField,
|
|
808
|
+
globalUiOptions = registry.globalUiOptions;
|
|
783
809
|
var ItemSchemaField = ArraySchemaField || SchemaField;
|
|
784
|
-
var _getUiOptions5 = utils.getUiOptions(uiSchema),
|
|
810
|
+
var _getUiOptions5 = utils.getUiOptions(uiSchema, globalUiOptions),
|
|
785
811
|
_getUiOptions5$ordera = _getUiOptions5.orderable,
|
|
786
812
|
orderable = _getUiOptions5$ordera === void 0 ? true : _getUiOptions5$ordera,
|
|
787
813
|
_getUiOptions5$remova = _getUiOptions5.removable,
|
|
788
|
-
removable = _getUiOptions5$remova === void 0 ? true : _getUiOptions5$remova
|
|
814
|
+
removable = _getUiOptions5$remova === void 0 ? true : _getUiOptions5$remova,
|
|
815
|
+
_getUiOptions5$copyab = _getUiOptions5.copyable,
|
|
816
|
+
copyable = _getUiOptions5$copyab === void 0 ? false : _getUiOptions5$copyab;
|
|
789
817
|
var has = {
|
|
790
818
|
moveUp: orderable && canMoveUp,
|
|
791
819
|
moveDown: orderable && canMoveDown,
|
|
820
|
+
copy: copyable && canAdd,
|
|
792
821
|
remove: removable && canRemove,
|
|
793
822
|
toolbar: false
|
|
794
823
|
};
|
|
@@ -821,6 +850,7 @@
|
|
|
821
850
|
className: 'array-item',
|
|
822
851
|
disabled: disabled,
|
|
823
852
|
canAdd: canAdd,
|
|
853
|
+
hasCopy: has.copy,
|
|
824
854
|
hasToolbar: has.toolbar,
|
|
825
855
|
hasMoveUp: has.moveUp,
|
|
826
856
|
hasMoveDown: has.moveDown,
|
|
@@ -829,6 +859,7 @@
|
|
|
829
859
|
totalItems: totalItems,
|
|
830
860
|
key: key,
|
|
831
861
|
onAddIndexClick: this.onAddIndexClick,
|
|
862
|
+
onCopyIndexClick: this.onCopyIndexClick,
|
|
832
863
|
onDropIndexClick: this.onDropIndexClick,
|
|
833
864
|
onReorderClick: this.onReorderClick,
|
|
834
865
|
readonly: readonly,
|
|
@@ -1281,8 +1312,10 @@
|
|
|
1281
1312
|
};
|
|
1282
1313
|
};
|
|
1283
1314
|
_this.getAvailableKey = function (preferredKey, formData) {
|
|
1284
|
-
var
|
|
1285
|
-
|
|
1315
|
+
var _this$props3 = _this.props,
|
|
1316
|
+
uiSchema = _this$props3.uiSchema,
|
|
1317
|
+
registry = _this$props3.registry;
|
|
1318
|
+
var _getUiOptions = utils.getUiOptions(uiSchema, registry.globalUiOptions),
|
|
1286
1319
|
_getUiOptions$duplica = _getUiOptions.duplicateKeySuffixSeparator,
|
|
1287
1320
|
duplicateKeySuffixSeparator = _getUiOptions$duplica === void 0 ? '-' : _getUiOptions$duplica;
|
|
1288
1321
|
var index = 0;
|
|
@@ -1298,10 +1331,10 @@
|
|
|
1298
1331
|
if (oldValue === value) {
|
|
1299
1332
|
return;
|
|
1300
1333
|
}
|
|
1301
|
-
var _this$
|
|
1302
|
-
formData = _this$
|
|
1303
|
-
onChange = _this$
|
|
1304
|
-
errorSchema = _this$
|
|
1334
|
+
var _this$props4 = _this.props,
|
|
1335
|
+
formData = _this$props4.formData,
|
|
1336
|
+
onChange = _this$props4.onChange,
|
|
1337
|
+
errorSchema = _this$props4.errorSchema;
|
|
1305
1338
|
value = _this.getAvailableKey(value, formData);
|
|
1306
1339
|
var newFormData = _extends({}, formData);
|
|
1307
1340
|
var newKeys = (_newKeys = {}, _newKeys[oldValue] = value, _newKeys);
|
|
@@ -1322,10 +1355,10 @@
|
|
|
1322
1355
|
if (!schema.additionalProperties) {
|
|
1323
1356
|
return;
|
|
1324
1357
|
}
|
|
1325
|
-
var _this$
|
|
1326
|
-
formData = _this$
|
|
1327
|
-
onChange = _this$
|
|
1328
|
-
registry = _this$
|
|
1358
|
+
var _this$props5 = _this.props,
|
|
1359
|
+
formData = _this$props5.formData,
|
|
1360
|
+
onChange = _this$props5.onChange,
|
|
1361
|
+
registry = _this$props5.registry;
|
|
1329
1362
|
var newFormData = _extends({}, formData);
|
|
1330
1363
|
var type = undefined;
|
|
1331
1364
|
if (isObject__default["default"](schema.additionalProperties)) {
|
|
@@ -1400,35 +1433,36 @@
|
|
|
1400
1433
|
*/
|
|
1401
1434
|
_proto.render = function render() {
|
|
1402
1435
|
var _this2 = this;
|
|
1403
|
-
var _this$
|
|
1404
|
-
rawSchema = _this$
|
|
1405
|
-
_this$
|
|
1406
|
-
uiSchema = _this$
|
|
1407
|
-
formData = _this$
|
|
1408
|
-
errorSchema = _this$
|
|
1409
|
-
idSchema = _this$
|
|
1410
|
-
name = _this$
|
|
1411
|
-
_this$
|
|
1412
|
-
required = _this$
|
|
1413
|
-
_this$
|
|
1414
|
-
disabled = _this$
|
|
1415
|
-
_this$
|
|
1416
|
-
readonly = _this$
|
|
1417
|
-
hideError = _this$
|
|
1418
|
-
idPrefix = _this$
|
|
1419
|
-
idSeparator = _this$
|
|
1420
|
-
onBlur = _this$
|
|
1421
|
-
onFocus = _this$
|
|
1422
|
-
registry = _this$
|
|
1436
|
+
var _this$props6 = this.props,
|
|
1437
|
+
rawSchema = _this$props6.schema,
|
|
1438
|
+
_this$props6$uiSchema = _this$props6.uiSchema,
|
|
1439
|
+
uiSchema = _this$props6$uiSchema === void 0 ? {} : _this$props6$uiSchema,
|
|
1440
|
+
formData = _this$props6.formData,
|
|
1441
|
+
errorSchema = _this$props6.errorSchema,
|
|
1442
|
+
idSchema = _this$props6.idSchema,
|
|
1443
|
+
name = _this$props6.name,
|
|
1444
|
+
_this$props6$required = _this$props6.required,
|
|
1445
|
+
required = _this$props6$required === void 0 ? false : _this$props6$required,
|
|
1446
|
+
_this$props6$disabled = _this$props6.disabled,
|
|
1447
|
+
disabled = _this$props6$disabled === void 0 ? false : _this$props6$disabled,
|
|
1448
|
+
_this$props6$readonly = _this$props6.readonly,
|
|
1449
|
+
readonly = _this$props6$readonly === void 0 ? false : _this$props6$readonly,
|
|
1450
|
+
hideError = _this$props6.hideError,
|
|
1451
|
+
idPrefix = _this$props6.idPrefix,
|
|
1452
|
+
idSeparator = _this$props6.idSeparator,
|
|
1453
|
+
onBlur = _this$props6.onBlur,
|
|
1454
|
+
onFocus = _this$props6.onFocus,
|
|
1455
|
+
registry = _this$props6.registry;
|
|
1423
1456
|
var fields = registry.fields,
|
|
1424
1457
|
formContext = registry.formContext,
|
|
1425
|
-
schemaUtils = registry.schemaUtils
|
|
1458
|
+
schemaUtils = registry.schemaUtils,
|
|
1459
|
+
translateString = registry.translateString;
|
|
1426
1460
|
var SchemaField = fields.SchemaField;
|
|
1427
1461
|
var schema = schemaUtils.retrieveSchema(rawSchema, formData);
|
|
1428
1462
|
var uiOptions = utils.getUiOptions(uiSchema);
|
|
1429
1463
|
var _schema$properties = schema.properties,
|
|
1430
1464
|
schemaProperties = _schema$properties === void 0 ? {} : _schema$properties;
|
|
1431
|
-
var title = schema.title === undefined ? name : schema.title;
|
|
1465
|
+
var title = uiOptions.title || (schema.title === undefined ? name : schema.title);
|
|
1432
1466
|
var description = uiOptions.description || schema.description;
|
|
1433
1467
|
var orderedProperties;
|
|
1434
1468
|
try {
|
|
@@ -1436,14 +1470,14 @@
|
|
|
1436
1470
|
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
1437
1471
|
} catch (err) {
|
|
1438
1472
|
return jsxRuntime.jsxs("div", {
|
|
1439
|
-
children: [jsxRuntime.
|
|
1473
|
+
children: [jsxRuntime.jsx("p", {
|
|
1440
1474
|
className: 'config-error',
|
|
1441
1475
|
style: {
|
|
1442
1476
|
color: 'red'
|
|
1443
1477
|
},
|
|
1444
|
-
children:
|
|
1445
|
-
children: err.message
|
|
1446
|
-
})
|
|
1478
|
+
children: jsxRuntime.jsx(Markdown__default["default"], {
|
|
1479
|
+
children: translateString(utils.TranslatableString.InvalidObjectField, [name || 'root', err.message])
|
|
1480
|
+
})
|
|
1447
1481
|
}), jsxRuntime.jsx("pre", {
|
|
1448
1482
|
children: JSON.stringify(schema)
|
|
1449
1483
|
})]
|
|
@@ -1451,7 +1485,7 @@
|
|
|
1451
1485
|
}
|
|
1452
1486
|
var Template = utils.getTemplate('ObjectFieldTemplate', registry, uiOptions);
|
|
1453
1487
|
var templateProps = {
|
|
1454
|
-
title:
|
|
1488
|
+
title: title,
|
|
1455
1489
|
description: description,
|
|
1456
1490
|
properties: orderedProperties.map(function (name) {
|
|
1457
1491
|
var addedByAdditionalProperties = has__default["default"](schema, [utils.PROPERTIES_KEY, name, utils.ADDITIONAL_PROPERTY_FLAG]);
|
|
@@ -1579,8 +1613,9 @@
|
|
|
1579
1613
|
_props$wasPropertyKey = props.wasPropertyKeyModified,
|
|
1580
1614
|
wasPropertyKeyModified = _props$wasPropertyKey === void 0 ? false : _props$wasPropertyKey;
|
|
1581
1615
|
var formContext = registry.formContext,
|
|
1582
|
-
schemaUtils = registry.schemaUtils
|
|
1583
|
-
|
|
1616
|
+
schemaUtils = registry.schemaUtils,
|
|
1617
|
+
globalUiOptions = registry.globalUiOptions;
|
|
1618
|
+
var uiOptions = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1584
1619
|
var FieldTemplate = utils.getTemplate('FieldTemplate', registry, uiOptions);
|
|
1585
1620
|
var DescriptionFieldTemplate = utils.getTemplate('DescriptionFieldTemplate', registry, uiOptions);
|
|
1586
1621
|
var FieldHelpTemplate = utils.getTemplate('FieldHelpTemplate', registry, uiOptions);
|
|
@@ -1605,7 +1640,7 @@
|
|
|
1605
1640
|
if (Object.keys(schema).length === 0) {
|
|
1606
1641
|
return null;
|
|
1607
1642
|
}
|
|
1608
|
-
var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
|
|
1643
|
+
var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1609
1644
|
var _ref = errorSchema || {},
|
|
1610
1645
|
__errors = _ref.__errors,
|
|
1611
1646
|
fieldErrorSchema = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
@@ -1902,13 +1937,16 @@
|
|
|
1902
1937
|
hasMoveDown = props.hasMoveDown,
|
|
1903
1938
|
hasMoveUp = props.hasMoveUp,
|
|
1904
1939
|
hasRemove = props.hasRemove,
|
|
1940
|
+
hasCopy = props.hasCopy,
|
|
1905
1941
|
index = props.index,
|
|
1942
|
+
onCopyIndexClick = props.onCopyIndexClick,
|
|
1906
1943
|
onDropIndexClick = props.onDropIndexClick,
|
|
1907
1944
|
onReorderClick = props.onReorderClick,
|
|
1908
1945
|
readonly = props.readonly,
|
|
1909
1946
|
registry = props.registry,
|
|
1910
1947
|
uiSchema = props.uiSchema;
|
|
1911
1948
|
var _registry$templates$B = registry.templates.ButtonTemplates,
|
|
1949
|
+
CopyButton = _registry$templates$B.CopyButton,
|
|
1912
1950
|
MoveDownButton = _registry$templates$B.MoveDownButton,
|
|
1913
1951
|
MoveUpButton = _registry$templates$B.MoveUpButton,
|
|
1914
1952
|
RemoveButton = _registry$templates$B.RemoveButton;
|
|
@@ -1943,6 +1981,12 @@
|
|
|
1943
1981
|
onClick: onReorderClick(index, index + 1),
|
|
1944
1982
|
uiSchema: uiSchema,
|
|
1945
1983
|
registry: registry
|
|
1984
|
+
}), hasCopy && jsxRuntime.jsx(CopyButton, {
|
|
1985
|
+
style: btnStyle,
|
|
1986
|
+
disabled: disabled || readonly,
|
|
1987
|
+
onClick: onCopyIndexClick(index),
|
|
1988
|
+
uiSchema: uiSchema,
|
|
1989
|
+
registry: registry
|
|
1946
1990
|
}), hasRemove && jsxRuntime.jsx(RemoveButton, {
|
|
1947
1991
|
style: btnStyle,
|
|
1948
1992
|
disabled: disabled || readonly,
|
|
@@ -2151,6 +2195,15 @@
|
|
|
2151
2195
|
})
|
|
2152
2196
|
}));
|
|
2153
2197
|
}
|
|
2198
|
+
function CopyButton(props) {
|
|
2199
|
+
var translateString = props.registry.translateString;
|
|
2200
|
+
return jsxRuntime.jsx(IconButton, _extends({
|
|
2201
|
+
title: translateString(utils.TranslatableString.CopyButton),
|
|
2202
|
+
className: 'array-item-copy'
|
|
2203
|
+
}, props, {
|
|
2204
|
+
icon: 'copy'
|
|
2205
|
+
}));
|
|
2206
|
+
}
|
|
2154
2207
|
function MoveDownButton(props) {
|
|
2155
2208
|
var translateString = props.registry.translateString;
|
|
2156
2209
|
return jsxRuntime.jsx(IconButton, _extends({
|
|
@@ -2209,6 +2262,7 @@
|
|
|
2209
2262
|
return {
|
|
2210
2263
|
SubmitButton: SubmitButton,
|
|
2211
2264
|
AddButton: AddButton,
|
|
2265
|
+
CopyButton: CopyButton,
|
|
2212
2266
|
MoveDownButton: MoveDownButton,
|
|
2213
2267
|
MoveUpButton: MoveUpButton,
|
|
2214
2268
|
RemoveButton: RemoveButton
|
|
@@ -2690,22 +2744,25 @@
|
|
|
2690
2744
|
onChange = _ref2.onChange,
|
|
2691
2745
|
value = _ref2.value;
|
|
2692
2746
|
var translateString = registry.translateString;
|
|
2747
|
+
var _useState = react.useState(value),
|
|
2748
|
+
lastValue = _useState[0],
|
|
2749
|
+
setLastValue = _useState[1];
|
|
2693
2750
|
var _useReducer = react.useReducer(function (state, action) {
|
|
2694
2751
|
return _extends({}, state, action);
|
|
2695
2752
|
}, utils.parseDateString(value, time)),
|
|
2696
2753
|
state = _useReducer[0],
|
|
2697
2754
|
setState = _useReducer[1];
|
|
2698
2755
|
react.useEffect(function () {
|
|
2699
|
-
|
|
2756
|
+
var stateValue = utils.toDateString(state, time);
|
|
2757
|
+
if (readyForChange(state) && stateValue !== value) {
|
|
2758
|
+
// The user changed the date to a new valid data via the comboboxes, so call onChange
|
|
2759
|
+
onChange(stateValue);
|
|
2760
|
+
} else if (lastValue !== value) {
|
|
2761
|
+
// We got a new value in the props
|
|
2762
|
+
setLastValue(value);
|
|
2700
2763
|
setState(utils.parseDateString(value, time));
|
|
2701
2764
|
}
|
|
2702
|
-
}, [value, state,
|
|
2703
|
-
react.useEffect(function () {
|
|
2704
|
-
if (readyForChange(state)) {
|
|
2705
|
-
// Only propagate to parent state if we have a complete date{time}
|
|
2706
|
-
onChange(utils.toDateString(state, time));
|
|
2707
|
-
}
|
|
2708
|
-
}, [state, time, onChange]);
|
|
2765
|
+
}, [time, value, onChange, state, lastValue]);
|
|
2709
2766
|
var handleChange = react.useCallback(function (property, value) {
|
|
2710
2767
|
var _setState;
|
|
2711
2768
|
setState((_setState = {}, _setState[property] = value, _setState));
|
|
@@ -2715,17 +2772,16 @@
|
|
|
2715
2772
|
if (disabled || readonly) {
|
|
2716
2773
|
return;
|
|
2717
2774
|
}
|
|
2718
|
-
var
|
|
2719
|
-
|
|
2775
|
+
var nextState = utils.parseDateString(new Date().toJSON(), time);
|
|
2776
|
+
onChange(utils.toDateString(nextState, time));
|
|
2720
2777
|
}, [disabled, readonly, time]);
|
|
2721
2778
|
var handleClear = react.useCallback(function (event) {
|
|
2722
2779
|
event.preventDefault();
|
|
2723
2780
|
if (disabled || readonly) {
|
|
2724
2781
|
return;
|
|
2725
2782
|
}
|
|
2726
|
-
setState(utils.parseDateString('', time));
|
|
2727
2783
|
onChange(undefined);
|
|
2728
|
-
}, [disabled, readonly,
|
|
2784
|
+
}, [disabled, readonly, onChange]);
|
|
2729
2785
|
return jsxRuntime.jsxs("ul", {
|
|
2730
2786
|
className: 'list-inline',
|
|
2731
2787
|
children: [dateElementProps(state, time, options.yearsRange).map(function (elemProps, i) {
|
|
@@ -3369,6 +3425,26 @@
|
|
|
3369
3425
|
return jsxRuntime.jsx(BaseInputTemplate, _extends({}, props));
|
|
3370
3426
|
}
|
|
3371
3427
|
|
|
3428
|
+
/** The `TimeWidget` component uses the `BaseInputTemplate` changing the type to `time` and transforms
|
|
3429
|
+
* the value to undefined when it is falsy during the `onChange` handling.
|
|
3430
|
+
*
|
|
3431
|
+
* @param props - The `WidgetProps` for this component
|
|
3432
|
+
*/
|
|
3433
|
+
function TimeWidget(props) {
|
|
3434
|
+
var onChange = props.onChange,
|
|
3435
|
+
options = props.options,
|
|
3436
|
+
registry = props.registry;
|
|
3437
|
+
var BaseInputTemplate = utils.getTemplate('BaseInputTemplate', registry, options);
|
|
3438
|
+
var handleChange = react.useCallback(function (value) {
|
|
3439
|
+
return onChange(value ? value + ":00" : undefined);
|
|
3440
|
+
}, [onChange]);
|
|
3441
|
+
return jsxRuntime.jsx(BaseInputTemplate, _extends({
|
|
3442
|
+
type: 'time'
|
|
3443
|
+
}, props, {
|
|
3444
|
+
onChange: handleChange
|
|
3445
|
+
}));
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3372
3448
|
/** The `URLWidget` component uses the `BaseInputTemplate` changing the type to `url`.
|
|
3373
3449
|
*
|
|
3374
3450
|
* @param props - The `WidgetProps` for this component
|
|
@@ -3397,24 +3473,25 @@
|
|
|
3397
3473
|
|
|
3398
3474
|
function widgets() {
|
|
3399
3475
|
return {
|
|
3476
|
+
AltDateWidget: AltDateWidget,
|
|
3477
|
+
AltDateTimeWidget: AltDateTimeWidget,
|
|
3478
|
+
CheckboxWidget: CheckboxWidget,
|
|
3479
|
+
CheckboxesWidget: CheckboxesWidget,
|
|
3480
|
+
ColorWidget: ColorWidget,
|
|
3481
|
+
DateWidget: DateWidget,
|
|
3482
|
+
DateTimeWidget: DateTimeWidget,
|
|
3483
|
+
EmailWidget: EmailWidget,
|
|
3484
|
+
FileWidget: FileWidget,
|
|
3485
|
+
HiddenWidget: HiddenWidget,
|
|
3400
3486
|
PasswordWidget: PasswordWidget,
|
|
3401
3487
|
RadioWidget: RadioWidget,
|
|
3402
|
-
UpDownWidget: UpDownWidget,
|
|
3403
3488
|
RangeWidget: RangeWidget,
|
|
3404
3489
|
SelectWidget: SelectWidget,
|
|
3405
3490
|
TextWidget: TextWidget,
|
|
3406
|
-
DateWidget: DateWidget,
|
|
3407
|
-
DateTimeWidget: DateTimeWidget,
|
|
3408
|
-
AltDateWidget: AltDateWidget,
|
|
3409
|
-
AltDateTimeWidget: AltDateTimeWidget,
|
|
3410
|
-
EmailWidget: EmailWidget,
|
|
3411
|
-
URLWidget: URLWidget,
|
|
3412
3491
|
TextareaWidget: TextareaWidget,
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
CheckboxWidget: CheckboxWidget,
|
|
3417
|
-
CheckboxesWidget: CheckboxesWidget
|
|
3492
|
+
TimeWidget: TimeWidget,
|
|
3493
|
+
UpDownWidget: UpDownWidget,
|
|
3494
|
+
URLWidget: URLWidget
|
|
3418
3495
|
};
|
|
3419
3496
|
}
|
|
3420
3497
|
|
|
@@ -3558,6 +3635,21 @@
|
|
|
3558
3635
|
return onChange && onChange(_extends({}, _this.state, state), id);
|
|
3559
3636
|
});
|
|
3560
3637
|
};
|
|
3638
|
+
_this.reset = function () {
|
|
3639
|
+
var onChange = _this.props.onChange;
|
|
3640
|
+
var newState = _this.getStateFromProps(_this.props, undefined);
|
|
3641
|
+
var newFormData = newState.formData;
|
|
3642
|
+
var state = {
|
|
3643
|
+
formData: newFormData,
|
|
3644
|
+
errorSchema: {},
|
|
3645
|
+
errors: [],
|
|
3646
|
+
schemaValidationErrors: [],
|
|
3647
|
+
schemaValidationErrorSchema: {}
|
|
3648
|
+
};
|
|
3649
|
+
_this.setState(state, function () {
|
|
3650
|
+
return onChange && onChange(_extends({}, _this.state, state));
|
|
3651
|
+
});
|
|
3652
|
+
};
|
|
3561
3653
|
_this.onBlur = function (id, data) {
|
|
3562
3654
|
var onBlur = _this.props.onBlur;
|
|
3563
3655
|
if (onBlur) {
|
|
@@ -3771,7 +3863,10 @@
|
|
|
3771
3863
|
/** Returns the registry for the form */
|
|
3772
3864
|
_proto.getRegistry = function getRegistry() {
|
|
3773
3865
|
var _this$props$templates;
|
|
3774
|
-
var
|
|
3866
|
+
var _this$props4 = this.props,
|
|
3867
|
+
customTranslateString = _this$props4.translateString,
|
|
3868
|
+
_this$props4$uiSchema = _this$props4.uiSchema,
|
|
3869
|
+
uiSchema = _this$props4$uiSchema === void 0 ? {} : _this$props4$uiSchema;
|
|
3775
3870
|
var schemaUtils = this.state.schemaUtils;
|
|
3776
3871
|
var _getDefaultRegistry = getDefaultRegistry(),
|
|
3777
3872
|
fields = _getDefaultRegistry.fields,
|
|
@@ -3788,7 +3883,8 @@
|
|
|
3788
3883
|
rootSchema: this.props.schema,
|
|
3789
3884
|
formContext: this.props.formContext || formContext,
|
|
3790
3885
|
schemaUtils: schemaUtils,
|
|
3791
|
-
translateString: customTranslateString || translateString
|
|
3886
|
+
translateString: customTranslateString || translateString,
|
|
3887
|
+
globalUiOptions: uiSchema[utils.UI_GLOBAL_OPTIONS_KEY]
|
|
3792
3888
|
};
|
|
3793
3889
|
}
|
|
3794
3890
|
/** Provides a function that can be used to programmatically submit the `Form` */;
|
|
@@ -3807,11 +3903,11 @@
|
|
|
3807
3903
|
* @param error - The error on which to focus
|
|
3808
3904
|
*/;
|
|
3809
3905
|
_proto.focusOnError = function focusOnError(error) {
|
|
3810
|
-
var _this$
|
|
3811
|
-
_this$
|
|
3812
|
-
idPrefix = _this$
|
|
3813
|
-
_this$
|
|
3814
|
-
idSeparator = _this$
|
|
3906
|
+
var _this$props5 = this.props,
|
|
3907
|
+
_this$props5$idPrefix = _this$props5.idPrefix,
|
|
3908
|
+
idPrefix = _this$props5$idPrefix === void 0 ? 'root' : _this$props5$idPrefix,
|
|
3909
|
+
_this$props5$idSepara = _this$props5.idSeparator,
|
|
3910
|
+
idSeparator = _this$props5$idSepara === void 0 ? '_' : _this$props5$idSepara;
|
|
3815
3911
|
var property = error.property;
|
|
3816
3912
|
var path = _toPath__default["default"](property);
|
|
3817
3913
|
if (path[0] === '') {
|
|
@@ -3837,10 +3933,10 @@
|
|
|
3837
3933
|
* @returns - True if the form is valid, false otherwise.
|
|
3838
3934
|
*/;
|
|
3839
3935
|
_proto.validateForm = function validateForm() {
|
|
3840
|
-
var _this$
|
|
3841
|
-
extraErrors = _this$
|
|
3842
|
-
focusOnFirstError = _this$
|
|
3843
|
-
onError = _this$
|
|
3936
|
+
var _this$props6 = this.props,
|
|
3937
|
+
extraErrors = _this$props6.extraErrors,
|
|
3938
|
+
focusOnFirstError = _this$props6.focusOnFirstError,
|
|
3939
|
+
onError = _this$props6.onError;
|
|
3844
3940
|
var formData = this.state.formData;
|
|
3845
3941
|
var schemaUtils = this.state.schemaUtils;
|
|
3846
3942
|
var schemaValidation = this.validate(formData);
|
|
@@ -3877,31 +3973,31 @@
|
|
|
3877
3973
|
* needed along with the submit button or any children of the form.
|
|
3878
3974
|
*/;
|
|
3879
3975
|
_proto.render = function render() {
|
|
3880
|
-
var _this$
|
|
3881
|
-
children = _this$
|
|
3882
|
-
id = _this$
|
|
3883
|
-
idPrefix = _this$
|
|
3884
|
-
idSeparator = _this$
|
|
3885
|
-
_this$
|
|
3886
|
-
className = _this$
|
|
3887
|
-
tagName = _this$
|
|
3888
|
-
name = _this$
|
|
3889
|
-
method = _this$
|
|
3890
|
-
target = _this$
|
|
3891
|
-
action = _this$
|
|
3892
|
-
autoComplete = _this$
|
|
3893
|
-
enctype = _this$
|
|
3894
|
-
acceptcharset = _this$
|
|
3895
|
-
_this$
|
|
3896
|
-
noHtml5Validate = _this$
|
|
3897
|
-
_this$
|
|
3898
|
-
disabled = _this$
|
|
3899
|
-
_this$
|
|
3900
|
-
readonly = _this$
|
|
3901
|
-
formContext = _this$
|
|
3902
|
-
_this$
|
|
3903
|
-
showErrorList = _this$
|
|
3904
|
-
_internalFormWrapper = _this$
|
|
3976
|
+
var _this$props7 = this.props,
|
|
3977
|
+
children = _this$props7.children,
|
|
3978
|
+
id = _this$props7.id,
|
|
3979
|
+
idPrefix = _this$props7.idPrefix,
|
|
3980
|
+
idSeparator = _this$props7.idSeparator,
|
|
3981
|
+
_this$props7$classNam = _this$props7.className,
|
|
3982
|
+
className = _this$props7$classNam === void 0 ? '' : _this$props7$classNam,
|
|
3983
|
+
tagName = _this$props7.tagName,
|
|
3984
|
+
name = _this$props7.name,
|
|
3985
|
+
method = _this$props7.method,
|
|
3986
|
+
target = _this$props7.target,
|
|
3987
|
+
action = _this$props7.action,
|
|
3988
|
+
autoComplete = _this$props7.autoComplete,
|
|
3989
|
+
enctype = _this$props7.enctype,
|
|
3990
|
+
acceptcharset = _this$props7.acceptcharset,
|
|
3991
|
+
_this$props7$noHtml5V = _this$props7.noHtml5Validate,
|
|
3992
|
+
noHtml5Validate = _this$props7$noHtml5V === void 0 ? false : _this$props7$noHtml5V,
|
|
3993
|
+
_this$props7$disabled = _this$props7.disabled,
|
|
3994
|
+
disabled = _this$props7$disabled === void 0 ? false : _this$props7$disabled,
|
|
3995
|
+
_this$props7$readonly = _this$props7.readonly,
|
|
3996
|
+
readonly = _this$props7$readonly === void 0 ? false : _this$props7$readonly,
|
|
3997
|
+
formContext = _this$props7.formContext,
|
|
3998
|
+
_this$props7$showErro = _this$props7.showErrorList,
|
|
3999
|
+
showErrorList = _this$props7$showErro === void 0 ? 'top' : _this$props7$showErro,
|
|
4000
|
+
_internalFormWrapper = _this$props7._internalFormWrapper;
|
|
3905
4001
|
var _this$state4 = this.state,
|
|
3906
4002
|
schema = _this$state4.schema,
|
|
3907
4003
|
uiSchema = _this$state4.uiSchema,
|