@opengeoweb/form-fields 13.2.1 → 14.0.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/index.esm.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { FormControl, FormHelperText, InputLabel, Select, RadioGroup, TextField, InputAdornment } from '@mui/material';
3
3
  import { useFormContext, useController, useForm, FormProvider } from 'react-hook-form';
4
- import { dateUtils } from '@opengeoweb/shared';
5
4
  import { isEqual } from 'lodash';
5
+ import { dateUtils } from '@opengeoweb/shared';
6
6
  import 'i18next';
7
7
  import { useTranslation } from 'react-i18next';
8
- import * as React from 'react';
8
+ import React from 'react';
9
9
  import { DateTimePicker } from '@mui/x-date-pickers';
10
10
  import { CalendarToday } from '@opengeoweb/theme';
11
- import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
12
11
  import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
12
+ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
13
13
 
14
14
  var en = {
15
15
  "form-fields-error-required": "This field is required",
@@ -96,23 +96,20 @@ function _objectWithoutPropertiesLoose(r, e) {
96
96
  return t;
97
97
  }
98
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 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
113
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
114
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
115
- * */
99
+ function getDeepProperty(property, state) {
100
+ return property.reduce(function (xs, x) {
101
+ if (xs && typeof xs === 'object' && x in xs) {
102
+ return xs[x];
103
+ }
104
+ return null;
105
+ }, state);
106
+ }
107
+ var getErrors = function getErrors(name, errors) {
108
+ var _getDeepProperty;
109
+ var nameAsArray = name.split('.');
110
+ return (_getDeepProperty = getDeepProperty(nameAsArray, errors)) != null ? _getDeepProperty : undefined;
111
+ };
112
+
116
113
  var defaultProps = {
117
114
  shouldUnregister: false
118
115
  };
@@ -187,10 +184,11 @@ var isValidMin = function isValidMin(value, minValue) {
187
184
  return !(value < minValue);
188
185
  };
189
186
  var hasValidGeometry = function hasValidGeometry(geojson) {
190
- if (!geojson || !geojson.features || !geojson.features.length || !geojson.features[0].geometry ||
187
+ var _geojson$features, _geojson$features$0$g;
188
+ if (!(geojson != null && (_geojson$features = geojson.features) != null && _geojson$features.length) ||
191
189
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
192
190
  // @ts-ignore
193
- !geojson.features[0].geometry.coordinates || !geojson.features[0].geometry.type) {
191
+ !((_geojson$features$0$g = geojson.features[0].geometry) != null && _geojson$features$0$g.coordinates) || !geojson.features[0].geometry.type) {
194
192
  return false;
195
193
  }
196
194
  return true;
@@ -202,9 +200,9 @@ var isValidGeoJsonCoordinates = function isValidGeoJsonCoordinates(geojson) {
202
200
  }
203
201
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
204
202
  // @ts-ignore
205
- var _geojson$features$0$g = geojson.features[0].geometry,
206
- coordinates = _geojson$features$0$g.coordinates,
207
- type = _geojson$features$0$g.type;
203
+ var _geojson$features$0$g2 = geojson.features[0].geometry,
204
+ coordinates = _geojson$features$0$g2.coordinates,
205
+ type = _geojson$features$0$g2.type;
208
206
  // For type POINT coordinates is an array of 2
209
207
  if (coordinates.length === 2 && type === 'Point') {
210
208
  return true;
@@ -222,9 +220,9 @@ var isMaximumOneDrawing = function isMaximumOneDrawing(geojson) {
222
220
  }
223
221
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
224
222
  // @ts-ignore
225
- var _geojson$features$0$g2 = geojson.features[0].geometry,
226
- coordinates = _geojson$features$0$g2.coordinates,
227
- type = _geojson$features$0$g2.type;
223
+ var _geojson$features$0$g3 = geojson.features[0].geometry,
224
+ coordinates = _geojson$features$0$g3.coordinates,
225
+ type = _geojson$features$0$g3.type;
228
226
  // For type POLYGON only one array of coordinates is allowed
229
227
  if (type === 'Polygon' && coordinates.length > 1) {
230
228
  return false;
@@ -262,17 +260,17 @@ var hasMulitpleIntersections = function hasMulitpleIntersections(geojson) {
262
260
  }
263
261
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
264
262
  // @ts-ignore
265
- var _geojson$features$0$g3 = geojson.features[0].geometry,
266
- coordinates = _geojson$features$0$g3.coordinates,
267
- type = _geojson$features$0$g3.type;
263
+ var _geojson$features$0$g4 = geojson.features[0].geometry,
264
+ coordinates = _geojson$features$0$g4.coordinates,
265
+ type = _geojson$features$0$g4.type;
268
266
  if (type === 'MultiPolygon' || coordinates.length > 1 && type !== 'Point') {
269
267
  return true;
270
268
  }
271
269
  return false;
272
270
  };
273
271
  var countIntersectionPoints = function countIntersectionPoints(geojson, intersection) {
274
- var _geojson$features$3, _intersection$feature3;
275
- if (!(geojson != null && geojson.features) || !((_geojson$features$3 = geojson.features[0]) != null && _geojson$features$3.geometry) || !(intersection != null && intersection.features) || !((_intersection$feature3 = intersection.features[0]) != null && _intersection$feature3.geometry)) {
272
+ var _geojson$features2, _intersection$feature3;
273
+ 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)) {
276
274
  return 0;
277
275
  }
278
276
  var geojsonGeometry = geojson.features[0].geometry;
@@ -398,9 +396,9 @@ var ReactHookFormFormControl = function ReactHookFormFormControl(_ref) {
398
396
  var _useFormFieldsTransla = useFormFieldsTranslation(),
399
397
  t = _useFormFieldsTransla.t;
400
398
  return jsxs(FormControl, Object.assign({
401
- fullWidth: true,
402
- error: !!errors,
403
399
  className: (isReadOnly ? 'is-read-only' : '') + " " + className,
400
+ error: !!errors,
401
+ fullWidth: true,
404
402
  size: size,
405
403
  sx: Object.assign({}, isReadOnly && {
406
404
  // Radio input
@@ -421,29 +419,16 @@ var ReactHookFormFormControl = function ReactHookFormFormControl(_ref) {
421
419
  '.Mui-disabled:before': {
422
420
  border: 'transparent'
423
421
  }
424
- }, sx)
422
+ }, Array.isArray(sx) ? Object.assign.apply(Object, [{}].concat(sx)) : sx)
425
423
  }, props, {
426
- children: [children, errors && jsx(FormHelperText, {
427
- variant: "filled",
424
+ children: [children, errors ? jsx(FormHelperText, {
428
425
  role: "alert",
426
+ variant: "filled",
429
427
  children: getErrorMessage(t, errors)
430
- })]
428
+ }) : null]
431
429
  }));
432
430
  };
433
431
 
434
- function getDeepProperty(property, state) {
435
- return property.reduce(function (xs, x) {
436
- if (xs && typeof xs === 'object' && x in xs) {
437
- return xs[x];
438
- }
439
- return null;
440
- }, state);
441
- }
442
- var getErrors = function getErrors(name, errors) {
443
- var nameAsArray = name.split('.');
444
- return getDeepProperty(nameAsArray, errors) || undefined;
445
- };
446
-
447
432
  var _excluded$5 = ["name", "label", "defaultValue", "children", "rules", "onChange", "disabled", "className", "sx", "isReadOnly", "size"];
448
433
  var ReactHookFormSelect = function ReactHookFormSelect(_ref) {
449
434
  var name = _ref.name,
@@ -478,25 +463,26 @@ var ReactHookFormSelect = function ReactHookFormSelect(_ref) {
478
463
  var errors = getErrors(name, formErrors);
479
464
  return jsxs(ReactHookFormFormControl, {
480
465
  className: className,
481
- sx: sx,
482
466
  disabled: disabled,
483
467
  errors: errors,
484
468
  isReadOnly: isReadOnly,
485
469
  size: size,
470
+ sx: sx,
486
471
  children: [jsx(InputLabel, {
487
- variant: "filled",
488
472
  id: labelId,
473
+ variant: "filled",
489
474
  children: label
490
475
  }), jsx(Select, Object.assign({
491
- labelId: labelId,
492
- label: label,
493
476
  inputRef: ref,
477
+ label: label,
478
+ labelId: labelId,
494
479
  name: name,
495
480
  onChange: function onChange(changeEvent, child) {
496
481
  onChangeField(changeEvent.target.value);
497
482
  // default props
498
483
  _onChange(changeEvent, child);
499
484
  },
485
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
500
486
  value: value || '',
501
487
  variant: "filled"
502
488
  }, otherProps, {
@@ -554,13 +540,13 @@ var ReactHookFormRadioGroup = function ReactHookFormRadioGroup(_ref) {
554
540
  id: labelId,
555
541
  children: label
556
542
  }), jsx(RadioGroup, Object.assign({
557
- value: value,
543
+ name: name,
558
544
  onChange: function onChange(changeEvent) {
559
545
  onChangeField(changeEvent.target.value);
560
546
  _onChange(changeEvent, changeEvent.target.value);
561
547
  },
562
548
  ref: ref,
563
- name: name
549
+ value: value
564
550
  }, otherProps, {
565
551
  children: children
566
552
  }))]
@@ -606,17 +592,16 @@ var ReactHookFormTextField = function ReactHookFormTextField(_ref) {
606
592
  var errors = getErrors(name, formErrors);
607
593
  return jsx(ReactHookFormFormControl, {
608
594
  className: className,
609
- sx: sx,
610
595
  disabled: disabled,
611
596
  errors: errors,
612
597
  isReadOnly: isReadOnly,
598
+ sx: sx,
613
599
  children: jsx(TextField, Object.assign({
614
- label: label,
600
+ disabled: disabled,
615
601
  error: !!errors,
616
602
  helperText: helperText,
617
- value: value,
618
- variant: "filled",
619
- type: "text",
603
+ inputRef: ref,
604
+ label: label,
620
605
  name: name,
621
606
  onChange: function onChange(evt) {
622
607
  var value = evt.target.value;
@@ -624,8 +609,9 @@ var ReactHookFormTextField = function ReactHookFormTextField(_ref) {
624
609
  onChangeField(convertedValue);
625
610
  _onChange(null);
626
611
  },
627
- disabled: disabled,
628
- inputRef: ref
612
+ type: "text",
613
+ value: value,
614
+ variant: "filled"
629
615
  }, otherProps, {
630
616
  slotProps: Object.assign({}, otherProps.slotProps, {
631
617
  input: Object.assign({}, inputSlotProps, isReadOnly && {
@@ -693,11 +679,11 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
693
679
  var after = inputElement.value.slice(inputElement.selectionEnd);
694
680
  var newValue = before + clipboardText + after;
695
681
  // eslint-disable-next-line no-useless-escape
696
- if (inputMode === 'numeric' && !newValue.match(/^\-?[0-9]+$/)) {
682
+ if (inputMode === 'numeric' && !/^\-?[0-9]+$/.exec(newValue)) {
697
683
  event.preventDefault();
698
684
  }
699
685
  // eslint-disable-next-line no-useless-escape
700
- if (inputMode === 'decimal' && !newValue.match(/^\-?[0-9]*(\.[0-9]+)?$/)) {
686
+ if (inputMode === 'decimal' && !/^\-?[0-9]*(\.[0-9]+)?$/.exec(newValue)) {
701
687
  event.preventDefault();
702
688
  }
703
689
  };
@@ -721,20 +707,18 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
721
707
  setDisplayValue = _React$useState[1];
722
708
  return jsx(ReactHookFormFormControl, {
723
709
  className: className,
724
- sx: sx,
725
710
  disabled: disabled,
726
711
  errors: errors,
727
712
  isReadOnly: isReadOnly,
713
+ sx: sx,
728
714
  children: jsx(TextField, Object.assign({
729
- label: label,
715
+ disabled: disabled,
730
716
  error: !!errors,
731
717
  helperText: helperText,
732
718
  inputMode: inputMode,
733
- value: displayValue,
734
- variant: "filled",
735
- type: "text",
719
+ inputRef: ref,
720
+ label: label,
736
721
  name: name,
737
- size: size,
738
722
  onChange: function onChange(evt) {
739
723
  var value = evt.target.value;
740
724
  setDisplayValue(value);
@@ -742,8 +726,10 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
742
726
  _onChange(null);
743
727
  },
744
728
  onKeyDown: onKeyDown,
745
- disabled: disabled,
746
- inputRef: ref
729
+ size: size,
730
+ type: "text",
731
+ value: displayValue,
732
+ variant: "filled"
747
733
  }, otherProps, {
748
734
  slotProps: Object.assign({}, otherProps.slotProps, {
749
735
  input: Object.assign({}, isReadOnly && {
@@ -836,19 +822,20 @@ var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_
836
822
  var minDateTime = disablePast ? now : null;
837
823
  var maxDateTime = disableFuture ? now : null;
838
824
  return jsx(ReactHookFormFormControl, {
825
+ className: className,
839
826
  disabled: disabled,
840
827
  errors: errors,
841
- className: className,
842
- sx: sx,
843
828
  isReadOnly: isReadOnly,
829
+ sx: sx,
844
830
  children: jsx(DateTimePicker, Object.assign({
845
- desktopModeMediaQuery: "@media (min-width: 720px)",
846
831
  ampm: false,
832
+ desktopModeMediaQuery: "@media (min-width: 720px)",
833
+ disabled: disabled,
847
834
  format: format,
835
+ inputRef: ref,
848
836
  label: label,
849
- value: dateValue,
850
- openTo: openTo,
851
- disabled: disabled,
837
+ maxDateTime: maxDateTime,
838
+ minDateTime: minDateTime,
852
839
  onChange: function onChange(value) {
853
840
  if (!value) {
854
841
  _onChange(null);
@@ -859,7 +846,7 @@ var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_
859
846
  onChangeField(formattedDate);
860
847
  _onChange(formattedDate);
861
848
  },
862
- inputRef: ref,
849
+ openTo: openTo,
863
850
  slotProps: {
864
851
  textField: Object.assign({
865
852
  variant: 'filled',
@@ -869,10 +856,10 @@ var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_
869
856
  placeholder: disabled ? '' : format.toLowerCase(),
870
857
  InputProps: Object.assign({}, !shouldHideUTC && {
871
858
  endAdornment: jsx(InputAdornment, {
859
+ position: "end",
872
860
  style: {
873
861
  paddingTop: '16px'
874
862
  },
875
- position: "end",
876
863
  children: "UTC"
877
864
  })
878
865
  }),
@@ -898,8 +885,7 @@ var ReactHookKeyboardDateTimePicker = function ReactHookKeyboardDateTimePicker(_
898
885
  timeSteps: {
899
886
  minutes: 1
900
887
  },
901
- minDateTime: minDateTime,
902
- maxDateTime: maxDateTime
888
+ value: dateValue
903
889
  }, otherProps))
904
890
  });
905
891
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/form-fields",
3
- "version": "13.2.1",
3
+ "version": "14.0.0",
4
4
  "description": "GeoWeb form-fields library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,11 +8,11 @@
8
8
  "url": "git@gitlab.com:opengeoweb/opengeoweb.git"
9
9
  },
10
10
  "dependencies": {
11
- "@opengeoweb/theme": "13.2.1",
11
+ "@opengeoweb/theme": "14.0.0",
12
12
  "react-hook-form": "^7.50.1",
13
13
  "@mui/x-date-pickers": "^8.11.2",
14
14
  "lodash": "^4.17.21",
15
- "@opengeoweb/shared": "13.2.1",
15
+ "@opengeoweb/shared": "14.0.0",
16
16
  "react-i18next": "^15.1.1",
17
17
  "@mui/material": "^7.0.1",
18
18
  "i18next": "^25.0.1",
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { UseFormProps } from 'react-hook-form';
2
+ import type { UseFormProps } from 'react-hook-form';
3
3
  export declare const zeplinLinks: {
4
4
  name: string;
5
5
  link: string;
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
2
- import { SxProps, Theme } from '@mui/material';
3
- import { DateTimePickerProps, DateTimePickerSlotProps } from '@mui/x-date-pickers';
4
- import { ReactHookFormInput } from './types';
1
+ import type { SxProps, Theme } from '@mui/material';
2
+ import type { DateTimePickerProps, DateTimePickerSlotProps } from '@mui/x-date-pickers';
3
+ import React from 'react';
4
+ import type { ReactHookFormInput } from './types';
5
5
  /**
6
6
  * Should return an isostring in the form "YYYY-MM-DDThh:mmZ";
7
7
  * The milli seconds section should not be included, strictly YYYY-MM-DDThh:mm:ssZ is important
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
2
- import { FormControlProps } from '@mui/material';
3
- import { FieldErrors } from 'react-hook-form';
4
- import { TFunction } from 'i18next';
1
+ import type { FormControlProps } from '@mui/material';
2
+ import type { TFunction } from 'i18next';
3
+ import React from 'react';
4
+ import type { FieldErrors } from 'react-hook-form';
5
5
  interface ReactHookFormFormControlProps extends FormControlProps {
6
6
  children?: React.ReactNode;
7
7
  errors?: FieldErrors;
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- import { ReactHookFormInput } from './types';
1
+ import React from 'react';
2
+ import type { ReactHookFormInput } from './types';
3
3
  type ReactHookFormHiddenInputProps = ReactHookFormInput<{
4
4
  defaultValue?: unknown;
5
5
  }>;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { TextFieldProps } from '@mui/material';
3
- import { ReactHookFormInput } from './types';
1
+ import type { TextFieldProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { ReactHookFormInput } from './types';
4
4
  type InputMode = 'numeric' | 'decimal';
5
5
  export declare const convertNumericInputValue: (value: string, inputMode: InputMode) => number | null;
6
6
  export declare const getAllowedKeys: (inputMode?: InputMode) => string[];
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { UseFormProps } from 'react-hook-form';
2
+ import type { UseFormProps } from 'react-hook-form';
3
3
  interface WrapperProps {
4
4
  children: React.ReactNode;
5
5
  options?: UseFormProps;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { RadioGroupProps } from '@mui/material';
3
- import { ReactHookFormInput } from './types';
1
+ import type { RadioGroupProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { ReactHookFormInput } from './types';
4
4
  type ReactHookFormRadioGroupProps = Partial<RadioGroupProps> & ReactHookFormInput<{
5
5
  disabled?: boolean;
6
6
  children?: React.ReactNode;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { SelectProps } from '@mui/material';
3
- import { ReactHookFormInput } from './types';
1
+ import type { SelectProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { ReactHookFormInput } from './types';
4
4
  type ReactHookFormSelectProps = Partial<SelectProps> & ReactHookFormInput<object>;
5
5
  declare const ReactHookFormSelect: React.FC<ReactHookFormSelectProps>;
6
6
  export default ReactHookFormSelect;
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { BaseTextFieldProps, FilledInputProps, SlotCommonProps, SlotProps, TextFieldProps } from '@mui/material';
3
- import { ReactHookFormInput } from './types';
1
+ import type { BaseTextFieldProps, FilledInputProps, SlotCommonProps, SlotProps, TextFieldProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { ReactHookFormInput } from './types';
4
4
  export declare const convertTextInputValue: (value: string, inCapitals: boolean) => number | string;
5
5
  type ReactHookFormTextFieldProps = Partial<TextFieldProps> & ReactHookFormInput<{
6
6
  upperCase?: boolean;
@@ -1,3 +1,3 @@
1
- import { FieldErrors } from 'react-hook-form';
1
+ import type { FieldErrors } from 'react-hook-form';
2
2
  export declare function getDeepProperty<I>(property: string[], state: I): I | null;
3
3
  export declare const getErrors: (name: string, errors: FieldErrors) => FieldErrors | undefined;
@@ -1,4 +1,4 @@
1
- import { RegisterOptions } from 'react-hook-form';
1
+ import type { RegisterOptions } from 'react-hook-form';
2
2
  export type ReactHookFormInput<T> = T & {
3
3
  name: string;
4
4
  label?: string;
@@ -1,4 +1,4 @@
1
- import { Polygon } from 'geojson';
1
+ import type { Polygon } from 'geojson';
2
2
  export declare const defaultProps: {
3
3
  shouldUnregister: boolean;
4
4
  };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  export declare const HIDDEN_INPUT_HELPER_IS_DRAFT = "IS_DRAFT";
3
3
  export declare const useDraftFormHelpers: (isDefaultDraft?: boolean) => {
4
4
  isRequired: (value: string) => boolean | string;
@@ -1,5 +1,5 @@
1
1
  import i18n from 'i18next';
2
- import { UseTranslationResponse } from 'react-i18next';
2
+ import type { UseTranslationResponse } from 'react-i18next';
3
3
  export declare const FORM_FIELDS_NAMESPACE = "form-fields";
4
4
  export declare const initFormFieldsI18n: () => void;
5
5
  export declare const translateKeyOutsideComponents: (key: string, params?: Record<string, string | number> | undefined) => string;