PageSourceSearch

https://sarploy.org/assets/AddressAutocompleteField-BFVlvEL-.js

js sarploy.org collected 2026-10-10 02:45:17 UTC 8,714 bytes, 1 lines download raw bytes

1import{j as d,r as o}from"./framework-BIHo1AUa.js";import{d as Z,b as U,l as de}from"./mapRuntimeGuidance-fCT12Wdg.js";import{q as B,A as fe,u as H,v as pe,w as se,x as ne,y as F,z as me,B as ge}from"./CommandOperationsRoute-BPiTO5SO.js";import"./OperationsRoute-LJcGV__p.js";const Se={verified:"Location found on map",partial:"Approximate map location",manual:"Location placed manually",unverified:"Location not yet placed on map",failed:"Could not place location on map"},_e={verified:"confirmed",partial:"pending",manual:"confirmed",unverified:"pending",failed:"critical"};function Ae({status:t}){return d.jsx("span",{className:`location-status-badge location-status-badge--${t}`,"data-location-status-tone":_e[t],children:Se[t]})}const ee=3,he=250;function ye(t){if(!t)return null;const e=t.lat(),r=t.lng();return Number.isFinite(e)&&Number.isFinite(r)?{latitude:e,longitude:r}:null}function te(t){return new Promise((e,r)=>{de().then(f=>{if(!f.Geocoder){r(new Error(se));return}new f.Geocoder().geocode(t,(u,a)=>{if(a==="OK"){e((u==null?void 0:u[0])??null);return}if(a==="ZERO_RESULTS"){e(null);return}r(ne(a,"geocode"))})}).catch(r)})}async function xe(t){return me(t)}function W(t){var e;return t?typeof t=="string"?t.trim():(t.text??((e=t.toString)==null?void 0:e.call(t))??"").trim():""}function we(t){var a;const e=t.placePrediction,r=(a=e==null?void 0:e.placeId)==null?void 0:a.trim(),f=W(e==null?void 0:e.text);if(!r||!f)return null;const S=W(e==null?void 0:e.mainText),u=W(e==null?void 0:e.secondaryText);return{description:f,place_id:r,types:e==null?void 0:e.types,structured_formatting:{main_text:S||f,secondary_text:u||void 0},toPlace:e!=null&&e.toPlace?()=>e.toPlace():void 0}}async function Ee(t){if(!t.toPlace)return null;const e=t.toPlace();try{await e.fetchFields({fields:["location","formattedAddress","types"]})}catch(r){return console.warn(`[SARploy] the picked place could not be looked up in its session; using the Geocoder: ${r instanceof Error?r.message:String(r)}`),null}return e.location?{geometry:{location:e.location},formatted_address:e.formattedAddress??void 0,types:e.types??void 0,place_id:t.place_id}:null}async function Le(t,e,r){var f,S;return(S=(f=t.places)==null?void 0:f.AutocompleteSuggestion)!=null&&S.fetchAutocompleteSuggestions?((await t.places.AutocompleteSuggestion.fetchAutocompleteSuggestions({input:e,sessionToken:r})).suggestions??[]).map(we).filter(a=>!!a):new Promise((u,a)=>{var x;const l=(x=t.places)==null?void 0:x.AutocompleteService;if(!l){a(new Error(se));return}new l().getPlacePredictions({input:e,sessionToken:r},(w,A)=>{if(A==="OK"){u(w??[]);return}if(A==="ZERO_RESULTS"){u([]);return}a(ne(A,"places"))})})}async function ke(t){var x,w;let e=null;try{e=await Ee(t)??await te({placeId:t.place_id})??await te({address:t.description})}catch(A){const O=await ge(t.description,!0);if(!O)throw A;return{...O,inputText:t.description,placeId:t.place_id,provider:"google_places"}}const r=ye((x=e==null?void 0:e.geometry)==null?void 0:x.location),f=new Set([...t.types??[],...(e==null?void 0:e.types)??[]]),S=["establishment","point_of_interest","park","hospital","school","place_of_worship","tourist_attraction"].some(A=>f.has(A)),u=["street_address","premise","subpremise","route","intersection"].some(A=>f.has(A)),a=oe(t).trim(),T=S||!u&&!/^\d/.test(a)?t.description.trim():((w=e==null?void 0:e.formatted_address)==null?void 0:w.trim())||t.description.trim();return!r||!T?null:{inputText:t.description,formattedAddress:T,latitude:r.latitude,longitude:r.longitude,placeId:t.place_id||(e==null?void 0:e.place_id),provider:"google_places",validationStatus:"verified",verifiedAt:new Date().toISOString()}}function oe(t){var e;return((e=t.structured_formatting)==null?void 0:e.main_text)??t.description}function re(t){var e;return(e=t.structured_formatting)==null?void 0:e.secondary_text}function De({label:t,value:e,status:r,isGeocoding:f=!1,enableGooglePlaces:S=!1,onChange:u,onResolve:a,onUnverified:l,disabled:T,onBlur:x,...w}){const A=o.useRef(null),O=o.useRef(u),G=o.useRef(a),p=o.useRef(l),D=o.useRef(!1),N=o.useRef(0),E=o.useRef(0),C=o.useRef(""),q=o.useRef(""),R=o.useRef(null),M=o.useRef(""),j=o.useRef(null),[V,m]=o.useState(null),[ae,J]=o.useState(!1),[ce,b]=o.useState(!1),[ue,P]=o.useState(!1),[I,L]=o.useState([]),[K,h]=o.use
1State(-1),Q=t.toLowerCase().replace(/[^a-z0-9]+/g,"-"),X=w.id??`${Q}-address-field`,z=`${w.id??Q}-address-suggestions`;o.useEffect(()=>{O.current=u,G.current=a,p.current=l},[u,a,l]),o.useEffect(()=>{const s=B(e);(r==="verified"||r==="manual")&&s&&(q.current=s,R.current=null)},[r,e]),o.useEffect(()=>{var g;const s=e.trim().length>=ee;if(!S||T||D.current){L([]),h(-1),P(!1);return}if(r==="verified"||r==="manual"){L([]),h(-1),m(null),P(!1);return}if(!s){L([]),h(-1),m(null),P(!1);return}if(!U()){const i=pe();m(i),L([]),h(-1),P(!1),(g=p.current)==null||g.call(p,e.trim(),i);return}const c=e.trim();if(C.current===c){P(!1);return}let k=!1;const y=++N.current,_=window.setTimeout(()=>{Z().then(i=>{var $;return j.current||(j.current=($=i.places)!=null&&$.AutocompleteSessionToken?new i.places.AutocompleteSessionToken:null),Le(i,c,j.current)}).then(i=>{k||y!==N.current||(C.current=c,L(i),h(i.length>0?0:-1),m(i.length>0?null:fe))}).catch(i=>{var v;if(k||y!==N.current)return;C.current=c;const $=H(i);L([]),h(-1),m($),(v=p.current)==null||v.call(p,c,$)}).finally(()=>{!k&&y===N.current&&P(!1)})},he);return P(!0),()=>{k=!0,_!==void 0&&window.clearTimeout(_)}},[T,S,r,e]);async function Y(s){var c,k,y;const n=++E.current;D.current=!0,m(null),L([]),h(-1),b(!0);try{await Z();const _=await ke(s);if(n!==E.current)return;if(!_){m(F),(c=p.current)==null||c.call(p,s.description,F);return}O.current(_.formattedAddress),(k=G.current)==null||k.call(G,_),q.current=B(_.formattedAddress),R.current=null,j.current=null}catch(_){if(n!==E.current)return;const g=H(_);m(g),(y=p.current)==null||y.call(p,s.description,g)}finally{n===E.current&&b(!1)}}async function le(s){if(I.length!==0){if(s.key==="ArrowDown"){s.preventDefault(),h(n=>(n+1)%I.length);return}if(s.key==="ArrowUp"){s.preventDefault(),h(n=>n<=0?I.length-1:n-1);return}if(s.key==="Escape"){L([]),h(-1);return}s.key==="Enter"&&K>=0&&(s.preventDefault(),await Y(I[K]))}}async function ie(s){var _;if(x==null||x(s),!S||T)return;const n=s.currentTarget.value.trim(),c=B(n);if(!n||n.length<ee||D.current){D.current=!1;return}if(c===q.current||r==="verified"||r==="manual"||M.current===c)return;if(((_=R.current)==null?void 0:_.value)===c){m(R.current.message),l==null||l(n,R.current.message);return}const k=U();N.current+=1,L([]),h(-1),P(!1),m(null),b(!0),M.current=c;const y=++E.current;try{k&&await Z().catch(()=>{});const g=await xe(n);if(y!==E.current)return;if(!g){m(F),R.current={value:c,message:F},l==null||l(n,F);return}u(g.formattedAddress),a==null||a(g),J(g.provider==="openstreetmap"),q.current=B(g.formattedAddress),R.current=null,j.current=null}catch(g){if(y!==E.current)return;const i=H(g);m(i),R.current={value:c,message:i},l==null||l(n,i)}finally{M.current===c&&(M.current=""),y===E.current&&b(!1)}}return d.jsxs("label",{className:"address-autocomplete-field",htmlFor:X,children:[d.jsxs("span",{className:"address-autocomplete-field__heading",children:[d.jsxs("span",{className:"address-autocomplete-field__label",children:[t,w.required?d.jsx("span",{"aria-hidden":"true",children:" *"}):null]}),e.trim()?d.jsx(Ae,{status:r}):null]}),d.jsxs("span",{className:"address-autocomplete-field__control",children:[d.jsx("input",{...w,id:X,ref:A,value:e,onBlur:ie,onKeyDown:le,"aria-autocomplete":S?"list":void 0,"aria-expanded":I.length>0?"true":"false","aria-controls":I.length>0?z:void 0,"aria-activedescendant":K>=0?`${z}-${K}`:void 0,onChange:s=>{E.current+=1,M.current="",D.current=!1,b(!1),m(null),J(!1),u(s.target.value)},disabled:T}),f||ce||ue?d.jsx("span",{className:"address-autocomplete-field__spinner","aria-label":`Geocoding ${t}`}):null,I.length>0?d.jsx("span",{id:z,className:"address-autocomplete-field__suggestions","data-mobile-overlay":"address-suggestions",role:"listbox","aria-label":`${t} suggestions`,children:I.map((s,n)=>d.jsxs("button",{id:`${z}-${n}`,type:"button",className:"address-autocomplete-field__suggestion",role:"option","aria-selected":n===K,onMouseDown:c=>c.preventDefault(),onPointerDown:()=>{D.current=!0},onClick:()=>{Y(s)},children:[d.jsx("strong",{children:oe(s)}),re(s)?d.jsx("span",{children:re(s)}):null]},s.place_id||`${s.description}-${n}`))}):null]}),V?d.jsx("span",{className:"address-autocomplete-field__error",role:"alert",children:V}):null,ae&&!V?d.jsx("span",{className:"address-autocomplete-field__backup",role:"status",children:"Found with OpenStreetMap: Google Maps did not answer."}):null]})}export{De as A};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.