@geoimpact/sep-map-sdk 1.0.20 → 1.0.21

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.
@@ -9,9 +9,8 @@ return F.jsx("div",{className:"sep-search-results",children:/* @__PURE__ */F.jsx
9
9
  return F.jsx("div",{className:"sep-search-results",children:/* @__PURE__ */F.jsxs("div",{className:"sep-search-status sep-search-status--error",role:"alert",children:[
10
10
  /* @__PURE__ */F.jsx("span",{className:"sep-search-error-icon","aria-hidden":"true",children:"⚠️"}),
11
11
  /* @__PURE__ */F.jsx("span",{children:u("search.error")})]})});if(0===e.length)/* @__PURE__ */
12
- return F.jsx("div",{className:"sep-search-results",children:/* @__PURE__ */F.jsx("div",{className:"sep-search-status sep-search-status--empty",children:u("search.noResults")})});let g=0;/* @__PURE__ */
13
- return F.jsx("div",{ref:d,className:"sep-search-results",role:"listbox",children:e.map(e=>/* @__PURE__ */F.jsxs("div",{className:"sep-search-group",children:[
14
- /* @__PURE__ */F.jsxs("div",{className:"sep-search-group__header",children:[e.label," (",e.items.length,")"]}),e.items.map((t,i)=>{const r=g++,o=r===n;/* @__PURE__ */
12
+ return F.jsx("div",{className:"sep-search-results",children:/* @__PURE__ */F.jsx("div",{className:"sep-search-status sep-search-status--empty",children:u("search.noResults")})});let g=0;const _=e.length>1;/* @__PURE__ */
13
+ return F.jsx("div",{ref:d,className:"sep-search-results",role:"listbox",children:e.map(e=>/* @__PURE__ */F.jsxs("div",{className:"sep-search-group",children:[_&&/* @__PURE__ */F.jsxs("div",{className:"sep-search-group__header",children:[e.label," (",e.items.length,")"]}),e.items.map((t,i)=>{const r=g++,o=r===n;/* @__PURE__ */
15
14
  return F.jsx("div",{ref:o?p:void 0,children:/* @__PURE__ */F.jsx(ti,{groupItem:t,isHighlighted:o,onClick:()=>m(t),onMouseEnter:()=>c(r),renderChip:f})},((e,t,i)=>{switch(t.kind){case"address":return`${e.id}-addr-${t.data.id}`;case"perimeter":return`${e.id}-perim-${t.data.id}`;case"municipality":return`${e.id}-muni-${t.data.label}`;case"region":return`${e.id}-region-${i}-${t.data.swissZipCode}-${t.data.town}`;case"parcel":return`${e.id}-parcel-${i}`;case"custom":return`${e.id}-custom-${t.data.id}-${i}`}})(e,t,i))})]},e.id))})}),ni=k.forwardRef(function({onSelect:e,onPerimeterSelect:t,onMunicipalitySelect:i,onRegionSelect:n,onCustomResultSelect:r,onSearchClear:o,placement:s="top-left",externalContainer:a,placeholder:l,className:c="",includePerimeters:u=!0,autoFocus:h=!1,value:d,onChange:p,style:f},m){const{t:g}=Pt(),_=k.useRef(null),y=k.useRef(null),v=k.useRef(""),{query:b,setQuery:x,resultGroups:w,isLoading:T,error:S,isOpen:P,highlightedIndex:C,clear:E,open:M,close:I,highlightNext:z,highlightPrev:A,selectHighlighted:L,totalResults:D,flatResults:R,showPrefetchedResults:O,hasPrefetchedData:B,setHighlightedIndex:N}=function(e={}){const{debounceMs:t=300,minQueryLength:i=2,includePerimeters:n=!0}=e,{services:r,config:o,t:s}=Tt(),[a,l]=k.useState(""),[c,u]=k.useState([]),[h,d]=k.useState(!1),[p,f]=k.useState(null),[m,g]=k.useState(!1),[_,y]=k.useState(-1),v=k.useRef(null),b=k.useRef(null);k.useEffect(()=>()=>{v.current&&clearTimeout(v.current),b.current?.abort()},[]);const x=k.useMemo(()=>function(e){const t=[];for(const i of e)for(const e of i.items)switch(e.kind){case"address":t.push({type:"address",item:e.data});break;case"perimeter":t.push({type:"perimeter",item:e.data});break;case"municipality":t.push({type:"municipality",item:e.data});break;case"parcel":t.push({type:"parcel",item:e.data});break;case"region":t.push({type:"region",item:e.data});break;case"custom":t.push({type:"custom",item:e.data,endpointId:e.endpointId})}return t}(c),[c]),w=x.length;k.useEffect(()=>{o.features?.search?.prefetchPerimeters&&o.features.perimeterSelection&&r.perimeter.getAll().catch(console.error)},[o.features?.search?.prefetchPerimeters,o.features?.perimeterSelection,r.perimeter]),k.useEffect(()=>{const e=o.features?.search?.customSearchTypes??[];for(const t of e)t.prefetch&&!1!==t.enabled&&r.customSearch.fetchAll(t).catch(console.error)},[o.features?.search?.customSearchTypes,r.customSearch]);const T=k.useCallback(async e=>{if(b.current?.abort(),e.length<i){f(null);const t=!(!o.features?.search?.prefetchPerimeters||!o.features?.perimeterSelection),i=(o.features?.search?.customSearchTypes??[]).filter(e=>e.prefetch&&!1!==e.enabled),n=i.length>0;if(t||n)try{const n=t?await r.perimeter.getAll():[],a={};for(const t of i){const i=r.customSearch.searchLocal(t.id,e);i.length>0&&(a[t.id]=i)}if(n.length>0||Object.keys(a).length>0){const e=Mt([],[],[],n,[],a,kt(o.features?.search),i,s);return u(e),void g(!0)}}catch{}return u([]),void g(!1)}b.current=new AbortController;const t=b.current.signal;d(!0),f(null),y(-1);const a=o.features?.search,l=kt(a);try{const c=[],h=[],d={signal:t,districts:a?.districts};for(const t of l)switch(t.type){case"address":c.push(r.address.search(e,d)),h.push("address");break;case"address-advanced":c.push(r.address.searchAdvanced(e,d)),h.push("address-advanced");break;case"parcel":c.push(r.address.searchParcel(e,d)),h.push("parcel");break;case"region-town":c.push(r.address.searchTown(e,d)),h.push("region-town");break;case"region-plz":c.push(r.address.searchPostalCode(e,d)),h.push("region-plz");break;case"municipality":c.push(r.municipality.search(e,d)),h.push("municipality");break;case"perimeter":n&&o.features?.perimeterSelection&&(c.push(r.perimeter.search(e)),h.push("perimeter"))}const p=(a?.customSearchTypes??[]).filter(e=>!1!==e.enabled);for(const n of p){const o=n.minQueryLength??i;e.length>=o&&(n.prefetch?c.push(Promise.resolve(r.customSearch.searchLocal(n.id,e))):c.push(r.customSearch.search(n,e,t)),h.push(`custom:${n.id}`))}const f=await Promise.allSettled(c);if(t.aborted)return;const m=[],_=[],y=[],v=[],b=[],x={};f.forEach((e,t)=>{if("rejected"===e.status){const t=e.reason;return void(t instanceof Error&&t.name)}const i=e.value,n=h[t];if(n.startsWith("custom:")){const e=n.substring(7);x[e]=i}else switch(n){case"address":case"address-advanced":m.push(...i);break;case"parcel":_.push(...i);break;case"region-town":case"region-plz":y.push(...i);break;case"perimeter":v.push(...i);break;case"municipality":b.push(...i)}});const w=Mt(m,_,y,v,b,x,l,p,s);u(w),g(!0)}catch(c){if(c instanceof Error&&"AbortError"===c.name)return;f(c instanceof Error?c.message:"Search failed"),u([])}finally{b.current?.signal.aborted||d(!1)}},[r,o.features,n,i,s]),S=k.useCallback(e=>new Promise(i=>{v.current&&clearTimeout(v.current),v.current=setTimeout(async()=>{await T(e),i()},t)}),[T,t]),P=k.useCallback(e=>{l(e),S(e)},[S]),C=k.useCallback(()=>{l(""),u([]),f(null),g(!1),y(-1),b.current?.abort()},[]),E=k.useCallback(()=>{(c.length>0||a.length>=i)&&g(!0)},[c,a,i]),M=k.useCallback(async()=>{const e=!(!o.features?.search?.prefetchPerimeters||!o.features?.perimeterSelection),t=(o.features?.search?.customSearchTypes??[]).filter(e=>e.prefetch&&!1!==e.enabled),i=t.length>0;if(e||i){d(!0),g(!0);try{const i=e?await r.perimeter.getAll():[],n={};for(const e of t){const t=r.customSearch.searchLocal(e.id,"");t.length>0&&(n[e.id]=t)}if(i.length>0||Object.keys(n).length>0){const e=Mt([],[],[],i,[],n,kt(o.features?.search),t,s);u(e)}else g(!1),u([])}catch(n){g(!1),u([])}finally{d(!1)}}},[r.perimeter,r.customSearch,o.features?.search,o.features?.perimeterSelection,s]),I=!!(o.features?.search?.prefetchPerimeters&&o.features?.perimeterSelection||(o.features?.search?.customSearchTypes??[]).some(e=>e.prefetch&&!1!==e.enabled)),z=k.useCallback(()=>{g(!1),y(-1)},[]),A=k.useCallback(()=>{0!==x.length&&y(e=>{const t=e+1;return t>=x.length?0:t})},[x]),L=k.useCallback(()=>{0!==x.length&&y(e=>{const t=e-1;return t<0?x.length-1:t})},[x]),D=k.useCallback(()=>_<0||_>=x.length?null:x[_].item,[x,_]);return{query:a,resultGroups:c,isLoading:h,error:p,isOpen:m,highlightedIndex:_,setHighlightedIndex:y,setQuery:P,search:T,clear:C,open:E,close:z,showPrefetchedResults:M,hasPrefetchedData:I,highlightNext:A,highlightPrev:L,selectHighlighted:D,totalResults:w,flatResults:x}}({includePerimeters:u});k.useImperativeHandle(m,()=>({setQuery:e=>{x(e),_.current&&(_.current.value=e)}}),[x]);const j=void 0!==d,V=j?d:b,U=k.useCallback(e=>{const t=e.target.value,i=v.current;j&&p?.(t),x(t),i.length>0&&0===t.length&&o?.(),v.current=t},[j,p,x,o]),Z=k.useCallback(()=>{B&&V.length<2?O():(V.length>=2||w.length>0)&&M()},[V,w,M,B,O]);k.useEffect(()=>{const e=e=>{if(!y.current)return;e.composedPath().includes(y.current)||I()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[I]),k.useEffect(()=>{h&&_.current&&_.current.focus()},[h]);const G=k.useCallback(t=>{j?p?.(t.label):x(t.label),I(),e(t),_.current?.blur()},[j,p,x,I,e]),q=k.useCallback(e=>{j?p?.(e.name):x(e.name),I(),t?.(e),_.current?.blur()},[j,p,x,I,t]),$=k.useCallback(e=>{j?p?.(e.label):x(e.label),I(),i?.(e),_.current?.blur()},[j,p,x,I,i]),H=k.useCallback(e=>{const t=[e.swissZipCode||"",e.town||""].filter(Boolean).join(" ");j?p?.(t):x(t),I(),n?.(e),_.current?.blur()},[j,p,x,I,n]),W=k.useCallback((e,t)=>{const i=t.label||"";j?p?.(i):x(i),I(),r?.(e,t),_.current?.blur()},[j,p,x,I,r]),X=k.useCallback(e=>{switch(e.key){case"ArrowDown":e.preventDefault(),!P&&V.length>=2?M():z();break;case"ArrowUp":e.preventDefault(),A();break;case"Enter":if(e.preventDefault(),P&&C>=0){const e=L();if(e){const t=R[C];"custom"===t.type?W(t.endpointId,e):"address"===t.type?G(e):"region"===t.type?H(e):"municipality"===t.type?$(e):q(e)}}break;case"Escape":e.preventDefault(),P?I():(E(),_.current?.blur());break;case"Tab":I()}},[P,V,C,M,I,E,z,A,L,R,G,q,$,H,W]),Y=k.useCallback(()=>{j&&p?.(""),B?(x(""),O()):E(),o?.(),v.current="",_.current?.focus()},[j,p,B,x,O,E,o]),K=k.useCallback(e=>{N(e)},[N]),Q="external"!==s?`sep-search--${s}`:"sep-search--external",J=T||S||w.length>0,ee=/* @__PURE__ */F.jsxs("div",{ref:y,className:`sep-search ${Q} ${c}`.trim(),style:f,role:"combobox","aria-expanded":P,"aria-haspopup":"listbox","aria-owns":"sep-search-results",children:[
16
15
  /* @__PURE__ */F.jsxs("div",{className:"sep-search__input-container",children:[
17
16
  /* @__PURE__ */F.jsx("span",{className:"sep-search__icon","aria-hidden":"true",children:/* @__PURE__ */F.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[