react-jsonschema-form-extras 0.9.67 → 0.9.71

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.
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
+
7
9
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
10
 
9
11
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -18,6 +20,8 @@ var _propTypes = require("prop-types");
18
20
 
19
21
  var _propTypes2 = _interopRequireDefault(_propTypes);
20
22
 
23
+ var _utils2 = require("./utils");
24
+
21
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
26
 
23
27
  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; }
@@ -90,55 +94,63 @@ var CollapseMenuAction = function (_Component) {
90
94
  }(_react.Component);
91
95
 
92
96
  function CollapseMenu(props) {
93
- var _props$uiSchema$colla = props.uiSchema.collapse,
94
- _props$uiSchema$colla2 = _props$uiSchema$colla.icon;
95
- _props$uiSchema$colla2 = _props$uiSchema$colla2 === undefined ? {} : _props$uiSchema$colla2;
96
- var _props$uiSchema$colla3 = _props$uiSchema$colla2.enabled,
97
- enabled = _props$uiSchema$colla3 === undefined ? "glyphicon glyphicon-chevron-down" : _props$uiSchema$colla3,
98
- _props$uiSchema$colla4 = _props$uiSchema$colla2.disabled,
99
- disabled = _props$uiSchema$colla4 === undefined ? "glyphicon glyphicon-chevron-right" : _props$uiSchema$colla4,
100
- _props$uiSchema$colla5 = _props$uiSchema$colla2.add,
101
- add = _props$uiSchema$colla5 === undefined ? "glyphicon glyphicon-plus-sign" : _props$uiSchema$colla5,
102
- _props$uiSchema$colla6 = _props$uiSchema$colla.separate,
103
- separate = _props$uiSchema$colla6 === undefined ? true : _props$uiSchema$colla6,
104
- addTo = _props$uiSchema$colla.addTo,
105
- _props$uiSchema$colla7 = _props$uiSchema$colla.wrapClassName,
106
- wrapClassName = _props$uiSchema$colla7 === undefined ? "lead" : _props$uiSchema$colla7,
107
- _props$uiSchema$colla8 = _props$uiSchema$colla.actions,
108
- actions = _props$uiSchema$colla8 === undefined ? [] : _props$uiSchema$colla8,
109
- _props$uiSchema$colla9 = _props$uiSchema$colla.classNames,
110
- classNames = _props$uiSchema$colla9 === undefined ? "collapsibleHeading" : _props$uiSchema$colla9,
111
- _props$uiSchema$colla10 = _props$uiSchema$colla.collapseDivStyles;
112
- _props$uiSchema$colla10 = _props$uiSchema$colla10 === undefined ? {} : _props$uiSchema$colla10;
113
- var _props$uiSchema$colla11 = _props$uiSchema$colla10.textColor,
114
- textColor = _props$uiSchema$colla11 === undefined ? "white" : _props$uiSchema$colla11,
115
- _props$uiSchema$colla12 = _props$uiSchema$colla10.background,
116
- background = _props$uiSchema$colla12 === undefined ? "linear-gradient(to right, #0472B6, white)" : _props$uiSchema$colla12,
117
- _props$uiSchema$colla13 = _props$uiSchema$colla10.collapseGlyphColor,
118
- collapseGlyphColor = _props$uiSchema$colla13 === undefined ? "white" : _props$uiSchema$colla13,
119
- _props$uiSchema$colla14 = _props$uiSchema$colla10.addGlyphColor,
120
- addGlyphColor = _props$uiSchema$colla14 === undefined ? "white" : _props$uiSchema$colla14,
121
- _props$uiSchema$colla15 = _props$uiSchema$colla10.padding,
122
- padding = _props$uiSchema$colla15 === undefined ? "14px" : _props$uiSchema$colla15,
123
- _props$uiSchema$colla16 = _props$uiSchema$colla10.margin,
124
- margin = _props$uiSchema$colla16 === undefined ? "" : _props$uiSchema$colla16,
125
- _props$uiSchema$colla17 = _props$uiSchema$colla10.marginLeft,
126
- marginLeft = _props$uiSchema$colla17 === undefined ? "-5px" : _props$uiSchema$colla17,
127
- _props$uiSchema$colla18 = _props$uiSchema$colla10.marginBottom,
128
- marginBottom = _props$uiSchema$colla18 === undefined ? "5px" : _props$uiSchema$colla18,
129
- _props$uiSchema$colla19 = _props$uiSchema$colla10.zIndex,
130
- zIndex = _props$uiSchema$colla19 === undefined ? -1 : _props$uiSchema$colla19,
131
- _props$uiSchema$colla20 = _props$uiSchema$colla10.divCursor,
132
- divCursor = _props$uiSchema$colla20 === undefined ? "pointer" : _props$uiSchema$colla20,
133
- _props$uiSchema$colla21 = _props$uiSchema$colla10.addCursor,
134
- addCursor = _props$uiSchema$colla21 === undefined ? "copy" : _props$uiSchema$colla21,
97
+ var headerElementsSchemas = props.headerElementsSchemas,
98
+ uiSchema = props.uiSchema,
135
99
  _props$formContext = props.formContext,
136
100
  formContext = _props$formContext === undefined ? {} : _props$formContext,
101
+ _props$formData = props.formData,
102
+ formData = _props$formData === undefined ? {} : _props$formData,
137
103
  onChange = props.onChange,
138
104
  onAdd = props.onAdd,
139
105
  title = props.title,
140
106
  name = props.name,
141
- collapsed = props.collapsed;
107
+ collapsed = props.collapsed,
108
+ fields = props.fields,
109
+ propsOnChange = props.propsOnChange;
110
+ var _uiSchema$collapse = uiSchema.collapse,
111
+ _uiSchema$collapse$co = _uiSchema$collapse.collapsibleHeaderElements,
112
+ collapsibleHeaderElements = _uiSchema$collapse$co === undefined ? {} : _uiSchema$collapse$co,
113
+ _uiSchema$collapse$ic = _uiSchema$collapse.icon;
114
+ _uiSchema$collapse$ic = _uiSchema$collapse$ic === undefined ? {} : _uiSchema$collapse$ic;
115
+ var _uiSchema$collapse$ic2 = _uiSchema$collapse$ic.enabled,
116
+ enabled = _uiSchema$collapse$ic2 === undefined ? "glyphicon glyphicon-chevron-down" : _uiSchema$collapse$ic2,
117
+ _uiSchema$collapse$ic3 = _uiSchema$collapse$ic.disabled,
118
+ disabled = _uiSchema$collapse$ic3 === undefined ? "glyphicon glyphicon-chevron-right" : _uiSchema$collapse$ic3,
119
+ _uiSchema$collapse$ic4 = _uiSchema$collapse$ic.add,
120
+ add = _uiSchema$collapse$ic4 === undefined ? "glyphicon glyphicon-plus-sign" : _uiSchema$collapse$ic4,
121
+ _uiSchema$collapse$se = _uiSchema$collapse.separate,
122
+ separate = _uiSchema$collapse$se === undefined ? true : _uiSchema$collapse$se,
123
+ addTo = _uiSchema$collapse.addTo,
124
+ _uiSchema$collapse$wr = _uiSchema$collapse.wrapClassName,
125
+ wrapClassName = _uiSchema$collapse$wr === undefined ? "lead" : _uiSchema$collapse$wr,
126
+ _uiSchema$collapse$ac = _uiSchema$collapse.actions,
127
+ actions = _uiSchema$collapse$ac === undefined ? [] : _uiSchema$collapse$ac,
128
+ _uiSchema$collapse$cl = _uiSchema$collapse.classNames,
129
+ classNames = _uiSchema$collapse$cl === undefined ? "collapsibleHeading" : _uiSchema$collapse$cl,
130
+ _uiSchema$collapse$co2 = _uiSchema$collapse.collapseDivStyles;
131
+ _uiSchema$collapse$co2 = _uiSchema$collapse$co2 === undefined ? {} : _uiSchema$collapse$co2;
132
+ var _uiSchema$collapse$co3 = _uiSchema$collapse$co2.textColor,
133
+ textColor = _uiSchema$collapse$co3 === undefined ? "white" : _uiSchema$collapse$co3,
134
+ _uiSchema$collapse$co4 = _uiSchema$collapse$co2.background,
135
+ background = _uiSchema$collapse$co4 === undefined ? "linear-gradient(to right, #0472B6, white)" : _uiSchema$collapse$co4,
136
+ _uiSchema$collapse$co5 = _uiSchema$collapse$co2.collapseGlyphColor,
137
+ collapseGlyphColor = _uiSchema$collapse$co5 === undefined ? "white" : _uiSchema$collapse$co5,
138
+ _uiSchema$collapse$co6 = _uiSchema$collapse$co2.addGlyphColor,
139
+ addGlyphColor = _uiSchema$collapse$co6 === undefined ? "white" : _uiSchema$collapse$co6,
140
+ _uiSchema$collapse$co7 = _uiSchema$collapse$co2.padding,
141
+ padding = _uiSchema$collapse$co7 === undefined ? "14px" : _uiSchema$collapse$co7,
142
+ _uiSchema$collapse$co8 = _uiSchema$collapse$co2.margin,
143
+ margin = _uiSchema$collapse$co8 === undefined ? "" : _uiSchema$collapse$co8,
144
+ _uiSchema$collapse$co9 = _uiSchema$collapse$co2.marginLeft,
145
+ marginLeft = _uiSchema$collapse$co9 === undefined ? "-5px" : _uiSchema$collapse$co9,
146
+ _uiSchema$collapse$co10 = _uiSchema$collapse$co2.marginBottom,
147
+ marginBottom = _uiSchema$collapse$co10 === undefined ? "5px" : _uiSchema$collapse$co10,
148
+ _uiSchema$collapse$co11 = _uiSchema$collapse$co2.zIndex,
149
+ zIndex = _uiSchema$collapse$co11 === undefined ? -1 : _uiSchema$collapse$co11,
150
+ _uiSchema$collapse$co12 = _uiSchema$collapse$co2.divCursor,
151
+ divCursor = _uiSchema$collapse$co12 === undefined ? "pointer" : _uiSchema$collapse$co12,
152
+ _uiSchema$collapse$co13 = _uiSchema$collapse$co2.addCursor,
153
+ addCursor = _uiSchema$collapse$co13 === undefined ? "copy" : _uiSchema$collapse$co13;
142
154
 
143
155
 
144
156
  var handleAdd = function handleAdd(event) {
@@ -146,6 +158,38 @@ function CollapseMenu(props) {
146
158
  onAdd(event);
147
159
  };
148
160
 
161
+ var headerElements = [];
162
+ var _collapsibleHeaderEle = collapsibleHeaderElements.className,
163
+ headerElementsWrapperClass = _collapsibleHeaderEle === undefined ? "header-element-wrapper" : _collapsibleHeaderEle;
164
+
165
+
166
+ Object.keys(headerElementsSchemas).map(function (key) {
167
+ var fieldSchema = headerElementsSchemas[key];
168
+ var fieldName = (0, _utils2.getFieldName)(fieldSchema.type);
169
+
170
+ if (fieldName) {
171
+ var FieldElement = fields[fieldName];
172
+ var fieldId = "" + key;
173
+ var fieldUiSchema = uiSchema[key];
174
+ var fieldFormData = formData[key];
175
+
176
+ var elementOnChange = function elementOnChange(value, options) {
177
+ formData[key] = value;
178
+ propsOnChange(formData, options);
179
+ };
180
+
181
+ headerElements.push(_react2.default.createElement(FieldElement, {
182
+ formContext: formContext,
183
+ formData: fieldFormData,
184
+ idSchema: { $id: fieldId },
185
+ key: key,
186
+ onChange: elementOnChange,
187
+ schema: fieldSchema,
188
+ uiSchema: fieldUiSchema
189
+ }));
190
+ }
191
+ });
192
+
149
193
  return _react2.default.createElement(
150
194
  "div",
151
195
  { className: "" + wrapClassName },
@@ -186,6 +230,16 @@ function CollapseMenu(props) {
186
230
  className: collapsed ? disabled : enabled
187
231
  })
188
232
  ),
233
+ !!headerElements.length && _react2.default.createElement(
234
+ "div",
235
+ {
236
+ className: headerElementsWrapperClass,
237
+ onClick: function onClick(event) {
238
+ return event.stopPropagation();
239
+ }
240
+ },
241
+ headerElements
242
+ ),
189
243
  actions.map(function (action, i) {
190
244
  return _react2.default.createElement(CollapseMenuAction, {
191
245
  key: i,
@@ -315,9 +369,9 @@ var CollapsibleField = function (_Component5) {
315
369
  formData = _this3$props.formData,
316
370
  fields = _this3$props.registry.fields,
317
371
  formContext = _this3$props.formContext;
318
- var _uiSchema$collapse = uiSchema.collapse,
319
- addTo = _uiSchema$collapse.addTo,
320
- addElement = _uiSchema$collapse.addElement;
372
+ var _uiSchema$collapse2 = uiSchema.collapse,
373
+ addTo = _uiSchema$collapse2.addTo,
374
+ addElement = _uiSchema$collapse2.addElement;
321
375
 
322
376
 
323
377
  var fieldSchema = addTo === "self" ? schema.items : schema.properties ? schema.properties[addTo] ? schema.properties[addTo].items : null : null;
@@ -367,10 +421,10 @@ var CollapsibleField = function (_Component5) {
367
421
  });
368
422
  };
369
423
 
370
- var _props$uiSchema$colla22 = props.uiSchema.collapse;
371
- _props$uiSchema$colla22 = _props$uiSchema$colla22 === undefined ? {} : _props$uiSchema$colla22;
372
- var _props$uiSchema$colla23 = _props$uiSchema$colla22.collapsed,
373
- collapsed = _props$uiSchema$colla23 === undefined ? true : _props$uiSchema$colla23;
424
+ var _props$uiSchema$colla = props.uiSchema.collapse;
425
+ _props$uiSchema$colla = _props$uiSchema$colla === undefined ? {} : _props$uiSchema$colla;
426
+ var _props$uiSchema$colla2 = _props$uiSchema$colla.collapsed,
427
+ collapsed = _props$uiSchema$colla2 === undefined ? true : _props$uiSchema$colla2;
374
428
 
375
429
 
376
430
  _this3.state = { collapsed: collapsed };
@@ -378,45 +432,95 @@ var CollapsibleField = function (_Component5) {
378
432
  }
379
433
 
380
434
  _createClass(CollapsibleField, [{
435
+ key: "componentDidCatch",
436
+ value: function componentDidCatch(error, errorInfo) {
437
+ // You can also log the error to an error reporting service
438
+ console.log({ error: error, errorInfo: errorInfo });
439
+ }
440
+ }, {
381
441
  key: "render",
382
442
  value: function render() {
383
443
  var _props3 = this.props,
384
- title = _props3.schema.title,
444
+ _props3$schema = _props3.schema,
445
+ title = _props3$schema.title,
446
+ _props3$schema$proper = _props3$schema.properties,
447
+ properties = _props3$schema$proper === undefined ? {} : _props3$schema$proper,
385
448
  uiSchema = _props3.uiSchema,
386
449
  fields = _props3.registry.fields,
387
450
  _props3$idSchema = _props3.idSchema;
388
451
  _props3$idSchema = _props3$idSchema === undefined ? {} : _props3$idSchema;
389
452
  var $id = _props3$idSchema.$id,
390
453
  name = _props3.name,
391
- formContext = _props3.formContext;
454
+ formContext = _props3.formContext,
455
+ formData = _props3.formData,
456
+ propsOnChange = _props3.onChange;
392
457
  var _state = this.state,
393
458
  collapsed = _state.collapsed,
394
459
  AddElement = _state.AddElement;
395
- var field = uiSchema.collapse.field;
460
+ var _uiSchema$collapse3 = uiSchema.collapse,
461
+ _uiSchema$collapse3$c = _uiSchema$collapse3.collapsibleHeaderElements,
462
+ collapsibleHeaderElements = _uiSchema$collapse3$c === undefined ? {} : _uiSchema$collapse3$c,
463
+ field = _uiSchema$collapse3.field;
396
464
 
397
465
  var CollapseElement = fields[field];
398
- // uischema retains the value form the state
466
+ var _collapsibleHeaderEle2 = collapsibleHeaderElements.elements,
467
+ elements = _collapsibleHeaderEle2 === undefined ? [] : _collapsibleHeaderEle2;
468
+ // uischema retains the value for the state
469
+
399
470
  uiSchema.collapse.collapsed = this.state.collapsed;
400
471
 
401
472
  title = uiSchema["ui:title"] ? uiSchema["ui:title"] : title ? title : name;
402
473
  var customizedId = collapsed ? $id : undefined;
474
+
475
+ //remove header elements from the schema
476
+ var headerElementsSchemas = {};
477
+ var propertiesNoHeader = _extends({}, properties);
478
+ var orderNoHeader = uiSchema["ui:order"];
479
+
480
+ if (orderNoHeader && orderNoHeader.filter) {
481
+ orderNoHeader = orderNoHeader.filter(function (x) {
482
+ return elements.indexOf(x) < 0;
483
+ });
484
+ } else if (orderNoHeader) {
485
+ orderNoHeader = [orderNoHeader].filter(function (x) {
486
+ return elements.indexOf(x) < 0;
487
+ });
488
+ }
489
+
490
+ elements.forEach(function (key) {
491
+ if (propertiesNoHeader[key]) {
492
+ headerElementsSchemas[key] = propertiesNoHeader[key];
493
+ delete propertiesNoHeader[key];
494
+ }
495
+ });
496
+
497
+ var collapseElementProps = _extends({}, this.props, {
498
+ schema: _extends({}, this.props.schema, { properties: propertiesNoHeader }),
499
+ uiSchema: _extends({}, this.props.uiSchema, { "ui:order": orderNoHeader })
500
+ });
501
+
403
502
  return _react2.default.createElement(
404
503
  "div",
405
504
  { id: customizedId },
406
505
  _react2.default.createElement(CollapseMenu, {
506
+ headerElementsSchemas: headerElementsSchemas,
507
+ collapsibleFieldId: $id,
407
508
  title: title,
408
509
  uiSchema: uiSchema,
409
510
  collapsed: collapsed,
410
511
  formContext: formContext,
512
+ formData: formData,
513
+ fields: fields,
411
514
  onAdd: this.handleAdd,
412
- onChange: this.handleCollapsed
515
+ onChange: this.handleCollapsed,
516
+ propsOnChange: propsOnChange
413
517
  }),
414
518
  _react2.default.createElement(
415
519
  "div",
416
520
  { className: "form-group" },
417
521
  AddElement && _react2.default.createElement(AddElement, null),
418
522
  !collapsed && _react2.default.createElement(CollapseLegend, this.props),
419
- !collapsed && _react2.default.createElement(CollapseElement, this.props)
523
+ !collapsed && _react2.default.createElement(CollapseElement, collapseElementProps)
420
524
  )
421
525
  );
422
526
  }