drf-react-by-schema 0.27.18 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/@types/index.d.ts +3 -5
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts +17 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +3 -1
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +1 -1
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.js +3 -3
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +13 -1
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/FileInputCell.js +1 -1
- 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 +81 -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 +84 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridDateInput.js +4 -5
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.js +4 -5
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +4 -5
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.js +1 -1
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +4 -5
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +1 -1
- 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/useProcessRowUpdate.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +14 -19
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +41 -26
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +3 -2
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -1
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -1
- package/dist/components/forms/DialogFormBySchema.js +27 -2
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/FieldBySchema.js +7 -0
- package/dist/components/forms/Form.d.ts.map +1 -1
- package/dist/components/forms/Form.js +69 -40
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +4 -5
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +2 -2
- 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 +57 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts +18 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
- package/dist/components/forms/inputs/MapGeometryPicker.js +248 -0
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +10 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -11
- package/dist/styles/theme.d.ts +1 -1
- package/dist/styles/theme.d.ts.map +1 -1
- package/dist/utils/utils.d.ts +39 -5
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +114 -19
- package/package.json +36 -2
|
@@ -1 +1 @@
|
|
|
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,EAGP,MAAM,WAAW,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,EAGP,MAAM,WAAW,CAAC;AA+BnB,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,qBAstBjB;;AAED,wBAAsC"}
|
|
@@ -186,7 +186,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, pageForm, setPageFo
|
|
|
186
186
|
return values;
|
|
187
187
|
}), [handleLoading, populateOptionsAC, serverEndPoint, resetPageForm, schemas, setPageForm]);
|
|
188
188
|
const onSubmit = (0, react_1.useCallback)((model, id, data) => __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
var _a;
|
|
189
|
+
var _a, _b;
|
|
190
190
|
const currentSchema = (_a = pageFormRef.current) === null || _a === void 0 ? void 0 : _a.schema;
|
|
191
191
|
const currentOptionsAC = optionsACRef.current;
|
|
192
192
|
if (!currentSchema) {
|
|
@@ -202,8 +202,16 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, pageForm, setPageFo
|
|
|
202
202
|
schema: currentSchema,
|
|
203
203
|
});
|
|
204
204
|
if (axios_1.default.isAxiosError(response)) {
|
|
205
|
+
// If the backend returned field-level validation errors (e.g. raised in
|
|
206
|
+
// a serializer's `validate()`), the form component maps them onto the
|
|
207
|
+
// offending fields. So point the user to those instead of a generic
|
|
208
|
+
// "contact support" message.
|
|
209
|
+
const hasFieldErrors = Object.keys((0, utils_1.getFieldErrorsFromResponse)((_b = response.response) === null || _b === void 0 ? void 0 : _b.data, currentSchema !== null && currentSchema !== void 0 ? currentSchema : undefined))
|
|
210
|
+
.length > 0;
|
|
205
211
|
onTriggerSnackBar({
|
|
206
|
-
msg:
|
|
212
|
+
msg: hasFieldErrors
|
|
213
|
+
? 'Não foi possível salvar. Confira os campos destacados.'
|
|
214
|
+
: 'Houve um problema ao salvar seus dados! Por favor, entre em contato',
|
|
207
215
|
severity: 'error',
|
|
208
216
|
});
|
|
209
217
|
console.log({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setAuthToken, hasJWT, clearJWT, AUTH_EXPIRED_EVENT } from './api';
|
|
2
|
-
import { emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getTmpId, isTmpId, getPatternFormat, slugToCamelCase } from './utils';
|
|
2
|
+
import { emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, slugToCamelCase } from './utils';
|
|
3
3
|
import DRFReactBySchemaProvider from './context/DRFReactBySchemaProvider';
|
|
4
4
|
import { useAPIWrapper } from './context/APIWrapperContext';
|
|
5
5
|
import Form from './components/forms/Form';
|
|
@@ -9,11 +9,11 @@ import GenericModelList from './components/GenericModelList';
|
|
|
9
9
|
import GenericRelatedModelList from './components/GenericRelatedModelList';
|
|
10
10
|
import DataTotals from './components/DataTotals';
|
|
11
11
|
import DialogActions from './components/DialogActions';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
12
|
+
import SelectEditInputCell from './components/DataGridBySchemaEditable/SelectEditInputCell';
|
|
13
|
+
import GridDateInput from './components/DataGridBySchemaEditable/GridDateInput';
|
|
14
|
+
import GridDecimalInput from './components/DataGridBySchemaEditable/GridDecimalInput';
|
|
15
|
+
import GridPatternInput from './components/DataGridBySchemaEditable/GridPatternInput';
|
|
16
|
+
import BooleanInputCell from './components/DataGridBySchemaEditable/BooleanInputCell';
|
|
17
17
|
import FormWatcher from './components/forms/FormWatcher';
|
|
18
18
|
import FormBySchema from './components/forms/FormBySchema';
|
|
19
19
|
import FieldBySchema from './components/forms/FieldBySchema';
|
|
@@ -26,6 +26,6 @@ import AutocompleteFieldBySchema from './components/forms/inputs/AutocompleteFie
|
|
|
26
26
|
import FloatFieldBySchema from './components/forms/inputs/FloatFieldBySchema';
|
|
27
27
|
import DetailBySchema from './components/details/DetailBySchema';
|
|
28
28
|
import DetailFieldBySchema from './components/details/DetailFieldBySchema';
|
|
29
|
-
export { DRFReactBySchemaProvider, useAPIWrapper, Form, DialogFormBySchema, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, SelectEditInputCell, GridDateInput, GridDecimalInput, GridPatternInput, BooleanInputCell, FormWatcher, FormBySchema, FieldBySchema, TextFieldBySchema, BooleanFieldBySchema, DesktopDatePickerBySchema, DesktopDateTimePickerBySchema, EditableAutocompleteFieldBySchema, AutocompleteFieldBySchema, FloatFieldBySchema, DetailBySchema, DetailFieldBySchema, setAuthToken, emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getTmpId, isTmpId, getPatternFormat, clearJWT, hasJWT, slugToCamelCase, AUTH_EXPIRED_EVENT, };
|
|
29
|
+
export { DRFReactBySchemaProvider, useAPIWrapper, Form, DialogFormBySchema, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, SelectEditInputCell, GridDateInput, GridDecimalInput, GridPatternInput, BooleanInputCell, FormWatcher, FormBySchema, FieldBySchema, TextFieldBySchema, BooleanFieldBySchema, DesktopDatePickerBySchema, DesktopDateTimePickerBySchema, EditableAutocompleteFieldBySchema, AutocompleteFieldBySchema, FloatFieldBySchema, DetailBySchema, DetailFieldBySchema, setAuthToken, emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, clearJWT, hasJWT, slugToCamelCase, AUTH_EXPIRED_EVENT, };
|
|
30
30
|
export * from './@types/index';
|
|
31
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,+BAA+B,EAC/B,UAAU,EACV,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB,OAAO,wBAAwB,MAAM,oCAAoC,CAAC;AAG1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AAGvE,OAAO,wBAAwB,MAAM,uCAAuC,CAAC;AAC7E,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAC3E,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,aAAa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G,OAAO,iCAAiC,MAAM,6DAA6D,CAAC;AAC5G,OAAO,yBAAyB,MAAM,qDAAqD,CAAC;AAC5F,OAAO,kBAAkB,MAAM,8CAA8C,CAAC;AAG9E,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,mBAAmB,MAAM,0CAA0C,CAAC;AAE3E,OAAO,EAEL,wBAAwB,EAGxB,aAAa,EAGb,IAAI,EACJ,kBAAkB,EAGlB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,aAAa,EAGb,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAGhB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,iCAAiC,EACjC,yBAAyB,EACzB,kBAAkB,EAGlB,cAAc,EACd,mBAAmB,EAGnB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,+BAA+B,EAC/B,UAAU,EACV,0BAA0B,EAC1B,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,eAAe,EACf,kBAAkB,GACnB,CAAC;AAEF,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AUTH_EXPIRED_EVENT = exports.slugToCamelCase = exports.hasJWT = exports.clearJWT = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.setAuthToken = exports.DetailFieldBySchema = exports.DetailBySchema = exports.FloatFieldBySchema = exports.AutocompleteFieldBySchema = exports.EditableAutocompleteFieldBySchema = exports.DesktopDateTimePickerBySchema = exports.DesktopDatePickerBySchema = exports.BooleanFieldBySchema = exports.TextFieldBySchema = exports.FieldBySchema = exports.FormBySchema = exports.FormWatcher = exports.BooleanInputCell = exports.GridPatternInput = exports.GridDecimalInput = exports.GridDateInput = exports.SelectEditInputCell = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.DialogFormBySchema = exports.Form = exports.useAPIWrapper = exports.DRFReactBySchemaProvider = void 0;
|
|
20
|
+
exports.AUTH_EXPIRED_EVENT = exports.slugToCamelCase = exports.hasJWT = exports.clearJWT = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.getFieldErrorsFromResponse = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.setAuthToken = exports.DetailFieldBySchema = exports.DetailBySchema = exports.FloatFieldBySchema = exports.AutocompleteFieldBySchema = exports.EditableAutocompleteFieldBySchema = exports.DesktopDateTimePickerBySchema = exports.DesktopDatePickerBySchema = exports.BooleanFieldBySchema = exports.TextFieldBySchema = exports.FieldBySchema = exports.FormBySchema = exports.FormWatcher = exports.BooleanInputCell = exports.GridPatternInput = exports.GridDecimalInput = exports.GridDateInput = exports.SelectEditInputCell = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.DialogFormBySchema = exports.Form = exports.useAPIWrapper = exports.DRFReactBySchemaProvider = void 0;
|
|
21
21
|
// Methods:
|
|
22
22
|
const api_1 = require("./api");
|
|
23
23
|
Object.defineProperty(exports, "setAuthToken", { enumerable: true, get: function () { return api_1.setAuthToken; } });
|
|
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "getChoiceByValue", { enumerable: true, get: func
|
|
|
30
30
|
Object.defineProperty(exports, "populateValues", { enumerable: true, get: function () { return utils_1.populateValues; } });
|
|
31
31
|
Object.defineProperty(exports, "buildGenericYupValidationSchema", { enumerable: true, get: function () { return utils_1.buildGenericYupValidationSchema; } });
|
|
32
32
|
Object.defineProperty(exports, "errorProps", { enumerable: true, get: function () { return utils_1.errorProps; } });
|
|
33
|
+
Object.defineProperty(exports, "getFieldErrorsFromResponse", { enumerable: true, get: function () { return utils_1.getFieldErrorsFromResponse; } });
|
|
33
34
|
Object.defineProperty(exports, "getTmpId", { enumerable: true, get: function () { return utils_1.getTmpId; } });
|
|
34
35
|
Object.defineProperty(exports, "isTmpId", { enumerable: true, get: function () { return utils_1.isTmpId; } });
|
|
35
36
|
Object.defineProperty(exports, "getPatternFormat", { enumerable: true, get: function () { return utils_1.getPatternFormat; } });
|
|
@@ -57,16 +58,16 @@ exports.DataTotals = DataTotals_1.default;
|
|
|
57
58
|
const DialogActions_1 = __importDefault(require("./components/DialogActions"));
|
|
58
59
|
exports.DialogActions = DialogActions_1.default;
|
|
59
60
|
// DataGridBySchema Components:
|
|
60
|
-
const SelectEditInputCell_1 = require("./components/DataGridBySchemaEditable/SelectEditInputCell");
|
|
61
|
-
|
|
62
|
-
const GridDateInput_1 = require("./components/DataGridBySchemaEditable/GridDateInput");
|
|
63
|
-
|
|
64
|
-
const GridDecimalInput_1 = require("./components/DataGridBySchemaEditable/GridDecimalInput");
|
|
65
|
-
|
|
66
|
-
const GridPatternInput_1 = require("./components/DataGridBySchemaEditable/GridPatternInput");
|
|
67
|
-
|
|
68
|
-
const BooleanInputCell_1 = require("./components/DataGridBySchemaEditable/BooleanInputCell");
|
|
69
|
-
|
|
61
|
+
const SelectEditInputCell_1 = __importDefault(require("./components/DataGridBySchemaEditable/SelectEditInputCell"));
|
|
62
|
+
exports.SelectEditInputCell = SelectEditInputCell_1.default;
|
|
63
|
+
const GridDateInput_1 = __importDefault(require("./components/DataGridBySchemaEditable/GridDateInput"));
|
|
64
|
+
exports.GridDateInput = GridDateInput_1.default;
|
|
65
|
+
const GridDecimalInput_1 = __importDefault(require("./components/DataGridBySchemaEditable/GridDecimalInput"));
|
|
66
|
+
exports.GridDecimalInput = GridDecimalInput_1.default;
|
|
67
|
+
const GridPatternInput_1 = __importDefault(require("./components/DataGridBySchemaEditable/GridPatternInput"));
|
|
68
|
+
exports.GridPatternInput = GridPatternInput_1.default;
|
|
69
|
+
const BooleanInputCell_1 = __importDefault(require("./components/DataGridBySchemaEditable/BooleanInputCell"));
|
|
70
|
+
exports.BooleanInputCell = BooleanInputCell_1.default;
|
|
70
71
|
// FormComponents
|
|
71
72
|
const FormWatcher_1 = __importDefault(require("./components/forms/FormWatcher"));
|
|
72
73
|
exports.FormWatcher = FormWatcher_1.default;
|
package/dist/styles/theme.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/styles/theme.ts"],"names":[],"mappings":"AAMA,OAAO,QAAQ,sBAAsB,CAAC;IAMpC,UAAU,OAAO;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7B,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAClC,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,iBAAiB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACtC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;KAC9B;IAKD,UAAU,YAAY;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CASF;AA4GD,QAAA,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/styles/theme.ts"],"names":[],"mappings":"AAMA,OAAO,QAAQ,sBAAsB,CAAC;IAMpC,UAAU,OAAO;QACf,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7B,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAClC,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjC,iBAAiB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACtC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;KAC9B;IAKD,UAAU,YAAY;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;CASF;AA4GD,QAAA,MAAM,YAAY,sCA0HjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
1
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
2
|
-
import
|
|
3
|
+
import * as geojson from 'geojson';
|
|
4
|
+
import { ChoiceItem, ChoiceValue, ConditionalVisible, CustomFormField, ExtraValidators, Field, FormFieldLayout, GenericValue, GeometryFieldType, GridEnrichedBySchemaColDef, Item, SchemaType, TField } from '../@types';
|
|
3
5
|
export declare const emptyByType: GenericValue;
|
|
4
6
|
export declare const getChoiceByValue: (value: ChoiceValue, choices: ChoiceItem[] | undefined) => string | null | undefined;
|
|
5
7
|
export declare function populateValues({ data, schema }: {
|
|
@@ -13,7 +15,13 @@ export declare function buildGenericYupValidationSchema({ data, schema, many, sk
|
|
|
13
15
|
skipFields?: string[];
|
|
14
16
|
extraValidators?: ExtraValidators;
|
|
15
17
|
uiFields?: string[];
|
|
16
|
-
}):
|
|
18
|
+
}): Yup.ObjectSchema<{
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
}, Yup.AnyObject, {
|
|
21
|
+
[x: string]: any;
|
|
22
|
+
}, ""> | Yup.ArraySchema<{
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}[] | undefined, Yup.AnyObject, "", "">;
|
|
17
25
|
export declare function loadSinglePageDataHelper({ data, schema, columns, fieldsLayout, defaults, extraValidators, }: {
|
|
18
26
|
data: Item;
|
|
19
27
|
schema: SchemaType;
|
|
@@ -26,7 +34,7 @@ export declare function loadSinglePageDataHelper({ data, schema, columns, fields
|
|
|
26
34
|
finalSchema: {
|
|
27
35
|
[x: string]: Field;
|
|
28
36
|
};
|
|
29
|
-
validationSchema: any;
|
|
37
|
+
validationSchema: Yup.ObjectSchema<Record<string, any>, Yup.AnyObject, any, ""> | null;
|
|
30
38
|
};
|
|
31
39
|
export declare const errorProps: ({ errors, fieldKey, fieldKeyProp, index, }: {
|
|
32
40
|
errors: Item;
|
|
@@ -37,6 +45,22 @@ export declare const errorProps: ({ errors, fieldKey, fieldKeyProp, index, }: {
|
|
|
37
45
|
error: any;
|
|
38
46
|
helperText: any;
|
|
39
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Normalizes a DRF (Django REST Framework) validation error payload into a
|
|
50
|
+
* react-hook-form `setError`-compatible map: `{ fieldKey: { type, message } }`.
|
|
51
|
+
*
|
|
52
|
+
* DRF returns per-field errors both as `{ field: "message" }` and
|
|
53
|
+
* `{ field: ["message 1", "message 2"] }`, plus `{ non_field_errors: [...] }`.
|
|
54
|
+
* Only fields present in the given `schema` are mapped, so backend-only keys
|
|
55
|
+
* (or `non_field_errors`) are skipped and remain surfaced through the generic
|
|
56
|
+
* error message instead. This is what allows a `validate()` raised
|
|
57
|
+
* `ValidationError({"field": "..."})` to be rendered under the offending field,
|
|
58
|
+
* exactly like a yup validation error.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getFieldErrorsFromResponse<T extends TField = void>(response: unknown, schema?: SchemaType<T>): Record<string, {
|
|
61
|
+
type: string;
|
|
62
|
+
message: string;
|
|
63
|
+
}>;
|
|
40
64
|
export declare const getTmpId: () => string;
|
|
41
65
|
export declare const isTmpId: (id: string | number | undefined | null) => boolean;
|
|
42
66
|
export declare function reducer<T>(state: T | null, newState: Partial<T> | null): T | null;
|
|
@@ -44,12 +68,12 @@ export declare const getPatternFormat: (type: string) => string;
|
|
|
44
68
|
export declare function buildDateFormatBySchema(dateViews: string[] | null | undefined): "DD/MM/YYYY" | "MM/YYYY" | "YYYY" | "MM" | "DD";
|
|
45
69
|
export declare const slugToCamelCase: (str: string, includeFirst?: boolean) => string;
|
|
46
70
|
export declare const slugify: (text: string | null) => string;
|
|
47
|
-
export declare function mergeFilterItems(defaultFilter: GridFilterModel | undefined, filter: GridFilterModel | undefined):
|
|
71
|
+
export declare function mergeFilterItems(defaultFilter: GridFilterModel | undefined, filter: GridFilterModel | undefined): GridFilterModel | undefined;
|
|
48
72
|
export declare function initViewColumns({ schema, columns, customColumnOperations, }: {
|
|
49
73
|
schema: SchemaType;
|
|
50
74
|
columns: GridEnrichedBySchemaColDef[];
|
|
51
75
|
customColumnOperations?: (p: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef | Promise<GridEnrichedBySchemaColDef>;
|
|
52
|
-
}): Promise<(Omit<GridColDef<
|
|
76
|
+
}): Promise<(Omit<import("@mui/x-data-grid").GridColDef<Record<string, any>>, "field"> & {
|
|
53
77
|
field: string;
|
|
54
78
|
isIndexField?: boolean;
|
|
55
79
|
creatable?: boolean;
|
|
@@ -68,4 +92,14 @@ export declare function extractFieldValue(genericValue: GenericValue): any;
|
|
|
68
92
|
export declare function buildConditionalVisibleBySchema<T extends TField = void>(schema?: SchemaType<T> | null): ConditionalVisible[];
|
|
69
93
|
export declare function showConditionalVisibleField(field: string | CustomFormField, conditionalVisible?: ConditionalVisible[], values?: GenericValue[]): boolean;
|
|
70
94
|
export declare function showConditionalVisibleFieldObj<T extends TField = void>(field: string | CustomFormField, conditionalVisible?: ConditionalVisible[], values?: Item<T>): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Detect whether the consuming app has installed leaflet + leaflet-draw.
|
|
97
|
+
* Uses CJS require so that the bundler does not fail to build when they are
|
|
98
|
+
* absent; returns null so callers can fall back to text inputs.
|
|
99
|
+
*/
|
|
100
|
+
export declare function getMapLibraries(): any;
|
|
101
|
+
/** Normalize a GeoJSON value (object, JSON string or null) to a string. */
|
|
102
|
+
export declare function geometryValueToString(value: GenericValue): string;
|
|
103
|
+
/** Parse a GeoJSON value (object or JSON string) into an object, or null. */
|
|
104
|
+
export declare function parseGeoJSON(geoType: GeometryFieldType, rawValue: GenericValue): geojson.GeoJsonObject | geojson.GeoJsonObject[] | null;
|
|
71
105
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EACL,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,KAAK,EAEL,eAAe,EACf,YAAY,EAEZ,iBAAiB,EACjB,0BAA0B,EAC1B,IAAI,EACJ,UAAU,EACV,MAAM,EACP,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,WAAW,EAAE,YA4Bz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exports.convertToFormData = exports.slugify = exports.slugToCamelCase = exports.
|
|
|
49
49
|
exports.populateValues = populateValues;
|
|
50
50
|
exports.buildGenericYupValidationSchema = buildGenericYupValidationSchema;
|
|
51
51
|
exports.loadSinglePageDataHelper = loadSinglePageDataHelper;
|
|
52
|
+
exports.getFieldErrorsFromResponse = getFieldErrorsFromResponse;
|
|
52
53
|
exports.reducer = reducer;
|
|
53
54
|
exports.buildDateFormatBySchema = buildDateFormatBySchema;
|
|
54
55
|
exports.mergeFilterItems = mergeFilterItems;
|
|
@@ -62,6 +63,9 @@ exports.extractFieldValue = extractFieldValue;
|
|
|
62
63
|
exports.buildConditionalVisibleBySchema = buildConditionalVisibleBySchema;
|
|
63
64
|
exports.showConditionalVisibleField = showConditionalVisibleField;
|
|
64
65
|
exports.showConditionalVisibleFieldObj = showConditionalVisibleFieldObj;
|
|
66
|
+
exports.getMapLibraries = getMapLibraries;
|
|
67
|
+
exports.geometryValueToString = geometryValueToString;
|
|
68
|
+
exports.parseGeoJSON = parseGeoJSON;
|
|
65
69
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
66
70
|
const Yup = __importStar(require("yup"));
|
|
67
71
|
const string_mask_1 = __importDefault(require("string-mask"));
|
|
@@ -201,6 +205,16 @@ const getYupValidator = (type) => {
|
|
|
201
205
|
case 'file upload':
|
|
202
206
|
yupFunc = Yup.object();
|
|
203
207
|
break;
|
|
208
|
+
// PostGIS geometry fields arrive as GeoJSON objects (e.g.
|
|
209
|
+
// { type: 'Point', coordinates: [...] }), so they must validate as
|
|
210
|
+
// objects rather than falling through to the default string schema.
|
|
211
|
+
case 'point':
|
|
212
|
+
case 'polygon':
|
|
213
|
+
case 'multipoint':
|
|
214
|
+
case 'multipolygon':
|
|
215
|
+
case 'geometrycollection':
|
|
216
|
+
yupFunc = Yup.object();
|
|
217
|
+
break;
|
|
204
218
|
// String-like types produced by SimpleMetadata but not needing
|
|
205
219
|
// specialized validation behave as plain strings:
|
|
206
220
|
case 'url':
|
|
@@ -222,14 +236,14 @@ const getYupValidator = (type) => {
|
|
|
222
236
|
return yupFunc.transform((v) => (v === '' ? null : v)).nullable();
|
|
223
237
|
};
|
|
224
238
|
function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, uiFields, }) {
|
|
225
|
-
var _a;
|
|
239
|
+
var _a, _b;
|
|
226
240
|
const yupValidator = {};
|
|
227
241
|
for (const entry of Object.entries(schema)) {
|
|
228
242
|
const [field, fieldSchema] = entry;
|
|
229
243
|
if (!data || !(field in data) || field === 'id' || skipFields.includes(field)) {
|
|
230
244
|
continue;
|
|
231
245
|
}
|
|
232
|
-
// OneToMany or ManyToMany:
|
|
246
|
+
// OneToMany or ManyToMany (built as an array-of-object schema):
|
|
233
247
|
if (fieldSchema.type === 'field' && ((_a = fieldSchema.child) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
234
248
|
yupValidator[field] =
|
|
235
249
|
extraValidators && field in extraValidators
|
|
@@ -240,27 +254,20 @@ function buildGenericYupValidationSchema({ data, schema, many = false, skipField
|
|
|
240
254
|
data: data[field],
|
|
241
255
|
uiFields,
|
|
242
256
|
});
|
|
243
|
-
continue;
|
|
244
257
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// data: data[key],
|
|
251
|
-
// extraValidators: key in extraValidators ? extraValidators[key] : {}
|
|
252
|
-
// });
|
|
253
|
-
// if (!field.model_required) {
|
|
254
|
-
// yupValidator[key] = yupValidator[key].nullable();
|
|
255
|
-
// }
|
|
256
|
-
// continue;
|
|
258
|
+
else {
|
|
259
|
+
yupValidator[field] =
|
|
260
|
+
extraValidators && field in extraValidators
|
|
261
|
+
? extraValidators[field]
|
|
262
|
+
: getYupValidator(fieldSchema.type);
|
|
257
263
|
}
|
|
258
|
-
yupValidator[field] =
|
|
259
|
-
extraValidators && field in extraValidators
|
|
260
|
-
? extraValidators[field]
|
|
261
|
-
: getYupValidator(fieldSchema.type);
|
|
262
264
|
if (isFieldRequired(fieldSchema, (uiFields || []).includes(field))) {
|
|
263
265
|
yupValidator[field] = yupValidator[field].required('Este campo é obrigatório');
|
|
266
|
+
// For required many-fields the selected items live in an array, and yup's
|
|
267
|
+
// `.required()` still allows `[]`; enforce at least one selection instead.
|
|
268
|
+
if (fieldSchema.type === 'field' && ((_b = fieldSchema.child) === null || _b === void 0 ? void 0 : _b.children)) {
|
|
269
|
+
yupValidator[field] = yupValidator[field].min(1, 'Este campo é obrigatório');
|
|
270
|
+
}
|
|
264
271
|
}
|
|
265
272
|
if (fieldSchema.max_length && fieldSchema.type === 'string') {
|
|
266
273
|
yupValidator[field] = yupValidator[field].max(parseInt(fieldSchema.max_length), `Este campo só pode ter no máximo ${fieldSchema.max_length} caracteres`);
|
|
@@ -338,6 +345,37 @@ const errorProps = ({ errors, fieldKey, fieldKeyProp, index, }) => {
|
|
|
338
345
|
return { error, helperText };
|
|
339
346
|
};
|
|
340
347
|
exports.errorProps = errorProps;
|
|
348
|
+
/**
|
|
349
|
+
* Normalizes a DRF (Django REST Framework) validation error payload into a
|
|
350
|
+
* react-hook-form `setError`-compatible map: `{ fieldKey: { type, message } }`.
|
|
351
|
+
*
|
|
352
|
+
* DRF returns per-field errors both as `{ field: "message" }` and
|
|
353
|
+
* `{ field: ["message 1", "message 2"] }`, plus `{ non_field_errors: [...] }`.
|
|
354
|
+
* Only fields present in the given `schema` are mapped, so backend-only keys
|
|
355
|
+
* (or `non_field_errors`) are skipped and remain surfaced through the generic
|
|
356
|
+
* error message instead. This is what allows a `validate()` raised
|
|
357
|
+
* `ValidationError({"field": "..."})` to be rendered under the offending field,
|
|
358
|
+
* exactly like a yup validation error.
|
|
359
|
+
*/
|
|
360
|
+
function getFieldErrorsFromResponse(response, schema) {
|
|
361
|
+
const result = {};
|
|
362
|
+
if (!response || typeof response !== 'object' || Array.isArray(response)) {
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
for (const [key, value] of Object.entries(response)) {
|
|
366
|
+
if (key === 'non_field_errors') {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (schema && !(key in schema)) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const message = Array.isArray(value) ? value[0] : value;
|
|
373
|
+
if (typeof message === 'string' && message.length > 0) {
|
|
374
|
+
result[key] = { type: 'server', message };
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
341
379
|
const getTmpId = () => {
|
|
342
380
|
return 'tmp' + Math.floor(Math.random() * 1000000);
|
|
343
381
|
};
|
|
@@ -815,3 +853,60 @@ function showConditionalVisibleFieldObj(field, conditionalVisible, values) {
|
|
|
815
853
|
.filter((item) => item.target === field);
|
|
816
854
|
return sources.length > 0;
|
|
817
855
|
}
|
|
856
|
+
// --- Optional OSM (leaflet) geometry support --------------------------------
|
|
857
|
+
// PostGIS geometry fields arrive from the backend as GeoJSON (type point /
|
|
858
|
+
// polygon / multipoint / multipolygon / geometrycollection). Editing them uses
|
|
859
|
+
// leaflet + leaflet-draw when those optional libraries are installed in the
|
|
860
|
+
// consuming app; otherwise the UI falls back to plain text editing.
|
|
861
|
+
/**
|
|
862
|
+
* Detect whether the consuming app has installed leaflet + leaflet-draw.
|
|
863
|
+
* Uses CJS require so that the bundler does not fail to build when they are
|
|
864
|
+
* absent; returns null so callers can fall back to text inputs.
|
|
865
|
+
*/
|
|
866
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
867
|
+
function getMapLibraries() {
|
|
868
|
+
try {
|
|
869
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
870
|
+
const L = require('leaflet');
|
|
871
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
872
|
+
require('leaflet-draw');
|
|
873
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
874
|
+
require('react-leaflet');
|
|
875
|
+
if (L && L.map && L.Control && typeof L.Control.Draw === 'function') {
|
|
876
|
+
return L;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
catch (_a) {
|
|
880
|
+
// leaflet / leaflet-draw / react-leaflet not installed -> no map support
|
|
881
|
+
}
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
/** Normalize a GeoJSON value (object, JSON string or null) to a string. */
|
|
885
|
+
function geometryValueToString(value) {
|
|
886
|
+
if (value === null || value === undefined)
|
|
887
|
+
return '';
|
|
888
|
+
if (typeof value === 'string')
|
|
889
|
+
return value;
|
|
890
|
+
try {
|
|
891
|
+
return JSON.stringify(value);
|
|
892
|
+
}
|
|
893
|
+
catch (_a) {
|
|
894
|
+
return '';
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
/** Parse a GeoJSON value (object or JSON string) into an object, or null. */
|
|
898
|
+
function parseGeoJSON(geoType, rawValue) {
|
|
899
|
+
const text = geometryValueToString(rawValue);
|
|
900
|
+
if (!text) {
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
try {
|
|
904
|
+
const parsed = JSON.parse(text);
|
|
905
|
+
return parsed && typeof parsed.type === 'string' && (0, exports.slugify)(parsed.type) === geoType
|
|
906
|
+
? parsed
|
|
907
|
+
: null;
|
|
908
|
+
}
|
|
909
|
+
catch (_a) {
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drf-react-by-schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "Components and Tools for building a React App having Django Rest Framework (DRF) as server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -42,25 +42,45 @@
|
|
|
42
42
|
"@babel/preset-env": "^7.20.2",
|
|
43
43
|
"@babel/preset-react": "^7.18.6",
|
|
44
44
|
"@babel/preset-typescript": "^7.18.6",
|
|
45
|
+
"@emotion/react": "^11",
|
|
46
|
+
"@emotion/styled": "^11",
|
|
45
47
|
"@eslint/compat": "^1.3.0",
|
|
46
48
|
"@eslint/eslintrc": "^3.3.1",
|
|
47
49
|
"@eslint/js": "^9.29.0",
|
|
50
|
+
"@hookform/resolvers": "^3",
|
|
51
|
+
"@mui/icons-material": "^6",
|
|
52
|
+
"@mui/material": "^6",
|
|
53
|
+
"@mui/x-data-grid": "^7",
|
|
54
|
+
"@mui/x-date-pickers": "^7",
|
|
55
|
+
"@types/leaflet": "^1.9.22",
|
|
56
|
+
"@types/leaflet-draw": "^1.0.13",
|
|
48
57
|
"@types/node": "^18.11.15",
|
|
49
58
|
"@types/react": "^19.1.8",
|
|
50
59
|
"@types/react-dom": "^19.1.6",
|
|
51
60
|
"@typescript-eslint/eslint-plugin": "^8.34.1",
|
|
52
61
|
"@typescript-eslint/parser": "8.34.1",
|
|
62
|
+
"axios": "^1",
|
|
63
|
+
"dayjs": "^1",
|
|
53
64
|
"eslint": "^9.29.0",
|
|
54
65
|
"eslint-config-prettier": "^8.5.0",
|
|
55
66
|
"eslint-plugin-prettier": "^5.0.0",
|
|
56
67
|
"eslint-plugin-react": "^7.37.5",
|
|
57
68
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
69
|
+
"leaflet": "^1.9.4",
|
|
70
|
+
"leaflet-draw": "^1.0.4",
|
|
58
71
|
"prettier": "^3.0.0",
|
|
72
|
+
"react": "^19",
|
|
59
73
|
"react-docgen-typescript": "^2.2.2",
|
|
74
|
+
"react-dom": "^19",
|
|
75
|
+
"react-hook-form": "^7",
|
|
76
|
+
"react-leaflet": "^5.0.0",
|
|
77
|
+
"react-number-format": "^5",
|
|
60
78
|
"semver": "^7.5.1",
|
|
79
|
+
"string-mask": "^0.3.0",
|
|
61
80
|
"ts-loader": "^9.4.2",
|
|
62
81
|
"typescript": "^5.7.3",
|
|
63
|
-
"webpack": "^5.75.0"
|
|
82
|
+
"webpack": "^5.75.0",
|
|
83
|
+
"yup": "^1"
|
|
64
84
|
},
|
|
65
85
|
"peerDependencies": {
|
|
66
86
|
"@emotion/react": "^11",
|
|
@@ -72,13 +92,27 @@
|
|
|
72
92
|
"@mui/x-date-pickers": "^7",
|
|
73
93
|
"axios": "^1",
|
|
74
94
|
"dayjs": "^1",
|
|
95
|
+
"leaflet": "^1.9.0",
|
|
96
|
+
"leaflet-draw": "^1.0.4",
|
|
75
97
|
"react": "^18 || ^19",
|
|
76
98
|
"react-dom": "^18 || ^19",
|
|
77
99
|
"react-hook-form": "^7",
|
|
100
|
+
"react-leaflet": "^5.0.0",
|
|
78
101
|
"react-number-format": "^5",
|
|
79
102
|
"string-mask": "^0.3.0",
|
|
80
103
|
"yup": "^1"
|
|
81
104
|
},
|
|
105
|
+
"peerDependenciesMeta": {
|
|
106
|
+
"leaflet": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"react-leaflet": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"leaflet-draw": {
|
|
113
|
+
"optional": true
|
|
114
|
+
}
|
|
115
|
+
},
|
|
82
116
|
"browserslist": [
|
|
83
117
|
">1%",
|
|
84
118
|
"last 1 version",
|