@arquimedes.co/eureka-forms 3.0.49-new-steps → 3.0.50-test
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/dist/@Types/Condition.d.ts +6 -4
- package/dist/@Types/ErkValue.d.ts +16 -0
- package/dist/@Types/ErkValue.js +1 -0
- package/dist/@Types/Form.d.ts +1 -0
- package/dist/@Types/FormStep.d.ts +10 -8
- package/dist/@Types/FormStep.js +1 -2
- package/dist/@Types/User.d.ts +13 -0
- package/dist/@Types/User.js +1 -0
- package/dist/App/App.js +1 -1
- package/dist/App/AppFunctions.js +8 -3
- package/dist/App/AppHooks.js +20 -1
- package/dist/Form/Form.js +6 -2
- package/dist/Form/Form.module.css +48 -39
- package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.js +8 -4
- package/dist/FormSteps/CBRStepMapper.js +1 -1
- package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +2 -2
- package/dist/FormSteps/DatePickerRangeStep/MaterialDatePickerRangeStep/MaterialDatePickerRangeStep.js +1 -1
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +52 -4
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.js +1 -1
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.module.css +1 -1
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +48 -17
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.module.css +16 -0
- package/dist/FormSteps/Step.js +0 -16
- package/dist/FormSteps/StepFunctions.js +6 -23
- package/dist/FormSteps/StepFunctions.test.js +3 -57
- package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +2 -1
- package/dist/Icons/@ErkIcon.d.ts +2 -2
- package/dist/Icons/@ErkIcon.js +2 -2
- package/dist/Icons/EmailIcon.d.ts +3 -0
- package/dist/Icons/{EditIcon.js → EmailIcon.js} +3 -3
- package/dist/Icons/Entities/SchoolIcon.d.ts +3 -0
- package/dist/Icons/Entities/SchoolIcon.js +7 -0
- package/dist/Icons/GroupIcon.d.ts +3 -0
- package/dist/Icons/GroupIcon.js +7 -0
- package/dist/Icons/LockedIcon.d.ts +3 -0
- package/dist/Icons/LockedIcon.js +7 -0
- package/dist/Login/Login.module.css +135 -0
- package/dist/Login/LoginLayout.module.css +68 -0
- package/dist/Login/LoginPage.d.ts +10 -0
- package/dist/Login/LoginPage.js +101 -0
- package/dist/Login/LoginTextField.d.ts +14 -0
- package/dist/Login/LoginTextField.js +29 -0
- package/dist/Services/ApiSelectorService.d.ts +366 -0
- package/dist/Services/ApiSelectorService.js +173 -0
- package/dist/Services/ApiSelectorService.test.d.ts +1 -0
- package/dist/Services/ApiSelectorService.test.js +87 -0
- package/dist/Services/DraftService.js +4 -1
- package/dist/Services/IntegrationService.d.ts +21 -0
- package/dist/Services/IntegrationService.js +22 -0
- package/dist/Services/UserService.d.ts +10 -0
- package/dist/Services/UserService.js +21 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +11 -4
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +3 -2
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +10 -4
- package/dist/Shared/ErkSelect/ErkSelect.d.ts +2 -2
- package/dist/Shared/InputIcon/InputIcon.js +6 -0
- package/dist/Shared/Navbar/Navbar.d.ts +2 -1
- package/dist/Shared/Navbar/Navbar.js +22 -3
- package/dist/Shared/Navbar/Navbar.module.css +22 -8
- package/dist/Shared/SmartDraftRenderer/LinkDecorator.d.ts +14 -0
- package/dist/Shared/SmartDraftRenderer/LinkDecorator.js +48 -0
- package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.js +10 -3
- package/dist/States/GlobalSlice.d.ts +4 -1
- package/dist/States/GlobalSlice.js +8 -1
- package/dist/constants/ErkIconTypes.d.ts +3 -1
- package/dist/constants/ErkIconTypes.js +2 -0
- package/dist/constants/ErkValueTypes.d.ts +6 -0
- package/dist/constants/ErkValueTypes.js +7 -0
- package/dist/constants/FormStepTypes.d.ts +3 -6
- package/dist/constants/FormStepTypes.js +1 -4
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +17 -1
- package/package.json +9 -3
- package/dist/@Types/AvailabilityFormStep.d.ts +0 -48
- package/dist/@Types/AvailabilityFormStep.js +0 -24
- package/dist/@Types/BankAccountFormStep.d.ts +0 -67
- package/dist/@Types/BankAccountFormStep.js +0 -14
- package/dist/@Types/BookingFormStep.d.ts +0 -156
- package/dist/@Types/BookingFormStep.js +0 -44
- package/dist/@Types/CalendarFormStep.d.ts +0 -192
- package/dist/@Types/CalendarFormStep.js +0 -48
- package/dist/@Types/CommunicationChannelFormStep.d.ts +0 -51
- package/dist/@Types/CommunicationChannelFormStep.js +0 -15
- package/dist/@Types/ConsentFormStep.d.ts +0 -36
- package/dist/@Types/ConsentFormStep.js +0 -8
- package/dist/@Types/EntityFormFormStep.d.ts +0 -66
- package/dist/@Types/EntityFormFormStep.js +0 -20
- package/dist/@Types/EventFormStep.d.ts +0 -52
- package/dist/@Types/EventFormStep.js +0 -13
- package/dist/@Types/ExternalReferenceFormStep.d.ts +0 -74
- package/dist/@Types/ExternalReferenceFormStep.js +0 -20
- package/dist/@Types/LocationFormStep.d.ts +0 -159
- package/dist/@Types/LocationFormStep.js +0 -46
- package/dist/@Types/NumericFormSteps.d.ts +0 -108
- package/dist/@Types/NumericFormSteps.js +0 -20
- package/dist/@Types/PredefinedSelectorFormStep.d.ts +0 -51
- package/dist/@Types/PredefinedSelectorFormStep.js +0 -39
- package/dist/@Types/StepRef.d.ts +0 -135
- package/dist/@Types/StepRef.js +0 -49
- package/dist/FormSteps/BookingStep/BookingStep.d.ts +0 -17
- package/dist/FormSteps/BookingStep/BookingStep.js +0 -14
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +0 -3
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +0 -362
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.module.css +0 -174
- package/dist/FormSteps/CalendarStep/CalendarStep.d.ts +0 -7
- package/dist/FormSteps/CalendarStep/CalendarStep.js +0 -14
- package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.d.ts +0 -3
- package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.js +0 -269
- package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.module.css +0 -531
- package/dist/FormSteps/LocationStep/LocationStep.d.ts +0 -10
- package/dist/FormSteps/LocationStep/LocationStep.js +0 -14
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +0 -3
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +0 -47
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +0 -18
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +0 -3
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +0 -168
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +0 -94
- package/dist/FormSteps/NumberStep/NumberStep.d.ts +0 -10
- package/dist/FormSteps/NumberStep/NumberStep.js +0 -14
- package/dist/Icons/AddIcon.d.ts +0 -3
- package/dist/Icons/AddIcon.js +0 -7
- package/dist/Icons/EditIcon.d.ts +0 -3
- package/dist/Icons/RemoveIcon.d.ts +0 -3
- package/dist/Icons/RemoveIcon.js +0 -7
- package/dist/Icons/ViewDayIcon.d.ts +0 -3
- package/dist/Icons/ViewDayIcon.js +0 -7
- package/dist/Icons/ViewWeekIcon.d.ts +0 -3
- package/dist/Icons/ViewWeekIcon.js +0 -7
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +0 -19
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +0 -80
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +0 -82
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +0 -29
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +0 -139
- package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +0 -23
- package/dist/Shared/ErkLocationField/ErkLocationField.js +0 -73
- package/dist/Shared/ErkLocationField/ErkLocationField.module.css +0 -29
- package/dist/Shared/ErkLocationField/addressFields.d.ts +0 -12
- package/dist/Shared/ErkLocationField/addressFields.js +0 -34
- package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +0 -6
- package/dist/Shared/ErkLocationField/locationRestrictions.js +0 -51
- package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +0 -15
- package/dist/Shared/ErkLocationInput/ErkLocationInput.js +0 -499
- package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +0 -115
- package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +0 -42
- package/dist/Shared/ErkNumberField/ErkNumberField.js +0 -170
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { LocationInputMode } from '../../@Types/LocationFormStep';
|
|
2
|
-
/**
|
|
3
|
-
* Carga y consulta de Google Places (nueva API `AutocompleteSuggestion`).
|
|
4
|
-
* Encapsula el script loader + importLibrary que antes vivía inline en ErkLocationInput,
|
|
5
|
-
* para reutilizarlo desde el autocomplete de Base UI sin duplicar lógica.
|
|
6
|
-
*/
|
|
7
|
-
// Google's new Places classes (AutocompleteSuggestion/SessionToken) are untyped in the
|
|
8
|
-
// installed @types/google.maps, so they're kept as `any` — same approach as ErkLocationInput.
|
|
9
|
-
let loadPromise = null;
|
|
10
|
-
let suggestionClass = null;
|
|
11
|
-
let sessionTokenClass = null;
|
|
12
|
-
let geocoderClass = null;
|
|
13
|
-
function loadScript(apiKey) {
|
|
14
|
-
if (typeof window === 'undefined')
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
const win = window;
|
|
17
|
-
if (win.google?.maps?.importLibrary)
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
if (loadPromise)
|
|
20
|
-
return loadPromise;
|
|
21
|
-
loadPromise = new Promise((resolve, reject) => {
|
|
22
|
-
const script = document.createElement('script');
|
|
23
|
-
script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&loading=async`;
|
|
24
|
-
script.async = true;
|
|
25
|
-
script.defer = true;
|
|
26
|
-
script.onload = () => resolve();
|
|
27
|
-
script.onerror = () => {
|
|
28
|
-
loadPromise = null;
|
|
29
|
-
reject(new Error('Google Maps script failed to load.'));
|
|
30
|
-
};
|
|
31
|
-
document.head.appendChild(script);
|
|
32
|
-
});
|
|
33
|
-
return loadPromise;
|
|
34
|
-
}
|
|
35
|
-
/** Asegura el script cargado y las clases de Places listas. Idempotente. */
|
|
36
|
-
export async function loadPlaces(apiKey) {
|
|
37
|
-
await loadScript(apiKey);
|
|
38
|
-
const win = window;
|
|
39
|
-
if (win.google?.maps?.importLibrary && !suggestionClass) {
|
|
40
|
-
const places = await win.google.maps.importLibrary('places');
|
|
41
|
-
suggestionClass = places.AutocompleteSuggestion;
|
|
42
|
-
sessionTokenClass = places.AutocompleteSessionToken;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/** Token de sesión nuevo (mejora el billing/relevancia de Google). */
|
|
46
|
-
export function newSessionToken() {
|
|
47
|
-
return sessionTokenClass ? new sessionTokenClass() : undefined;
|
|
48
|
-
}
|
|
49
|
-
/** Reverse-geocoding para el modo GPS: coordenadas → dirección estructurada. */
|
|
50
|
-
export async function reverseGeocode(apiKey, lat, lng) {
|
|
51
|
-
await loadScript(apiKey);
|
|
52
|
-
const win = window;
|
|
53
|
-
if (win.google?.maps?.importLibrary && !geocoderClass) {
|
|
54
|
-
const geocoding = await win.google.maps.importLibrary('geocoding');
|
|
55
|
-
geocoderClass = geocoding.Geocoder;
|
|
56
|
-
}
|
|
57
|
-
else if (!geocoderClass && win.google?.maps?.Geocoder) {
|
|
58
|
-
geocoderClass = win.google.maps.Geocoder;
|
|
59
|
-
}
|
|
60
|
-
if (!geocoderClass)
|
|
61
|
-
return { addressDetail: {} };
|
|
62
|
-
const geocoder = new geocoderClass();
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
geocoder.geocode({ location: { lat, lng } }, (results, status) => {
|
|
65
|
-
if (status === 'OK' && results?.[0]) {
|
|
66
|
-
resolve({
|
|
67
|
-
address: results[0].formatted_address,
|
|
68
|
-
addressDetail: parseAddressComponents(results[0].address_components),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
resolve({ addressDetail: {} });
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export async function fetchAddressSuggestions(input, options) {
|
|
78
|
-
if (!suggestionClass)
|
|
79
|
-
return [];
|
|
80
|
-
const request = { input };
|
|
81
|
-
if (options?.sessionToken)
|
|
82
|
-
request.sessionToken = options.sessionToken;
|
|
83
|
-
if (options?.regionCodes)
|
|
84
|
-
request.includedRegionCodes = options.regionCodes;
|
|
85
|
-
const { suggestions } = await suggestionClass.fetchAutocompleteSuggestions(request);
|
|
86
|
-
return suggestions
|
|
87
|
-
.filter((s) => s.placePrediction)
|
|
88
|
-
.map((s) => ({
|
|
89
|
-
placeId: s.placePrediction.placeId,
|
|
90
|
-
label: s.placePrediction.mainText?.text ?? s.placePrediction.text.text,
|
|
91
|
-
description: s.placePrediction.secondaryText?.text ?? s.placePrediction.text.text,
|
|
92
|
-
toPlace: () => s.placePrediction.toPlace(),
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Descompone los `addressComponents` de un Place en el shape estructurado del step.
|
|
97
|
-
* Acepta el formato nuevo (`longText`/`shortText`) y el legacy (`long_name`/`short_name`).
|
|
98
|
-
*/
|
|
99
|
-
export function parseAddressComponents(components) {
|
|
100
|
-
const detail = {};
|
|
101
|
-
for (const component of components ?? []) {
|
|
102
|
-
const types = component.types;
|
|
103
|
-
const longName = component.longText ?? component.long_name;
|
|
104
|
-
const shortName = component.shortText ?? component.short_name;
|
|
105
|
-
if (types.includes('route'))
|
|
106
|
-
detail.street = longName;
|
|
107
|
-
else if (types.includes('street_number'))
|
|
108
|
-
detail.streetNumber = longName;
|
|
109
|
-
else if (types.includes('subpremise'))
|
|
110
|
-
detail.unit = longName;
|
|
111
|
-
else if (types.includes('neighborhood') || types.includes('sublocality'))
|
|
112
|
-
detail.neighborhood = longName;
|
|
113
|
-
else if (types.includes('locality'))
|
|
114
|
-
detail.city = longName;
|
|
115
|
-
else if (types.includes('administrative_area_level_1'))
|
|
116
|
-
detail.state = longName;
|
|
117
|
-
else if (types.includes('country')) {
|
|
118
|
-
detail.country = longName;
|
|
119
|
-
detail.countryCode = shortName;
|
|
120
|
-
}
|
|
121
|
-
else if (types.includes('postal_code'))
|
|
122
|
-
detail.postalCode = longName;
|
|
123
|
-
}
|
|
124
|
-
return detail;
|
|
125
|
-
}
|
|
126
|
-
/** Resuelve una predicción a un `LocationStepValue` completo (fetchFields + parse). */
|
|
127
|
-
export async function resolvePrediction(prediction) {
|
|
128
|
-
const place = prediction.toPlace();
|
|
129
|
-
await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location', 'addressComponents'] });
|
|
130
|
-
return {
|
|
131
|
-
source: LocationInputMode.GOOGLE_PLACES,
|
|
132
|
-
latitude: place.location?.lat(),
|
|
133
|
-
longitude: place.location?.lng(),
|
|
134
|
-
name: place.displayName ?? prediction.label,
|
|
135
|
-
address: place.formattedAddress ?? undefined,
|
|
136
|
-
placeId: prediction.placeId,
|
|
137
|
-
addressDetail: parseAddressComponents(place.addressComponents),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LocationInputMode, LocationStep, LocationStepValue } from '../../@Types/LocationFormStep';
|
|
3
|
-
export interface ErkLocationFieldProps {
|
|
4
|
-
value?: LocationStepValue | null;
|
|
5
|
-
onChange: (value: LocationStepValue | null) => void;
|
|
6
|
-
allowedModes: LocationInputMode[];
|
|
7
|
-
defaultMode?: LocationInputMode;
|
|
8
|
-
addressFields?: LocationStep['addressFields'];
|
|
9
|
-
/** ISO-2 para acotar el buscador (ej. ['co']). */
|
|
10
|
-
regionCodes?: string[];
|
|
11
|
-
error?: boolean;
|
|
12
|
-
helperText?: string | null;
|
|
13
|
-
required?: boolean;
|
|
14
|
-
readOnly?: boolean;
|
|
15
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Campo de ubicación (rehecho con Base UI). Ofrece los modos habilitados
|
|
19
|
-
* (buscador de Google Places, GPS, entrada manual) y aplica la config por campo
|
|
20
|
-
* (fijo / omitir) al valor resultante.
|
|
21
|
-
*/
|
|
22
|
-
declare function ErkLocationField({ value, onChange, allowedModes, defaultMode, addressFields, regionCodes, error, helperText, required, readOnly, inputRef, }: ErkLocationFieldProps): JSX.Element;
|
|
23
|
-
export default ErkLocationField;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useState } from 'react';
|
|
3
|
-
import { AddressFieldMode, LocationInputMode, } from '../../@Types/LocationFormStep';
|
|
4
|
-
import ErkAddressAutocomplete from '../ErkAddressAutocomplete/ErkAddressAutocomplete';
|
|
5
|
-
import { reverseGeocode } from '../ErkAddressAutocomplete/googlePlaces';
|
|
6
|
-
import { ADDRESS_FIELDS, applyAddressFields, fieldConfig } from './addressFields';
|
|
7
|
-
import ErkTextField from '../ErkTextField/ErkTextField';
|
|
8
|
-
import ErkButton from '../ErkButton/ErkButton';
|
|
9
|
-
import LocationIcon from '../../Icons/LocationIcon';
|
|
10
|
-
import styles from './ErkLocationField.module.css';
|
|
11
|
-
const MODE_LABELS = {
|
|
12
|
-
[LocationInputMode.GOOGLE_PLACES]: 'Buscar',
|
|
13
|
-
[LocationInputMode.GPS]: 'Mi ubicación',
|
|
14
|
-
[LocationInputMode.MANUAL]: 'Manual',
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Campo de ubicación (rehecho con Base UI). Ofrece los modos habilitados
|
|
18
|
-
* (buscador de Google Places, GPS, entrada manual) y aplica la config por campo
|
|
19
|
-
* (fijo / omitir) al valor resultante.
|
|
20
|
-
*/
|
|
21
|
-
function ErkLocationField({ value, onChange, allowedModes, defaultMode, addressFields, regionCodes = ['co'], error = false, helperText, required = false, readOnly = false, inputRef, }) {
|
|
22
|
-
const apiKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY ?? '';
|
|
23
|
-
const initialMode = defaultMode && allowedModes.includes(defaultMode) ? defaultMode : allowedModes[0];
|
|
24
|
-
const [mode, setMode] = useState(initialMode);
|
|
25
|
-
const [gpsLoading, setGpsLoading] = useState(false);
|
|
26
|
-
const [gpsError, setGpsError] = useState(null);
|
|
27
|
-
const handleGoogle = useCallback((resolved) => {
|
|
28
|
-
onChange({ ...resolved, addressDetail: applyAddressFields(resolved.addressDetail ?? {}, addressFields) });
|
|
29
|
-
}, [onChange, addressFields]);
|
|
30
|
-
const handleGps = useCallback(() => {
|
|
31
|
-
if (!navigator.geolocation) {
|
|
32
|
-
setGpsError('La geolocalización no es compatible con este navegador.');
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
setGpsLoading(true);
|
|
36
|
-
setGpsError(null);
|
|
37
|
-
navigator.geolocation.getCurrentPosition((position) => {
|
|
38
|
-
const lat = position.coords.latitude;
|
|
39
|
-
const lng = position.coords.longitude;
|
|
40
|
-
void reverseGeocode(apiKey, lat, lng)
|
|
41
|
-
.then(({ address, addressDetail }) => {
|
|
42
|
-
onChange({
|
|
43
|
-
source: LocationInputMode.GPS,
|
|
44
|
-
latitude: lat,
|
|
45
|
-
longitude: lng,
|
|
46
|
-
address: address ?? `${lat.toFixed(6)}, ${lng.toFixed(6)}`,
|
|
47
|
-
addressDetail: applyAddressFields(addressDetail, addressFields),
|
|
48
|
-
});
|
|
49
|
-
})
|
|
50
|
-
.finally(() => setGpsLoading(false));
|
|
51
|
-
}, () => {
|
|
52
|
-
setGpsError('No se pudo obtener la ubicación.');
|
|
53
|
-
setGpsLoading(false);
|
|
54
|
-
}, { enableHighAccuracy: false, timeout: 15000, maximumAge: 300000 });
|
|
55
|
-
}, [apiKey, onChange, addressFields]);
|
|
56
|
-
const updateManualField = useCallback((key, text) => {
|
|
57
|
-
const base = value?.source === LocationInputMode.MANUAL ? (value.addressDetail ?? {}) : {};
|
|
58
|
-
const nextDetail = applyAddressFields({ ...base, [key]: text || undefined }, addressFields);
|
|
59
|
-
const address = ADDRESS_FIELDS.map(({ key: k }) => nextDetail[k])
|
|
60
|
-
.filter(Boolean)
|
|
61
|
-
.join(', ');
|
|
62
|
-
onChange({ source: LocationInputMode.MANUAL, address, addressDetail: nextDetail });
|
|
63
|
-
}, [value, onChange, addressFields]);
|
|
64
|
-
const manualDetail = value?.source === LocationInputMode.MANUAL ? (value.addressDetail ?? {}) : {};
|
|
65
|
-
return (_jsxs("div", { className: styles.container, children: [allowedModes.length > 1 && (_jsx("div", { className: styles.modeSwitch, children: allowedModes.map((m) => (_jsx(ErkButton, { color: m === mode ? 'primary' : 'secondary', disabled: readOnly, onClick: () => setMode(m), children: MODE_LABELS[m] }, m))) })), mode === LocationInputMode.GOOGLE_PLACES && (_jsx(ErkAddressAutocomplete, { value: value, onChange: handleGoogle, regionCodes: regionCodes, error: error, required: required, readOnly: readOnly, inputRef: inputRef })), mode === LocationInputMode.GPS && (_jsxs(ErkButton, { color: "primary", loading: gpsLoading, disabled: readOnly, onClick: handleGps, children: [_jsx(LocationIcon, { fill: "currentColor" }), " Usar mi ubicaci\u00F3n actual"] })), mode === LocationInputMode.MANUAL && (_jsx("div", { className: styles.manualGrid, children: ADDRESS_FIELDS.map(({ key, label }) => {
|
|
66
|
-
const config = fieldConfig(addressFields, key);
|
|
67
|
-
if (config.mode === AddressFieldMode.OMIT)
|
|
68
|
-
return null;
|
|
69
|
-
const fixed = config.mode === AddressFieldMode.FIXED;
|
|
70
|
-
return (_jsx(ErkTextField, { label: fixed ? `${label} (fijo)` : label, value: fixed ? (config.fixedValue ?? '') : (manualDetail[key] ?? ''), readOnly: fixed || readOnly, onChange: (text) => updateManualField(key, text) }, key));
|
|
71
|
-
}) })), (gpsError ?? helperText) && (_jsx("div", { className: error || gpsError ? styles.errorText : styles.helperText, children: gpsError ?? helperText }))] }));
|
|
72
|
-
}
|
|
73
|
-
export default ErkLocationField;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
gap: 10px;
|
|
5
|
-
width: 100%;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.modeSwitch {
|
|
9
|
-
display: flex;
|
|
10
|
-
gap: 8px;
|
|
11
|
-
flex-wrap: wrap;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.manualGrid {
|
|
15
|
-
display: grid;
|
|
16
|
-
grid-template-columns: repeat(2, 1fr);
|
|
17
|
-
gap: 10px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.helperText {
|
|
21
|
-
font-size: 12px;
|
|
22
|
-
color: var(--eureka-text, #666);
|
|
23
|
-
opacity: 0.7;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.errorText {
|
|
27
|
-
font-size: 12px;
|
|
28
|
-
color: var(--eureka-error, #e53935);
|
|
29
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AddressFieldConfig, AddressFieldKey, LocationAddressDetail, LocationStep } from '../../@Types/LocationFormStep';
|
|
2
|
-
/** Campos de dirección en orden de render, con su etiqueta de UI. */
|
|
3
|
-
export declare const ADDRESS_FIELDS: {
|
|
4
|
-
key: AddressFieldKey;
|
|
5
|
-
label: string;
|
|
6
|
-
}[];
|
|
7
|
-
export declare function fieldConfig(addressFields: LocationStep['addressFields'], key: AddressFieldKey): AddressFieldConfig;
|
|
8
|
-
/**
|
|
9
|
-
* Aplica la config por campo a una dirección resuelta (Google/GPS):
|
|
10
|
-
* los `FIXED` se sobreescriben con el valor del diseñador y los `OMIT` se descartan.
|
|
11
|
-
*/
|
|
12
|
-
export declare function applyAddressFields(detail: LocationAddressDetail, addressFields: LocationStep['addressFields']): LocationAddressDetail;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AddressFieldMode, } from '../../@Types/LocationFormStep';
|
|
2
|
-
/** Campos de dirección en orden de render, con su etiqueta de UI. */
|
|
3
|
-
export const ADDRESS_FIELDS = [
|
|
4
|
-
{ key: 'street', label: 'Calle' },
|
|
5
|
-
{ key: 'streetNumber', label: 'Número' },
|
|
6
|
-
{ key: 'unit', label: 'Interior / Apto' },
|
|
7
|
-
{ key: 'neighborhood', label: 'Barrio' },
|
|
8
|
-
{ key: 'city', label: 'Ciudad' },
|
|
9
|
-
{ key: 'state', label: 'Departamento / Región' },
|
|
10
|
-
{ key: 'postalCode', label: 'Código postal' },
|
|
11
|
-
{ key: 'country', label: 'País' },
|
|
12
|
-
];
|
|
13
|
-
export function fieldConfig(addressFields, key) {
|
|
14
|
-
return addressFields?.[key] ?? { mode: AddressFieldMode.ASK };
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Aplica la config por campo a una dirección resuelta (Google/GPS):
|
|
18
|
-
* los `FIXED` se sobreescriben con el valor del diseñador y los `OMIT` se descartan.
|
|
19
|
-
*/
|
|
20
|
-
export function applyAddressFields(detail, addressFields) {
|
|
21
|
-
if (!addressFields)
|
|
22
|
-
return detail;
|
|
23
|
-
const result = { ...detail };
|
|
24
|
-
for (const { key } of ADDRESS_FIELDS) {
|
|
25
|
-
const config = addressFields[key];
|
|
26
|
-
if (!config)
|
|
27
|
-
continue;
|
|
28
|
-
if (config.mode === AddressFieldMode.OMIT)
|
|
29
|
-
delete result[key];
|
|
30
|
-
else if (config.mode === AddressFieldMode.FIXED)
|
|
31
|
-
result[key] = config.fixedValue;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { LocationRestriction } from '../../@Types/LocationFormStep';
|
|
2
|
-
/**
|
|
3
|
-
* Valida una coordenada contra todas las restricciones (lógica AND).
|
|
4
|
-
* Devuelve el mensaje de error de la primera restricción que falla, o `null` si es válida.
|
|
5
|
-
*/
|
|
6
|
-
export declare function validateRestrictions(lat: number, lng: number, restrictions: LocationRestriction[] | undefined): string | null;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { LocationRestrictionBehavior, LocationRestrictionType, } from '../../@Types/LocationFormStep';
|
|
2
|
-
const EARTH_RADIUS_M = 6371000;
|
|
3
|
-
function toRad(deg) {
|
|
4
|
-
return (deg * Math.PI) / 180;
|
|
5
|
-
}
|
|
6
|
-
/** Distancia en metros entre dos coordenadas (haversine). */
|
|
7
|
-
function haversineMeters(aLat, aLng, bLat, bLng) {
|
|
8
|
-
const dLat = toRad(bLat - aLat);
|
|
9
|
-
const dLng = toRad(bLng - aLng);
|
|
10
|
-
const lat1 = toRad(aLat);
|
|
11
|
-
const lat2 = toRad(bLat);
|
|
12
|
-
const h = Math.sin(dLat / 2) ** 2 + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLng / 2) ** 2;
|
|
13
|
-
return 2 * EARTH_RADIUS_M * Math.asin(Math.min(1, Math.sqrt(h)));
|
|
14
|
-
}
|
|
15
|
-
/** Punto dentro de polígono (ray casting). El polígono se cierra automáticamente. */
|
|
16
|
-
function pointInPolygon(lat, lng, polygon) {
|
|
17
|
-
let inside = false;
|
|
18
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
19
|
-
const yi = polygon[i].latitude;
|
|
20
|
-
const xi = polygon[i].longitude;
|
|
21
|
-
const yj = polygon[j].latitude;
|
|
22
|
-
const xj = polygon[j].longitude;
|
|
23
|
-
const intersects = yi > lat !== yj > lat && lng < ((xj - xi) * (lat - yi)) / (yj - yi) + xi;
|
|
24
|
-
if (intersects)
|
|
25
|
-
inside = !inside;
|
|
26
|
-
}
|
|
27
|
-
return inside;
|
|
28
|
-
}
|
|
29
|
-
function isInside(lat, lng, restriction) {
|
|
30
|
-
if (restriction.type === LocationRestrictionType.RADIUS) {
|
|
31
|
-
return (haversineMeters(lat, lng, restriction.center.latitude, restriction.center.longitude) <=
|
|
32
|
-
restriction.radiusMeters);
|
|
33
|
-
}
|
|
34
|
-
return pointInPolygon(lat, lng, restriction.polygon);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Valida una coordenada contra todas las restricciones (lógica AND).
|
|
38
|
-
* Devuelve el mensaje de error de la primera restricción que falla, o `null` si es válida.
|
|
39
|
-
*/
|
|
40
|
-
export function validateRestrictions(lat, lng, restrictions) {
|
|
41
|
-
for (const restriction of restrictions ?? []) {
|
|
42
|
-
const inside = isInside(lat, lng, restriction);
|
|
43
|
-
if (restriction.behavior === LocationRestrictionBehavior.ALLOW && !inside) {
|
|
44
|
-
return restriction.errorMessage ?? 'La ubicación está fuera de la zona permitida.';
|
|
45
|
-
}
|
|
46
|
-
if (restriction.behavior === LocationRestrictionBehavior.DENY && inside) {
|
|
47
|
-
return restriction.errorMessage ?? 'La ubicación está en una zona no permitida.';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LocationInputMode, LocationStepValue } from '../../@Types/LocationFormStep';
|
|
3
|
-
export interface ErkLocationInputProps {
|
|
4
|
-
value?: LocationStepValue | null;
|
|
5
|
-
onChange?: (value: LocationStepValue | null) => void;
|
|
6
|
-
allowedModes: LocationInputMode[];
|
|
7
|
-
defaultMode?: LocationInputMode;
|
|
8
|
-
label: string;
|
|
9
|
-
helperText?: string | null;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
error?: boolean;
|
|
12
|
-
readOnly?: boolean;
|
|
13
|
-
inputRef?: React.Ref<any>;
|
|
14
|
-
}
|
|
15
|
-
export default function ErkLocationInput({ value, onChange, allowedModes, label, helperText, required, error, readOnly, inputRef, }: ErkLocationInputProps): JSX.Element;
|