@opengeoweb/form-fields 4.21.0 → 4.22.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.
Files changed (38) hide show
  1. package/index.js +40770 -0
  2. package/package.json +13 -13
  3. package/index.esm.js +0 -973
  4. package/index.umd.js +0 -945
  5. /package/{index.d.ts → src/index.d.ts} +0 -0
  6. /package/{lib → src/lib}/components/Providers.d.ts +0 -0
  7. /package/{lib → src/lib}/components/Providers.spec.d.ts +0 -0
  8. /package/{lib → src/lib}/components/ReactHookFormDateTime.d.ts +0 -0
  9. /package/{lib → src/lib}/components/ReactHookFormDateTime.spec.d.ts +0 -0
  10. /package/{lib → src/lib}/components/ReactHookFormDateTime.stories.d.ts +0 -0
  11. /package/{lib → src/lib}/components/ReactHookFormFormControl.d.ts +0 -0
  12. /package/{lib → src/lib}/components/ReactHookFormFormControl.spec.d.ts +0 -0
  13. /package/{lib → src/lib}/components/ReactHookFormHiddenInput.d.ts +0 -0
  14. /package/{lib → src/lib}/components/ReactHookFormHiddenInput.spec.d.ts +0 -0
  15. /package/{lib → src/lib}/components/ReactHookFormHiddenInput.stories.d.ts +0 -0
  16. /package/{lib → src/lib}/components/ReactHookFormNumberField.d.ts +0 -0
  17. /package/{lib → src/lib}/components/ReactHookFormNumberField.spec.d.ts +0 -0
  18. /package/{lib → src/lib}/components/ReactHookFormNumberField.stories.d.ts +0 -0
  19. /package/{lib → src/lib}/components/ReactHookFormProvider.d.ts +0 -0
  20. /package/{lib → src/lib}/components/ReactHookFormProvider.stories.d.ts +0 -0
  21. /package/{lib → src/lib}/components/ReactHookFormRadioGroup.d.ts +0 -0
  22. /package/{lib → src/lib}/components/ReactHookFormRadioGroup.spec.d.ts +0 -0
  23. /package/{lib → src/lib}/components/ReactHookFormRadioGroup.stories.d.ts +0 -0
  24. /package/{lib → src/lib}/components/ReactHookFormSelect.d.ts +0 -0
  25. /package/{lib → src/lib}/components/ReactHookFormSelect.spec.d.ts +0 -0
  26. /package/{lib → src/lib}/components/ReactHookFormSelect.stories.d.ts +0 -0
  27. /package/{lib → src/lib}/components/ReactHookFormTextField.d.ts +0 -0
  28. /package/{lib → src/lib}/components/ReactHookFormTextField.spec.d.ts +0 -0
  29. /package/{lib → src/lib}/components/ReactHookFormTextField.stories.d.ts +0 -0
  30. /package/{lib → src/lib}/components/formUtils.d.ts +0 -0
  31. /package/{lib → src/lib}/components/formUtils.spec.d.ts +0 -0
  32. /package/{lib → src/lib}/components/index.d.ts +0 -0
  33. /package/{lib → src/lib}/components/types.d.ts +0 -0
  34. /package/{lib → src/lib}/components/utils.d.ts +0 -0
  35. /package/{lib → src/lib}/components/utils.spec.d.ts +0 -0
  36. /package/{lib → src/lib}/hooks/useDraftFormHelpers/useDraftFormHelpers.d.ts +0 -0
  37. /package/{lib → src/lib}/hooks/useDraftFormHelpers/useDraftFormHelpers.spec.d.ts +0 -0
  38. /package/{lib → src/lib}/storyshots/Storyshots.spec.d.ts +0 -0
package/index.esm.js DELETED
@@ -1,973 +0,0 @@
1
- import * as React from 'react';
2
- import React__default from 'react';
3
- import { FormControl, FormHelperText, InputLabel, Select, RadioGroup, TextField, InputAdornment } from '@mui/material';
4
- import { useFormContext, useController, useForm, FormProvider } from 'react-hook-form';
5
- import moment from 'moment';
6
- import { isEqual } from 'lodash';
7
- import moment$1 from 'moment-timezone';
8
- import { DateTimePicker } from '@mui/x-date-pickers';
9
- import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
10
- import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
11
-
12
- /*! *****************************************************************************
13
- Copyright (c) Microsoft Corporation.
14
-
15
- Permission to use, copy, modify, and/or distribute this software for any
16
- purpose with or without fee is hereby granted.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
- PERFORMANCE OF THIS SOFTWARE.
25
- ***************************************************************************** */
26
-
27
- function __rest(s, e) {
28
- var t = {};
29
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
- t[p] = s[p];
31
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
- t[p[i]] = s[p[i]];
35
- }
36
- return t;
37
- }
38
-
39
- /* *
40
- * Licensed under the Apache License, Version 2.0 (the "License");
41
- * you may not use this file except in compliance with the License.
42
- * You may obtain a copy of the License at
43
- *
44
- * http://www.apache.org/licenses/LICENSE-2.0
45
- *
46
- * Unless required by applicable law or agreed to in writing, software
47
- * distributed under the License is distributed on an "AS IS" BASIS,
48
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
- * See the License for the specific language governing permissions and
50
- * limitations under the License.
51
- *
52
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
53
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
54
- * */
55
- var defaultProps = {
56
- shouldUnregister: false
57
- };
58
- var errorMessages = {
59
- required: 'This field is required',
60
- isValidDate: 'Not a valid date',
61
- isAfter: 'Date should not be before',
62
- isXHoursBefore: 'Date is too far in the past',
63
- isXHoursAfter: 'Date is too far in the future',
64
- isBefore: 'Timestamp too late',
65
- minLevel: 'The minimum level is 1',
66
- isLatitude: 'Invalid latitude, expected number with maximum two decimal degrees between -90.00 and 90.00',
67
- isLongitude: 'Invalid longitude, expected number with maximum two decimal degrees between -180.00 and 180.00',
68
- isValidMax: 'The maximum value is exceeded',
69
- isLevelLower: 'The lower level has to be below the upper level',
70
- isNonOrBothCoordinates: 'Please enter both coordinates',
71
- isInteger: 'Invalid entry, enter a non-decimal number',
72
- isNumeric: 'Invalid entry, enter a numeric value'
73
- };
74
- var regexMaxTwoDecimals = /^\s*-?\d+(\.\d{1,2})?\s*$/; // validations
75
-
76
- var isEmpty = function isEmpty(value) {
77
- if (typeof value === 'string' && !value.trim().length || value === null || value === undefined) {
78
- return true;
79
- }
80
-
81
- return false;
82
- };
83
- var isValidDate = function isValidDate(value) {
84
- return value ? moment(value).isValid() : true;
85
- };
86
- var isBefore = function isBefore(ownDate, referenceDate) {
87
- return ownDate ? moment.utc(ownDate) < moment.utc(referenceDate) : true;
88
- };
89
- var isAfter = function isAfter(ownDate, otherDate) {
90
- return ownDate ? moment.utc(ownDate).isAfter(moment.utc(otherDate)) : true;
91
- };
92
- var isBetween = function isBetween(ownDate, otherDateStart, otherDateEnd) {
93
- return moment.utc(ownDate) >= moment.utc(otherDateStart) && moment.utc(ownDate) <= moment.utc(otherDateEnd);
94
- };
95
- var isXHoursBefore = function isXHoursBefore(ownDate, otherDate) {
96
- var hours = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
97
-
98
- if (isEmpty(ownDate) || isEmpty(otherDate)) {
99
- return true;
100
- }
101
-
102
- var duration = moment.duration(moment.utc(ownDate).diff(otherDate));
103
- var inHours = duration.asHours();
104
- return inHours >= -hours;
105
- };
106
- var isXHoursAfter = function isXHoursAfter(ownDate, otherDate) {
107
- var hours = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
108
-
109
- if (isEmpty(ownDate) || isEmpty(otherDate)) {
110
- return true;
111
- }
112
-
113
- var duration = moment.duration(moment.utc(ownDate).diff(otherDate));
114
- var inHours = duration.asHours();
115
- return inHours <= hours;
116
- };
117
- var isLatitude = function isLatitude(lat) {
118
- if (!lat) {
119
- return true;
120
- }
121
-
122
- return isFinite(lat) && Math.abs(lat) <= 90 && regexMaxTwoDecimals.test(lat.toString());
123
- };
124
- var isLongitude = function isLongitude(lng) {
125
- if (!lng) {
126
- return true;
127
- }
128
-
129
- return isFinite(lng) && Math.abs(lng) <= 180 && lng >= -180 && regexMaxTwoDecimals.test(lng.toString());
130
- }; // Pass null if no maxValue
131
-
132
- var isValidMax = function isValidMax(value, maxValue) {
133
- if (isEmpty(value) || maxValue === null) {
134
- return true;
135
- }
136
-
137
- return !(value > maxValue);
138
- }; // Pass null if no minValue
139
-
140
- var isValidMin = function isValidMin(value, minValue) {
141
- if (isEmpty(value) || minValue === null) {
142
- return true;
143
- }
144
-
145
- return !(value < minValue);
146
- };
147
- var hasValidGeometry = function hasValidGeometry(geojson) {
148
- if (!geojson || !geojson.features || !geojson.features.length || !geojson.features[0].geometry || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
149
- // @ts-ignore
150
- !geojson.features[0].geometry.coordinates || !geojson.features[0].geometry.type) {
151
- return false;
152
- }
153
-
154
- return true;
155
- };
156
- var isValidGeoJsonCoordinates = function isValidGeoJsonCoordinates(geojson) {
157
- var hasGeometry = hasValidGeometry(geojson);
158
-
159
- if (!hasGeometry) {
160
- return false;
161
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
162
- // @ts-ignore
163
-
164
-
165
- var _geojson$features$0$g = geojson.features[0].geometry,
166
- coordinates = _geojson$features$0$g.coordinates,
167
- type = _geojson$features$0$g.type; // For type POINT coordinates is an array of 2
168
-
169
- if (coordinates.length === 2 && type === 'Point') {
170
- return true;
171
- } // For type POLYGON coordinates is an array of arrays
172
-
173
-
174
- if (coordinates.length === 1 && coordinates[0].length > 0 && type === 'Polygon') {
175
- return true;
176
- }
177
-
178
- return false;
179
- };
180
- var isMaximumOneDrawing = function isMaximumOneDrawing(geojson) {
181
- var hasGeometry = hasValidGeometry(geojson);
182
-
183
- if (!hasGeometry) {
184
- return true; // no need to check further when there is no drawing yet
185
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
186
- // @ts-ignore
187
-
188
-
189
- var _geojson$features$0$g2 = geojson.features[0].geometry,
190
- coordinates = _geojson$features$0$g2.coordinates,
191
- type = _geojson$features$0$g2.type; // For type POLYGON only one array of coordinates is allowed
192
-
193
- if (type === 'Polygon' && coordinates.length > 1) {
194
- return false;
195
- }
196
-
197
- return true;
198
- };
199
- var hasIntersectionWithFIR = function hasIntersectionWithFIR(geojson, intersection) {
200
- if (!hasValidGeometry(geojson) || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
201
- // @ts-ignore
202
- !geojson.features[0].geometry.coordinates.length || geojson.features[0].geometry.type === 'Polygon' && !geojson.features[0].geometry.coordinates[0].length) {
203
- return true; // no need to check further when there is no drawing yet
204
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
205
- // @ts-ignore
206
-
207
-
208
- var coordinates = intersection.features[0].geometry.coordinates;
209
-
210
- if (coordinates.length > 0 && coordinates[0].length === 0) {
211
- return false;
212
- }
213
-
214
- return true;
215
- };
216
- var hasMaxFeaturePoints = function hasMaxFeaturePoints(geojson) {
217
- var maxPoints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 7;
218
- var hasGeometry = hasValidGeometry(geojson);
219
-
220
- if (!hasGeometry) {
221
- return false;
222
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
223
- // @ts-ignore
224
-
225
-
226
- var _geojson$features$0$g3 = geojson.features[0].geometry,
227
- coordinates = _geojson$features$0$g3.coordinates,
228
- type = _geojson$features$0$g3.type;
229
-
230
- if (type === 'Polygon' && coordinates[0].length > maxPoints) {
231
- return true;
232
- }
233
-
234
- return false;
235
- };
236
- var hasMulitpleIntersections = function hasMulitpleIntersections(geojson) {
237
- var hasGeometry = hasValidGeometry(geojson);
238
-
239
- if (!hasGeometry) {
240
- return false;
241
- } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
242
- // @ts-ignore
243
-
244
-
245
- var _geojson$features$0$g4 = geojson.features[0].geometry,
246
- coordinates = _geojson$features$0$g4.coordinates,
247
- type = _geojson$features$0$g4.type;
248
-
249
- if (type === 'MultiPolygon' || coordinates.length > 1 && type !== 'Point') {
250
- return true;
251
- }
252
-
253
- return false;
254
- };
255
- var isGeometryDirty = function isGeometryDirty(geoJSON, formGeoJSON) {
256
- if (geoJSON === (undefined) || formGeoJSON === (undefined) || !hasValidGeometry(geoJSON) || !hasValidGeometry(formGeoJSON)) {
257
- return false;
258
- }
259
-
260
- return !isEqual( // eslint-disable-next-line @typescript-eslint/ban-ts-comment
261
- // @ts-ignore
262
- geoJSON.features[0].geometry.coordinates, // eslint-disable-next-line @typescript-eslint/ban-ts-comment
263
- // @ts-ignore
264
- formGeoJSON.features[0].geometry.coordinates);
265
- };
266
- var isInteger = function isInteger(value) {
267
- if (isEmpty(value)) {
268
- return true;
269
- }
270
-
271
- return Number.isInteger(value);
272
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
273
- var isNonOrBothCoordinates = function isNonOrBothCoordinates(coordinate, otherCoordinate) {
274
- if (typeof coordinate === 'number' && typeof otherCoordinate === 'number' || coordinate === null && otherCoordinate === null || coordinate === undefined && otherCoordinate === undefined) {
275
- return true;
276
- }
277
-
278
- if (typeof coordinate === 'number') {
279
- return true;
280
- }
281
-
282
- return false;
283
- };
284
-
285
- var radioCheckboxStyle = {
286
- // hides unchecked values
287
- display: 'none',
288
- '&+.MuiFormControlLabel-label': {
289
- display: 'none'
290
- },
291
- // shows checked value
292
- '&.Mui-checked': {
293
- display: 'inherit',
294
- '&+.MuiFormControlLabel-label': {
295
- display: 'inherit'
296
- }
297
- },
298
- '&.Mui-checked+.MuiFormControlLabel-label': {
299
- color: 'geowebColors.typographyAndIcons.text'
300
- },
301
- '&.Mui-disabled.Mui-checked': {
302
- color: 'geowebColors.typographyAndIcons.iconLinkActive'
303
- }
304
- };
305
- var getErrorMessage = function getErrorMessage(errors) {
306
- if (errors && errors.message && typeof errors.message === 'string') {
307
- return errors.message;
308
- }
309
-
310
- if (errors && errors.type && typeof errors.type === 'string') {
311
- return errorMessages[errors.type];
312
- }
313
-
314
- return '';
315
- };
316
-
317
- var ReactHookFormFormControl = function ReactHookFormFormControl(_a) {
318
- var children = _a.children,
319
- errors = _a.errors,
320
- isReadOnly = _a.isReadOnly,
321
- _a$sx = _a.sx,
322
- sx = _a$sx === void 0 ? {} : _a$sx,
323
- _a$className = _a.className,
324
- className = _a$className === void 0 ? '' : _a$className,
325
- props = __rest(_a, ["children", "errors", "isReadOnly", "sx", "className"]);
326
-
327
- return /*#__PURE__*/React.createElement(FormControl, Object.assign({
328
- fullWidth: true,
329
- error: !!errors,
330
- className: "".concat(isReadOnly ? 'is-read-only' : '', " ").concat(className),
331
- sx: Object.assign(Object.assign({}, isReadOnly && {
332
- // Radio input
333
- '.MuiRadio-root': radioCheckboxStyle,
334
- // Checkbox input
335
- '.MuiCheckbox-root': radioCheckboxStyle,
336
- // Select input
337
- '.MuiSelect-select.Mui-disabled': {
338
- color: 'geowebColors.typographyAndIcons.text',
339
- WebkitTextFillColor: 'inherit',
340
- '&:before': {
341
- borderColor: 'transparent'
342
- }
343
- },
344
- '.MuiSelect-nativeInput+.MuiSvgIcon-root': {
345
- display: 'none'
346
- },
347
- '.Mui-disabled:before': {
348
- border: 'transparent'
349
- }
350
- }), sx)
351
- }, props), children, errors && /*#__PURE__*/React.createElement(FormHelperText, {
352
- variant: "filled"
353
- }, getErrorMessage(errors)));
354
- };
355
-
356
- function getDeepProperty(p, o) {
357
- return p.reduce(function (xs, x) {
358
- return xs && xs[x] ? xs[x] : null;
359
- }, o);
360
- }
361
- var getErrors = function getErrors(name, errors) {
362
- var nameAsArray = name.split('.');
363
- return getDeepProperty(nameAsArray, errors);
364
- };
365
-
366
- var ReactHookFormSelect = function ReactHookFormSelect(_a) {
367
- var name = _a.name,
368
- label = _a.label,
369
- _a$defaultValue = _a.defaultValue,
370
- defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
371
- children = _a.children,
372
- rules = _a.rules,
373
- _a$onChange = _a.onChange,
374
- _onChange = _a$onChange === void 0 ? function () {} : _a$onChange,
375
- disabled = _a.disabled,
376
- className = _a.className,
377
- sx = _a.sx,
378
- isReadOnly = _a.isReadOnly,
379
- otherProps = __rest(_a, ["name", "label", "defaultValue", "children", "rules", "onChange", "disabled", "className", "sx", "isReadOnly"]);
380
-
381
- var labelId = "".concat(name, "-label");
382
-
383
- var _useFormContext = useFormContext(),
384
- control = _useFormContext.control;
385
-
386
- var _useController = useController(Object.assign({
387
- name: name,
388
- control: control,
389
- rules: rules,
390
- defaultValue: defaultValue
391
- }, defaultProps)),
392
- _useController$field = _useController.field,
393
- onChangeField = _useController$field.onChange,
394
- value = _useController$field.value,
395
- ref = _useController$field.ref,
396
- formErrors = _useController.formState.errors;
397
-
398
- var errors = getErrors(name, formErrors);
399
- return /*#__PURE__*/React.createElement(ReactHookFormFormControl, {
400
- className: className,
401
- sx: sx,
402
- disabled: disabled,
403
- errors: errors,
404
- isReadOnly: isReadOnly
405
- }, /*#__PURE__*/React.createElement(InputLabel, {
406
- variant: "filled",
407
- id: labelId
408
- }, label), /*#__PURE__*/React.createElement(Select, Object.assign({
409
- labelId: labelId,
410
- label: label,
411
- inputRef: ref,
412
- name: name,
413
- onChange: function onChange(changeEvent) {
414
- onChangeField(changeEvent.target.value); // default props
415
-
416
- _onChange(changeEvent);
417
- },
418
- value: value || '',
419
- variant: "filled"
420
- }, otherProps), children));
421
- };
422
-
423
- var ReactHookFormRadioGroup = function ReactHookFormRadioGroup(_a) {
424
- var name = _a.name,
425
- label = _a.label,
426
- _a$defaultValue = _a.defaultValue,
427
- defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
428
- children = _a.children,
429
- rules = _a.rules,
430
- _a$disabled = _a.disabled,
431
- disabled = _a$disabled === void 0 ? false : _a$disabled,
432
- _a$onChange = _a.onChange,
433
- _onChange = _a$onChange === void 0 ? function () {} : _a$onChange,
434
- isReadOnly = _a.isReadOnly,
435
- otherProps = __rest(_a, ["name", "label", "defaultValue", "children", "rules", "disabled", "onChange", "isReadOnly"]);
436
-
437
- var labelId = "".concat(name, "-label");
438
-
439
- var _useFormContext = useFormContext(),
440
- control = _useFormContext.control;
441
-
442
- var _useController = useController(Object.assign({
443
- name: name,
444
- control: control,
445
- rules: rules,
446
- defaultValue: defaultValue
447
- }, defaultProps)),
448
- _useController$field = _useController.field,
449
- onChangeField = _useController$field.onChange,
450
- value = _useController$field.value,
451
- ref = _useController$field.ref,
452
- formErrors = _useController.formState.errors;
453
-
454
- var errors = getErrors(name, formErrors);
455
- React.useEffect(function () {
456
- if (errors) {
457
- var firstError = Object.keys(formErrors)[0];
458
-
459
- if (firstError === name) {
460
- // if first error in form is same, focus on that input
461
- var inputNode = document.querySelector("[name=\"".concat(name, "\"]"));
462
-
463
- if (inputNode !== null) {
464
- inputNode.focus();
465
- }
466
- }
467
- }
468
- }, [errors, formErrors, name]);
469
- return /*#__PURE__*/React.createElement(ReactHookFormFormControl, {
470
- disabled: disabled,
471
- errors: errors,
472
- isReadOnly: isReadOnly
473
- }, /*#__PURE__*/React.createElement(InputLabel, {
474
- id: labelId
475
- }, label), /*#__PURE__*/React.createElement(RadioGroup, Object.assign({
476
- value: value,
477
- onChange: function onChange(changeEvent) {
478
- onChangeField(changeEvent.target.value);
479
-
480
- _onChange(changeEvent, changeEvent.target.value);
481
- },
482
- ref: ref,
483
- name: name
484
- }, otherProps), children));
485
- };
486
-
487
- var convertTextInputValue = function convertTextInputValue(value, inCapitals) {
488
- return inCapitals ? value.toUpperCase() : value;
489
- };
490
-
491
- var ReactHookFormTextField = function ReactHookFormTextField(_a) {
492
- var name = _a.name,
493
- label = _a.label,
494
- _a$defaultValue = _a.defaultValue,
495
- defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
496
- rules = _a.rules,
497
- _a$disabled = _a.disabled,
498
- disabled = _a$disabled === void 0 ? false : _a$disabled,
499
- _a$upperCase = _a.upperCase,
500
- upperCase = _a$upperCase === void 0 ? false : _a$upperCase,
501
- _a$helperText = _a.helperText,
502
- helperText = _a$helperText === void 0 ? '' : _a$helperText,
503
- className = _a.className,
504
- sx = _a.sx,
505
- _a$onChange = _a.onChange,
506
- _onChange = _a$onChange === void 0 ? function () {} : _a$onChange,
507
- isReadOnly = _a.isReadOnly,
508
- InputProps = _a.InputProps,
509
- otherProps = __rest(_a, ["name", "label", "defaultValue", "rules", "disabled", "upperCase", "helperText", "className", "sx", "onChange", "isReadOnly", "InputProps"]);
510
-
511
- var _useFormContext = useFormContext(),
512
- control = _useFormContext.control;
513
-
514
- var _useController = useController(Object.assign({
515
- name: name,
516
- control: control,
517
- rules: rules,
518
- defaultValue: defaultValue
519
- }, defaultProps)),
520
- _useController$field = _useController.field,
521
- onChangeField = _useController$field.onChange,
522
- value = _useController$field.value,
523
- ref = _useController$field.ref,
524
- formErrors = _useController.formState.errors;
525
-
526
- var errors = getErrors(name, formErrors);
527
- return /*#__PURE__*/React.createElement(ReactHookFormFormControl, {
528
- className: className,
529
- sx: sx,
530
- disabled: disabled,
531
- errors: errors,
532
- isReadOnly: isReadOnly
533
- }, /*#__PURE__*/React.createElement(TextField, Object.assign({
534
- label: label,
535
- error: !!errors,
536
- helperText: helperText,
537
- value: value,
538
- variant: "filled",
539
- type: "text",
540
- name: name,
541
- onChange: function onChange(evt) {
542
- var value = evt.target.value;
543
- var convertedValue = convertTextInputValue(value, upperCase);
544
- onChangeField(convertedValue);
545
-
546
- _onChange(null);
547
- },
548
- disabled: disabled,
549
- inputRef: ref,
550
- InputProps: Object.assign(Object.assign({}, InputProps), isReadOnly && {
551
- readOnly: true
552
- })
553
- }, otherProps)));
554
- };
555
-
556
- function _slicedToArray(arr, i) {
557
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
558
- }
559
-
560
- function _toConsumableArray(arr) {
561
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
562
- }
563
-
564
- function _arrayWithoutHoles(arr) {
565
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
566
- }
567
-
568
- function _arrayWithHoles(arr) {
569
- if (Array.isArray(arr)) return arr;
570
- }
571
-
572
- function _iterableToArray(iter) {
573
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
574
- }
575
-
576
- function _iterableToArrayLimit(arr, i) {
577
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
578
- var _arr = [];
579
- var _n = true;
580
- var _d = false;
581
- var _e = undefined;
582
-
583
- try {
584
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
585
- _arr.push(_s.value);
586
-
587
- if (i && _arr.length === i) break;
588
- }
589
- } catch (err) {
590
- _d = true;
591
- _e = err;
592
- } finally {
593
- try {
594
- if (!_n && _i["return"] != null) _i["return"]();
595
- } finally {
596
- if (_d) throw _e;
597
- }
598
- }
599
-
600
- return _arr;
601
- }
602
-
603
- function _unsupportedIterableToArray(o, minLen) {
604
- if (!o) return;
605
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
606
- var n = Object.prototype.toString.call(o).slice(8, -1);
607
- if (n === "Object" && o.constructor) n = o.constructor.name;
608
- if (n === "Map" || n === "Set") return Array.from(o);
609
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
610
- }
611
-
612
- function _arrayLikeToArray(arr, len) {
613
- if (len == null || len > arr.length) len = arr.length;
614
-
615
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
616
-
617
- return arr2;
618
- }
619
-
620
- function _nonIterableSpread() {
621
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
622
- }
623
-
624
- function _nonIterableRest() {
625
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
626
- }
627
-
628
- var convertNumericInputValue = function convertNumericInputValue(value, inputMode) {
629
- if (value !== '' && !isNaN(parseFloat(value))) {
630
- return inputMode === 'numeric' ? parseInt(value, 10) : parseFloat(value);
631
- }
632
-
633
- return null;
634
- };
635
- var getAllowedKeys = function getAllowedKeys() {
636
- var inputMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'numeric';
637
- var allowedKeys = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', 'Backspace', 'ArrowRight', 'ArrowLeft', 'Tab', 'Home', 'End', 'PageDown', 'PageUp', 'Delete'].concat(_toConsumableArray(inputMode === 'decimal' ? ['.'] : []));
638
- return allowedKeys;
639
- };
640
-
641
- var ReactHookFormNumberField = function ReactHookFormNumberField(_a) {
642
- var name = _a.name,
643
- label = _a.label,
644
- _a$defaultValue = _a.defaultValue,
645
- defaultValue = _a$defaultValue === void 0 ? null : _a$defaultValue,
646
- rules = _a.rules,
647
- _a$disabled = _a.disabled,
648
- disabled = _a$disabled === void 0 ? false : _a$disabled,
649
- _a$inputMode = _a.inputMode,
650
- inputMode = _a$inputMode === void 0 ? 'numeric' : _a$inputMode,
651
- _a$helperText = _a.helperText,
652
- helperText = _a$helperText === void 0 ? '' : _a$helperText,
653
- className = _a.className,
654
- sx = _a.sx,
655
- _a$onChange = _a.onChange,
656
- _onChange = _a$onChange === void 0 ? function () {} : _a$onChange,
657
- isReadOnly = _a.isReadOnly,
658
- otherProps = __rest(_a, ["name", "label", "defaultValue", "rules", "disabled", "inputMode", "helperText", "className", "sx", "onChange", "isReadOnly"]);
659
-
660
- var _useFormContext = useFormContext(),
661
- control = _useFormContext.control;
662
-
663
- var _useController = useController(Object.assign({
664
- name: name,
665
- control: control,
666
- rules: rules,
667
- defaultValue: defaultValue
668
- }, defaultProps)),
669
- _useController$field = _useController.field,
670
- onChangeField = _useController$field.onChange,
671
- value = _useController$field.value,
672
- ref = _useController$field.ref,
673
- formErrors = _useController.formState.errors;
674
-
675
- var errors = getErrors(name, formErrors);
676
- var allowedKeyes = getAllowedKeys(inputMode);
677
-
678
- var onKeyDown = function onKeyDown(event) {
679
- if (!allowedKeyes.includes(event.key) || // only allow one seperator
680
- event.key === '.' && event.target.value.includes('.') || // only allow one -
681
- event.key === '-' && event.target.value.includes('-')) {
682
- event.preventDefault();
683
- }
684
- };
685
-
686
- var _React$useState = React.useState(value === null || isNaN(value) ? '' : value),
687
- _React$useState2 = _slicedToArray(_React$useState, 2),
688
- displayValue = _React$useState2[0],
689
- setDisplayValue = _React$useState2[1];
690
-
691
- return /*#__PURE__*/React.createElement(ReactHookFormFormControl, {
692
- className: className,
693
- sx: sx,
694
- disabled: disabled,
695
- errors: errors,
696
- isReadOnly: isReadOnly
697
- }, /*#__PURE__*/React.createElement(TextField, Object.assign({
698
- label: label,
699
- error: !!errors,
700
- helperText: helperText,
701
- inputMode: inputMode,
702
- value: displayValue,
703
- variant: "filled",
704
- type: "text",
705
- inputProps: {
706
- inputMode: inputMode
707
- },
708
- name: name,
709
- onChange: function onChange(evt) {
710
- var value = evt.target.value;
711
- setDisplayValue(value);
712
- onChangeField(convertNumericInputValue(value, inputMode));
713
-
714
- _onChange(null);
715
- },
716
- onKeyDown: onKeyDown,
717
- disabled: disabled,
718
- inputRef: ref,
719
- // eslint-disable-next-line react/jsx-no-duplicate-props
720
- InputProps: Object.assign(Object.assign({}, isReadOnly && {
721
- readOnly: true
722
- }), otherProps.InputProps)
723
- }, otherProps)));
724
- };
725
-
726
- moment$1.tz.setDefault('Etc/GMT-0'); // TODO: remove when issue is fixed in upcoming release https://github.com/mui/mui-x/issues/8150
727
-
728
- var temporaryStripChineseCharacters = function temporaryStripChineseCharacters(dirtyString) {
729
- return dirtyString.replace(/[\u2066\u2067\u2068\u2069\u200e]/g, '');
730
- };
731
- var getFormattedValue = function getFormattedValue(value) {
732
- var isMoment = moment$1(value).isValid();
733
- return isMoment ? moment$1.utc(value).format() : value;
734
- };
735
-
736
- var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_a) {
737
- var name = _a.name,
738
- rules = _a.rules,
739
- disabled = _a.disabled,
740
- _a$label = _a.label,
741
- label = _a$label === void 0 ? 'Select date and time' : _a$label,
742
- _a$format = _a.format,
743
- format = _a$format === void 0 ? 'YYYY/MM/DD HH:mm' : _a$format,
744
- _a$openTo = _a.openTo,
745
- openTo = _a$openTo === void 0 ? 'hours' : _a$openTo,
746
- _a$defaultNullValue = _a.defaultNullValue,
747
- defaultNullValue = _a$defaultNullValue === void 0 ? null : _a$defaultNullValue,
748
- _a$helperText = _a.helperText,
749
- helperText = _a$helperText === void 0 ? '' : _a$helperText,
750
- _a$onChange = _a.onChange,
751
- _onChange = _a$onChange === void 0 ? function () {} : _a$onChange,
752
- className = _a.className,
753
- sx = _a.sx,
754
- isReadOnly = _a.isReadOnly,
755
- inputAdornment = _a.inputAdornment,
756
- otherProps = __rest(_a, ["name", "rules", "disabled", "label", "format", "openTo", "defaultNullValue", "helperText", "onChange", "className", "sx", "isReadOnly", "inputAdornment"]);
757
-
758
- var _useFormContext = useFormContext(),
759
- control = _useFormContext.control;
760
-
761
- var _useController = useController(Object.assign({
762
- name: name,
763
- control: control,
764
- rules: rules,
765
- defaultValue: defaultNullValue
766
- }, defaultProps)),
767
- _useController$field = _useController.field,
768
- onChangeField = _useController$field.onChange,
769
- value = _useController$field.value,
770
- ref = _useController$field.ref,
771
- formErrors = _useController.formState.errors;
772
-
773
- var errors = getErrors(name, formErrors); // Ensure value is a Moment object
774
-
775
- var dateValue = value ? moment$1(value) : null;
776
- return /*#__PURE__*/React.createElement(ReactHookFormFormControl, {
777
- disabled: disabled,
778
- errors: errors,
779
- className: className,
780
- sx: sx,
781
- isReadOnly: isReadOnly
782
- }, /*#__PURE__*/React.createElement(DateTimePicker, Object.assign({
783
- desktopModeMediaQuery: "@media (min-width: 720px)",
784
- ampm: false,
785
- format: format,
786
- label: label,
787
- value: dateValue,
788
- openTo: openTo,
789
- disabled: disabled,
790
- onChange: function onChange(value) {
791
- onChangeField(getFormattedValue(value));
792
-
793
- _onChange(getFormattedValue(value));
794
- },
795
- inputRef: ref,
796
- slotProps: {
797
- textField: {
798
- variant: 'filled',
799
- helperText: helperText,
800
- error: !!errors,
801
- name: name,
802
- placeholder: disabled ? '' : format.toLowerCase(),
803
- InputProps: Object.assign({
804
- endAdornment: /*#__PURE__*/React.createElement(InputAdornment, {
805
- style: {
806
- paddingTop: '16px'
807
- },
808
- position: "end"
809
- }, "UTC")
810
- }, isReadOnly && {
811
- readOnly: true
812
- }),
813
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
814
- // @ts-ignore
815
- 'data-testid': otherProps['data-testid']
816
- },
817
- inputAdornment: Object.assign({}, inputAdornment || {
818
- position: 'start'
819
- }),
820
- tabs: {
821
- hidden: false
822
- }
823
- }
824
- }, otherProps)));
825
- };
826
-
827
- /* *
828
- * Licensed under the Apache License, Version 2.0 (the "License");
829
- * you may not use this file except in compliance with the License.
830
- * You may obtain a copy of the License at
831
- *
832
- * http://www.apache.org/licenses/LICENSE-2.0
833
- *
834
- * Unless required by applicable law or agreed to in writing, software
835
- * distributed under the License is distributed on an "AS IS" BASIS,
836
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
837
- * See the License for the specific language governing permissions and
838
- * limitations under the License.
839
- *
840
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
841
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
842
- * */
843
- var defaultFormOptions = {
844
- mode: 'onChange',
845
- reValidateMode: 'onChange'
846
- };
847
-
848
- var ReactHookFormProvider = function ReactHookFormProvider(_ref) {
849
- var children = _ref.children,
850
- _ref$options = _ref.options,
851
- options = _ref$options === void 0 ? defaultFormOptions : _ref$options;
852
- var formMethods = useForm(options); // added this ignore as the build is failing otherwise on: Type instantiation is excessively deep and possibly infinite.
853
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
854
- // @ts-ignore
855
-
856
- return /*#__PURE__*/React__default.createElement(FormProvider, Object.assign({}, formMethods), children);
857
- };
858
-
859
- var ReactHookFormProviderWrapper = function ReactHookFormProviderWrapper(_ref2) {
860
- var children = _ref2.children,
861
- _ref2$options = _ref2.options,
862
- options = _ref2$options === void 0 ? defaultFormOptions : _ref2$options;
863
- return /*#__PURE__*/React__default.createElement(LocalizationProvider, {
864
- dateAdapter: AdapterMoment
865
- }, /*#__PURE__*/React__default.createElement(ReactHookFormProvider, {
866
- options: options
867
- }, children));
868
- };
869
-
870
- /* *
871
- * Licensed under the Apache License, Version 2.0 (the "License");
872
- * you may not use this file except in compliance with the License.
873
- * You may obtain a copy of the License at
874
- *
875
- * http://www.apache.org/licenses/LICENSE-2.0
876
- *
877
- * Unless required by applicable law or agreed to in writing, software
878
- * distributed under the License is distributed on an "AS IS" BASIS,
879
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
880
- * See the License for the specific language governing permissions and
881
- * limitations under the License.
882
- *
883
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
884
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
885
- * */
886
-
887
- var ReactHookFormHiddenInput = function ReactHookFormHiddenInput(_ref) {
888
- var name = _ref.name,
889
- _ref$defaultValue = _ref.defaultValue,
890
- defaultValue = _ref$defaultValue === void 0 ? null : _ref$defaultValue,
891
- rules = _ref.rules;
892
-
893
- var _useFormContext = useFormContext(),
894
- control = _useFormContext.control;
895
-
896
- var _useController = useController(Object.assign({
897
- name: name,
898
- control: control,
899
- rules: rules,
900
- defaultValue: defaultValue
901
- }, defaultProps)),
902
- field = _useController.field;
903
-
904
- return field.value !== null ? /*#__PURE__*/React.createElement("input", Object.assign({}, field, {
905
- type: "hidden"
906
- })) : null;
907
- };
908
-
909
- /* *
910
- * Licensed under the Apache License, Version 2.0 (the "License");
911
- * you may not use this file except in compliance with the License.
912
- * You may obtain a copy of the License at
913
- *
914
- * http://www.apache.org/licenses/LICENSE-2.0
915
- *
916
- * Unless required by applicable law or agreed to in writing, software
917
- * distributed under the License is distributed on an "AS IS" BASIS,
918
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
919
- * See the License for the specific language governing permissions and
920
- * limitations under the License.
921
- *
922
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
923
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
924
- * */
925
-
926
- var HIDDEN_INPUT_HELPER_IS_DRAFT = 'IS_DRAFT';
927
- var useDraftFormHelpers = function useDraftFormHelpers() {
928
- var isDefaultDraft = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
929
-
930
- var _useFormContext = useFormContext(),
931
- getValues = _useFormContext.getValues,
932
- setValue = _useFormContext.setValue,
933
- register = _useFormContext.register;
934
-
935
- React.useEffect(function () {
936
- setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDefaultDraft, {
937
- shouldDirty: false
938
- }); // eslint-disable-next-line react-hooks/exhaustive-deps
939
- }, []);
940
-
941
- var isDraft = function isDraft() {
942
- return getValues(HIDDEN_INPUT_HELPER_IS_DRAFT) === true;
943
- };
944
-
945
- var isRequired = function isRequired(value) {
946
- if (!isDraft() && isEmpty(value)) {
947
- return errorMessages.required;
948
- }
949
-
950
- return true;
951
- };
952
-
953
- var toggleIsDraft = function toggleIsDraft(isDraft) {
954
- return setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDraft, {
955
- shouldDirty: false
956
- });
957
- };
958
-
959
- var DraftFieldHelper = function DraftFieldHelper() {
960
- return /*#__PURE__*/React.createElement("input", Object.assign({}, register(HIDDEN_INPUT_HELPER_IS_DRAFT), {
961
- type: "hidden"
962
- }));
963
- };
964
-
965
- return {
966
- isRequired: isRequired,
967
- toggleIsDraft: toggleIsDraft,
968
- isDraft: isDraft,
969
- DraftFieldHelper: DraftFieldHelper
970
- };
971
- };
972
-
973
- export { HIDDEN_INPUT_HELPER_IS_DRAFT, ReactHookKeyboardDateTimePicker as ReactHookFormDateTime, ReactHookFormFormControl, ReactHookFormHiddenInput, ReactHookFormNumberField, ReactHookFormProviderWrapper as ReactHookFormProvider, ReactHookFormRadioGroup, ReactHookFormSelect, ReactHookFormTextField, defaultFormOptions, errorMessages, getDeepProperty, hasIntersectionWithFIR, hasMaxFeaturePoints, hasMulitpleIntersections, isAfter, isBefore, isBetween, isEmpty, isGeometryDirty, isInteger, isLatitude, isLongitude, isMaximumOneDrawing, isNonOrBothCoordinates, isValidDate, isValidGeoJsonCoordinates, isValidMax, isValidMin, isXHoursAfter, isXHoursBefore, temporaryStripChineseCharacters, useDraftFormHelpers };