drf-react-by-schema 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/api.d.ts +7 -13
  2. package/dist/api.js +77 -77
  3. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
  4. package/dist/components/DataGridBySchemaEditable.js +5 -5
  5. package/dist/components/DialogActions.d.ts +3 -3
  6. package/dist/components/DialogActions.js +2 -4
  7. package/dist/components/GenericModelList.js +4 -0
  8. package/dist/components/forms/DialogFormBySchema.d.ts +14 -0
  9. package/dist/components/forms/DialogFormBySchema.js +61 -0
  10. package/dist/components/forms/FieldBySchema.d.ts +3 -0
  11. package/dist/components/forms/FieldBySchema.js +65 -0
  12. package/dist/components/forms/FormBySchema.d.ts +19 -0
  13. package/dist/components/forms/FormBySchema.js +164 -0
  14. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +3 -0
  15. package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +86 -0
  16. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +3 -0
  17. package/dist/components/forms/inputs/BooleanFieldBySchema.js +41 -0
  18. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +3 -0
  19. package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +49 -0
  20. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +3 -0
  21. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +41 -0
  22. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +4 -0
  23. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +203 -0
  24. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +3 -0
  25. package/dist/components/forms/inputs/FloatFieldBySchema.js +60 -0
  26. package/dist/components/forms/inputs/TextFieldBySchema.d.ts +3 -0
  27. package/dist/components/forms/inputs/TextFieldBySchema.js +44 -0
  28. package/dist/context/APIWrapper.d.ts +5 -5
  29. package/dist/context/APIWrapper.js +135 -87
  30. package/dist/context/APIWrapperContext.d.ts +22 -9
  31. package/dist/context/APIWrapperContext.js +42 -9
  32. package/dist/context/DRFReactBySchemaContext.d.ts +4 -4
  33. package/dist/context/DRFReactBySchemaContext.js +5 -5
  34. package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
  35. package/dist/context/DRFReactBySchemaProvider.js +6 -9
  36. package/dist/context/Form.d.ts +1 -1
  37. package/dist/context/Form.js +13 -14
  38. package/dist/context/FormContext.js +0 -7
  39. package/dist/context/Overlays.js +11 -12
  40. package/dist/index.d.ts +16 -6
  41. package/dist/index.js +31 -7
  42. package/dist/styles/layout.d.ts +7 -0
  43. package/dist/styles/layout.js +2 -1
  44. package/dist/utils.d.ts +42 -4
  45. package/dist/utils.js +22 -18
  46. package/package.json +1 -1
@@ -0,0 +1,164 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __rest = (this && this.__rest) || function (s, e) {
35
+ var t = {};
36
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ const react_1 = __importStar(require("react"));
50
+ const Box_1 = __importDefault(require("@mui/material/Box"));
51
+ const Card_1 = __importDefault(require("@mui/material/Card"));
52
+ const CardHeader_1 = __importDefault(require("@mui/material/CardHeader"));
53
+ const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
54
+ const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
55
+ const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
56
+ const styles_1 = require("../../styles");
57
+ const APIWrapperContext_1 = require("../../context/APIWrapperContext");
58
+ function FormBySchema(_a) {
59
+ var { schema, control, errors, register, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, forceReload, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 0 }, options, isSemaphoric = false, label, onValueChange, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, hiddenFields = [], isolatedGetAutoComplete } = _a, props = __rest(_a, ["schema", "control", "errors", "register", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "setOptionsAC", "forceReload", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale", "fieldsLayout", "hiddenFields", "isolatedGetAutoComplete"]);
60
+ const { getAutoComplete } = (0, APIWrapperContext_1.useAPIWrapper)();
61
+ const [fieldsLayout, setFieldsLayout] = (0, react_1.useState)([]);
62
+ const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)(undefined);
63
+ const getColumns = () => {
64
+ const optionsACModels = [];
65
+ if (fieldsLayoutInitial && fieldsLayoutInitial.length > 0) {
66
+ for (const section of fieldsLayoutInitial) {
67
+ if (!section.rows) {
68
+ continue;
69
+ }
70
+ for (const row of section.rows) {
71
+ if (typeof row === 'string') {
72
+ const field = row;
73
+ if (['field', 'nested object'].includes(schema[field].type) &&
74
+ !optionsACModels.includes(field)) {
75
+ optionsACModels.push(field);
76
+ }
77
+ continue;
78
+ }
79
+ for (const field of row) {
80
+ if (['field', 'nested object'].includes(schema[field].type) &&
81
+ !optionsACModels.includes(field)) {
82
+ optionsACModels.push(field);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return { newFieldsLayout: fieldsLayoutInitial, optionsACModels };
88
+ }
89
+ const rows = [];
90
+ for (const [key, field] of Object.entries(schema)) {
91
+ if (['field', 'nested object'].includes(field.type)) {
92
+ rows.push(key);
93
+ if (!optionsACModels.includes(key)) {
94
+ optionsACModels.push(key);
95
+ }
96
+ continue;
97
+ }
98
+ if (!field.read_only) {
99
+ rows.push(key);
100
+ }
101
+ }
102
+ return { newFieldsLayout: [{ rows }], optionsACModels };
103
+ };
104
+ const populateOptionsAC = (optionsACModels) => __awaiter(this, void 0, void 0, function* () {
105
+ const newOptionsAC = {};
106
+ for (const model of optionsACModels) {
107
+ const ret = isolatedGetAutoComplete
108
+ ? yield isolatedGetAutoComplete(model)
109
+ : yield getAutoComplete(model);
110
+ if (ret !== false) {
111
+ newOptionsAC[model] = ret;
112
+ }
113
+ }
114
+ if (setOptionsAC) {
115
+ setOptionsAC(newOptionsAC);
116
+ return;
117
+ }
118
+ setLocalOptionsAC(newOptionsAC);
119
+ });
120
+ (0, react_1.useEffect)(() => {
121
+ const { newFieldsLayout, optionsACModels } = getColumns();
122
+ setFieldsLayout(newFieldsLayout);
123
+ populateOptionsAC(optionsACModels);
124
+ }, []);
125
+ (0, react_1.useEffect)(() => {
126
+ if (forceReload) {
127
+ const { newFieldsLayout, optionsACModels } = getColumns();
128
+ setFieldsLayout(newFieldsLayout);
129
+ populateOptionsAC(optionsACModels);
130
+ }
131
+ }, [forceReload]);
132
+ if (fieldsLayout.length === 0 ||
133
+ (setOptionsAC && !optionsAC) ||
134
+ (!setOptionsAC && !localOptionsAC)) {
135
+ return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
136
+ react_1.default.createElement(CardContent_1.default, null,
137
+ react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBoxWhite },
138
+ react_1.default.createElement(CircularProgress_1.default, null)))));
139
+ }
140
+ return (react_1.default.createElement(react_1.default.Fragment, null,
141
+ register &&
142
+ hiddenFields.map((hiddenField) => (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: getValues ? getValues(hiddenField) : null, key: hiddenField })))),
143
+ fieldsLayout.map((section, sectionIndex) => {
144
+ return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard, key: `section_${sectionIndex}` },
145
+ section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title }),
146
+ react_1.default.createElement(CardContent_1.default, null,
147
+ section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
148
+ section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
149
+ if (typeof row === 'string') {
150
+ const field = row;
151
+ return (react_1.default.createElement(react_1.default.Fragment, { key: field },
152
+ react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: setOptionsAC
153
+ ? optionsAC
154
+ : localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, sx: sx, options: options, isSemaphoric: isSemaphoric, label: label, onValueChange: onValueChange, decimalScale: decimalScale }, props))));
155
+ }
156
+ return (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
157
+ react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => (react_1.default.createElement(react_1.default.Fragment, { key: field },
158
+ react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, sx: {
159
+ mr: i + 1 === j.length ? 0 : 2,
160
+ }, options: options, isSemaphoric: isSemaphoric, label: label, onValueChange: onValueChange, decimalScale: decimalScale }, props))))))));
161
+ }))))));
162
+ })));
163
+ }
164
+ exports.default = FormBySchema;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldBySchemaProps } from '../../../utils';
3
+ export default function BooleanFieldBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldBySchemaProps } from '../../../utils';
3
+ export default function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { FieldBySchemaProps } from '../../../utils';
3
+ export default function DesktopDateTimePickerBySchema({ name, schema, control, errors, multiline, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
@@ -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,4 @@
1
+ import React from 'react';
2
+ import { FieldBySchemaProps } from '../../../utils';
3
+ declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<FieldBySchemaProps & React.RefAttributes<any>>;
4
+ export default EditableAutocompleteFieldBySchema;
@@ -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;