@scenid/react-formulator 0.1.10 → 0.1.12
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/index.cjs.js +76 -46
- package/dist/index.esm.js +76 -46
- package/package.json +3 -1
- package/src/Editable/FormField.jsx +2 -3
- package/src/Editable/FormSelect.jsx +2 -1
- package/src/FormulatorForm.jsx +6 -4
- package/src/FormulatorFormSection.jsx +33 -23
- package/src/ReadOnly/FormReadOnlyField.jsx +3 -3
- package/src/ReadOnly/FormReadOnlyText.jsx +17 -7
- package/stories/Forms.stories.jsx +11 -1
- package/stories/forms/rlp.render.schema.json +8 -29
- package/stories/forms/rlp.validation.schema.json +1 -560
package/dist/index.esm.js
CHANGED
|
@@ -7,6 +7,7 @@ import cx from 'classnames';
|
|
|
7
7
|
import { makeStyles as makeStyles$1 } from '@material-ui/styles';
|
|
8
8
|
import AutorenewIcon from '@material-ui/icons/Autorenew';
|
|
9
9
|
import { Delete, Save, Clear } from '@material-ui/icons';
|
|
10
|
+
import { DateTime } from 'luxon';
|
|
10
11
|
import path$3 from 'path';
|
|
11
12
|
import proc from 'process';
|
|
12
13
|
import { fileURLToPath } from 'url';
|
|
@@ -29126,7 +29127,6 @@ var useStyles = makeStyles$1(function (theme) {
|
|
|
29126
29127
|
var FormControlField$1 = function FormControlField(_ref) {
|
|
29127
29128
|
var variant = _ref.variant,
|
|
29128
29129
|
type = _ref.type,
|
|
29129
|
-
isRender = _ref.isRender,
|
|
29130
29130
|
name = _ref.name,
|
|
29131
29131
|
label = _ref.label,
|
|
29132
29132
|
component = _ref.component,
|
|
@@ -29155,6 +29155,8 @@ var FormControlField$1 = function FormControlField(_ref) {
|
|
|
29155
29155
|
onChange: onChange
|
|
29156
29156
|
});
|
|
29157
29157
|
|
|
29158
|
+
var isRender = type === 'render';
|
|
29159
|
+
|
|
29158
29160
|
if (validating) {
|
|
29159
29161
|
finalProps.endAdornment = [/*#__PURE__*/React__default.createElement(InputAdornment, {
|
|
29160
29162
|
position: "end"
|
|
@@ -29204,7 +29206,6 @@ var FormControlField$1 = function FormControlField(_ref) {
|
|
|
29204
29206
|
|
|
29205
29207
|
FormControlField$1.propTypes = {
|
|
29206
29208
|
variant: PropTypes__default.oneOf(['standard', 'filled', 'outlined']),
|
|
29207
|
-
isRender: PropTypes__default.bool,
|
|
29208
29209
|
component: PropTypes__default.any.isRequired,
|
|
29209
29210
|
componentProps: PropTypes__default.object,
|
|
29210
29211
|
type: PropTypes__default.string.isRequired,
|
|
@@ -29248,7 +29249,6 @@ var FormField = function FormField(_ref2) {
|
|
|
29248
29249
|
|
|
29249
29250
|
FormField.propTypes = {
|
|
29250
29251
|
variant: PropTypes__default.oneOf(['standard', 'filled', 'outlined']),
|
|
29251
|
-
isRender: PropTypes__default.bool,
|
|
29252
29252
|
component: PropTypes__default.any.isRequired,
|
|
29253
29253
|
componentProps: PropTypes__default.object,
|
|
29254
29254
|
type: PropTypes__default.string.isRequired,
|
|
@@ -29355,11 +29355,12 @@ FormNumber.propTypes = {
|
|
|
29355
29355
|
onChange: PropTypes__default.func.isRequired
|
|
29356
29356
|
};
|
|
29357
29357
|
|
|
29358
|
-
var _excluded$3 = ["options", "required"];
|
|
29358
|
+
var _excluded$3 = ["options", "required", "value"];
|
|
29359
29359
|
|
|
29360
29360
|
var FormSelect = function FormSelect(_ref) {
|
|
29361
29361
|
var options = _ref.options,
|
|
29362
29362
|
required = _ref.required,
|
|
29363
|
+
value = _ref.value,
|
|
29363
29364
|
props = _objectWithoutProperties(_ref, _excluded$3);
|
|
29364
29365
|
|
|
29365
29366
|
var unselectOption = [];
|
|
@@ -29376,7 +29377,8 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
29376
29377
|
})));
|
|
29377
29378
|
return /*#__PURE__*/React__default.createElement(TextField, _extends({
|
|
29378
29379
|
select: true,
|
|
29379
|
-
required: required
|
|
29380
|
+
required: required,
|
|
29381
|
+
value: value === undefined ? '' : value
|
|
29380
29382
|
}, props), allOptions.map(function (_ref2) {
|
|
29381
29383
|
var itemLabel = _ref2.label,
|
|
29382
29384
|
itemValue = _ref2.value;
|
|
@@ -29658,7 +29660,7 @@ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if
|
|
|
29658
29660
|
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29659
29661
|
|
|
29660
29662
|
var FormControlField = function FormControlField(_ref) {
|
|
29661
|
-
var
|
|
29663
|
+
var type = _ref.type,
|
|
29662
29664
|
name = _ref.name,
|
|
29663
29665
|
label = _ref.label,
|
|
29664
29666
|
component = _ref.component,
|
|
@@ -29681,7 +29683,7 @@ var FormControlField = function FormControlField(_ref) {
|
|
|
29681
29683
|
}
|
|
29682
29684
|
|
|
29683
29685
|
var control;
|
|
29684
|
-
if (
|
|
29686
|
+
if (type === 'render') control = /*#__PURE__*/React__default.cloneElement(component, finalProps);else control = /*#__PURE__*/React__default.createElement(component, finalProps);
|
|
29685
29687
|
return /*#__PURE__*/React__default.createElement(Box, {
|
|
29686
29688
|
width: "100%",
|
|
29687
29689
|
display: "flex",
|
|
@@ -29694,10 +29696,10 @@ var FormControlField = function FormControlField(_ref) {
|
|
|
29694
29696
|
};
|
|
29695
29697
|
|
|
29696
29698
|
FormControlField.propTypes = {
|
|
29697
|
-
isRender: PropTypes__default.bool,
|
|
29698
29699
|
component: PropTypes__default.any.isRequired,
|
|
29699
29700
|
componentProps: PropTypes__default.object,
|
|
29700
29701
|
name: PropTypes__default.string.isRequired,
|
|
29702
|
+
type: PropTypes__default.string.isRequired,
|
|
29701
29703
|
label: PropTypes__default.string.isRequired,
|
|
29702
29704
|
value: PropTypes__default.oneOfType([PropTypes__default.string, PropTypes__default.number, PropTypes__default.bool, PropTypes__default.array]),
|
|
29703
29705
|
options: PropTypes__default.arrayOf(PropTypes__default.shape({
|
|
@@ -29756,14 +29758,21 @@ FormReadOnlyField.propTypes = {
|
|
|
29756
29758
|
};
|
|
29757
29759
|
var FormReadOnlyField$1 = /*#__PURE__*/React__default.memo(FormReadOnlyField);
|
|
29758
29760
|
|
|
29759
|
-
var
|
|
29760
|
-
var value = _ref.value
|
|
29761
|
+
var FormReadOnlyText = function FormReadOnlyText(_ref) {
|
|
29762
|
+
var value = _ref.value,
|
|
29763
|
+
type = _ref.type;
|
|
29764
|
+
var finalValue = value;
|
|
29765
|
+
|
|
29766
|
+
if (type === 'date' || type === 'datetime-local') {
|
|
29767
|
+
finalValue = DateTime.fromISO(value).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY);
|
|
29768
|
+
}
|
|
29769
|
+
|
|
29761
29770
|
return /*#__PURE__*/React__default.createElement(Typography, {
|
|
29762
29771
|
variant: "body1"
|
|
29763
|
-
},
|
|
29772
|
+
}, finalValue);
|
|
29764
29773
|
};
|
|
29765
29774
|
|
|
29766
|
-
|
|
29775
|
+
FormReadOnlyText.propTypes = {
|
|
29767
29776
|
value: PropTypes__default.oneOfType([PropTypes__default.number, PropTypes__default.string])
|
|
29768
29777
|
};
|
|
29769
29778
|
|
|
@@ -67978,7 +67987,7 @@ FormReadOnlyMarkdown.propTypes = {
|
|
|
67978
67987
|
|
|
67979
67988
|
var FormReadOnlyNumber = function FormReadOnlyNumber(_ref) {
|
|
67980
67989
|
var value = _ref.value;
|
|
67981
|
-
return /*#__PURE__*/React__default.createElement(
|
|
67990
|
+
return /*#__PURE__*/React__default.createElement(FormReadOnlyText, {
|
|
67982
67991
|
value: castToNumber(value)
|
|
67983
67992
|
});
|
|
67984
67993
|
};
|
|
@@ -67992,7 +68001,7 @@ var FormReadOnlySelect = function FormReadOnlySelect(_ref) {
|
|
|
67992
68001
|
|
|
67993
68002
|
var value = _ref.value,
|
|
67994
68003
|
options = _ref.options;
|
|
67995
|
-
return /*#__PURE__*/React__default.createElement(
|
|
68004
|
+
return /*#__PURE__*/React__default.createElement(FormReadOnlyText, {
|
|
67996
68005
|
value: (_options$find = options.find(function (o) {
|
|
67997
68006
|
return o.value === value;
|
|
67998
68007
|
})) === null || _options$find === void 0 ? void 0 : _options$find.label
|
|
@@ -75404,9 +75413,9 @@ function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeRefl
|
|
|
75404
75413
|
|
|
75405
75414
|
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
75406
75415
|
var formReadOnlyComponentMap = {
|
|
75407
|
-
"default":
|
|
75416
|
+
"default": FormReadOnlyText,
|
|
75408
75417
|
markdown: FormReadOnlyMarkdown,
|
|
75409
|
-
string:
|
|
75418
|
+
string: FormReadOnlyText,
|
|
75410
75419
|
number: FormReadOnlyNumber,
|
|
75411
75420
|
select: FormReadOnlySelect,
|
|
75412
75421
|
"boolean": FormReadOnlyBoolean,
|
|
@@ -75448,17 +75457,23 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75448
75457
|
errorMessages = _this$props.errorMessages,
|
|
75449
75458
|
results = _this$props.results,
|
|
75450
75459
|
data = _this$props.data,
|
|
75451
|
-
fieldStates = _this$props.fieldStates
|
|
75460
|
+
fieldStates = _this$props.fieldStates,
|
|
75461
|
+
renderComponentMap = _this$props.renderComponentMap;
|
|
75452
75462
|
var field = fieldEntry,
|
|
75453
75463
|
specialProps = {};
|
|
75454
75464
|
|
|
75455
75465
|
if (Array.isArray(fieldEntry)) {
|
|
75456
75466
|
if (fieldEntry[0] === '@@render') {
|
|
75457
75467
|
field = fieldEntry[1];
|
|
75458
|
-
|
|
75459
|
-
|
|
75460
|
-
|
|
75461
|
-
|
|
75468
|
+
return {
|
|
75469
|
+
type: 'render',
|
|
75470
|
+
name: field,
|
|
75471
|
+
component: renderComponentMap[field],
|
|
75472
|
+
componentProps: fieldEntry[2] || {}
|
|
75473
|
+
};
|
|
75474
|
+
}
|
|
75475
|
+
|
|
75476
|
+
if (fieldEntry[0] === '@@markdown') {
|
|
75462
75477
|
return {
|
|
75463
75478
|
type: 'markdown',
|
|
75464
75479
|
name: fieldEntry[1],
|
|
@@ -75467,11 +75482,11 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75467
75482
|
content: fieldEntry[2]
|
|
75468
75483
|
}
|
|
75469
75484
|
};
|
|
75470
|
-
} else {
|
|
75471
|
-
field = fieldEntry[0];
|
|
75472
|
-
if (!fieldEntry[1]) throw new Error("field \"".concat(field, "\" is defined in an array, but has no props definition"));
|
|
75473
|
-
specialProps = fieldEntry[1];
|
|
75474
75485
|
}
|
|
75486
|
+
|
|
75487
|
+
field = fieldEntry[0];
|
|
75488
|
+
if (!fieldEntry[1]) throw new Error("field \"".concat(field, "\" is defined in an array, but has no props definition"));
|
|
75489
|
+
specialProps = fieldEntry[1];
|
|
75475
75490
|
}
|
|
75476
75491
|
|
|
75477
75492
|
var _specialProps = specialProps,
|
|
@@ -75492,8 +75507,8 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75492
75507
|
type = _schema$properties$fi.type,
|
|
75493
75508
|
defaultValue = _schema$properties$fi["default"];
|
|
75494
75509
|
var mapKey;
|
|
75495
|
-
if (
|
|
75496
|
-
var mapEntry =
|
|
75510
|
+
if (componentMap[field] !== undefined) mapKey = field;else if (typeof type === 'string' && componentMap[type] !== undefined) mapKey = type;else if (Array.isArray(type)) mapKey = 'select';else if (componentMap["default"] !== undefined) mapKey = 'default';else throw new Error("Could not find a Component to render for \"".concat(field, "\""));
|
|
75511
|
+
var mapEntry = componentMap[mapKey];
|
|
75497
75512
|
var component = mapEntry,
|
|
75498
75513
|
props = {};
|
|
75499
75514
|
|
|
@@ -75553,7 +75568,7 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75553
75568
|
nested = _this$props2$nested === void 0 ? 0 : _this$props2$nested,
|
|
75554
75569
|
schema = _this$props2.schema,
|
|
75555
75570
|
fields = _this$props2.fields,
|
|
75556
|
-
|
|
75571
|
+
obscuredFields = _this$props2.obscuredFields,
|
|
75557
75572
|
results = _this$props2.results,
|
|
75558
75573
|
data = _this$props2.data,
|
|
75559
75574
|
fieldStates = _this$props2.fieldStates,
|
|
@@ -75589,7 +75604,18 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75589
75604
|
_errors = _fieldProps.errors,
|
|
75590
75605
|
_validating = _fieldProps.validating,
|
|
75591
75606
|
_dirty = _fieldProps.dirty;
|
|
75592
|
-
|
|
75607
|
+
|
|
75608
|
+
if (readOnly) {
|
|
75609
|
+
if (!_value) return false;
|
|
75610
|
+
|
|
75611
|
+
if (Array.isArray(obscuredFields) && obscuredFields.includes(_name)) {
|
|
75612
|
+
return /*#__PURE__*/React__default.createElement(HiddenData, {
|
|
75613
|
+
subject: "Das Feld",
|
|
75614
|
+
label: _label
|
|
75615
|
+
});
|
|
75616
|
+
}
|
|
75617
|
+
}
|
|
75618
|
+
|
|
75593
75619
|
return /*#__PURE__*/React__default.createElement(readOnly ? FormReadOnlyField$1 : FormField$1, {
|
|
75594
75620
|
key: "form-render-component-".concat(cKey),
|
|
75595
75621
|
variant: inputVariant,
|
|
@@ -75597,7 +75623,6 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75597
75623
|
type: _type,
|
|
75598
75624
|
label: _label,
|
|
75599
75625
|
value: _value,
|
|
75600
|
-
isRender: true,
|
|
75601
75626
|
required: _required,
|
|
75602
75627
|
hasErrors: _hasErrors,
|
|
75603
75628
|
errors: _errors,
|
|
@@ -75627,9 +75652,9 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75627
75652
|
schema: schema,
|
|
75628
75653
|
label: fieldEntry.label,
|
|
75629
75654
|
fields: fieldEntry.fields,
|
|
75630
|
-
hideSensitiveData: hideSensitiveData,
|
|
75631
75655
|
results: results,
|
|
75632
75656
|
data: data,
|
|
75657
|
+
obscuredFields: obscuredFields,
|
|
75633
75658
|
fieldStates: fieldStates,
|
|
75634
75659
|
translations: translations,
|
|
75635
75660
|
errorMessages: errorMessages,
|
|
@@ -75655,7 +75680,18 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75655
75680
|
errors = fieldProps.errors,
|
|
75656
75681
|
validating = fieldProps.validating,
|
|
75657
75682
|
dirty = fieldProps.dirty;
|
|
75658
|
-
|
|
75683
|
+
|
|
75684
|
+
if (readOnly) {
|
|
75685
|
+
if (!value) return false;
|
|
75686
|
+
|
|
75687
|
+
if (Array.isArray(obscuredFields) && obscuredFields.includes(name)) {
|
|
75688
|
+
return /*#__PURE__*/React__default.createElement(HiddenData, {
|
|
75689
|
+
subject: "Das Feld",
|
|
75690
|
+
label: label
|
|
75691
|
+
});
|
|
75692
|
+
}
|
|
75693
|
+
}
|
|
75694
|
+
|
|
75659
75695
|
var apProps = {};
|
|
75660
75696
|
|
|
75661
75697
|
for (var i = 0; i < fields.length; i++) {
|
|
@@ -75689,14 +75725,6 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
75689
75725
|
}
|
|
75690
75726
|
|
|
75691
75727
|
var FormFieldComponent = readOnly ? FormReadOnlyField$1 : FormField$1;
|
|
75692
|
-
|
|
75693
|
-
if (hideSensitiveData && (name === 'reportingPin' || name === 'reportingAuthCode')) {
|
|
75694
|
-
return /*#__PURE__*/React__default.createElement(HiddenData, {
|
|
75695
|
-
subject: "Das Feld",
|
|
75696
|
-
label: label
|
|
75697
|
-
});
|
|
75698
|
-
}
|
|
75699
|
-
|
|
75700
75728
|
return /*#__PURE__*/React__default.createElement(FormFieldComponent, {
|
|
75701
75729
|
key: "form-".concat(id, "-").concat(name),
|
|
75702
75730
|
variant: inputVariant,
|
|
@@ -75793,7 +75821,7 @@ FormulatorFormSection.propTypes = {
|
|
|
75793
75821
|
nested: PropTypes__default.number,
|
|
75794
75822
|
sectionId: PropTypes__default.string.isRequired,
|
|
75795
75823
|
fields: PropTypes__default.array.isRequired,
|
|
75796
|
-
|
|
75824
|
+
obscuredFields: PropTypes__default.array,
|
|
75797
75825
|
schema: PropTypes__default.object.isRequired,
|
|
75798
75826
|
results: PropTypes__default.object.isRequired,
|
|
75799
75827
|
data: PropTypes__default.object.isRequired,
|
|
@@ -76263,12 +76291,13 @@ var FormulatorForm = /*#__PURE__*/function (_React$Component) {
|
|
|
76263
76291
|
readOnly = _this$props7.readOnly,
|
|
76264
76292
|
listErrors = _this$props7.listErrors,
|
|
76265
76293
|
schema = _this$props7.schema,
|
|
76266
|
-
hideSensitiveData = _this$props7.hideSensitiveData,
|
|
76267
76294
|
renderSchema = _this$props7.renderSchema,
|
|
76268
76295
|
propDisabled = _this$props7.disabled,
|
|
76269
76296
|
translations = _this$props7.translations,
|
|
76270
76297
|
componentMap = _this$props7.componentMap,
|
|
76271
76298
|
renderComponentMap = _this$props7.renderComponentMap,
|
|
76299
|
+
obscuredFields = _this$props7.obscuredFields,
|
|
76300
|
+
obscuredGroups = _this$props7.obscuredGroups,
|
|
76272
76301
|
errorMessages = _this$props7.errorMessages,
|
|
76273
76302
|
_onReset = _this$props7.onReset;
|
|
76274
76303
|
var _this$state6 = this.state,
|
|
@@ -76300,7 +76329,7 @@ var FormulatorForm = /*#__PURE__*/function (_React$Component) {
|
|
|
76300
76329
|
description = _ref12.description,
|
|
76301
76330
|
fields = _ref12.fields;
|
|
76302
76331
|
|
|
76303
|
-
if (
|
|
76332
|
+
if (readOnly && Array.isArray(obscuredGroups) && obscuredGroups.includes(sectionId)) {
|
|
76304
76333
|
return /*#__PURE__*/React__default.createElement(HiddenData, {
|
|
76305
76334
|
subject: "Der Bereich",
|
|
76306
76335
|
label: label
|
|
@@ -76322,10 +76351,10 @@ var FormulatorForm = /*#__PURE__*/function (_React$Component) {
|
|
|
76322
76351
|
label: label,
|
|
76323
76352
|
desc: description,
|
|
76324
76353
|
fields: fields,
|
|
76325
|
-
hideSensitiveData: hideSensitiveData,
|
|
76326
76354
|
results: results,
|
|
76327
76355
|
data: data,
|
|
76328
76356
|
fieldStates: fieldStates,
|
|
76357
|
+
obscuredFields: obscuredFields,
|
|
76329
76358
|
translations: translations,
|
|
76330
76359
|
errorMessages: errorMessages,
|
|
76331
76360
|
componentMap: componentMap,
|
|
@@ -76368,7 +76397,6 @@ FormulatorForm.propTypes = {
|
|
|
76368
76397
|
listErrors: PropTypes__default.bool,
|
|
76369
76398
|
schema: PropTypes__default.object.isRequired,
|
|
76370
76399
|
data: PropTypes__default.object.isRequired,
|
|
76371
|
-
hideSensitiveData: PropTypes__default.bool,
|
|
76372
76400
|
transientData: PropTypes__default.object,
|
|
76373
76401
|
fieldStates: PropTypes__default.object,
|
|
76374
76402
|
renderSchema: PropTypes__default.object.isRequired,
|
|
@@ -76377,6 +76405,8 @@ FormulatorForm.propTypes = {
|
|
|
76377
76405
|
errorMessages: PropTypes__default.object,
|
|
76378
76406
|
componentMap: PropTypes__default.object,
|
|
76379
76407
|
renderComponentMap: PropTypes__default.object,
|
|
76408
|
+
obscuredFields: PropTypes__default.array,
|
|
76409
|
+
obscuredGroups: PropTypes__default.array,
|
|
76380
76410
|
onSubmit: PropTypes__default.func,
|
|
76381
76411
|
onReset: PropTypes__default.func,
|
|
76382
76412
|
onStatusUpdate: PropTypes__default.func,
|
|
@@ -76388,4 +76418,4 @@ FormulatorForm.defaultProps = {
|
|
|
76388
76418
|
errorMessages: {}
|
|
76389
76419
|
};
|
|
76390
76420
|
|
|
76391
|
-
export { FormBoolean, FormField$1 as FormField, FormNumber, FormReadOnlyBoolean, FormReadOnlyField$1 as FormReadOnlyField, FormReadOnlyMarkdown, FormReadOnlyNumber, FormReadOnlyRepeater, FormReadOnlySelect,
|
|
76421
|
+
export { FormBoolean, FormField$1 as FormField, FormNumber, FormReadOnlyBoolean, FormReadOnlyField$1 as FormReadOnlyField, FormReadOnlyMarkdown, FormReadOnlyNumber, FormReadOnlyRepeater, FormReadOnlySelect, FormReadOnlyText, FormRepeater, FormSelect, FormText, FormulatorForm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenid/react-formulator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"repository": "https://dennykoch@bitbucket.org/scenid/react-formulator.git",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@material-ui/icons": "^4.11.3",
|
|
22
22
|
"@material-ui/styles": "^4.11.5",
|
|
23
23
|
"classnames": "^2.3.1",
|
|
24
|
+
"luxon": "^2.3.2",
|
|
24
25
|
"prop-types": "^15.8.1",
|
|
25
26
|
"react": "16.11.0",
|
|
26
27
|
"react-dom": "16.11.0"
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"@storybook/testing-library": "^0.0.11",
|
|
47
48
|
"babel-loader": "^8.2.5",
|
|
48
49
|
"classnames": "^2.3.1",
|
|
50
|
+
"luxon": "^2.3.2",
|
|
49
51
|
"cross-env": "^7.0.3",
|
|
50
52
|
"eslint": "^7.11.0",
|
|
51
53
|
"eslint-config-airbnb": "^18.0.1",
|
|
@@ -21,7 +21,6 @@ const useStyles = makeStyles(theme => ({ error: { color: theme.palette.error.mai
|
|
|
21
21
|
const FormControlField = ({
|
|
22
22
|
variant,
|
|
23
23
|
type,
|
|
24
|
-
isRender,
|
|
25
24
|
name,
|
|
26
25
|
label,
|
|
27
26
|
component,
|
|
@@ -51,6 +50,8 @@ const FormControlField = ({
|
|
|
51
50
|
onChange
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
const isRender = type === 'render'
|
|
54
|
+
|
|
54
55
|
if (validating) {
|
|
55
56
|
finalProps.endAdornment = [(
|
|
56
57
|
<InputAdornment position="end">
|
|
@@ -127,7 +128,6 @@ const FormControlField = ({
|
|
|
127
128
|
|
|
128
129
|
FormControlField.propTypes = {
|
|
129
130
|
variant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
|
|
130
|
-
isRender: PropTypes.bool,
|
|
131
131
|
component: PropTypes.any.isRequired,
|
|
132
132
|
componentProps: PropTypes.object,
|
|
133
133
|
type: PropTypes.string.isRequired,
|
|
@@ -190,7 +190,6 @@ const FormField = ({
|
|
|
190
190
|
|
|
191
191
|
FormField.propTypes = {
|
|
192
192
|
variant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
|
|
193
|
-
isRender: PropTypes.bool,
|
|
194
193
|
component: PropTypes.any.isRequired,
|
|
195
194
|
componentProps: PropTypes.object,
|
|
196
195
|
type: PropTypes.string.isRequired,
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
|
|
4
4
|
import { TextField, MenuItem } from '@material-ui/core'
|
|
5
5
|
|
|
6
|
-
const FormSelect = ({ options, required, ...props }) => {
|
|
6
|
+
const FormSelect = ({ options, required, value, ...props }) => {
|
|
7
7
|
let unselectOption = []
|
|
8
8
|
|
|
9
9
|
if (!required) {
|
|
@@ -19,6 +19,7 @@ const FormSelect = ({ options, required, ...props }) => {
|
|
|
19
19
|
<TextField
|
|
20
20
|
select
|
|
21
21
|
required={required}
|
|
22
|
+
value={value === undefined ? '' : value}
|
|
22
23
|
{...props}
|
|
23
24
|
>
|
|
24
25
|
{
|
package/src/FormulatorForm.jsx
CHANGED
|
@@ -361,12 +361,13 @@ class FormulatorForm extends React.Component {
|
|
|
361
361
|
readOnly,
|
|
362
362
|
listErrors,
|
|
363
363
|
schema,
|
|
364
|
-
hideSensitiveData,
|
|
365
364
|
renderSchema,
|
|
366
365
|
disabled: propDisabled,
|
|
367
366
|
translations,
|
|
368
367
|
componentMap,
|
|
369
368
|
renderComponentMap,
|
|
369
|
+
obscuredFields,
|
|
370
|
+
obscuredGroups,
|
|
370
371
|
errorMessages,
|
|
371
372
|
onReset
|
|
372
373
|
} = this.props
|
|
@@ -408,7 +409,7 @@ class FormulatorForm extends React.Component {
|
|
|
408
409
|
{
|
|
409
410
|
renderSchema.groups
|
|
410
411
|
.map(({ id: sectionId, label, description, fields }) => {
|
|
411
|
-
if (
|
|
412
|
+
if (readOnly && Array.isArray(obscuredGroups) && obscuredGroups.includes(sectionId)) {
|
|
412
413
|
return <HiddenData subject="Der Bereich" label={label} />
|
|
413
414
|
}
|
|
414
415
|
|
|
@@ -428,10 +429,10 @@ class FormulatorForm extends React.Component {
|
|
|
428
429
|
label={label}
|
|
429
430
|
desc={description}
|
|
430
431
|
fields={fields}
|
|
431
|
-
hideSensitiveData={hideSensitiveData}
|
|
432
432
|
results={results}
|
|
433
433
|
data={data}
|
|
434
434
|
fieldStates={fieldStates}
|
|
435
|
+
obscuredFields={obscuredFields}
|
|
435
436
|
translations={translations}
|
|
436
437
|
errorMessages={errorMessages}
|
|
437
438
|
componentMap={componentMap}
|
|
@@ -513,7 +514,6 @@ FormulatorForm.propTypes = {
|
|
|
513
514
|
listErrors: PropTypes.bool,
|
|
514
515
|
schema: PropTypes.object.isRequired,
|
|
515
516
|
data: PropTypes.object.isRequired,
|
|
516
|
-
hideSensitiveData: PropTypes.bool,
|
|
517
517
|
transientData: PropTypes.object,
|
|
518
518
|
fieldStates: PropTypes.object,
|
|
519
519
|
renderSchema: PropTypes.object.isRequired,
|
|
@@ -522,6 +522,8 @@ FormulatorForm.propTypes = {
|
|
|
522
522
|
errorMessages: PropTypes.object,
|
|
523
523
|
componentMap: PropTypes.object,
|
|
524
524
|
renderComponentMap: PropTypes.object,
|
|
525
|
+
obscuredFields: PropTypes.array,
|
|
526
|
+
obscuredGroups: PropTypes.array,
|
|
525
527
|
onSubmit: PropTypes.func,
|
|
526
528
|
onReset: PropTypes.func,
|
|
527
529
|
onStatusUpdate: PropTypes.func,
|
|
@@ -60,18 +60,23 @@ class FormulatorFormSection extends React.Component {
|
|
|
60
60
|
errorMessages,
|
|
61
61
|
results,
|
|
62
62
|
data,
|
|
63
|
-
fieldStates
|
|
63
|
+
fieldStates,
|
|
64
|
+
renderComponentMap
|
|
64
65
|
} = this.props
|
|
65
66
|
|
|
66
67
|
let field = fieldEntry, specialProps = {}
|
|
67
68
|
if (Array.isArray(fieldEntry)) {
|
|
68
69
|
if (fieldEntry[0] === '@@render') {
|
|
69
70
|
field = fieldEntry[1]
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
return ({
|
|
72
|
+
type: 'render',
|
|
73
|
+
name: field,
|
|
74
|
+
component: renderComponentMap[field],
|
|
75
|
+
componentProps: fieldEntry[2] || {}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (fieldEntry[0] === '@@markdown') {
|
|
75
80
|
return ({
|
|
76
81
|
type: 'markdown',
|
|
77
82
|
name: fieldEntry[1],
|
|
@@ -80,11 +85,12 @@ class FormulatorFormSection extends React.Component {
|
|
|
80
85
|
content: fieldEntry[2]
|
|
81
86
|
}
|
|
82
87
|
})
|
|
83
|
-
} else {
|
|
84
|
-
field = fieldEntry[0]
|
|
85
|
-
if (!fieldEntry[1]) throw new Error(`field "${field}" is defined in an array, but has no props definition`)
|
|
86
|
-
specialProps = fieldEntry[1]
|
|
87
88
|
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
field = fieldEntry[0]
|
|
92
|
+
if (!fieldEntry[1]) throw new Error(`field "${field}" is defined in an array, but has no props definition`)
|
|
93
|
+
specialProps = fieldEntry[1]
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
const { hidden, hideLabel, ...extraProps } = specialProps
|
|
@@ -98,14 +104,13 @@ class FormulatorFormSection extends React.Component {
|
|
|
98
104
|
const { type, default: defaultValue } = schema.properties[field]
|
|
99
105
|
|
|
100
106
|
let mapKey
|
|
101
|
-
if (
|
|
102
|
-
else if (componentMap[field] !== undefined) mapKey = field
|
|
107
|
+
if (componentMap[field] !== undefined) mapKey = field
|
|
103
108
|
else if (typeof type === 'string' && componentMap[type] !== undefined) mapKey = type
|
|
104
109
|
else if (Array.isArray(type)) mapKey = 'select'
|
|
105
110
|
else if (componentMap.default !== undefined) mapKey = 'default'
|
|
106
111
|
else throw new Error(`Could not find a Component to render for "${field}"`)
|
|
107
112
|
|
|
108
|
-
const mapEntry =
|
|
113
|
+
const mapEntry = componentMap[mapKey]
|
|
109
114
|
let component = mapEntry, props = {}
|
|
110
115
|
|
|
111
116
|
if (mapKey === 'select') {
|
|
@@ -165,7 +170,7 @@ class FormulatorFormSection extends React.Component {
|
|
|
165
170
|
nested = 0,
|
|
166
171
|
schema,
|
|
167
172
|
fields,
|
|
168
|
-
|
|
173
|
+
obscuredFields,
|
|
169
174
|
results,
|
|
170
175
|
data,
|
|
171
176
|
fieldStates,
|
|
@@ -208,7 +213,12 @@ class FormulatorFormSection extends React.Component {
|
|
|
208
213
|
dirty
|
|
209
214
|
} = fieldProps
|
|
210
215
|
|
|
211
|
-
if (readOnly
|
|
216
|
+
if (readOnly) {
|
|
217
|
+
if (!value) return false
|
|
218
|
+
if (Array.isArray(obscuredFields) && obscuredFields.includes(name)) {
|
|
219
|
+
return <HiddenData subject="Das Feld" label={label} />
|
|
220
|
+
}
|
|
221
|
+
}
|
|
212
222
|
|
|
213
223
|
return React.createElement(
|
|
214
224
|
readOnly ? FormReadOnlyField : FormField,
|
|
@@ -219,7 +229,6 @@ class FormulatorFormSection extends React.Component {
|
|
|
219
229
|
type,
|
|
220
230
|
label,
|
|
221
231
|
value,
|
|
222
|
-
isRender: true,
|
|
223
232
|
required,
|
|
224
233
|
hasErrors,
|
|
225
234
|
errors,
|
|
@@ -251,9 +260,9 @@ class FormulatorFormSection extends React.Component {
|
|
|
251
260
|
schema={schema}
|
|
252
261
|
label={fieldEntry.label}
|
|
253
262
|
fields={fieldEntry.fields}
|
|
254
|
-
hideSensitiveData={hideSensitiveData}
|
|
255
263
|
results={results}
|
|
256
264
|
data={data}
|
|
265
|
+
obscuredFields={obscuredFields}
|
|
257
266
|
fieldStates={fieldStates}
|
|
258
267
|
translations={translations}
|
|
259
268
|
errorMessages={errorMessages}
|
|
@@ -285,7 +294,12 @@ class FormulatorFormSection extends React.Component {
|
|
|
285
294
|
dirty
|
|
286
295
|
} = fieldProps
|
|
287
296
|
|
|
288
|
-
if (readOnly
|
|
297
|
+
if (readOnly) {
|
|
298
|
+
if (!value) return false
|
|
299
|
+
if (Array.isArray(obscuredFields) && obscuredFields.includes(name)) {
|
|
300
|
+
return <HiddenData subject="Das Feld" label={label} />
|
|
301
|
+
}
|
|
302
|
+
}
|
|
289
303
|
|
|
290
304
|
const apProps = {}
|
|
291
305
|
|
|
@@ -331,10 +345,6 @@ class FormulatorFormSection extends React.Component {
|
|
|
331
345
|
|
|
332
346
|
const FormFieldComponent = readOnly ? FormReadOnlyField : FormField
|
|
333
347
|
|
|
334
|
-
if (hideSensitiveData && (name === 'reportingPin' || name === 'reportingAuthCode')) {
|
|
335
|
-
return <HiddenData subject="Das Feld" label={label} />
|
|
336
|
-
}
|
|
337
|
-
|
|
338
348
|
return (
|
|
339
349
|
React.createElement(
|
|
340
350
|
FormFieldComponent,
|
|
@@ -481,7 +491,7 @@ FormulatorFormSection.propTypes = {
|
|
|
481
491
|
nested: PropTypes.number,
|
|
482
492
|
sectionId: PropTypes.string.isRequired,
|
|
483
493
|
fields: PropTypes.array.isRequired,
|
|
484
|
-
|
|
494
|
+
obscuredFields: PropTypes.array,
|
|
485
495
|
schema: PropTypes.object.isRequired,
|
|
486
496
|
results: PropTypes.object.isRequired,
|
|
487
497
|
data: PropTypes.object.isRequired,
|
|
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
|
|
|
4
4
|
import { Typography, Box } from '@material-ui/core'
|
|
5
5
|
|
|
6
6
|
const FormControlField = ({
|
|
7
|
-
|
|
7
|
+
type,
|
|
8
8
|
name,
|
|
9
9
|
label,
|
|
10
10
|
component,
|
|
@@ -28,7 +28,7 @@ const FormControlField = ({
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
let control
|
|
31
|
-
if (
|
|
31
|
+
if (type === 'render') control = React.cloneElement(component, finalProps)
|
|
32
32
|
else control = React.createElement(component, finalProps)
|
|
33
33
|
|
|
34
34
|
return (
|
|
@@ -55,10 +55,10 @@ const FormControlField = ({
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
FormControlField.propTypes = {
|
|
58
|
-
isRender: PropTypes.bool,
|
|
59
58
|
component: PropTypes.any.isRequired,
|
|
60
59
|
componentProps: PropTypes.object,
|
|
61
60
|
name: PropTypes.string.isRequired,
|
|
61
|
+
type: PropTypes.string.isRequired,
|
|
62
62
|
label: PropTypes.string.isRequired,
|
|
63
63
|
value: PropTypes.oneOfType([
|
|
64
64
|
PropTypes.string,
|
|
@@ -3,17 +3,27 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
|
|
4
4
|
import { Typography } from '@material-ui/core'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
<Typography variant="body1">
|
|
8
|
-
{value}
|
|
9
|
-
</Typography>
|
|
10
|
-
)
|
|
6
|
+
import { DateTime } from 'luxon'
|
|
11
7
|
|
|
12
|
-
|
|
8
|
+
const FormReadOnlyText = ({ value, type }) => {
|
|
9
|
+
let finalValue = value
|
|
10
|
+
|
|
11
|
+
if (type === 'date' || type === 'datetime-local') {
|
|
12
|
+
finalValue = DateTime.fromISO(value).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Typography variant="body1">
|
|
17
|
+
{finalValue}
|
|
18
|
+
</Typography>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
FormReadOnlyText.propTypes = {
|
|
13
23
|
value: PropTypes.oneOfType([
|
|
14
24
|
PropTypes.number,
|
|
15
25
|
PropTypes.string
|
|
16
26
|
])
|
|
17
27
|
}
|
|
18
28
|
|
|
19
|
-
export default
|
|
29
|
+
export default FormReadOnlyText
|