drf-react-by-schema 0.6.5 → 0.7.1
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/api.d.ts +7 -13
- package/dist/api.js +77 -77
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable.js +5 -7
- package/dist/components/DialogActions.d.ts +3 -3
- package/dist/components/DialogActions.js +2 -4
- package/dist/components/forms/DialogFormBySchema.d.ts +14 -0
- package/dist/components/forms/DialogFormBySchema.js +61 -0
- package/dist/components/forms/FieldBySchema.d.ts +3 -0
- package/dist/components/forms/FieldBySchema.js +65 -0
- package/dist/components/forms/FormBySchema.d.ts +19 -0
- package/dist/components/forms/FormBySchema.js +164 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +86 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +41 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +49 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +41 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +203 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.js +60 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/TextFieldBySchema.js +44 -0
- package/dist/context/APIWrapper.d.ts +5 -5
- package/dist/context/APIWrapper.js +135 -87
- package/dist/context/APIWrapperContext.d.ts +22 -9
- package/dist/context/APIWrapperContext.js +42 -9
- package/dist/context/DRFReactBySchemaContext.d.ts +4 -4
- package/dist/context/DRFReactBySchemaContext.js +5 -5
- package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +7 -10
- package/dist/context/Form.d.ts +1 -1
- package/dist/context/Form.js +13 -14
- package/dist/context/FormContext.js +0 -7
- package/dist/context/Overlays.js +11 -12
- package/dist/index.d.ts +16 -6
- package/dist/index.js +31 -7
- package/dist/styles/layout.d.ts +7 -0
- package/dist/styles/layout.js +2 -1
- package/dist/styles/theme.js +77 -42
- package/dist/utils.d.ts +42 -4
- package/dist/utils.js +22 -18
- package/package.json +1 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
+
export default function AutocompleteFieldBySchema({ fieldKey, index, name, schema, control, errors, optionIdKey, optionLabelKey, options, isSemaphoric, sx, label, ...other }: FieldBySchemaProps): JSX.Element;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
19
|
+
const Autocomplete_1 = __importDefault(require("@mui/material/Autocomplete"));
|
|
20
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
21
|
+
const utils_1 = require("../../../utils");
|
|
22
|
+
const DRFReactBySchemaContext_1 = require("../../../context/DRFReactBySchemaContext");
|
|
23
|
+
const renderInput = (_a) => {
|
|
24
|
+
var { control, options, optionLabelKey, schema, name, errors, fieldKey, index, isSemaphoric, label, theme } = _a, params = __rest(_a, ["control", "options", "optionLabelKey", "schema", "name", "errors", "fieldKey", "index", "isSemaphoric", "label", "theme"]);
|
|
25
|
+
const model = name;
|
|
26
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
27
|
+
? (0, utils_1.errorProps)({
|
|
28
|
+
fieldKey,
|
|
29
|
+
index,
|
|
30
|
+
fieldKeyProp: name,
|
|
31
|
+
errors,
|
|
32
|
+
})
|
|
33
|
+
: {
|
|
34
|
+
error: errors && Boolean(errors[name]),
|
|
35
|
+
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
36
|
+
};
|
|
37
|
+
let sx = undefined;
|
|
38
|
+
if (isSemaphoric && options && optionLabelKey) {
|
|
39
|
+
let tipo;
|
|
40
|
+
switch (params.inputProps.value) {
|
|
41
|
+
case options[0][optionLabelKey]:
|
|
42
|
+
tipo = 'success';
|
|
43
|
+
break;
|
|
44
|
+
case options[1][optionLabelKey]:
|
|
45
|
+
tipo = 'warning';
|
|
46
|
+
break;
|
|
47
|
+
case options[2][optionLabelKey]:
|
|
48
|
+
tipo = 'error';
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (tipo) {
|
|
52
|
+
sx = { backgroundColor: theme.palette[tipo].semaphoric };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label || schema[model].label, required: schema[model].required, margin: "normal", error: error, helperText: helperText, sx: sx })));
|
|
56
|
+
};
|
|
57
|
+
function AutocompleteFieldBySchema(_a) {
|
|
58
|
+
var { fieldKey, index, name, schema, control, errors, optionIdKey = 'id', optionLabelKey = 'label', options, isSemaphoric = false, sx = { mr: 2 }, label } = _a, other = __rest(_a, ["fieldKey", "index", "name", "schema", "control", "errors", "optionIdKey", "optionLabelKey", "options", "isSemaphoric", "sx", "label"]);
|
|
59
|
+
const model = name;
|
|
60
|
+
const { theme } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
61
|
+
if (!options) {
|
|
62
|
+
options = schema[model].choices;
|
|
63
|
+
}
|
|
64
|
+
if (fieldKey && index && index >= 0) {
|
|
65
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
66
|
+
}
|
|
67
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({}, field, { key: name, id: name, options: options || [], selectOnFocus: true, autoHighlight: true, isOptionEqualToValue: (option, value) => {
|
|
68
|
+
return option[optionIdKey] === value[optionIdKey];
|
|
69
|
+
}, getOptionLabel: (option) => {
|
|
70
|
+
return option[optionLabelKey];
|
|
71
|
+
}, onChange: (e, value) => {
|
|
72
|
+
field.onChange(value);
|
|
73
|
+
}, fullWidth: true, renderInput: (params) => {
|
|
74
|
+
return renderInput(Object.assign(Object.assign({}, params), { control,
|
|
75
|
+
isSemaphoric,
|
|
76
|
+
options,
|
|
77
|
+
optionLabelKey,
|
|
78
|
+
schema,
|
|
79
|
+
name,
|
|
80
|
+
errors,
|
|
81
|
+
fieldKey,
|
|
82
|
+
index,
|
|
83
|
+
theme }));
|
|
84
|
+
}, sx: sx }, other))) }));
|
|
85
|
+
}
|
|
86
|
+
exports.default = AutocompleteFieldBySchema;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
19
|
+
const Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
|
|
20
|
+
const FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
|
|
21
|
+
function BooleanFieldBySchema(_a) {
|
|
22
|
+
var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 } } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx"]);
|
|
23
|
+
const model = name;
|
|
24
|
+
if (fieldKey && index && index >= 0) {
|
|
25
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
26
|
+
}
|
|
27
|
+
// const { error, helperText } =
|
|
28
|
+
// fieldKey && index >= 0
|
|
29
|
+
// ? errorProps({
|
|
30
|
+
// fieldKey,
|
|
31
|
+
// index,
|
|
32
|
+
// fieldKeyProp: name,
|
|
33
|
+
// errors,
|
|
34
|
+
// })
|
|
35
|
+
// : {
|
|
36
|
+
// error: errors && Boolean(errors[name]),
|
|
37
|
+
// helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
38
|
+
// };
|
|
39
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(FormControlLabel_1.default, { control: react_1.default.createElement(Checkbox_1.default, Object.assign({}, field, other, { value: field.value || false, checked: field.value || false, inputProps: { 'aria-label': 'controlled' } })), label: schema[model].label, required: schema[model].required })) }));
|
|
40
|
+
}
|
|
41
|
+
exports.default = BooleanFieldBySchema;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
19
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
|
+
const DesktopDatePicker_1 = require("@mui/x-date-pickers/DesktopDatePicker");
|
|
21
|
+
const utils_1 = require("drf-react-by-schema/dist/utils");
|
|
22
|
+
const utils_2 = require("../../../utils");
|
|
23
|
+
function DesktopDatePickerBySchema(_a) {
|
|
24
|
+
var { name, schema, control, errors, fieldKey = null, index = null, sx } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx"]);
|
|
25
|
+
if (!sx) {
|
|
26
|
+
sx = { minWidth: 200 };
|
|
27
|
+
}
|
|
28
|
+
if (!sx.hasOwnProperty('minWidth')) {
|
|
29
|
+
sx = Object.assign(Object.assign({}, sx), { minWidth: 200 });
|
|
30
|
+
}
|
|
31
|
+
const model = name;
|
|
32
|
+
if (fieldKey && index && index >= 0) {
|
|
33
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
34
|
+
}
|
|
35
|
+
const inputFormat = (0, utils_1.buildDateFormatBySchema)(schema[model].date_views);
|
|
36
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
37
|
+
? (0, utils_2.errorProps)({
|
|
38
|
+
fieldKey,
|
|
39
|
+
index,
|
|
40
|
+
fieldKeyProp: name,
|
|
41
|
+
errors,
|
|
42
|
+
})
|
|
43
|
+
: {
|
|
44
|
+
error: errors && Boolean(errors[name]),
|
|
45
|
+
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
46
|
+
};
|
|
47
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(DesktopDatePicker_1.DesktopDatePicker, Object.assign({}, field, { label: schema[model].label, views: schema[model].date_views, inputFormat: inputFormat, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, other, { sx: sx, margin: "normal", error: error, helperText: helperText }))) }))) }));
|
|
48
|
+
}
|
|
49
|
+
exports.default = DesktopDatePickerBySchema;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
19
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
|
+
const DesktopDateTimePicker_1 = require("@mui/x-date-pickers/DesktopDateTimePicker");
|
|
21
|
+
const utils_1 = require("../../../utils");
|
|
22
|
+
function DesktopDateTimePickerBySchema(_a) {
|
|
23
|
+
var { name, schema, control, errors, multiline = false, fieldKey = null, index = null, sx = { mr: 2 } } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "fieldKey", "index", "sx"]);
|
|
24
|
+
const model = name;
|
|
25
|
+
if (fieldKey && index && index >= 0) {
|
|
26
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
27
|
+
}
|
|
28
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
29
|
+
? (0, utils_1.errorProps)({
|
|
30
|
+
fieldKey,
|
|
31
|
+
index,
|
|
32
|
+
fieldKeyProp: name,
|
|
33
|
+
errors,
|
|
34
|
+
})
|
|
35
|
+
: {
|
|
36
|
+
error: errors && Boolean(errors[name]),
|
|
37
|
+
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
38
|
+
};
|
|
39
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(DesktopDateTimePicker_1.DesktopDateTimePicker, Object.assign({}, field, { label: schema[model].label, inputFormat: "DD/MM/yyyy HH:mm", renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, other, { sx: sx, margin: "normal", error: error, helperText: helperText }))) }))) }));
|
|
40
|
+
}
|
|
41
|
+
exports.default = DesktopDateTimePickerBySchema;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
42
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
43
|
+
const Autocomplete_1 = __importStar(require("@mui/material/Autocomplete"));
|
|
44
|
+
const Edit_1 = __importDefault(require("@mui/icons-material/Edit"));
|
|
45
|
+
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
46
|
+
const Chip_1 = __importDefault(require("@mui/material/Chip"));
|
|
47
|
+
const utils_1 = require("../../../utils");
|
|
48
|
+
const DialogActions_1 = __importDefault(require("../../DialogActions"));
|
|
49
|
+
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
50
|
+
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
51
|
+
const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) => {
|
|
52
|
+
var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, multiple = false } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "multiple"]);
|
|
53
|
+
const { setDialog } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
54
|
+
const model = name;
|
|
55
|
+
const label = schema[model].label;
|
|
56
|
+
if (!optionsModel) {
|
|
57
|
+
optionsModel = model;
|
|
58
|
+
}
|
|
59
|
+
const options = optionsAC ? optionsAC[optionsModel] : [];
|
|
60
|
+
if (fieldKey && index && index >= 0) {
|
|
61
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
62
|
+
}
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (!getValues || !setValue) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const valuesInitial = getValues(model);
|
|
68
|
+
if (!valuesInitial) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (multiple) {
|
|
72
|
+
const harmonizedValues = [];
|
|
73
|
+
for (const valueInitial of valuesInitial) {
|
|
74
|
+
const harmonizedValue = options.find((option) => option.id === valueInitial.id);
|
|
75
|
+
if (harmonizedValue) {
|
|
76
|
+
harmonizedValues.push(harmonizedValue);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
setValue(model, harmonizedValues);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const harmonizedValues = options.find((option) => option.id === valuesInitial.id);
|
|
83
|
+
setValue(model, harmonizedValues);
|
|
84
|
+
}, []);
|
|
85
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
86
|
+
? (0, utils_1.errorProps)({
|
|
87
|
+
fieldKey,
|
|
88
|
+
index,
|
|
89
|
+
fieldKeyProp: name,
|
|
90
|
+
errors,
|
|
91
|
+
})
|
|
92
|
+
: {
|
|
93
|
+
error: errors && Boolean(errors[name]),
|
|
94
|
+
helperText: errors && errors[name]
|
|
95
|
+
? errors[name].message
|
|
96
|
+
: schema[name].help_text || '',
|
|
97
|
+
};
|
|
98
|
+
if (!schema[model].disabled && onEditModel && optionsModel) {
|
|
99
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: options.length === 0 || schema[model].disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
100
|
+
let valueAr = value;
|
|
101
|
+
if (!multiple) {
|
|
102
|
+
valueAr = [value];
|
|
103
|
+
}
|
|
104
|
+
const newValueAr = [];
|
|
105
|
+
if (valueAr) {
|
|
106
|
+
for (let newValue of valueAr) {
|
|
107
|
+
if (typeof newValue === 'string') {
|
|
108
|
+
const tmpId = (0, utils_1.getTmpId)();
|
|
109
|
+
newValue = {
|
|
110
|
+
id: tmpId,
|
|
111
|
+
label: newValue,
|
|
112
|
+
[labelKey]: newValue,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (newValue && newValue.inputValue) {
|
|
116
|
+
const tmpId = (0, utils_1.getTmpId)();
|
|
117
|
+
newValue = {
|
|
118
|
+
id: tmpId,
|
|
119
|
+
label: newValue.inputValue,
|
|
120
|
+
[labelKey]: newValue.inputValue,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
newValueAr.push(newValue);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
field.onChange(multiple ? newValueAr : newValueAr[0]);
|
|
127
|
+
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: schema[model].required, margin: "normal", error: error, helperText: helperText, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
128
|
+
!multiple && field.value && (react_1.default.createElement(IconButton_1.default, { size: "small", onClick: () => {
|
|
129
|
+
if ((0, utils_1.isTmpId)(field.value.id)) {
|
|
130
|
+
setDialog({
|
|
131
|
+
open: true,
|
|
132
|
+
loading: false,
|
|
133
|
+
title: 'Item sendo criado',
|
|
134
|
+
Body: 'Este item está sendo criado agora por você. Para editar suas propriedades, salve antes, e depois você poderá editar!',
|
|
135
|
+
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, btnCancel: "Entendi" })),
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (optionsModel) {
|
|
140
|
+
onEditModel({
|
|
141
|
+
fieldKey,
|
|
142
|
+
index,
|
|
143
|
+
model: optionsModel,
|
|
144
|
+
id: field.value.id,
|
|
145
|
+
labelKey,
|
|
146
|
+
setValue,
|
|
147
|
+
getValues,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
} },
|
|
151
|
+
react_1.default.createElement(Edit_1.default, null))),
|
|
152
|
+
params.InputProps.endAdornment)) }) }, other))), freeSolo: true, filterOptions: (options, params) => {
|
|
153
|
+
const filtered = filter(options, params);
|
|
154
|
+
const { inputValue } = params;
|
|
155
|
+
// Suggest the creation of a new value
|
|
156
|
+
const isExisting = options.some((option) => inputValue === option.label);
|
|
157
|
+
if (inputValue !== '' && !isExisting) {
|
|
158
|
+
filtered.push({
|
|
159
|
+
inputValue,
|
|
160
|
+
label: `Criar "${inputValue}"`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return filtered;
|
|
164
|
+
}, handleHomeEndKeys: true, getOptionLabel: getOptionLabel
|
|
165
|
+
? getOptionLabel
|
|
166
|
+
: (option) => {
|
|
167
|
+
// Value selected with enter, right from the input
|
|
168
|
+
if (typeof option === 'string') {
|
|
169
|
+
return option;
|
|
170
|
+
}
|
|
171
|
+
// Criar "xxx" option created dynamically
|
|
172
|
+
if (option.inputValue) {
|
|
173
|
+
return option.inputValue;
|
|
174
|
+
}
|
|
175
|
+
// Regular option
|
|
176
|
+
return option.label;
|
|
177
|
+
}, renderOption: renderOption
|
|
178
|
+
? renderOption
|
|
179
|
+
: (props, option) => (react_1.default.createElement("li", Object.assign({ key: option.id }, props), option.label)), renderTags: multiple
|
|
180
|
+
? (tagValue, getTagProps) => {
|
|
181
|
+
return tagValue.map((option, index) => (react_1.default.createElement(Chip_1.default, Object.assign({}, getTagProps({ index }), { label: option.label, icon: (0, utils_1.isTmpId)(option.id) ? (react_1.default.createElement(react_1.default.Fragment, null)) : (react_1.default.createElement(IconButton_1.default, { size: "small", onClick: () => {
|
|
182
|
+
if (optionsModel) {
|
|
183
|
+
onEditModel({
|
|
184
|
+
fieldKey,
|
|
185
|
+
index,
|
|
186
|
+
model: optionsModel,
|
|
187
|
+
id: option.id,
|
|
188
|
+
labelKey,
|
|
189
|
+
setValue,
|
|
190
|
+
getValues,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
} },
|
|
194
|
+
react_1.default.createElement(Edit_1.default, null))) }))));
|
|
195
|
+
}
|
|
196
|
+
: undefined }))) }));
|
|
197
|
+
}
|
|
198
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: options.length === 0 || schema[model].disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
199
|
+
field.onChange(value);
|
|
200
|
+
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: schema[model].required, margin: "normal", error: error, helperText: helperText }, other))), getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
201
|
+
});
|
|
202
|
+
EditableAutocompleteFieldBySchema.displayName = 'EditableAutocompleteFieldBySchema';
|
|
203
|
+
exports.default = EditableAutocompleteFieldBySchema;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
+
export default function FloatFieldBySchema({ fieldKey, index, name, control, schema, errors, onValueChange, decimalScale, label, ...other }: Omit<FieldBySchemaProps, 'type'>): JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_number_format_1 = require("react-number-format");
|
|
19
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
21
|
+
const utils_1 = require("../../../utils");
|
|
22
|
+
function FloatFieldBySchema(_a) {
|
|
23
|
+
var { fieldKey, index, name, control, schema, errors, onValueChange, decimalScale, label } = _a, other = __rest(_a, ["fieldKey", "index", "name", "control", "schema", "errors", "onValueChange", "decimalScale", "label"]);
|
|
24
|
+
const model = name;
|
|
25
|
+
if (!label) {
|
|
26
|
+
label = schema[model].label;
|
|
27
|
+
}
|
|
28
|
+
if (fieldKey && index && index >= 0) {
|
|
29
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
30
|
+
}
|
|
31
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
32
|
+
? (0, utils_1.errorProps)({
|
|
33
|
+
fieldKey,
|
|
34
|
+
index,
|
|
35
|
+
fieldKeyProp: name,
|
|
36
|
+
errors,
|
|
37
|
+
})
|
|
38
|
+
: {
|
|
39
|
+
error: errors && Boolean(errors[name]),
|
|
40
|
+
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
41
|
+
};
|
|
42
|
+
const prefix = schema[model].is_currency
|
|
43
|
+
? 'R$ '
|
|
44
|
+
: schema[model].prefix !== ''
|
|
45
|
+
? `${schema[model].prefix} `
|
|
46
|
+
: '';
|
|
47
|
+
const suffix = schema[model].suffix !== '' ? ` ${schema[model].suffix}` : '';
|
|
48
|
+
const decimals = decimalScale || schema[model].decimal_places || 2;
|
|
49
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: (_a) => {
|
|
50
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]);
|
|
51
|
+
const moedaInputProps = Object.assign(Object.assign({}, field), { onChange: undefined });
|
|
52
|
+
return (react_1.default.createElement(react_number_format_1.NumericFormat, Object.assign({}, moedaInputProps, other, { label: label, required: schema[model].required, onValueChange: (values, sourceInfo) => {
|
|
53
|
+
field.onChange(values.floatValue);
|
|
54
|
+
if (onValueChange) {
|
|
55
|
+
onValueChange(values.floatValue);
|
|
56
|
+
}
|
|
57
|
+
}, thousandSeparator: ".", decimalSeparator: ",", decimalScale: decimals, fixedDecimalScale: true, valueIsNumericString: true, prefix: prefix, suffix: suffix, error: error, helperText: helperText, margin: "normal", customInput: TextField_1.default })));
|
|
58
|
+
} }));
|
|
59
|
+
}
|
|
60
|
+
exports.default = FloatFieldBySchema;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
+
export default function TextFieldBySchema({ name, schema, control, errors, multiline, minRows, fieldKey, index, sx, isPassword, type, autocomplete, ...other }: FieldBySchemaProps): JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
19
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
|
+
const utils_1 = require("../../../utils");
|
|
21
|
+
function TextFieldBySchema(_a) {
|
|
22
|
+
var { name, schema, control, errors, multiline = false, minRows, fieldKey, index, sx = { mr: 2 }, isPassword = false, type, autocomplete } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "minRows", "fieldKey", "index", "sx", "isPassword", "type", "autocomplete"]);
|
|
23
|
+
const model = name;
|
|
24
|
+
if (fieldKey && index && index >= 0) {
|
|
25
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
26
|
+
}
|
|
27
|
+
if (isPassword) {
|
|
28
|
+
type = 'password';
|
|
29
|
+
autocomplete = 'off';
|
|
30
|
+
}
|
|
31
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
32
|
+
? (0, utils_1.errorProps)({
|
|
33
|
+
fieldKey,
|
|
34
|
+
index,
|
|
35
|
+
fieldKeyProp: name,
|
|
36
|
+
errors,
|
|
37
|
+
})
|
|
38
|
+
: {
|
|
39
|
+
error: errors && Boolean(errors[name]),
|
|
40
|
+
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
41
|
+
};
|
|
42
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(TextField_1.default, Object.assign({}, field, other, { id: name, key: name, label: schema[model].label, required: schema[model].required, disabled: schema[model].disabled === true, margin: "normal", fullWidth: true, multiline: multiline, error: error, helperText: helperText, sx: sx, type: type, autoComplete: autocomplete, minRows: minRows }))) }));
|
|
43
|
+
}
|
|
44
|
+
exports.default = TextFieldBySchema;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DialogType, SnackBarType } from './APIWrapperContext';
|
|
3
3
|
interface APIWrapperProps {
|
|
4
|
-
setLoading:
|
|
5
|
-
handleLoading: (
|
|
6
|
-
setSnackBar:
|
|
7
|
-
setDialog:
|
|
4
|
+
setLoading: (x: boolean) => void;
|
|
5
|
+
handleLoading: (x: boolean) => void;
|
|
6
|
+
setSnackBar: (x: Partial<SnackBarType>) => void;
|
|
7
|
+
setDialog: (x: Partial<DialogType>) => void;
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
}
|
|
10
|
-
declare function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, children }: APIWrapperProps): JSX.Element;
|
|
10
|
+
declare function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, children, }: APIWrapperProps): JSX.Element;
|
|
11
11
|
declare const _default: React.MemoExoticComponent<typeof APIWrapper>;
|
|
12
12
|
export default _default;
|