material-form-builder
Version:
FormBuilder For React.js
914 lines (887 loc) • 170 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var ArrowDropDownIcon = require('@mui/icons-material/ArrowDropDown');
var ClearIcon = require('@mui/icons-material/Clear');
var material = require('@mui/material');
var TextField = require('@mui/material/TextField');
var colors = require('@mui/material/colors');
var xDatePickers = require('@mui/x-date-pickers');
var AdapterDayjs = require('@mui/x-date-pickers/AdapterDayjs');
var iconsMaterial = require('@mui/icons-material');
var styles = require('@mui/material/styles');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var ArrowDropDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(ArrowDropDownIcon);
var ClearIcon__default = /*#__PURE__*/_interopDefaultLegacy(ClearIcon);
var TextField__default = /*#__PURE__*/_interopDefaultLegacy(TextField);
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var selectFromObject = function (selector, data) {
var regex = new RegExp('.*[.*=.*]');
var splitSelector = selector.split('.');
var workingObject = data;
splitSelector.forEach(function (selectorItem) {
if (!workingObject)
workingObject = {};
if (regex.test(selectorItem)) {
var objectBeforeQuery = selectorItem.replace(/\[.*\]/g, '');
if (objectBeforeQuery) {
workingObject = workingObject[objectBeforeQuery];
}
if (!Array.isArray(workingObject))
return false;
var splitQuery = selectorItem.replace(/.*\[|\]/g, '').split('=');
var queryKey_1 = splitQuery[0].trim();
var queryValue_1 = isNaN(parseInt(splitQuery[1])) ? splitQuery[1] : parseInt(splitQuery[1]);
workingObject = workingObject.find(function (ob) { return ob[queryKey_1] === queryValue_1; });
}
else {
workingObject = workingObject[selectorItem];
}
});
return workingObject;
};
var setToObject = function (selector, value, object) {
// value = typeof value !== 'boolean' && !Array.isArray(value) && value && !isNaN(value) ? parseInt(value, 10) : value
var regex = new RegExp('.*[.*=.*]');
var splitSelector = selector.split('.');
if (splitSelector.length > 1) {
var workingObject_1 = object;
splitSelector.forEach(function (selectorItem, index) {
var _a;
var isLast = splitSelector.length === index + 1;
if (regex.test(selectorItem)) {
var replacedSelectorItem = selectorItem.replace(/\[.*\]/, '');
if (!workingObject_1.hasOwnProperty(replacedSelectorItem))
workingObject_1[replacedSelectorItem] = [];
var splitQuery = selectorItem.replace(/.*\[|\]/g, '').split('=');
var queryKey_2 = splitQuery[0].trim();
var queryValue_2 = isNaN(parseInt(splitQuery[1])) ? splitQuery[1] : parseInt(splitQuery[1]);
var exists = workingObject_1[replacedSelectorItem].find(function (item) { return item[queryKey_2] === queryValue_2; });
if (exists) {
workingObject_1 = exists;
}
else {
var newObject = (_a = {}, _a[queryKey_2] = queryValue_2, _a);
workingObject_1[replacedSelectorItem].push(newObject);
workingObject_1 = newObject;
}
}
else {
if (isLast) {
workingObject_1[selectorItem] = value;
}
else {
if (!workingObject_1.hasOwnProperty(selectorItem))
workingObject_1[selectorItem] = {};
workingObject_1 = workingObject_1[selectorItem];
}
}
});
}
else {
object[selector] = value;
}
return object;
};
var randomString = function (length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
var mask = function (value, pattern, placeholder) {
if (placeholder === void 0) { placeholder = ''; }
var i = 0, v = value.toString();
return pattern.replace(/\./g, function (_) { return v[i++] || placeholder; });
};
var isNull = function (data) {
return data === null;
};
var checkValue = function (value) {
if (value === null)
return false;
if (value === undefined)
return false;
return true;
};
var stringify = function (obj) {
var cache = [];
var str = JSON.stringify(obj, function (_, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null; // reset the cache
return str;
};
var LoadingComponent$1 = function (props) { return (React__default["default"].createElement(material.Grow, { in: true, timeout: 550 },
React__default["default"].createElement(material.Box, { sx: { paddingRight: '8px', paddingTop: '4px' } },
React__default["default"].createElement(material.CircularProgress, { size: 18 })))); };
var AutocompleteInput = /** @class */ (function (_super) {
__extends(AutocompleteInput, _super);
function AutocompleteInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
value: _this.getValuesFrom(_this.props.defaultValue || null),
error: false
};
_this.onChange = function (_, option, reason, details) {
var _a, _b;
if (Array.isArray(option)) {
_this.setValue(option.map(function (i) { return typeof i === "string" ? i : i.value; }));
}
else {
_this.setValue(typeof option === "string" ? option : option.value);
}
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, _, option, reason, details);
};
_this.onClick = function (event) {
var _a, _b;
clearTimeout(_this.validationTimeout);
_this.setState(__assign(__assign({}, _this.state), { error: false }));
(_b = (_a = _this.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.click = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.blur();
};
_this.onInputBlur = function (event) {
var _a, _b;
if (!_this.props.multiple && _this.props.freeSolo) {
_this.setValue(event.target.value);
}
(_b = (_a = _this.props.InputProps) === null || _a === void 0 ? void 0 : _a.onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.renderOption = function (props, option) {
var key = props.key, rest = __rest(props, ["key"]);
return (React__default["default"].createElement("li", __assign({ key: key }, rest), typeof option === "object" ? option.label : (option.toString())));
};
_this.getOptionLabel = function (option) { return typeof option === "object" ? option.label : (option.toString()); };
_this.isOptionEqualToValue = function (option, value) {
if (!value)
return false;
return typeof option === "string" ? option === (typeof value === "string" ? value : value.value.toString()) : option.value.toString() === (typeof value === "string" ? value : value.value.toString());
};
return _this;
}
AutocompleteInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _this = this;
var _a, _b, _c, _d, _e;
switch (true) {
case this.state.value !== nextState.value:
case this.getValueForCheck(this.state.value || undefined) !== this.getValueForCheck(nextState.value || undefined):
case this.state.error !== nextState.error:
case ((_a = this.props.options) === null || _a === void 0 ? void 0 : _a.map(function (i) { return _this.optionGetter(i, 'value'); }).join('@')) !== ((_b = nextProps.options) === null || _b === void 0 ? void 0 : _b.map(function (i) { return _this.optionGetter(i, 'value'); }).join('@')):
case this.props.loading !== nextProps.loading:
case this.props.loadingText !== nextProps.loadingText:
case this.props.label !== nextProps.label:
case this.props.disabled !== nextProps.disabled:
case stringify((_c = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _c !== void 0 ? _c : {}) !== stringify((_e = (_d = this.props) === null || _d === void 0 ? void 0 : _d.updateListener) !== null && _e !== void 0 ? _e : {}):
return true;
default: return false;
}
};
AutocompleteInput.prototype.getValuesFrom = function (value) {
var _this = this;
if (!value)
return null;
if (this.props.multiple && !Array.isArray(value))
return null;
if (!this.props.multiple && Array.isArray(value))
return null;
if (this.props.freeSolo && !this.props.multiple) {
var exists = this.props.options.find(function (i) { return (typeof i === "string" ? i : i.value) === value || (typeof i === "string" ? i : i.label) === value; });
return exists || { label: (value === null || value === void 0 ? void 0 : value.toString()) || "", value: (value === null || value === void 0 ? void 0 : value.toString()) || "" };
}
if (this.props.freeSolo && this.props.multiple && typeof value === "object" && Array.isArray(value)) {
var outputOptions = value.map(function (valueItem) {
var exists = _this.props.options.find(function (i) { return (typeof i === "string" ? i : i.value) === valueItem; });
return exists || { label: (valueItem === null || valueItem === void 0 ? void 0 : valueItem.toString().trim()) || "", value: (valueItem === null || valueItem === void 0 ? void 0 : valueItem.toString().trim()) || "" };
});
return outputOptions;
}
if (typeof value === "object" && Array.isArray(value)) {
return this.props.options.filter(function (i) { return value.indexOf(typeof i === "string" ? i : i.value) > -1; });
}
else if (value) {
return this.props.options.find(function (i) { return (typeof i === "string" ? i : i.value) === value; });
}
return undefined;
};
AutocompleteInput.prototype.componentDidUpdate = function (props) {
var _this = this;
var _a, _b;
if (((_a = this.props.options) === null || _a === void 0 ? void 0 : _a.map(function (i) { return _this.optionGetter(i, 'value'); }).join('@')) !== ((_b = props.options) === null || _b === void 0 ? void 0 : _b.map(function (i) { return _this.optionGetter(i, 'value'); }).join('@'))) {
if (!this.props.disableClearOnChangeOptions)
this.clear();
}
};
AutocompleteInput.prototype.setValue = function (value) {
var _this = this;
var valueToSet = this.getValuesFrom(value);
return new Promise(function (resolve) {
_this.setState(__assign(__assign({}, _this.state), { value: valueToSet }), function () {
var _a, _b, _c, _d;
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, value);
resolve(value);
});
});
};
AutocompleteInput.prototype.getValue = function () {
var _a;
return (Array.isArray(this.state.value)
? this.state.value.map(function (i) { return typeof i === "string" ? i : i.value; })
: typeof this.state.value === "string" ? this.state.value : (_a = this.state.value) === null || _a === void 0 ? void 0 : _a.value) || (this.props.multiple ? [] : null);
};
AutocompleteInput.prototype.clear = function (withoutDefaults) {
if (withoutDefaults === void 0) { withoutDefaults = false; }
return this.setValue((!withoutDefaults ? this.props.defaultValue : null) || null);
};
AutocompleteInput.prototype.validation = function () {
var _this = this;
if (!this.getValueForCheck(this.state.value) && this.props.required) {
clearTimeout(this.validationTimeout);
this.setState(__assign(__assign({}, this.state), { error: true }));
this.validationTimeout = setTimeout(function () {
_this.setState(__assign(__assign({}, _this.state), { error: false }));
}, 3000);
return false;
}
return true;
};
AutocompleteInput.prototype.optionGetter = function (item, selector) {
var _a;
if (selector === void 0) { selector = "value"; }
return typeof item === "string" || typeof item === "number" || isNull(item) ? (item !== null && item !== void 0 ? item : "") : ((_a = item === null || item === void 0 ? void 0 : item[selector]) !== null && _a !== void 0 ? _a : "");
};
AutocompleteInput.prototype.getValueForCheck = function (value) {
return !isNull(value) && Array.isArray(value) ? value.join('@') : value;
};
AutocompleteInput.prototype.render = function () {
var _this = this;
var _a, _b, _c;
var _d = this.props; _d.defaultValue; _d.onChangeValue; var InputProps = _d.InputProps, renderInput = _d.renderInput, label = _d.label, variant = _d.variant, required = _d.required; _d.visible; _d._call_parent_for_update; _d.updateListener; var restProps = __rest(_d, ["defaultValue", "onChangeValue", "InputProps", "renderInput", "label", "variant", "required", "visible", "_call_parent_for_update", "updateListener"]);
var variantWidth = '207px';
if (this.props.variant === "outlined")
variantWidth = "235px";
if (this.props.variant === "filled")
variantWidth = "231px";
var inputWidth = this.props.fullWidth ? '100%' : variantWidth;
return (React__default["default"].createElement(material.Autocomplete, __assign({}, restProps, { sx: __assign({ width: inputWidth, display: 'inline-flex' }, this.props.sx), options: this.props.options, renderOption: (_a = this.props.renderOption) !== null && _a !== void 0 ? _a : this.renderOption, getOptionLabel: (_b = this.props.getOptionLabel) !== null && _b !== void 0 ? _b : this.getOptionLabel, onChange: this.onChange, disableClearable: this.props.disableClearable || true, size: this.props.size || !variant || variant === "standard" ? "small" : "medium", value: this.state.value || (this.props.multiple ? [] : (this.props.freeSolo ? "" : null)), disabled: this.props.disabled || this.props.loading, clearOnBlur: this.props.multiple || (this.props.multiple && this.props.freeSolo) || (!this.props.multiple && !this.props.freeSolo), popupIcon: this.props.loading ? React__default["default"].createElement(LoadingComponent$1, null) : (this.props.popupIcon || React__default["default"].createElement(ArrowDropDownIcon__default["default"], null)), isOptionEqualToValue: (_c = this.props.isOptionEqualToValue) !== null && _c !== void 0 ? _c : this.isOptionEqualToValue, renderInput: renderInput ? function (params) {
params.inputRef = function (el) { return _this.inputRef = el; };
params.error = _this.state.error;
params.variant = variant || "standard";
params.label = label;
params.required = required;
params.onClick = _this.onClick;
return renderInput(params);
} : (function (params) { return (React__default["default"].createElement(TextField__default["default"], __assign({}, params, InputProps, { label: label, placeholder: InputProps === null || InputProps === void 0 ? void 0 : InputProps.placeholder, variant: variant || "standard", required: required, onClick: _this.onClick, error: _this.state.error, inputRef: function (el) { return _this.inputRef = el; }, InputProps: __assign(__assign(__assign({}, InputProps === null || InputProps === void 0 ? void 0 : InputProps.InputProps), params.InputProps), { onBlur: _this.onInputBlur, endAdornment: (React__default["default"].createElement(material.InputAdornment, { position: "end" },
params.InputProps.endAdornment,
!_this.props.disableClearable && _this.getValueForCheck(_this.state.value) ? (React__default["default"].createElement(material.IconButton, { size: "small", onClick: function (e) {
e.stopPropagation();
_this.clear(true);
} },
React__default["default"].createElement(ClearIcon__default["default"], { fontSize: "small" }))) : null)) }) }))); }) })));
};
return AutocompleteInput;
}(React.Component));
var CheckboxInput = /** @class */ (function (_super) {
__extends(CheckboxInput, _super);
function CheckboxInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
value: _this.props.defaultChecked || false,
error: false
};
_this.onChange = function (event, checked) {
var _a, _b;
_this.setValue(checked || false);
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, event, checked);
};
_this.onClick = function (event) {
var _a, _b;
clearTimeout(_this.validationTimeout);
_this.setState(__assign(__assign({}, _this.state), { error: false }));
(_b = (_a = _this.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.click = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.blur();
};
return _this;
}
CheckboxInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _a, _b, _c;
switch (true) {
case this.state.value !== nextState.value:
case this.state.error !== nextState.error:
case this.props.label !== nextProps.label:
case this.props.disabled !== nextProps.disabled:
case stringify((_a = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _a !== void 0 ? _a : {}) !== stringify((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.updateListener) !== null && _c !== void 0 ? _c : {}):
return true;
default: return false;
}
};
CheckboxInput.prototype.setValue = function (value) {
var _this = this;
if (value === this.state.value)
return Promise.resolve(value);
return new Promise(function (resolve) {
_this.setState(__assign(__assign({}, _this.state), { value: value }), function () {
var _a, _b, _c, _d;
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, value);
resolve(value);
});
});
};
CheckboxInput.prototype.getValue = function () {
return this.state.value || false;
};
CheckboxInput.prototype.clear = function () {
return this.setValue(this.props.checked || this.props.defaultChecked || false);
};
CheckboxInput.prototype.validation = function () {
var _this = this;
if (!this.state.value && this.props.required) {
clearTimeout(this.validationTimeout);
this.setState(__assign(__assign({}, this.state), { error: true }));
this.validationTimeout = setTimeout(function () {
_this.setState(__assign(__assign({}, _this.state), { error: false }));
}, 3000);
return false;
}
return true;
};
CheckboxInput.prototype.render = function () {
var _this = this;
var _a = this.props; _a.defaultChecked; _a.defaultValue; _a.onChangeValue; _a.visible; _a._call_parent_for_update; _a.updateListener; var restProps = __rest(_a, ["defaultChecked", "defaultValue", "onChangeValue", "visible", "_call_parent_for_update", "updateListener"]);
var label = this.props.label + (this.props.required ? ' *' : '');
return (React__default["default"].createElement(material.FormControlLabel, { onClick: this.onClick, control: React__default["default"].createElement(material.Checkbox, __assign({}, restProps, { sx: { color: this.state.error ? colors.red[700] : colors.grey[700] }, checked: this.state.value, onChange: this.onChange, inputRef: function (el) { return _this.inputRef = el; } })), style: { userSelect: 'none' }, label: label }));
};
return CheckboxInput;
}(React.Component));
var CustomInput = /** @class */ (function (_super) {
__extends(CustomInput, _super);
function CustomInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
value: null,
error: false
};
_this.click = function () {
var _a;
(_a = _this.elementRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.elementRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.elementRef) === null || _a === void 0 ? void 0 : _a.blur();
};
return _this;
}
CustomInput.prototype.setValue = function (value) {
var _a, _b;
if (typeof ((_a = this.elementRef) === null || _a === void 0 ? void 0 : _a.setValue) === "function") {
return (_b = this.elementRef) === null || _b === void 0 ? void 0 : _b.setValue(value);
}
return Promise.resolve(null);
};
CustomInput.prototype.getValue = function () {
var _a, _b;
if (typeof ((_a = this.elementRef) === null || _a === void 0 ? void 0 : _a.getValue) === "function") {
return (_b = this.elementRef) === null || _b === void 0 ? void 0 : _b.getValue();
}
return null;
};
CustomInput.prototype.clear = function () {
var _a, _b;
if (typeof ((_a = this.elementRef) === null || _a === void 0 ? void 0 : _a.clear) === "function") {
return (_b = this.elementRef) === null || _b === void 0 ? void 0 : _b.clear();
}
return Promise.resolve(null);
};
CustomInput.prototype.validation = function () {
var _a, _b;
if (typeof ((_a = this.elementRef) === null || _a === void 0 ? void 0 : _a.validation) === "function") {
return (_b = this.elementRef) === null || _b === void 0 ? void 0 : _b.validation();
}
return true;
};
CustomInput.prototype.render = function () {
var _this = this;
var _a = this.props, element = _a.element, rest = __rest(_a, ["element"]);
var render = React__default["default"].createElement(element, __assign({ ref: function (el) { return _this.elementRef = el; } }, rest));
return (React__default["default"].createElement(React.Fragment, null,
" ",
render,
" "));
};
return CustomInput;
}(React.Component));
var DateInput = /** @class */ (function (_super) {
__extends(DateInput, _super);
function DateInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
value: _this.props.defaultValue || null,
error: false
};
_this.onChange = function (event, keyboardInputValue) {
var _a, _b;
var value = event && event.toDate ? event.toDate() : event;
_this.setValue(value || null);
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, event, keyboardInputValue);
};
_this.onClick = function (event) {
var _a, _b;
clearTimeout(_this.validationTimeout);
_this.setState(__assign(__assign({}, _this.state), { error: false }));
(_b = (_a = _this.props.InputProps) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.click = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.blur();
};
return _this;
}
DateInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _a, _b, _c;
switch (true) {
case this.state.value !== nextState.value:
case this.state.error !== nextState.error:
case this.props.label !== nextProps.label:
case this.props.disabled !== nextProps.disabled:
case stringify((_a = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _a !== void 0 ? _a : {}) !== stringify((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.updateListener) !== null && _c !== void 0 ? _c : {}):
return true;
default: return false;
}
};
DateInput.prototype.setValue = function (value) {
var _this = this;
if (value === this.state.value)
return Promise.resolve(value);
return new Promise(function (resolve) {
_this.setState(__assign(__assign({}, _this.state), { value: value }), function () {
var _a, _b, _c, _d;
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, value);
resolve(value);
});
});
};
DateInput.prototype.getValue = function () {
return this.state.value || null;
};
DateInput.prototype.clear = function () {
return this.setValue(this.props.defaultValue || null);
};
DateInput.prototype.validation = function () {
var _this = this;
if (!this.state.value && this.props.required) {
clearTimeout(this.validationTimeout);
this.setState(__assign(__assign({}, this.state), { error: true }));
this.validationTimeout = setTimeout(function () {
_this.setState(__assign(__assign({}, _this.state), { error: false }));
}, 3000);
return false;
}
return true;
};
DateInput.prototype.render = function () {
var _this = this;
var _a = this.props; _a.onChangeValue; _a.defaultValue; var dateAdapter = _a.dateAdapter, variant = _a.variant, required = _a.required; _a.visible; _a._call_parent_for_update; _a.updateListener; var restProps = __rest(_a, ["onChangeValue", "defaultValue", "dateAdapter", "variant", "required", "visible", "_call_parent_for_update", "updateListener"]);
return (React__default["default"].createElement(xDatePickers.LocalizationProvider, { dateAdapter: dateAdapter || AdapterDayjs.AdapterDayjs },
React__default["default"].createElement(xDatePickers.DatePicker, __assign({}, restProps, { value: this.state.value, onChange: this.onChange, inputRef: function (el) { return _this.inputRef = el; }, renderInput: function (params) { return (React__default["default"].createElement(TextField__default["default"], __assign({}, params, { inputProps: __assign(__assign({}, params.inputProps), _this.props.inputProps), fullWidth: _this.props.fullWidth || false, variant: variant || 'standard', required: required || false, error: _this.state.error, onClick: _this.onClick }))); } }))));
};
return DateInput;
}(React.Component));
var DatetimeInput = /** @class */ (function (_super) {
__extends(DatetimeInput, _super);
function DatetimeInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
value: _this.props.defaultValue || null,
error: false
};
_this.onChange = function (event, keyboardInputValue) {
var _a, _b;
var value = event && event.toDate ? event.toDate() : event;
_this.setValue(value || null);
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, event, keyboardInputValue);
};
_this.onClick = function (event) {
var _a, _b;
clearTimeout(_this.validationTimeout);
_this.setState(__assign(__assign({}, _this.state), { error: false }));
(_b = (_a = _this.props.InputProps) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.click = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.blur();
};
return _this;
}
DatetimeInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _a, _b, _c;
switch (true) {
case this.state.value !== nextState.value:
case this.state.error !== nextState.error:
case this.props.label !== nextProps.label:
case this.props.disabled !== nextProps.disabled:
case stringify((_a = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _a !== void 0 ? _a : {}) !== stringify((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.updateListener) !== null && _c !== void 0 ? _c : {}):
return true;
default: return false;
}
};
DatetimeInput.prototype.setValue = function (value) {
var _this = this;
if (value === this.state.value)
return Promise.resolve(value);
return new Promise(function (resolve) {
_this.setState(__assign(__assign({}, _this.state), { value: value }), function () {
var _a, _b, _c, _d;
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, value);
resolve(value);
});
});
};
DatetimeInput.prototype.getValue = function () {
return this.state.value || null;
};
DatetimeInput.prototype.clear = function () {
return this.setValue(this.props.defaultValue || null);
};
DatetimeInput.prototype.validation = function () {
var _this = this;
if (!this.state.value && this.props.required) {
clearTimeout(this.validationTimeout);
this.setState(__assign(__assign({}, this.state), { error: true }));
this.validationTimeout = setTimeout(function () {
_this.setState(__assign(__assign({}, _this.state), { error: false }));
}, 3000);
return false;
}
return true;
};
DatetimeInput.prototype.render = function () {
var _this = this;
var _a = this.props; _a.onChangeValue; _a.defaultValue; var dateAdapter = _a.dateAdapter, variant = _a.variant, required = _a.required; _a.visible; _a._call_parent_for_update; _a.updateListener; var restProps = __rest(_a, ["onChangeValue", "defaultValue", "dateAdapter", "variant", "required", "visible", "_call_parent_for_update", "updateListener"]);
return (React__default["default"].createElement(xDatePickers.LocalizationProvider, { dateAdapter: dateAdapter || AdapterDayjs.AdapterDayjs },
React__default["default"].createElement(xDatePickers.DateTimePicker, __assign({}, restProps, { ampm: this.props.ampm || false, value: this.state.value, onChange: this.onChange, inputRef: function (el) { return _this.inputRef = el; }, renderInput: function (params) { return (React__default["default"].createElement(TextField__default["default"], __assign({}, params, { inputProps: __assign(__assign({}, params.inputProps), _this.props.inputProps), fullWidth: _this.props.fullWidth || false, variant: variant || 'standard', required: required || false, error: _this.state.error, onClick: _this.onClick }))); } }))));
};
return DatetimeInput;
}(React.Component));
var FileInput = /** @class */ (function (_super) {
__extends(FileInput, _super);
function FileInput(props) {
var _this = _super.call(this, props) || this;
_this.state = {
value: _this.props.defaultValue || null,
error: false,
inputKey: randomString(20)
};
_this.inputIdentity = '';
_this.textHelperIdentity = '';
_this.onChange = function (event) {
var _a, _b;
var value = event.target.files;
_this.setValue(value || null);
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.onClick = function (event) {
var _a, _b;
clearTimeout(_this.validationTimeout);
_this.setState(__assign(__assign({}, _this.state), { error: false }));
(_b = (_a = _this.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
};
_this.click = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.click();
};
_this.focus = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.focus();
};
_this.blur = function () {
var _a;
(_a = _this.inputRef) === null || _a === void 0 ? void 0 : _a.blur();
};
_this.inputIdentity = randomString(20);
_this.textHelperIdentity = randomString(20);
return _this;
}
FileInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _a, _b, _c;
switch (true) {
case this.state.value !== nextState.value:
case this.state.error !== nextState.error:
case this.props.label !== nextProps.label:
case this.props.disabled !== nextProps.disabled:
case stringify((_a = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _a !== void 0 ? _a : {}) !== stringify((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.updateListener) !== null && _c !== void 0 ? _c : {}):
return true;
default: return false;
}
};
FileInput.prototype.setValue = function (value) {
var _this = this;
if (value === this.state.value)
return Promise.resolve(value);
return new Promise(function (resolve) {
var inputKey = !value ? randomString(20) : _this.state.inputKey;
_this.setState(__assign(__assign({}, _this.state), { value: value, inputKey: inputKey }), function () {
var _a, _b, _c, _d;
if (_this.inputRef && value) {
_this.inputRef.files = value;
}
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, value);
resolve(value);
});
});
};
FileInput.prototype.getValue = function () {
return this.state.value || null;
};
FileInput.prototype.clear = function () {
return this.setValue(this.props.defaultValue || null);
};
FileInput.prototype.validation = function () {
var _this = this;
if (!this.state.value && this.props.required) {
clearTimeout(this.validationTimeout);
this.setState(__assign(__assign({}, this.state), { error: true }));
this.validationTimeout = setTimeout(function () {
_this.setState(__assign(__assign({}, _this.state), { error: false }));
}, 3000);
return false;
}
return true;
};
FileInput.prototype.render = function () {
var _this = this;
var _a, _b;
var _c = this.props; _c.defaultValue; _c.onChangeValue; _c.label; var helperText = _c.helperText, FormControlProps = _c.FormControlProps, InputLabelProps = _c.InputLabelProps, FormHelperTextProps = _c.FormHelperTextProps, InputProps = _c.InputProps, multiple = _c.multiple; _c.visible; _c._call_parent_for_update; _c.updateListener; var restProps = __rest(_c, ["defaultValue", "onChangeValue", "label", "helperText", "FormControlProps", "InputLabelProps", "FormHelperTextProps", "InputProps", "multiple", "visible", "_call_parent_for_update", "updateListener"]);
return (React__default["default"].createElement(material.FormControl, __assign({}, FormControlProps, { variant: (_a = FormControlProps === null || FormControlProps === void 0 ? void 0 : FormControlProps.variant) !== null && _a !== void 0 ? _a : 'standard' }),
this.props.label ? (React__default["default"].createElement(material.InputLabel, __assign({}, InputLabelProps, { shrink: (_b = InputLabelProps === null || InputLabelProps === void 0 ? void 0 : InputLabelProps.shrink) !== null && _b !== void 0 ? _b : true, htmlFor: this.inputIdentity }), this.props.label)) : null,
React__default["default"].createElement(material.Input, __assign({}, restProps, { id: this.inputIdentity, "aria-describedby": this.textHelperIdentity, type: "file", inputProps: __assign(__assign({ multiple: multiple || false }, InputProps), { key: this.state.inputKey }), error: this.state.error, onChange: this.onChange, onClick: this.onClick,
// value={this.state.value?.length ? this.state.value[0].name : ''}
inputRef: function (el) { return _this.inputRef = el; } })),
helperText ? (React__default["default"].createElement(material.FormHelperText, __assign({}, FormHelperTextProps, { id: this.textHelperIdentity }), helperText)) : null));
};
return FileInput;
}(React.Component));
var GroupInput = /** @class */ (function (_super) {
__extends(GroupInput, _super);
function GroupInput(props) {
var _this = _super.call(this, props) || this;
_this.state = {
error: false,
value: null
};
_this.onChangeValue = function (data) {
var _a, _b, _c, _d;
(_b = (_a = _this.props)._call_parent_for_update) === null || _b === void 0 ? void 0 : _b.call(_a);
(_d = (_c = _this.props).onChangeValue) === null || _d === void 0 ? void 0 : _d.call(_c, data);
};
_this.click = function () { };
_this.focus = function () { };
_this.blur = function () { };
_this.builderRef = React.createRef();
return _this;
}
GroupInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var _a, _b, _c;
switch (true) {
case JSON.stringify(this.state.value) !== JSON.stringify(nextState.value):
case stringify((_a = nextProps === null || nextProps === void 0 ? void 0 : nextProps.updateListener) !== null && _a !== void 0 ? _a : {}) !== stringify((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.updateListener) !== null && _c !== void 0 ? _c : {}):
return true;
default: return false;
}
};
GroupInput.prototype.setValue = function (values) {
if (!this.builderRef.current || !values)
return Promise.reject(values);
return this.builderRef.current.setValues(values);
};
GroupInput.prototype.getValue = function (validation) {
var _a;
return (_a = this.builderRef.current) === null || _a === void 0 ? void 0 : _a.getValues(validation).data;
};
GroupInput.prototype.clear = function () {
var _a;
return ((_a = this.builderRef.current) === null || _a === void 0 ? void 0 : _a.clear()) || Promise.resolve();
};
GroupInput.prototype.validation = function () {
var _a, _b;
var validation = (_b = (_a = this.builderRef.current) === null || _a === void 0 ? void 0 : _a.getValues(true)) === null || _b === void 0 ? void 0 : _b.validation;
return typeof (validation === null || validation === void 0 ? void 0 : validation.status) == "boolean" ? validation === null || validation === void 0 ? void 0 : validation.status : true;
};
GroupInput.prototype.render = function () {
return (React__default["default"].createElement(FormBuilder, { inputs: this.props.inputs, ref: this.builderRef, onChange: this.onChangeValue }));
};
return GroupInput;
}(React.Component));
var ItemsInput = /** @class */ (function (_super) {
__extends(ItemsInput, _super);
function ItemsInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {