@maif/react-forms 1.0.22 → 1.0.26
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/.github/workflows/release.yml +1 -1
- package/README.md +5 -1
- package/dist/react-form.js +1 -1
- package/lib/form.js +251 -86
- package/lib/inputs/SelectInput.js +5 -2
- package/lib/style.d.ts +30 -23
- package/lib/style.js +10 -1
- package/lib/styleContext.d.ts +1 -1
- package/package.json +1 -1
package/lib/form.js
CHANGED
|
@@ -41,6 +41,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
41
41
|
|
|
42
42
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
43
43
|
|
|
44
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
45
|
+
|
|
46
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
47
|
+
|
|
48
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
49
|
+
|
|
50
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
51
|
+
|
|
44
52
|
function _extends() { _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; }; return _extends.apply(this, arguments); }
|
|
45
53
|
|
|
46
54
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -163,12 +171,16 @@ var defaultVal = function defaultVal(t, array, defaultValue) {
|
|
|
163
171
|
|
|
164
172
|
var getDefaultValues = function getDefaultValues(flow, schema) {
|
|
165
173
|
return flow.reduce(function (acc, key) {
|
|
166
|
-
var entry = schema[key];
|
|
167
|
-
|
|
168
174
|
if (_typeof(key) === 'object') {
|
|
169
175
|
return _objectSpread(_objectSpread({}, acc), getDefaultValues(key.flow, schema));
|
|
170
176
|
}
|
|
171
177
|
|
|
178
|
+
var entry = schema[key];
|
|
179
|
+
|
|
180
|
+
if (!entry) {
|
|
181
|
+
return acc;
|
|
182
|
+
}
|
|
183
|
+
|
|
172
184
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, defaultVal(entry.type, entry.array || entry.isMulti, entry.defaultValue)));
|
|
173
185
|
}, {});
|
|
174
186
|
};
|
|
@@ -238,7 +250,7 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
238
250
|
}
|
|
239
251
|
|
|
240
252
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, v));
|
|
241
|
-
} else if (!!v && _typeof(v) === 'object') {
|
|
253
|
+
} else if (!!v && _typeof(v) === 'object' && !(v instanceof Date)) {
|
|
242
254
|
var _subSchema$key;
|
|
243
255
|
|
|
244
256
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, cleanInputArray(v, ((_subSchema$key = subSchema[key]) === null || _subSchema$key === void 0 ? void 0 : _subSchema$key.schema) || {})));
|
|
@@ -269,7 +281,7 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, v));
|
|
272
|
-
} else if (!!v && _typeof(v) === 'object') {
|
|
284
|
+
} else if (!!v && _typeof(v) === 'object' && !(v instanceof Date)) {
|
|
273
285
|
var _subSchema$key2;
|
|
274
286
|
|
|
275
287
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, cleanOutputArray(v, ((_subSchema$key2 = subSchema[key]) === null || _subSchema$key2 === void 0 ? void 0 : _subSchema$key2.schema) || {})));
|
|
@@ -335,6 +347,18 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
335
347
|
}
|
|
336
348
|
};
|
|
337
349
|
});
|
|
350
|
+
|
|
351
|
+
var functionalProperty = function functionalProperty(entry, prop) {
|
|
352
|
+
if (typeof prop === 'function') {
|
|
353
|
+
return prop({
|
|
354
|
+
rawValues: getValues(),
|
|
355
|
+
value: getValues(entry)
|
|
356
|
+
});
|
|
357
|
+
} else {
|
|
358
|
+
return prop;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
338
362
|
return /*#__PURE__*/_react["default"].createElement(_reactHookForm.FormProvider, methods, /*#__PURE__*/_react["default"].createElement("form", {
|
|
339
363
|
className: className || "".concat(classes.pr_15, " ").concat(classes.full_width),
|
|
340
364
|
onSubmit: _handleSubmit(function (data) {
|
|
@@ -343,6 +367,12 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
343
367
|
}, onError)
|
|
344
368
|
}, formFlow.map(function (entry, idx) {
|
|
345
369
|
var step = schema[entry];
|
|
370
|
+
|
|
371
|
+
if (!step && typeof entry === 'string') {
|
|
372
|
+
console.error("no step found for the entry \"".concat(entry, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
|
|
346
376
|
var error = _typeof(entry) === 'object' ? undefined : entry.split('.').reduce(function (object, key) {
|
|
347
377
|
return object && object[key];
|
|
348
378
|
}, errors);
|
|
@@ -373,7 +403,7 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
373
403
|
key: "".concat(entry, "-").concat(idx),
|
|
374
404
|
entry: entry,
|
|
375
405
|
error: error,
|
|
376
|
-
label: (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry,
|
|
406
|
+
label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
|
|
377
407
|
help: step === null || step === void 0 ? void 0 : step.help,
|
|
378
408
|
render: inputWrapper
|
|
379
409
|
}, /*#__PURE__*/_react["default"].createElement(Step, {
|
|
@@ -390,7 +420,8 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
|
390
420
|
setValue: setValue,
|
|
391
421
|
watch: watch,
|
|
392
422
|
inputWrapper: inputWrapper,
|
|
393
|
-
httpClient: maybeCustomHttpClient
|
|
423
|
+
httpClient: maybeCustomHttpClient,
|
|
424
|
+
functionalProperty: functionalProperty
|
|
394
425
|
}));
|
|
395
426
|
}), /*#__PURE__*/_react["default"].createElement(Footer, {
|
|
396
427
|
render: footer,
|
|
@@ -455,7 +486,8 @@ var Step = function Step(_ref4) {
|
|
|
455
486
|
inputWrapper = _ref4.inputWrapper,
|
|
456
487
|
httpClient = _ref4.httpClient,
|
|
457
488
|
defaultValue = _ref4.defaultValue,
|
|
458
|
-
index = _ref4.index
|
|
489
|
+
index = _ref4.index,
|
|
490
|
+
functionalProperty = _ref4.functionalProperty;
|
|
459
491
|
var classes = (0, _styleContext.useCustomStyle)();
|
|
460
492
|
|
|
461
493
|
if (entry && _typeof(entry) === 'object') {
|
|
@@ -469,6 +501,12 @@ var Step = function Step(_ref4) {
|
|
|
469
501
|
var err = _typeof(en) === 'object' ? undefined : en.split('.').reduce(function (object, key) {
|
|
470
502
|
return object && object[key];
|
|
471
503
|
}, errors);
|
|
504
|
+
|
|
505
|
+
if (!stp && typeof en === 'string') {
|
|
506
|
+
console.error("no step found for the entry \"".concat(en, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
|
|
472
510
|
var visibleStep = (0, _Option.option)(stp).map(function (s) {
|
|
473
511
|
return s.visible;
|
|
474
512
|
}).map(function (visible) {
|
|
@@ -495,7 +533,7 @@ var Step = function Step(_ref4) {
|
|
|
495
533
|
key: "collapse-".concat(en, "-").concat(entryIdx),
|
|
496
534
|
entry: en,
|
|
497
535
|
error: err,
|
|
498
|
-
label: (stp === null || stp === void 0 ? void 0 : stp.label) === null ? null : (stp === null || stp === void 0 ? void 0 : stp.label) || en,
|
|
536
|
+
label: functionalProperty(en, (stp === null || stp === void 0 ? void 0 : stp.label) === null ? null : (stp === null || stp === void 0 ? void 0 : stp.label) || en),
|
|
499
537
|
help: stp === null || stp === void 0 ? void 0 : stp.help,
|
|
500
538
|
render: inputWrapper
|
|
501
539
|
}, /*#__PURE__*/_react["default"].createElement(Step, {
|
|
@@ -512,7 +550,8 @@ var Step = function Step(_ref4) {
|
|
|
512
550
|
watch: watch,
|
|
513
551
|
inputWrapper: inputWrapper,
|
|
514
552
|
httpClient: httpClient,
|
|
515
|
-
defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue
|
|
553
|
+
defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue,
|
|
554
|
+
functionalProperty: functionalProperty
|
|
516
555
|
}));
|
|
517
556
|
}));
|
|
518
557
|
}
|
|
@@ -528,12 +567,15 @@ var Step = function Step(_ref4) {
|
|
|
528
567
|
setValue: _setValue,
|
|
529
568
|
values: getValues(entry),
|
|
530
569
|
defaultValue: step.defaultValue || defaultVal(step.type),
|
|
570
|
+
getValues: getValues,
|
|
571
|
+
disabled: functionalProperty(entry, step.disabled),
|
|
531
572
|
component: function component(props, idx) {
|
|
532
573
|
var _error$idx;
|
|
533
574
|
|
|
534
575
|
return /*#__PURE__*/_react["default"].createElement(Step, {
|
|
535
576
|
entry: "".concat(entry, "[").concat(idx, "].value"),
|
|
536
577
|
step: _objectSpread(_objectSpread({}, schema[realEntry || entry]), {}, {
|
|
578
|
+
onChange: undefined,
|
|
537
579
|
array: false
|
|
538
580
|
}),
|
|
539
581
|
error: error && ((_error$idx = error[idx]) === null || _error$idx === void 0 ? void 0 : _error$idx.value),
|
|
@@ -548,12 +590,28 @@ var Step = function Step(_ref4) {
|
|
|
548
590
|
httpClient: httpClient,
|
|
549
591
|
defaultValue: props.defaultValue,
|
|
550
592
|
value: props.value,
|
|
551
|
-
index: idx
|
|
593
|
+
index: idx,
|
|
594
|
+
functionalProperty: functionalProperty
|
|
552
595
|
});
|
|
553
596
|
}
|
|
554
597
|
});
|
|
555
598
|
}
|
|
556
599
|
|
|
600
|
+
var registeredInput = register(entry);
|
|
601
|
+
|
|
602
|
+
var inputProps = _objectSpread(_objectSpread({}, registeredInput), {}, {
|
|
603
|
+
onChange: function onChange(e) {
|
|
604
|
+
registeredInput.onChange(e);
|
|
605
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
606
|
+
return onChange({
|
|
607
|
+
rawValues: getValues(),
|
|
608
|
+
value: e.target.value,
|
|
609
|
+
setValue: _setValue
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
|
|
557
615
|
switch (step.type) {
|
|
558
616
|
case _type.type.string:
|
|
559
617
|
switch (step.format) {
|
|
@@ -575,12 +633,11 @@ var Step = function Step(_ref4) {
|
|
|
575
633
|
type: "text",
|
|
576
634
|
id: entry,
|
|
577
635
|
className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
|
|
578
|
-
readOnly: step.disabled ? 'readOnly' : null
|
|
636
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null
|
|
579
637
|
}, step.props, {
|
|
580
|
-
name: entry,
|
|
581
638
|
defaultValue: defaultValue,
|
|
582
639
|
placeholder: step.placeholder
|
|
583
|
-
},
|
|
640
|
+
}, inputProps)));
|
|
584
641
|
|
|
585
642
|
case _format.format.code:
|
|
586
643
|
return /*#__PURE__*/_react["default"].createElement(_reactHookForm.Controller, {
|
|
@@ -599,8 +656,17 @@ var Step = function Step(_ref4) {
|
|
|
599
656
|
error: error
|
|
600
657
|
}, /*#__PURE__*/_react["default"].createElement(_index.CodeInput, _extends({
|
|
601
658
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
602
|
-
readOnly: step.disabled ? true : false,
|
|
603
|
-
onChange:
|
|
659
|
+
readOnly: functionalProperty(entry, step.disabled) ? true : false,
|
|
660
|
+
onChange: function onChange(e) {
|
|
661
|
+
field.onChange(e);
|
|
662
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
663
|
+
return onChange({
|
|
664
|
+
rawValues: getValues(),
|
|
665
|
+
value: e,
|
|
666
|
+
setValue: _setValue
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
},
|
|
604
670
|
value: field.value,
|
|
605
671
|
defaultValue: defaultValue
|
|
606
672
|
}, step.props)));
|
|
@@ -624,8 +690,17 @@ var Step = function Step(_ref4) {
|
|
|
624
690
|
error: error
|
|
625
691
|
}, /*#__PURE__*/_react["default"].createElement(_index.MarkdownInput, _extends({}, step.props, {
|
|
626
692
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
627
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
628
|
-
onChange:
|
|
693
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
694
|
+
onChange: function onChange(e) {
|
|
695
|
+
field.onChange(e);
|
|
696
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
697
|
+
return onChange({
|
|
698
|
+
rawValues: getValues(),
|
|
699
|
+
value: e,
|
|
700
|
+
setValue: _setValue
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
},
|
|
629
704
|
value: field.value,
|
|
630
705
|
defaultValue: defaultValue
|
|
631
706
|
}, step)));
|
|
@@ -648,15 +723,24 @@ var Step = function Step(_ref4) {
|
|
|
648
723
|
rawValues: getValues()
|
|
649
724
|
}, field),
|
|
650
725
|
error: error
|
|
651
|
-
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, {
|
|
726
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
|
|
652
727
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
653
|
-
|
|
654
|
-
onChange: field.onChange,
|
|
728
|
+
disabled: functionalProperty(entry, step.disabled),
|
|
655
729
|
value: field.value,
|
|
656
730
|
possibleValues: step.options,
|
|
657
731
|
defaultValue: defaultValue,
|
|
658
|
-
httpClient: httpClient
|
|
659
|
-
|
|
732
|
+
httpClient: httpClient,
|
|
733
|
+
onChange: function onChange(value) {
|
|
734
|
+
field.onChange(value);
|
|
735
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
736
|
+
return onChange({
|
|
737
|
+
rawValues: getValues(),
|
|
738
|
+
value: value,
|
|
739
|
+
setValue: _setValue
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
})));
|
|
660
744
|
}
|
|
661
745
|
});
|
|
662
746
|
|
|
@@ -677,14 +761,13 @@ var Step = function Step(_ref4) {
|
|
|
677
761
|
},
|
|
678
762
|
error: error
|
|
679
763
|
}, /*#__PURE__*/_react["default"].createElement("input", _extends({
|
|
680
|
-
// {...step.props}
|
|
681
764
|
type: step.format || 'text',
|
|
682
765
|
id: entry,
|
|
683
766
|
className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
|
|
684
|
-
readOnly: step.disabled ? 'readOnly' : null
|
|
685
|
-
,
|
|
767
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
768
|
+
defaultValue: defaultValue,
|
|
686
769
|
placeholder: step.placeholder
|
|
687
|
-
},
|
|
770
|
+
}, inputProps)));
|
|
688
771
|
}
|
|
689
772
|
|
|
690
773
|
case _type.type.number:
|
|
@@ -705,15 +788,24 @@ var Step = function Step(_ref4) {
|
|
|
705
788
|
rawValues: getValues()
|
|
706
789
|
}, field),
|
|
707
790
|
error: error
|
|
708
|
-
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, {
|
|
791
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
|
|
709
792
|
className: (0, _classnames["default"])(classes.content, _defineProperty({}, classes.input__invalid, error)),
|
|
710
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
711
|
-
onChange:
|
|
793
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
794
|
+
onChange: function onChange(e) {
|
|
795
|
+
field.onChange(e);
|
|
796
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
797
|
+
return onChange({
|
|
798
|
+
rawValues: getValues(),
|
|
799
|
+
value: e,
|
|
800
|
+
setValue: _setValue
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
},
|
|
712
804
|
value: field.value,
|
|
713
805
|
possibleValues: step.options,
|
|
714
806
|
defaultValue: defaultValue,
|
|
715
807
|
httpClient: httpClient
|
|
716
|
-
}
|
|
808
|
+
})));
|
|
717
809
|
}
|
|
718
810
|
});
|
|
719
811
|
|
|
@@ -735,11 +827,11 @@ var Step = function Step(_ref4) {
|
|
|
735
827
|
type: step.format || 'number',
|
|
736
828
|
id: entry,
|
|
737
829
|
className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
|
|
738
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
830
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
739
831
|
name: entry,
|
|
740
832
|
placeholder: step.placeholder,
|
|
741
833
|
defaultValue: defaultValue
|
|
742
|
-
},
|
|
834
|
+
}, inputProps)));
|
|
743
835
|
}
|
|
744
836
|
|
|
745
837
|
case _type.type.bool:
|
|
@@ -759,8 +851,17 @@ var Step = function Step(_ref4) {
|
|
|
759
851
|
error: error
|
|
760
852
|
}, /*#__PURE__*/_react["default"].createElement(_index.BooleanInput, _extends({}, step.props, {
|
|
761
853
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
762
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
763
|
-
onChange:
|
|
854
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
855
|
+
onChange: function onChange(e) {
|
|
856
|
+
field.onChange(e);
|
|
857
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
858
|
+
return onChange({
|
|
859
|
+
rawValues: getValues(),
|
|
860
|
+
value: e,
|
|
861
|
+
setValue: _setValue
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
},
|
|
764
865
|
value: field.value
|
|
765
866
|
})));
|
|
766
867
|
}
|
|
@@ -785,18 +886,28 @@ var Step = function Step(_ref4) {
|
|
|
785
886
|
rawValues: getValues()
|
|
786
887
|
}, field),
|
|
787
888
|
error: error
|
|
788
|
-
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, {
|
|
889
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
|
|
789
890
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
790
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
791
|
-
onChange:
|
|
891
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
892
|
+
onChange: function onChange(e) {
|
|
893
|
+
field.onChange(e);
|
|
894
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
895
|
+
return onChange({
|
|
896
|
+
rawValues: getValues(),
|
|
897
|
+
value: e,
|
|
898
|
+
setValue: _setValue
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
},
|
|
792
902
|
value: field.value,
|
|
793
903
|
possibleValues: step.options,
|
|
794
904
|
httpClient: httpClient
|
|
795
|
-
}
|
|
905
|
+
})));
|
|
796
906
|
}
|
|
797
907
|
});
|
|
798
908
|
|
|
799
909
|
case _format.format.form:
|
|
910
|
+
//todo: disabled ?
|
|
800
911
|
var flow = (0, _Option.option)(step.flow).getOrElse((0, _Option.option)(step.schema).map(function (s) {
|
|
801
912
|
return Object.keys(s);
|
|
802
913
|
}).getOrNull());
|
|
@@ -824,7 +935,8 @@ var Step = function Step(_ref4) {
|
|
|
824
935
|
maybeCustomHttpClient: httpClient,
|
|
825
936
|
value: getValues(entry) || defaultValue,
|
|
826
937
|
error: error,
|
|
827
|
-
index: index
|
|
938
|
+
index: index,
|
|
939
|
+
functionalProperty: functionalProperty
|
|
828
940
|
}));
|
|
829
941
|
|
|
830
942
|
default:
|
|
@@ -843,13 +955,22 @@ var Step = function Step(_ref4) {
|
|
|
843
955
|
rawValues: getValues()
|
|
844
956
|
}, field),
|
|
845
957
|
error: error
|
|
846
|
-
}, /*#__PURE__*/_react["default"].createElement(_index.ObjectInput, _extends({}, step.props, {
|
|
958
|
+
}, /*#__PURE__*/_react["default"].createElement(_index.ObjectInput, _extends({}, step.props, step, {
|
|
847
959
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
848
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
849
|
-
onChange:
|
|
960
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
961
|
+
onChange: function onChange(e) {
|
|
962
|
+
field.onChange(e);
|
|
963
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
964
|
+
return onChange({
|
|
965
|
+
rawValues: getValues(),
|
|
966
|
+
value: e,
|
|
967
|
+
setValue: _setValue
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
},
|
|
850
971
|
value: field.value,
|
|
851
972
|
possibleValues: step.options
|
|
852
|
-
}
|
|
973
|
+
})));
|
|
853
974
|
}
|
|
854
975
|
});
|
|
855
976
|
}
|
|
@@ -873,11 +994,19 @@ var Step = function Step(_ref4) {
|
|
|
873
994
|
}, /*#__PURE__*/_react["default"].createElement(_reactRainbowComponents.DatePicker, _extends({}, step.props, {
|
|
874
995
|
id: "datePicker-1",
|
|
875
996
|
className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
|
|
876
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
997
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
877
998
|
value: field.value,
|
|
878
|
-
onChange:
|
|
879
|
-
|
|
880
|
-
|
|
999
|
+
onChange: function onChange(e) {
|
|
1000
|
+
field.onChange(e);
|
|
1001
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
1002
|
+
return onChange({
|
|
1003
|
+
rawValues: getValues(),
|
|
1004
|
+
value: e,
|
|
1005
|
+
setValue: _setValue
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
},
|
|
1009
|
+
formatStyle: "large"
|
|
881
1010
|
})));
|
|
882
1011
|
}
|
|
883
1012
|
});
|
|
@@ -927,7 +1056,7 @@ var Step = function Step(_ref4) {
|
|
|
927
1056
|
}), /*#__PURE__*/_react["default"].createElement("button", {
|
|
928
1057
|
type: "button",
|
|
929
1058
|
className: "".concat(classes.btn, " ").concat(classes.flex, " ").concat(classes.ai_center),
|
|
930
|
-
disabled: uploading,
|
|
1059
|
+
disabled: uploading || functionalProperty(entry, step.disabled),
|
|
931
1060
|
onClick: trigger
|
|
932
1061
|
}, uploading && /*#__PURE__*/_react["default"].createElement(_reactFeather.Loader, null), !uploading && /*#__PURE__*/_react["default"].createElement(_reactFeather.Upload, null), /*#__PURE__*/_react["default"].createElement("span", {
|
|
933
1062
|
className: "".concat(classes.ml_5)
|
|
@@ -944,7 +1073,16 @@ var Step = function Step(_ref4) {
|
|
|
944
1073
|
}, field),
|
|
945
1074
|
error: error
|
|
946
1075
|
}, /*#__PURE__*/_react["default"].createElement(FileInput, {
|
|
947
|
-
onChange:
|
|
1076
|
+
onChange: function onChange(e) {
|
|
1077
|
+
field.onChange(e);
|
|
1078
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
1079
|
+
return onChange({
|
|
1080
|
+
rawValues: getValues(),
|
|
1081
|
+
value: e,
|
|
1082
|
+
setValue: _setValue
|
|
1083
|
+
});
|
|
1084
|
+
});
|
|
1085
|
+
},
|
|
948
1086
|
error: error
|
|
949
1087
|
}));
|
|
950
1088
|
}
|
|
@@ -970,10 +1108,10 @@ var Step = function Step(_ref4) {
|
|
|
970
1108
|
type: "file",
|
|
971
1109
|
id: entry,
|
|
972
1110
|
className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
|
|
973
|
-
readOnly: step.disabled ? 'readOnly' : null,
|
|
1111
|
+
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
974
1112
|
name: entry,
|
|
975
1113
|
placeholder: step.placeholder
|
|
976
|
-
},
|
|
1114
|
+
}, inputProps)));
|
|
977
1115
|
|
|
978
1116
|
default:
|
|
979
1117
|
return null;
|
|
@@ -990,7 +1128,9 @@ var ArrayStep = function ArrayStep(_ref15) {
|
|
|
990
1128
|
component = _ref15.component,
|
|
991
1129
|
values = _ref15.values,
|
|
992
1130
|
defaultValue = _ref15.defaultValue,
|
|
993
|
-
setValue = _ref15.setValue
|
|
1131
|
+
setValue = _ref15.setValue,
|
|
1132
|
+
getValues = _ref15.getValues,
|
|
1133
|
+
disabled = _ref15.disabled;
|
|
994
1134
|
var classes = (0, _styleContext.useCustomStyle)();
|
|
995
1135
|
|
|
996
1136
|
var _useFieldArray = (0, _reactHookForm.useFieldArray)({
|
|
@@ -1018,6 +1158,7 @@ var ArrayStep = function ArrayStep(_ref15) {
|
|
|
1018
1158
|
className: "input-group-append"
|
|
1019
1159
|
}, /*#__PURE__*/_react["default"].createElement("button", {
|
|
1020
1160
|
className: "btn btn-danger btn-sm",
|
|
1161
|
+
disabled: disabled,
|
|
1021
1162
|
onClick: function onClick() {
|
|
1022
1163
|
remove(idx);
|
|
1023
1164
|
trigger(entry);
|
|
@@ -1028,10 +1169,18 @@ var ArrayStep = function ArrayStep(_ref15) {
|
|
|
1028
1169
|
className: (0, _classnames["default"])("btn btn-info mt-2", _defineProperty({}, classes.input__invalid, error)),
|
|
1029
1170
|
onClick: function onClick() {
|
|
1030
1171
|
append({
|
|
1031
|
-
value: step.addableDefaultValue
|
|
1172
|
+
value: step.addableDefaultValue || defaultVal(step.type)
|
|
1032
1173
|
});
|
|
1033
1174
|
trigger(entry);
|
|
1175
|
+
(0, _Option.option)(step.onChange).map(function (onChange) {
|
|
1176
|
+
return onChange({
|
|
1177
|
+
rawValues: getValues(),
|
|
1178
|
+
value: getValues(entry),
|
|
1179
|
+
setValue: setValue
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1034
1182
|
},
|
|
1183
|
+
disabled: disabled,
|
|
1035
1184
|
value: "Add"
|
|
1036
1185
|
}), error && /*#__PURE__*/_react["default"].createElement("div", {
|
|
1037
1186
|
className: "invalid-feedback"
|
|
@@ -1047,7 +1196,8 @@ var NestedForm = function NestedForm(_ref16) {
|
|
|
1047
1196
|
index = _ref16.index,
|
|
1048
1197
|
error = _ref16.error,
|
|
1049
1198
|
value = _ref16.value,
|
|
1050
|
-
step = _ref16.step
|
|
1199
|
+
step = _ref16.step,
|
|
1200
|
+
functionalProperty = _ref16.functionalProperty;
|
|
1051
1201
|
|
|
1052
1202
|
var _useFormContext = (0, _reactHookForm.useFormContext)(),
|
|
1053
1203
|
register = _useFormContext.register,
|
|
@@ -1095,14 +1245,38 @@ var NestedForm = function NestedForm(_ref16) {
|
|
|
1095
1245
|
});
|
|
1096
1246
|
}
|
|
1097
1247
|
}, [prevSchema, schemaAndFlow.schema]);
|
|
1248
|
+
var computedSandF = schemaAndFlow.flow.reduce(function (acc, entry) {
|
|
1249
|
+
var step = schemaAndFlow.schema[entry];
|
|
1250
|
+
var visibleStep = (0, _Option.option)(step).map(function (s) {
|
|
1251
|
+
return s.visible;
|
|
1252
|
+
}).map(function (visible) {
|
|
1253
|
+
switch (_typeof(visible)) {
|
|
1254
|
+
case 'object':
|
|
1255
|
+
var _value2 = watch(visible.ref);
|
|
1256
|
+
|
|
1257
|
+
return (0, _Option.option)(visible.test).map(function (test) {
|
|
1258
|
+
return test(_value2);
|
|
1259
|
+
}).getOrElse(_value2);
|
|
1260
|
+
|
|
1261
|
+
case 'boolean':
|
|
1262
|
+
return visible;
|
|
1263
|
+
|
|
1264
|
+
default:
|
|
1265
|
+
return true;
|
|
1266
|
+
}
|
|
1267
|
+
}).getOrElse(true);
|
|
1268
|
+
return [].concat(_toConsumableArray(acc), [{
|
|
1269
|
+
step: step,
|
|
1270
|
+
visibleStep: visibleStep,
|
|
1271
|
+
entry: entry
|
|
1272
|
+
}]);
|
|
1273
|
+
}, []);
|
|
1274
|
+
var bordered = computedSandF.filter(function (x) {
|
|
1275
|
+
return x.visibleStep;
|
|
1276
|
+
}).length > 1 && step.label !== null;
|
|
1098
1277
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
paddingLeft: '1rem',
|
|
1102
|
-
marginBottom: '.5rem',
|
|
1103
|
-
position: 'relative'
|
|
1104
|
-
}
|
|
1105
|
-
}, schemaAndFlow.flow.length > 1 && collapsed && /*#__PURE__*/_react["default"].createElement(_reactFeather.ArrowDown, {
|
|
1278
|
+
className: (0, _classnames["default"])(_defineProperty({}, classes.nestedform__border, bordered))
|
|
1279
|
+
}, !!step.collapsable && schemaAndFlow.flow.length > 1 && collapsed && /*#__PURE__*/_react["default"].createElement(_reactFeather.ArrowDown, {
|
|
1106
1280
|
size: 30,
|
|
1107
1281
|
className: classes.cursor_pointer,
|
|
1108
1282
|
style: {
|
|
@@ -1114,7 +1288,7 @@ var NestedForm = function NestedForm(_ref16) {
|
|
|
1114
1288
|
onClick: function onClick() {
|
|
1115
1289
|
return setCollapsed(!collapsed);
|
|
1116
1290
|
}
|
|
1117
|
-
}), schemaAndFlow.flow.length > 1 && !collapsed && /*#__PURE__*/_react["default"].createElement(_reactFeather.ArrowUp, {
|
|
1291
|
+
}), !!step.collapsable && schemaAndFlow.flow.length > 1 && !collapsed && /*#__PURE__*/_react["default"].createElement(_reactFeather.ArrowUp, {
|
|
1118
1292
|
size: 30,
|
|
1119
1293
|
className: classes.cursor_pointer,
|
|
1120
1294
|
style: {
|
|
@@ -1122,41 +1296,31 @@ var NestedForm = function NestedForm(_ref16) {
|
|
|
1122
1296
|
top: '5px',
|
|
1123
1297
|
left: '-16px'
|
|
1124
1298
|
},
|
|
1125
|
-
"
|
|
1299
|
+
"strok-width": "3",
|
|
1126
1300
|
onClick: function onClick() {
|
|
1127
1301
|
return setCollapsed(!collapsed);
|
|
1128
1302
|
}
|
|
1129
|
-
}),
|
|
1130
|
-
var step =
|
|
1303
|
+
}), computedSandF.map(function (_ref17, idx) {
|
|
1304
|
+
var step = _ref17.step,
|
|
1305
|
+
visibleStep = _ref17.visibleStep,
|
|
1306
|
+
entry = _ref17.entry;
|
|
1307
|
+
|
|
1308
|
+
if (!step && typeof entry === 'string') {
|
|
1309
|
+
console.error("no step found for the entry \"".concat(entry, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
1310
|
+
return null;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1131
1313
|
var realError = error && error[entry];
|
|
1132
|
-
var oneVisibleSetup = Object.values(schema).some(function (v) {
|
|
1314
|
+
var oneVisibleSetup = Object.values(schemaAndFlow.schema).some(function (v) {
|
|
1133
1315
|
return !!v.visibleOnCollapse;
|
|
1134
1316
|
});
|
|
1135
1317
|
var isCollapsed = collapsed && (oneVisibleSetup ? !step.visibleOnCollapse : idx > 0);
|
|
1136
|
-
var visibleStep = (0, _Option.option)(step).map(function (s) {
|
|
1137
|
-
return s.visible;
|
|
1138
|
-
}).map(function (visible) {
|
|
1139
|
-
switch (_typeof(visible)) {
|
|
1140
|
-
case 'object':
|
|
1141
|
-
var _value2 = watch(visible.ref);
|
|
1142
|
-
|
|
1143
|
-
return (0, _Option.option)(visible.test).map(function (test) {
|
|
1144
|
-
return test(_value2);
|
|
1145
|
-
}).getOrElse(_value2);
|
|
1146
|
-
|
|
1147
|
-
case 'boolean':
|
|
1148
|
-
return visible;
|
|
1149
|
-
|
|
1150
|
-
default:
|
|
1151
|
-
return true;
|
|
1152
|
-
}
|
|
1153
|
-
}).getOrElse(true);
|
|
1154
1318
|
return /*#__PURE__*/_react["default"].createElement(BasicWrapper, {
|
|
1155
1319
|
key: "".concat(entry, ".").concat(idx),
|
|
1156
1320
|
className: (0, _classnames["default"])(_defineProperty({}, classes.display__none, isCollapsed || !visibleStep)),
|
|
1157
1321
|
entry: "".concat(parent, ".").concat(entry),
|
|
1158
1322
|
error: realError,
|
|
1159
|
-
label: (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry,
|
|
1323
|
+
label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
|
|
1160
1324
|
help: step.help,
|
|
1161
1325
|
render: inputWrapper
|
|
1162
1326
|
}, /*#__PURE__*/_react["default"].createElement(Step, {
|
|
@@ -1174,7 +1338,8 @@ var NestedForm = function NestedForm(_ref16) {
|
|
|
1174
1338
|
watch: watch,
|
|
1175
1339
|
inputWrapper: inputWrapper,
|
|
1176
1340
|
httpClient: maybeCustomHttpClient,
|
|
1177
|
-
defaultValue: value && value[entry]
|
|
1341
|
+
defaultValue: value && value[entry],
|
|
1342
|
+
functionalProperty: functionalProperty
|
|
1178
1343
|
}));
|
|
1179
1344
|
}));
|
|
1180
1345
|
};
|
|
@@ -189,6 +189,7 @@ var SelectInput = function SelectInput(props) {
|
|
|
189
189
|
return /*#__PURE__*/_react["default"].createElement("button", {
|
|
190
190
|
key: idx,
|
|
191
191
|
type: "button",
|
|
192
|
+
disabled: props.disabled,
|
|
192
193
|
className: (0, _classnames["default"])(props.className, classes.btn, classes.btn_grey, classes.ml_5, {
|
|
193
194
|
active: active
|
|
194
195
|
}),
|
|
@@ -213,7 +214,8 @@ var SelectInput = function SelectInput(props) {
|
|
|
213
214
|
return handleCreate(option, props.onCreateOption);
|
|
214
215
|
},
|
|
215
216
|
classNamePrefix: "react-form-select",
|
|
216
|
-
className: props.className
|
|
217
|
+
className: props.className,
|
|
218
|
+
readOnly: props.disabled ? 'readOnly' : null
|
|
217
219
|
}));
|
|
218
220
|
} else {
|
|
219
221
|
return /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], _extends({}, props, {
|
|
@@ -225,7 +227,8 @@ var SelectInput = function SelectInput(props) {
|
|
|
225
227
|
options: values,
|
|
226
228
|
onChange: onChange,
|
|
227
229
|
classNamePrefix: "react-form-select",
|
|
228
|
-
className: props.className
|
|
230
|
+
className: props.className,
|
|
231
|
+
readOnly: props.disabled ? 'readOnly' : null
|
|
229
232
|
}));
|
|
230
233
|
}
|
|
231
234
|
};
|