drf-react-by-schema 0.28.8 → 0.28.9
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/@types/index.d.ts +410 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/@types/index.js +9 -0
- package/dist/@types/string-mask.d.ts +10 -0
- package/dist/@types/string-mask.d.ts.map +1 -0
- package/dist/@types/string-mask.js +1 -0
- package/dist/api.d.ts +81 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +1118 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +86 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts +12 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.js +71 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +26 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +146 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +73 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +421 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +18 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +105 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +11 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.js +155 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +12 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +36 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts +10 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.js +85 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts +11 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.js +87 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts +18 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.js +24 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.js +166 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts +6 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.js +154 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +10 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +78 -0
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.js +30 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +7 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +74 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +21 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.js +131 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.js +70 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts +7 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.js +41 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +24 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +259 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts +5 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.js +6 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +33 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.js +161 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +14 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +69 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.js +73 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +30 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +199 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +33 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +270 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +40 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/utils.js +181 -0
- package/dist/components/DataGridBySchemaEditable.d.ts +64 -0
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable.js +172 -0
- package/dist/components/DataTotals.d.ts +12 -0
- package/dist/components/DataTotals.d.ts.map +1 -0
- package/dist/components/DataTotals.js +32 -0
- package/dist/components/DataTotalsServer.d.ts +10 -0
- package/dist/components/DataTotalsServer.d.ts.map +1 -0
- package/dist/components/DataTotalsServer.js +18 -0
- package/dist/components/DialogActions.d.ts +11 -0
- package/dist/components/DialogActions.d.ts.map +1 -0
- package/dist/components/DialogActions.js +20 -0
- package/dist/components/FileTypeIcon.d.ts +18 -0
- package/dist/components/FileTypeIcon.d.ts.map +1 -0
- package/dist/components/FileTypeIcon.js +48 -0
- package/dist/components/GenericModelList.d.ts +53 -0
- package/dist/components/GenericModelList.d.ts.map +1 -0
- package/dist/components/GenericModelList.js +194 -0
- package/dist/components/GenericRelatedModelList.d.ts +55 -0
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -0
- package/dist/components/GenericRelatedModelList.js +181 -0
- package/dist/components/GenericRelatedModelListTable.d.ts +56 -0
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -0
- package/dist/components/GenericRelatedModelListTable.js +31 -0
- package/dist/components/Image.d.ts +10 -0
- package/dist/components/Image.d.ts.map +1 -0
- package/dist/components/Image.js +111 -0
- package/dist/components/details/DetailBySchema.d.ts +4 -0
- package/dist/components/details/DetailBySchema.d.ts.map +1 -0
- package/dist/components/details/DetailBySchema.js +175 -0
- package/dist/components/details/DetailFieldBySchema.d.ts +4 -0
- package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -0
- package/dist/components/details/DetailFieldBySchema.js +88 -0
- package/dist/components/forms/ChangePasswordForm.d.ts +7 -0
- package/dist/components/forms/ChangePasswordForm.d.ts.map +1 -0
- package/dist/components/forms/ChangePasswordForm.js +93 -0
- package/dist/components/forms/DialogFormBySchema.d.ts +22 -0
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -0
- package/dist/components/forms/DialogFormBySchema.js +97 -0
- package/dist/components/forms/FieldBySchema.d.ts +4 -0
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/FieldBySchema.js +80 -0
- package/dist/components/forms/ForgotPasswordForm.d.ts +11 -0
- package/dist/components/forms/ForgotPasswordForm.d.ts.map +1 -0
- package/dist/components/forms/ForgotPasswordForm.js +114 -0
- package/dist/components/forms/Form.d.ts +61 -0
- package/dist/components/forms/Form.d.ts.map +1 -0
- package/dist/components/forms/Form.js +264 -0
- package/dist/components/forms/FormActions.d.ts +20 -0
- package/dist/components/forms/FormActions.d.ts.map +1 -0
- package/dist/components/forms/FormActions.js +55 -0
- package/dist/components/forms/FormBySchema.d.ts +21 -0
- package/dist/components/forms/FormBySchema.d.ts.map +1 -0
- package/dist/components/forms/FormBySchema.js +280 -0
- package/dist/components/forms/FormWatcher.d.ts +10 -0
- package/dist/components/forms/FormWatcher.d.ts.map +1 -0
- package/dist/components/forms/FormWatcher.js +25 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +13 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +133 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +39 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +5 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +54 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +5 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +47 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +14 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +272 -0
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/FileFieldBySchema.js +144 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.js +64 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts +8 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.js +61 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts +19 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
- package/dist/components/forms/inputs/MapGeometryPicker.js +344 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.js +56 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/TextFieldBySchema.js +56 -0
- package/dist/components/forms/inputs/leafletMarker.d.ts +12 -0
- package/dist/components/forms/inputs/leafletMarker.d.ts.map +1 -0
- package/dist/components/forms/inputs/leafletMarker.js +52 -0
- package/dist/context/APIWrapper.d.ts +18 -0
- package/dist/context/APIWrapper.d.ts.map +1 -0
- package/dist/context/APIWrapper.js +593 -0
- package/dist/context/APIWrapperContext.d.ts +132 -0
- package/dist/context/APIWrapperContext.d.ts.map +1 -0
- package/dist/context/APIWrapperContext.js +63 -0
- package/dist/context/DRFReactBySchemaContext.d.ts +31 -0
- package/dist/context/DRFReactBySchemaContext.d.ts.map +1 -0
- package/dist/context/DRFReactBySchemaContext.js +20 -0
- package/dist/context/DRFReactBySchemaProvider.d.ts +5 -0
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -0
- package/dist/context/DRFReactBySchemaProvider.js +105 -0
- package/dist/context/Overlays.d.ts +5 -0
- package/dist/context/Overlays.d.ts.map +1 -0
- package/dist/context/Overlays.js +114 -0
- package/dist/context/PrivateContext.d.ts +10 -0
- package/dist/context/PrivateContext.d.ts.map +1 -0
- package/dist/context/PrivateContext.js +16 -0
- package/dist/hooks/useDeepMemo.d.ts +2 -0
- package/dist/hooks/useDeepMemo.d.ts.map +1 -0
- package/dist/hooks/useDeepMemo.js +13 -0
- package/dist/hooks/useWhyDidYouUpdate.d.ts +4 -0
- package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -0
- package/dist/hooks/useWhyDidYouUpdate.js +26 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/styles/grid.d.ts +3 -0
- package/dist/styles/grid.d.ts.map +1 -0
- package/dist/styles/grid.js +38 -0
- package/dist/styles/index.d.ts +3 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/index.js +38 -0
- package/dist/styles/layout.d.ts +23 -0
- package/dist/styles/layout.d.ts.map +1 -0
- package/dist/styles/layout.js +71 -0
- package/dist/styles/texts.d.ts +66 -0
- package/dist/styles/texts.d.ts.map +1 -0
- package/dist/styles/texts.js +73 -0
- package/dist/styles/theme.d.ts +29 -0
- package/dist/styles/theme.d.ts.map +1 -0
- package/dist/styles/theme.js +226 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +107 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +957 -0
- package/package.json +1 -1
|
@@ -0,0 +1,264 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const react_1 = __importStar(require("react"));
|
|
49
|
+
const axios_1 = __importDefault(require("axios"));
|
|
50
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
51
|
+
const yup_1 = require("@hookform/resolvers/yup");
|
|
52
|
+
const _types_1 = require("../../@types");
|
|
53
|
+
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
54
|
+
const utils_1 = require("../../utils");
|
|
55
|
+
const FormBySchema_1 = __importDefault(require("./FormBySchema"));
|
|
56
|
+
const FormActions_1 = __importDefault(require("./FormActions"));
|
|
57
|
+
const PrivateContext_1 = require("../../context/PrivateContext");
|
|
58
|
+
const useDeepMemo_1 = require("../../hooks/useDeepMemo");
|
|
59
|
+
const utils_2 = require("../DataGridBySchemaEditable/utils");
|
|
60
|
+
const FormWatcher_1 = __importDefault(require("./FormWatcher"));
|
|
61
|
+
function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle, watchValues, onWatchChange, reloadStateStamp, }) {
|
|
62
|
+
const loadingRef = (0, react_1.useRef)(false);
|
|
63
|
+
const { setFormTools } = (0, PrivateContext_1.usePrivateContext)();
|
|
64
|
+
const { pageForm, loadSinglePageData, onSubmit, formTools, resetPageForm } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
65
|
+
const formToolsRef = (0, react_1.useRef)(formTools);
|
|
66
|
+
const onSaveRef = (0, react_1.useRef)(onSave);
|
|
67
|
+
const customExitRef = (0, react_1.useRef)(customExit);
|
|
68
|
+
const methods = (0, react_hook_form_1.useForm)({
|
|
69
|
+
mode: 'onBlur',
|
|
70
|
+
// yupResolver infers against untyped base `Item`; reassert to generic `Item<T>`.
|
|
71
|
+
resolver: (pageForm === null || pageForm === void 0 ? void 0 : pageForm.validationSchema)
|
|
72
|
+
? (0, yup_1.yupResolver)(pageForm.validationSchema)
|
|
73
|
+
: undefined,
|
|
74
|
+
});
|
|
75
|
+
const { control, handleSubmit, reset, getValues, setValue, setError, formState: { errors, isDirty }, register, watch, } = methods;
|
|
76
|
+
const stableDefaults = (0, useDeepMemo_1.useDeepMemo)(defaults);
|
|
77
|
+
const stableExtraValidators = (0, useDeepMemo_1.useDeepMemo)(extraValidators);
|
|
78
|
+
const FinalFormActions = CustomFormActions || FormActions_1.default;
|
|
79
|
+
const conditionalVisible = (0, react_1.useMemo)(() => {
|
|
80
|
+
return (0, utils_1.buildConditionalVisibleBySchema)(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema);
|
|
81
|
+
}, [pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema]);
|
|
82
|
+
const watchedValues = watch(conditionalVisible.map((item) => item.source));
|
|
83
|
+
const loadData = (0, react_1.useCallback)((newId) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
loadingRef.current = true;
|
|
85
|
+
const values = yield loadSinglePageData({
|
|
86
|
+
model,
|
|
87
|
+
objId: newId,
|
|
88
|
+
defaults: stableDefaults,
|
|
89
|
+
objTitleField,
|
|
90
|
+
extraValidators: stableExtraValidators,
|
|
91
|
+
});
|
|
92
|
+
if (values && !axios_1.default.isAxiosError(values)) {
|
|
93
|
+
reset(values);
|
|
94
|
+
}
|
|
95
|
+
loadingRef.current = false;
|
|
96
|
+
}), [loadSinglePageData, model, stableDefaults, objTitleField, stableExtraValidators, reset]);
|
|
97
|
+
const genericNavigate = (0, react_1.useCallback)((path) => {
|
|
98
|
+
if (navigate) {
|
|
99
|
+
if (typeof path === 'string') {
|
|
100
|
+
navigate(path);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
navigate(path);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (typeof path === 'string') {
|
|
107
|
+
window.location.href = path;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
window.history.back();
|
|
111
|
+
}, [navigate]);
|
|
112
|
+
const exit = (0, react_1.useCallback)((id) => {
|
|
113
|
+
if (customExitRef.current) {
|
|
114
|
+
customExitRef.current(id);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (exitPath) {
|
|
118
|
+
genericNavigate((0, utils_2.buildExitPath)(exitPath, id));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// const parentPath = window.location.pathname.replace(/\/[^\/]+\/?$/, '/');
|
|
122
|
+
// genericNavigate(parentPath);
|
|
123
|
+
genericNavigate(-1);
|
|
124
|
+
}, [exitPath, genericNavigate]);
|
|
125
|
+
const localOnSubmit = (0, react_1.useCallback)((data, event) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
const currentId = objId || (0, utils_1.getTmpId)();
|
|
128
|
+
const response = yield onSubmit(model, currentId, data, event);
|
|
129
|
+
if (axios_1.default.isAxiosError(response)) {
|
|
130
|
+
// Map DRF field validation errors (e.g. raised in a serializer's
|
|
131
|
+
// `validate()`) onto the corresponding form fields so they are shown
|
|
132
|
+
// underlined with the message right below them, just like yup errors.
|
|
133
|
+
const fieldErrors = (0, utils_1.getFieldErrorsFromResponse)((_a = response.response) === null || _a === void 0 ? void 0 : _a.data, (_b = pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema) !== null && _b !== void 0 ? _b : undefined);
|
|
134
|
+
const entries = Object.entries(fieldErrors);
|
|
135
|
+
if (entries.length > 0) {
|
|
136
|
+
entries.forEach(([field, { type, message }]) => {
|
|
137
|
+
setError(field, { type, message });
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const newId = response;
|
|
143
|
+
const buttonType = (event === null || event === void 0 ? void 0 : event.nativeEvent.submitter.name) || _types_1.FormSaveActions.EXIT_ON_SAVE;
|
|
144
|
+
switch (buttonType) {
|
|
145
|
+
case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
|
|
146
|
+
loadData(undefined);
|
|
147
|
+
break;
|
|
148
|
+
case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
|
|
149
|
+
reset(Object.assign(Object.assign({}, data), { id: newId }));
|
|
150
|
+
break;
|
|
151
|
+
case _types_1.FormSaveActions.EXIT_ON_SAVE:
|
|
152
|
+
default:
|
|
153
|
+
resetPageForm();
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
// In case the user wants to do something else after saving
|
|
157
|
+
if (onSaveRef.current) {
|
|
158
|
+
onSaveRef.current(currentId, newId, buttonType);
|
|
159
|
+
}
|
|
160
|
+
const goToEdit = (id = 'novo') => {
|
|
161
|
+
const populatedEditPath = editPath
|
|
162
|
+
? (0, utils_2.buildEditPath)(editPath, id)
|
|
163
|
+
: `${window.location.pathname.replace(/\/[^\/]+\/?$/, '/')}${id}`;
|
|
164
|
+
genericNavigate(populatedEditPath);
|
|
165
|
+
};
|
|
166
|
+
switch (buttonType) {
|
|
167
|
+
case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
|
|
168
|
+
goToEdit();
|
|
169
|
+
break;
|
|
170
|
+
case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
|
|
171
|
+
goToEdit(newId);
|
|
172
|
+
break;
|
|
173
|
+
case _types_1.FormSaveActions.EXIT_ON_SAVE:
|
|
174
|
+
default:
|
|
175
|
+
exit(newId);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}), [
|
|
179
|
+
loadData,
|
|
180
|
+
model,
|
|
181
|
+
objId,
|
|
182
|
+
onSubmit,
|
|
183
|
+
pageForm,
|
|
184
|
+
reset,
|
|
185
|
+
resetPageForm,
|
|
186
|
+
exit,
|
|
187
|
+
editPath,
|
|
188
|
+
genericNavigate,
|
|
189
|
+
setError,
|
|
190
|
+
]);
|
|
191
|
+
const updateFormTools = (0, react_1.useCallback)(() => {
|
|
192
|
+
const currentFormTools = formToolsRef.current;
|
|
193
|
+
if (!currentFormTools ||
|
|
194
|
+
currentFormTools.errors !== errors ||
|
|
195
|
+
currentFormTools.isDirty !== isDirty ||
|
|
196
|
+
currentFormTools.reset !== reset ||
|
|
197
|
+
currentFormTools.getValues !== getValues ||
|
|
198
|
+
currentFormTools.setValue !== setValue) {
|
|
199
|
+
setFormTools({
|
|
200
|
+
errors,
|
|
201
|
+
reset,
|
|
202
|
+
getValues,
|
|
203
|
+
setValue,
|
|
204
|
+
isDirty,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}, [errors, getValues, isDirty, reset, setFormTools, setValue]);
|
|
208
|
+
(0, react_1.useEffect)(() => {
|
|
209
|
+
loadData(objId);
|
|
210
|
+
}, [objId, loadData, reloadStateStamp]);
|
|
211
|
+
// Why was I using this useEffect???
|
|
212
|
+
// useEffect(() => {
|
|
213
|
+
// if (!loadingRef.current && !pageForm?.model) {
|
|
214
|
+
// loadData(objId);
|
|
215
|
+
// }
|
|
216
|
+
// }, [objId, pageForm?.model, pageForm?.id, loadData]);
|
|
217
|
+
(0, react_1.useEffect)(() => {
|
|
218
|
+
updateFormTools();
|
|
219
|
+
}, [updateFormTools]);
|
|
220
|
+
(0, react_1.useEffect)(() => {
|
|
221
|
+
if (errors && Object.keys(errors).length > 0) {
|
|
222
|
+
console.log({ errors });
|
|
223
|
+
}
|
|
224
|
+
}, [errors]);
|
|
225
|
+
(0, react_1.useEffect)(() => {
|
|
226
|
+
const handleBeforeUnload = (event) => {
|
|
227
|
+
if (isDirty) {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
event.returnValue = '';
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
234
|
+
return () => {
|
|
235
|
+
window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
236
|
+
};
|
|
237
|
+
}, [isDirty]);
|
|
238
|
+
(0, react_1.useEffect)(() => {
|
|
239
|
+
formToolsRef.current = formTools;
|
|
240
|
+
}, [formTools]);
|
|
241
|
+
(0, react_1.useEffect)(() => {
|
|
242
|
+
onSaveRef.current = onSave;
|
|
243
|
+
}, [onSave]);
|
|
244
|
+
(0, react_1.useEffect)(() => {
|
|
245
|
+
customExitRef.current = customExit;
|
|
246
|
+
}, [customExit]);
|
|
247
|
+
(0, react_1.useEffect)(() => {
|
|
248
|
+
return () => {
|
|
249
|
+
resetPageForm();
|
|
250
|
+
};
|
|
251
|
+
}, [resetPageForm]);
|
|
252
|
+
if (!(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema) || (pageForm === null || pageForm === void 0 ? void 0 : pageForm.model) !== model) {
|
|
253
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
254
|
+
}
|
|
255
|
+
return (react_1.default.createElement(react_hook_form_1.FormProvider, Object.assign({}, methods),
|
|
256
|
+
react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
|
|
257
|
+
react_1.default.createElement(FinalFormActions, { formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }),
|
|
258
|
+
react_1.default.createElement(FormBySchema_1.default, { fieldsLayout: fieldsLayout, hiddenFields: hiddenFields, control: control, register: register, errors: errors, schema: pageForm.schema, getValues: getValues, setValue: setValue, multiline: multiline, fieldKey: fieldKey, labelKey: labelKey, optionsAC: optionsAC, setOptionsAC: setOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, customFieldFormLayouts: customFieldFormLayouts, fieldsProps: fieldsProps, isolatedGetAutoComplete: isolatedGetAutoComplete, relatedEditable: relatedEditable, autoFocusField: autoFocusField, elevation: elevation, sxRow: sxRow, sxRowMultiple: sxRowMultiple, sxSection: sxSection, sxSectionTitle: sxSectionTitle, conditionalVisible: conditionalVisible, watchedValues: watchedValues }),
|
|
259
|
+
watchValues && onWatchChange && (react_1.default.createElement(FormWatcher_1.default, {
|
|
260
|
+
// FormWatcher only uses useWatch; align control to Control<GenericValue>.
|
|
261
|
+
control: control, watch: watchValues, onChange: onWatchChange })),
|
|
262
|
+
react_1.default.createElement(FinalFormActions, { bottom: true, formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }))));
|
|
263
|
+
}
|
|
264
|
+
exports.default = Form;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Id, TField } from '../../@types';
|
|
3
|
+
export type FormActionsProps = {
|
|
4
|
+
formDisabled?: boolean;
|
|
5
|
+
model: string;
|
|
6
|
+
objId?: Id;
|
|
7
|
+
onCancel?: React.MouseEventHandler<HTMLButtonElement>;
|
|
8
|
+
onDelete?: (removedId: Id) => void;
|
|
9
|
+
exit: (id?: Id) => void;
|
|
10
|
+
bottom?: boolean;
|
|
11
|
+
saveAndContinue?: boolean;
|
|
12
|
+
title?: string;
|
|
13
|
+
labelSave?: string;
|
|
14
|
+
labelSaveAndContinue?: string;
|
|
15
|
+
labelSaveAndCreateNew?: string;
|
|
16
|
+
labelCancel?: string;
|
|
17
|
+
labelRemove?: string;
|
|
18
|
+
};
|
|
19
|
+
export default function FormActions<T extends TField = void>({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
|
|
20
|
+
//# sourceMappingURL=FormActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormActions.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAmB,EAAE,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC3D,YAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,eAAe,EACf,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,GACZ,EAAE,gBAAgB,qBAiHlB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = FormActions;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
9
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
10
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
11
|
+
const styles_1 = require("@mui/material/styles");
|
|
12
|
+
const styles_2 = require("../../styles");
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const _types_1 = require("../../@types");
|
|
15
|
+
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
16
|
+
const texts_1 = require("../../styles/texts");
|
|
17
|
+
function FormActions({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }) {
|
|
18
|
+
const { onDeleteModel, isMobile } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
19
|
+
const texts = (0, texts_1.getThemeTexts)((0, styles_1.useTheme)());
|
|
20
|
+
const formTexts = texts.forms;
|
|
21
|
+
if (isMobile && !bottom) {
|
|
22
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
23
|
+
}
|
|
24
|
+
const finalSx = Object.assign(Object.assign({}, styles_2.Layout.flexRowGrow), (bottom && !(0, utils_1.isTmpId)(objId)
|
|
25
|
+
? {
|
|
26
|
+
mb: 5,
|
|
27
|
+
pb: 2,
|
|
28
|
+
borderBottom: 'solid 1px #aaa',
|
|
29
|
+
}
|
|
30
|
+
: {}));
|
|
31
|
+
const handleDelete = () => {
|
|
32
|
+
if (objId && !(0, utils_1.isTmpId)(objId)) {
|
|
33
|
+
onDeleteModel(model, objId);
|
|
34
|
+
if (onDelete) {
|
|
35
|
+
onDelete(objId);
|
|
36
|
+
}
|
|
37
|
+
exit(objId);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handleCancel = (event) => {
|
|
41
|
+
if (onCancel) {
|
|
42
|
+
onCancel(event);
|
|
43
|
+
}
|
|
44
|
+
exit(objId);
|
|
45
|
+
};
|
|
46
|
+
return (react_1.default.createElement(Box_1.default, { sx: finalSx },
|
|
47
|
+
bottom ? (react_1.default.createElement(Button_1.default, { variant: "contained", type: "button", color: "error", size: "small", disabled: (0, utils_1.isTmpId)(objId) || !onDeleteModel, onClick: handleDelete }, labelRemove || formTexts.remove)) : title ? (react_1.default.createElement(Typography_1.default, { variant: "h5" }, title)) : (react_1.default.createElement(Box_1.default, null)),
|
|
48
|
+
isMobile ? (react_1.default.createElement(Box_1.default, { sx: styles_2.Layout.flexRow },
|
|
49
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || formTexts.save))) : (react_1.default.createElement(Box_1.default, { sx: styles_2.Layout.flexRow },
|
|
50
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: handleCancel }, labelCancel || formTexts.cancel),
|
|
51
|
+
!isMobile && saveAndContinue && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
52
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CREATE_NEW, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndCreateNew || formTexts.saveAndCreateNew),
|
|
53
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CONTINUE, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndContinue || formTexts.saveAndContinue))),
|
|
54
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || formTexts.save)))));
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AxiosError } from 'axios';
|
|
3
|
+
import { UseFormRegister } from 'react-hook-form';
|
|
4
|
+
import { AutocompleteItem, ConditionalVisible, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldBySchemaProps, FieldsProps, FormFieldLayout, GenericValue, Item, OptionsAC, FieldKey, FieldList, TField } from '../../@types';
|
|
5
|
+
type FormBySchemaProps<T extends TField = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
|
|
6
|
+
fieldsLayout?: FormFieldLayout<T>[];
|
|
7
|
+
customFieldFormLayouts?: CustomFormFieldLayouts<T>;
|
|
8
|
+
hiddenFields?: FieldList<T>;
|
|
9
|
+
register?: UseFormRegister<Item<T>>;
|
|
10
|
+
setOptionsAC?: (x: OptionsAC<T>) => void;
|
|
11
|
+
isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
|
|
12
|
+
fieldsProps?: FieldsProps<T>;
|
|
13
|
+
relatedEditable?: boolean;
|
|
14
|
+
autoFocusField?: FieldKey<T>;
|
|
15
|
+
elevation?: number;
|
|
16
|
+
conditionalVisible?: ConditionalVisible[];
|
|
17
|
+
watchedValues?: GenericValue[];
|
|
18
|
+
};
|
|
19
|
+
export default function FormBySchema<T extends TField = void>({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, sxRow, sxRowMultiple, sxSection, sxSectionTitle, }: FormBySchemaProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=FormBySchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;AAQtB,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAEtF,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACzC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,GAAG,UAAU,CAAC,CAAC;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC5D,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAgC,EAChC,KAAK,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAgB,EAEhB,YAAY,EAAE,mBAAmB,EACjC,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EAEb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAKT,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,GAKf,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACrB,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBA8WF"}
|
|
@@ -0,0 +1,280 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.default = FormBySchema;
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
|
+
const axios_1 = __importDefault(require("axios"));
|
|
51
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
52
|
+
const Card_1 = __importDefault(require("@mui/material/Card"));
|
|
53
|
+
const CardHeader_1 = __importDefault(require("@mui/material/CardHeader"));
|
|
54
|
+
const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
|
|
55
|
+
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
56
|
+
const styles_1 = require("../../styles");
|
|
57
|
+
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
58
|
+
const utils_1 = require("../../utils");
|
|
59
|
+
const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
|
|
60
|
+
const api_1 = require("../../api");
|
|
61
|
+
function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation,
|
|
62
|
+
// sx,
|
|
63
|
+
// sxField,
|
|
64
|
+
// sxLabel,
|
|
65
|
+
sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
66
|
+
// sxValue,
|
|
67
|
+
// sxValueList,
|
|
68
|
+
// sxValueListItem,
|
|
69
|
+
// sxValueListItemText,
|
|
70
|
+
}) {
|
|
71
|
+
var _a;
|
|
72
|
+
const { getAutoComplete: defaulGetAutoComplete, onEditModel: defaultOnEditModel, isMobile, } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
73
|
+
const getAutoComplete = (0, react_1.useMemo)(() => isolatedGetAutoComplete || defaulGetAutoComplete, [defaulGetAutoComplete, isolatedGetAutoComplete]);
|
|
74
|
+
const onEditModel = (0, react_1.useMemo)(() => (relatedEditable === false ? undefined : customOnEditModel || defaultOnEditModel), [customOnEditModel, defaultOnEditModel, relatedEditable]);
|
|
75
|
+
const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)();
|
|
76
|
+
const defaultSx = { mr: 0 };
|
|
77
|
+
const { fieldsLayout, optionsACModels } = (0, react_1.useMemo)(() => {
|
|
78
|
+
if (!schema) {
|
|
79
|
+
return { fieldsLayout: undefined, optionsACModels: [] };
|
|
80
|
+
}
|
|
81
|
+
const newOptionsACModels = [];
|
|
82
|
+
if (fieldsLayoutInitial && fieldsLayoutInitial.length > 0) {
|
|
83
|
+
const mobileFieldsLayout = [];
|
|
84
|
+
for (const section of fieldsLayoutInitial) {
|
|
85
|
+
if (!section.rows) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const mobileSection = {
|
|
89
|
+
title: section.title,
|
|
90
|
+
rows: [],
|
|
91
|
+
};
|
|
92
|
+
for (const row of section.rows) {
|
|
93
|
+
if (typeof row === 'string') {
|
|
94
|
+
const field = row;
|
|
95
|
+
const fieldSchema = schema[field];
|
|
96
|
+
if (!fieldSchema) {
|
|
97
|
+
console.log(`there is no schema for field ${field}!`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (['field', 'nested object'].includes(fieldSchema.type) &&
|
|
101
|
+
!newOptionsACModels.includes(field)) {
|
|
102
|
+
newOptionsACModels.push(field);
|
|
103
|
+
}
|
|
104
|
+
if (isMobile) {
|
|
105
|
+
mobileSection.rows.push(field);
|
|
106
|
+
}
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(row)) {
|
|
110
|
+
for (const field of row) {
|
|
111
|
+
if (typeof field === 'string' && !(field in schema)) {
|
|
112
|
+
console.log(`there is no schema for field ${field}!`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (typeof field === 'string' &&
|
|
116
|
+
['field', 'nested object'].includes(schema[field].type) &&
|
|
117
|
+
!newOptionsACModels.includes(field)) {
|
|
118
|
+
newOptionsACModels.push(field);
|
|
119
|
+
}
|
|
120
|
+
if (isMobile && typeof field === 'string') {
|
|
121
|
+
mobileSection.rows.push(field);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (newOptionsACModels.includes(row.key)) {
|
|
127
|
+
newOptionsACModels.push(row.key);
|
|
128
|
+
}
|
|
129
|
+
if (isMobile) {
|
|
130
|
+
mobileSection.rows.push(row.key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (isMobile) {
|
|
134
|
+
mobileFieldsLayout.push(mobileSection);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
fieldsLayout: isMobile ? mobileFieldsLayout : fieldsLayoutInitial,
|
|
139
|
+
optionsACModels: newOptionsACModels,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const rows = [];
|
|
143
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
144
|
+
if (field && ['field', 'nested object'].includes(field.type)) {
|
|
145
|
+
rows.push(key);
|
|
146
|
+
if (!newOptionsACModels.includes(key)) {
|
|
147
|
+
newOptionsACModels.push(key);
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!(field === null || field === void 0 ? void 0 : field.read_only)) {
|
|
152
|
+
rows.push(key);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { fieldsLayout: [{ rows }], optionsACModels: newOptionsACModels };
|
|
156
|
+
}, [schema, fieldsLayoutInitial, isMobile]);
|
|
157
|
+
(0, react_1.useEffect)(() => {
|
|
158
|
+
const populateOptionsACAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const promises = [];
|
|
160
|
+
const fieldsToLoad = [];
|
|
161
|
+
optionsACModels.map((field) => {
|
|
162
|
+
if (!optionsAC || !(field in optionsAC)) {
|
|
163
|
+
fieldsToLoad.push(field);
|
|
164
|
+
promises.push(getAutoComplete(field));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
const newOptionsAC = {};
|
|
168
|
+
const results = yield Promise.all(promises);
|
|
169
|
+
results.map((result, index) => {
|
|
170
|
+
if (!axios_1.default.isAxiosError(result)) {
|
|
171
|
+
newOptionsAC[fieldsToLoad[index]] = result;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
if (setOptionsAC) {
|
|
175
|
+
setOptionsAC(newOptionsAC);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
setLocalOptionsAC(newOptionsAC);
|
|
179
|
+
});
|
|
180
|
+
populateOptionsACAsync();
|
|
181
|
+
}, [optionsACModels, setOptionsAC]);
|
|
182
|
+
const preparedHiddenFields = (0, react_1.useMemo)(() => {
|
|
183
|
+
const values = {};
|
|
184
|
+
if (!getValues || !hiddenFields) {
|
|
185
|
+
return values;
|
|
186
|
+
}
|
|
187
|
+
for (const [key, value] of Object.entries(getValues())) {
|
|
188
|
+
if (hiddenFields.includes(key)) {
|
|
189
|
+
values[key] = value;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return (0, api_1.prepareDataBySchema)({ data: values, schema }).data;
|
|
193
|
+
}, [getValues, hiddenFields, schema]);
|
|
194
|
+
if (!fieldsLayout ||
|
|
195
|
+
fieldsLayout.length === 0 ||
|
|
196
|
+
(setOptionsAC && !optionsAC) ||
|
|
197
|
+
(!setOptionsAC && !localOptionsAC)) {
|
|
198
|
+
return (react_1.default.createElement(Card_1.default, { sx: sxSection ? Object.assign(Object.assign({}, styles_1.Layout.formCard), sxSection) : styles_1.Layout.formCard, elevation: elevation },
|
|
199
|
+
react_1.default.createElement(CardContent_1.default, null,
|
|
200
|
+
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBoxWhite },
|
|
201
|
+
react_1.default.createElement(CircularProgress_1.default, null)))));
|
|
202
|
+
}
|
|
203
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
204
|
+
register &&
|
|
205
|
+
((_a = Object.entries(preparedHiddenFields)) === null || _a === void 0 ? void 0 : _a.map(([hiddenField, preparedValue]) => {
|
|
206
|
+
return (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: preparedValue, key: hiddenField })));
|
|
207
|
+
})),
|
|
208
|
+
fieldsLayout.map((section, sectionIndex) => {
|
|
209
|
+
return (react_1.default.createElement(Card_1.default, { sx: sxSection ? Object.assign(Object.assign({}, styles_1.Layout.formCard), sxSection) : styles_1.Layout.formCard, key: `section_${sectionIndex}`, elevation: elevation },
|
|
210
|
+
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: sxSectionTitle }),
|
|
211
|
+
react_1.default.createElement(CardContent_1.default, null,
|
|
212
|
+
section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
|
|
213
|
+
section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
|
|
214
|
+
if (typeof row === 'string') {
|
|
215
|
+
if (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(row)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const field = row;
|
|
219
|
+
const fieldProps = fieldsProps && field in fieldsProps
|
|
220
|
+
? fieldsProps[field]
|
|
221
|
+
: {};
|
|
222
|
+
if (fieldProps) {
|
|
223
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
224
|
+
}
|
|
225
|
+
const isVisible = (0, utils_1.showConditionalVisibleField)(field, conditionalVisible, watchedValues);
|
|
226
|
+
if (!isVisible) {
|
|
227
|
+
return react_1.default.createElement(Box_1.default, { key: field, sx: sxRow });
|
|
228
|
+
}
|
|
229
|
+
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
230
|
+
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,
|
|
231
|
+
// optionsAC={setOptionsAC ? optionsAC : localOptionsAC}
|
|
232
|
+
optionsAC: optionsAC && field in optionsAC
|
|
233
|
+
? optionsAC
|
|
234
|
+
: localOptionsAC,
|
|
235
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>>
|
|
236
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>> | undefined
|
|
237
|
+
optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, fieldsLayout: customFieldFormLayouts && field in customFieldFormLayouts
|
|
238
|
+
? customFieldFormLayouts[field]
|
|
239
|
+
: undefined, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field || (sectionIndex === 0 && rowIndex === 0) }, fieldProps))));
|
|
240
|
+
}
|
|
241
|
+
if (Array.isArray(row)) {
|
|
242
|
+
return (react_1.default.createElement(Box_1.default, { sx: sxRowMultiple
|
|
243
|
+
? Object.assign(Object.assign({}, styles_1.Layout.inLineForm), { sxRowMultiple })
|
|
244
|
+
: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
|
|
245
|
+
react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => {
|
|
246
|
+
if (typeof field === 'string' && (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(field))) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
const mr = i + 1 === j.length ? 0 : 2;
|
|
250
|
+
const key = typeof field === 'string' ? field : field.key;
|
|
251
|
+
const fieldProps = fieldsProps && key in fieldsProps
|
|
252
|
+
? fieldsProps[key]
|
|
253
|
+
: {};
|
|
254
|
+
if (fieldProps) {
|
|
255
|
+
fieldProps.sx =
|
|
256
|
+
'sx' in fieldProps
|
|
257
|
+
? Object.assign(Object.assign({}, fieldProps.sx), { mr }) : {
|
|
258
|
+
mr,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const isVisible = (0, utils_1.showConditionalVisibleField)(key, conditionalVisible, watchedValues);
|
|
262
|
+
if (!isVisible) {
|
|
263
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }));
|
|
264
|
+
}
|
|
265
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }, typeof field === 'string' ? (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 && field in optionsAC
|
|
266
|
+
? optionsAC
|
|
267
|
+
: localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field ||
|
|
268
|
+
(sectionIndex === 0 && rowIndex === 0 && i === 0) }, fieldProps))) : (react_1.default.createElement(field.CustomElement, Object.assign({}, fieldProps)))));
|
|
269
|
+
}))));
|
|
270
|
+
}
|
|
271
|
+
const fieldProps = fieldsProps && row.key in fieldsProps
|
|
272
|
+
? fieldsProps[row.key]
|
|
273
|
+
: {};
|
|
274
|
+
if (fieldProps) {
|
|
275
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
276
|
+
}
|
|
277
|
+
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `customElement_row_${rowIndex}` }, fieldProps)));
|
|
278
|
+
}))))));
|
|
279
|
+
})));
|
|
280
|
+
}
|