drf-react-by-schema 0.28.0 → 0.28.2
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/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 +18 -11
- 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 +17 -20
- 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 +45 -26
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +3 -2
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -1
- 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/details/DetailFieldBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailFieldBySchema.js +18 -3
- 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 +20 -3
- 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 +19 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
- package/dist/components/forms/inputs/MapGeometryPicker.js +250 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/styles/theme.d.ts +1 -1
- package/dist/styles/theme.d.ts.map +1 -1
- package/dist/utils/utils.d.ts +23 -5
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +92 -19
- package/package.json +36 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import SvgIcon from '@mui/material/SvgIcon';
|
|
3
|
+
/**
|
|
4
|
+
* File extension → icon, reused anywhere a stored file is shown (detail page,
|
|
5
|
+
* grid cells, mobile lists, ...). Kept here until a central constants module
|
|
6
|
+
* groups it with the other shared constants (as done with the types).
|
|
7
|
+
*/
|
|
8
|
+
export declare const FILE_TYPE_ICONS: Record<string, typeof SvgIcon>;
|
|
9
|
+
export declare const DEFAULT_FILE_ICON: import("@mui/material/OverridableComponent").OverridableComponent<import("@mui/material/SvgIcon").SvgIconTypeMap<{}, "svg">> & {
|
|
10
|
+
muiName: string;
|
|
11
|
+
};
|
|
12
|
+
export interface FileTypeIconProps {
|
|
13
|
+
/** File name (or URL) whose extension selects the icon. */
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Renders the small icon matching a stored file's extension. */
|
|
17
|
+
export default function FileTypeIcon({ name }: FileTypeIconProps): React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=FileTypeIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileTypeIcon.d.ts","sourceRoot":"","sources":["../../src/components/FileTypeIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAQ5C;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,OAAO,CAoB1D,CAAC;AAEF,eAAO,MAAM,iBAAiB;;CAAsB,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,iEAAiE;AACjE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,iBAAiB,qBAI/D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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_FILE_ICON = exports.FILE_TYPE_ICONS = void 0;
|
|
7
|
+
exports.default = FileTypeIcon;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const Description_1 = __importDefault(require("@mui/icons-material/Description"));
|
|
10
|
+
const FolderZip_1 = __importDefault(require("@mui/icons-material/FolderZip"));
|
|
11
|
+
const Image_1 = __importDefault(require("@mui/icons-material/Image"));
|
|
12
|
+
const InsertDriveFile_1 = __importDefault(require("@mui/icons-material/InsertDriveFile"));
|
|
13
|
+
const PictureAsPdf_1 = __importDefault(require("@mui/icons-material/PictureAsPdf"));
|
|
14
|
+
const TableChart_1 = __importDefault(require("@mui/icons-material/TableChart"));
|
|
15
|
+
/**
|
|
16
|
+
* File extension → icon, reused anywhere a stored file is shown (detail page,
|
|
17
|
+
* grid cells, mobile lists, ...). Kept here until a central constants module
|
|
18
|
+
* groups it with the other shared constants (as done with the types).
|
|
19
|
+
*/
|
|
20
|
+
exports.FILE_TYPE_ICONS = {
|
|
21
|
+
pdf: PictureAsPdf_1.default,
|
|
22
|
+
jpg: Image_1.default,
|
|
23
|
+
jpeg: Image_1.default,
|
|
24
|
+
png: Image_1.default,
|
|
25
|
+
gif: Image_1.default,
|
|
26
|
+
webp: Image_1.default,
|
|
27
|
+
doc: Description_1.default,
|
|
28
|
+
docx: Description_1.default,
|
|
29
|
+
txt: Description_1.default,
|
|
30
|
+
rtf: Description_1.default,
|
|
31
|
+
odt: Description_1.default,
|
|
32
|
+
xls: TableChart_1.default,
|
|
33
|
+
xlsx: TableChart_1.default,
|
|
34
|
+
csv: TableChart_1.default,
|
|
35
|
+
zip: FolderZip_1.default,
|
|
36
|
+
rar: FolderZip_1.default,
|
|
37
|
+
'7z': FolderZip_1.default,
|
|
38
|
+
tar: FolderZip_1.default,
|
|
39
|
+
gz: FolderZip_1.default,
|
|
40
|
+
};
|
|
41
|
+
exports.DEFAULT_FILE_ICON = InsertDriveFile_1.default;
|
|
42
|
+
/** Renders the small icon matching a stored file's extension. */
|
|
43
|
+
function FileTypeIcon({ name }) {
|
|
44
|
+
var _a;
|
|
45
|
+
const extension = (_a = (name !== null && name !== void 0 ? name : '').split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
46
|
+
const Icon = (extension && exports.FILE_TYPE_ICONS[extension]) || exports.DEFAULT_FILE_ICON;
|
|
47
|
+
return react_1.default.createElement(Icon, null);
|
|
48
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetailFieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/details/DetailFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DetailFieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/details/DetailFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAQxD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,QAAQ,EACR,WAAW,EACX,KAAK,EACL,OAAO,EACP,OAAO,EACP,OAAO,EACP,WAAW,EACX,eAAe,EACf,mBAAmB,GACpB,EAAE,wBAAwB,4BA6K1B"}
|
|
@@ -11,10 +11,13 @@ const List_1 = __importDefault(require("@mui/material/List"));
|
|
|
11
11
|
const ListItem_1 = __importDefault(require("@mui/material/ListItem"));
|
|
12
12
|
const ListItemText_1 = __importDefault(require("@mui/material/ListItemText"));
|
|
13
13
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
14
|
+
const Stack_1 = __importDefault(require("@mui/material/Stack"));
|
|
14
15
|
const Download_1 = __importDefault(require("@mui/icons-material/Download"));
|
|
15
16
|
const DRFReactBySchemaContext_1 = require("../../context/DRFReactBySchemaContext");
|
|
16
17
|
const styles_1 = require("../../styles");
|
|
17
18
|
const Image_1 = __importDefault(require("../Image"));
|
|
19
|
+
const FileTypeIcon_1 = __importDefault(require("../FileTypeIcon"));
|
|
20
|
+
const GeoThumbCell_1 = __importDefault(require("../DataGridBySchemaEditable/GeoThumbCell"));
|
|
18
21
|
function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
19
22
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
20
23
|
if (!fieldSchema) {
|
|
@@ -24,7 +27,8 @@ function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, s
|
|
|
24
27
|
if (!value) {
|
|
25
28
|
return react_1.default.createElement(Box_1.default, { sx: sxField }, "-");
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
const fieldType = fieldSchema.type;
|
|
31
|
+
switch (fieldType) {
|
|
28
32
|
case 'nested object':
|
|
29
33
|
case 'field':
|
|
30
34
|
const multiple = fieldSchema.many || false;
|
|
@@ -39,7 +43,7 @@ function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, s
|
|
|
39
43
|
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, value.valueStr)));
|
|
40
44
|
case 'choice':
|
|
41
45
|
case 'list':
|
|
42
|
-
const multipleChoice =
|
|
46
|
+
const multipleChoice = fieldType === 'list' || fieldSchema.many ? true : false;
|
|
43
47
|
if (multipleChoice) {
|
|
44
48
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
45
49
|
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, value.title),
|
|
@@ -57,7 +61,10 @@ function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, s
|
|
|
57
61
|
case 'file upload':
|
|
58
62
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
59
63
|
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, value.title),
|
|
60
|
-
react_1.default.createElement(
|
|
64
|
+
value.value ? (react_1.default.createElement(Stack_1.default, { direction: "row", spacing: 1, alignItems: "center" },
|
|
65
|
+
react_1.default.createElement(FileTypeIcon_1.default, { name: value.value.name }),
|
|
66
|
+
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
67
|
+
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${value.value.url}`, target: "_blank", variant: "outlined", startIcon: react_1.default.createElement(Download_1.default, null) }, value.valueStr)))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
61
68
|
case 'image upload':
|
|
62
69
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
63
70
|
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, value.title),
|
|
@@ -65,6 +72,14 @@ function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, s
|
|
|
65
72
|
react_1.default.createElement(Image_1.default, { sx: styles_1.Layout.detailFieldImg, src: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${value.value.url}`, alt: value.valueStr }),
|
|
66
73
|
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
67
74
|
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${value.value.url}`, target: "_blank", variant: "contained", startIcon: react_1.default.createElement(Download_1.default, null) }, value.valueStr)))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
75
|
+
case 'point':
|
|
76
|
+
case 'polygon':
|
|
77
|
+
case 'multipoint':
|
|
78
|
+
case 'multipolygon':
|
|
79
|
+
case 'geometrycollection':
|
|
80
|
+
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
81
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, value.title),
|
|
82
|
+
react_1.default.createElement(GeoThumbCell_1.default, { geometry: fieldType, value: value.value })));
|
|
68
83
|
default:
|
|
69
84
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
70
85
|
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, value.title),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAc,kBAAkB,
|
|
1
|
+
{"version":3,"file":"FieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAc,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AAajF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,SAAiB,EACjB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAiB,EACjB,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,EAAE,EACF,OAAO,EACP,YAAoB,EACpB,KAAK,EACL,aAAa,EACb,YAAgB,EAChB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,kBAAkB,qBA8NpB"}
|
|
@@ -25,6 +25,7 @@ const FloatFieldBySchema_1 = __importDefault(require("./inputs/FloatFieldBySchem
|
|
|
25
25
|
const TextFieldBySchema_1 = __importDefault(require("./inputs/TextFieldBySchema"));
|
|
26
26
|
const FileFieldBySchema_1 = __importDefault(require("./inputs/FileFieldBySchema"));
|
|
27
27
|
const PatternFieldBySchema_1 = __importDefault(require("./inputs/PatternFieldBySchema"));
|
|
28
|
+
const GeometryFieldBySchema_1 = __importDefault(require("./inputs/GeometryFieldBySchema"));
|
|
28
29
|
function FieldBySchema(_a) {
|
|
29
30
|
var _b, _c, _d;
|
|
30
31
|
var { name, schema, control, errors, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, fieldsLayout, sx, options, isSemaphoric = false, label, onValueChange, decimalScale = 2, autoFocus } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "fieldsLayout", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale", "autoFocus"]);
|
|
@@ -59,6 +60,12 @@ function FieldBySchema(_a) {
|
|
|
59
60
|
case 'image':
|
|
60
61
|
case 'image upload':
|
|
61
62
|
return (react_1.default.createElement(FileFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
|
|
63
|
+
case 'point':
|
|
64
|
+
case 'polygon':
|
|
65
|
+
case 'multipoint':
|
|
66
|
+
case 'multipolygon':
|
|
67
|
+
case 'geometrycollection':
|
|
68
|
+
return (react_1.default.createElement(GeometryFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, geometry: fieldSchema.type, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
|
|
62
69
|
case 'number':
|
|
63
70
|
case 'integer':
|
|
64
71
|
case 'password':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/forms/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/forms/Form.tsx"],"names":[],"mappings":"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"}
|
|
@@ -67,7 +67,10 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
67
67
|
const customExitRef = (0, react_1.useRef)(customExit);
|
|
68
68
|
const methods = (0, react_hook_form_1.useForm)({
|
|
69
69
|
mode: 'onBlur',
|
|
70
|
-
|
|
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,
|
|
71
74
|
});
|
|
72
75
|
const { control, handleSubmit, reset, getValues, setValue, setError, formState: { errors, isDirty }, register, watch, } = methods;
|
|
73
76
|
const stableDefaults = (0, useDeepMemo_1.useDeepMemo)(defaults);
|
|
@@ -172,7 +175,19 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
172
175
|
exit(newId);
|
|
173
176
|
break;
|
|
174
177
|
}
|
|
175
|
-
}), [
|
|
178
|
+
}), [
|
|
179
|
+
loadData,
|
|
180
|
+
model,
|
|
181
|
+
objId,
|
|
182
|
+
onSubmit,
|
|
183
|
+
pageForm,
|
|
184
|
+
reset,
|
|
185
|
+
resetPageForm,
|
|
186
|
+
exit,
|
|
187
|
+
editPath,
|
|
188
|
+
genericNavigate,
|
|
189
|
+
setError,
|
|
190
|
+
]);
|
|
176
191
|
const updateFormTools = (0, react_1.useCallback)(() => {
|
|
177
192
|
const currentFormTools = formToolsRef.current;
|
|
178
193
|
if (!currentFormTools ||
|
|
@@ -241,7 +256,9 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
241
256
|
react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
|
|
242
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 }),
|
|
243
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 }),
|
|
244
|
-
watchValues && onWatchChange && (react_1.default.createElement(FormWatcher_1.default, {
|
|
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 })),
|
|
245
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 }))));
|
|
246
263
|
}
|
|
247
264
|
exports.default = Form;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { Item } from '../../../@types';
|
|
2
|
+
import Autocomplete from '@mui/material/Autocomplete';
|
|
4
3
|
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<Omit<import("../../../@types").CommonFieldProps<void>, "value" | "onEditModel"> & {
|
|
5
4
|
onEditModel?: <U extends import("../../../@types").TField = void>(x: import("../../../@types").OnEditModelType<U>) => void;
|
|
6
5
|
name: string;
|
|
7
6
|
schema: {
|
|
8
7
|
[x: string]: import("../../../@types").Field;
|
|
9
8
|
};
|
|
10
|
-
control:
|
|
11
|
-
errors:
|
|
9
|
+
control: import("react-hook-form").Control<Record<string, any>, any, Record<string, any>>;
|
|
10
|
+
errors: import("react-hook-form").FieldErrors<Record<string, any>>;
|
|
12
11
|
autoFocus?: boolean;
|
|
13
|
-
} & React.RefAttributes<
|
|
12
|
+
} & React.RefAttributes<typeof Autocomplete>>;
|
|
14
13
|
export default EditableAutocompleteFieldBySchema;
|
|
15
14
|
//# 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;AAGnD,OAAO,YAAqC,MAAM,4BAA4B,CAAC;AAY/E,QAAA,MAAM,iCAAiC;;;;;;;;;6CA6WtC,CAAC;AAGF,eAAe,iCAAiC,CAAC"}
|
|
@@ -170,7 +170,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
170
170
|
if (onValueChange) {
|
|
171
171
|
onValueChange(e);
|
|
172
172
|
}
|
|
173
|
-
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema), margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
173
|
+
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema) && !multiple, margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
174
174
|
!multiple && field.value && (react_1.default.createElement(IconButton_1.default, { size: "small", "aria-label": "Editar", onClick: () => {
|
|
175
175
|
if ((0, utils_1.isTmpId)(field.value.id)) {
|
|
176
176
|
setDialog({
|
|
@@ -266,7 +266,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
266
266
|
if (onValueChange) {
|
|
267
267
|
onValueChange(e);
|
|
268
268
|
}
|
|
269
|
-
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema), margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText }, other))), getOptionKey: ({ id }) => id, getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
269
|
+
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema) && !multiple, margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText }, other))), getOptionKey: ({ id }) => id, getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
270
270
|
});
|
|
271
271
|
EditableAutocompleteFieldBySchema.displayName = 'EditableAutocompleteFieldBySchema';
|
|
272
272
|
exports.default = EditableAutocompleteFieldBySchema;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldBySchemaProps, GeometryFieldType, TField } from '../../../@types';
|
|
3
|
+
export interface GeometryFieldBySchemaProps<T extends TField = void> extends FieldBySchemaProps<T> {
|
|
4
|
+
geometry: GeometryFieldType;
|
|
5
|
+
height?: number;
|
|
6
|
+
}
|
|
7
|
+
export default function GeometryFieldBySchema({ name, schema, control, errors, geometry, fieldKey, index, sx, autoFocus, disabled, height, onValueChange, ...other }: GeometryFieldBySchemaProps): React.JSX.Element | undefined;
|
|
8
|
+
//# sourceMappingURL=GeometryFieldBySchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeometryFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/GeometryFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGhF,MAAM,WAAW,0BAA0B,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,CAAE,SAAQ,kBAAkB,CAAC,CAAC,CAAC;IAChG,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAC5C,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,EAAc,EACd,SAAS,EACT,QAAQ,EACR,MAAM,EACN,aAAa,EACb,GAAG,KAAK,EACT,EAAE,0BAA0B,iCAqE5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.default = GeometryFieldBySchema;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
20
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
21
|
+
const utils_1 = require("../../../utils");
|
|
22
|
+
const MapGeometryPicker_1 = __importDefault(require("./MapGeometryPicker"));
|
|
23
|
+
function GeometryFieldBySchema(_a) {
|
|
24
|
+
var _b;
|
|
25
|
+
var { name, schema, control, errors, geometry, fieldKey, index, sx = { mr: 2 }, autoFocus, disabled, height, onValueChange } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "geometry", "fieldKey", "index", "sx", "autoFocus", "disabled", "height", "onValueChange"]);
|
|
26
|
+
if (!(name in schema)) {
|
|
27
|
+
console.error(`GeometryFieldBySchema: could not find schema for ${name}! Not rendering`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const fieldSchema = schema[name];
|
|
31
|
+
if (fieldKey && index && index >= 0) {
|
|
32
|
+
name = `${fieldKey}.${index}.${name}`;
|
|
33
|
+
}
|
|
34
|
+
const { error, helperText } = fieldKey && index && index >= 0
|
|
35
|
+
? (0, utils_1.errorProps)({ fieldKey, index, fieldKeyProp: name, errors })
|
|
36
|
+
: {
|
|
37
|
+
error: errors && Boolean(errors[name]),
|
|
38
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
39
|
+
};
|
|
40
|
+
const mapAvailable = Boolean((0, utils_1.getMapLibraries)());
|
|
41
|
+
const multiline = geometry !== 'point';
|
|
42
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => {
|
|
43
|
+
const currentValue = (0, utils_1.geometryValueToString)(field.value);
|
|
44
|
+
if (mapAvailable) {
|
|
45
|
+
return (react_1.default.createElement(MapGeometryPicker_1.default, { geometry: geometry, value: currentValue, onChange: (geoJSON) => {
|
|
46
|
+
field.onChange(geoJSON);
|
|
47
|
+
if (onValueChange)
|
|
48
|
+
onValueChange(geoJSON);
|
|
49
|
+
}, label: fieldSchema.label, error: error, helperText: helperText, height: height }));
|
|
50
|
+
}
|
|
51
|
+
return (react_1.default.createElement(TextField_1.default, Object.assign({}, other, { id: name, value: currentValue, label: fieldSchema.label, required: (0, utils_1.isFieldRequired)(fieldSchema), disabled: fieldSchema.disabled === true || disabled, onChange: (e) => {
|
|
52
|
+
field.onChange(e.target.value);
|
|
53
|
+
if (onValueChange)
|
|
54
|
+
onValueChange(e);
|
|
55
|
+
}, margin: "normal", fullWidth: true, multiline: multiline, minRows: multiline ? 4 : 0, error: error, helperText: helperText, sx: sx, autoFocus: autoFocus })));
|
|
56
|
+
} }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
3
|
+
import 'leaflet/dist/leaflet.css';
|
|
4
|
+
import 'leaflet-draw';
|
|
5
|
+
import 'leaflet-draw/dist/leaflet.draw.css';
|
|
6
|
+
import { GeometryFieldType } from '../../../@types';
|
|
7
|
+
interface MapGeometryPickerProps {
|
|
8
|
+
geometry: GeometryFieldType;
|
|
9
|
+
value: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
onChange: (geoJSON: string | null) => void;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
helperText?: string;
|
|
14
|
+
sx?: SxProps<Theme>;
|
|
15
|
+
height?: number;
|
|
16
|
+
}
|
|
17
|
+
export default function MapGeometryPicker({ geometry, value, label, onChange, error, helperText, sx, height, }: MapGeometryPickerProps): React.JSX.Element;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=MapGeometryPicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapGeometryPicker.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/MapGeometryPicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAIjD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,0BAA0B,CAAC;AAElC,OAAO,cAAc,CAAC;AACtB,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA4LD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,QAAQ,EACR,KAAK,EACL,KAAK,EACL,QAAQ,EACR,KAAK,EACL,UAAU,EACV,EAAE,EACF,MAAY,GACb,EAAE,sBAAsB,qBAwDxB"}
|
|
@@ -0,0 +1,250 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = MapGeometryPicker;
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
42
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
43
|
+
const FormHelperText_1 = __importDefault(require("@mui/material/FormHelperText"));
|
|
44
|
+
const react_leaflet_1 = require("react-leaflet");
|
|
45
|
+
const leaflet_1 = __importDefault(require("leaflet"));
|
|
46
|
+
require("leaflet/dist/leaflet.css");
|
|
47
|
+
// leaflet-draw does not export; augments global L with Control.Draw.
|
|
48
|
+
require("leaflet-draw");
|
|
49
|
+
require("leaflet-draw/dist/leaflet.draw.css");
|
|
50
|
+
const utils_1 = require("../../../utils");
|
|
51
|
+
// Build the drf-react-by-schema geometry out of leaflet-draw features. Leaflet
|
|
52
|
+
// already parses/produces GeoJSON (L.geoJSON, FeatureGroup.toGeoJSON), so here
|
|
53
|
+
// we only reshape the resulting features into the right geometry type.
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
function buildOutput(geometry, features) {
|
|
56
|
+
const geoms = features.map((f) => f === null || f === void 0 ? void 0 : f.geometry).filter((g) => g);
|
|
57
|
+
if (geometry === 'point') {
|
|
58
|
+
const point = geoms.find((g) => g.type === 'Point');
|
|
59
|
+
return point ? { type: 'Point', coordinates: point.coordinates } : null;
|
|
60
|
+
}
|
|
61
|
+
if (geometry === 'polygon') {
|
|
62
|
+
const polygon = geoms.find((g) => g.type === 'Polygon');
|
|
63
|
+
return polygon ? { type: 'Polygon', coordinates: polygon.coordinates } : null;
|
|
64
|
+
}
|
|
65
|
+
if (geometry === 'multipoint') {
|
|
66
|
+
const coords = geoms.filter((g) => g.type === 'Point').map((g) => g.coordinates);
|
|
67
|
+
return coords.length ? { type: 'MultiPoint', coordinates: coords } : null;
|
|
68
|
+
}
|
|
69
|
+
if (geometry === 'multipolygon') {
|
|
70
|
+
const coords = geoms.filter((g) => g.type === 'Polygon').map((g) => g.coordinates);
|
|
71
|
+
return coords.length ? { type: 'MultiPolygon', coordinates: coords } : null;
|
|
72
|
+
}
|
|
73
|
+
// geometrycollection: points and polygons drawn together
|
|
74
|
+
const list = geoms.filter((g) => g.type === 'Point' || g.type === 'Polygon');
|
|
75
|
+
return list.length ? { type: 'GeometryCollection', geometries: list } : null;
|
|
76
|
+
}
|
|
77
|
+
// Counts the markers/polygons currently drawn so single-instance fields can
|
|
78
|
+
// hide their "add" tool once one shape already exists.
|
|
79
|
+
function layerCounts(featureGroup) {
|
|
80
|
+
let markers = 0;
|
|
81
|
+
let polygons = 0;
|
|
82
|
+
featureGroup.eachLayer((layer) => {
|
|
83
|
+
if (layer instanceof leaflet_1.default.Marker)
|
|
84
|
+
markers += 1;
|
|
85
|
+
else if (layer instanceof leaflet_1.default.Polygon)
|
|
86
|
+
polygons += 1;
|
|
87
|
+
});
|
|
88
|
+
return { markers, polygons };
|
|
89
|
+
}
|
|
90
|
+
// Which draw tools each geometry allows.
|
|
91
|
+
const markerEnabledFor = (g) => g === 'point' || g === 'multipoint' || g === 'geometrycollection';
|
|
92
|
+
const polygonEnabledFor = (g) => g === 'polygon' || g === 'multipolygon' || g === 'geometrycollection';
|
|
93
|
+
// Attaches leaflet-draw to the react-leaflet map and emits GeoJSON on changes.
|
|
94
|
+
// Per-geometry behavior:
|
|
95
|
+
// point / polygon -> single instance (add hidden once one exists; move/remove)
|
|
96
|
+
// multipoint -> many draggable/removable points
|
|
97
|
+
// multipolygon -> many editable/removable polygons
|
|
98
|
+
// geometrycollection -> many points AND many polygons
|
|
99
|
+
function DrawEditor({ geometry, value, onChange, }) {
|
|
100
|
+
const map = (0, react_leaflet_1.useMap)();
|
|
101
|
+
const featureGroupRef = (0, react_1.useRef)(null);
|
|
102
|
+
const drawControlRef = (0, react_1.useRef)(null);
|
|
103
|
+
const lastEmittedRef = (0, react_1.useRef)('__init__');
|
|
104
|
+
const onChangeRef = (0, react_1.useRef)(onChange);
|
|
105
|
+
onChangeRef.current = onChange;
|
|
106
|
+
const geometryRef = (0, react_1.useRef)(geometry);
|
|
107
|
+
geometryRef.current = geometry;
|
|
108
|
+
// Hides the add tool for single-instance fields once a shape exists; existing
|
|
109
|
+
// shapes stay draggable (points) / editable (polygons) and removable.
|
|
110
|
+
const updateCap = () => {
|
|
111
|
+
const featureGroup = featureGroupRef.current;
|
|
112
|
+
const drawControl = drawControlRef.current;
|
|
113
|
+
if (!featureGroup || !drawControl)
|
|
114
|
+
return;
|
|
115
|
+
const g = geometryRef.current;
|
|
116
|
+
const { markers, polygons } = layerCounts(featureGroup);
|
|
117
|
+
const single = isSingle(g);
|
|
118
|
+
const capMarker = single && g === 'point' && markers > 0;
|
|
119
|
+
const capPolygon = single && g === 'polygon' && polygons > 0;
|
|
120
|
+
drawControl.setDrawingOptions({
|
|
121
|
+
marker: markerEnabledFor(g) && !capMarker ? {} : false,
|
|
122
|
+
polygon: polygonEnabledFor(g) && !capPolygon ? {} : false,
|
|
123
|
+
polyline: false,
|
|
124
|
+
rectangle: false,
|
|
125
|
+
circle: false,
|
|
126
|
+
circlemarker: false,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const emit = () => {
|
|
130
|
+
var _a;
|
|
131
|
+
const featureGroup = featureGroupRef.current;
|
|
132
|
+
if (!featureGroup)
|
|
133
|
+
return;
|
|
134
|
+
const g = geometryRef.current;
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
+
const output = buildOutput(g, ((_a = featureGroup.toGeoJSON()) === null || _a === void 0 ? void 0 : _a.features) || []);
|
|
137
|
+
const text = output ? JSON.stringify(output) : '';
|
|
138
|
+
lastEmittedRef.current = text;
|
|
139
|
+
onChangeRef.current(text || null);
|
|
140
|
+
updateCap();
|
|
141
|
+
};
|
|
142
|
+
// Markers are draggable so an existing point can be moved; drag-end updates value.
|
|
143
|
+
const applyBehaviors = (layer) => {
|
|
144
|
+
if (layer instanceof leaflet_1.default.Marker) {
|
|
145
|
+
layer.options.draggable = true;
|
|
146
|
+
layer.on('dragend', emit);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
+
const addGeoJSON = (data) => {
|
|
151
|
+
const featureGroup = featureGroupRef.current;
|
|
152
|
+
if (!featureGroup || !data)
|
|
153
|
+
return;
|
|
154
|
+
leaflet_1.default.geoJSON(data).eachLayer((layer) => {
|
|
155
|
+
featureGroup.addLayer(layer);
|
|
156
|
+
applyBehaviors(layer);
|
|
157
|
+
});
|
|
158
|
+
const bounds = featureGroup.getBounds();
|
|
159
|
+
if (bounds.isValid())
|
|
160
|
+
map.fitBounds(bounds, { padding: [40, 40] });
|
|
161
|
+
};
|
|
162
|
+
(0, react_1.useEffect)(() => {
|
|
163
|
+
const featureGroup = new leaflet_1.default.FeatureGroup().addTo(map);
|
|
164
|
+
featureGroupRef.current = featureGroup;
|
|
165
|
+
const g = geometryRef.current;
|
|
166
|
+
const drawControl = new leaflet_1.default.Control.Draw({
|
|
167
|
+
draw: {
|
|
168
|
+
marker: markerEnabledFor(g) ? {} : false,
|
|
169
|
+
polygon: polygonEnabledFor(g) ? {} : false,
|
|
170
|
+
polyline: false,
|
|
171
|
+
rectangle: false,
|
|
172
|
+
circle: false,
|
|
173
|
+
circlemarker: false,
|
|
174
|
+
},
|
|
175
|
+
edit: { featureGroup },
|
|
176
|
+
});
|
|
177
|
+
drawControlRef.current = drawControl;
|
|
178
|
+
map.addControl(drawControl);
|
|
179
|
+
map.on(leaflet_1.default.Draw.Event.CREATED,
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
|
+
(e) => {
|
|
182
|
+
featureGroup.addLayer(e.layer);
|
|
183
|
+
applyBehaviors(e.layer);
|
|
184
|
+
emit();
|
|
185
|
+
});
|
|
186
|
+
map.on(leaflet_1.default.Draw.Event.EDITED, emit);
|
|
187
|
+
map.on(leaflet_1.default.Draw.Event.DELETED, emit);
|
|
188
|
+
const initial = (0, utils_1.parseGeoJSON)(geometry, value);
|
|
189
|
+
if (initial)
|
|
190
|
+
addGeoJSON(initial);
|
|
191
|
+
updateCap();
|
|
192
|
+
return () => {
|
|
193
|
+
map.removeControl(drawControl);
|
|
194
|
+
map.removeLayer(featureGroup);
|
|
195
|
+
featureGroupRef.current = null;
|
|
196
|
+
drawControlRef.current = null;
|
|
197
|
+
};
|
|
198
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
199
|
+
}, []);
|
|
200
|
+
// Sync externally-driven value (reset after save/edit elsewhere). Avoids the
|
|
201
|
+
// feedback loop when this component itself emitted the change. Malformed text
|
|
202
|
+
// keeps the last valid geometry on the map (an error is shown in the field);
|
|
203
|
+
// only a legitimate empty value clears the features.
|
|
204
|
+
(0, react_1.useEffect)(() => {
|
|
205
|
+
const normalized = value || '';
|
|
206
|
+
if (normalized === lastEmittedRef.current)
|
|
207
|
+
return;
|
|
208
|
+
lastEmittedRef.current = normalized;
|
|
209
|
+
const featureGroup = featureGroupRef.current;
|
|
210
|
+
if (!featureGroup)
|
|
211
|
+
return;
|
|
212
|
+
const geo = (0, utils_1.parseGeoJSON)(geometry, value);
|
|
213
|
+
if (geo) {
|
|
214
|
+
featureGroup.clearLayers();
|
|
215
|
+
addGeoJSON(geo);
|
|
216
|
+
}
|
|
217
|
+
else if (normalized.trim() === '') {
|
|
218
|
+
featureGroup.clearLayers();
|
|
219
|
+
updateCap();
|
|
220
|
+
}
|
|
221
|
+
// malformed non-empty text: keep current features, error is shown in the field
|
|
222
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
223
|
+
}, [value, geometry, map]);
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function MapGeometryPicker({ geometry, value, label, onChange, error, helperText, sx, height = 340, }) {
|
|
227
|
+
const valueText = value || '';
|
|
228
|
+
// Malformed detection: non-empty text that isn't GeoJSON (or of the wrong
|
|
229
|
+
// geometry type). Invalid input is flagged as an error instead of silently
|
|
230
|
+
// wiping the features from the map.
|
|
231
|
+
const malformed = valueText.trim() !== '' && !(0, utils_1.parseGeoJSON)(geometry, valueText);
|
|
232
|
+
return (react_1.default.createElement(Box_1.default, { sx: Object.assign({ mt: 1, mb: 1, width: '100%' }, sx) },
|
|
233
|
+
react_1.default.createElement(Box_1.default, { "data-testid": `map-${geometry}`, sx: {
|
|
234
|
+
height,
|
|
235
|
+
width: '100%',
|
|
236
|
+
overflow: 'hidden',
|
|
237
|
+
borderRadius: 1,
|
|
238
|
+
border: (t) => `1px solid ${error ? t.palette.error.main : t.palette.divider}`,
|
|
239
|
+
zIndex: 1 /* keep leaflet controls above MUI overlays */,
|
|
240
|
+
} },
|
|
241
|
+
react_1.default.createElement(react_leaflet_1.MapContainer, { center: [-14.235, -51.9253], zoom: 4, style: { height: '100%', width: '100%' }, zoomControl: true },
|
|
242
|
+
react_1.default.createElement(react_leaflet_1.TileLayer, { attribution: "\u00A9 OpenStreetMap contributors", url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" }),
|
|
243
|
+
react_1.default.createElement(DrawEditor, { geometry: geometry, value: value, onChange: onChange }))),
|
|
244
|
+
react_1.default.createElement(TextField_1.default, { value: value, onChange: (e) => onChange(e.target.value || null), variant: "outlined", margin: "dense", fullWidth: true, size: "small", label: geometry === 'point' ? 'Coordenadas (GeoJSON)' : 'GeoJSON (cole aqui)', multiline: geometry !== 'point', minRows: geometry !== 'point' ? 3 : 1, sx: { mt: 1 }, error: malformed, helperText: malformed
|
|
245
|
+
? 'Dados malformados, corrija o GeoJSON para refletir no mapa.'
|
|
246
|
+
: 'O GeoJSON abaixo é sincronizado com o mapa.' }),
|
|
247
|
+
label && react_1.default.createElement(FormHelperText_1.default, { sx: { mt: 0.5 } }, label),
|
|
248
|
+
(helperText || error) && (react_1.default.createElement(FormHelperText_1.default, { error: error, sx: { mt: 0.5 } }, helperText))));
|
|
249
|
+
}
|
|
250
|
+
const isSingle = (g) => g === 'point' || g === 'polygon';
|