@vs-form/vs-form
Version:
A schema-based form generator component for React using material-ui
1,332 lines (1,309 loc) • 123 kB
JavaScript
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var React__default = _interopDefault(React);
var capitalize = _interopDefault(require('lodash/capitalize'));
var cloneDeep = _interopDefault(require('lodash/cloneDeep'));
var get = _interopDefault(require('lodash/get'));
var has = _interopDefault(require('lodash/has'));
var isArray = _interopDefault(require('lodash/isArray'));
var isDate = _interopDefault(require('lodash/isDate'));
require('lodash/isBoolean');
require('lodash/isEmpty');
var isFunction = _interopDefault(require('lodash/isFunction'));
var isInteger = _interopDefault(require('lodash/isInteger'));
var isNull = _interopDefault(require('lodash/isNull'));
var isNumber = _interopDefault(require('lodash/isNumber'));
var isObject = _interopDefault(require('lodash/isObject'));
var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
var isRegExp = _interopDefault(require('lodash/isRegExp'));
var isString = _interopDefault(require('lodash/isString'));
var isUndefined = _interopDefault(require('lodash/isUndefined'));
var merge = _interopDefault(require('lodash/merge'));
var set = _interopDefault(require('lodash/set'));
require('lodash/toInteger');
require('lodash/toNumber');
require('lodash/trimEnd');
var uniq = _interopDefault(require('lodash/uniq'));
require('lodash/debounce');
require('lodash/throttle');
var __chunk_2 = require('./chunk-e8808437.js');
var TextField = _interopDefault(require('@material-ui/core/TextField'));
var InputAdornment = _interopDefault(require('@material-ui/core/InputAdornment'));
var __chunk_3 = require('./chunk-7581cbb1.js');
var Tooltip = _interopDefault(require('@material-ui/core/Tooltip'));
var styles$2 = require('@material-ui/core/styles');
var __chunk_5 = require('./chunk-41ea4037.js');
var __chunk_6 = require('./chunk-2f21f066.js');
var dateFns = require('date-fns');
var events = require('events');
var __chunk_7 = require('./chunk-819d0a62.js');
var Grid = _interopDefault(require('@material-ui/core/Grid'));
var IconButton = _interopDefault(require('@material-ui/core/IconButton'));
var __chunk_8 = require('./chunk-f9facc49.js');
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true });
console.log(this.props, error, info);
}
render() {
if (this.state.hasError) {
return (React.createElement(React.Fragment, null,
React.createElement("p", { style: { color: 'red' } },
"Component with id: \"",
this.props.comp.node,
"\" has errors! "),
React.createElement("p", { style: { color: 'red' } }, "check the console for more info.")));
}
return this.props.children;
}
}
const addStyles = (component, styles) => {
return styles$2.withStyles(styles)(component);
};
const styles = styles$2.createStyles({
itemSelected: {
boxSizing: 'border-box',
position: 'absolute',
width: '10px',
height: '10px',
background: 'lightgray',
border: '1px solid #333',
zIndex: 1,
},
dragArea: {
minHeight: '50px',
},
itemFocused: {
boxSizing: 'border-box',
position: 'absolute',
width: '10px',
height: '10px',
background: 'greenyellow',
border: '1px solid #333',
zIndex: 1,
}
});
const getSelectedClass = (props) => {
if (isFocused(props)) {
return props.classes.itemFocused;
}
else if (isSelected(props)) {
return props.classes.itemSelected;
}
else {
return '';
}
};
const isFocused = (props) => {
return props.schemaManager.selection.length >= 1 && props.schemaManager.selection[0] === props.comp;
};
const isSelected = (props) => {
return !isFocused(props) && props.schemaManager.selection.includes(props.comp);
};
const SelectDiv = (props) => (React.createElement("div", { className: getSelectedClass(props) }));
var SelectDiv$1 = addStyles(SelectDiv, styles);
class VsForm extends React.Component {
constructor(props) {
super(props);
this.counter = 0;
this.getKey = () => {
const s = this.props.schemaManager.schema;
return s.name + (this.counter > 0 ? '_' + this.counter : '');
};
}
render() {
return (React.createElement(Item, Object.assign({}, this.props, { schema: this.props.schemaManager.schema, node: this.props.node, comp: this.props.schemaManager.schema.components[this.props.node], key: this.getKey() })));
}
componentDidMount() {
this.props.schemaManager.callSchemaEvent('onDidMount');
}
componentWillUnmount() {
this.props.schemaManager.clearInputRefList();
this.props.schemaManager.callSchemaEvent('onWillUnmount');
}
}
VsForm.defaultProps = {
node: 'root',
designMode: false
};
var propTypes = /*#__PURE__*/Object.freeze({
});
const buttons = {
btnOk: 'btnOk',
btnCancel: 'btnCancel',
};
const arrayKeyField = '__rec_id__';
const htmlDateFormat = 'yyyy-MM-dd';
const htmlTimeFormat = 'HH:mm';
const htmlTimeFormatWithSeconds = 'HH:mm:ss';
var constants = /*#__PURE__*/Object.freeze({
buttons: buttons,
arrayKeyField: arrayKeyField,
htmlDateFormat: htmlDateFormat,
htmlTimeFormat: htmlTimeFormat,
htmlTimeFormatWithSeconds: htmlTimeFormatWithSeconds
});
const dataTypeIsArray = (dataType) => [__chunk_3.DataType.array, __chunk_3.DataType.arrayString, __chunk_3.DataType.arrayNumber, __chunk_3.DataType.arrayObject].indexOf(dataType) > -1;
const dataTypeToValue = (dataType) => {
if (dataType === __chunk_3.DataType.string) {
return '';
}
else if (dataType === __chunk_3.DataType.date) {
return null;
}
else if (dataType === __chunk_3.DataType.number || dataType === __chunk_3.DataType.integer) {
return null;
}
else if (dataType === __chunk_3.DataType.boolean) {
return false;
}
else if (dataType === __chunk_3.DataType.object) {
return {};
}
else if (dataTypeIsArray(dataType)) {
return [];
}
else {
return '';
}
};
const checkType = (type, value) => {
if (type === __chunk_3.DataType.any) {
return true;
}
else if (type === __chunk_3.DataType.string) {
return isString(value) || isNull(value);
}
else if (type === __chunk_3.DataType.number) {
return isNumber(value) || isNull(value);
}
else if (type === __chunk_3.DataType.integer) {
return isInteger(value) || isNull(value);
}
else if (type === __chunk_3.DataType.date) {
return isDate(value) || isNull(value);
}
else if (type === __chunk_3.DataType.function) {
return isFunction(value);
}
else if (type === __chunk_3.DataType.regex) {
return isRegExp(value);
}
else if (type === __chunk_3.DataType.array) {
return isArray(value);
}
else if (type === __chunk_3.DataType.arrayString) {
return isArray(value) && value.filter(e => !isString(e)).length === 0;
}
else if (type === __chunk_3.DataType.arrayNumber) {
return isArray(value) && value.filter(e => !isNumber(e)).length === 0;
}
else if (type === __chunk_3.DataType.arrayObject) {
return isArray(value) && value.filter(e => !isObject(e)).length === 0;
}
if (dataTypeIsArray(type)) {
return isArray(value);
}
if (isArray(value)) {
return (dataTypeIsArray(type));
}
return typeof value === type;
};
const formatJSON = (obj) => {
return JSON.stringify(obj, null, 2);
};
const valueIsNumber = (val) => {
if (typeof val === 'string') {
return !isNaN(Number(val));
}
return typeof val === 'number';
};
const dateToString = (date, compType, withSeconds) => {
const f = withSeconds ? htmlTimeFormatWithSeconds : htmlTimeFormat;
if (compType === __chunk_3.Component.date) {
return dateFns.format(date, htmlDateFormat);
}
else if (compType === __chunk_3.Component.datetime) {
return dateFns.format(date, htmlDateFormat) + 'T' + dateFns.format(date, f);
}
else if (compType === __chunk_3.Component.time) {
return dateFns.format(date, f);
}
return '';
};
const stringToDate = (compType, val) => {
let dt = null;
if ([__chunk_3.Component.date, __chunk_3.Component.datetime].indexOf(compType) > -1) {
try {
dt = new Date(val);
}
catch (error) {
}
}
else if (compType === __chunk_3.Component.time) {
try {
dt = new Date('1970-01-01T' + val);
}
catch (error) {
}
}
return dt;
};
const checkIsParentComponent = (comp) => {
if (comp && has(comp, 'children')) {
return comp;
}
else {
return undefined;
}
};
const checkIsDataComponent = (comp) => {
if (comp && has(comp, 'data.field')) {
return comp;
}
else {
return undefined;
}
};
const checkIsButtonComponent = (comp) => {
if (comp && (comp.type === __chunk_3.Component.button || comp.type === __chunk_3.Component.iconbutton)) {
return comp;
}
else {
return undefined;
}
};
const checkIsSelectComponent = (comp) => {
if (comp && (comp.type === __chunk_3.Component.select || comp.type === __chunk_3.Component.radiogroup || comp.type === __chunk_3.Component.selectext)) {
return comp;
}
else {
return undefined;
}
};
var common = /*#__PURE__*/Object.freeze({
dataTypeIsArray: dataTypeIsArray,
dataTypeToValue: dataTypeToValue,
checkType: checkType,
formatJSON: formatJSON,
valueIsNumber: valueIsNumber,
dateToString: dateToString,
stringToDate: stringToDate,
checkIsParentComponent: checkIsParentComponent,
checkIsDataComponent: checkIsDataComponent,
checkIsButtonComponent: checkIsButtonComponent,
checkIsSelectComponent: checkIsSelectComponent
});
var SchemaErrorType;
(function (SchemaErrorType) {
SchemaErrorType["error"] = "error";
SchemaErrorType["warning"] = "warning";
})(SchemaErrorType || (SchemaErrorType = {}));
var types = /*#__PURE__*/Object.freeze({
get SchemaErrorType () { return SchemaErrorType; }
});
var ErrorCode;
(function (ErrorCode) {
ErrorCode["rootnotContainer"] = "rootnotContainer";
ErrorCode["rootChildrenEmpty"] = "rootChildrenEmpty";
ErrorCode["errParseString"] = "errParseString";
ErrorCode["schemaNotFound"] = "schemaNotFound";
ErrorCode["subSchemaNotFound"] = "subSchemaNotFound";
ErrorCode["subSchemaKeyInvalid"] = "subSchemaKeyInvalid";
ErrorCode["componentsnotdefined"] = "componentsnotdefined";
ErrorCode["valuesnotdefined"] = "valuesnotdefined";
ErrorCode["namePropMissing"] = "namePropMissing";
ErrorCode["duplicateFields"] = "duplicateFields";
ErrorCode["duplicateFieldPaths"] = "duplicateFieldPaths";
ErrorCode["duplicateIds"] = "duplicateIds";
ErrorCode["fieldsHasNoParent"] = "fieldsHasNoParent";
ErrorCode["fieldhasDuplicatesInChildren"] = "fieldhasDuplicatesInChildren";
ErrorCode["valuesKeyHasNoField"] = "valuesKeyHasNoField";
ErrorCode["onlyFormTagForRootComp"] = "onlyFormTagForRootComp";
ErrorCode["recursiveChildren"] = "recursiveChildren";
ErrorCode["possibleRecursion"] = "possibleRecursion";
ErrorCode["hasnotype"] = "hasnotype";
ErrorCode["invalidtype"] = "invalidtype";
ErrorCode["invalidComponentType"] = "invalidComponentType";
ErrorCode["hasNoComponentType"] = "hasNoComponentType";
ErrorCode["requiredPropMissing"] = "requiredPropMissing";
ErrorCode["wrongPropertyType"] = "wrongPropertyType";
ErrorCode["wrongPropertyTypeInArray"] = "wrongPropertyTypeInArray";
ErrorCode["arrayIsEmpty"] = "arrayIsEmpty";
ErrorCode["noChildrenKeys"] = "noChildrenKeys";
ErrorCode["invalidChildrenKeys"] = "invalidChildrenKeys";
ErrorCode["invalidTabsKeys"] = "invalidTabsKeys";
ErrorCode["invalidColumns"] = "invalidColumns";
ErrorCode["notDataFieldColumns"] = "notDataFieldColumns";
ErrorCode["valueNotInEnum"] = "valueNotInEnum";
ErrorCode["valueSmallerThanMin"] = "valueSmallerThanMin";
ErrorCode["valueGreaterThanMax"] = "valueGreaterThanMax";
ErrorCode["valueNotInMinMax"] = "valueNotInMinMax";
ErrorCode["fieldNotInValues"] = "fieldNotInValues";
ErrorCode["wrongDataTypeInValues"] = "wrongDataTypeInValues";
ErrorCode["hasInvalidProp"] = "hasInvalidProp";
ErrorCode["wrongDataType"] = "wrongDataType";
ErrorCode["wrongDataTypeDefaultValue"] = "wrongDataTypeDefaultValue";
ErrorCode["selectItemsMustBeObjects"] = "selectItemsMustBeObjects";
ErrorCode["selectItemsMustHaveValueAndText"] = "selectItemsMustHaveValueAndText";
ErrorCode["selectItemsMustHaveCorrectDataType"] = "selectItemsMustHaveCorrectDataType";
ErrorCode["selectItemsUnique"] = "selectItemsUnique";
ErrorCode["selectItemsTextMusBeString"] = "selectItemsTextMusBeString";
ErrorCode["selectItemsTextOnlyOneEmpty"] = "selectItemsTextOnlyOneEmpty";
ErrorCode["selectItemsTextNotUnique"] = "selectItemsTextNotUnique";
ErrorCode["typeStringOrArray"] = "typeStringOrArray";
ErrorCode["compNotFound"] = "compNotFound";
ErrorCode["invalidPrefixType"] = "invalidPrefixType";
ErrorCode["invalidIconType"] = "invalidIconType";
ErrorCode["maskOnlyInMaskInputComponent"] = "maskOnlyInMaskInputComponent";
ErrorCode["maskNotMultilineInput"] = "maskNotMultilineInput";
ErrorCode["maskArrayOrFunction"] = "maskArrayOrFunction";
ErrorCode["maskArrayItemsStringOrRegExp"] = "maskArrayItemsStringOrRegExp";
ErrorCode["stringOrFunction"] = "stringOrFunction";
ErrorCode["styleMustBeObject"] = "styleMustBeObject";
ErrorCode["styleAttrNotObject"] = "styleAttrNotObject";
ErrorCode["speedDialActionObject"] = "speedDialActionObject";
ErrorCode["iconOrSvg"] = "iconOrSvg";
})(ErrorCode || (ErrorCode = {}));
const ErrorStrings = {
rootnotContainer: 'Root component type must be a container',
rootChildrenEmpty: 'the children array may not be empty',
errParseString: 'String parsing error',
schemaNotFound: 'ISchema not found in List',
subSchemaNotFound: 'Sub-Schema not found',
subSchemaKeyInvalid: 'The keyField is not a valid field.',
componentsnotdefined: 'components not defined!',
valuesnotdefined: 'values not defined!',
namePropMissing: 'schema has no name property',
duplicateFields: 'duplicate fields are present',
duplicateFieldPaths: 'duplicate Field Paths are present',
duplicateIds: 'duplicate Ids are present',
fieldsHasNoParent: 'field has no parent (not in any children)',
fieldhasDuplicatesInChildren: 'field is in several parents',
valuesKeyHasNoField: 'For the following value key(s) the component is missing:',
onlyFormTagForRootComp: 'Form component is only allowed for the root component',
recursiveChildren: 'Possible Recursion with children in containers',
possibleRecursion: 'Possible Recursion : More than 100 Sub-Schemas found',
hasnotype: 'has no type',
invalidtype: 'has invalid type',
requiredPropMissing: 'required Property missing',
wrongPropertyType: 'property has wrong type',
wrongPropertyTypeInArray: 'Items in the array has the wrong type',
arrayIsEmpty: 'array should not be empty',
noChildrenKeys: 'Container has no children',
invalidChildrenKeys: 'Container contains invalid keys',
invalidTabsKeys: 'Only tabs-Component are allowed',
invalidColumns: 'Data Table has invalid columns',
notDataFieldColumns: 'The columns of the Data Table must be data fields',
valueNotInEnum: 'value is not in the list of allowed values',
valueSmallerThanMin: 'value is smaller than minimum',
valueGreaterThanMax: 'value is greater than maximum',
valueNotInMinMax: 'value is not between min and max',
fieldNotInValues: 'field not present in schema.values',
wrongDataTypeInValues: 'field has wrong Value Type in schema.values',
hasInvalidProp: 'invalid (unnecessary) property',
wrongDataType: 'the value has a wrong data-type',
wrongDataTypeDefaultValue: 'the default value has the wrong data-type',
invalidComponentType: 'IComponent has an invalid type',
hasNoComponentType: 'Component has no type',
selectItemsMustBeObjects: 'Items in select must objects',
selectItemsMustHaveValueAndText: 'All Items in select must have a text and a value property',
selectItemsMustHaveCorrectDataType: 'All Item-Values must have the type defined in the datatype',
selectItemsUnique: 'All Item-Values must be unique',
selectItemsTextMusBeString: 'All Item-Texts must be string',
selectItemsTextOnlyOneEmpty: 'Only one Item should have empty string',
selectItemsTextNotUnique: 'Text in items are not unique',
typeStringOrArray: 'property must be either string or array of strings',
compNotFound: 'Prefix/Suffix: Component not found',
invalidPrefixType: 'Prefix/Suffix-Components must be either text, button or iconbutton',
invalidIconType: 'Icon-Component is not an icon',
maskOnlyInMaskInputComponent: 'mask can only be defined in the input component',
maskNotMultilineInput: 'masks cannot be applied to multiline inputs',
maskArrayOrFunction: 'mask must be either an array or a function',
maskArrayItemsStringOrRegExp: 'each item in the mask array mmust be either a string or a regexp',
stringOrFunction: 'property must be either string or a function',
styleMustBeObject: 'Style must be an object',
styleAttrNotObject: 'Style attribute should not be an object',
speedDialActionObject: 'Each Speed Dial Action must be an object',
iconOrSvg: 'Icon or svg property must be provided for Icon-Component',
};
var str_err = /*#__PURE__*/Object.freeze({
get ErrorCode () { return ErrorCode; },
ErrorStrings: ErrorStrings
});
const required = (name) => (v) => !!v || `${name} is required`;
const checkItemsInSelect = (_items, dataType) => {
if (isFunction(_items)) {
return '';
}
const items = _items;
let arr = [];
let sortedArr = [];
const dataTypeValue = () => dataType === __chunk_3.DataType.arrayString ? __chunk_3.DataType.string : (dataType === __chunk_3.DataType.arrayNumber || dataType === __chunk_3.DataType.integer || dataType === __chunk_3.DataType.arrayInteger) ? __chunk_3.DataType.number : dataType;
const getLineNumbers = (orig, error) => {
return error.map(el => orig.indexOf(el) + 1);
};
const arrToString = (a) => {
return a.map(e => e && e.value ? e.value.toString() : '' + ',' + (e ? e.text : '')).toString();
};
arr = items.filter(el => !(isObject(el)));
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsMustBeObjects, addOn: arrToString(arr), itemNo: getLineNumbers(items, arr).toString() };
}
arr = items.filter(el => !(has(el, 'value') && has(el, 'text')));
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsMustHaveValueAndText, addOn: arrToString(arr), itemNo: getLineNumbers(items, arr).toString() };
}
arr = items.filter((el) => typeof el.value !== dataTypeValue());
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsMustHaveCorrectDataType, addOn: arrToString(arr), itemNo: getLineNumbers(items, arr).toString() };
}
sortedArr = items.map(e => e);
if (dataTypeValue() === __chunk_3.DataType.number) {
sortedArr.sort((a, b) => (a.value - b.value));
}
else {
sortedArr.sort((a, b) => {
if (a.value < b.value) {
return -1;
}
else if (a.value > b.value) {
return 1;
}
else {
return 0;
}
});
}
arr = [];
for (let i = 0; i < sortedArr.length - 2; i++) {
if (sortedArr[i + 1] && sortedArr[i + 1].value === sortedArr[i].value) {
arr.push(sortedArr[i]);
}
}
arr = uniq(arr);
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsUnique, addOn: arrToString(arr), itemNo: getLineNumbers(items, arr).toString() };
}
arr = items.filter(el => !isString(el.text));
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsTextMusBeString, addOn: arrToString(arr) };
}
arr = items.filter(el => (el.text.trim() === ''));
if (arr.length > 1) {
return { errcode: ErrorCode.selectItemsTextOnlyOneEmpty, addOn: arrToString(arr) };
}
sortedArr = items.sort((a, b) => {
if (a.text < b.text) {
return -1;
}
else if (a.text > b.text) {
return 1;
}
else {
return 0;
}
});
arr = [];
for (let i = 0; i < sortedArr.length - 1; i++) {
if (sortedArr[i + 1].text === sortedArr[i].text) {
arr.push(sortedArr[i]);
}
}
arr = uniq(arr);
if (arr.length > 0) {
return { errcode: ErrorCode.selectItemsTextNotUnique, type: SchemaErrorType.warning, addOn: arrToString(arr), itemNo: getLineNumbers(items, arr).toString() };
}
return '';
};
var fieldValidators = /*#__PURE__*/Object.freeze({
required: required,
checkItemsInSelect: checkItemsInSelect
});
const rootIsWrong = sm => {
const comp = sm.schema.components.root;
if ([__chunk_3.Component.form, __chunk_3.Component.panel, __chunk_3.Component.card, __chunk_3.Component.expansionpanel, __chunk_3.Component.tabs].indexOf(comp.type) === -1) {
return { errcode: ErrorCode.rootnotContainer, schemaName: sm.schema.name };
}
if (comp.children && isArray(comp.children) && comp.children.length === 0) {
return { errcode: ErrorCode.rootChildrenEmpty, schemaName: sm.schema.name };
}
return '';
};
const hasRecursion = sm => {
const counter = { count: 0, max: 100 };
hasRecursion1(sm, sm.schema, sm.schemaList, counter);
return counter.count >= counter.max
? { errcode: ErrorCode.possibleRecursion, schemaName: sm.schema.name }
: '';
};
function hasRecursion1(schemaManager, schema, schemaList, counter) {
if (counter.count >= counter.max) {
counter.count = counter.max + 1;
return;
}
Object.keys(schema.components).forEach(key => {
const comp = schema.components[key];
if (comp.type === __chunk_3.Component.subschema) {
counter.count++;
if (comp.schemaName && counter.count < counter.max) {
const s = schemaManager.getSchemaFromList(comp.schemaName);
if (s) {
hasRecursion1(schemaManager, s, schemaList, counter);
}
}
}
});
}
const hasUnresolvedSubschemaNames = sm => {
const arr = [];
const componentCallback = p => {
if (p.comp && p.comp.type === __chunk_3.Component.subschema && p.comp.schemaName) {
const s = sm.getSchemaFromList(p.comp.schemaName);
if (!s) {
arr.push(p.comp.schemaName);
}
}
};
const options = { processSubSchemas: true };
SchemaManager.processSchema({ componentCallback, schema: sm.schema, options });
return arr.length > 0
? {
errcode: ErrorCode.subSchemaNotFound,
addOn: arr.toString(),
schemaName: sm.schema.name
}
: '';
};
const onlyFormTagForRoot = sm => {
const arr = [];
const componentCallback = p => {
if (p.comp && p.comp.type === __chunk_3.Component.form && p.comp.id !== 'root') {
arr.push(p.comp.id);
}
};
const options = { processSubSchemas: false };
SchemaManager.processSchema({ componentCallback, schema: sm.schema, options });
return arr.length > 0
? {
errcode: ErrorCode.onlyFormTagForRootComp,
addOn: arr.toString(),
schemaName: sm.schema.name
}
: '';
};
const isDuplicateInChildren = sm => {
const parents = Object.keys(sm.schema.components).map(c => sm.schema.components[c]).filter(c => has(c, 'children'));
const getParents = (key) => parents.filter(c => c.children.includes(key));
const dup = [];
const componentCallback = p => {
const pr = getParents(p.comp.node);
if (pr.length > 1) {
dup.push(p.comp.node);
}
};
const options = { processSubSchemas: true };
SchemaManager.processSchema({ componentCallback, schema: sm.schema, options });
if (dup.length > 0) {
return {
errcode: ErrorCode.fieldhasDuplicatesInChildren,
type: SchemaErrorType.warning,
addOn: dup.toString(),
schemaName: sm.schema.name
};
}
else {
return '';
}
};
const childrenHasRecursion = sm => {
const dup = [];
const recursiveChildren = (comp, counter) => {
if (counter.count >= counter.max) {
counter.count = counter.max + 1;
return;
}
const cp = checkIsParentComponent(comp);
if (cp) {
cp.children.forEach((child) => {
counter.count++;
if (has(sm.schema.components, child) && counter.count < counter.max) {
recursiveChildren(sm.schema.components[child], counter);
}
});
}
};
const componentCallback = p => {
const counter = { count: 0, max: 500 };
recursiveChildren(p.comp, counter);
if (counter.count >= counter.max) {
const key = p.key;
if (!dup.includes(key)) {
dup.push(key);
}
}
};
const options = { processSubSchemas: true };
SchemaManager.processSchema({ componentCallback, schema: sm.schema, options });
if (dup.length > 0) {
return { errcode: ErrorCode.recursiveChildren, addOn: dup.toString(), schemaName: sm.schema.name };
}
else {
return '';
}
};
const hasDuplicateFields = sm => {
const arr = [];
let dup = [];
const componentCallback = p => {
const cd = checkIsDataComponent(p.comp);
if (cd) {
const field = cd.data.field;
if (arr.includes(field)) {
dup.push(field);
}
arr.push(field);
}
};
const options = { processSubSchemas: false };
SchemaManager.processSchema({ componentCallback, schema: sm.schema, options });
dup = uniq(dup);
if (dup.length > 0) {
return { errcode: ErrorCode.duplicateFields, addOn: dup.toString(), type: SchemaErrorType.warning, schemaName: sm.schema.name };
}
else {
return '';
}
};
const hasFieldsNotInChildren = sm => {
const missing = sm.getComponentsWithNoParent();
return missing.length > 0
? {
errcode: ErrorCode.fieldsHasNoParent,
addOn: missing.toString(),
type: SchemaErrorType.warning,
schemaName: sm.schema.name
}
: '';
};
const valuesKeyHasNoComponent = sm => {
const arr = [];
const getFields = (values, parent) => {
Object.keys(values).forEach(key => {
const comp = sm.getComponentByFieldPath(parent + key);
if (!comp) {
arr.push(parent + key);
}
else if (comp.type === __chunk_3.Component.subschema) {
getFields(values[key], parent + key + '.');
}
});
};
if (sm.schema.values) {
getFields(sm.schema.values, '');
}
if (arr.length > 0) {
return { errcode: ErrorCode.valuesKeyHasNoField, addOn: arr.toString(), type: SchemaErrorType.warning, schemaName: sm.schema.name };
}
else {
return '';
}
};
const hasValidChildrenKeys = (validSchema, component, schema) => {
const property = get(component, validSchema.prop);
if (property.length === 0) {
return { errcode: ErrorCode.noChildrenKeys, type: SchemaErrorType.warning };
}
const arr = [];
property.forEach((el) => {
if (!has(schema.components, el)) {
arr.push(el);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidChildrenKeys, addOn: arr.toString() };
}
return '';
};
const hasValidTabsKeys = (validSchema, component, schema) => {
const property = get(component, validSchema.prop);
if (property.length === 0) {
return { errcode: ErrorCode.noChildrenKeys, type: SchemaErrorType.warning };
}
let arr = [];
property.forEach((el) => {
if (!has(schema.components, el)) {
arr.push(el);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidChildrenKeys, addOn: arr.toString() };
}
arr = [];
property.forEach((el) => {
if (schema.components[el].type !== __chunk_3.Component.tab) {
arr.push(el);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidTabsKeys, addOn: arr.toString() };
}
return '';
};
const stylesValid = (validSchema, component, _schema) => {
let err = '';
const property = get(component, validSchema.prop);
if (isObject(property)) {
Object.keys(property).forEach(key => {
if (!isObject(property[key])) {
err = { errcode: ErrorCode.styleMustBeObject, prop: 'styles.' + key };
return;
}
});
}
return err;
};
const speedDialActionsValid = (validSchema, component, _schema) => {
let err = '';
const property = get(component, validSchema.prop);
if (isArray(property)) {
if (property.length === 0) {
return { errcode: ErrorCode.arrayIsEmpty };
}
property.forEach((obj, ind) => {
const sInd = (ind + 1).toString();
if (isObject(obj)) {
if (isUndefined(obj['icon'])) {
err = { errcode: ErrorCode.requiredPropMissing, addOn: 'prop: icon', itemNo: sInd };
return;
}
if (!isString(obj['icon'])) {
err = { errcode: ErrorCode.wrongPropertyTypeInArray, addOn: 'prop: icon', itemNo: sInd };
return;
}
if (isUndefined(obj['tooltip'])) {
err = { errcode: ErrorCode.requiredPropMissing, addOn: 'prop: tooltip', itemNo: sInd };
return;
}
if (!isString(obj['tooltip'])) {
err = { errcode: ErrorCode.wrongPropertyTypeInArray, addOn: 'prop: tooltip', itemNo: sInd };
return;
}
if (isUndefined(obj['onClick'])) {
err = { errcode: ErrorCode.requiredPropMissing, addOn: 'prop: onClick', itemNo: sInd, type: SchemaErrorType.warning };
return;
}
if (!isFunction(obj['onClick'])) {
err = { errcode: ErrorCode.wrongPropertyTypeInArray, addOn: 'prop: onClick', itemNo: sInd };
return;
}
}
else {
err = { errcode: ErrorCode.speedDialActionObject, addOn: 'Entry No.: ' + sInd, itemNo: sInd };
return;
}
});
}
return err;
};
const prefixSuffixCompValid = (validSchema, component, schema) => {
const property = get(component, validSchema.prop);
if (!(isArray(property) || isString(property))) {
return { errcode: ErrorCode.typeStringOrArray };
}
if (isArray(property)) {
const arr = [];
property.forEach((s) => {
const c = schema.components[s];
if (!c) {
arr.push(s);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.compNotFound, addOn: arr.toString() };
}
property.forEach((s) => {
const c = schema.components[s];
if ([__chunk_3.Component.button, __chunk_3.Component.iconbutton, __chunk_3.Component.icon, __chunk_3.Component.text].indexOf(c.type) === -1) {
arr.push(s);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidPrefixType, addOn: arr.toString() };
}
}
return '';
};
const iconValid = (_validSchema, component, _schema) => {
if (!(component['icon'] || component['svg'] || component['component'])) {
return { errcode: ErrorCode.iconOrSvg };
}
return '';
};
const iconCompValid = (validSchema, component, schema) => {
const property = get(component, validSchema.prop);
if (!(isArray(property) || isString(property))) {
return { errcode: ErrorCode.typeStringOrArray };
}
if (isArray(property)) {
const arr = [];
property.forEach((s) => {
const c = schema.components[s];
if (!c) {
arr.push(s);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.compNotFound, addOn: arr.toString() };
}
property.forEach((s) => {
const c = schema.components[s];
if (c.type !== __chunk_3.Component.icon) {
arr.push(s);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidIconType, addOn: arr.toString() };
}
}
return '';
};
const subschemaKeyField = (validSchema, component, schema) => {
const property = get(component, validSchema.prop);
const subschema = component['schema'];
const options = { done: false };
let fieldFound = false;
const componentCallback = p => {
const cd = checkIsDataComponent(p.comp);
if (cd) {
if (cd.data.field === property) {
options.done = true;
fieldFound = true;
}
}
};
SchemaManager.processSchema({ componentCallback, schema: subschema, options });
if (!fieldFound) {
return { errcode: ErrorCode.subSchemaKeyInvalid };
}
return '';
};
const maskInput = (_validSchema, component, _schema) => {
if (component.type === __chunk_3.Component.maskinput) {
if (component.props && component.props.multiline) {
return { errcode: ErrorCode.maskNotMultilineInput };
}
const mask = component.maskProps.mask;
if (isFunction(mask)) {
return '';
}
else if (isArray(mask)) {
const arr = mask.filter(e => !(isString(e) || isRegExp(e)));
if (arr.length > 0) {
return { errcode: ErrorCode.maskArrayItemsStringOrRegExp };
}
}
else {
return { errcode: ErrorCode.maskArrayOrFunction };
}
}
else {
return { errcode: ErrorCode.maskOnlyInMaskInputComponent };
}
return '';
};
const numberFormat = (_validSchema, component, _schema) => {
const ci = component;
if (!ci.numberFormatProps) {
return { errcode: ErrorCode.requiredPropMissing };
}
if (ci.numberFormatProps.format) {
if (!(isString(ci.numberFormatProps.format) || isFunction(ci.numberFormatProps.format))) {
return { errcode: ErrorCode.stringOrFunction, prop: 'numberFormatProps.format' };
}
}
if (ci.numberFormatProps.mask) {
if (!(isString(ci.numberFormatProps.mask) || isArray(ci.numberFormatProps.mask))) {
return { errcode: ErrorCode.typeStringOrArray, prop: 'numberFormatProps.mask' };
}
}
return '';
};
const defaultValue = (validSchema, component, _schema) => {
let err = false;
const cd = checkIsDataComponent(component);
if (cd) {
const property = get(component, validSchema.prop);
if (isUndefined(property) || !cd.data.dataType) {
return '';
}
if (isFunction(property)) {
return '';
}
if (get(cd, 'data.dataType') === __chunk_3.DataType.integer) {
err = !(isInteger(property));
}
else if (get(cd, 'data.dataType') === __chunk_3.DataType.date) {
err = !(isDate(property));
}
else if (get(cd, 'data.dataType') === __chunk_3.DataType.arrayNumber) {
if (!isArray(property)) {
err = true;
}
else {
property.forEach(item => {
if (typeof item !== __chunk_3.DataType.number) {
err = true;
}
});
}
}
else if (get(cd, 'data.dataType') === __chunk_3.DataType.arrayInteger) {
if (!isArray(property)) {
err = true;
}
else {
property.forEach(item => {
if (!isInteger(item)) {
err = true;
}
});
}
}
else if (get(cd, 'data.dataType') === __chunk_3.DataType.arrayString) {
if (!isArray(property)) {
err = true;
}
else {
property.forEach(item => {
if (typeof item !== __chunk_3.DataType.string) {
err = true;
}
});
}
}
else if (get(cd, 'data.dataType') === __chunk_3.DataType.arrayObject) {
if (!isArray(property)) {
err = true;
}
else {
property.forEach(item => {
if (!isObject(item)) {
err = true;
}
});
}
}
else if (typeof property !== get(cd, 'data.dataType')) {
err = true;
return { errcode: ErrorCode.wrongDataTypeDefaultValue };
}
}
if (err) {
return { errcode: ErrorCode.wrongDataTypeDefaultValue };
}
else {
return '';
}
};
const hasValidColumns = (validSchema, component, _schema) => {
const property = get(component, validSchema.prop);
const arr = [];
if (property) {
property.forEach((el) => {
const comp = get(component.schema.components, el.compId);
const cd = checkIsDataComponent(comp);
if (!cd) {
arr.push(el.compId);
}
});
if (arr.length > 0) {
return { errcode: ErrorCode.invalidColumns, addOn: arr.toString() };
}
}
return '';
};
const itemsInSelect = (_validSchema, component, _schema) => {
if (has(component, 'data.items')) {
return checkItemsInSelect(component.data.items, component.data.dataType);
}
return '';
};
const required$1 = () => ({
required: true
});
const typeString = () => ({
type: __chunk_3.DataType.string
});
const typeNumber = () => ({
type: __chunk_3.DataType.number
});
const typeObject = () => ({
type: __chunk_3.DataType.object
});
const typeStringOrFunction = () => ({
type: [__chunk_3.DataType.string, __chunk_3.DataType.function]
});
const typeStringOrStringArray = () => ({
type: [__chunk_3.DataType.string, __chunk_3.DataType.arrayString]
});
const typeArray = () => ({
type: __chunk_3.DataType.array
});
const typeBoolean = () => ({
type: __chunk_3.DataType.boolean
});
const typeBooleanOrFunction = () => ({
type: [__chunk_3.DataType.boolean, __chunk_3.DataType.function]
});
const typeAny = () => ({
type: __chunk_3.DataType.any
});
const typeFunction = () => ({
type: __chunk_3.DataType.function
});
const typeRegex = () => ({
type: __chunk_3.DataType.regex
});
const gridSize = () => ({
enum: [true, false, 'auto', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
});
const objectRequired = () => ({
...required$1(), ...typeObject()
});
const arrayRequired = () => ({
...required$1(), ...typeArray()
});
const arrayNotRequired = () => ({
...typeArray()
});
const labelRequired = () => ({
label: { ...required$1(), ...typeStringOrFunction() },
});
const label = () => ({
label: { ...typeStringOrFunction() },
});
const hint = () => ({
hint: { ...typeStringOrFunction() },
});
const tooltip = () => ({
tooltip: { ...typeStringOrFunction() },
tooltipProps: { ...typeObject() }
});
const text = () => ({
text: { ...typeStringOrFunction() },
});
const fieldRequired = () => ({
field: { ...required$1(), ...typeString() }
});
const stringRequired = () => ({
...required$1(), ...typeString()
});
const validatorsChildren = () => ({
validators: [hasValidChildrenKeys]
});
const validatorsTabsChildren = () => ({
validators: [hasValidTabsKeys]
});
const itemsChildren = () => ({
items: { ...typeString() }
});
const validatorsColumns = () => ({
validators: [hasValidColumns]
});
const validatorsDefaultValue = () => ({
validators: [defaultValue]
});
const validatorsMaskInput = () => ({
validators: [maskInput]
});
const validatorsNumberFormat = () => ({
validators: [numberFormat]
});
const validatorsPrefixComp = () => ({
validators: [prefixSuffixCompValid]
});
const validatorsIconComp = () => ({
validators: [iconCompValid]
});
const validatorsSubschemaKeyField = () => ({
validators: [subschemaKeyField]
});
const validatorsIcon = () => ({
validators: [iconValid]
});
const validatorsStyles = () => ({
validators: [stylesValid]
});
const validatorsSpeedDialActions = () => ({
validators: [speedDialActionsValid]
});
const gridProps = () => ({
...typeObject(),
properties: {
xl: { ...typeAny(), ...gridSize() },
lg: { ...typeAny(), ...gridSize() },
md: { ...typeAny(), ...gridSize() },
sm: { ...typeAny(), ...gridSize() },
xs: { ...typeAny(), ...gridSize() },
alignContent: { ...typeString(), enum: ['stretch', 'center', 'flex-start', 'flex-end', 'space-between', 'space-around'] },
alignItems: { ...typeString(), enum: ['flex-start', 'center', 'flex-end', 'stretch', 'baseline'] },
direction: { ...typeString(), enum: ['row', 'row-reverse', 'column', 'column-reverse'] },
justify: { ...typeString(), enum: ['flex-start', 'center', 'flex-end', 'space-between', 'space-around', 'space-evenly'] },
spacing: { ...typeNumber(), enum: [0, 8, 16, 24, 32, 40] },
wrap: { ...typeString(), enum: ['nowrap', 'wrap', 'wrap-reverse'] },
zeroMinWidth: { ...typeBoolean() },
item: { ...typeBoolean() },
container: { ...typeBoolean() },
style: { ...typeObject() },
}
});
const maskProps = () => ({
...typeObject(),
properties: {
mask: { ...typeAny(), ...validatorsMaskInput() },
guide: { ...typeBoolean() },
placeholder: { ...typeString() },
pipe: { ...typeFunction() },
showMask: { ...typeBoolean() },
}
});
const numberFormatProps = () => ({
...objectRequired(),
properties: {
thousandSeparator: { ...typeString() },
decimalSeparator: { ...typeString() },
decimalScale: { ...typeNumber() },
fixedDecimalScale: { ...typeBoolean() },
displayType: { ...typeString(), enum: ['input', 'text'] },
prefix: { ...typeString() },
suffix: { ...typeString() },
format: { ...typeStringOrFunction() },
removeFormatting: { ...typeFunction() },
mask: { ...typeStringOrStringArray() },
allowNegative: { ...typeBoolean() },
allowEmptyFormatting: { ...typeBoolean() },
isAllowed: { ...typeFunction() }
}
});
const modifyDataPropsText = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.string];
};
const modifyDataPropsSelect = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.string, __chunk_3.DataType.integer, __chunk_3.DataType.number, __chunk_3.DataType.arrayString, __chunk_3.DataType.arrayInteger, __chunk_3.DataType.arrayNumber];
obj.properties.items = arrayRequired();
obj.properties.items.validators = [itemsInSelect];
};
const modifyDataPropsCheckListBox = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.arrayString, __chunk_3.DataType.arrayInteger, __chunk_3.DataType.arrayNumber];
obj.properties.items = arrayRequired();
obj.properties.items.validators = [itemsInSelect];
};
const modifyDataPropsRadio = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.string, __chunk_3.DataType.integer, __chunk_3.DataType.number];
obj.properties.items = arrayRequired();
obj.properties.items.validators = [itemsInSelect];
};
const modifyDataPropsNumber = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.number];
};
const modifyDataPropsSlider = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.number];
obj.properties.validations.properties.step = { ...typeNumber() };
};
const modifyDataPropsNumberFormat = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.number, __chunk_3.DataType.integer];
};
const modifyDataPropsInteger = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.integer];
};
const modifyDataPropsDate = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.date];
};
const modifyDataPropsBoolean = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.boolean];
};
const modifyDataPropsSubschema = (obj) => {
obj.properties.dataType.enum = [__chunk_3.DataType.object, __chunk_3.DataType.array];
};
const commonProps = (modifyPropsProps) => {
const fn = modifyPropsProps ? modifyPropsProps : () => ({});
return {
type: { ...stringRequired() },
id: { ...typeString() },
node: { ...typeString() },
...tooltip(),
gridItem: { ...gridProps() },
styles: { ...typeObject(), ...validatorsStyles() },
...commonPropsProps(fn),
disabled: { ...typeBoolean() },
hidden: { ...typeBoolean() },
};
};
const _validSchemaSchema = () => ({
...typeObject(),
preValidators: [rootIsWrong, hasRecursion, childrenHasRecursion, hasUnresolvedSubschemaNames],
postValidators: [hasDuplicateFields, hasFieldsNotInChildren, isDuplicateInChildren, onlyFormTagForRoot, valuesKeyHasNoComponent],
additionalProperties: true,
properties: {
id: { ...typeString() },
name: { ...stringRequired() },
node: { ...typeString() },
validationMethod: {
...typeNumber(),
enum: [__chunk_3.ValidationMethod.validateOnChange, __chunk_3.ValidationMethod.validateOnSubmit]
},
hideValidationErrorPanel: { ...typeBoolean() },
label: { ...typeString() },
values: { ...typeObject() },
components: {
...objectRequired(),
additionalProperties: true,
properties: {
root: {
...objectRequired(),
properties: {
label: { ...typeString() },
...commonProps(),
...label(),
gridContainer: { ...gridProps() },
children: {
...arrayRequired(),
...required$1(),
...itemsChildren(),
},
}
},
}
},
styles: { ...typeObject(), ...validatorsStyles() },
disabled: { ...typeBoolean() },
onCreated: { ...typeFunction() },
onDidMount: { ...typeFunction() },
onWillUnmount: { ...typeFunction() },
onChange: { ...typeFunction() },
onSubmit: { ...typeFunction() },
onCancelValues: { ...typeFunction() },
validate: { ...typeFunction() },
}
});
const commonDataProps = (modifyProps) => {
const obj = {
...objectRequired(),
properties: {
...fieldRequired(),
dataType: { ...stringRequired(), enum: [] },
fieldPath: { ...typeString() },
default: { ...typeAny(), ...validatorsDefaultValue() },
onBeforeChange: { ...typeFunction() },
onChange: { ...typeFunction() },
validations: {
...typeObject(),
properties: {
required: { ...typeBooleanOrFunction() },
allowedValues: { ...typeArray() },