@scenid/react-formulator 0.4.4 → 0.5.0
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 +78 -30
- package/dist/index.esm.js +77 -28
- package/package.json +2 -2
- package/src/Editable/FormRepeater.jsx +75 -48
- package/src/FormulatorFormSection.jsx +12 -5
- package/stories/Forms.stories.jsx +9 -1
- package/stories/forms/types.schemas.js +15 -0
package/dist/index.cjs.js
CHANGED
|
@@ -29,8 +29,7 @@ var utils = require('@material-ui/core/utils');
|
|
|
29
29
|
var _MenuItem = require('@material-ui/core/esm/MenuItem');
|
|
30
30
|
var _Switch = require('@material-ui/core/esm/Switch');
|
|
31
31
|
var _Checkbox = require('@material-ui/core/esm/Checkbox');
|
|
32
|
-
var
|
|
33
|
-
var _InputLabel = require('@material-ui/core/esm/InputLabel');
|
|
32
|
+
var _ClickAwayListener = require('@material-ui/core/esm/ClickAwayListener');
|
|
34
33
|
var _Clear = require('@material-ui/icons/esm/Clear');
|
|
35
34
|
var _Save = require('@material-ui/icons/esm/Save');
|
|
36
35
|
var _Button = require('@material-ui/core/esm/Button');
|
|
@@ -98,8 +97,7 @@ var Chip__default = /*#__PURE__*/_interopDefaultLegacy(Chip);
|
|
|
98
97
|
var _MenuItem__default = /*#__PURE__*/_interopDefaultLegacy(_MenuItem);
|
|
99
98
|
var _Switch__default = /*#__PURE__*/_interopDefaultLegacy(_Switch);
|
|
100
99
|
var _Checkbox__default = /*#__PURE__*/_interopDefaultLegacy(_Checkbox);
|
|
101
|
-
var
|
|
102
|
-
var _InputLabel__default = /*#__PURE__*/_interopDefaultLegacy(_InputLabel);
|
|
100
|
+
var _ClickAwayListener__default = /*#__PURE__*/_interopDefaultLegacy(_ClickAwayListener);
|
|
103
101
|
var _Clear__default = /*#__PURE__*/_interopDefaultLegacy(_Clear);
|
|
104
102
|
var _Save__default = /*#__PURE__*/_interopDefaultLegacy(_Save);
|
|
105
103
|
var _Button__default = /*#__PURE__*/_interopDefaultLegacy(_Button);
|
|
@@ -19715,7 +19713,7 @@ function require_Error () {
|
|
|
19715
19713
|
|
|
19716
19714
|
var _super2 = _createSuper(ValidationError);
|
|
19717
19715
|
|
|
19718
|
-
function ValidationError(message, path, validator, options) {
|
|
19716
|
+
function ValidationError(message, path, validator, options, index) {
|
|
19719
19717
|
var _this2;
|
|
19720
19718
|
|
|
19721
19719
|
(0, _classCallCheck2["default"])(this, ValidationError);
|
|
@@ -19723,6 +19721,7 @@ function require_Error () {
|
|
|
19723
19721
|
_this2.path = path;
|
|
19724
19722
|
_this2.validator = validator;
|
|
19725
19723
|
_this2.options = options;
|
|
19724
|
+
_this2.index = index;
|
|
19726
19725
|
return _this2;
|
|
19727
19726
|
}
|
|
19728
19727
|
|
|
@@ -28390,24 +28389,36 @@ function requireValidator () {
|
|
|
28390
28389
|
}
|
|
28391
28390
|
}, {
|
|
28392
28391
|
key: "validateType",
|
|
28393
|
-
value: function validateType(name, field, value, otherFields) {
|
|
28392
|
+
value: function validateType(name, field, value, otherFields, index) {
|
|
28394
28393
|
var type = field.type,
|
|
28395
28394
|
validator = field.validator,
|
|
28396
28395
|
options = field.options;
|
|
28397
28396
|
|
|
28397
|
+
if (type === 'array' && validator && Array.isArray(value)) {
|
|
28398
|
+
for (var i = 0; i < value.length; i++) {
|
|
28399
|
+
this.validateType(name, {
|
|
28400
|
+
type: 'string',
|
|
28401
|
+
validator: validator,
|
|
28402
|
+
options: options
|
|
28403
|
+
}, value[i], otherFields, i);
|
|
28404
|
+
}
|
|
28405
|
+
|
|
28406
|
+
return true;
|
|
28407
|
+
}
|
|
28408
|
+
|
|
28398
28409
|
if (validator === undefined) {
|
|
28399
|
-
if (type === undefined) throw new _Error.SchemaError("Invalid type definition \"".concat(type, "\" at path \"").concat(name, "\"."));
|
|
28410
|
+
if (type === undefined) throw new _Error.SchemaError("Invalid type definition \"".concat(type, "\" at path \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\"."));
|
|
28400
28411
|
|
|
28401
28412
|
if (this.validateBaseType(type, value) === false) {
|
|
28402
|
-
if (Array.isArray(type)) throw new _Error.ValidationError("\"".concat(
|
|
28413
|
+
if (Array.isArray(type)) throw new _Error.ValidationError("invalid value for \"".concat(name).concat(index ? "[".concat(index, "]") : '', "\""), name, 'enum', type, index);else throw new _Error.ValidationError("value is not of type \"".concat(type, "\" in \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\""), name, type, index);
|
|
28403
28414
|
}
|
|
28404
28415
|
} else {
|
|
28405
28416
|
var func = _TypeValidator["default"]["is".concat(validator)];
|
|
28406
28417
|
|
|
28407
|
-
if (typeof func !== 'function') throw new _Error.SchemaError("Unknown validator \"".concat(validator, "\" at path \"").concat(name, "\"."));
|
|
28418
|
+
if (typeof func !== 'function') throw new _Error.SchemaError("Unknown validator \"".concat(validator, "\" at path \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\"."));
|
|
28408
28419
|
|
|
28409
28420
|
if (func(String(value), options, otherFields) === false) {
|
|
28410
|
-
throw new _Error.ValidationError('invalid', name, validator, options);
|
|
28421
|
+
throw new _Error.ValidationError('invalid', name, validator, options, index);
|
|
28411
28422
|
}
|
|
28412
28423
|
}
|
|
28413
28424
|
|
|
@@ -28494,12 +28505,14 @@ function requireValidator () {
|
|
|
28494
28505
|
this.validateType(name, schema[name], value, data);
|
|
28495
28506
|
} catch (e) {
|
|
28496
28507
|
if (!(e instanceof _Error.ValidationError)) throw e;
|
|
28497
|
-
|
|
28508
|
+
var errorEntry = {
|
|
28498
28509
|
message: e.message,
|
|
28499
28510
|
path: e.path,
|
|
28500
28511
|
validator: e.validator,
|
|
28501
28512
|
options: e.options
|
|
28502
|
-
}
|
|
28513
|
+
};
|
|
28514
|
+
if (e.index) errorEntry.index = e.index;
|
|
28515
|
+
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional, true, [errorEntry]);
|
|
28503
28516
|
}
|
|
28504
28517
|
|
|
28505
28518
|
return new FieldResult(name, data[name], this.castType(name, type, value), isProhibited, isRequired, isOptional);
|
|
@@ -32132,8 +32145,9 @@ var getValue$1 = function getValue(value, catalog) {
|
|
|
32132
32145
|
var FormRepeater = function FormRepeater(_ref) {
|
|
32133
32146
|
var variant = _ref.variant,
|
|
32134
32147
|
name = _ref.name,
|
|
32148
|
+
label = _ref.label,
|
|
32135
32149
|
value = _ref.value,
|
|
32136
|
-
|
|
32150
|
+
options = _ref.options,
|
|
32137
32151
|
onChange = _ref.onChange;
|
|
32138
32152
|
|
|
32139
32153
|
var _useState = React.useState(value || []),
|
|
@@ -32151,6 +32165,11 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32151
32165
|
inputValue = _useState6[0],
|
|
32152
32166
|
setInputValue = _useState6[1];
|
|
32153
32167
|
|
|
32168
|
+
var _useState7 = React.useState(''),
|
|
32169
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
32170
|
+
catalogSelectValue = _useState8[0],
|
|
32171
|
+
setCatalogSelectValue = _useState8[1];
|
|
32172
|
+
|
|
32154
32173
|
var handleEntryAdd = function handleEntryAdd() {
|
|
32155
32174
|
if (inputValue.length > 0) {
|
|
32156
32175
|
setEntries([].concat(_toConsumableArray(entries), [inputValue]));
|
|
@@ -32161,6 +32180,7 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32161
32180
|
var handleCancelNewEntry = function handleCancelNewEntry() {
|
|
32162
32181
|
setInEdit(false);
|
|
32163
32182
|
setInputValue('');
|
|
32183
|
+
setCatalogSelectValue('');
|
|
32164
32184
|
};
|
|
32165
32185
|
|
|
32166
32186
|
var handleEntryDel = function handleEntryDel(delIndex) {
|
|
@@ -32181,15 +32201,23 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32181
32201
|
}, [entries]);
|
|
32182
32202
|
var blockedOptions = [];
|
|
32183
32203
|
|
|
32184
|
-
if (
|
|
32185
|
-
blockedOptions = Object.entries(
|
|
32186
|
-
return value.includes(e[0]);
|
|
32204
|
+
if (options) {
|
|
32205
|
+
blockedOptions = Object.entries(options).filter(function (e) {
|
|
32206
|
+
return Array.isArray(value) && value.includes(e[0]);
|
|
32187
32207
|
}).map(function (e) {
|
|
32188
32208
|
return e[0];
|
|
32189
32209
|
});
|
|
32190
32210
|
}
|
|
32191
32211
|
|
|
32192
|
-
return /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], null, /*#__PURE__*/React__default["default"].createElement(
|
|
32212
|
+
return /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], null, /*#__PURE__*/React__default["default"].createElement(_Typography__default["default"], {
|
|
32213
|
+
variant: "body1"
|
|
32214
|
+
}, label), (!entries || (entries === null || entries === void 0 ? void 0 : entries.length) === 0) && /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], {
|
|
32215
|
+
mt: 1,
|
|
32216
|
+
pl: 2
|
|
32217
|
+
}, /*#__PURE__*/React__default["default"].createElement(_Typography__default["default"], {
|
|
32218
|
+
variant: "body2",
|
|
32219
|
+
color: "textSecondary"
|
|
32220
|
+
}, "Keine Eintr\xE4ge vorhanden")), /*#__PURE__*/React__default["default"].createElement(_List__default["default"], {
|
|
32193
32221
|
dense: true
|
|
32194
32222
|
}, entries.map(function (entry, index) {
|
|
32195
32223
|
return (
|
|
@@ -32198,7 +32226,7 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32198
32226
|
React__default["default"].createElement(_ListItem__default["default"], {
|
|
32199
32227
|
key: "entry-".concat(index)
|
|
32200
32228
|
}, /*#__PURE__*/React__default["default"].createElement(_ListItemText__default["default"], {
|
|
32201
|
-
primary: getValue$1(entry,
|
|
32229
|
+
primary: getValue$1(entry, options)
|
|
32202
32230
|
}), /*#__PURE__*/React__default["default"].createElement(_ListItemSecondaryAction__default["default"], null, /*#__PURE__*/React__default["default"].createElement(_IconButton__default["default"], {
|
|
32203
32231
|
edge: "end",
|
|
32204
32232
|
"aria-label": "delete",
|
|
@@ -32216,10 +32244,16 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32216
32244
|
onClick: function onClick() {
|
|
32217
32245
|
return setInEdit(true);
|
|
32218
32246
|
}
|
|
32219
|
-
}, "
|
|
32247
|
+
}, "Eintr\xE4ge hinzuf\xFCgen")), inEdit && !options && /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], {
|
|
32220
32248
|
width: "100%",
|
|
32221
32249
|
display: "flex",
|
|
32222
32250
|
alignItems: "center"
|
|
32251
|
+
}, /*#__PURE__*/React__default["default"].createElement(_ClickAwayListener__default["default"], {
|
|
32252
|
+
onClickAway: function onClickAway() {
|
|
32253
|
+
if (inputValue === '') {
|
|
32254
|
+
setInEdit(false);
|
|
32255
|
+
}
|
|
32256
|
+
}
|
|
32223
32257
|
}, /*#__PURE__*/React__default["default"].createElement(_FormControl__default["default"], {
|
|
32224
32258
|
variant: "filled",
|
|
32225
32259
|
fullWidth: true
|
|
@@ -32251,22 +32285,24 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32251
32285
|
onChange: function onChange(e) {
|
|
32252
32286
|
return setInputValue(e.target.value);
|
|
32253
32287
|
}
|
|
32254
|
-
}))), inEdit &&
|
|
32288
|
+
})))), inEdit && options && /*#__PURE__*/React__default["default"].createElement(_Box__default["default"], {
|
|
32255
32289
|
width: "100%",
|
|
32256
32290
|
display: "flex",
|
|
32257
32291
|
alignItems: "center"
|
|
32258
32292
|
}, /*#__PURE__*/React__default["default"].createElement(_FormControl__default["default"], {
|
|
32259
32293
|
variant: "filled",
|
|
32260
32294
|
fullWidth: true
|
|
32261
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
32262
|
-
|
|
32295
|
+
}, /*#__PURE__*/React__default["default"].createElement(_TextField__default["default"], {
|
|
32296
|
+
label: "Eintrag ausw\xE4hlen",
|
|
32297
|
+
select: true,
|
|
32298
|
+
variant: variant,
|
|
32299
|
+
value: catalogSelectValue,
|
|
32300
|
+
onBlur: handleCancelNewEntry,
|
|
32263
32301
|
onChange: function onChange(e) {
|
|
32264
|
-
|
|
32302
|
+
setCatalogSelectValue('');
|
|
32303
|
+
setEntries([].concat(_toConsumableArray(entries), [e.target.value]));
|
|
32265
32304
|
}
|
|
32266
|
-
},
|
|
32267
|
-
value: "please-select",
|
|
32268
|
-
disabled: true
|
|
32269
|
-
}, "Eintrag hinzuf\xFCgen"), Object.entries(catalog).sort(function (a, b) {
|
|
32305
|
+
}, Object.entries(options).sort(function (a, b) {
|
|
32270
32306
|
return a[1].localeCompare(b[1]);
|
|
32271
32307
|
}).map(function (e) {
|
|
32272
32308
|
return /*#__PURE__*/React__default["default"].createElement(_MenuItem__default["default"], {
|
|
@@ -32279,9 +32315,10 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32279
32315
|
|
|
32280
32316
|
FormRepeater.propTypes = {
|
|
32281
32317
|
variant: PropTypes__default["default"].oneOf(['standard', 'filled', 'outlined']),
|
|
32282
|
-
name: PropTypes__default["default"].string
|
|
32318
|
+
name: PropTypes__default["default"].string,
|
|
32319
|
+
label: PropTypes__default["default"].string,
|
|
32283
32320
|
value: PropTypes__default["default"].any,
|
|
32284
|
-
|
|
32321
|
+
options: PropTypes__default["default"].object,
|
|
32285
32322
|
onChange: PropTypes__default["default"].func.isRequired
|
|
32286
32323
|
};
|
|
32287
32324
|
|
|
@@ -76092,11 +76129,22 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
76092
76129
|
var mapEntry = isRender ? renderComponentMap[field] : componentMap[mapKey];
|
|
76093
76130
|
var component = mapEntry,
|
|
76094
76131
|
props = {};
|
|
76132
|
+
console.log(schema.properties, fieldEntry);
|
|
76133
|
+
|
|
76134
|
+
if (mapKey === 'array' && schema.properties[fieldEntry].options) {
|
|
76135
|
+
props.options = schema.properties[fieldEntry].options.reduce(function (l, r) {
|
|
76136
|
+
var _translations$fieldEn;
|
|
76137
|
+
|
|
76138
|
+
return _objectSpread$1(_objectSpread$1({}, l), {}, _defineProperty({}, r, (translations === null || translations === void 0 ? void 0 : (_translations$fieldEn = translations[fieldEntry]) === null || _translations$fieldEn === void 0 ? void 0 : _translations$fieldEn[r]) || r));
|
|
76139
|
+
}, {});
|
|
76140
|
+
}
|
|
76095
76141
|
|
|
76096
76142
|
if (mapKey === 'select') {
|
|
76097
76143
|
props.options = type.map(function (value) {
|
|
76144
|
+
var _translations$field;
|
|
76145
|
+
|
|
76098
76146
|
return {
|
|
76099
|
-
label: translations
|
|
76147
|
+
label: (translations === null || translations === void 0 ? void 0 : (_translations$field = translations.field) === null || _translations$field === void 0 ? void 0 : _translations$field.value) || value,
|
|
76100
76148
|
value: value
|
|
76101
76149
|
};
|
|
76102
76150
|
});
|
package/dist/index.esm.js
CHANGED
|
@@ -27,8 +27,7 @@ import { createSvgIcon, unstable_useId, useControlled, useEventCallback, setRef,
|
|
|
27
27
|
import _MenuItem from '@material-ui/core/esm/MenuItem';
|
|
28
28
|
import _Switch from '@material-ui/core/esm/Switch';
|
|
29
29
|
import _Checkbox from '@material-ui/core/esm/Checkbox';
|
|
30
|
-
import
|
|
31
|
-
import _InputLabel from '@material-ui/core/esm/InputLabel';
|
|
30
|
+
import _ClickAwayListener from '@material-ui/core/esm/ClickAwayListener';
|
|
32
31
|
import _Clear from '@material-ui/icons/esm/Clear';
|
|
33
32
|
import _Save from '@material-ui/icons/esm/Save';
|
|
34
33
|
import _Button from '@material-ui/core/esm/Button';
|
|
@@ -19646,7 +19645,7 @@ function require_Error () {
|
|
|
19646
19645
|
|
|
19647
19646
|
var _super2 = _createSuper(ValidationError);
|
|
19648
19647
|
|
|
19649
|
-
function ValidationError(message, path, validator, options) {
|
|
19648
|
+
function ValidationError(message, path, validator, options, index) {
|
|
19650
19649
|
var _this2;
|
|
19651
19650
|
|
|
19652
19651
|
(0, _classCallCheck2["default"])(this, ValidationError);
|
|
@@ -19654,6 +19653,7 @@ function require_Error () {
|
|
|
19654
19653
|
_this2.path = path;
|
|
19655
19654
|
_this2.validator = validator;
|
|
19656
19655
|
_this2.options = options;
|
|
19656
|
+
_this2.index = index;
|
|
19657
19657
|
return _this2;
|
|
19658
19658
|
}
|
|
19659
19659
|
|
|
@@ -28321,24 +28321,36 @@ function requireValidator () {
|
|
|
28321
28321
|
}
|
|
28322
28322
|
}, {
|
|
28323
28323
|
key: "validateType",
|
|
28324
|
-
value: function validateType(name, field, value, otherFields) {
|
|
28324
|
+
value: function validateType(name, field, value, otherFields, index) {
|
|
28325
28325
|
var type = field.type,
|
|
28326
28326
|
validator = field.validator,
|
|
28327
28327
|
options = field.options;
|
|
28328
28328
|
|
|
28329
|
+
if (type === 'array' && validator && Array.isArray(value)) {
|
|
28330
|
+
for (var i = 0; i < value.length; i++) {
|
|
28331
|
+
this.validateType(name, {
|
|
28332
|
+
type: 'string',
|
|
28333
|
+
validator: validator,
|
|
28334
|
+
options: options
|
|
28335
|
+
}, value[i], otherFields, i);
|
|
28336
|
+
}
|
|
28337
|
+
|
|
28338
|
+
return true;
|
|
28339
|
+
}
|
|
28340
|
+
|
|
28329
28341
|
if (validator === undefined) {
|
|
28330
|
-
if (type === undefined) throw new _Error.SchemaError("Invalid type definition \"".concat(type, "\" at path \"").concat(name, "\"."));
|
|
28342
|
+
if (type === undefined) throw new _Error.SchemaError("Invalid type definition \"".concat(type, "\" at path \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\"."));
|
|
28331
28343
|
|
|
28332
28344
|
if (this.validateBaseType(type, value) === false) {
|
|
28333
|
-
if (Array.isArray(type)) throw new _Error.ValidationError("\"".concat(
|
|
28345
|
+
if (Array.isArray(type)) throw new _Error.ValidationError("invalid value for \"".concat(name).concat(index ? "[".concat(index, "]") : '', "\""), name, 'enum', type, index);else throw new _Error.ValidationError("value is not of type \"".concat(type, "\" in \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\""), name, type, index);
|
|
28334
28346
|
}
|
|
28335
28347
|
} else {
|
|
28336
28348
|
var func = _TypeValidator["default"]["is".concat(validator)];
|
|
28337
28349
|
|
|
28338
|
-
if (typeof func !== 'function') throw new _Error.SchemaError("Unknown validator \"".concat(validator, "\" at path \"").concat(name, "\"."));
|
|
28350
|
+
if (typeof func !== 'function') throw new _Error.SchemaError("Unknown validator \"".concat(validator, "\" at path \"").concat(name).concat(index ? "[".concat(index, "]") : '', "\"."));
|
|
28339
28351
|
|
|
28340
28352
|
if (func(String(value), options, otherFields) === false) {
|
|
28341
|
-
throw new _Error.ValidationError('invalid', name, validator, options);
|
|
28353
|
+
throw new _Error.ValidationError('invalid', name, validator, options, index);
|
|
28342
28354
|
}
|
|
28343
28355
|
}
|
|
28344
28356
|
|
|
@@ -28425,12 +28437,14 @@ function requireValidator () {
|
|
|
28425
28437
|
this.validateType(name, schema[name], value, data);
|
|
28426
28438
|
} catch (e) {
|
|
28427
28439
|
if (!(e instanceof _Error.ValidationError)) throw e;
|
|
28428
|
-
|
|
28440
|
+
var errorEntry = {
|
|
28429
28441
|
message: e.message,
|
|
28430
28442
|
path: e.path,
|
|
28431
28443
|
validator: e.validator,
|
|
28432
28444
|
options: e.options
|
|
28433
|
-
}
|
|
28445
|
+
};
|
|
28446
|
+
if (e.index) errorEntry.index = e.index;
|
|
28447
|
+
return new FieldResult(name, data[name], undefined, isProhibited, isRequired, isOptional, true, [errorEntry]);
|
|
28434
28448
|
}
|
|
28435
28449
|
|
|
28436
28450
|
return new FieldResult(name, data[name], this.castType(name, type, value), isProhibited, isRequired, isOptional);
|
|
@@ -32063,8 +32077,9 @@ var getValue$1 = function getValue(value, catalog) {
|
|
|
32063
32077
|
var FormRepeater = function FormRepeater(_ref) {
|
|
32064
32078
|
var variant = _ref.variant,
|
|
32065
32079
|
name = _ref.name,
|
|
32080
|
+
label = _ref.label,
|
|
32066
32081
|
value = _ref.value,
|
|
32067
|
-
|
|
32082
|
+
options = _ref.options,
|
|
32068
32083
|
onChange = _ref.onChange;
|
|
32069
32084
|
|
|
32070
32085
|
var _useState = useState(value || []),
|
|
@@ -32082,6 +32097,11 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32082
32097
|
inputValue = _useState6[0],
|
|
32083
32098
|
setInputValue = _useState6[1];
|
|
32084
32099
|
|
|
32100
|
+
var _useState7 = useState(''),
|
|
32101
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
32102
|
+
catalogSelectValue = _useState8[0],
|
|
32103
|
+
setCatalogSelectValue = _useState8[1];
|
|
32104
|
+
|
|
32085
32105
|
var handleEntryAdd = function handleEntryAdd() {
|
|
32086
32106
|
if (inputValue.length > 0) {
|
|
32087
32107
|
setEntries([].concat(_toConsumableArray(entries), [inputValue]));
|
|
@@ -32092,6 +32112,7 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32092
32112
|
var handleCancelNewEntry = function handleCancelNewEntry() {
|
|
32093
32113
|
setInEdit(false);
|
|
32094
32114
|
setInputValue('');
|
|
32115
|
+
setCatalogSelectValue('');
|
|
32095
32116
|
};
|
|
32096
32117
|
|
|
32097
32118
|
var handleEntryDel = function handleEntryDel(delIndex) {
|
|
@@ -32112,15 +32133,23 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32112
32133
|
}, [entries]);
|
|
32113
32134
|
var blockedOptions = [];
|
|
32114
32135
|
|
|
32115
|
-
if (
|
|
32116
|
-
blockedOptions = Object.entries(
|
|
32117
|
-
return value.includes(e[0]);
|
|
32136
|
+
if (options) {
|
|
32137
|
+
blockedOptions = Object.entries(options).filter(function (e) {
|
|
32138
|
+
return Array.isArray(value) && value.includes(e[0]);
|
|
32118
32139
|
}).map(function (e) {
|
|
32119
32140
|
return e[0];
|
|
32120
32141
|
});
|
|
32121
32142
|
}
|
|
32122
32143
|
|
|
32123
|
-
return /*#__PURE__*/React__default.createElement(_Box, null, /*#__PURE__*/React__default.createElement(
|
|
32144
|
+
return /*#__PURE__*/React__default.createElement(_Box, null, /*#__PURE__*/React__default.createElement(_Typography, {
|
|
32145
|
+
variant: "body1"
|
|
32146
|
+
}, label), (!entries || (entries === null || entries === void 0 ? void 0 : entries.length) === 0) && /*#__PURE__*/React__default.createElement(_Box, {
|
|
32147
|
+
mt: 1,
|
|
32148
|
+
pl: 2
|
|
32149
|
+
}, /*#__PURE__*/React__default.createElement(_Typography, {
|
|
32150
|
+
variant: "body2",
|
|
32151
|
+
color: "textSecondary"
|
|
32152
|
+
}, "Keine Eintr\xE4ge vorhanden")), /*#__PURE__*/React__default.createElement(_List, {
|
|
32124
32153
|
dense: true
|
|
32125
32154
|
}, entries.map(function (entry, index) {
|
|
32126
32155
|
return (
|
|
@@ -32129,7 +32158,7 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32129
32158
|
React__default.createElement(_ListItem, {
|
|
32130
32159
|
key: "entry-".concat(index)
|
|
32131
32160
|
}, /*#__PURE__*/React__default.createElement(_ListItemText, {
|
|
32132
|
-
primary: getValue$1(entry,
|
|
32161
|
+
primary: getValue$1(entry, options)
|
|
32133
32162
|
}), /*#__PURE__*/React__default.createElement(_ListItemSecondaryAction, null, /*#__PURE__*/React__default.createElement(_IconButton, {
|
|
32134
32163
|
edge: "end",
|
|
32135
32164
|
"aria-label": "delete",
|
|
@@ -32147,10 +32176,16 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32147
32176
|
onClick: function onClick() {
|
|
32148
32177
|
return setInEdit(true);
|
|
32149
32178
|
}
|
|
32150
|
-
}, "
|
|
32179
|
+
}, "Eintr\xE4ge hinzuf\xFCgen")), inEdit && !options && /*#__PURE__*/React__default.createElement(_Box, {
|
|
32151
32180
|
width: "100%",
|
|
32152
32181
|
display: "flex",
|
|
32153
32182
|
alignItems: "center"
|
|
32183
|
+
}, /*#__PURE__*/React__default.createElement(_ClickAwayListener, {
|
|
32184
|
+
onClickAway: function onClickAway() {
|
|
32185
|
+
if (inputValue === '') {
|
|
32186
|
+
setInEdit(false);
|
|
32187
|
+
}
|
|
32188
|
+
}
|
|
32154
32189
|
}, /*#__PURE__*/React__default.createElement(_FormControl, {
|
|
32155
32190
|
variant: "filled",
|
|
32156
32191
|
fullWidth: true
|
|
@@ -32182,22 +32217,24 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32182
32217
|
onChange: function onChange(e) {
|
|
32183
32218
|
return setInputValue(e.target.value);
|
|
32184
32219
|
}
|
|
32185
|
-
}))), inEdit &&
|
|
32220
|
+
})))), inEdit && options && /*#__PURE__*/React__default.createElement(_Box, {
|
|
32186
32221
|
width: "100%",
|
|
32187
32222
|
display: "flex",
|
|
32188
32223
|
alignItems: "center"
|
|
32189
32224
|
}, /*#__PURE__*/React__default.createElement(_FormControl, {
|
|
32190
32225
|
variant: "filled",
|
|
32191
32226
|
fullWidth: true
|
|
32192
|
-
}, /*#__PURE__*/React__default.createElement(
|
|
32193
|
-
|
|
32227
|
+
}, /*#__PURE__*/React__default.createElement(_TextField, {
|
|
32228
|
+
label: "Eintrag ausw\xE4hlen",
|
|
32229
|
+
select: true,
|
|
32230
|
+
variant: variant,
|
|
32231
|
+
value: catalogSelectValue,
|
|
32232
|
+
onBlur: handleCancelNewEntry,
|
|
32194
32233
|
onChange: function onChange(e) {
|
|
32195
|
-
|
|
32234
|
+
setCatalogSelectValue('');
|
|
32235
|
+
setEntries([].concat(_toConsumableArray(entries), [e.target.value]));
|
|
32196
32236
|
}
|
|
32197
|
-
},
|
|
32198
|
-
value: "please-select",
|
|
32199
|
-
disabled: true
|
|
32200
|
-
}, "Eintrag hinzuf\xFCgen"), Object.entries(catalog).sort(function (a, b) {
|
|
32237
|
+
}, Object.entries(options).sort(function (a, b) {
|
|
32201
32238
|
return a[1].localeCompare(b[1]);
|
|
32202
32239
|
}).map(function (e) {
|
|
32203
32240
|
return /*#__PURE__*/React__default.createElement(_MenuItem, {
|
|
@@ -32210,9 +32247,10 @@ var FormRepeater = function FormRepeater(_ref) {
|
|
|
32210
32247
|
|
|
32211
32248
|
FormRepeater.propTypes = {
|
|
32212
32249
|
variant: PropTypes__default.oneOf(['standard', 'filled', 'outlined']),
|
|
32213
|
-
name: PropTypes__default.string
|
|
32250
|
+
name: PropTypes__default.string,
|
|
32251
|
+
label: PropTypes__default.string,
|
|
32214
32252
|
value: PropTypes__default.any,
|
|
32215
|
-
|
|
32253
|
+
options: PropTypes__default.object,
|
|
32216
32254
|
onChange: PropTypes__default.func.isRequired
|
|
32217
32255
|
};
|
|
32218
32256
|
|
|
@@ -76023,11 +76061,22 @@ var FormulatorFormSection = /*#__PURE__*/function (_React$Component) {
|
|
|
76023
76061
|
var mapEntry = isRender ? renderComponentMap[field] : componentMap[mapKey];
|
|
76024
76062
|
var component = mapEntry,
|
|
76025
76063
|
props = {};
|
|
76064
|
+
console.log(schema.properties, fieldEntry);
|
|
76065
|
+
|
|
76066
|
+
if (mapKey === 'array' && schema.properties[fieldEntry].options) {
|
|
76067
|
+
props.options = schema.properties[fieldEntry].options.reduce(function (l, r) {
|
|
76068
|
+
var _translations$fieldEn;
|
|
76069
|
+
|
|
76070
|
+
return _objectSpread$1(_objectSpread$1({}, l), {}, _defineProperty({}, r, (translations === null || translations === void 0 ? void 0 : (_translations$fieldEn = translations[fieldEntry]) === null || _translations$fieldEn === void 0 ? void 0 : _translations$fieldEn[r]) || r));
|
|
76071
|
+
}, {});
|
|
76072
|
+
}
|
|
76026
76073
|
|
|
76027
76074
|
if (mapKey === 'select') {
|
|
76028
76075
|
props.options = type.map(function (value) {
|
|
76076
|
+
var _translations$field;
|
|
76077
|
+
|
|
76029
76078
|
return {
|
|
76030
|
-
label: translations
|
|
76079
|
+
label: (translations === null || translations === void 0 ? void 0 : (_translations$field = translations.field) === null || _translations$field === void 0 ? void 0 : _translations$field.value) || value,
|
|
76031
76080
|
value: value
|
|
76032
76081
|
};
|
|
76033
76082
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenid/react-formulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^13.2.1",
|
|
48
48
|
"@scenid/cloud-icons": "^2.6.0",
|
|
49
|
-
"@scenid/formulator": "^2.
|
|
49
|
+
"@scenid/formulator": "^2.1.1",
|
|
50
50
|
"@storybook/addon-actions": "^6.4.22",
|
|
51
51
|
"@storybook/addon-essentials": "^6.4.22",
|
|
52
52
|
"@storybook/addon-interactions": "^6.4.22",
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
IconButton,
|
|
13
13
|
InputAdornment,
|
|
14
14
|
FormControl,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
Typography,
|
|
16
|
+
MenuItem,
|
|
17
|
+
ClickAwayListener
|
|
18
18
|
} from '@material-ui/core'
|
|
19
19
|
|
|
20
20
|
import {
|
|
@@ -28,10 +28,11 @@ const getValue = (value, catalog) => {
|
|
|
28
28
|
return value
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const FormRepeater = ({ variant, name, value,
|
|
31
|
+
const FormRepeater = ({ variant, name, label, value, options, onChange }) => {
|
|
32
32
|
const [entries, setEntries] = useState(value || [])
|
|
33
33
|
const [inEdit, setInEdit] = useState(false)
|
|
34
34
|
const [inputValue, setInputValue] = useState('')
|
|
35
|
+
const [catalogSelectValue, setCatalogSelectValue] = useState('')
|
|
35
36
|
|
|
36
37
|
const handleEntryAdd = () => {
|
|
37
38
|
if (inputValue.length > 0) {
|
|
@@ -43,6 +44,7 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
43
44
|
const handleCancelNewEntry = () => {
|
|
44
45
|
setInEdit(false)
|
|
45
46
|
setInputValue('')
|
|
47
|
+
setCatalogSelectValue('')
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
const handleEntryDel = delIndex => {
|
|
@@ -57,18 +59,31 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
57
59
|
}, [entries])
|
|
58
60
|
|
|
59
61
|
let blockedOptions = []
|
|
60
|
-
if (
|
|
61
|
-
blockedOptions = Object.entries(
|
|
62
|
+
if (options) {
|
|
63
|
+
blockedOptions = Object.entries(options).filter(e => Array.isArray(value) && value.includes(e[0])).map(e => e[0])
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
return (
|
|
65
67
|
<Box>
|
|
68
|
+
<Typography variant="body1">
|
|
69
|
+
{label}
|
|
70
|
+
</Typography>
|
|
71
|
+
{
|
|
72
|
+
(!entries || entries?.length === 0)
|
|
73
|
+
&& (
|
|
74
|
+
<Box mt={1} pl={2}>
|
|
75
|
+
<Typography variant="body2" color="textSecondary">
|
|
76
|
+
Keine Einträge vorhanden
|
|
77
|
+
</Typography>
|
|
78
|
+
</Box>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
66
81
|
<List dense>
|
|
67
82
|
{
|
|
68
83
|
entries.map((entry, index) => (
|
|
69
84
|
// eslint-disable-next-line react/no-array-index-key
|
|
70
85
|
<ListItem key={`entry-${index}`}>
|
|
71
|
-
<ListItemText primary={getValue(entry,
|
|
86
|
+
<ListItemText primary={getValue(entry, options)} />
|
|
72
87
|
<ListItemSecondaryAction>
|
|
73
88
|
<IconButton
|
|
74
89
|
edge="end"
|
|
@@ -92,53 +107,61 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
92
107
|
variant="outlined"
|
|
93
108
|
onClick={() => setInEdit(true)}
|
|
94
109
|
>
|
|
95
|
-
|
|
110
|
+
Einträge hinzufügen
|
|
96
111
|
</Button>
|
|
97
112
|
</Box>
|
|
98
113
|
)
|
|
99
114
|
}
|
|
100
115
|
{
|
|
101
|
-
(inEdit && !
|
|
116
|
+
(inEdit && !options)
|
|
102
117
|
&& (
|
|
103
118
|
<Box
|
|
104
119
|
width="100%"
|
|
105
120
|
display="flex"
|
|
106
121
|
alignItems="center"
|
|
107
122
|
>
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
<ClickAwayListener
|
|
124
|
+
onClickAway={() => {
|
|
125
|
+
if (inputValue === '') {
|
|
126
|
+
setInEdit(false)
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
111
129
|
>
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
<FormControl
|
|
131
|
+
variant="filled"
|
|
132
|
+
fullWidth
|
|
133
|
+
>
|
|
134
|
+
<TextField
|
|
135
|
+
label="Neuer Eintrag"
|
|
136
|
+
variant={variant}
|
|
137
|
+
value={inputValue}
|
|
138
|
+
InputProps={{
|
|
139
|
+
endAdornment: (
|
|
140
|
+
<InputAdornment position="end">
|
|
141
|
+
<Box mr={1}>
|
|
142
|
+
<IconButton size="small" onClick={handleEntryAdd}>
|
|
143
|
+
<SaveIcon fontSize="small" />
|
|
144
|
+
</IconButton>
|
|
145
|
+
</Box>
|
|
146
|
+
<IconButton size="small" onClick={handleCancelNewEntry}>
|
|
147
|
+
<ClearIcon fontSize="small" />
|
|
122
148
|
</IconButton>
|
|
123
|
-
</
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
onChange={e => setInputValue(e.target.value)}
|
|
135
|
-
/>
|
|
136
|
-
</FormControl>
|
|
149
|
+
</InputAdornment>
|
|
150
|
+
)
|
|
151
|
+
}}
|
|
152
|
+
onKeyDown={e => {
|
|
153
|
+
if (e.key === 'Enter') handleEntryAdd()
|
|
154
|
+
if (e.key === 'Escape') handleCancelNewEntry()
|
|
155
|
+
}}
|
|
156
|
+
onChange={e => setInputValue(e.target.value)}
|
|
157
|
+
/>
|
|
158
|
+
</FormControl>
|
|
159
|
+
</ClickAwayListener>
|
|
137
160
|
</Box>
|
|
138
161
|
)
|
|
139
162
|
}
|
|
140
163
|
{
|
|
141
|
-
(inEdit &&
|
|
164
|
+
(inEdit && options)
|
|
142
165
|
&& (
|
|
143
166
|
<Box
|
|
144
167
|
width="100%"
|
|
@@ -149,17 +172,20 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
149
172
|
variant="filled"
|
|
150
173
|
fullWidth
|
|
151
174
|
>
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
175
|
+
<TextField
|
|
176
|
+
label="Eintrag auswählen"
|
|
177
|
+
select
|
|
178
|
+
variant={variant}
|
|
179
|
+
value={catalogSelectValue}
|
|
180
|
+
onBlur={handleCancelNewEntry}
|
|
181
|
+
onChange={e => {
|
|
182
|
+
setCatalogSelectValue('')
|
|
183
|
+
setEntries([...entries, e.target.value])
|
|
184
|
+
}}
|
|
156
185
|
>
|
|
157
|
-
<MenuItem value="please-select" disabled>
|
|
158
|
-
Eintrag hinzufügen
|
|
159
|
-
</MenuItem>
|
|
160
186
|
{
|
|
161
187
|
Object
|
|
162
|
-
.entries(
|
|
188
|
+
.entries(options)
|
|
163
189
|
.sort((a, b) => a[1].localeCompare(b[1]))
|
|
164
190
|
.map(e => (
|
|
165
191
|
<MenuItem
|
|
@@ -171,7 +197,7 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
171
197
|
</MenuItem>
|
|
172
198
|
))
|
|
173
199
|
}
|
|
174
|
-
</
|
|
200
|
+
</TextField>
|
|
175
201
|
</FormControl>
|
|
176
202
|
</Box>
|
|
177
203
|
)
|
|
@@ -182,9 +208,10 @@ const FormRepeater = ({ variant, name, value, catalog, onChange }) => {
|
|
|
182
208
|
|
|
183
209
|
FormRepeater.propTypes = {
|
|
184
210
|
variant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
|
|
185
|
-
name: PropTypes.string
|
|
211
|
+
name: PropTypes.string,
|
|
212
|
+
label: PropTypes.string,
|
|
186
213
|
value: PropTypes.any,
|
|
187
|
-
|
|
214
|
+
options: PropTypes.object,
|
|
188
215
|
onChange: PropTypes.func.isRequired
|
|
189
216
|
}
|
|
190
217
|
|
|
@@ -110,14 +110,21 @@ class FormulatorFormSection extends React.Component {
|
|
|
110
110
|
const mapEntry = isRender ? renderComponentMap[field] : componentMap[mapKey]
|
|
111
111
|
let component = mapEntry, props = {}
|
|
112
112
|
|
|
113
|
+
console.log(schema.properties, fieldEntry)
|
|
114
|
+
if (mapKey === 'array' && schema.properties[fieldEntry].options) {
|
|
115
|
+
props.options = (
|
|
116
|
+
schema.properties[fieldEntry].options
|
|
117
|
+
.reduce((l, r) => ({
|
|
118
|
+
...l,
|
|
119
|
+
[r]: translations?.[fieldEntry]?.[r] || r
|
|
120
|
+
}), {})
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
113
124
|
if (mapKey === 'select') {
|
|
114
125
|
props.options = (
|
|
115
126
|
type.map(value => ({
|
|
116
|
-
label:
|
|
117
|
-
translations[field]
|
|
118
|
-
&& translations[field][value]
|
|
119
|
-
)
|
|
120
|
-
|| value,
|
|
127
|
+
label: translations?.field?.value || value,
|
|
121
128
|
value
|
|
122
129
|
}))
|
|
123
130
|
)
|
|
@@ -135,7 +135,15 @@ Types.args = {
|
|
|
135
135
|
/>
|
|
136
136
|
)
|
|
137
137
|
},
|
|
138
|
-
translations:
|
|
138
|
+
translations: {
|
|
139
|
+
...typesTranslations,
|
|
140
|
+
arrayCatalogRepeater: {
|
|
141
|
+
cat: 'Mieze',
|
|
142
|
+
dog: 'Doggo',
|
|
143
|
+
fish: 'Fishy',
|
|
144
|
+
horse: 'Horsy'
|
|
145
|
+
}
|
|
146
|
+
},
|
|
139
147
|
data: {
|
|
140
148
|
hiddenDataInput: 'Data we do not want to show in Video Calls',
|
|
141
149
|
hiddenGroupInput1: 'sensitive data',
|
|
@@ -171,6 +171,21 @@ const inputs = [
|
|
|
171
171
|
render: ['arrayRepeater'],
|
|
172
172
|
validation: { type: 'array' }
|
|
173
173
|
},
|
|
174
|
+
{
|
|
175
|
+
label: 'Repeater with Catalog',
|
|
176
|
+
key: 'arrayCatalogRepeater',
|
|
177
|
+
render: ['arrayCatalogRepeater'],
|
|
178
|
+
validation: {
|
|
179
|
+
type: 'array',
|
|
180
|
+
validator: 'In',
|
|
181
|
+
options: [
|
|
182
|
+
'cat',
|
|
183
|
+
'dog',
|
|
184
|
+
'fish',
|
|
185
|
+
'horse'
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
},
|
|
174
189
|
{
|
|
175
190
|
label: 'Autocomplete Field',
|
|
176
191
|
desc: 'You can supply an array of options or an async function to fetch options on the fly.',
|