@rjsf/core 2.2.1 → 2.4.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.
@@ -50,31 +50,6 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
50
50
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
51
51
 
52
52
  function DefaultObjectFieldTemplate(props) {
53
- var canExpand = function canExpand() {
54
- var formData = props.formData,
55
- schema = props.schema,
56
- uiSchema = props.uiSchema;
57
-
58
- if (!schema.additionalProperties) {
59
- return false;
60
- }
61
-
62
- var _getUiOptions = (0, _utils.getUiOptions)(uiSchema),
63
- expandable = _getUiOptions.expandable;
64
-
65
- if (expandable === false) {
66
- return expandable;
67
- } // if ui:options.expandable was not explicitly set to false, we can add
68
- // another property if we have not exceeded maxProperties yet
69
-
70
-
71
- if (schema.maxProperties !== undefined) {
72
- return Object.keys(formData).length < schema.maxProperties;
73
- }
74
-
75
- return true;
76
- };
77
-
78
53
  var TitleField = props.TitleField,
79
54
  DescriptionField = props.DescriptionField;
80
55
  return _react["default"].createElement("fieldset", {
@@ -90,7 +65,7 @@ function DefaultObjectFieldTemplate(props) {
90
65
  formContext: props.formContext
91
66
  }), props.properties.map(function (prop) {
92
67
  return prop.content;
93
- }), canExpand() && _react["default"].createElement(_AddButton["default"], {
68
+ }), (0, _utils.canExpand)(props.schema, props.uiSchema, props.formData) && _react["default"].createElement(_AddButton["default"], {
94
69
  className: "object-property-expand",
95
70
  onClick: props.onAddClick(props.schema),
96
71
  disabled: props.disabled || props.readonly
@@ -314,7 +314,6 @@ function SchemaFieldRender(props) {
314
314
  rawErrors: __errors
315
315
  }));
316
316
 
317
- var type = schema.type;
318
317
  var id = idSchema.$id; // If this schema has a title defined, but the user has set a new key/label, retain their input.
319
318
 
320
319
  var label;
@@ -329,7 +328,7 @@ function SchemaFieldRender(props) {
329
328
  var errors = __errors;
330
329
  var help = uiSchema["ui:help"];
331
330
  var hidden = uiSchema["ui:widget"] === "hidden";
332
- var classNames = ["form-group", "field", "field-".concat(type), errors && errors.length > 0 ? "field-error has-error has-danger" : "", uiSchema.classNames].join(" ").trim();
331
+ var classNames = ["form-group", "field", "field-".concat(schema.type), errors && errors.length > 0 ? "field-error has-error has-danger" : "", uiSchema.classNames].join(" ").trim();
333
332
  var fieldProps = {
334
333
  description: _react["default"].createElement(DescriptionField, {
335
334
  id: id + "__description",
@@ -9,36 +9,9 @@ var _react = _interopRequireDefault(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- // Check to see if a schema specifies that a value must be true
15
- function schemaRequiresTrueValue(schema) {
16
- // Check if const is a truthy value
17
- if (schema["const"]) {
18
- return true;
19
- } // Check if an enum has a single value of true
20
-
21
-
22
- if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
23
- return true;
24
- } // If anyOf has a single value, evaluate the subschema
25
-
26
-
27
- if (schema.anyOf && schema.anyOf.length === 1) {
28
- return schemaRequiresTrueValue(schema.anyOf[0]);
29
- } // If oneOf has a single value, evaluate the subschema
12
+ var _utils = require("../../utils");
30
13
 
31
-
32
- if (schema.oneOf && schema.oneOf.length === 1) {
33
- return schemaRequiresTrueValue(schema.oneOf[0]);
34
- } // Evaluate each subschema in allOf, to see if one of them requires a true
35
- // value
36
-
37
-
38
- if (schema.allOf) {
39
- return schema.allOf.some(schemaRequiresTrueValue);
40
- }
41
- }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
42
15
 
43
16
  function CheckboxWidget(props) {
44
17
  var schema = props.schema,
@@ -55,7 +28,7 @@ function CheckboxWidget(props) {
55
28
  // the "required" attribute if the field value must be "true", due to the
56
29
  // "const" or "enum" keywords
57
30
 
58
- var required = schemaRequiresTrueValue(schema);
31
+ var required = (0, _utils.schemaRequiresTrueValue)(schema);
59
32
  return _react["default"].createElement("div", {
60
33
  className: "checkbox ".concat(disabled || readonly ? "disabled" : "")
61
34
  }, schema.description && _react["default"].createElement(DescriptionField, {
package/dist/cjs/utils.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.canExpand = canExpand;
6
7
  exports.getDefaultRegistry = getDefaultRegistry;
7
8
  exports.getSchemaType = getSchemaType;
8
9
  exports.getWidget = getWidget;
@@ -40,6 +41,7 @@ exports.pad = pad;
40
41
  exports.dataURItoBlob = dataURItoBlob;
41
42
  exports.rangeSpec = rangeSpec;
42
43
  exports.getMatchingOption = getMatchingOption;
44
+ exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
43
45
  exports.guessType = exports.ADDITIONAL_PROPERTY_FLAG = void 0;
44
46
 
45
47
  var _react = _interopRequireDefault(require("react"));
@@ -50,12 +52,16 @@ var _jsonSchemaMergeAllof = _interopRequireDefault(require("json-schema-merge-al
50
52
 
51
53
  var _fill = _interopRequireDefault(require("core-js/library/fn/array/fill"));
52
54
 
53
- var _validate = _interopRequireWildcard(require("./validate"));
54
-
55
55
  var _union = _interopRequireDefault(require("lodash/union"));
56
56
 
57
57
  var _jsonpointer = _interopRequireDefault(require("jsonpointer"));
58
58
 
59
+ var _fields = _interopRequireDefault(require("./components/fields"));
60
+
61
+ var _widgets = _interopRequireDefault(require("./components/widgets"));
62
+
63
+ var _validate = _interopRequireWildcard(require("./validate"));
64
+
59
65
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
60
66
 
61
67
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -138,10 +144,31 @@ var widgetMap = {
138
144
  }
139
145
  };
140
146
 
147
+ function canExpand(schema, uiSchema, formData) {
148
+ if (!schema.additionalProperties) {
149
+ return false;
150
+ }
151
+
152
+ var _getUiOptions = getUiOptions(uiSchema),
153
+ expandable = _getUiOptions.expandable;
154
+
155
+ if (expandable === false) {
156
+ return expandable;
157
+ } // if ui:options.expandable was not explicitly set to false, we can add
158
+ // another property if we have not exceeded maxProperties yet
159
+
160
+
161
+ if (schema.maxProperties !== undefined) {
162
+ return Object.keys(formData).length < schema.maxProperties;
163
+ }
164
+
165
+ return true;
166
+ }
167
+
141
168
  function getDefaultRegistry() {
142
169
  return {
143
- fields: require("./components/fields")["default"],
144
- widgets: require("./components/widgets")["default"],
170
+ fields: _fields["default"],
171
+ widgets: _widgets["default"],
145
172
  definitions: {},
146
173
  rootSchema: {},
147
174
  formContext: {}
@@ -1275,4 +1302,35 @@ function getMatchingOption(formData, options, rootSchema) {
1275
1302
  }
1276
1303
 
1277
1304
  return 0;
1305
+ } // Check to see if a schema specifies that a value must be true
1306
+
1307
+
1308
+ function schemaRequiresTrueValue(schema) {
1309
+ // Check if const is a truthy value
1310
+ if (schema["const"]) {
1311
+ return true;
1312
+ } // Check if an enum has a single value of true
1313
+
1314
+
1315
+ if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
1316
+ return true;
1317
+ } // If anyOf has a single value, evaluate the subschema
1318
+
1319
+
1320
+ if (schema.anyOf && schema.anyOf.length === 1) {
1321
+ return schemaRequiresTrueValue(schema.anyOf[0]);
1322
+ } // If oneOf has a single value, evaluate the subschema
1323
+
1324
+
1325
+ if (schema.oneOf && schema.oneOf.length === 1) {
1326
+ return schemaRequiresTrueValue(schema.oneOf[0]);
1327
+ } // Evaluate each subschema in allOf, to see if one of them requires a true
1328
+ // value
1329
+
1330
+
1331
+ if (schema.allOf) {
1332
+ return schema.allOf.some(schemaRequiresTrueValue);
1333
+ }
1334
+
1335
+ return false;
1278
1336
  }
@@ -2,6 +2,7 @@ import _JSON$stringify from "@babel/runtime-corejs2/core-js/json/stringify";
2
2
  import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
3
3
  import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray";
4
4
  import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
5
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
5
6
  import _objectSpread from "@babel/runtime-corejs2/helpers/esm/objectSpread";
6
7
  import _classCallCheck from "@babel/runtime-corejs2/helpers/esm/classCallCheck";
7
8
  import _createClass from "@babel/runtime-corejs2/helpers/esm/createClass";
@@ -10,38 +11,12 @@ import _getPrototypeOf from "@babel/runtime-corejs2/helpers/esm/getPrototypeOf";
10
11
  import _assertThisInitialized from "@babel/runtime-corejs2/helpers/esm/assertThisInitialized";
11
12
  import _inherits from "@babel/runtime-corejs2/helpers/esm/inherits";
12
13
  import _defineProperty from "@babel/runtime-corejs2/helpers/esm/defineProperty";
13
- import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
14
14
  import AddButton from "../AddButton";
15
15
  import React, { Component } from "react";
16
16
  import * as types from "../../types";
17
- import { orderProperties, retrieveSchema, getDefaultRegistry, getUiOptions, ADDITIONAL_PROPERTY_FLAG } from "../../utils";
17
+ import { orderProperties, retrieveSchema, getDefaultRegistry, canExpand, ADDITIONAL_PROPERTY_FLAG } from "../../utils";
18
18
 
19
19
  function DefaultObjectFieldTemplate(props) {
20
- var canExpand = function canExpand() {
21
- var formData = props.formData,
22
- schema = props.schema,
23
- uiSchema = props.uiSchema;
24
-
25
- if (!schema.additionalProperties) {
26
- return false;
27
- }
28
-
29
- var _getUiOptions = getUiOptions(uiSchema),
30
- expandable = _getUiOptions.expandable;
31
-
32
- if (expandable === false) {
33
- return expandable;
34
- } // if ui:options.expandable was not explicitly set to false, we can add
35
- // another property if we have not exceeded maxProperties yet
36
-
37
-
38
- if (schema.maxProperties !== undefined) {
39
- return _Object$keys(formData).length < schema.maxProperties;
40
- }
41
-
42
- return true;
43
- };
44
-
45
20
  var TitleField = props.TitleField,
46
21
  DescriptionField = props.DescriptionField;
47
22
  return React.createElement("fieldset", {
@@ -57,7 +32,7 @@ function DefaultObjectFieldTemplate(props) {
57
32
  formContext: props.formContext
58
33
  }), props.properties.map(function (prop) {
59
34
  return prop.content;
60
- }), canExpand() && React.createElement(AddButton, {
35
+ }), canExpand(props.schema, props.uiSchema, props.formData) && React.createElement(AddButton, {
61
36
  className: "object-property-expand",
62
37
  onClick: props.onAddClick(props.schema),
63
38
  disabled: props.disabled || props.readonly
@@ -278,7 +278,6 @@ function SchemaFieldRender(props) {
278
278
  formContext: formContext,
279
279
  rawErrors: __errors
280
280
  }));
281
- var type = schema.type;
282
281
  var id = idSchema.$id; // If this schema has a title defined, but the user has set a new key/label, retain their input.
283
282
 
284
283
  var label;
@@ -293,7 +292,7 @@ function SchemaFieldRender(props) {
293
292
  var errors = __errors;
294
293
  var help = uiSchema["ui:help"];
295
294
  var hidden = uiSchema["ui:widget"] === "hidden";
296
- var classNames = ["form-group", "field", "field-".concat(type), errors && errors.length > 0 ? "field-error has-error has-danger" : "", uiSchema.classNames].join(" ").trim();
295
+ var classNames = ["form-group", "field", "field-".concat(schema.type), errors && errors.length > 0 ? "field-error has-error has-danger" : "", uiSchema.classNames].join(" ").trim();
297
296
  var fieldProps = {
298
297
  description: React.createElement(DescriptionField, {
299
298
  id: id + "__description",
@@ -1,33 +1,6 @@
1
1
  import React from "react";
2
- import PropTypes from "prop-types"; // Check to see if a schema specifies that a value must be true
3
-
4
- function schemaRequiresTrueValue(schema) {
5
- // Check if const is a truthy value
6
- if (schema["const"]) {
7
- return true;
8
- } // Check if an enum has a single value of true
9
-
10
-
11
- if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
12
- return true;
13
- } // If anyOf has a single value, evaluate the subschema
14
-
15
-
16
- if (schema.anyOf && schema.anyOf.length === 1) {
17
- return schemaRequiresTrueValue(schema.anyOf[0]);
18
- } // If oneOf has a single value, evaluate the subschema
19
-
20
-
21
- if (schema.oneOf && schema.oneOf.length === 1) {
22
- return schemaRequiresTrueValue(schema.oneOf[0]);
23
- } // Evaluate each subschema in allOf, to see if one of them requires a true
24
- // value
25
-
26
-
27
- if (schema.allOf) {
28
- return schema.allOf.some(schemaRequiresTrueValue);
29
- }
30
- }
2
+ import PropTypes from "prop-types";
3
+ import { schemaRequiresTrueValue } from "../../utils";
31
4
 
32
5
  function CheckboxWidget(props) {
33
6
  var schema = props.schema,
package/dist/es/utils.js CHANGED
@@ -4,12 +4,12 @@ import _Array$from from "@babel/runtime-corejs2/core-js/array/from";
4
4
  import _toConsumableArray from "@babel/runtime-corejs2/helpers/esm/toConsumableArray";
5
5
  import _Number$isNaN from "@babel/runtime-corejs2/core-js/number/is-nan";
6
6
  import _defineProperty from "@babel/runtime-corejs2/helpers/esm/defineProperty";
7
- import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
8
7
  import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
9
8
  import _typeof from "@babel/runtime-corejs2/helpers/esm/typeof";
10
9
  import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
11
10
  import _objectSpread from "@babel/runtime-corejs2/helpers/esm/objectSpread";
12
11
  import _objectWithoutProperties from "@babel/runtime-corejs2/helpers/esm/objectWithoutProperties";
12
+ import _Object$keys from "@babel/runtime-corejs2/core-js/object/keys";
13
13
 
14
14
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
15
 
@@ -19,9 +19,11 @@ import React from "react";
19
19
  import * as ReactIs from "react-is";
20
20
  import mergeAllOf from "json-schema-merge-allof";
21
21
  import fill from "core-js/library/fn/array/fill";
22
- import validateFormData, { isValid } from "./validate";
23
22
  import union from "lodash/union";
24
23
  import jsonpointer from "jsonpointer";
24
+ import fields from "./components/fields";
25
+ import widgets from "./components/widgets";
26
+ import validateFormData, { isValid } from "./validate";
25
27
  export var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
26
28
  var widgetMap = {
27
29
  "boolean": {
@@ -74,10 +76,30 @@ var widgetMap = {
74
76
  hidden: "HiddenWidget"
75
77
  }
76
78
  };
79
+ export function canExpand(schema, uiSchema, formData) {
80
+ if (!schema.additionalProperties) {
81
+ return false;
82
+ }
83
+
84
+ var _getUiOptions = getUiOptions(uiSchema),
85
+ expandable = _getUiOptions.expandable;
86
+
87
+ if (expandable === false) {
88
+ return expandable;
89
+ } // if ui:options.expandable was not explicitly set to false, we can add
90
+ // another property if we have not exceeded maxProperties yet
91
+
92
+
93
+ if (schema.maxProperties !== undefined) {
94
+ return _Object$keys(formData).length < schema.maxProperties;
95
+ }
96
+
97
+ return true;
98
+ }
77
99
  export function getDefaultRegistry() {
78
100
  return {
79
- fields: require("./components/fields")["default"],
80
- widgets: require("./components/widgets")["default"],
101
+ fields: fields,
102
+ widgets: widgets,
81
103
  definitions: {},
82
104
  rootSchema: {},
83
105
  formContext: {}
@@ -1180,4 +1202,34 @@ export function getMatchingOption(formData, options, rootSchema) {
1180
1202
  }
1181
1203
 
1182
1204
  return 0;
1205
+ } // Check to see if a schema specifies that a value must be true
1206
+
1207
+ export function schemaRequiresTrueValue(schema) {
1208
+ // Check if const is a truthy value
1209
+ if (schema["const"]) {
1210
+ return true;
1211
+ } // Check if an enum has a single value of true
1212
+
1213
+
1214
+ if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
1215
+ return true;
1216
+ } // If anyOf has a single value, evaluate the subschema
1217
+
1218
+
1219
+ if (schema.anyOf && schema.anyOf.length === 1) {
1220
+ return schemaRequiresTrueValue(schema.anyOf[0]);
1221
+ } // If oneOf has a single value, evaluate the subschema
1222
+
1223
+
1224
+ if (schema.oneOf && schema.oneOf.length === 1) {
1225
+ return schemaRequiresTrueValue(schema.oneOf[0]);
1226
+ } // Evaluate each subschema in allOf, to see if one of them requires a true
1227
+ // value
1228
+
1229
+
1230
+ if (schema.allOf) {
1231
+ return schema.allOf.some(schemaRequiresTrueValue);
1232
+ }
1233
+
1234
+ return false;
1183
1235
  }