@opengeoweb/form-fields 17.0.1 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +22 -9
- package/readme.mdx +7 -0
- package/index.d.ts +0 -1
- package/index.esm.js +0 -1278
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/form-fields",
|
|
3
|
-
"version": "17.0
|
|
3
|
+
"version": "17.2.0",
|
|
4
4
|
"description": "GeoWeb form-fields library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git@gitlab.com:opengeoweb/opengeoweb.git"
|
|
9
9
|
},
|
|
10
|
+
"main": "./dist/index.esm.js",
|
|
11
|
+
"module": "./dist/index.esm.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
".": {
|
|
16
|
+
"@opengeoweb/source": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"default": "./dist/index.esm.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
10
22
|
"dependencies": {
|
|
11
|
-
"@opengeoweb/theme": "
|
|
23
|
+
"@opengeoweb/theme": "*",
|
|
12
24
|
"react-hook-form": "^7.50.1",
|
|
13
25
|
"@mui/x-date-pickers": "^8.11.2",
|
|
14
|
-
"lodash": "^4.
|
|
15
|
-
"@opengeoweb/shared": "
|
|
26
|
+
"lodash": "^4.18.1",
|
|
27
|
+
"@opengeoweb/shared": "*",
|
|
16
28
|
"react-i18next": "^15.1.1",
|
|
17
29
|
"@mui/material": "^7.0.1",
|
|
18
30
|
"i18next": "^25.0.1",
|
|
@@ -26,8 +38,9 @@
|
|
|
26
38
|
"devDependencies": {
|
|
27
39
|
"eslint-plugin-storybook": "10.3.3"
|
|
28
40
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"package.json"
|
|
45
|
+
]
|
|
46
|
+
}
|
package/readme.mdx
ADDED
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.esm.js
DELETED
|
@@ -1,1278 +0,0 @@
|
|
|
1
|
-
import { FormControl, FormHelperText, InputLabel, Select, RadioGroup, TextField, InputAdornment } from '@mui/material';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import { useFormContext, useController, useForm, FormProvider, Controller } from 'react-hook-form';
|
|
4
|
-
import { isEqual } from 'lodash';
|
|
5
|
-
import { dateUtils } from '@opengeoweb/shared';
|
|
6
|
-
import 'i18next';
|
|
7
|
-
import { useTranslation } from 'react-i18next';
|
|
8
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
9
|
-
import { DateTimePicker } from '@mui/x-date-pickers';
|
|
10
|
-
import { CalendarToday } from '@opengeoweb/theme';
|
|
11
|
-
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
|
|
12
|
-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
13
|
-
|
|
14
|
-
var en = {
|
|
15
|
-
"form-fields-error-required": "This field is required",
|
|
16
|
-
"form-fields-error-date-valid": "Not a valid date",
|
|
17
|
-
"form-fields-error-date-after": "Date should not be before",
|
|
18
|
-
"form-fields-error-date-hours-before": "Date is too far in the past",
|
|
19
|
-
"form-fields-error-date-hours-after": "Date is too far in the future",
|
|
20
|
-
"form-fields-error-date-before": "Timestamp too late",
|
|
21
|
-
"form-fields-error-min-level": "The minimum level is 1",
|
|
22
|
-
"form-fields-error-latitude": "Invalid latitude, expected number with maximum two decimal degrees between -90.00 and 90.00",
|
|
23
|
-
"form-fields-error-longitude": "Invalid longitude, expected number with maximum two decimal degrees between -180.00 and 180.00",
|
|
24
|
-
"form-fields-error-latitude-minutes": "Latitude must be between -90° and 90°",
|
|
25
|
-
"form-fields-error-longitude-minutes": "Longitude must be between -180° and 180°",
|
|
26
|
-
"form-fields-error-valid-max": "The maximum value is exceeded",
|
|
27
|
-
"form-fields-error-level-lower": "The lower level has to be below the upper level",
|
|
28
|
-
"form-fields-error-non-or-both-cooordinates": "Please enter both coordinates",
|
|
29
|
-
"form-fields-error-integer": "Invalid entry, enter a non-decimal number",
|
|
30
|
-
"form-fields-error-numeric": "Invalid entry, enter a numeric value"
|
|
31
|
-
};
|
|
32
|
-
var fi = {
|
|
33
|
-
"form-fields-error-required": "Tämä kenttä vaaditaan",
|
|
34
|
-
"form-fields-error-date-valid": "Epäkelpo päivämäärä",
|
|
35
|
-
"form-fields-error-date-after": "Päivämäärä ei voi olla aiemmin valittua ajanhetkeä",
|
|
36
|
-
"form-fields-error-date-hours-before": "Päivämäärä on liian kaukanan menneisyydessä",
|
|
37
|
-
"form-fields-error-date-hours-after": "Päivämäärä on liian kaukana tulevaisuudessa",
|
|
38
|
-
"form-fields-error-date-before": "Aikaleima on ajallisesti liian myöhään",
|
|
39
|
-
"form-fields-error-min-level": "Pienin sallittu taso on 1",
|
|
40
|
-
"form-fields-error-latitude": "Virheellinen leveysaste, odotettu arvo on kahden desimaalin tarkkuudella -90.00 ja 90.00 asteen välissä",
|
|
41
|
-
"form-fields-error-longitude": "Virheellinen pituusaste, odotettu arvo on kahden desimaalin tarkkuudella -180 ja 180 asteen välissä",
|
|
42
|
-
"form-fields-error-valid-max": "Maksimiarvo on ylitetty",
|
|
43
|
-
"form-fields-error-level-lower": "Alemman tason arvon on oltava ylemmän tason alla",
|
|
44
|
-
"form-fields-error-non-or-both-cooordinates": "Lisää molemmat kordinaatit",
|
|
45
|
-
"form-fields-error-integer": "Epäkelpo arvo, lisää kokonaisluku",
|
|
46
|
-
"form-fields-error-numeric": "Epäkelpo arvo, lisää numeerinen arvo"
|
|
47
|
-
};
|
|
48
|
-
var no = {
|
|
49
|
-
"form-fields-error-required": "This field is required",
|
|
50
|
-
"form-fields-error-date-valid": "Not a valid date",
|
|
51
|
-
"form-fields-error-date-after": "Date should not be before",
|
|
52
|
-
"form-fields-error-date-hours-before": "Date is too far in the past",
|
|
53
|
-
"form-fields-error-date-hours-after": "Date is too far in the future",
|
|
54
|
-
"form-fields-error-date-before": "Timestamp too late",
|
|
55
|
-
"form-fields-error-min-level": "The minimum level is 1",
|
|
56
|
-
"form-fields-error-latitude": "Invalid latitude, expected number with maximum two decimal degrees between -90.00 and 90.00",
|
|
57
|
-
"form-fields-error-longitude": "Invalid longitude, expected number with maximum two decimal degrees between -180.00 and 180.00",
|
|
58
|
-
"form-fields-error-latitude-minutes": "Latitude must be between -90° and 90°",
|
|
59
|
-
"form-fields-error-longitude-minutes": "Longitude must be between -180° and 180°",
|
|
60
|
-
"form-fields-error-valid-max": "The maximum value is exceeded",
|
|
61
|
-
"form-fields-error-level-lower": "The lower level has to be below the upper level",
|
|
62
|
-
"form-fields-error-non-or-both-cooordinates": "Please enter both coordinates",
|
|
63
|
-
"form-fields-error-integer": "Invalid entry, enter a non-decimal number",
|
|
64
|
-
"form-fields-error-numeric": "Invalid entry, enter a numeric value"
|
|
65
|
-
};
|
|
66
|
-
var nl = {
|
|
67
|
-
"form-fields-error-required": "Dit veld is verplicht",
|
|
68
|
-
"form-fields-error-date-valid": "Geen geldige datum",
|
|
69
|
-
"form-fields-error-date-after": "Datum mag niet in het verleden liggen",
|
|
70
|
-
"form-fields-error-date-hours-before": "Datum ligt te ver in het verleden",
|
|
71
|
-
"form-fields-error-date-hours-after": "Datum ligt te ver in de toekomst",
|
|
72
|
-
"form-fields-error-date-before": "Tijdsaanduiding is te laat",
|
|
73
|
-
"form-fields-error-min-level": "Het minimum niveau is 1",
|
|
74
|
-
"form-fields-error-latitude": "Ongeldige breedtegraad, er wordt een getal verwacht van maximaal 2 decimalen in graden tussen -90.00 en 90.00",
|
|
75
|
-
"form-fields-error-longitude": "Ongeldige lengtegraad, er wordt een getal verwacht van maximaal 2 decimalen in graden tussen -180.00 en 180.00",
|
|
76
|
-
"form-fields-error-valid-max": "Het maximum niveau is bereikt",
|
|
77
|
-
"form-fields-error-level-lower": "Het lage niveau moet onder het hoge niveau zijn",
|
|
78
|
-
"form-fields-error-non-or-both-cooordinates": "Voer beide coördinaten in",
|
|
79
|
-
"form-fields-error-integer": "Ongeldige invoer, voer een niet decimaal getal in",
|
|
80
|
-
"form-fields-error-numeric": "Ongeldige invoer, voor een numerieke waarde in"
|
|
81
|
-
};
|
|
82
|
-
var formFieldsTranslations = {
|
|
83
|
-
en: en,
|
|
84
|
-
fi: fi,
|
|
85
|
-
no: no,
|
|
86
|
-
nl: nl
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
90
|
-
if (null == r) return {};
|
|
91
|
-
var t = {};
|
|
92
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
93
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
94
|
-
t[n] = r[n];
|
|
95
|
-
}
|
|
96
|
-
return t;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/* *
|
|
100
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
101
|
-
* you may not use this file except in compliance with the License.
|
|
102
|
-
* You may obtain a copy of the License at
|
|
103
|
-
*
|
|
104
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
-
*
|
|
106
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
107
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
108
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
109
|
-
* See the License for the specific language governing permissions and
|
|
110
|
-
* limitations under the License.
|
|
111
|
-
*
|
|
112
|
-
* Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
113
|
-
* Copyright 2023 - Finnish Meteorological Institute (FMI)
|
|
114
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
115
|
-
* */
|
|
116
|
-
|
|
117
|
-
function getDeepProperty(property, state) {
|
|
118
|
-
return property.reduce(function (xs, x) {
|
|
119
|
-
if (xs && typeof xs === 'object' && x in xs) {
|
|
120
|
-
return xs[x];
|
|
121
|
-
}
|
|
122
|
-
return null;
|
|
123
|
-
}, state);
|
|
124
|
-
}
|
|
125
|
-
var getErrors = function getErrors(name, errors) {
|
|
126
|
-
var _getDeepProperty;
|
|
127
|
-
var nameAsArray = name.split('.');
|
|
128
|
-
return (_getDeepProperty = getDeepProperty(nameAsArray, errors)) != null ? _getDeepProperty : undefined;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/* *
|
|
132
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
133
|
-
* you may not use this file except in compliance with the License.
|
|
134
|
-
* You may obtain a copy of the License at
|
|
135
|
-
*
|
|
136
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
137
|
-
*
|
|
138
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
139
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
140
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
141
|
-
* See the License for the specific language governing permissions and
|
|
142
|
-
* limitations under the License.
|
|
143
|
-
*
|
|
144
|
-
* Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
145
|
-
* Copyright 2021 - Finnish Meteorological Institute (FMI)
|
|
146
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
147
|
-
* */
|
|
148
|
-
|
|
149
|
-
var defaultProps = {
|
|
150
|
-
shouldUnregister: false
|
|
151
|
-
};
|
|
152
|
-
var errorMessages = {
|
|
153
|
-
required: 'form-fields-error-required',
|
|
154
|
-
isValidDate: 'form-fields-error-date-valid',
|
|
155
|
-
isAfter: 'form-fields-error-date-after',
|
|
156
|
-
isXHoursBefore: 'form-fields-error-date-hours-before',
|
|
157
|
-
isXHoursAfter: 'form-fields-error-date-hours-after',
|
|
158
|
-
isBefore: 'form-fields-error-date-before',
|
|
159
|
-
minLevel: 'form-fields-error-min-level',
|
|
160
|
-
isLatitude: 'form-fields-error-latitude',
|
|
161
|
-
isLongitude: 'form-fields-error-longitude',
|
|
162
|
-
isValidMax: 'form-fields-error-valid-max',
|
|
163
|
-
isLevelLower: 'form-fields-error-level-lower',
|
|
164
|
-
isNonOrBothCoordinates: 'form-fields-error-non-or-both-cooordinate',
|
|
165
|
-
isInteger: 'form-fields-error-integer',
|
|
166
|
-
isNumeric: 'form-fields-error-numeric'
|
|
167
|
-
};
|
|
168
|
-
var regexMaxTwoDecimals = /^\s*-?\d+(\.\d{1,2})?\s*$/;
|
|
169
|
-
|
|
170
|
-
// validations
|
|
171
|
-
var isEmpty = function isEmpty(value) {
|
|
172
|
-
if (typeof value === 'string' && !value.trim().length || value === null || value === undefined) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
};
|
|
177
|
-
var isXHoursBefore = function isXHoursBefore(ownDate, otherDate, hours) {
|
|
178
|
-
if (hours === void 0) {
|
|
179
|
-
hours = 4;
|
|
180
|
-
}
|
|
181
|
-
if (isEmpty(ownDate) || isEmpty(otherDate)) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
var duration = dateUtils.differenceInHours(dateUtils.utc(otherDate), dateUtils.utc(ownDate), 'ceil');
|
|
185
|
-
return duration <= hours;
|
|
186
|
-
};
|
|
187
|
-
var isXHoursAfter = function isXHoursAfter(ownDate, otherDate, hours) {
|
|
188
|
-
if (hours === void 0) {
|
|
189
|
-
hours = 4;
|
|
190
|
-
}
|
|
191
|
-
if (isEmpty(ownDate) || isEmpty(otherDate)) {
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
var duration = dateUtils.differenceInHours(dateUtils.utc(ownDate), dateUtils.utc(otherDate), 'ceil');
|
|
195
|
-
return duration <= hours;
|
|
196
|
-
};
|
|
197
|
-
var isLatitude = function isLatitude(lat) {
|
|
198
|
-
if (!lat) {
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
return isFinite(lat) && Math.abs(lat) <= 90 && regexMaxTwoDecimals.test(lat.toString());
|
|
202
|
-
};
|
|
203
|
-
var isLongitude = function isLongitude(lng) {
|
|
204
|
-
if (!lng) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
return isFinite(lng) && Math.abs(lng) <= 180 && lng >= -180 && regexMaxTwoDecimals.test(lng.toString());
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// Pass null if no maxValue
|
|
211
|
-
var isValidMax = function isValidMax(value, maxValue) {
|
|
212
|
-
if (isEmpty(value) || maxValue === null) {
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
return !(value > maxValue);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// Pass null if no minValue
|
|
219
|
-
var isValidMin = function isValidMin(value, minValue) {
|
|
220
|
-
if (isEmpty(value) || minValue === null) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
return !(value < minValue);
|
|
224
|
-
};
|
|
225
|
-
var hasValidGeometry = function hasValidGeometry(geojson) {
|
|
226
|
-
var _geojson$features, _geojson$features$0$g;
|
|
227
|
-
if (!(geojson != null && (_geojson$features = geojson.features) != null && _geojson$features.length) ||
|
|
228
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
!((_geojson$features$0$g = geojson.features[0].geometry) != null && _geojson$features$0$g.coordinates) || !geojson.features[0].geometry.type) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
return true;
|
|
234
|
-
};
|
|
235
|
-
var isValidGeoJsonCoordinates = function isValidGeoJsonCoordinates(geojson) {
|
|
236
|
-
var hasGeometry = hasValidGeometry(geojson);
|
|
237
|
-
if (!hasGeometry) {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
242
|
-
// @ts-ignore
|
|
243
|
-
var _geojson$features$0$g2 = geojson.features[0].geometry,
|
|
244
|
-
coordinates = _geojson$features$0$g2.coordinates,
|
|
245
|
-
type = _geojson$features$0$g2.type;
|
|
246
|
-
// For type POINT coordinates is an array of 2
|
|
247
|
-
if (coordinates.length === 2 && type === 'Point') {
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
// For type LINESTRING coordinates is an array of at least 2
|
|
251
|
-
if (coordinates.length > 1 && type === 'LineString') {
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
254
|
-
// For type POLYGON coordinates is an array of arrays
|
|
255
|
-
if (coordinates.length === 1 && coordinates[0].length > 0 && type === 'Polygon') {
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
return false;
|
|
259
|
-
};
|
|
260
|
-
var isMaximumOneDrawing = function isMaximumOneDrawing(geojson) {
|
|
261
|
-
if (!hasValidGeometry(geojson)) {
|
|
262
|
-
return true;
|
|
263
|
-
}
|
|
264
|
-
var geometry = geojson.features[0].geometry;
|
|
265
|
-
if (geometry.type === 'MultiPolygon') {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
if (geometry.type === 'Polygon' && geometry.coordinates.length > 1) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
return true;
|
|
272
|
-
};
|
|
273
|
-
var hasIntersectionWithFIR = function hasIntersectionWithFIR(geojson, intersection) {
|
|
274
|
-
var _geojson$features$, _geojson$features$2, _intersection$feature;
|
|
275
|
-
if (!hasValidGeometry(geojson) ||
|
|
276
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
277
|
-
// @ts-ignore
|
|
278
|
-
!geojson.features[0].geometry.coordinates.length || ((_geojson$features$ = geojson.features[0]) == null || (_geojson$features$ = _geojson$features$.geometry) == null ? void 0 : _geojson$features$.type) === 'Polygon' && !((_geojson$features$2 = geojson.features[0]) != null && (_geojson$features$2 = _geojson$features$2.geometry) != null && (_geojson$features$2 = _geojson$features$2.coordinates) != null && (_geojson$features$2 = _geojson$features$2[0]) != null && _geojson$features$2.length)) {
|
|
279
|
-
return true; // no need to check further when there is no drawing yet
|
|
280
|
-
}
|
|
281
|
-
if (!(intersection != null && intersection.features) || intersection.features.length === 0 || !((_intersection$feature = intersection.features[0]) != null && _intersection$feature.geometry)) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
286
|
-
// @ts-ignore
|
|
287
|
-
var _intersection$feature2 = intersection.features[0].geometry,
|
|
288
|
-
coordinates = _intersection$feature2.coordinates,
|
|
289
|
-
type = _intersection$feature2.type;
|
|
290
|
-
if (type === 'Point' && coordinates.length === 0) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
if (type !== 'Point' && coordinates.length > 0 && coordinates[0].length === 0) {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
return true;
|
|
297
|
-
};
|
|
298
|
-
var hasMulitpleIntersections = function hasMulitpleIntersections(geojson) {
|
|
299
|
-
var hasGeometry = hasValidGeometry(geojson);
|
|
300
|
-
if (!hasGeometry) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
304
|
-
// @ts-ignore
|
|
305
|
-
var _geojson$features$0$g3 = geojson.features[0].geometry,
|
|
306
|
-
coordinates = _geojson$features$0$g3.coordinates,
|
|
307
|
-
type = _geojson$features$0$g3.type;
|
|
308
|
-
if (type === 'MultiPolygon' || coordinates.length > 1 && type !== 'Point') {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
return false;
|
|
312
|
-
};
|
|
313
|
-
var countIntersectionPoints = function countIntersectionPoints(geojson, intersection) {
|
|
314
|
-
var _geojson$features2, _intersection$feature3;
|
|
315
|
-
if (!(geojson != null && (_geojson$features2 = geojson.features) != null && (_geojson$features2 = _geojson$features2[0]) != null && _geojson$features2.geometry) || !(intersection != null && (_intersection$feature3 = intersection.features) != null && (_intersection$feature3 = _intersection$feature3[0]) != null && _intersection$feature3.geometry)) {
|
|
316
|
-
return 0;
|
|
317
|
-
}
|
|
318
|
-
var geojsonGeometry = geojson.features[0].geometry;
|
|
319
|
-
var intersectionGeometry = intersection.features[0].geometry;
|
|
320
|
-
if (geojsonGeometry.type !== 'Polygon' || intersectionGeometry.type !== 'Polygon') {
|
|
321
|
-
return 0;
|
|
322
|
-
}
|
|
323
|
-
var geojsonCoordinates = geojsonGeometry.coordinates[0];
|
|
324
|
-
var intersectionCoordinates = intersectionGeometry.coordinates[0];
|
|
325
|
-
|
|
326
|
-
// If both arrays are empty, return 0
|
|
327
|
-
if (!geojsonCoordinates && !intersectionCoordinates) {
|
|
328
|
-
return 0;
|
|
329
|
-
}
|
|
330
|
-
var intersectionPoints = intersectionCoordinates.map(function (point) {
|
|
331
|
-
return [point[0], point[1]];
|
|
332
|
-
});
|
|
333
|
-
var uniqueIntersectionPoints = intersectionPoints.filter(function (point, index, self) {
|
|
334
|
-
return index === self.findIndex(function (otherPoint) {
|
|
335
|
-
return otherPoint[0] === point[0] && otherPoint[1] === point[1];
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
var collisionPoints = uniqueIntersectionPoints.filter(function (point) {
|
|
339
|
-
var x = point[0],
|
|
340
|
-
y = point[1];
|
|
341
|
-
return !geojsonCoordinates.some(function (originalPoint) {
|
|
342
|
-
return originalPoint[0] === x && originalPoint[1] === y;
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
return collisionPoints.length;
|
|
346
|
-
};
|
|
347
|
-
var isGeometryDirty = function isGeometryDirty(geoJSON, formGeoJSON) {
|
|
348
|
-
if (!geoJSON || !formGeoJSON || !hasValidGeometry(geoJSON) || !hasValidGeometry(formGeoJSON)) {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
return !isEqual(
|
|
352
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
353
|
-
// @ts-ignore
|
|
354
|
-
geoJSON.features[0].geometry.coordinates,
|
|
355
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
356
|
-
// @ts-ignore
|
|
357
|
-
formGeoJSON.features[0].geometry.coordinates);
|
|
358
|
-
};
|
|
359
|
-
var isInteger = function isInteger(value) {
|
|
360
|
-
if (isEmpty(value)) {
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
return Number.isInteger(value);
|
|
364
|
-
};
|
|
365
|
-
var isNonOrBothCoordinates = function isNonOrBothCoordinates(coordinate, otherCoordinate) {
|
|
366
|
-
if (typeof coordinate === 'number' && typeof otherCoordinate === 'number' || coordinate === null && otherCoordinate === null || coordinate === undefined && otherCoordinate === undefined) {
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
if (typeof coordinate === 'number') {
|
|
370
|
-
return true;
|
|
371
|
-
}
|
|
372
|
-
return false;
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
/* *
|
|
376
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
377
|
-
* you may not use this file except in compliance with the License.
|
|
378
|
-
* You may obtain a copy of the License at
|
|
379
|
-
*
|
|
380
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
381
|
-
*
|
|
382
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
383
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
384
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
385
|
-
* See the License for the specific language governing permissions and
|
|
386
|
-
* limitations under the License.
|
|
387
|
-
*
|
|
388
|
-
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
389
|
-
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
390
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
391
|
-
* */
|
|
392
|
-
|
|
393
|
-
var FORM_FIELDS_NAMESPACE = 'form-fields';
|
|
394
|
-
var ns = [FORM_FIELDS_NAMESPACE];
|
|
395
|
-
var useFormFieldsTranslation = function useFormFieldsTranslation() {
|
|
396
|
-
return useTranslation(ns);
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
var _excluded$6 = ["children", "errors", "isReadOnly", "sx", "className", "size"];
|
|
400
|
-
var radioCheckboxStyle = {
|
|
401
|
-
// hides unchecked values
|
|
402
|
-
display: 'none',
|
|
403
|
-
'&+.MuiFormControlLabel-label': {
|
|
404
|
-
display: 'none'
|
|
405
|
-
},
|
|
406
|
-
// shows checked value
|
|
407
|
-
'&.Mui-checked': {
|
|
408
|
-
display: 'inherit',
|
|
409
|
-
'&+.MuiFormControlLabel-label': {
|
|
410
|
-
display: 'inherit'
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
'&.Mui-checked+.MuiFormControlLabel-label': {
|
|
414
|
-
color: 'geowebColors.typographyAndIcons.text'
|
|
415
|
-
},
|
|
416
|
-
'&.Mui-disabled.Mui-checked': {
|
|
417
|
-
color: 'geowebColors.typographyAndIcons.iconLinkActive'
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
var getErrorMessage = function getErrorMessage(t, errors) {
|
|
421
|
-
if (errors && errors.message && typeof errors.message === 'string') {
|
|
422
|
-
return t(errors.message);
|
|
423
|
-
}
|
|
424
|
-
if (errors && errors.type && typeof errors.type === 'string') {
|
|
425
|
-
return t(errorMessages[errors.type]);
|
|
426
|
-
}
|
|
427
|
-
return '';
|
|
428
|
-
};
|
|
429
|
-
var ReactHookFormFormControl = function ReactHookFormFormControl(_ref) {
|
|
430
|
-
var children = _ref.children,
|
|
431
|
-
errors = _ref.errors,
|
|
432
|
-
isReadOnly = _ref.isReadOnly,
|
|
433
|
-
_ref$sx = _ref.sx,
|
|
434
|
-
sx = _ref$sx === void 0 ? {} : _ref$sx,
|
|
435
|
-
_ref$className = _ref.className,
|
|
436
|
-
className = _ref$className === void 0 ? '' : _ref$className,
|
|
437
|
-
_ref$size = _ref.size,
|
|
438
|
-
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
439
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
440
|
-
var _useFormFieldsTransla = useFormFieldsTranslation(),
|
|
441
|
-
t = _useFormFieldsTransla.t;
|
|
442
|
-
return /*#__PURE__*/jsxs(FormControl, Object.assign({
|
|
443
|
-
className: (isReadOnly ? 'is-read-only' : '') + " " + className,
|
|
444
|
-
error: !!errors,
|
|
445
|
-
fullWidth: true,
|
|
446
|
-
size: size,
|
|
447
|
-
sx: Object.assign({}, isReadOnly && {
|
|
448
|
-
// Radio input
|
|
449
|
-
'.MuiRadio-root': radioCheckboxStyle,
|
|
450
|
-
// Checkbox input
|
|
451
|
-
'.MuiCheckbox-root': radioCheckboxStyle,
|
|
452
|
-
// Select input
|
|
453
|
-
'.MuiSelect-select.Mui-disabled': {
|
|
454
|
-
color: 'geowebColors.typographyAndIcons.text',
|
|
455
|
-
WebkitTextFillColor: 'inherit',
|
|
456
|
-
'&:before': {
|
|
457
|
-
borderColor: 'transparent'
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
'.MuiSelect-nativeInput+.MuiSvgIcon-root': {
|
|
461
|
-
display: 'none'
|
|
462
|
-
},
|
|
463
|
-
'.Mui-disabled:before': {
|
|
464
|
-
border: 'transparent'
|
|
465
|
-
}
|
|
466
|
-
}, Array.isArray(sx) ? Object.assign.apply(Object, [{}].concat(sx)) : sx)
|
|
467
|
-
}, props, {
|
|
468
|
-
children: [children, errors ? /*#__PURE__*/jsx(FormHelperText, {
|
|
469
|
-
role: "alert",
|
|
470
|
-
variant: "filled",
|
|
471
|
-
children: getErrorMessage(t, errors)
|
|
472
|
-
}) : null]
|
|
473
|
-
}));
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
var _excluded$5 = ["name", "label", "defaultValue", "children", "rules", "onBeforeChange", "onChange", "disabled", "className", "sx", "isReadOnly", "size"];
|
|
477
|
-
var ReactHookFormSelect = function ReactHookFormSelect(_ref) {
|
|
478
|
-
var name = _ref.name,
|
|
479
|
-
label = _ref.label,
|
|
480
|
-
_ref$defaultValue = _ref.defaultValue,
|
|
481
|
-
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
482
|
-
children = _ref.children,
|
|
483
|
-
rules = _ref.rules,
|
|
484
|
-
_ref$onBeforeChange = _ref.onBeforeChange,
|
|
485
|
-
onBeforeChange = _ref$onBeforeChange === void 0 ? function () {} : _ref$onBeforeChange,
|
|
486
|
-
_ref$onChange = _ref.onChange,
|
|
487
|
-
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
488
|
-
disabled = _ref.disabled,
|
|
489
|
-
className = _ref.className,
|
|
490
|
-
sx = _ref.sx,
|
|
491
|
-
isReadOnly = _ref.isReadOnly,
|
|
492
|
-
_ref$size = _ref.size,
|
|
493
|
-
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
494
|
-
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
495
|
-
var labelId = name + "-label";
|
|
496
|
-
var _useFormContext = useFormContext(),
|
|
497
|
-
control = _useFormContext.control;
|
|
498
|
-
var _useController = useController(Object.assign({
|
|
499
|
-
name: name,
|
|
500
|
-
control: control,
|
|
501
|
-
rules: rules,
|
|
502
|
-
defaultValue: defaultValue
|
|
503
|
-
}, defaultProps)),
|
|
504
|
-
_useController$field = _useController.field,
|
|
505
|
-
onChangeField = _useController$field.onChange,
|
|
506
|
-
value = _useController$field.value,
|
|
507
|
-
ref = _useController$field.ref,
|
|
508
|
-
formErrors = _useController.formState.errors;
|
|
509
|
-
var errors = getErrors(name, formErrors);
|
|
510
|
-
return /*#__PURE__*/jsxs(ReactHookFormFormControl, {
|
|
511
|
-
className: className,
|
|
512
|
-
disabled: disabled,
|
|
513
|
-
errors: errors,
|
|
514
|
-
isReadOnly: isReadOnly,
|
|
515
|
-
size: size,
|
|
516
|
-
sx: sx,
|
|
517
|
-
children: [/*#__PURE__*/jsx(InputLabel, {
|
|
518
|
-
id: labelId,
|
|
519
|
-
variant: "filled",
|
|
520
|
-
children: label
|
|
521
|
-
}), /*#__PURE__*/jsx(Select, Object.assign({
|
|
522
|
-
inputRef: ref,
|
|
523
|
-
label: label,
|
|
524
|
-
labelId: labelId,
|
|
525
|
-
name: name,
|
|
526
|
-
onChange: function onChange(changeEvent, child) {
|
|
527
|
-
onBeforeChange();
|
|
528
|
-
onChangeField(changeEvent.target.value);
|
|
529
|
-
// default props
|
|
530
|
-
_onChange(changeEvent, child);
|
|
531
|
-
},
|
|
532
|
-
value: value != null ? value : '',
|
|
533
|
-
variant: "filled"
|
|
534
|
-
}, otherProps, {
|
|
535
|
-
children: children
|
|
536
|
-
}))]
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
var _excluded$4 = ["name", "label", "defaultValue", "children", "rules", "disabled", "onChange", "isReadOnly"];
|
|
541
|
-
var ReactHookFormRadioGroup = function ReactHookFormRadioGroup(_ref) {
|
|
542
|
-
var name = _ref.name,
|
|
543
|
-
label = _ref.label,
|
|
544
|
-
_ref$defaultValue = _ref.defaultValue,
|
|
545
|
-
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
546
|
-
children = _ref.children,
|
|
547
|
-
rules = _ref.rules,
|
|
548
|
-
_ref$disabled = _ref.disabled,
|
|
549
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
550
|
-
_ref$onChange = _ref.onChange,
|
|
551
|
-
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
552
|
-
isReadOnly = _ref.isReadOnly,
|
|
553
|
-
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
554
|
-
var labelId = name + "-label";
|
|
555
|
-
var _useFormContext = useFormContext(),
|
|
556
|
-
control = _useFormContext.control;
|
|
557
|
-
var _useController = useController(Object.assign({
|
|
558
|
-
name: name,
|
|
559
|
-
control: control,
|
|
560
|
-
rules: rules,
|
|
561
|
-
defaultValue: defaultValue
|
|
562
|
-
}, defaultProps)),
|
|
563
|
-
_useController$field = _useController.field,
|
|
564
|
-
onChangeField = _useController$field.onChange,
|
|
565
|
-
value = _useController$field.value,
|
|
566
|
-
ref = _useController$field.ref,
|
|
567
|
-
formErrors = _useController.formState.errors;
|
|
568
|
-
var errors = getErrors(name, formErrors);
|
|
569
|
-
React.useEffect(function () {
|
|
570
|
-
if (errors) {
|
|
571
|
-
var firstError = Object.keys(formErrors)[0];
|
|
572
|
-
if (firstError === name) {
|
|
573
|
-
// if first error in form is same, focus on that input
|
|
574
|
-
var inputNode = document.querySelector("[name=\"" + name + "\"]");
|
|
575
|
-
if (inputNode !== null) {
|
|
576
|
-
inputNode.focus();
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}, [errors, formErrors, name]);
|
|
581
|
-
return /*#__PURE__*/jsxs(ReactHookFormFormControl, {
|
|
582
|
-
disabled: disabled,
|
|
583
|
-
errors: errors,
|
|
584
|
-
isReadOnly: isReadOnly,
|
|
585
|
-
children: [/*#__PURE__*/jsx(InputLabel, {
|
|
586
|
-
id: labelId,
|
|
587
|
-
children: label
|
|
588
|
-
}), /*#__PURE__*/jsx(RadioGroup, Object.assign({
|
|
589
|
-
name: name,
|
|
590
|
-
onChange: function onChange(changeEvent) {
|
|
591
|
-
onChangeField(changeEvent.target.value);
|
|
592
|
-
_onChange(changeEvent, changeEvent.target.value);
|
|
593
|
-
},
|
|
594
|
-
ref: ref,
|
|
595
|
-
value: value
|
|
596
|
-
}, otherProps, {
|
|
597
|
-
children: children
|
|
598
|
-
}))]
|
|
599
|
-
});
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
var _excluded$3 = ["name", "label", "defaultValue", "rules", "disabled", "upperCase", "helperText", "className", "sx", "onChange", "isReadOnly", "inputSlotProps"];
|
|
603
|
-
var convertTextInputValue = function convertTextInputValue(value, inCapitals) {
|
|
604
|
-
return inCapitals ? value.toUpperCase() : value;
|
|
605
|
-
};
|
|
606
|
-
var ReactHookFormTextField = function ReactHookFormTextField(_ref) {
|
|
607
|
-
var name = _ref.name,
|
|
608
|
-
label = _ref.label,
|
|
609
|
-
_ref$defaultValue = _ref.defaultValue,
|
|
610
|
-
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
611
|
-
rules = _ref.rules,
|
|
612
|
-
_ref$disabled = _ref.disabled,
|
|
613
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
614
|
-
_ref$upperCase = _ref.upperCase,
|
|
615
|
-
upperCase = _ref$upperCase === void 0 ? false : _ref$upperCase,
|
|
616
|
-
_ref$helperText = _ref.helperText,
|
|
617
|
-
helperText = _ref$helperText === void 0 ? '' : _ref$helperText,
|
|
618
|
-
className = _ref.className,
|
|
619
|
-
sx = _ref.sx,
|
|
620
|
-
_ref$onChange = _ref.onChange,
|
|
621
|
-
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
622
|
-
isReadOnly = _ref.isReadOnly,
|
|
623
|
-
inputSlotProps = _ref.inputSlotProps,
|
|
624
|
-
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
625
|
-
var _useFormContext = useFormContext(),
|
|
626
|
-
control = _useFormContext.control;
|
|
627
|
-
var _useController = useController(Object.assign({
|
|
628
|
-
name: name,
|
|
629
|
-
control: control,
|
|
630
|
-
rules: rules,
|
|
631
|
-
defaultValue: defaultValue
|
|
632
|
-
}, defaultProps)),
|
|
633
|
-
_useController$field = _useController.field,
|
|
634
|
-
onChangeField = _useController$field.onChange,
|
|
635
|
-
value = _useController$field.value,
|
|
636
|
-
ref = _useController$field.ref,
|
|
637
|
-
formErrors = _useController.formState.errors;
|
|
638
|
-
var errors = getErrors(name, formErrors);
|
|
639
|
-
return /*#__PURE__*/jsx(ReactHookFormFormControl, {
|
|
640
|
-
className: className,
|
|
641
|
-
disabled: disabled,
|
|
642
|
-
errors: errors,
|
|
643
|
-
isReadOnly: isReadOnly,
|
|
644
|
-
sx: sx,
|
|
645
|
-
children: /*#__PURE__*/jsx(TextField, Object.assign({
|
|
646
|
-
disabled: disabled,
|
|
647
|
-
error: !!errors,
|
|
648
|
-
helperText: helperText,
|
|
649
|
-
inputRef: ref,
|
|
650
|
-
label: label,
|
|
651
|
-
name: name,
|
|
652
|
-
onChange: function onChange(evt) {
|
|
653
|
-
var value = evt.target.value;
|
|
654
|
-
var convertedValue = convertTextInputValue(value, upperCase);
|
|
655
|
-
onChangeField(convertedValue);
|
|
656
|
-
_onChange(null);
|
|
657
|
-
},
|
|
658
|
-
type: "text",
|
|
659
|
-
value: value,
|
|
660
|
-
variant: "filled"
|
|
661
|
-
}, otherProps, {
|
|
662
|
-
slotProps: Object.assign({}, otherProps.slotProps, {
|
|
663
|
-
input: Object.assign({}, inputSlotProps, isReadOnly && {
|
|
664
|
-
readOnly: true
|
|
665
|
-
})
|
|
666
|
-
})
|
|
667
|
-
}))
|
|
668
|
-
});
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
var _excluded$2 = ["name", "label", "defaultValue", "rules", "disabled", "inputMode", "helperText", "className", "size", "sx", "onBeforeChange", "onChange", "isReadOnly"];
|
|
672
|
-
var convertNumericInputValue = function convertNumericInputValue(value, inputMode) {
|
|
673
|
-
if (value !== '' && !isNaN(parseFloat(value))) {
|
|
674
|
-
return inputMode === 'numeric' ? parseInt(value, 10) : parseFloat(value);
|
|
675
|
-
}
|
|
676
|
-
return null;
|
|
677
|
-
};
|
|
678
|
-
var getAllowedKeys = function getAllowedKeys(inputMode) {
|
|
679
|
-
if (inputMode === void 0) {
|
|
680
|
-
inputMode = 'numeric';
|
|
681
|
-
}
|
|
682
|
-
var allowedKeys = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', 'Backspace', 'ArrowRight', 'ArrowLeft', 'Tab', 'Home', 'End', 'PageDown', 'PageUp', 'Delete'].concat(inputMode === 'decimal' ? ['.'] : []);
|
|
683
|
-
return allowedKeys;
|
|
684
|
-
};
|
|
685
|
-
var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
|
|
686
|
-
var _otherProps$slotProps;
|
|
687
|
-
var name = _ref.name,
|
|
688
|
-
label = _ref.label,
|
|
689
|
-
_ref$defaultValue = _ref.defaultValue,
|
|
690
|
-
defaultValue = _ref$defaultValue === void 0 ? null : _ref$defaultValue,
|
|
691
|
-
rules = _ref.rules,
|
|
692
|
-
_ref$disabled = _ref.disabled,
|
|
693
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
694
|
-
_ref$inputMode = _ref.inputMode,
|
|
695
|
-
inputMode = _ref$inputMode === void 0 ? 'numeric' : _ref$inputMode,
|
|
696
|
-
_ref$helperText = _ref.helperText,
|
|
697
|
-
helperText = _ref$helperText === void 0 ? '' : _ref$helperText,
|
|
698
|
-
className = _ref.className,
|
|
699
|
-
_ref$size = _ref.size,
|
|
700
|
-
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
701
|
-
sx = _ref.sx,
|
|
702
|
-
_ref$onBeforeChange = _ref.onBeforeChange,
|
|
703
|
-
onBeforeChange = _ref$onBeforeChange === void 0 ? function () {} : _ref$onBeforeChange,
|
|
704
|
-
_ref$onChange = _ref.onChange,
|
|
705
|
-
_onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
706
|
-
isReadOnly = _ref.isReadOnly,
|
|
707
|
-
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
708
|
-
var _useFormContext = useFormContext(),
|
|
709
|
-
control = _useFormContext.control;
|
|
710
|
-
var _useController = useController(Object.assign({
|
|
711
|
-
name: name,
|
|
712
|
-
control: control,
|
|
713
|
-
rules: rules,
|
|
714
|
-
defaultValue: defaultValue
|
|
715
|
-
}, defaultProps)),
|
|
716
|
-
_useController$field = _useController.field,
|
|
717
|
-
onChangeField = _useController$field.onChange,
|
|
718
|
-
value = _useController$field.value,
|
|
719
|
-
ref = _useController$field.ref,
|
|
720
|
-
formErrors = _useController.formState.errors;
|
|
721
|
-
var errors = getErrors(name, formErrors);
|
|
722
|
-
var allowedKeyes = getAllowedKeys(inputMode);
|
|
723
|
-
var onPaste = function onPaste(event) {
|
|
724
|
-
var clipboardText = event.clipboardData.getData('text/plain');
|
|
725
|
-
var inputElement = event.target;
|
|
726
|
-
var before = inputElement.value.slice(0, inputElement.selectionStart);
|
|
727
|
-
var after = inputElement.value.slice(inputElement.selectionEnd);
|
|
728
|
-
var newValue = before + clipboardText + after;
|
|
729
|
-
if (inputMode === 'numeric' && !/^-?[0-9]+$/.exec(newValue)) {
|
|
730
|
-
event.preventDefault();
|
|
731
|
-
}
|
|
732
|
-
if (inputMode === 'decimal' && !/^-?[0-9]*(.[0-9]+)?$/.exec(newValue)) {
|
|
733
|
-
event.preventDefault();
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
var onKeyDown = function onKeyDown(event) {
|
|
737
|
-
var isMac = window.navigator.userAgent.includes(' Mac ');
|
|
738
|
-
if (isMac && event.metaKey || !isMac && event.ctrlKey) {
|
|
739
|
-
if (['c', 'v', 'x'].includes(event.key.toLowerCase())) {
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
if (!allowedKeyes.includes(event.key) ||
|
|
744
|
-
// only allow one seperator
|
|
745
|
-
event.key === '.' && event.target.value.includes('.') ||
|
|
746
|
-
// only allow one -
|
|
747
|
-
event.key === '-' && event.target.value.includes('-')) {
|
|
748
|
-
event.preventDefault();
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
// Transform number value to string for display, following React Hook Form transform pattern
|
|
753
|
-
var formatValueForDisplay = React.useCallback(function (numValue) {
|
|
754
|
-
if (numValue === null || numValue === undefined || isNaN(numValue)) {
|
|
755
|
-
return '';
|
|
756
|
-
}
|
|
757
|
-
return String(numValue);
|
|
758
|
-
}, []);
|
|
759
|
-
|
|
760
|
-
// Local state to preserve string precision during editing (e.g., trailing zeros), only sync from form value when not actively editing
|
|
761
|
-
var _React$useState = React.useState(null),
|
|
762
|
-
localValue = _React$useState[0],
|
|
763
|
-
setLocalValue = _React$useState[1];
|
|
764
|
-
var isFocusedRef = React.useRef(false);
|
|
765
|
-
var previousValueRef = React.useRef(value);
|
|
766
|
-
var lastSetValueRef = React.useRef(null);
|
|
767
|
-
|
|
768
|
-
// Sync local value from form value when value changes externally, but only when not actively editing and the change wasn't from our own update
|
|
769
|
-
React.useEffect(function () {
|
|
770
|
-
if (!isFocusedRef.current && value !== previousValueRef.current) {
|
|
771
|
-
var wasOurUpdate = lastSetValueRef.current !== null && lastSetValueRef.current === value;
|
|
772
|
-
if (!wasOurUpdate) {
|
|
773
|
-
setLocalValue(null); // Clear local value to use form value
|
|
774
|
-
} else if (localValue !== null) {
|
|
775
|
-
// It was our update, but check if localValue still represents this number accurately
|
|
776
|
-
var numFromLocal = convertNumericInputValue(localValue, inputMode);
|
|
777
|
-
if (numFromLocal !== value) {
|
|
778
|
-
// Local value no longer matches form value, clear it
|
|
779
|
-
setLocalValue(null);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
previousValueRef.current = value;
|
|
783
|
-
}
|
|
784
|
-
}, [value, localValue, inputMode]);
|
|
785
|
-
|
|
786
|
-
// Compute display value: prefer local value if it has more precision than number representation
|
|
787
|
-
var displayValue = React.useMemo(function () {
|
|
788
|
-
// Always use local value if it exists and represents the same number as form value
|
|
789
|
-
if (localValue !== null) {
|
|
790
|
-
var numFromLocal = convertNumericInputValue(localValue, inputMode);
|
|
791
|
-
var valuesMatch = numFromLocal === value || numFromLocal === null && value === null || numFromLocal !== null && typeof numFromLocal === 'number' && typeof value === 'number' && isNaN(numFromLocal) && isNaN(value);
|
|
792
|
-
if (valuesMatch) {
|
|
793
|
-
return localValue;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
// When no local value or it doesn't match, use formatted form value
|
|
797
|
-
return formatValueForDisplay(value);
|
|
798
|
-
}, [value, localValue, inputMode, formatValueForDisplay]);
|
|
799
|
-
return /*#__PURE__*/jsx(ReactHookFormFormControl, {
|
|
800
|
-
className: className,
|
|
801
|
-
disabled: disabled,
|
|
802
|
-
errors: errors,
|
|
803
|
-
isReadOnly: isReadOnly,
|
|
804
|
-
sx: sx,
|
|
805
|
-
children: /*#__PURE__*/jsx(TextField, Object.assign({
|
|
806
|
-
disabled: disabled,
|
|
807
|
-
error: !!errors,
|
|
808
|
-
helperText: helperText,
|
|
809
|
-
inputMode: inputMode,
|
|
810
|
-
inputRef: ref,
|
|
811
|
-
label: label,
|
|
812
|
-
name: name,
|
|
813
|
-
onBlur: function onBlur(evt) {
|
|
814
|
-
isFocusedRef.current = false;
|
|
815
|
-
// Keep local value on blur to preserve precision (e.g., trailing zeros), it will be cleared only if form value changes externally
|
|
816
|
-
previousValueRef.current = value;
|
|
817
|
-
otherProps.onBlur == null || otherProps.onBlur(evt);
|
|
818
|
-
},
|
|
819
|
-
onChange: function onChange(evt) {
|
|
820
|
-
var inputValue = evt.target.value;
|
|
821
|
-
// Update local value to preserve string precision during editing
|
|
822
|
-
setLocalValue(inputValue);
|
|
823
|
-
// Convert to number for form value
|
|
824
|
-
var numericValue = convertNumericInputValue(inputValue, inputMode);
|
|
825
|
-
lastSetValueRef.current = numericValue;
|
|
826
|
-
onBeforeChange();
|
|
827
|
-
onChangeField(numericValue);
|
|
828
|
-
_onChange(null);
|
|
829
|
-
},
|
|
830
|
-
onFocus: function onFocus(evt) {
|
|
831
|
-
isFocusedRef.current = true;
|
|
832
|
-
// Initialize local value with current display value when focusing
|
|
833
|
-
if (localValue === null) {
|
|
834
|
-
setLocalValue(formatValueForDisplay(value));
|
|
835
|
-
}
|
|
836
|
-
otherProps.onFocus == null || otherProps.onFocus(evt);
|
|
837
|
-
},
|
|
838
|
-
onKeyDown: onKeyDown,
|
|
839
|
-
size: size,
|
|
840
|
-
type: "text",
|
|
841
|
-
value: displayValue,
|
|
842
|
-
variant: "filled"
|
|
843
|
-
}, otherProps, {
|
|
844
|
-
slotProps: Object.assign({}, otherProps.slotProps, {
|
|
845
|
-
input: Object.assign({}, isReadOnly && {
|
|
846
|
-
readOnly: true
|
|
847
|
-
}, {
|
|
848
|
-
onPaste: onPaste
|
|
849
|
-
}),
|
|
850
|
-
htmlInput: Object.assign({}, (_otherProps$slotProps = otherProps.slotProps) == null ? void 0 : _otherProps$slotProps.htmlInput, {
|
|
851
|
-
inputMode: inputMode
|
|
852
|
-
})
|
|
853
|
-
})
|
|
854
|
-
}))
|
|
855
|
-
});
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
var _excluded$1 = ["name", "rules", "disabled", "label", "format", "openTo", "defaultNullValue", "helperText", "onChange", "className", "sx", "isReadOnly", "shouldHideUTC", "disablePast", "disableFuture"];
|
|
859
|
-
var OpenPicker = function OpenPicker() {
|
|
860
|
-
return /*#__PURE__*/jsx(CalendarToday, {});
|
|
861
|
-
};
|
|
862
|
-
var getTimezoneOffset = function getTimezoneOffset(value) {
|
|
863
|
-
return value.getTimezoneOffset() * 60000;
|
|
864
|
-
};
|
|
865
|
-
var makeLocalAppearUTC = function makeLocalAppearUTC(value) {
|
|
866
|
-
return new Date(value.getTime() + getTimezoneOffset(value));
|
|
867
|
-
};
|
|
868
|
-
var localToUTC = function localToUTC(dateTime) {
|
|
869
|
-
return new Date(dateTime.getTime() - getTimezoneOffset(dateTime));
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Should return an isostring in the form "YYYY-MM-DDThh:mmZ";
|
|
874
|
-
* The milli seconds section should not be included, strictly YYYY-MM-DDThh:mm:ssZ is important
|
|
875
|
-
* @param value input Date
|
|
876
|
-
* @returns iso string in YYYY-MM-DDThh:mm format.
|
|
877
|
-
*/
|
|
878
|
-
var getFormattedValueForDatePicker = function getFormattedValueForDatePicker(value) {
|
|
879
|
-
var _dateUtils$dateToStri;
|
|
880
|
-
return (_dateUtils$dateToStri = dateUtils.dateToString(value, "yyyy-MM-dd'T'HH:mm:00'Z'", true)) != null ? _dateUtils$dateToStri : null;
|
|
881
|
-
};
|
|
882
|
-
var getDateValue = function getDateValue(value) {
|
|
883
|
-
if (value) {
|
|
884
|
-
var _ref, _dateUtils$stringToDa;
|
|
885
|
-
var dateValue = (_ref = (_dateUtils$stringToDa = dateUtils.stringToDate(value, 'yyyy/MM/dd HH:mm', false)) != null ? _dateUtils$stringToDa : dateUtils.isoStringToDate(value, false)) != null ? _ref : null;
|
|
886
|
-
if (dateValue) {
|
|
887
|
-
return makeLocalAppearUTC(dateUtils.setSeconds(dateValue, 0));
|
|
888
|
-
}
|
|
889
|
-
return null;
|
|
890
|
-
}
|
|
891
|
-
return null;
|
|
892
|
-
};
|
|
893
|
-
var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_ref2) {
|
|
894
|
-
var name = _ref2.name,
|
|
895
|
-
rules = _ref2.rules,
|
|
896
|
-
disabled = _ref2.disabled,
|
|
897
|
-
_ref2$label = _ref2.label,
|
|
898
|
-
label = _ref2$label === void 0 ? 'Select date and time' : _ref2$label,
|
|
899
|
-
_ref2$format = _ref2.format,
|
|
900
|
-
format = _ref2$format === void 0 ? dateUtils.DATE_FORMAT_DATEPICKER : _ref2$format,
|
|
901
|
-
_ref2$openTo = _ref2.openTo,
|
|
902
|
-
openTo = _ref2$openTo === void 0 ? 'hours' : _ref2$openTo,
|
|
903
|
-
_ref2$defaultNullValu = _ref2.defaultNullValue,
|
|
904
|
-
defaultNullValue = _ref2$defaultNullValu === void 0 ? null : _ref2$defaultNullValu,
|
|
905
|
-
_ref2$helperText = _ref2.helperText,
|
|
906
|
-
helperText = _ref2$helperText === void 0 ? '' : _ref2$helperText,
|
|
907
|
-
_ref2$onChange = _ref2.onChange,
|
|
908
|
-
_onChange = _ref2$onChange === void 0 ? function () {} : _ref2$onChange,
|
|
909
|
-
className = _ref2.className,
|
|
910
|
-
sx = _ref2.sx,
|
|
911
|
-
isReadOnly = _ref2.isReadOnly,
|
|
912
|
-
shouldHideUTC = _ref2.shouldHideUTC,
|
|
913
|
-
disablePast = _ref2.disablePast,
|
|
914
|
-
disableFuture = _ref2.disableFuture,
|
|
915
|
-
otherProps = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
|
|
916
|
-
var _useFormContext = useFormContext(),
|
|
917
|
-
control = _useFormContext.control;
|
|
918
|
-
var _useController = useController(Object.assign({
|
|
919
|
-
name: name,
|
|
920
|
-
control: control,
|
|
921
|
-
rules: rules,
|
|
922
|
-
defaultValue: defaultNullValue
|
|
923
|
-
}, defaultProps)),
|
|
924
|
-
_useController$field = _useController.field,
|
|
925
|
-
onChangeField = _useController$field.onChange,
|
|
926
|
-
value = _useController$field.value,
|
|
927
|
-
ref = _useController$field.ref,
|
|
928
|
-
formErrors = _useController.formState.errors;
|
|
929
|
-
var errors = getErrors(name, formErrors);
|
|
930
|
-
|
|
931
|
-
// Ensure value is a Date object
|
|
932
|
-
|
|
933
|
-
var dateValue = getDateValue(value);
|
|
934
|
-
var now = makeLocalAppearUTC(dateUtils.utc());
|
|
935
|
-
var minDateTime = disablePast ? now : null;
|
|
936
|
-
var maxDateTime = disableFuture ? now : null;
|
|
937
|
-
return /*#__PURE__*/jsx(ReactHookFormFormControl, {
|
|
938
|
-
className: className,
|
|
939
|
-
disabled: disabled,
|
|
940
|
-
errors: errors,
|
|
941
|
-
isReadOnly: isReadOnly,
|
|
942
|
-
sx: sx,
|
|
943
|
-
children: /*#__PURE__*/jsx(DateTimePicker, Object.assign({
|
|
944
|
-
ampm: false,
|
|
945
|
-
desktopModeMediaQuery: "@media (min-width: 720px)",
|
|
946
|
-
disabled: disabled,
|
|
947
|
-
format: format,
|
|
948
|
-
inputRef: ref,
|
|
949
|
-
label: label,
|
|
950
|
-
maxDateTime: maxDateTime,
|
|
951
|
-
minDateTime: minDateTime,
|
|
952
|
-
onChange: function onChange(value) {
|
|
953
|
-
if (!value) {
|
|
954
|
-
_onChange(null);
|
|
955
|
-
onChangeField(null);
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
958
|
-
var formattedDate = getFormattedValueForDatePicker(localToUTC(value));
|
|
959
|
-
onChangeField(formattedDate);
|
|
960
|
-
_onChange(formattedDate);
|
|
961
|
-
},
|
|
962
|
-
openTo: openTo,
|
|
963
|
-
slotProps: {
|
|
964
|
-
textField: Object.assign({
|
|
965
|
-
variant: 'filled',
|
|
966
|
-
helperText: helperText,
|
|
967
|
-
error: !!errors,
|
|
968
|
-
name: name,
|
|
969
|
-
placeholder: disabled ? '' : format.toLowerCase(),
|
|
970
|
-
InputProps: Object.assign({}, !shouldHideUTC && {
|
|
971
|
-
endAdornment: /*#__PURE__*/jsx(InputAdornment, {
|
|
972
|
-
position: "end",
|
|
973
|
-
style: {
|
|
974
|
-
paddingTop: '16px'
|
|
975
|
-
},
|
|
976
|
-
children: "UTC"
|
|
977
|
-
})
|
|
978
|
-
}),
|
|
979
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
980
|
-
// @ts-ignore
|
|
981
|
-
'data-testid': otherProps['data-testid']
|
|
982
|
-
}, isReadOnly && {
|
|
983
|
-
readOnly: true
|
|
984
|
-
}),
|
|
985
|
-
field: {
|
|
986
|
-
openPickerButtonPosition: 'start'
|
|
987
|
-
},
|
|
988
|
-
openPickerButton: {
|
|
989
|
-
size: 'small',
|
|
990
|
-
sx: {
|
|
991
|
-
padding: 0
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
},
|
|
995
|
-
slots: {
|
|
996
|
-
openPickerIcon: OpenPicker
|
|
997
|
-
},
|
|
998
|
-
timeSteps: {
|
|
999
|
-
minutes: 1
|
|
1000
|
-
},
|
|
1001
|
-
value: dateValue
|
|
1002
|
-
}, otherProps))
|
|
1003
|
-
});
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
|
-
/* *
|
|
1007
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1008
|
-
* you may not use this file except in compliance with the License.
|
|
1009
|
-
* You may obtain a copy of the License at
|
|
1010
|
-
*
|
|
1011
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1012
|
-
*
|
|
1013
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1014
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1015
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1016
|
-
* See the License for the specific language governing permissions and
|
|
1017
|
-
* limitations under the License.
|
|
1018
|
-
*
|
|
1019
|
-
* Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1020
|
-
* Copyright 2021 - Finnish Meteorological Institute (FMI)
|
|
1021
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1022
|
-
* */
|
|
1023
|
-
var defaultFormOptions = {
|
|
1024
|
-
mode: 'onChange',
|
|
1025
|
-
reValidateMode: 'onChange'
|
|
1026
|
-
};
|
|
1027
|
-
var ReactHookFormProvider = function ReactHookFormProvider(_ref) {
|
|
1028
|
-
var children = _ref.children,
|
|
1029
|
-
_ref$options = _ref.options,
|
|
1030
|
-
options = _ref$options === void 0 ? defaultFormOptions : _ref$options;
|
|
1031
|
-
var formMethods = useForm(options);
|
|
1032
|
-
// added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
|
|
1033
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1034
|
-
// @ts-ignore
|
|
1035
|
-
return /*#__PURE__*/jsx(FormProvider, Object.assign({}, formMethods, {
|
|
1036
|
-
children: children
|
|
1037
|
-
}));
|
|
1038
|
-
};
|
|
1039
|
-
var ReactHookFormProviderWrapper = function ReactHookFormProviderWrapper(_ref2) {
|
|
1040
|
-
var children = _ref2.children,
|
|
1041
|
-
_ref2$options = _ref2.options,
|
|
1042
|
-
options = _ref2$options === void 0 ? defaultFormOptions : _ref2$options;
|
|
1043
|
-
return /*#__PURE__*/jsx(LocalizationProvider, {
|
|
1044
|
-
dateAdapter: AdapterDateFns,
|
|
1045
|
-
children: /*#__PURE__*/jsx(ReactHookFormProvider, {
|
|
1046
|
-
options: options,
|
|
1047
|
-
children: children
|
|
1048
|
-
})
|
|
1049
|
-
});
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
var _excluded = ["name", "defaultValue", "rules"];
|
|
1053
|
-
var ReactHookFormHiddenInput = function ReactHookFormHiddenInput(_ref) {
|
|
1054
|
-
var name = _ref.name,
|
|
1055
|
-
_ref$defaultValue = _ref.defaultValue,
|
|
1056
|
-
defaultValue = _ref$defaultValue === void 0 ? null : _ref$defaultValue,
|
|
1057
|
-
rules = _ref.rules,
|
|
1058
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1059
|
-
var _useFormContext = useFormContext(),
|
|
1060
|
-
control = _useFormContext.control;
|
|
1061
|
-
var _useController = useController(Object.assign({
|
|
1062
|
-
name: name,
|
|
1063
|
-
control: control,
|
|
1064
|
-
rules: rules,
|
|
1065
|
-
defaultValue: defaultValue
|
|
1066
|
-
}, defaultProps)),
|
|
1067
|
-
field = _useController.field;
|
|
1068
|
-
return field.value !== null ? /*#__PURE__*/jsx("input", Object.assign({}, field, {
|
|
1069
|
-
type: "hidden"
|
|
1070
|
-
}, props)) : null;
|
|
1071
|
-
};
|
|
1072
|
-
|
|
1073
|
-
/* *
|
|
1074
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1075
|
-
* you may not use this file except in compliance with the License.
|
|
1076
|
-
* You may obtain a copy of the License at
|
|
1077
|
-
*
|
|
1078
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1079
|
-
*
|
|
1080
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1081
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1082
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1083
|
-
* See the License for the specific language governing permissions and
|
|
1084
|
-
* limitations under the License.
|
|
1085
|
-
*
|
|
1086
|
-
* Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1087
|
-
* Copyright 2025 - Finnish Meteorological Institute (FMI)
|
|
1088
|
-
* Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
|
|
1089
|
-
* */
|
|
1090
|
-
|
|
1091
|
-
function decimalToDegreesMinutes(value) {
|
|
1092
|
-
var sign = value < 0 ? '-' : '';
|
|
1093
|
-
var abs = Math.abs(value);
|
|
1094
|
-
var degrees = Math.floor(abs);
|
|
1095
|
-
var minutes = Math.round((abs - degrees) * 60);
|
|
1096
|
-
|
|
1097
|
-
// normalize rounding overflow (e.g. 59.9 min → +1 degree)
|
|
1098
|
-
if (minutes === 60) {
|
|
1099
|
-
abs += 1;
|
|
1100
|
-
return decimalToDegreesMinutes(sign === '-' ? -abs : abs);
|
|
1101
|
-
}
|
|
1102
|
-
return "" + sign + degrees + "\xB0" + minutes.toString().padStart(2, '0') + "\u2032";
|
|
1103
|
-
}
|
|
1104
|
-
function degreesMinutesToDecimal(input) {
|
|
1105
|
-
var raw = input.toString().trim();
|
|
1106
|
-
var negative = raw.startsWith('-');
|
|
1107
|
-
var digits = raw.replace(/[^0-9]/g, '');
|
|
1108
|
-
var sign = negative ? -1 : 1;
|
|
1109
|
-
if (digits.length <= 2) {
|
|
1110
|
-
var _deg = parseInt(digits || '0', 10);
|
|
1111
|
-
return sign * _deg;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// split into degrees + minutes
|
|
1115
|
-
var deg = parseInt(digits.slice(0, digits.length - 2), 10);
|
|
1116
|
-
var min = parseInt(digits.slice(-2), 10);
|
|
1117
|
-
|
|
1118
|
-
// normalize minutes overflow (e.g. 65 → 1°05′)
|
|
1119
|
-
var extraDeg = Math.floor(min / 60);
|
|
1120
|
-
min %= 60;
|
|
1121
|
-
return sign * (deg + extraDeg + min / 60);
|
|
1122
|
-
}
|
|
1123
|
-
var DegreesMinutesField = function DegreesMinutesField(_ref) {
|
|
1124
|
-
var name = _ref.name,
|
|
1125
|
-
label = _ref.label,
|
|
1126
|
-
_ref$disabled = _ref.disabled,
|
|
1127
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1128
|
-
_ref$isReadOnly = _ref.isReadOnly,
|
|
1129
|
-
isReadOnly = _ref$isReadOnly === void 0 ? false : _ref$isReadOnly,
|
|
1130
|
-
_ref$size = _ref.size,
|
|
1131
|
-
size = _ref$size === void 0 ? 'small' : _ref$size,
|
|
1132
|
-
_ref$isLongitude = _ref.isLongitude,
|
|
1133
|
-
isLongitude = _ref$isLongitude === void 0 ? false : _ref$isLongitude,
|
|
1134
|
-
t = _ref.t;
|
|
1135
|
-
var _useFormContext = useFormContext(),
|
|
1136
|
-
control = _useFormContext.control;
|
|
1137
|
-
var _useState = useState(null),
|
|
1138
|
-
localInput = _useState[0],
|
|
1139
|
-
setLocalInput = _useState[1];
|
|
1140
|
-
var _useState2 = useState(false),
|
|
1141
|
-
isEditing = _useState2[0],
|
|
1142
|
-
setIsEditing = _useState2[1];
|
|
1143
|
-
return /*#__PURE__*/jsx(Controller, {
|
|
1144
|
-
control: control,
|
|
1145
|
-
name: name,
|
|
1146
|
-
render: function render(_ref2) {
|
|
1147
|
-
var _fieldState$error;
|
|
1148
|
-
var field = _ref2.field,
|
|
1149
|
-
fieldState = _ref2.fieldState;
|
|
1150
|
-
var value = field.value,
|
|
1151
|
-
onChange = field.onChange;
|
|
1152
|
-
var handleChange = function handleChange(e) {
|
|
1153
|
-
setLocalInput(e.target.value);
|
|
1154
|
-
setIsEditing(true);
|
|
1155
|
-
};
|
|
1156
|
-
var handleBlur = function handleBlur() {
|
|
1157
|
-
if (localInput != null && localInput !== '-' && localInput !== '') {
|
|
1158
|
-
var input = localInput.replace(/[^\d-]/g, '');
|
|
1159
|
-
var negative = input.startsWith('-');
|
|
1160
|
-
var digits = input.replace(/[^0-9]/g, '');
|
|
1161
|
-
|
|
1162
|
-
// Latitude: 4 digits (DDMM), Longitude: 5 (DDDMM)
|
|
1163
|
-
var maxLen = isLongitude ? 5 : 4;
|
|
1164
|
-
if (digits.length > maxLen) {
|
|
1165
|
-
digits = digits.slice(0, maxLen);
|
|
1166
|
-
}
|
|
1167
|
-
var normalized = negative ? "-" + digits : digits;
|
|
1168
|
-
try {
|
|
1169
|
-
var decimal = degreesMinutesToDecimal(normalized);
|
|
1170
|
-
onChange(decimal);
|
|
1171
|
-
} catch (_unused) {
|
|
1172
|
-
// Invalid, do not update form value
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
setIsEditing(false);
|
|
1176
|
-
setLocalInput(null);
|
|
1177
|
-
};
|
|
1178
|
-
var displayValue;
|
|
1179
|
-
if (isEditing) {
|
|
1180
|
-
displayValue = localInput != null ? localInput : '';
|
|
1181
|
-
} else if (value != null) {
|
|
1182
|
-
displayValue = decimalToDegreesMinutes(value);
|
|
1183
|
-
} else {
|
|
1184
|
-
displayValue = '';
|
|
1185
|
-
}
|
|
1186
|
-
return /*#__PURE__*/jsx(TextField, {
|
|
1187
|
-
disabled: disabled,
|
|
1188
|
-
error: !!fieldState.error,
|
|
1189
|
-
helperText: (_fieldState$error = fieldState.error) == null ? void 0 : _fieldState$error.message,
|
|
1190
|
-
label: label,
|
|
1191
|
-
onBlur: handleBlur,
|
|
1192
|
-
onChange: handleChange,
|
|
1193
|
-
placeholder: isLongitude ? 'DDD°MM′' : 'DD°MM′',
|
|
1194
|
-
size: size,
|
|
1195
|
-
slotProps: {
|
|
1196
|
-
input: {
|
|
1197
|
-
readOnly: isReadOnly
|
|
1198
|
-
}
|
|
1199
|
-
},
|
|
1200
|
-
value: displayValue
|
|
1201
|
-
});
|
|
1202
|
-
},
|
|
1203
|
-
rules: {
|
|
1204
|
-
validate: function validate(value) {
|
|
1205
|
-
if (value == null || isNaN(value)) {
|
|
1206
|
-
return true;
|
|
1207
|
-
} // let empty pass
|
|
1208
|
-
if (!isLongitude && (value < -90 || value > 90)) {
|
|
1209
|
-
return t('form-fields-error-latitude-minutes');
|
|
1210
|
-
}
|
|
1211
|
-
if (isLongitude && (value < -180 || value > 180)) {
|
|
1212
|
-
return t('form-fields-error-longitude-minutes');
|
|
1213
|
-
}
|
|
1214
|
-
return true;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
});
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
/* *
|
|
1221
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1222
|
-
* you may not use this file except in compliance with the License.
|
|
1223
|
-
* You may obtain a copy of the License at
|
|
1224
|
-
*
|
|
1225
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1226
|
-
*
|
|
1227
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1228
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1229
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1230
|
-
* See the License for the specific language governing permissions and
|
|
1231
|
-
* limitations under the License.
|
|
1232
|
-
*
|
|
1233
|
-
* Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
1234
|
-
* Copyright 2021 - Finnish Meteorological Institute (FMI)
|
|
1235
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
1236
|
-
* */
|
|
1237
|
-
var HIDDEN_INPUT_HELPER_IS_DRAFT = 'IS_DRAFT';
|
|
1238
|
-
var useDraftFormHelpers = function useDraftFormHelpers(isDefaultDraft) {
|
|
1239
|
-
if (isDefaultDraft === void 0) {
|
|
1240
|
-
isDefaultDraft = false;
|
|
1241
|
-
}
|
|
1242
|
-
var _useFormContext = useFormContext(),
|
|
1243
|
-
getValues = _useFormContext.getValues,
|
|
1244
|
-
setValue = _useFormContext.setValue,
|
|
1245
|
-
register = _useFormContext.register;
|
|
1246
|
-
React.useEffect(function () {
|
|
1247
|
-
setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDefaultDraft, {
|
|
1248
|
-
shouldDirty: false
|
|
1249
|
-
});
|
|
1250
|
-
}, [isDefaultDraft, setValue]);
|
|
1251
|
-
var isDraft = function isDraft() {
|
|
1252
|
-
return getValues(HIDDEN_INPUT_HELPER_IS_DRAFT) === true;
|
|
1253
|
-
};
|
|
1254
|
-
var isRequired = function isRequired(value) {
|
|
1255
|
-
if (!isDraft() && isEmpty(value)) {
|
|
1256
|
-
return errorMessages.required;
|
|
1257
|
-
}
|
|
1258
|
-
return true;
|
|
1259
|
-
};
|
|
1260
|
-
var toggleIsDraft = function toggleIsDraft(isDraft) {
|
|
1261
|
-
return setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDraft, {
|
|
1262
|
-
shouldDirty: false
|
|
1263
|
-
});
|
|
1264
|
-
};
|
|
1265
|
-
var DraftFieldHelper = function DraftFieldHelper() {
|
|
1266
|
-
return /*#__PURE__*/jsx("input", Object.assign({}, register(HIDDEN_INPUT_HELPER_IS_DRAFT), {
|
|
1267
|
-
type: "hidden"
|
|
1268
|
-
}));
|
|
1269
|
-
};
|
|
1270
|
-
return {
|
|
1271
|
-
isRequired: isRequired,
|
|
1272
|
-
toggleIsDraft: toggleIsDraft,
|
|
1273
|
-
isDraft: isDraft,
|
|
1274
|
-
DraftFieldHelper: DraftFieldHelper
|
|
1275
|
-
};
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
export { DegreesMinutesField, FORM_FIELDS_NAMESPACE, HIDDEN_INPUT_HELPER_IS_DRAFT, ReactHookKeyboardDateTimePicker as ReactHookFormDateTime, ReactHookFormFormControl, ReactHookFormHiddenInput, ReactHookFormNumberField, ReactHookFormProviderWrapper as ReactHookFormProvider, ReactHookFormRadioGroup, ReactHookFormSelect, ReactHookFormTextField, countIntersectionPoints, defaultFormOptions, errorMessages, formFieldsTranslations, getDateValue, getDeepProperty, getFormattedValueForDatePicker, hasIntersectionWithFIR, hasMulitpleIntersections, hasValidGeometry, isEmpty, isGeometryDirty, isInteger, isLatitude, isLongitude, isMaximumOneDrawing, isNonOrBothCoordinates, isValidGeoJsonCoordinates, isValidMax, isValidMin, isXHoursAfter, isXHoursBefore, useDraftFormHelpers };
|