drf-react-by-schema 0.28.0 → 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/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 -10
- 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/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/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 +18 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
- package/dist/components/forms/inputs/MapGeometryPicker.js +248 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- 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 +82 -19
- package/package.json +36 -2
package/dist/utils/utils.js
CHANGED
|
@@ -63,6 +63,9 @@ exports.extractFieldValue = extractFieldValue;
|
|
|
63
63
|
exports.buildConditionalVisibleBySchema = buildConditionalVisibleBySchema;
|
|
64
64
|
exports.showConditionalVisibleField = showConditionalVisibleField;
|
|
65
65
|
exports.showConditionalVisibleFieldObj = showConditionalVisibleFieldObj;
|
|
66
|
+
exports.getMapLibraries = getMapLibraries;
|
|
67
|
+
exports.geometryValueToString = geometryValueToString;
|
|
68
|
+
exports.parseGeoJSON = parseGeoJSON;
|
|
66
69
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
67
70
|
const Yup = __importStar(require("yup"));
|
|
68
71
|
const string_mask_1 = __importDefault(require("string-mask"));
|
|
@@ -202,6 +205,16 @@ const getYupValidator = (type) => {
|
|
|
202
205
|
case 'file upload':
|
|
203
206
|
yupFunc = Yup.object();
|
|
204
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;
|
|
205
218
|
// String-like types produced by SimpleMetadata but not needing
|
|
206
219
|
// specialized validation behave as plain strings:
|
|
207
220
|
case 'url':
|
|
@@ -223,14 +236,14 @@ const getYupValidator = (type) => {
|
|
|
223
236
|
return yupFunc.transform((v) => (v === '' ? null : v)).nullable();
|
|
224
237
|
};
|
|
225
238
|
function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, uiFields, }) {
|
|
226
|
-
var _a;
|
|
239
|
+
var _a, _b;
|
|
227
240
|
const yupValidator = {};
|
|
228
241
|
for (const entry of Object.entries(schema)) {
|
|
229
242
|
const [field, fieldSchema] = entry;
|
|
230
243
|
if (!data || !(field in data) || field === 'id' || skipFields.includes(field)) {
|
|
231
244
|
continue;
|
|
232
245
|
}
|
|
233
|
-
// OneToMany or ManyToMany:
|
|
246
|
+
// OneToMany or ManyToMany (built as an array-of-object schema):
|
|
234
247
|
if (fieldSchema.type === 'field' && ((_a = fieldSchema.child) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
235
248
|
yupValidator[field] =
|
|
236
249
|
extraValidators && field in extraValidators
|
|
@@ -241,27 +254,20 @@ function buildGenericYupValidationSchema({ data, schema, many = false, skipField
|
|
|
241
254
|
data: data[field],
|
|
242
255
|
uiFields,
|
|
243
256
|
});
|
|
244
|
-
continue;
|
|
245
257
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// data: data[key],
|
|
252
|
-
// extraValidators: key in extraValidators ? extraValidators[key] : {}
|
|
253
|
-
// });
|
|
254
|
-
// if (!field.model_required) {
|
|
255
|
-
// yupValidator[key] = yupValidator[key].nullable();
|
|
256
|
-
// }
|
|
257
|
-
// continue;
|
|
258
|
+
else {
|
|
259
|
+
yupValidator[field] =
|
|
260
|
+
extraValidators && field in extraValidators
|
|
261
|
+
? extraValidators[field]
|
|
262
|
+
: getYupValidator(fieldSchema.type);
|
|
258
263
|
}
|
|
259
|
-
yupValidator[field] =
|
|
260
|
-
extraValidators && field in extraValidators
|
|
261
|
-
? extraValidators[field]
|
|
262
|
-
: getYupValidator(fieldSchema.type);
|
|
263
264
|
if (isFieldRequired(fieldSchema, (uiFields || []).includes(field))) {
|
|
264
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
|
+
}
|
|
265
271
|
}
|
|
266
272
|
if (fieldSchema.max_length && fieldSchema.type === 'string') {
|
|
267
273
|
yupValidator[field] = yupValidator[field].max(parseInt(fieldSchema.max_length), `Este campo só pode ter no máximo ${fieldSchema.max_length} caracteres`);
|
|
@@ -847,3 +853,60 @@ function showConditionalVisibleFieldObj(field, conditionalVisible, values) {
|
|
|
847
853
|
.filter((item) => item.target === field);
|
|
848
854
|
return sources.length > 0;
|
|
849
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.28.
|
|
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",
|