@lmb-it/kitsconcerto-native 0.1.237 → 0.1.239
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/form/inputs/InputLocation/googlePlaces.cjs +35 -0
- package/form/inputs/InputLocation/googlePlaces.cjs.map +1 -0
- package/form/inputs/InputLocation/googlePlaces.js +32 -0
- package/form/inputs/InputLocation/googlePlaces.js.map +1 -0
- package/form/inputs/InputLocation/index.cjs +11 -25
- package/form/inputs/InputLocation/index.cjs.map +1 -1
- package/form/inputs/InputLocation/index.js +11 -25
- package/form/inputs/InputLocation/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var axios = require('axios');
|
|
4
|
+
|
|
5
|
+
const GOOGLE_AUTOCOMPLETE = "https://maps.googleapis.com/maps/api/place/autocomplete/json";
|
|
6
|
+
const GOOGLE_DETAILS = "https://maps.googleapis.com/maps/api/place/details/json";
|
|
7
|
+
async function googleAutocomplete(query, apiKey, countryISO) {
|
|
8
|
+
let url = `${GOOGLE_AUTOCOMPLETE}?input=${encodeURIComponent(query)}&key=${apiKey}`;
|
|
9
|
+
if (countryISO) {
|
|
10
|
+
url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;
|
|
11
|
+
}
|
|
12
|
+
const { data } = await axios.get(url);
|
|
13
|
+
return data.predictions?.map((p) => ({
|
|
14
|
+
label: p.description,
|
|
15
|
+
value: p.place_id
|
|
16
|
+
})) || [];
|
|
17
|
+
}
|
|
18
|
+
async function googleDetails(placeId, apiKey) {
|
|
19
|
+
const url = `${GOOGLE_DETAILS}?place_id=${placeId}&key=${apiKey}&fields=address_components,formatted_address,geometry`;
|
|
20
|
+
const { data } = await axios.get(url);
|
|
21
|
+
return {
|
|
22
|
+
formattedAddress: data.result.formatted_address,
|
|
23
|
+
latitude: data.result.geometry?.location?.lat ?? null,
|
|
24
|
+
longitude: data.result.geometry?.location?.lng ?? null,
|
|
25
|
+
components: data.result.address_components.map((c) => ({
|
|
26
|
+
type: c?.types?.[0],
|
|
27
|
+
long: c.long_name,
|
|
28
|
+
short: c.short_name
|
|
29
|
+
}))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.googleAutocomplete = googleAutocomplete;
|
|
34
|
+
exports.googleDetails = googleDetails;
|
|
35
|
+
//# sourceMappingURL=googlePlaces.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"googlePlaces.cjs","sources":["../../../../../src/form/inputs/InputLocation/googlePlaces.native.ts"],"sourcesContent":["/**\n * Google Places transport — LEGACY Web Service endpoints (NATIVE build).\n *\n * React Native has no CORS, so the legacy REST endpoints keep working there\n * unchanged. Browsers cannot call them (no ACAO header) — the web build\n * resolves `googlePlaces.web.ts` (Places API New) instead. Both files export\n * the SAME normalized contract (`googlePlaces.types.ts`) so `index.tsx` is\n * platform-agnostic. There is deliberately NO bare `googlePlaces.ts`: a bare\n * sibling wins module resolution over the platform-suffixed files and ships\n * the wrong transport (the v0.1.238 regression).\n */\nimport axios from \"axios\";\nimport type {ILocationDetailsResponse, ILocationResponse} from \"@lmb-it/kitsconcerto-types\";\nimport type {IGooglePlaceDetails, IGoogleSuggestion} from \"./googlePlaces.types\";\n\nconst GOOGLE_AUTOCOMPLETE =\n \"https://maps.googleapis.com/maps/api/place/autocomplete/json\";\nconst GOOGLE_DETAILS =\n \"https://maps.googleapis.com/maps/api/place/details/json\";\n\nexport type {IGoogleAddressComponent, IGooglePlaceDetails, IGoogleSuggestion} from \"./googlePlaces.types\";\n\nexport async function googleAutocomplete(\n query: string,\n apiKey: string,\n countryISO?: string\n): Promise<IGoogleSuggestion[]> {\n let url = `${GOOGLE_AUTOCOMPLETE}?input=${encodeURIComponent(query)}&key=${apiKey}`;\n if (countryISO) {\n url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;\n }\n const {data} = await axios.get<ILocationResponse>(url);\n return (\n data.predictions?.map((p) => ({\n label: p.description,\n value: p.place_id,\n })) || []\n );\n}\n\nexport async function googleDetails(\n placeId: string,\n apiKey: string\n): Promise<IGooglePlaceDetails> {\n // Request address_components AND geometry so we get lat/lng too.\n const url = `${GOOGLE_DETAILS}?place_id=${placeId}&key=${apiKey}&fields=address_components,formatted_address,geometry`;\n const {data} = await axios.get<ILocationDetailsResponse>(url);\n return {\n formattedAddress: data.result.formatted_address,\n latitude: data.result.geometry?.location?.lat ?? null,\n longitude: data.result.geometry?.location?.lng ?? null,\n components: data.result.address_components.map((c) => ({\n type: c?.types?.[0],\n long: c.long_name,\n short: c.short_name,\n })),\n };\n}\n"],"names":[],"mappings":";;;;AAeA,MAAM,mBAAA,GACF,8DAAA;AACJ,MAAM,cAAA,GACF,yDAAA;AAIJ,eAAsB,kBAAA,CAClB,KAAA,EACA,MAAA,EACA,UAAA,EAC4B;AAC5B,EAAA,IAAI,GAAA,GAAM,GAAG,mBAAmB,CAAA,OAAA,EAAU,mBAAmB,KAAK,CAAC,QAAQ,MAAM,CAAA,CAAA;AACjF,EAAA,IAAI,UAAA,EAAY;AACZ,IAAA,GAAA,IAAO,uBAAuB,UAAA,CAAW,WAAA,GAAc,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AAAA,EACtE;AACA,EAAA,MAAM,EAAC,IAAA,EAAI,GAAI,MAAM,KAAA,CAAM,IAAuB,GAAG,CAAA;AACrD,EAAA,OACI,IAAA,CAAK,WAAA,EAAa,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,IAC1B,OAAO,CAAA,CAAE,WAAA;AAAA,IACT,OAAO,CAAA,CAAE;AAAA,GACb,CAAE,KAAK,EAAC;AAEhB;AAEA,eAAsB,aAAA,CAClB,SACA,MAAA,EAC4B;AAE5B,EAAA,MAAM,MAAM,CAAA,EAAG,cAAc,CAAA,UAAA,EAAa,OAAO,QAAQ,MAAM,CAAA,qDAAA,CAAA;AAC/D,EAAA,MAAM,EAAC,IAAA,EAAI,GAAI,MAAM,KAAA,CAAM,IAA8B,GAAG,CAAA;AAC5D,EAAA,OAAO;AAAA,IACH,gBAAA,EAAkB,KAAK,MAAA,CAAO,iBAAA;AAAA,IAC9B,QAAA,EAAU,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU,UAAU,GAAA,IAAO,IAAA;AAAA,IACjD,SAAA,EAAW,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU,UAAU,GAAA,IAAO,IAAA;AAAA,IAClD,YAAY,IAAA,CAAK,MAAA,CAAO,kBAAA,CAAmB,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,MACnD,IAAA,EAAM,CAAA,EAAG,KAAA,GAAQ,CAAC,CAAA;AAAA,MAClB,MAAM,CAAA,CAAE,SAAA;AAAA,MACR,OAAO,CAAA,CAAE;AAAA,KACb,CAAE;AAAA,GACN;AACJ;;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const GOOGLE_AUTOCOMPLETE = "https://maps.googleapis.com/maps/api/place/autocomplete/json";
|
|
4
|
+
const GOOGLE_DETAILS = "https://maps.googleapis.com/maps/api/place/details/json";
|
|
5
|
+
async function googleAutocomplete(query, apiKey, countryISO) {
|
|
6
|
+
let url = `${GOOGLE_AUTOCOMPLETE}?input=${encodeURIComponent(query)}&key=${apiKey}`;
|
|
7
|
+
if (countryISO) {
|
|
8
|
+
url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;
|
|
9
|
+
}
|
|
10
|
+
const { data } = await axios.get(url);
|
|
11
|
+
return data.predictions?.map((p) => ({
|
|
12
|
+
label: p.description,
|
|
13
|
+
value: p.place_id
|
|
14
|
+
})) || [];
|
|
15
|
+
}
|
|
16
|
+
async function googleDetails(placeId, apiKey) {
|
|
17
|
+
const url = `${GOOGLE_DETAILS}?place_id=${placeId}&key=${apiKey}&fields=address_components,formatted_address,geometry`;
|
|
18
|
+
const { data } = await axios.get(url);
|
|
19
|
+
return {
|
|
20
|
+
formattedAddress: data.result.formatted_address,
|
|
21
|
+
latitude: data.result.geometry?.location?.lat ?? null,
|
|
22
|
+
longitude: data.result.geometry?.location?.lng ?? null,
|
|
23
|
+
components: data.result.address_components.map((c) => ({
|
|
24
|
+
type: c?.types?.[0],
|
|
25
|
+
long: c.long_name,
|
|
26
|
+
short: c.short_name
|
|
27
|
+
}))
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { googleAutocomplete, googleDetails };
|
|
32
|
+
//# sourceMappingURL=googlePlaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"googlePlaces.js","sources":["../../../../../src/form/inputs/InputLocation/googlePlaces.native.ts"],"sourcesContent":["/**\n * Google Places transport — LEGACY Web Service endpoints (NATIVE build).\n *\n * React Native has no CORS, so the legacy REST endpoints keep working there\n * unchanged. Browsers cannot call them (no ACAO header) — the web build\n * resolves `googlePlaces.web.ts` (Places API New) instead. Both files export\n * the SAME normalized contract (`googlePlaces.types.ts`) so `index.tsx` is\n * platform-agnostic. There is deliberately NO bare `googlePlaces.ts`: a bare\n * sibling wins module resolution over the platform-suffixed files and ships\n * the wrong transport (the v0.1.238 regression).\n */\nimport axios from \"axios\";\nimport type {ILocationDetailsResponse, ILocationResponse} from \"@lmb-it/kitsconcerto-types\";\nimport type {IGooglePlaceDetails, IGoogleSuggestion} from \"./googlePlaces.types\";\n\nconst GOOGLE_AUTOCOMPLETE =\n \"https://maps.googleapis.com/maps/api/place/autocomplete/json\";\nconst GOOGLE_DETAILS =\n \"https://maps.googleapis.com/maps/api/place/details/json\";\n\nexport type {IGoogleAddressComponent, IGooglePlaceDetails, IGoogleSuggestion} from \"./googlePlaces.types\";\n\nexport async function googleAutocomplete(\n query: string,\n apiKey: string,\n countryISO?: string\n): Promise<IGoogleSuggestion[]> {\n let url = `${GOOGLE_AUTOCOMPLETE}?input=${encodeURIComponent(query)}&key=${apiKey}`;\n if (countryISO) {\n url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;\n }\n const {data} = await axios.get<ILocationResponse>(url);\n return (\n data.predictions?.map((p) => ({\n label: p.description,\n value: p.place_id,\n })) || []\n );\n}\n\nexport async function googleDetails(\n placeId: string,\n apiKey: string\n): Promise<IGooglePlaceDetails> {\n // Request address_components AND geometry so we get lat/lng too.\n const url = `${GOOGLE_DETAILS}?place_id=${placeId}&key=${apiKey}&fields=address_components,formatted_address,geometry`;\n const {data} = await axios.get<ILocationDetailsResponse>(url);\n return {\n formattedAddress: data.result.formatted_address,\n latitude: data.result.geometry?.location?.lat ?? null,\n longitude: data.result.geometry?.location?.lng ?? null,\n components: data.result.address_components.map((c) => ({\n type: c?.types?.[0],\n long: c.long_name,\n short: c.short_name,\n })),\n };\n}\n"],"names":[],"mappings":";;AAeA,MAAM,mBAAA,GACF,8DAAA;AACJ,MAAM,cAAA,GACF,yDAAA;AAIJ,eAAsB,kBAAA,CAClB,KAAA,EACA,MAAA,EACA,UAAA,EAC4B;AAC5B,EAAA,IAAI,GAAA,GAAM,GAAG,mBAAmB,CAAA,OAAA,EAAU,mBAAmB,KAAK,CAAC,QAAQ,MAAM,CAAA,CAAA;AACjF,EAAA,IAAI,UAAA,EAAY;AACZ,IAAA,GAAA,IAAO,uBAAuB,UAAA,CAAW,WAAA,GAAc,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AAAA,EACtE;AACA,EAAA,MAAM,EAAC,IAAA,EAAI,GAAI,MAAM,KAAA,CAAM,IAAuB,GAAG,CAAA;AACrD,EAAA,OACI,IAAA,CAAK,WAAA,EAAa,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,IAC1B,OAAO,CAAA,CAAE,WAAA;AAAA,IACT,OAAO,CAAA,CAAE;AAAA,GACb,CAAE,KAAK,EAAC;AAEhB;AAEA,eAAsB,aAAA,CAClB,SACA,MAAA,EAC4B;AAE5B,EAAA,MAAM,MAAM,CAAA,EAAG,cAAc,CAAA,UAAA,EAAa,OAAO,QAAQ,MAAM,CAAA,qDAAA,CAAA;AAC/D,EAAA,MAAM,EAAC,IAAA,EAAI,GAAI,MAAM,KAAA,CAAM,IAA8B,GAAG,CAAA;AAC5D,EAAA,OAAO;AAAA,IACH,gBAAA,EAAkB,KAAK,MAAA,CAAO,iBAAA;AAAA,IAC9B,QAAA,EAAU,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU,UAAU,GAAA,IAAO,IAAA;AAAA,IACjD,SAAA,EAAW,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU,UAAU,GAAA,IAAO,IAAA;AAAA,IAClD,YAAY,IAAA,CAAK,MAAA,CAAO,kBAAA,CAAmB,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,MACnD,IAAA,EAAM,CAAA,EAAG,KAAA,GAAQ,CAAC,CAAA;AAAA,MAClB,MAAM,CAAA,CAAE,SAAA;AAAA,MACR,OAAO,CAAA,CAAE;AAAA,KACb,CAAE;AAAA,GACN;AACJ;;;;"}
|
|
@@ -4,13 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var axios = require('axios');
|
|
8
7
|
var Experian = require('./Experian.cjs');
|
|
8
|
+
var googlePlaces_native = require('./googlePlaces.cjs');
|
|
9
9
|
var SelectContext = require('../../selects/SelectContext.cjs');
|
|
10
10
|
require('../../../contexts/DialogContext.cjs');
|
|
11
11
|
|
|
12
|
-
const GOOGLE_AUTOCOMPLETE = "https://maps.googleapis.com/maps/api/place/autocomplete/json";
|
|
13
|
-
const GOOGLE_DETAILS = "https://maps.googleapis.com/maps/api/place/details/json";
|
|
14
12
|
const KitsInputLocation = ({
|
|
15
13
|
id,
|
|
16
14
|
label,
|
|
@@ -43,17 +41,7 @@ const KitsInputLocation = ({
|
|
|
43
41
|
if (query.length < 4) return [];
|
|
44
42
|
try {
|
|
45
43
|
if (provider === "google") {
|
|
46
|
-
|
|
47
|
-
query
|
|
48
|
-
)}&key=${api_key}`;
|
|
49
|
-
if (countryISO) {
|
|
50
|
-
url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;
|
|
51
|
-
}
|
|
52
|
-
const { data } = await axios.get(url);
|
|
53
|
-
const mapped = data.predictions?.map((p) => ({
|
|
54
|
-
label: p.description,
|
|
55
|
-
value: p.place_id
|
|
56
|
-
})) || [];
|
|
44
|
+
const mapped = await googlePlaces_native.googleAutocomplete(query, api_key, countryISO);
|
|
57
45
|
setSuggestions(mapped);
|
|
58
46
|
return mapped;
|
|
59
47
|
} else {
|
|
@@ -83,20 +71,18 @@ const KitsInputLocation = ({
|
|
|
83
71
|
});
|
|
84
72
|
if (!onAddressClick || !placeId) return;
|
|
85
73
|
if (provider === "google") {
|
|
86
|
-
const
|
|
87
|
-
const { data } = await axios.get(url);
|
|
74
|
+
const details = await googlePlaces_native.googleDetails(placeId, api_key);
|
|
88
75
|
const richAddress = {
|
|
89
|
-
formatted_address:
|
|
76
|
+
formatted_address: details.formattedAddress,
|
|
90
77
|
place_id: placeId,
|
|
91
|
-
latitude:
|
|
92
|
-
longitude:
|
|
78
|
+
latitude: details.latitude,
|
|
79
|
+
longitude: details.longitude
|
|
93
80
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
short: c.short_name
|
|
81
|
+
details.components.forEach((c) => {
|
|
82
|
+
if (c.type && !(c.type in richAddress)) {
|
|
83
|
+
richAddress[c.type] = {
|
|
84
|
+
long: c.long,
|
|
85
|
+
short: c.short
|
|
100
86
|
};
|
|
101
87
|
}
|
|
102
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../../src/form/inputs/InputLocation/index.tsx"],"sourcesContent":["import React, {useCallback, useMemo, useRef, useState} from \"react\";\nimport axios from \"axios\";\nimport Experian from \"./Experian\";\nimport type {IKitsInputLocation, ILocationDetailsResponse, ILocationResponse, IRef} from \"@lmb-it/kitsconcerto-types\";\nimport {FormSelect} from \"../../../_compat\";\n\nconst GOOGLE_AUTOCOMPLETE =\n \"https://maps.googleapis.com/maps/api/place/autocomplete/json\";\nconst GOOGLE_DETAILS =\n \"https://maps.googleapis.com/maps/api/place/details/json\";\n\ntype Suggestion = {\n label: string;\n value: string;\n format?: string;\n};\n\nconst KitsInputLocation = ({\n id,\n label,\n errors,\n invalid,\n value,\n hideError,\n onAddressClick,\n onChange,\n disabled,\n placeholder,\n countryISO = \"AUS\",\n helperText,\n provider,\n api_key,\n labelKey = \"label\",\n valueKey = \"value\",\n // list,\n ...rest\n }: IKitsInputLocation) => {\n if (!api_key) throw new Error(\"API KEY NOT PROVIDED\");\n\n const selectRef = useRef<IRef>(null);\n const [suggestions, setSuggestions] = useState<Suggestion[]>([]);\n\n const experian = useMemo(\n () => (provider !== \"google\" ? new Experian(api_key) : null),\n [provider, api_key]\n );\n\n const search = useCallback(\n async (query: string): Promise<Suggestion[]> => {\n if (query.length < 4) return [];\n\n try {\n if (provider === \"google\") {\n let url = `${GOOGLE_AUTOCOMPLETE}?input=${encodeURIComponent(\n query\n )}&key=${api_key}`;\n if (countryISO) {\n url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;\n }\n const {data} = await axios.get<ILocationResponse>(url);\n\n const mapped = data.predictions?.map((p) => ({\n label: p.description,\n value: p.place_id,\n })) || [];\n setSuggestions(mapped);\n return mapped;\n } else {\n const res = await experian?.searchAddress(query, countryISO);\n const mapped = res?.data?.result?.suggestions?.map((s: any) => ({\n label: s.text,\n value: s.global_address_key,\n format: s.format,\n })) || [];\n setSuggestions(mapped);\n return mapped;\n }\n } catch {\n setSuggestions([]);\n return [];\n }\n },\n [provider, api_key, countryISO, experian]\n );\n\n const onPickAddress = useCallback(\n async (event: any, rawItem?: any) => {\n // rawItem is the full suggestion { label, value } passed as second arg by the hook\n const selected = rawItem ?? event;\n\n if (!selected) return;\n\n const placeId = selected[valueKey];\n\n onChange?.({\n target: {value: selected[labelKey]},\n } as any);\n\n if (!onAddressClick || !placeId) return;\n\n if (provider === \"google\") {\n // Request address_components AND geometry so we get lat/lng too.\n const url = `${GOOGLE_DETAILS}?place_id=${placeId}&key=${api_key}&fields=address_components,formatted_address,geometry`;\n\n const {data} = await axios.get<ILocationDetailsResponse>(url);\n\n // Build rich address format: each component has a `long` and `short` value.\n const richAddress: Record<string, any> = {\n formatted_address: data.result.formatted_address,\n place_id: placeId,\n latitude: data.result.geometry?.location?.lat ?? null,\n longitude: data.result.geometry?.location?.lng ?? null,\n };\n\n data.result.address_components.forEach((c) => {\n const type = c?.types?.[0];\n if (type && !(type in richAddress)) {\n richAddress[type] = {\n long: c.long_name,\n short: c.short_name,\n };\n }\n });\n\n onAddressClick(richAddress);\n } else {\n const res = await experian?.formatAddress(placeId);\n if (res?.data?.result) { // @ts-ignore\n onAddressClick(res.data.result);\n }\n }\n },\n [\n provider,\n api_key,\n valueKey,\n labelKey,\n onChange,\n onAddressClick,\n experian,\n ]\n );\n\n return (\n <FormSelect\n ref={selectRef}\n id={id}\n shape=\"autocomplete\"\n value={value}\n label={label}\n placeholder={placeholder}\n labelKey={labelKey}\n valueKey={valueKey}\n onChange={onPickAddress}\n isMultiple={false}\n forceSelection\n completeMethod={search}\n list={suggestions}\n helperText={helperText}\n hideError={hideError}\n disabled={disabled}\n invalid={invalid}\n errors={errors}\n {...rest}\n />\n );\n};\n\nexport default KitsInputLocation;\n"],"names":["useRef","useState","useMemo","Experian","useCallback","jsx","FormSelect"],"mappings":";;;;;;;;;;;AAMA,MAAM,mBAAA,GACF,8DAAA;AACJ,MAAM,cAAA,GACF,yDAAA;AAQJ,MAAM,oBAAoB,CAAC;AAAA,EACI,EAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,QAAA;AAAA,EAC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AAAA,MACL,EAAA;AAAA,MACA,KAAA,EAAM,cAAA;AAAA,MACN,KAAA;AAAA,MACA,KAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA,EAAU,aAAA;AAAA,MACV,UAAA,EAAY,KAAA;AAAA,MACZ,cAAA,EAAc,IAAA;AAAA,MACd,cAAA,EAAgB,MAAA;AAAA,MAChB,IAAA,EAAM,WAAA;AAAA,MACN,UAAA;AAAA,MACA,SAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA;AAAA,MACA,MAAA;AAAA,MACC,GAAG;AAAA;AAAA,GACR;AAER;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../src/form/inputs/InputLocation/index.tsx"],"sourcesContent":["import React, {useCallback, useMemo, useRef, useState} from \"react\";\nimport Experian from \"./Experian\";\nimport type {IKitsInputLocation, IRef} from \"@lmb-it/kitsconcerto-types\";\nimport {FormSelect} from \"../../../_compat\";\n// Platform-forked Google transport: legacy Web Service on native\n// (`googlePlaces.native.ts` — RN has no CORS), Places API (New) on web\n// (`googlePlaces.web.ts` — browsers block the legacy endpoints). Same\n// normalized contract on both sides (`googlePlaces.types.ts`), so the\n// Suggestion / IAddressFormat output is unchanged. There is deliberately NO\n// bare `googlePlaces.ts` — a bare sibling wins resolution over the platform\n// files and ships the wrong transport (the v0.1.238 regression).\nimport {googleAutocomplete, googleDetails} from \"./googlePlaces\";\n\ntype Suggestion = {\n label: string;\n value: string;\n format?: string;\n};\n\nconst KitsInputLocation = ({\n id,\n label,\n errors,\n invalid,\n value,\n hideError,\n onAddressClick,\n onChange,\n disabled,\n placeholder,\n countryISO = \"AUS\",\n helperText,\n provider,\n api_key,\n labelKey = \"label\",\n valueKey = \"value\",\n // list,\n ...rest\n }: IKitsInputLocation) => {\n if (!api_key) throw new Error(\"API KEY NOT PROVIDED\");\n\n const selectRef = useRef<IRef>(null);\n const [suggestions, setSuggestions] = useState<Suggestion[]>([]);\n\n const experian = useMemo(\n () => (provider !== \"google\" ? new Experian(api_key) : null),\n [provider, api_key]\n );\n\n const search = useCallback(\n async (query: string): Promise<Suggestion[]> => {\n if (query.length < 4) return [];\n\n try {\n if (provider === \"google\") {\n const mapped = await googleAutocomplete(query, api_key, countryISO);\n setSuggestions(mapped);\n return mapped;\n } else {\n const res = await experian?.searchAddress(query, countryISO);\n const mapped = res?.data?.result?.suggestions?.map((s: any) => ({\n label: s.text,\n value: s.global_address_key,\n format: s.format,\n })) || [];\n setSuggestions(mapped);\n return mapped;\n }\n } catch {\n setSuggestions([]);\n return [];\n }\n },\n [provider, api_key, countryISO, experian]\n );\n\n const onPickAddress = useCallback(\n async (event: any, rawItem?: any) => {\n // rawItem is the full suggestion { label, value } passed as second arg by the hook\n const selected = rawItem ?? event;\n\n if (!selected) return;\n\n const placeId = selected[valueKey];\n\n onChange?.({\n target: {value: selected[labelKey]},\n } as any);\n\n if (!onAddressClick || !placeId) return;\n\n if (provider === \"google\") {\n const details = await googleDetails(placeId, api_key);\n\n // Build rich address format: each component has a `long` and `short` value.\n const richAddress: Record<string, any> = {\n formatted_address: details.formattedAddress,\n place_id: placeId,\n latitude: details.latitude,\n longitude: details.longitude,\n };\n\n details.components.forEach((c) => {\n if (c.type && !(c.type in richAddress)) {\n richAddress[c.type] = {\n long: c.long,\n short: c.short,\n };\n }\n });\n\n onAddressClick(richAddress);\n } else {\n const res = await experian?.formatAddress(placeId);\n if (res?.data?.result) { // @ts-ignore\n onAddressClick(res.data.result);\n }\n }\n },\n [\n provider,\n api_key,\n valueKey,\n labelKey,\n onChange,\n onAddressClick,\n experian,\n ]\n );\n\n return (\n <FormSelect\n ref={selectRef}\n id={id}\n shape=\"autocomplete\"\n value={value}\n label={label}\n placeholder={placeholder}\n labelKey={labelKey}\n valueKey={valueKey}\n onChange={onPickAddress}\n isMultiple={false}\n forceSelection\n completeMethod={search}\n list={suggestions}\n helperText={helperText}\n hideError={hideError}\n disabled={disabled}\n invalid={invalid}\n errors={errors}\n {...rest}\n />\n );\n};\n\nexport default KitsInputLocation;\n"],"names":["useRef","useState","useMemo","Experian","useCallback","googleAutocomplete","googleDetails","jsx","FormSelect"],"mappings":";;;;;;;;;;;AAmBA,MAAM,oBAAoB,CAAC;AAAA,EACI,EAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA,GAAa,KAAA;AAAA,EACb,UAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA,GAAW,OAAA;AAAA,EACX,QAAA,GAAW,OAAA;AAAA;AAAA,EAEX,GAAG;AACP,CAAA,KAA0B;AACjD,EAAA,IAAI,CAAC,OAAA,EAAS,MAAM,IAAI,MAAM,sBAAsB,CAAA;AAEpD,EAAA,MAAM,SAAA,GAAYA,aAAa,IAAI,CAAA;AACnC,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAIC,cAAA,CAAuB,EAAE,CAAA;AAE/D,EAAA,MAAM,QAAA,GAAWC,aAAA;AAAA,IACb,MAAO,QAAA,KAAa,QAAA,GAAW,IAAIC,gBAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,IACvD,CAAC,UAAU,OAAO;AAAA,GACtB;AAEA,EAAA,MAAM,MAAA,GAASC,iBAAA;AAAA,IACX,OAAO,KAAA,KAAyC;AAC5C,MAAA,IAAI,KAAA,CAAM,MAAA,GAAS,CAAA,EAAG,OAAO,EAAC;AAE9B,MAAA,IAAI;AACA,QAAA,IAAI,aAAa,QAAA,EAAU;AACvB,UAAA,MAAM,MAAA,GAAS,MAAMC,sCAAA,CAAmB,KAAA,EAAO,SAAS,UAAU,CAAA;AAClE,UAAA,cAAA,CAAe,MAAM,CAAA;AACrB,UAAA,OAAO,MAAA;AAAA,QACX,CAAA,MAAO;AACH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;;"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useRef, useState, useMemo, useCallback } from 'react';
|
|
3
|
-
import axios from 'axios';
|
|
4
3
|
import Experian from './Experian.js';
|
|
4
|
+
import { googleAutocomplete, googleDetails } from './googlePlaces.js';
|
|
5
5
|
import FormSelect from '../../selects/SelectContext.js';
|
|
6
6
|
import '../../../contexts/DialogContext.js';
|
|
7
7
|
|
|
8
|
-
const GOOGLE_AUTOCOMPLETE = "https://maps.googleapis.com/maps/api/place/autocomplete/json";
|
|
9
|
-
const GOOGLE_DETAILS = "https://maps.googleapis.com/maps/api/place/details/json";
|
|
10
8
|
const KitsInputLocation = ({
|
|
11
9
|
id,
|
|
12
10
|
label,
|
|
@@ -39,17 +37,7 @@ const KitsInputLocation = ({
|
|
|
39
37
|
if (query.length < 4) return [];
|
|
40
38
|
try {
|
|
41
39
|
if (provider === "google") {
|
|
42
|
-
|
|
43
|
-
query
|
|
44
|
-
)}&key=${api_key}`;
|
|
45
|
-
if (countryISO) {
|
|
46
|
-
url += `&components=country:${countryISO.toLowerCase().slice(0, 2)}`;
|
|
47
|
-
}
|
|
48
|
-
const { data } = await axios.get(url);
|
|
49
|
-
const mapped = data.predictions?.map((p) => ({
|
|
50
|
-
label: p.description,
|
|
51
|
-
value: p.place_id
|
|
52
|
-
})) || [];
|
|
40
|
+
const mapped = await googleAutocomplete(query, api_key, countryISO);
|
|
53
41
|
setSuggestions(mapped);
|
|
54
42
|
return mapped;
|
|
55
43
|
} else {
|
|
@@ -79,20 +67,18 @@ const KitsInputLocation = ({
|
|
|
79
67
|
});
|
|
80
68
|
if (!onAddressClick || !placeId) return;
|
|
81
69
|
if (provider === "google") {
|
|
82
|
-
const
|
|
83
|
-
const { data } = await axios.get(url);
|
|
70
|
+
const details = await googleDetails(placeId, api_key);
|
|
84
71
|
const richAddress = {
|
|
85
|
-
formatted_address:
|
|
72
|
+
formatted_address: details.formattedAddress,
|
|
86
73
|
place_id: placeId,
|
|
87
|
-
latitude:
|
|
88
|
-
longitude:
|
|
74
|
+
latitude: details.latitude,
|
|
75
|
+
longitude: details.longitude
|
|
89
76
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
short: c.short_name
|
|
77
|
+
details.components.forEach((c) => {
|
|
78
|
+
if (c.type && !(c.type in richAddress)) {
|
|
79
|
+
richAddress[c.type] = {
|
|
80
|
+
long: c.long,
|
|
81
|
+
short: c.short
|
|
96
82
|
};
|
|
97
83
|
}
|
|
98
84
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/form/inputs/InputLocation/index.tsx"],"sourcesContent":["import React, {useCallback, useMemo, useRef, useState} from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/form/inputs/InputLocation/index.tsx"],"sourcesContent":["import React, {useCallback, useMemo, useRef, useState} from \"react\";\nimport Experian from \"./Experian\";\nimport type {IKitsInputLocation, IRef} from \"@lmb-it/kitsconcerto-types\";\nimport {FormSelect} from \"../../../_compat\";\n// Platform-forked Google transport: legacy Web Service on native\n// (`googlePlaces.native.ts` — RN has no CORS), Places API (New) on web\n// (`googlePlaces.web.ts` — browsers block the legacy endpoints). Same\n// normalized contract on both sides (`googlePlaces.types.ts`), so the\n// Suggestion / IAddressFormat output is unchanged. There is deliberately NO\n// bare `googlePlaces.ts` — a bare sibling wins resolution over the platform\n// files and ships the wrong transport (the v0.1.238 regression).\nimport {googleAutocomplete, googleDetails} from \"./googlePlaces\";\n\ntype Suggestion = {\n label: string;\n value: string;\n format?: string;\n};\n\nconst KitsInputLocation = ({\n id,\n label,\n errors,\n invalid,\n value,\n hideError,\n onAddressClick,\n onChange,\n disabled,\n placeholder,\n countryISO = \"AUS\",\n helperText,\n provider,\n api_key,\n labelKey = \"label\",\n valueKey = \"value\",\n // list,\n ...rest\n }: IKitsInputLocation) => {\n if (!api_key) throw new Error(\"API KEY NOT PROVIDED\");\n\n const selectRef = useRef<IRef>(null);\n const [suggestions, setSuggestions] = useState<Suggestion[]>([]);\n\n const experian = useMemo(\n () => (provider !== \"google\" ? new Experian(api_key) : null),\n [provider, api_key]\n );\n\n const search = useCallback(\n async (query: string): Promise<Suggestion[]> => {\n if (query.length < 4) return [];\n\n try {\n if (provider === \"google\") {\n const mapped = await googleAutocomplete(query, api_key, countryISO);\n setSuggestions(mapped);\n return mapped;\n } else {\n const res = await experian?.searchAddress(query, countryISO);\n const mapped = res?.data?.result?.suggestions?.map((s: any) => ({\n label: s.text,\n value: s.global_address_key,\n format: s.format,\n })) || [];\n setSuggestions(mapped);\n return mapped;\n }\n } catch {\n setSuggestions([]);\n return [];\n }\n },\n [provider, api_key, countryISO, experian]\n );\n\n const onPickAddress = useCallback(\n async (event: any, rawItem?: any) => {\n // rawItem is the full suggestion { label, value } passed as second arg by the hook\n const selected = rawItem ?? event;\n\n if (!selected) return;\n\n const placeId = selected[valueKey];\n\n onChange?.({\n target: {value: selected[labelKey]},\n } as any);\n\n if (!onAddressClick || !placeId) return;\n\n if (provider === \"google\") {\n const details = await googleDetails(placeId, api_key);\n\n // Build rich address format: each component has a `long` and `short` value.\n const richAddress: Record<string, any> = {\n formatted_address: details.formattedAddress,\n place_id: placeId,\n latitude: details.latitude,\n longitude: details.longitude,\n };\n\n details.components.forEach((c) => {\n if (c.type && !(c.type in richAddress)) {\n richAddress[c.type] = {\n long: c.long,\n short: c.short,\n };\n }\n });\n\n onAddressClick(richAddress);\n } else {\n const res = await experian?.formatAddress(placeId);\n if (res?.data?.result) { // @ts-ignore\n onAddressClick(res.data.result);\n }\n }\n },\n [\n provider,\n api_key,\n valueKey,\n labelKey,\n onChange,\n onAddressClick,\n experian,\n ]\n );\n\n return (\n <FormSelect\n ref={selectRef}\n id={id}\n shape=\"autocomplete\"\n value={value}\n label={label}\n placeholder={placeholder}\n labelKey={labelKey}\n valueKey={valueKey}\n onChange={onPickAddress}\n isMultiple={false}\n forceSelection\n completeMethod={search}\n list={suggestions}\n helperText={helperText}\n hideError={hideError}\n disabled={disabled}\n invalid={invalid}\n errors={errors}\n {...rest}\n />\n );\n};\n\nexport default KitsInputLocation;\n"],"names":[],"mappings":";;;;;;;AAmBA,MAAM,oBAAoB,CAAC;AAAA,EACI,EAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA,GAAa,KAAA;AAAA,EACb,UAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA,GAAW,OAAA;AAAA,EACX,QAAA,GAAW,OAAA;AAAA;AAAA,EAEX,GAAG;AACP,CAAA,KAA0B;AACjD,EAAA,IAAI,CAAC,OAAA,EAAS,MAAM,IAAI,MAAM,sBAAsB,CAAA;AAEpD,EAAA,MAAM,SAAA,GAAY,OAAa,IAAI,CAAA;AACnC,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,QAAA,CAAuB,EAAE,CAAA;AAE/D,EAAA,MAAM,QAAA,GAAW,OAAA;AAAA,IACb,MAAO,QAAA,KAAa,QAAA,GAAW,IAAI,QAAA,CAAS,OAAO,CAAA,GAAI,IAAA;AAAA,IACvD,CAAC,UAAU,OAAO;AAAA,GACtB;AAEA,EAAA,MAAM,MAAA,GAAS,WAAA;AAAA,IACX,OAAO,KAAA,KAAyC;AAC5C,MAAA,IAAI,KAAA,CAAM,MAAA,GAAS,CAAA,EAAG,OAAO,EAAC;AAE9B,MAAA,IAAI;AACA,QAAA,IAAI,aAAa,QAAA,EAAU;AACvB,UAAA,MAAM,MAAA,GAAS,MAAM,kBAAA,CAAmB,KAAA,EAAO,SAAS,UAAU,CAAA;AAClE,UAAA,cAAA,CAAe,MAAM,CAAA;AACrB,UAAA,O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