drf-react-by-schema 0.24.5 → 0.25.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.
- package/dist/@types/index.d.ts +151 -91
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts +22 -17
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +612 -572
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +19 -19
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +7 -7
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +12 -12
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +8 -8
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +5 -3
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +5 -5
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +13 -13
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +154 -155
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +11 -12
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +149 -148
- package/dist/components/DataGridBySchemaEditable.d.ts +17 -17
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable.js +44 -24
- package/dist/components/DataTotals.d.ts.map +1 -1
- package/dist/components/DataTotalsServer.d.ts +1 -1
- package/dist/components/DataTotalsServer.d.ts.map +1 -1
- package/dist/components/DataTotalsServer.js +7 -10
- package/dist/components/GenericModelList.d.ts +17 -18
- package/dist/components/GenericModelList.d.ts.map +1 -1
- package/dist/components/GenericModelList.js +2 -1
- package/dist/components/GenericRelatedModelList.d.ts +16 -17
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelList.js +2 -2
- package/dist/components/GenericRelatedModelListTable.d.ts +15 -15
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelListTable.js +3 -2
- package/dist/components/details/DetailBySchema.d.ts +2 -2
- package/dist/components/details/DetailBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.js +30 -21
- package/dist/components/forms/DialogFormBySchema.d.ts +9 -9
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -1
- package/dist/components/forms/DialogFormBySchema.js +1 -1
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/FieldBySchema.js +4 -4
- package/dist/components/forms/Form.d.ts +17 -16
- package/dist/components/forms/Form.d.ts.map +1 -1
- package/dist/components/forms/Form.js +6 -4
- package/dist/components/forms/FormActions.d.ts +2 -2
- package/dist/components/forms/FormActions.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.d.ts +11 -11
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +45 -22
- package/dist/components/forms/FormWatcher.d.ts +7 -5
- package/dist/components/forms/FormWatcher.d.ts.map +1 -1
- package/dist/components/forms/FormWatcher.js +9 -5
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +2 -1
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +2 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +12 -2
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +6 -5
- package/dist/components/forms/inputs/FileFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/PatternFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/TextFieldBySchema.js +2 -1
- package/dist/context/APIWrapper.d.ts +7 -6
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +22 -18
- package/dist/context/APIWrapperContext.d.ts +51 -51
- package/dist/context/APIWrapperContext.d.ts.map +1 -1
- package/dist/context/APIWrapperContext.js +16 -18
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -1
- package/dist/context/PrivateContext.d.ts +6 -5
- package/dist/context/PrivateContext.d.ts.map +1 -1
- package/dist/utils/utils.d.ts +14 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +16 -14
- package/package.json +4 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts +0 -18
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts.map +0 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.js +0 -43
- package/dist/components/DialogJSONSchemaForm.d.ts +0 -13
- package/dist/components/DialogJSONSchemaForm.js +0 -20
- package/dist/components/FilteredButton.d.ts +0 -2
- package/dist/components/FilteredButton.js +0 -23
- package/dist/components/FilteredGridActionsCellItem.d.ts +0 -2
- package/dist/components/FilteredGridActionsCellItem.js +0 -29
- package/dist/components/FormButtons.d.ts +0 -23
- package/dist/components/FormButtons.d.ts.map +0 -1
- package/dist/components/FormButtons.js +0 -38
- package/dist/components/forms/inputs/PatternBySchema.d.ts +0 -4
- package/dist/components/forms/inputs/PatternBySchema.d.ts.map +0 -1
- package/dist/components/forms/inputs/PatternBySchema.js +0 -45
- package/dist/context/Form.d.ts +0 -21
- package/dist/context/Form.js +0 -95
- package/dist/context/FormContext.d.ts +0 -71
- package/dist/context/FormContext.js +0 -8
- package/dist/utils.d.ts +0 -60
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -726
|
@@ -45,7 +45,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.default = Form;
|
|
49
48
|
const react_1 = __importStar(require("react"));
|
|
50
49
|
const axios_1 = __importDefault(require("axios"));
|
|
51
50
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -58,7 +57,8 @@ const FormActions_1 = __importDefault(require("./FormActions"));
|
|
|
58
57
|
const PrivateContext_1 = require("../../context/PrivateContext");
|
|
59
58
|
const useDeepMemo_1 = require("../../hooks/useDeepMemo");
|
|
60
59
|
const utils_2 = require("../DataGridBySchemaEditable/utils");
|
|
61
|
-
|
|
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, }) {
|
|
62
62
|
const { setFormTools } = (0, PrivateContext_1.usePrivateContext)();
|
|
63
63
|
const { pageForm, loadSinglePageData, onSubmit, formTools, resetPageForm } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
64
64
|
const formToolsRef = (0, react_1.useRef)(formTools);
|
|
@@ -73,12 +73,13 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
73
73
|
const stableExtraValidators = (0, useDeepMemo_1.useDeepMemo)(extraValidators);
|
|
74
74
|
const FinalFormActions = CustomFormActions || FormActions_1.default;
|
|
75
75
|
const conditionalVisible = (0, react_1.useMemo)(() => {
|
|
76
|
+
var _a;
|
|
76
77
|
const fields = [];
|
|
77
78
|
if (!(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema)) {
|
|
78
79
|
return fields;
|
|
79
80
|
}
|
|
80
81
|
for (const fieldKey of Object.keys(pageForm.schema)) {
|
|
81
|
-
const conditionalVisible = pageForm.schema[fieldKey].conditional_visible;
|
|
82
|
+
const conditionalVisible = (_a = pageForm.schema[fieldKey]) === null || _a === void 0 ? void 0 : _a.conditional_visible;
|
|
82
83
|
if (!conditionalVisible || conditionalVisible.length === 0) {
|
|
83
84
|
continue;
|
|
84
85
|
}
|
|
@@ -237,6 +238,7 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
237
238
|
react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
|
|
238
239
|
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 }),
|
|
239
240
|
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 }),
|
|
240
|
-
|
|
241
|
+
watchValues && onWatchChange && (react_1.default.createElement(FormWatcher_1.default, { control: control, watch: watchValues, onChange: onWatchChange })),
|
|
241
242
|
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 }))));
|
|
242
243
|
}
|
|
244
|
+
exports.default = Form;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Id } from '../../@types';
|
|
2
|
+
import { Id, TField } from '../../@types';
|
|
3
3
|
export type FormActionsProps = {
|
|
4
4
|
formDisabled?: boolean;
|
|
5
5
|
model: string;
|
|
@@ -16,5 +16,5 @@ export type FormActionsProps = {
|
|
|
16
16
|
labelCancel?: string;
|
|
17
17
|
labelRemove?: string;
|
|
18
18
|
};
|
|
19
|
-
export default function FormActions({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
|
|
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
20
|
//# sourceMappingURL=FormActions.d.ts.map
|
|
@@ -1 +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,cAAc,CAAC;
|
|
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;AAG3D,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,MAAM,IAAI,CAAC;IACjB,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,qBA+GlB"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
3
|
import { UseFormRegister } from 'react-hook-form';
|
|
4
|
-
import { AutocompleteItem,
|
|
5
|
-
|
|
6
|
-
fieldsLayout?: FormFieldLayout[];
|
|
7
|
-
customFieldFormLayouts?:
|
|
8
|
-
hiddenFields?:
|
|
9
|
-
register?: UseFormRegister<Item
|
|
10
|
-
setOptionsAC?: (x: OptionsAC) => void;
|
|
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
11
|
isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
|
|
12
|
-
fieldsProps?:
|
|
12
|
+
fieldsProps?: FieldsProps<T>;
|
|
13
13
|
relatedEditable?: boolean;
|
|
14
|
-
autoFocusField?:
|
|
14
|
+
autoFocusField?: FieldKey<T>;
|
|
15
15
|
elevation?: number;
|
|
16
16
|
conditionalVisible?: ConditionalVisible[];
|
|
17
17
|
watchedValues?: GenericValue[];
|
|
18
|
-
}
|
|
19
|
-
export default function FormBySchema({ 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 & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
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
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=FormBySchema.d.ts.map
|
|
@@ -1 +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,
|
|
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;AAOtB,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,qBAkWF"}
|
|
@@ -57,7 +57,7 @@ const styles_1 = require("../../styles");
|
|
|
57
57
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
58
58
|
const utils_1 = require("../../utils");
|
|
59
59
|
const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
|
|
60
|
-
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
|
|
60
|
+
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,
|
|
61
61
|
// sx,
|
|
62
62
|
// sxField,
|
|
63
63
|
// sxLabel,
|
|
@@ -90,11 +90,12 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
90
90
|
for (const row of section.rows) {
|
|
91
91
|
if (typeof row === 'string') {
|
|
92
92
|
const field = row;
|
|
93
|
-
|
|
93
|
+
const fieldSchema = schema[field];
|
|
94
|
+
if (!fieldSchema) {
|
|
94
95
|
console.log(`there is no schema for field ${field}!`);
|
|
95
96
|
continue;
|
|
96
97
|
}
|
|
97
|
-
if (['field', 'nested object'].includes(
|
|
98
|
+
if (['field', 'nested object'].includes(fieldSchema.type) &&
|
|
98
99
|
!newOptionsACModels.includes(field)) {
|
|
99
100
|
newOptionsACModels.push(field);
|
|
100
101
|
}
|
|
@@ -105,7 +106,7 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
105
106
|
}
|
|
106
107
|
if (Array.isArray(row)) {
|
|
107
108
|
for (const field of row) {
|
|
108
|
-
if (typeof field === 'string' && !schema
|
|
109
|
+
if (typeof field === 'string' && !(field in schema)) {
|
|
109
110
|
console.log(`there is no schema for field ${field}!`);
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
@@ -138,14 +139,14 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
138
139
|
}
|
|
139
140
|
const rows = [];
|
|
140
141
|
for (const [key, field] of Object.entries(schema)) {
|
|
141
|
-
if (['field', 'nested object'].includes(field.type)) {
|
|
142
|
+
if (field && ['field', 'nested object'].includes(field.type)) {
|
|
142
143
|
rows.push(key);
|
|
143
144
|
if (!newOptionsACModels.includes(key)) {
|
|
144
145
|
newOptionsACModels.push(key);
|
|
145
146
|
}
|
|
146
147
|
continue;
|
|
147
148
|
}
|
|
148
|
-
if (!field.read_only) {
|
|
149
|
+
if (!(field === null || field === void 0 ? void 0 : field.read_only)) {
|
|
149
150
|
rows.push(key);
|
|
150
151
|
}
|
|
151
152
|
}
|
|
@@ -187,7 +188,10 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
187
188
|
}
|
|
188
189
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
189
190
|
register &&
|
|
190
|
-
hiddenFields
|
|
191
|
+
(hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.map((hiddenField) => {
|
|
192
|
+
const typedHiddenField = hiddenField;
|
|
193
|
+
return (react_1.default.createElement("input", Object.assign({ hidden: true }, register(typedHiddenField), { value: getValues ? getValues(typedHiddenField) : undefined, key: hiddenField })));
|
|
194
|
+
})),
|
|
191
195
|
fieldsLayout.map((section, sectionIndex) => {
|
|
192
196
|
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 },
|
|
193
197
|
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: sxSectionTitle }),
|
|
@@ -195,12 +199,16 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
195
199
|
section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
|
|
196
200
|
section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
|
|
197
201
|
if (typeof row === 'string') {
|
|
198
|
-
if (hiddenFields.includes(row)) {
|
|
202
|
+
if (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(row)) {
|
|
199
203
|
return null;
|
|
200
204
|
}
|
|
201
205
|
const field = row;
|
|
202
|
-
const fieldProps = fieldsProps && field in fieldsProps
|
|
203
|
-
|
|
206
|
+
const fieldProps = fieldsProps && field in fieldsProps
|
|
207
|
+
? fieldsProps[field]
|
|
208
|
+
: {};
|
|
209
|
+
if (fieldProps) {
|
|
210
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
211
|
+
}
|
|
204
212
|
const isVisible = (0, utils_1.showConditionalVisibleField)(field, conditionalVisible, watchedValues);
|
|
205
213
|
if (!isVisible) {
|
|
206
214
|
return react_1.default.createElement(Box_1.default, { key: field, sx: sxRow });
|
|
@@ -208,7 +216,12 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
208
216
|
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
209
217
|
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,
|
|
210
218
|
// optionsAC={setOptionsAC ? optionsAC : localOptionsAC}
|
|
211
|
-
optionsAC: optionsAC && field in optionsAC
|
|
219
|
+
optionsAC: optionsAC && field in optionsAC
|
|
220
|
+
? optionsAC
|
|
221
|
+
: localOptionsAC,
|
|
222
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>>
|
|
223
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>> | undefined
|
|
224
|
+
optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, fieldsLayout: customFieldFormLayouts && field in customFieldFormLayouts
|
|
212
225
|
? customFieldFormLayouts[field]
|
|
213
226
|
: undefined, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field || (sectionIndex === 0 && rowIndex === 0) }, fieldProps))));
|
|
214
227
|
}
|
|
@@ -217,27 +230,37 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
217
230
|
? Object.assign(Object.assign({}, styles_1.Layout.inLineForm), { sxRowMultiple })
|
|
218
231
|
: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
|
|
219
232
|
react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => {
|
|
220
|
-
if (typeof field === 'string' && hiddenFields.includes(field)) {
|
|
233
|
+
if (typeof field === 'string' && (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(field))) {
|
|
221
234
|
return null;
|
|
222
235
|
}
|
|
223
236
|
const mr = i + 1 === j.length ? 0 : 2;
|
|
224
237
|
const key = typeof field === 'string' ? field : field.key;
|
|
225
|
-
const fieldProps = fieldsProps && key in fieldsProps
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
238
|
+
const fieldProps = fieldsProps && key in fieldsProps
|
|
239
|
+
? fieldsProps[key]
|
|
240
|
+
: {};
|
|
241
|
+
if (fieldProps) {
|
|
242
|
+
fieldProps.sx =
|
|
243
|
+
'sx' in fieldProps
|
|
244
|
+
? Object.assign(Object.assign({}, fieldProps.sx), { mr }) : {
|
|
245
|
+
mr,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const isVisible = (0, utils_1.showConditionalVisibleField)(key, conditionalVisible, watchedValues);
|
|
232
249
|
if (!isVisible) {
|
|
233
250
|
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }));
|
|
234
251
|
}
|
|
235
|
-
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
|
|
252
|
+
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
|
|
253
|
+
? optionsAC
|
|
254
|
+
: localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field ||
|
|
236
255
|
(sectionIndex === 0 && rowIndex === 0 && i === 0) }, fieldProps))) : (react_1.default.createElement(field.CustomElement, Object.assign({}, fieldProps)))));
|
|
237
256
|
}))));
|
|
238
257
|
}
|
|
239
|
-
const fieldProps = fieldsProps && row.key in fieldsProps
|
|
240
|
-
|
|
258
|
+
const fieldProps = fieldsProps && row.key in fieldsProps
|
|
259
|
+
? fieldsProps[row.key]
|
|
260
|
+
: {};
|
|
261
|
+
if (fieldProps) {
|
|
262
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
263
|
+
}
|
|
241
264
|
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `customElement_row_${rowIndex}` }, fieldProps)));
|
|
242
265
|
}))))));
|
|
243
266
|
})));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Control } from 'react-hook-form';
|
|
2
|
+
import { FieldList, FormWatchObject, GenericValue, TField } from '../../@types';
|
|
3
|
+
export interface FormWatcherProps<T extends TField = void> {
|
|
4
|
+
control: Control<GenericValue>;
|
|
5
|
+
watch: FieldList<T>;
|
|
6
|
+
onChange: (values: FormWatchObject<T>) => void;
|
|
5
7
|
}
|
|
6
|
-
declare
|
|
8
|
+
declare function FormWatcher<T extends TField = void>({ control, watch, onChange }: FormWatcherProps<T>): null;
|
|
7
9
|
export default FormWatcher;
|
|
8
10
|
//# sourceMappingURL=FormWatcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormWatcher.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormWatcher.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FormWatcher.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormWatcher.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAQ,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtF,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACvD,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAChD;AAGD,iBAAS,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC,QAqB9F;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const react_hook_form_1 = require("react-hook-form");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// Ensure K is constrained to the same type as the prop
|
|
7
|
+
function FormWatcher({ control, watch, onChange }) {
|
|
8
8
|
const values = (0, react_hook_form_1.useWatch)({
|
|
9
9
|
control,
|
|
10
10
|
name: watch,
|
|
@@ -13,9 +13,13 @@ const FormWatcher = ({ watch, onChange }) => {
|
|
|
13
13
|
(0, react_1.useEffect)(() => {
|
|
14
14
|
if (!(0, utils_1.deepEqual)(values, previousValues.current)) {
|
|
15
15
|
previousValues.current = values;
|
|
16
|
-
|
|
16
|
+
const valuesObject = watch.reduce((acc, key, index) => {
|
|
17
|
+
acc[key] = values[index];
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
onChange(valuesObject);
|
|
17
21
|
}
|
|
18
|
-
}, [values, onChange]);
|
|
22
|
+
}, [values, watch, onChange]);
|
|
19
23
|
return null;
|
|
20
|
-
}
|
|
24
|
+
}
|
|
21
25
|
exports.default = FormWatcher;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,EAA8B,MAAM,iBAAiB,CAAC;AA8DjF,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,EAChD,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,WAAkB,EAClB,cAAwB,EACxB,OAAO,EAAE,cAAc,EACvB,YAAoB,EACpB,EAAc,EACd,aAAa,EACb,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,CAAC,EACf,GAAG,KAAK,EACT,EAAE,kBAAkB,iCA8DpB"}
|
|
@@ -13,6 +13,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
13
13
|
require("dayjs/locale/pt-br");
|
|
14
14
|
const utils_1 = require("../../../utils");
|
|
15
15
|
function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, index, sx = { mr: 2, mt: 2 }, autoFocus, disabled, }) {
|
|
16
|
+
var _a;
|
|
16
17
|
if (!(name in schema)) {
|
|
17
18
|
console.error(`DesktopDatePickerBySchema: could not find schema for ${name}! Not rendering`);
|
|
18
19
|
return;
|
|
@@ -37,7 +38,7 @@ function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, in
|
|
|
37
38
|
})
|
|
38
39
|
: {
|
|
39
40
|
error: errors && Boolean(errors[name]),
|
|
40
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
41
|
+
helperText: errors && errors[name] ? (_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message : fieldSchema.help_text || '',
|
|
41
42
|
};
|
|
42
43
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterDayjs_1.AdapterDayjs, adapterLocale: "pt-br" },
|
|
43
44
|
react_1.default.createElement(DesktopDatePicker_1.DesktopDatePicker, Object.assign({}, field, { value: (0, dayjs_1.default)(field.value), label: fieldSchema.label, disabled: fieldSchema.disabled === true || disabled === true, views: fieldSchema.date_views, format: inputFormat, sx: Object.assign({ mt: 2, mb: 1 }, sx), slotProps: {
|
|
@@ -13,6 +13,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
13
13
|
require("dayjs/locale/pt-br");
|
|
14
14
|
const utils_1 = require("../../../utils");
|
|
15
15
|
function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey, index, sx = { mr: 2, mt: 2 }, autoFocus, disabled, }) {
|
|
16
|
+
var _a;
|
|
16
17
|
if (!(name in schema)) {
|
|
17
18
|
console.error(`DesktopDateTimePickerBySchema: could not find schema for ${name}! Not rendering`);
|
|
18
19
|
return;
|
|
@@ -30,7 +31,7 @@ function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey
|
|
|
30
31
|
})
|
|
31
32
|
: {
|
|
32
33
|
error: errors && Boolean(errors[name]),
|
|
33
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
34
|
+
helperText: errors && errors[name] ? (_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message : fieldSchema.help_text || '',
|
|
34
35
|
};
|
|
35
36
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterDayjs_1.AdapterDayjs, adapterLocale: "pt-br" },
|
|
36
37
|
react_1.default.createElement(DesktopDateTimePicker_1.DesktopDateTimePicker, Object.assign({}, field, { value: (0, dayjs_1.default)(field.value), label: fieldSchema.label, disabled: fieldSchema.disabled === true || disabled === true, format: "DD/MM/YYYY HH:mm", sx: Object.assign({ mt: 2, mb: 1 }, sx), slotProps: {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { Item } from '../../../@types';
|
|
4
|
+
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<Omit<import("../../../@types").CommonFieldProps<void>, "value" | "onEditModel"> & {
|
|
5
|
+
onEditModel?: <U extends import("../../../@types").TField = void>(x: import("../../../@types").OnEditModelType<U>) => void;
|
|
6
|
+
name: string;
|
|
7
|
+
schema: {
|
|
8
|
+
[x: string]: import("../../../@types").Field;
|
|
9
|
+
};
|
|
10
|
+
control: Controller<Item<T>, import("../../../@types").GenericValue, Item<T>>;
|
|
11
|
+
errors: Controller<Item<T>>;
|
|
12
|
+
autoFocus?: boolean;
|
|
13
|
+
} & React.RefAttributes<any>>;
|
|
4
14
|
export default EditableAutocompleteFieldBySchema;
|
|
5
15
|
//# sourceMappingURL=EditableAutocompleteFieldBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditableAutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/EditableAutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EditableAutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/EditableAutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,EAAE,IAAI,EAAkC,MAAM,iBAAiB,CAAC;AAOvE,QAAA,MAAM,iCAAiC;;;;;;;;;6BAsWtC,CAAC;AAGF,eAAe,iCAAiC,CAAC"}
|
|
@@ -59,6 +59,7 @@ const DialogActions_1 = __importDefault(require("../../DialogActions"));
|
|
|
59
59
|
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
60
60
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
61
61
|
const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) => {
|
|
62
|
+
var _b;
|
|
62
63
|
var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, onValueChange, multiple = false, disabled, fieldsLayout, autoFocus } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "onValueChange", "multiple", "disabled", "fieldsLayout", "autoFocus"]);
|
|
63
64
|
const { setDialog } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
64
65
|
const [options, setOptions] = (0, react_1.useState)(null);
|
|
@@ -95,7 +96,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
97
98
|
const fieldSchema = schema[name];
|
|
98
|
-
const label = fieldSchema.label;
|
|
99
|
+
const label = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.label;
|
|
99
100
|
if (!optionsModel) {
|
|
100
101
|
optionsModel = model;
|
|
101
102
|
}
|
|
@@ -111,13 +112,13 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
111
112
|
})
|
|
112
113
|
: {
|
|
113
114
|
error: errors && Boolean(errors[name]),
|
|
114
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
115
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.help_text) || '',
|
|
115
116
|
};
|
|
116
117
|
if (!options) {
|
|
117
118
|
return null;
|
|
118
119
|
}
|
|
119
|
-
if (!disabled && !fieldSchema.disabled && onEditModel && optionsModel) {
|
|
120
|
-
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: fieldSchema.disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
120
|
+
if (!disabled && !(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) && onEditModel && optionsModel) {
|
|
121
|
+
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: (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
121
122
|
let valueAr = value || '';
|
|
122
123
|
if (!multiple) {
|
|
123
124
|
valueAr = [value];
|
|
@@ -256,7 +257,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
256
257
|
}
|
|
257
258
|
: undefined }))) }));
|
|
258
259
|
}
|
|
259
|
-
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: fieldSchema.disabled === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
260
|
+
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: (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
260
261
|
field.onChange(value);
|
|
261
262
|
if (onValueChange) {
|
|
262
263
|
onValueChange(e);
|
|
@@ -40,6 +40,7 @@ const VisuallyHiddenInput = (0, styles_1.styled)('input')({
|
|
|
40
40
|
width: 1,
|
|
41
41
|
});
|
|
42
42
|
function FileFieldBySchema(_a) {
|
|
43
|
+
var _b;
|
|
43
44
|
var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 }, onValueChange, autoFocus, disabled } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx", "onValueChange", "autoFocus", "disabled"]);
|
|
44
45
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
45
46
|
if (!(name in schema)) {
|
|
@@ -59,7 +60,7 @@ function FileFieldBySchema(_a) {
|
|
|
59
60
|
})
|
|
60
61
|
: {
|
|
61
62
|
error: errors && Boolean(errors[name]),
|
|
62
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
63
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
63
64
|
};
|
|
64
65
|
const fileTypeStr = fieldSchema.type === 'image upload' ? 'imagem' : 'documento';
|
|
65
66
|
const accept = fieldSchema.allowed_mime_types
|
|
@@ -21,6 +21,7 @@ const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
|
21
21
|
const react_number_format_1 = require("react-number-format");
|
|
22
22
|
const utils_1 = require("../../../utils");
|
|
23
23
|
function FloatFieldBySchema(_a) {
|
|
24
|
+
var _b;
|
|
24
25
|
var { name, schema, control, errors, fieldKey, index, onValueChange, decimalScale, label, autoFocus, disabled } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "onValueChange", "decimalScale", "label", "autoFocus", "disabled"]);
|
|
25
26
|
if (!(name in schema)) {
|
|
26
27
|
console.error(`FloatFieldBySchema: could not find schema for ${name}! Not rendering`);
|
|
@@ -42,7 +43,7 @@ function FloatFieldBySchema(_a) {
|
|
|
42
43
|
})
|
|
43
44
|
: {
|
|
44
45
|
error: errors && Boolean(errors[name]),
|
|
45
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
46
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
46
47
|
};
|
|
47
48
|
const prefix = fieldSchema.is_currency
|
|
48
49
|
? 'R$ '
|
|
@@ -21,6 +21,7 @@ const react_number_format_1 = require("react-number-format");
|
|
|
21
21
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
22
22
|
const utils_1 = require("../../../utils");
|
|
23
23
|
function PatternFieldBySchema(_a) {
|
|
24
|
+
var _b;
|
|
24
25
|
var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 }, type, autoComplete, disabled, onValueChange, autoFocus } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx", "type", "autoComplete", "disabled", "onValueChange", "autoFocus"]);
|
|
25
26
|
if (!(name in schema)) {
|
|
26
27
|
console.error(`PatternFieldBySchema: could not find schema for ${name}! Not rendering`);
|
|
@@ -39,7 +40,7 @@ function PatternFieldBySchema(_a) {
|
|
|
39
40
|
})
|
|
40
41
|
: {
|
|
41
42
|
error: errors && Boolean(errors[name]),
|
|
42
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
43
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
43
44
|
};
|
|
44
45
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(react_number_format_1.PatternFormat, Object.assign({}, field, other, { id: name, key: name, label: fieldSchema.label, required: (0, utils_1.isFieldRequired)(fieldSchema), disabled: fieldSchema.disabled === true || disabled, onChange: undefined, onValueChange: (values) => {
|
|
45
46
|
field.onChange(values.value);
|
|
@@ -20,6 +20,7 @@ const react_hook_form_1 = require("react-hook-form");
|
|
|
20
20
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
21
21
|
const utils_1 = require("../../../utils");
|
|
22
22
|
function TextFieldBySchema(_a) {
|
|
23
|
+
var _b;
|
|
23
24
|
var { name, schema, control, errors, multiline = false, minRows, fieldKey, index, sx = { mr: 2 }, type, autoComplete, disabled, onValueChange, autoFocus } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "minRows", "fieldKey", "index", "sx", "type", "autoComplete", "disabled", "onValueChange", "autoFocus"]);
|
|
24
25
|
if (!(name in schema)) {
|
|
25
26
|
console.error(`TextFieldBySchema: could not find schema for ${name}! Not rendering`);
|
|
@@ -44,7 +45,7 @@ function TextFieldBySchema(_a) {
|
|
|
44
45
|
})
|
|
45
46
|
: {
|
|
46
47
|
error: errors && Boolean(errors[name]),
|
|
47
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
48
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
48
49
|
};
|
|
49
50
|
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: fieldSchema.label, required: (0, utils_1.isFieldRequired)(fieldSchema), disabled: fieldSchema.disabled === true || disabled, onChange: (e) => {
|
|
50
51
|
field.onChange(e.target.value);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { TField } from '../@types';
|
|
2
3
|
import { DialogType, FormTools, PageFormType, SnackBarType } from './APIWrapperContext';
|
|
3
|
-
interface APIWrapperProps {
|
|
4
|
+
interface APIWrapperProps<T extends TField = void> {
|
|
4
5
|
handleLoading: (x: boolean) => void;
|
|
5
6
|
setSnackBar: (x: Partial<SnackBarType>) => void;
|
|
6
|
-
setDialog:
|
|
7
|
-
pageForm: PageFormType | null;
|
|
8
|
-
setPageForm: (x: Partial<PageFormType
|
|
7
|
+
setDialog: (newState: Partial<DialogType> | null) => void;
|
|
8
|
+
pageForm: PageFormType<T> | null;
|
|
9
|
+
setPageForm: (x: Partial<PageFormType<T>>) => void;
|
|
9
10
|
resetPageForm: () => void;
|
|
10
|
-
formTools?: FormTools
|
|
11
|
-
setFormTools: (x: FormTools) => void;
|
|
11
|
+
formTools?: FormTools<T>;
|
|
12
|
+
setFormTools: (x: FormTools<T>) => void;
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
}
|
|
14
15
|
declare function APIWrapper({ handleLoading, setSnackBar, setDialog, pageForm, setPageForm, resetPageForm, formTools, setFormTools, children, }: APIWrapperProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;AAM7F,OAAO,EAgBL,MAAM,EAEP,MAAM,WAAW,CAAC;AA6BnB,OAAO,EAEL,UAAU,EAEV,SAAS,EAMT,YAAY,EACZ,YAAY,EACb,MAAM,qBAAqB,CAAC;AAI7B,UAAU,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IAC/C,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAChD,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACzB,YAAY,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,iBAAS,UAAU,CAAC,EAClB,aAAa,EACb,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,aAAa,EACb,SAAS,EACT,YAAY,EACZ,QAAQ,GACT,EAAE,eAAe,qBAkrBjB;;AAED,wBAAsC"}
|