@opengeoweb/form-fields 4.13.1 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './lib/components';
2
+ export * from './lib/hooks/useDraftFormHelpers/useDraftFormHelpers';
package/index.esm.js CHANGED
@@ -69,9 +69,7 @@ var errorMessages = {
69
69
  isLevelLower: 'The lower level has to be below the upper level',
70
70
  isNonOrBothCoordinates: 'Please enter both coordinates',
71
71
  isInteger: 'Invalid entry, enter a non-decimal number',
72
- isNumeric: 'Invalid entry, enter a numeric value',
73
- minVisibility: 'The minimum visibility is 0',
74
- maxVisibility: 'The maximum visibility is 4900'
72
+ isNumeric: 'Invalid entry, enter a numeric value'
75
73
  };
76
74
  var regexMaxTwoDecimals = /^\s*-?\d+(\.\d{1,2})?\s*$/; // validations
77
75
 
@@ -123,16 +121,18 @@ var isLatitude = function isLatitude(lat) {
123
121
  var isLongitude = function isLongitude(lng) {
124
122
  if (!lng) return true;
125
123
  return isFinite(lng) && Math.abs(lng) <= 180 && lng >= -180 && regexMaxTwoDecimals.test(lng.toString());
126
- };
124
+ }; // Pass null if no maxValue
125
+
127
126
  var isValidMax = function isValidMax(value, maxValue) {
128
- if (isEmpty(value)) {
127
+ if (isEmpty(value) || maxValue === null) {
129
128
  return true;
130
129
  }
131
130
 
132
131
  return !(value > maxValue);
133
- };
132
+ }; // Pass null if no minValue
133
+
134
134
  var isValidMin = function isValidMin(value, minValue) {
135
- if (isEmpty(value)) {
135
+ if (isEmpty(value) || minValue === null) {
136
136
  return true;
137
137
  }
138
138
 
@@ -902,4 +902,68 @@ var ReactHookFormHiddenInput = function ReactHookFormHiddenInput(_ref) {
902
902
  })) : null;
903
903
  };
904
904
 
905
- export { 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 };
905
+ /* *
906
+ * Licensed under the Apache License, Version 2.0 (the "License");
907
+ * you may not use this file except in compliance with the License.
908
+ * You may obtain a copy of the License at
909
+ *
910
+ * http://www.apache.org/licenses/LICENSE-2.0
911
+ *
912
+ * Unless required by applicable law or agreed to in writing, software
913
+ * distributed under the License is distributed on an "AS IS" BASIS,
914
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
915
+ * See the License for the specific language governing permissions and
916
+ * limitations under the License.
917
+ *
918
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
919
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
920
+ * */
921
+
922
+ var HIDDEN_INPUT_HELPER_IS_DRAFT = 'IS_DRAFT';
923
+ var useDraftFormHelpers = function useDraftFormHelpers() {
924
+ var isDefaultDraft = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
925
+
926
+ var _useFormContext = useFormContext(),
927
+ getValues = _useFormContext.getValues,
928
+ setValue = _useFormContext.setValue,
929
+ register = _useFormContext.register;
930
+
931
+ React.useEffect(function () {
932
+ setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDefaultDraft, {
933
+ shouldDirty: false
934
+ }); // eslint-disable-next-line react-hooks/exhaustive-deps
935
+ }, []);
936
+
937
+ var isDraft = function isDraft() {
938
+ return getValues(HIDDEN_INPUT_HELPER_IS_DRAFT) === true;
939
+ };
940
+
941
+ var isRequired = function isRequired(value) {
942
+ if (!isDraft() && isEmpty(value)) {
943
+ return errorMessages.required;
944
+ }
945
+
946
+ return true;
947
+ };
948
+
949
+ var toggleIsDraft = function toggleIsDraft(isDraft) {
950
+ return setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDraft, {
951
+ shouldDirty: false
952
+ });
953
+ };
954
+
955
+ var DraftFieldHelper = function DraftFieldHelper() {
956
+ return /*#__PURE__*/React.createElement("input", Object.assign({}, register(HIDDEN_INPUT_HELPER_IS_DRAFT), {
957
+ type: "hidden"
958
+ }));
959
+ };
960
+
961
+ return {
962
+ isRequired: isRequired,
963
+ toggleIsDraft: toggleIsDraft,
964
+ isDraft: isDraft,
965
+ DraftFieldHelper: DraftFieldHelper
966
+ };
967
+ };
968
+
969
+ 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, useDraftFormHelpers };
package/index.umd.js CHANGED
@@ -127,9 +127,7 @@
127
127
  isLevelLower: 'The lower level has to be below the upper level',
128
128
  isNonOrBothCoordinates: 'Please enter both coordinates',
129
129
  isInteger: 'Invalid entry, enter a non-decimal number',
130
- isNumeric: 'Invalid entry, enter a numeric value',
131
- minVisibility: 'The minimum visibility is 0',
132
- maxVisibility: 'The maximum visibility is 4900'
130
+ isNumeric: 'Invalid entry, enter a numeric value'
133
131
  };
134
132
  var regexMaxTwoDecimals = /^\s*-?\d+(\.\d{1,2})?\s*$/; // validations
135
133
 
@@ -185,16 +183,18 @@
185
183
  var isLongitude = function isLongitude(lng) {
186
184
  if (!lng) return true;
187
185
  return isFinite(lng) && Math.abs(lng) <= 180 && lng >= -180 && regexMaxTwoDecimals.test(lng.toString());
188
- };
186
+ }; // Pass null if no maxValue
187
+
189
188
  var isValidMax = function isValidMax(value, maxValue) {
190
- if (isEmpty(value)) {
189
+ if (isEmpty(value) || maxValue === null) {
191
190
  return true;
192
191
  }
193
192
 
194
193
  return !(value > maxValue);
195
- };
194
+ }; // Pass null if no minValue
195
+
196
196
  var isValidMin = function isValidMin(value, minValue) {
197
- if (isEmpty(value)) {
197
+ if (isEmpty(value) || minValue === null) {
198
198
  return true;
199
199
  }
200
200
 
@@ -853,6 +853,56 @@
853
853
  })) : null;
854
854
  };
855
855
 
856
+ var HIDDEN_INPUT_HELPER_IS_DRAFT = 'IS_DRAFT';
857
+ var useDraftFormHelpers = function useDraftFormHelpers(isDefaultDraft) {
858
+ if (isDefaultDraft === void 0) {
859
+ isDefaultDraft = false;
860
+ }
861
+
862
+ var _a = reactHookForm.useFormContext(),
863
+ getValues = _a.getValues,
864
+ setValue = _a.setValue,
865
+ register = _a.register;
866
+
867
+ React__namespace.useEffect(function () {
868
+ setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDefaultDraft, {
869
+ shouldDirty: false
870
+ }); // eslint-disable-next-line react-hooks/exhaustive-deps
871
+ }, []);
872
+
873
+ var isDraft = function isDraft() {
874
+ return getValues(HIDDEN_INPUT_HELPER_IS_DRAFT) === true;
875
+ };
876
+
877
+ var isRequired = function isRequired(value) {
878
+ if (!isDraft() && isEmpty(value)) {
879
+ return errorMessages.required;
880
+ }
881
+
882
+ return true;
883
+ };
884
+
885
+ var toggleIsDraft = function toggleIsDraft(isDraft) {
886
+ return setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDraft, {
887
+ shouldDirty: false
888
+ });
889
+ };
890
+
891
+ var DraftFieldHelper = function DraftFieldHelper() {
892
+ return /*#__PURE__*/React__namespace.createElement("input", __assign({}, register(HIDDEN_INPUT_HELPER_IS_DRAFT), {
893
+ type: "hidden"
894
+ }));
895
+ };
896
+
897
+ return {
898
+ isRequired: isRequired,
899
+ toggleIsDraft: toggleIsDraft,
900
+ isDraft: isDraft,
901
+ DraftFieldHelper: DraftFieldHelper
902
+ };
903
+ };
904
+
905
+ exports.HIDDEN_INPUT_HELPER_IS_DRAFT = HIDDEN_INPUT_HELPER_IS_DRAFT;
856
906
  exports.ReactHookFormDateTime = ReactHookKeyboardDateTimePicker;
857
907
  exports.ReactHookFormFormControl = ReactHookFormFormControl;
858
908
  exports.ReactHookFormHiddenInput = ReactHookFormHiddenInput;
@@ -883,6 +933,7 @@
883
933
  exports.isValidMin = isValidMin;
884
934
  exports.isXHoursAfter = isXHoursAfter;
885
935
  exports.isXHoursBefore = isXHoursBefore;
936
+ exports.useDraftFormHelpers = useDraftFormHelpers;
886
937
 
887
938
  Object.defineProperty(exports, '__esModule', { value: true });
888
939
 
@@ -17,8 +17,6 @@ export declare const errorMessages: {
17
17
  isNonOrBothCoordinates: string;
18
18
  isInteger: string;
19
19
  isNumeric: string;
20
- minVisibility: string;
21
- maxVisibility: string;
22
20
  };
23
21
  export declare const isEmpty: (value?: string | number | null | undefined) => boolean;
24
22
  export declare const isValidDate: (value?: string | moment.Moment | null | undefined) => boolean;
@@ -29,8 +27,8 @@ export declare const isXHoursBefore: (ownDate: string, otherDate: string, hours?
29
27
  export declare const isXHoursAfter: (ownDate: string, otherDate: string, hours?: number) => boolean;
30
28
  export declare const isLatitude: (lat?: number | null | undefined) => boolean;
31
29
  export declare const isLongitude: (lng?: number | null | undefined) => boolean;
32
- export declare const isValidMax: (value: number, maxValue: number) => boolean;
33
- export declare const isValidMin: (value: number, minValue: number) => boolean;
30
+ export declare const isValidMax: (value: number, maxValue: number | null) => boolean;
31
+ export declare const isValidMin: (value: number, minValue: number | null) => boolean;
34
32
  export declare const hasValidGeometry: (geojson?: import("geojson").FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | null | undefined) => boolean;
35
33
  export declare const isValidGeoJsonCoordinates: (geojson: GeoJSON.FeatureCollection) => boolean;
36
34
  export declare const isMaximumOneDrawing: (geojson: GeoJSON.FeatureCollection) => boolean;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ export declare const HIDDEN_INPUT_HELPER_IS_DRAFT = "IS_DRAFT";
3
+ export declare const useDraftFormHelpers: (isDefaultDraft?: boolean) => {
4
+ isRequired: (value: string) => boolean | string;
5
+ toggleIsDraft: (isDraft: boolean) => void;
6
+ isDraft: () => boolean;
7
+ DraftFieldHelper: () => React.ReactElement;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/form-fields",
3
- "version": "4.13.1",
3
+ "version": "4.14.1",
4
4
  "description": "GeoWeb form-fields library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "react-hook-form": "^7.41.5",
16
16
  "react": "^18.2.0",
17
17
  "@mui/material": "^5.10.8",
18
- "@opengeoweb/theme": "4.13.1",
18
+ "@opengeoweb/theme": "4.14.1",
19
19
  "moment": "^2.29.0",
20
20
  "moment-timezone": "^0.5.31",
21
21
  "@mui/x-date-pickers": "^5.0.4",