@opengeoweb/form-fields 9.21.0 → 9.23.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.esm.js +117 -17
- package/package.json +5 -3
- package/src/index.d.ts +3 -0
- package/src/lib/components/Providers.d.ts +3 -0
- package/src/lib/utils/i18n.d.ts +4 -0
package/index.esm.js
CHANGED
|
@@ -3,12 +3,85 @@ import { FormControl, FormHelperText, InputLabel, Select, RadioGroup, TextField,
|
|
|
3
3
|
import { useFormContext, useController, useForm, FormProvider } from 'react-hook-form';
|
|
4
4
|
import { isEqual } from 'lodash';
|
|
5
5
|
import { dateUtils } from '@opengeoweb/shared';
|
|
6
|
+
import i18n from 'i18next';
|
|
7
|
+
import { initReactI18next } from 'react-i18next';
|
|
6
8
|
import * as React from 'react';
|
|
7
9
|
import { DateTimePicker } from '@mui/x-date-pickers';
|
|
8
10
|
import { CalendarToday } from '@opengeoweb/theme';
|
|
9
11
|
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
10
12
|
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
|
|
11
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-valid-max": "The maximum value is exceeded",
|
|
25
|
+
"form-fields-error-level-lower": "The lower level has to be below the upper level",
|
|
26
|
+
"form-fields-error-non-or-both-cooordinates": "Please enter both coordinates",
|
|
27
|
+
"form-fields-error-integer": "Invalid entry, enter a non-decimal number",
|
|
28
|
+
"form-fields-error-numeric": "Invalid entry, enter a numeric value"
|
|
29
|
+
};
|
|
30
|
+
var fi = {
|
|
31
|
+
"form-fields-error-required": "Tämä kenttä vaaditaan",
|
|
32
|
+
"form-fields-error-date-valid": "Epäkelpo päivämäärä",
|
|
33
|
+
"form-fields-error-date-after": "Päivämäärä ei voi olla aiemmin valittua ajanhetkeä",
|
|
34
|
+
"form-fields-error-date-hours-before": "Päivämäärä on liian kaukanan menneisyydessä",
|
|
35
|
+
"form-fields-error-date-hours-after": "Päivämäärä on liian kaukana tulevaisuudessa",
|
|
36
|
+
"form-fields-error-date-before": "Aikaleima on ajallisesti liian myöhään",
|
|
37
|
+
"form-fields-error-min-level": "Pienin sallittu taso on 1",
|
|
38
|
+
"form-fields-error-latitude": "Virheellinen leveysaste, odotettu arvo on kahden desimaalin tarkkuudella -90.00 ja 90.00 asteen välissä",
|
|
39
|
+
"form-fields-error-longitude": "Virheellinen pituusaste, odotettu arvo on kahden desimaalin tarkkuudella -180 ja 180 asteen välissä",
|
|
40
|
+
"form-fields-error-valid-max": "Maksimiarvo on ylitetty",
|
|
41
|
+
"form-fields-error-level-lower": "Alemman tason arvon on oltava ylemmän tason alla",
|
|
42
|
+
"form-fields-error-non-or-both-cooordinates": "Lisää molemmat kordinaatit",
|
|
43
|
+
"form-fields-error-integer": "Epäkelpo arvo, lisää kokonaisluku",
|
|
44
|
+
"form-fields-error-numeric": "Epäkelpo arvo, lisää numeerinen arvo"
|
|
45
|
+
};
|
|
46
|
+
var no = {
|
|
47
|
+
"form-fields-error-required": "Dette feltet er påkrevet",
|
|
48
|
+
"form-fields-error-date-valid": "Ingen gyldig dato",
|
|
49
|
+
"form-fields-error-date-after": "Dato skal ikke vere før",
|
|
50
|
+
"form-fields-error-date-hours-before": "Dato er for langt tilbake i tid",
|
|
51
|
+
"form-fields-error-date-hours-after": "Dato er for langt fram i tid",
|
|
52
|
+
"form-fields-error-date-before": "Tidspunktet er for seint",
|
|
53
|
+
"form-fields-error-min-level": "Mimimumsgrensen er 1",
|
|
54
|
+
"form-fields-error-latitude": "Ikke gyldig breddegrad, forventet et tall med to desimaler mellom -90.00 og 90.00",
|
|
55
|
+
"form-fields-error-longitude": "Ikke gyldig lengdegrad, forventet et tall med to desimaler mellom -180.00 og 180.00",
|
|
56
|
+
"form-fields-error-valid-max": "Maksimalverdien er overskredet",
|
|
57
|
+
"form-fields-error-level-lower": "Den laveste verdien må vere mindre enn den høyeste",
|
|
58
|
+
"form-fields-error-non-or-both-cooordinates": "Vennligst skriv inn begge koordinatene",
|
|
59
|
+
"form-fields-error-integer": "Ikke gyldig input, skriv inn et heltall",
|
|
60
|
+
"form-fields-error-numeric": "Ikke gyldig input, skriv inn et tall"
|
|
61
|
+
};
|
|
62
|
+
var nl = {
|
|
63
|
+
"form-fields-error-required": "Dit veld is verplicht",
|
|
64
|
+
"form-fields-error-date-valid": "Geen geldige datum",
|
|
65
|
+
"form-fields-error-date-after": "Datum mag niet in het verleden liggen",
|
|
66
|
+
"form-fields-error-date-hours-before": "Datum ligt te ver in het verleden",
|
|
67
|
+
"form-fields-error-date-hours-after": "Datum ligt te ver in de toekomst",
|
|
68
|
+
"form-fields-error-date-before": "Tijdsaanduiding is te laat",
|
|
69
|
+
"form-fields-error-min-level": "Het minimum niveau is 1",
|
|
70
|
+
"form-fields-error-latitude": "Ongeldige breedtegraad, er wordt een getal verwacht van maximaal 2 decimalen in graden tussen -90.00 en 90.00",
|
|
71
|
+
"form-fields-error-longitude": "Ongeldige lengtegraad, er wordt een getal verwacht van maximaal 2 decimalen in graden tussen -180.00 en 180.00",
|
|
72
|
+
"form-fields-error-valid-max": "Het maximum niveau is bereikt",
|
|
73
|
+
"form-fields-error-level-lower": "Het lage niveau moet onder het hoge niveau zijn",
|
|
74
|
+
"form-fields-error-non-or-both-cooordinates": "Voer beide coördinaten in",
|
|
75
|
+
"form-fields-error-integer": "Ongeldige invoer, voer een niet decimaal getal in",
|
|
76
|
+
"form-fields-error-numeric": "Ongeldige invoer, voor een numerieke waarde in"
|
|
77
|
+
};
|
|
78
|
+
var formFieldsTranslations = {
|
|
79
|
+
en: en,
|
|
80
|
+
fi: fi,
|
|
81
|
+
no: no,
|
|
82
|
+
nl: nl
|
|
83
|
+
};
|
|
84
|
+
|
|
12
85
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
13
86
|
|
|
14
87
|
var check = function (it) {
|
|
@@ -2080,20 +2153,20 @@ const defaultProps = {
|
|
|
2080
2153
|
shouldUnregister: false
|
|
2081
2154
|
};
|
|
2082
2155
|
const errorMessages = {
|
|
2083
|
-
required: '
|
|
2084
|
-
isValidDate: '
|
|
2085
|
-
isAfter: '
|
|
2086
|
-
isXHoursBefore: '
|
|
2087
|
-
isXHoursAfter: '
|
|
2088
|
-
isBefore: '
|
|
2089
|
-
minLevel: '
|
|
2090
|
-
isLatitude: '
|
|
2091
|
-
isLongitude: '
|
|
2092
|
-
isValidMax: '
|
|
2093
|
-
isLevelLower: '
|
|
2094
|
-
isNonOrBothCoordinates: '
|
|
2095
|
-
isInteger: '
|
|
2096
|
-
isNumeric: '
|
|
2156
|
+
required: 'form-fields-error-required',
|
|
2157
|
+
isValidDate: 'form-fields-error-date-valid',
|
|
2158
|
+
isAfter: 'form-fields-error-date-after',
|
|
2159
|
+
isXHoursBefore: 'form-fields-error-date-hours-before',
|
|
2160
|
+
isXHoursAfter: 'form-fields-error-date-hours-after',
|
|
2161
|
+
isBefore: 'form-fields-error-date-before',
|
|
2162
|
+
minLevel: 'form-fields-error-min-level',
|
|
2163
|
+
isLatitude: 'form-fields-error-latitude',
|
|
2164
|
+
isLongitude: 'form-fields-error-longitude',
|
|
2165
|
+
isValidMax: 'form-fields-error-valid-max',
|
|
2166
|
+
isLevelLower: 'form-fields-error-level-lower',
|
|
2167
|
+
isNonOrBothCoordinates: 'form-fields-error-non-or-both-cooordinate',
|
|
2168
|
+
isInteger: 'form-fields-error-integer',
|
|
2169
|
+
isNumeric: 'form-fields-error-numeric'
|
|
2097
2170
|
};
|
|
2098
2171
|
const regexMaxTwoDecimals = /^\s*-?\d+(\.\d{1,2})?\s*$/;
|
|
2099
2172
|
// validations
|
|
@@ -2279,6 +2352,33 @@ const isNonOrBothCoordinates = (coordinate, otherCoordinate) => {
|
|
|
2279
2352
|
return false;
|
|
2280
2353
|
};
|
|
2281
2354
|
|
|
2355
|
+
const FORM_FIELDS_NAMESPACE = 'form-fields';
|
|
2356
|
+
i18n.use(initReactI18next).init({
|
|
2357
|
+
lng: 'en',
|
|
2358
|
+
ns: FORM_FIELDS_NAMESPACE,
|
|
2359
|
+
interpolation: {
|
|
2360
|
+
escapeValue: false
|
|
2361
|
+
},
|
|
2362
|
+
resources: {
|
|
2363
|
+
en: {
|
|
2364
|
+
[FORM_FIELDS_NAMESPACE]: formFieldsTranslations.en
|
|
2365
|
+
},
|
|
2366
|
+
fi: {
|
|
2367
|
+
[FORM_FIELDS_NAMESPACE]: formFieldsTranslations.fi
|
|
2368
|
+
},
|
|
2369
|
+
no: {
|
|
2370
|
+
[FORM_FIELDS_NAMESPACE]: formFieldsTranslations.no
|
|
2371
|
+
},
|
|
2372
|
+
nl: {
|
|
2373
|
+
[FORM_FIELDS_NAMESPACE]: formFieldsTranslations.nl
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
});
|
|
2377
|
+
const ns = [FORM_FIELDS_NAMESPACE];
|
|
2378
|
+
const translateKeyOutsideComponents = (key, params = undefined) => i18n.t(key, Object.assign({
|
|
2379
|
+
ns
|
|
2380
|
+
}, params));
|
|
2381
|
+
|
|
2282
2382
|
const radioCheckboxStyle = {
|
|
2283
2383
|
// hides unchecked values
|
|
2284
2384
|
display: 'none',
|
|
@@ -2301,10 +2401,10 @@ const radioCheckboxStyle = {
|
|
|
2301
2401
|
};
|
|
2302
2402
|
const getErrorMessage = errors => {
|
|
2303
2403
|
if (errors && errors.message && typeof errors.message === 'string') {
|
|
2304
|
-
return errors.message;
|
|
2404
|
+
return translateKeyOutsideComponents(errors.message);
|
|
2305
2405
|
}
|
|
2306
2406
|
if (errors && errors.type && typeof errors.type === 'string') {
|
|
2307
|
-
return errorMessages[errors.type];
|
|
2407
|
+
return translateKeyOutsideComponents(errorMessages[errors.type]);
|
|
2308
2408
|
}
|
|
2309
2409
|
return '';
|
|
2310
2410
|
};
|
|
@@ -3294,4 +3394,4 @@ const useDraftFormHelpers = (isDefaultDraft = false) => {
|
|
|
3294
3394
|
};
|
|
3295
3395
|
};
|
|
3296
3396
|
|
|
3297
|
-
export { HIDDEN_INPUT_HELPER_IS_DRAFT, ReactHookKeyboardDateTimePicker as ReactHookFormDateTime, ReactHookFormFormControl, ReactHookFormHiddenInput, ReactHookFormNumberField, ReactHookFormProviderWrapper as ReactHookFormProvider, ReactHookFormRadioGroup, ReactHookFormSelect, ReactHookFormTextField, countIntersectionPoints, defaultFormOptions, errorMessages, getDateValue, getDeepProperty, getFormattedValueForDatePicker, hasIntersectionWithFIR, hasMulitpleIntersections, hasValidGeometry, isEmpty, isGeometryDirty, isInteger, isLatitude, isLongitude, isMaximumOneDrawing, isNonOrBothCoordinates, isValidGeoJsonCoordinates, isValidMax, isValidMin, isXHoursAfter, isXHoursBefore, useDraftFormHelpers };
|
|
3397
|
+
export { 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/form-fields",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.23.1",
|
|
4
4
|
"description": "GeoWeb form-fields library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
"url": "git@gitlab.com:opengeoweb/opengeoweb.git"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@mui/material": "
|
|
11
|
+
"@mui/material": "^5.16.0",
|
|
12
12
|
"@opengeoweb/theme": "*",
|
|
13
13
|
"react-hook-form": "^7.50.1",
|
|
14
14
|
"@mui/x-date-pickers": "^6.18.5",
|
|
15
15
|
"lodash": "^4.17.21",
|
|
16
|
-
"@opengeoweb/shared": "9.
|
|
16
|
+
"@opengeoweb/shared": "9.23.1",
|
|
17
|
+
"react-i18next": "^14.1.2",
|
|
18
|
+
"i18next": "^23.11.5"
|
|
17
19
|
},
|
|
18
20
|
"peerDependencies": {
|
|
19
21
|
"react": "18"
|
package/src/index.d.ts
CHANGED