@pro6pp/infer-js 0.0.2-beta.9 → 0.1.0-beta.19

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.
@@ -1,23 +1,31 @@
1
- "use strict";var Pro6PP=(()=>{var m=Object.defineProperty,L=Object.defineProperties,T=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var w=(a,e,t)=>e in a?m(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,f=(a,e)=>{for(var t in e||(e={}))C.call(e,t)&&w(a,t,e[t]);if(S)for(var t of S(e))A.call(e,t)&&w(a,t,e[t]);return a},b=(a,e)=>L(a,M(e));var _=(a,e)=>{for(var t in e)m(a,t,{get:e[t],enumerable:!0})},B=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k(e))!C.call(a,i)&&i!==t&&m(a,i,{get:()=>e[i],enumerable:!(s=T(e,i))||s.enumerable});return a};var D=a=>B(m({},"__esModule",{value:!0}),a);var R={};_(R,{InferJS:()=>x,attach:()=>F});var g={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},I={DIGITS_1_3:/^[0-9]{1,3}$/},E={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},y=class{constructor(e){this.abortController=null;this.isSelecting=!1;this.country=e.country,this.authKey=e.authKey,this.explicitApiUrl=e.apiUrl,this.baseLimit=e.limit||g.LIMIT,this.currentLimit=this.baseLimit;let t=e.maxRetries!==void 0?e.maxRetries:g.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(t,10)),this.fetcher=e.fetcher||((r,n)=>fetch(r,n)),this.onStateChange=e.onStateChange||(()=>{}),this.onSelect=e.onSelect||(()=>{}),this.state=f({},E);let s=e.debounceMs!==void 0?e.debounceMs:g.DEBOUNCE_MS,i=Math.max(s,g.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(r=>this.executeFetch(r),i)}handleInput(e){if(this.isSelecting){this.isSelecting=!1;return}this.currentLimit=this.baseLimit;let t=this.state.stage==="final"&&e!==this.state.query;this.updateState({query:e,isValid:!1,isLoading:!!e.trim(),selectedSuggestionIndex:-1,hasMore:!1}),t&&this.onSelect(null),this.debouncedFetch(e)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(e){let t=e.target;if(!t)return;let s=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(s>0){if(e.key==="ArrowDown"){e.preventDefault();let r=this.state.selectedSuggestionIndex+1;r>=s&&(r=0),this.updateState({selectedSuggestionIndex:r});return}if(e.key==="ArrowUp"){e.preventDefault();let r=this.state.selectedSuggestionIndex-1;r<0&&(r=s-1),this.updateState({selectedSuggestionIndex:r});return}if(e.key==="Enter"&&this.state.selectedSuggestionIndex>=0){e.preventDefault();let n=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];n&&(this.selectItem(n),this.updateState({selectedSuggestionIndex:-1}));return}}let i=t.value;if(e.key===" "&&this.shouldAutoInsertComma(i)){e.preventDefault();let r=`${i.trim()}, `;this.updateQueryAndFetch(r)}}selectItem(e){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let t=typeof e=="string"?e:e.label,s=t;typeof e!="string"&&typeof e.value=="string"&&(s=e.value);let i=typeof e!="string"&&typeof e.value=="object"?e.value:void 0,r=!!i&&Object.keys(i).length>0;if(this.isSelecting=!0,this.state.stage==="final"||r){let u=t;if(i&&Object.keys(i).length>0){let{street:l,street_number:p,house_number:h,city:o}=i,c=p||h;l&&c&&o&&(u=`${l} ${c}, ${o}`)}return this.finishSelection(u,i),!0}let n=typeof e!="string"?e.subtitle:null;return this.processSelection(s,n),!1}shouldAutoInsertComma(e){if(!e.includes(",")&&I.DIGITS_1_3.test(e.trim()))return!0;if(this.state.stage==="house_number"){let s=this.getCurrentFragment(e);return I.DIGITS_1_3.test(s)}return!1}finishSelection(e,t){this.updateState({query:e,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final",hasMore:!1}),this.onSelect(t||e)}processSelection(e,t){let{stage:s,query:i}=this.state,r=i;if(t&&(s==="city"||s==="street"||s==="mixed")){if(s==="city")r=`${t}, ${e}, `;else{let p=this.getQueryPrefix(i);r=p?`${p} ${e}, ${t}, `:`${e}, ${t}, `}this.updateQueryAndFetch(r);return}if(s==="direct"||s==="addition"){this.finishSelection(e);return}!i.includes(",")&&(s==="city"||s==="street"||s==="house_number_first")?r=`${e}, `:(r=this.replaceLastSegment(i,e),s!=="house_number"&&(r+=", ")),this.updateQueryAndFetch(r)}executeFetch(e,t=0){var p,h;let s=(e||"").toString();if(!s.trim()){(p=this.abortController)==null||p.abort(),this.resetState();return}t===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let i=(h=this.abortController)==null?void 0:h.signal,r=this.explicitApiUrl?this.explicitApiUrl:`${g.API_URL}/infer/${this.country.toLowerCase()}`,n=new URLSearchParams({country:this.country.toLowerCase(),query:s,limit:this.currentLimit.toString()});this.authKey&&n.set("authKey",this.authKey);let u=r.includes("?")?"&":"?",l=`${r}${u}${n.toString()}`;this.fetcher(l,{signal:i}).then(o=>{if(!o.ok){if(t<this.maxRetries&&(o.status>=500||o.status===429))return this.retry(e,t,i);throw new Error("Network error")}return o.json()}).then(o=>{o&&this.mapResponseToState(o)}).catch(o=>{if(o.name!=="AbortError"){if(t<this.maxRetries)return this.retry(e,t,i);this.updateState({isError:!0,isLoading:!1})}})}retry(e,t,s){if(s!=null&&s.aborted)return;let i=Math.pow(2,t)*200;setTimeout(()=>{s!=null&&s.aborted||this.executeFetch(e,t+1)},i)}mapResponseToState(e){var p,h;let t={stage:e.stage,isLoading:!1},s=!1,i=null,r=e.suggestions||[],n=[],u=new Set;for(let o of r){let c=`${o.label}|${o.subtitle||""}|${JSON.stringify(o.value||{})}`;u.has(c)||(u.add(c),n.push(o))}let l=n.length+(((p=e.cities)==null?void 0:p.length)||0)+(((h=e.streets)==null?void 0:h.length)||0);if(t.hasMore=l>=this.currentLimit,e.stage==="mixed")t.cities=e.cities||[],t.streets=e.streets||[],t.suggestions=[];else{t.suggestions=n,t.cities=[],t.streets=[];let o=n[0],c=o&&typeof o.value=="object"&&o.value!==null&&Object.keys(o.value).length>0;(e.stage==="final"||c)&&n.length===1&&(s=!0,i=o)}if(t.isValid=e.stage==="final",s&&i){t.query=i.label,t.suggestions=[],t.cities=[],t.streets=[],t.isValid=!0,t.hasMore=!1,this.isSelecting=!0,this.updateState(t);let o=typeof i.value=="object"?i.value:i.label;this.onSelect(o)}else this.updateState(t)}updateQueryAndFetch(e){this.updateState({query:e,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(e)}replaceLastSegment(e,t){let s=e.lastIndexOf(",");return s===-1?t:`${e.slice(0,s+1)} ${t}`.trim()}getQueryPrefix(e){let t=e.lastIndexOf(",");return t===-1?"":e.slice(0,t+1).trimEnd()}getCurrentFragment(e){var t;return((t=e.split(",").slice(-1)[0])!=null?t:"").trim()}resetState(){this.updateState(b(f({},E),{query:this.state.query}))}updateState(e){this.state=f(f({},this.state),e),this.onStateChange(this.state)}debounce(e,t){let s,i=(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>e.apply(this,r),t)};return i.cancel=()=>{s&&(clearTimeout(s),s=void 0)},i}};var v=`
1
+ "use strict";var Pro6PP=(()=>{var y=Object.defineProperty,k=Object.defineProperties,$=Object.getOwnPropertyDescriptor,R=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertyNames,L=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var I=(o,e,t)=>e in o?y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,f=(o,e)=>{for(var t in e||(e={}))T.call(e,t)&&I(o,t,e[t]);if(L)for(var t of L(e))H.call(e,t)&&I(o,t,e[t]);return o},m=(o,e)=>k(o,R(e));var N=(o,e)=>{for(var t in e)y(o,t,{get:e[t],enumerable:!0})},B=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!T.call(o,s)&&s!==t&&y(o,s,{get:()=>e[s],enumerable:!(n=$(e,s))||n.enumerable});return o};var O=o=>B(y({},"__esModule",{value:!0}),o);var K={};N(K,{InferJS:()=>v,attach:()=>q});function _(o){return o.toLowerCase().trim()}function U(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(o,e){let t=_(o),n=_(e);if(n.includes(" "))return t.indexOf(n);let r=new RegExp(`(?:^|[,\\s])${U(n)}(?:$|[,\\s])`,"g").exec(t);if(r){let i=r.index,p=t[i];return p===","||p===" "?i+1:i}return-1}function P(o,e){let t=[],n=[];e.street&&n.push({value:e.street,type:"street"}),e.city&&n.push({value:e.city,type:"city"}),e.postcode&&n.push({value:e.postcode,type:"postcode"}),e.street_number!==void 0&&e.street_number!==null&&n.push({value:String(e.street_number),type:"street_number"}),e.addition&&n.push({value:e.addition,type:"addition"});for(let s of n){let r=V(o,s.value);r!==-1&&t.push({type:s.type,value:s.value,position:r})}return t.sort((s,r)=>s.position-r.position),t}function M(o,e){if(!e||!o)return"";let t=P(o,e),n=new Set(t.map(i=>i.type)),s=[];for(let i of t)s.push(i.value);let r=["street","street_number","addition","postcode","city"];for(let i of r){if(n.has(i))continue;let p;switch(i){case"street":p=e.street;break;case"city":p=e.city;break;case"street_number":p=e.street_number!==void 0?String(e.street_number):void 0;break;case"postcode":p=e.postcode;break;case"addition":p=e.addition;break}p&&s.push(p)}return s.join(", ")}var b={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},w={DIGITS_1_3:/^[0-9]{1,3}$/,STREET_NUMBER_PREFIX:/^(\d+)\s*,\s*$/},A={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,value:null,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},x=class{constructor(e){this.abortController=null;this.country=e.country,this.authKey=e.authKey,this.explicitApiUrl=e.apiUrl,this.baseLimit=e.limit||b.LIMIT,this.currentLimit=this.baseLimit,this.language=e.language;let t=e.maxRetries!==void 0?e.maxRetries:b.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(t,10)),this.fetcher=e.fetcher||((r,i)=>fetch(r,i)),this.onStateChange=e.onStateChange||(()=>{}),this.onSelect=e.onSelect||(()=>{}),this.state=f({},A);let n=e.debounceMs!==void 0?e.debounceMs:b.DEBOUNCE_MS,s=Math.max(n,b.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(r=>this.executeFetch(r),s)}handleInput(e){this.currentLimit=this.baseLimit;let t=this.state.stage==="final"&&e!==this.state.query;this.updateState({query:e,isValid:!1,value:null,isLoading:!!e.trim(),selectedSuggestionIndex:-1,hasMore:!1,stage:t?null:this.state.stage}),t&&this.onSelect(null),this.debouncedFetch(e)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(e){let t=e.target;if(!t)return;let n=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(n>0){if(e.key==="ArrowDown"){e.preventDefault();let r=this.state.selectedSuggestionIndex+1;r>=n&&(r=0),this.updateState({selectedSuggestionIndex:r});return}if(e.key==="ArrowUp"){e.preventDefault();let r=this.state.selectedSuggestionIndex-1;r<0&&(r=n-1),this.updateState({selectedSuggestionIndex:r});return}if(e.key==="Enter"&&this.state.selectedSuggestionIndex>=0){e.preventDefault();let i=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];i&&(this.selectItem(i),this.updateState({selectedSuggestionIndex:-1}));return}}let s=t.value;if(e.key===" "&&this.shouldAutoInsertComma(s)){e.preventDefault();let r=`${s.trim()}, `;this.updateQueryAndFetch(r)}}selectItem(e){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let t=typeof e=="string"?e:e.label,n=t;typeof e!="string"&&typeof e.value=="string"&&(n=e.value);let s=typeof e!="string"&&typeof e.value=="object"?e.value:void 0,r=!!s&&Object.keys(s).length>0;if(this.state.stage==="final"||r){let p=t;if(s&&Object.keys(s).length>0){let{street:u,street_number:a,postcode:c,city:l,addition:h}=s;if(u&&a&&l){let g=h?` ${h}`:"",d=c?`${c}, `:"";p=`${u}, ${a}${g}, ${d}${l}`}}return this.finishSelection(p,s),!0}let i=typeof e!="string"?e.subtitle:null;return this.processSelection(n,i),!1}shouldAutoInsertComma(e){if(!e.includes(",")&&w.DIGITS_1_3.test(e.trim()))return!0;if(this.state.stage==="street_number"){let n=this.getCurrentFragment(e);return w.DIGITS_1_3.test(n)}return!1}finishSelection(e,t){this.updateState({query:e,suggestions:[],cities:[],streets:[],isValid:!0,value:t||null,stage:"final",hasMore:!1}),this.onSelect(t||e)}processSelection(e,t){let{stage:n,query:s}=this.state,r=s;if(t&&(n==="city"||n==="street"||n==="mixed")){if(n==="city")r=`${t}, ${e}, `;else{let a=this.getQueryPrefix(s),c=!a||!a.includes(t),l=a;if(a&&t){let h=a.match(w.STREET_NUMBER_PREFIX);if(h){let g=h[1];t.startsWith(g)&&(l="")}}c?r=l?`${l} ${e}, ${t}, `:`${e}, ${t}, `:r=l?`${l} ${e}, `:`${e}, `}this.updateQueryAndFetch(r);return}if(n==="direct"||n==="addition"){this.finishSelection(e);return}!s.includes(",")&&(n==="city"||n==="street"||n==="street_number_first")?r=`${e}, `:(r=this.replaceLastSegment(s,e),n!=="street_number"&&(r+=", ")),this.updateQueryAndFetch(r)}executeFetch(e,t=0){var a,c;let n=(e||"").toString();if(!n.trim()){(a=this.abortController)==null||a.abort(),this.resetState();return}t===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let s=(c=this.abortController)==null?void 0:c.signal,r=this.explicitApiUrl?this.explicitApiUrl:`${b.API_URL}/infer/${this.country.toLowerCase()}`,i=new URLSearchParams({query:n,limit:this.currentLimit.toString()});this.explicitApiUrl&&i.append("country",this.country.toLowerCase()),this.authKey&&i.set("authKey",this.authKey),this.language&&i.set("language",this.language);let p=r.includes("?")?"&":"?",u=`${r}${p}${i.toString()}`;this.fetcher(u,{signal:s}).then(l=>{if(!l.ok){if(t<this.maxRetries&&(l.status>=500||l.status===429))return this.retry(e,t,s);throw new Error("Network error")}return l.json()}).then(l=>{l&&this.mapResponseToState(l)}).catch(l=>{if(l.name!=="AbortError"){if(t<this.maxRetries)return this.retry(e,t,s);this.updateState({isError:!0,isLoading:!1})}})}retry(e,t,n){if(n!=null&&n.aborted)return;let s=Math.pow(2,t)*200;setTimeout(()=>{n!=null&&n.aborted||this.executeFetch(e,t+1)},s)}mapResponseToState(e){var p,u,a,c;let t={stage:e.stage,isLoading:!1},n=e.suggestions||[],s=[],r=new Set;for(let l of n){let h=`${l.label}|${l.subtitle||""}|${JSON.stringify(l.value||{})}`;if(!r.has(h)){r.add(h);let g=this.reformatSuggestionLabel(l);s.push(g)}}let i=s.length+(((p=e.cities)==null?void 0:p.length)||0)+(((u=e.streets)==null?void 0:u.length)||0);t.hasMore=i>=this.currentLimit,e.stage==="mixed"?(t.cities=e.cities||[],t.streets=e.streets||[],((a=t.cities)==null?void 0:a.length)===0&&((c=t.streets)==null?void 0:c.length)===0?t.suggestions=s:t.suggestions=[]):(t.suggestions=s,t.cities=[],t.streets=[]),t.isValid=e.stage==="final",this.updateState(t),t.isValid&&s.length===1&&this.selectItem(s[0])}reformatSuggestionLabel(e){if(!e.value||typeof e.value=="string")return e;let t=e.value;if(!t.street||!t.city)return e;let n=M(this.state.query,t);return n?m(f({},e),{label:n}):e}updateQueryAndFetch(e){this.updateState({query:e,suggestions:[],cities:[],streets:[],isValid:!1,value:null,isLoading:!0,hasMore:!1}),this.debouncedFetch(e)}replaceLastSegment(e,t){let n=e.lastIndexOf(",");return n===-1?t:`${e.slice(0,n+1)} ${t}`.trim()}getQueryPrefix(e){let t=e.lastIndexOf(",");return t===-1?"":e.slice(0,t+1).trimEnd()}getCurrentFragment(e){var t;return((t=e.split(",").slice(-1)[0])!=null?t:"").trim()}resetState(){this.updateState(m(f({},A),{query:this.state.query}))}updateState(e){this.state=f(f({},this.state),e),this.onStateChange(this.state)}debounce(e,t){let n,s=(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>e.apply(this,r),t)};return s.cancel=()=>{n&&(clearTimeout(n),n=void 0)},s}};function z(o){if(o.length===0)return o;let e=[];for(let t of o){let n=e[e.length-1];n&&n.match===t.match?n.text+=t.text:e.push({text:t.text,match:t.match})}return e}function D(o,e){if(!e||!o)return[{text:o,match:!1}];let t=[],n=o.toLowerCase(),s=e.toLowerCase(),r=0,i=0;for(let a=0;a<o.length;a++){if(!(r<e.length&&n[a]===s[r]))continue;a>i&&t.push({text:o.slice(i,a),match:!1}),t.push({text:o[a],match:!0}),r++,i=a+1}return i<o.length&&t.push({text:o.slice(i),match:!1}),r===e.length?z(t):[{text:o,match:!1}]}var C=`
2
2
  .pro6pp-wrapper {
3
3
  position: relative;
4
4
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
5
  box-sizing: border-box;
6
6
  width: 100%;
7
+ -webkit-tap-highlight-color: transparent;
7
8
  }
8
9
  .pro6pp-wrapper * {
9
10
  box-sizing: border-box;
10
11
  }
11
12
  .pro6pp-input {
12
13
  width: 100%;
13
- padding: 10px 12px;
14
+ padding: 12px 14px;
14
15
  padding-right: 48px;
15
16
  border: 1px solid #e0e0e0;
16
- border-radius: 4px;
17
+ border-radius: 8px;
17
18
  font-size: 16px;
18
19
  line-height: 1.5;
20
+ appearance: none;
19
21
  transition: border-color 0.2s, box-shadow 0.2s;
20
22
  }
23
+
24
+ .pro6pp-input::placeholder {
25
+ font-size: 16px;
26
+ color: #a3a3a3;
27
+ }
28
+
21
29
  .pro6pp-input:focus {
22
30
  outline: none;
23
31
  border-color: #3b82f6;
@@ -26,12 +34,11 @@
26
34
 
27
35
  .pro6pp-input-addons {
28
36
  position: absolute;
29
- right: 6px;
37
+ right: 4px;
30
38
  top: 0;
31
39
  bottom: 0;
32
40
  display: flex;
33
41
  align-items: center;
34
- gap: 2px;
35
42
  pointer-events: none;
36
43
  }
37
44
  .pro6pp-input-addons > * {
@@ -41,37 +48,27 @@
41
48
  .pro6pp-clear-button {
42
49
  background: none;
43
50
  border: none;
44
- width: 28px;
45
- height: 28px;
51
+ width: 32px;
52
+ height: 32px;
46
53
  cursor: pointer;
47
54
  color: #a3a3a3;
48
55
  display: flex;
49
56
  align-items: center;
50
57
  justify-content: center;
51
58
  border-radius: 50%;
52
- transition: color 0.2s, background-color 0.2s, transform 0.1s;
53
- }
54
- .pro6pp-clear-button:hover {
55
- color: #1f2937;
56
- background-color: #f3f4f6;
57
- }
58
- .pro6pp-clear-button:active {
59
- transform: scale(0.92);
59
+ transition: color 0.2s, background-color 0.2s;
60
+ touch-action: manipulation;
60
61
  }
61
- .pro6pp-clear-button svg {
62
- width: 18px;
63
- height: 18px;
62
+
63
+ @media (hover: hover) {
64
+ .pro6pp-clear-button:hover {
65
+ color: #1f2937;
66
+ background-color: #f3f4f6;
67
+ }
64
68
  }
65
69
 
66
- .pro6pp-loader {
67
- width: 18px;
68
- height: 18px;
69
- margin: 0 4px;
70
- border: 2px solid #e0e0e0;
71
- border-top-color: #6b7280;
72
- border-radius: 50%;
73
- animation: pro6pp-spin 0.6s linear infinite;
74
- flex-shrink: 0;
70
+ .pro6pp-clear-button:active {
71
+ background-color: #f3f4f6;
75
72
  }
76
73
 
77
74
  .pro6pp-dropdown {
@@ -79,89 +76,141 @@
79
76
  top: 100%;
80
77
  left: 0;
81
78
  right: 0;
82
- z-index: 9999;
83
79
  margin-top: 4px;
84
- background: white;
85
- border: 1px solid #e0e0e0;
86
- border-radius: 4px;
87
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
88
- max-height: 300px;
80
+ background: #ffffff;
81
+ border: 1px solid #e5e7eb;
82
+ border-radius: 6px;
83
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
84
+ z-index: 9999;
85
+ padding: 0;
86
+ max-height: 280px;
89
87
  overflow-y: auto;
90
88
  display: flex;
91
89
  flex-direction: column;
92
90
  }
91
+
92
+ @media (max-height: 500px) {
93
+ .pro6pp-dropdown {
94
+ max-height: 180px;
95
+ }
96
+ }
97
+
93
98
  .pro6pp-list {
94
- list-style: none !important;
95
- padding: 0 !important;
96
- margin: 0 !important;
97
- flex-grow: 1;
99
+ list-style: none;
100
+ margin: 0;
101
+ padding: 0;
102
+ width: 100%;
98
103
  }
104
+
99
105
  .pro6pp-item {
100
- padding: 12px 16px;
106
+ padding: 12px 14px;
101
107
  cursor: pointer;
102
108
  display: flex;
103
- flex-direction: row;
104
109
  align-items: center;
105
- color: #111827;
106
- font-size: 14px;
107
- line-height: 1.2;
108
- white-space: nowrap;
109
- overflow: hidden;
110
+ font-size: 15px;
111
+ line-height: 1.4;
112
+ color: #374151;
113
+ border-bottom: 1px solid #f3f4f6;
114
+ transition: background-color 0.1s;
115
+ flex-shrink: 0;
110
116
  }
111
- .pro6pp-item:hover, .pro6pp-item--active {
112
- background-color: #f9fafb;
117
+
118
+ .pro6pp-item:last-child {
119
+ border-bottom: none;
120
+ }
121
+
122
+ @media (hover: hover) {
123
+ .pro6pp-item:hover, .pro6pp-item--active {
124
+ background-color: #f9fafb;
125
+ }
113
126
  }
127
+
128
+ .pro6pp-item:active {
129
+ background-color: #f3f4f6;
130
+ }
131
+
114
132
  .pro6pp-item__label {
115
- font-weight: 500;
116
- flex-shrink: 0;
133
+ font-weight: 400;
134
+ flex-shrink: 1;
135
+ overflow: hidden;
136
+ text-overflow: ellipsis;
137
+ white-space: nowrap;
138
+ }
139
+
140
+ .pro6pp-item__label--match {
141
+ font-weight: 520;
142
+ }
143
+
144
+ .pro6pp-item__label--unmatched {
145
+ font-weight: 400;
146
+ color: #4b5563;
117
147
  }
148
+
118
149
  .pro6pp-item__subtitle {
119
- font-size: 14px;
120
150
  color: #6b7280;
121
- overflow: hidden;
122
- text-overflow: ellipsis;
123
- flex-shrink: 1;
151
+ flex-shrink: 0;
124
152
  }
153
+
125
154
  .pro6pp-item__chevron {
126
- margin-left: auto;
155
+ color: #d1d5db;
127
156
  display: flex;
128
157
  align-items: center;
129
- color: #9ca3af;
158
+ margin-left: auto;
130
159
  padding-left: 8px;
131
160
  }
161
+
132
162
  .pro6pp-no-results {
133
- padding: 16px;
163
+ padding: 24px 16px;
134
164
  color: #6b7280;
135
- font-size: 14px;
165
+ font-size: 15px;
136
166
  text-align: center;
137
167
  }
138
- .pro6pp-load-more {
139
- width: 100%;
140
- padding: 10px;
141
- background: #f9fafb;
142
- border: none;
143
- border-top: 1px solid #e0e0e0;
144
- color: #3b82f6;
145
- font-size: 13px;
146
- font-weight: 600;
147
- cursor: pointer;
148
- transition: background-color 0.2s;
149
- flex-shrink: 0;
168
+
169
+ .pro6pp-loader-item {
170
+ padding: 10px 12px;
171
+ color: #6b7280;
172
+ font-size: 0.875rem;
173
+ display: flex;
174
+ align-items: center;
175
+ justify-content: center;
176
+ gap: 8px;
177
+ background-color: #f9fafb;
178
+ border-top: 1px solid #f3f4f6;
150
179
  }
151
- .pro6pp-load-more:hover {
152
- background-color: #f3f4f6;
180
+
181
+ .pro6pp-mini-spinner {
182
+ width: 14px;
183
+ height: 14px;
184
+ border: 2px solid #e5e7eb;
185
+ border-top-color: #6b7280;
186
+ border-radius: 50%;
187
+ animation: pro6pp-spin 0.6s linear infinite;
188
+ }
189
+
190
+ @media (max-width: 640px) {
191
+ .pro6pp-input {
192
+ font-size: 16px;
193
+ padding: 10px 12px;
194
+ }
195
+ .pro6pp-item {
196
+ padding: 10px 12px;
197
+ font-size: 14px;
198
+ }
153
199
  }
154
200
 
155
201
  @keyframes pro6pp-spin {
156
202
  to { transform: rotate(360deg); }
157
203
  }
158
- `;var x=class{constructor(e,t){this.isOpen=!1;var r;let s=typeof e=="string"?document.querySelector(e):e;if(!s)throw new Error("InferJS: Target element not found.");if(this.noResultsText=t.noResultsText||"No results found",this.loadMoreText=t.loadMoreText||"Show more results...",this.showClearButton=t.showClearButton!==!1,this.useDefaultStyles=t.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",s instanceof HTMLInputElement?(this.input=s,(r=this.input.parentNode)==null||r.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(s.appendChild(this.wrapper),this.input=document.createElement("input"),this.input.type="text",t.placeholder&&(this.input.placeholder=t.placeholder),this.wrapper.appendChild(this.input)),this.useDefaultStyles&&this.input.classList.add("pro6pp-input"),t.inputClass){let n=t.inputClass.split(" ");this.input.classList.add(...n)}let i=document.createElement("div");i.className="pro6pp-input-addons",this.wrapper.appendChild(i),this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",i.appendChild(this.loader),this.clearButton=document.createElement("button"),this.clearButton.type="button",this.clearButton.className="pro6pp-clear-button",this.clearButton.setAttribute("aria-label","Clear input"),this.clearButton.style.display="none",this.clearButton.innerHTML=`
204
+ `;var v=class{constructor(e,t){this.isOpen=!1;this.boundHandlers=null;this.isDestroyed=!1;var r;let n=typeof e=="string"?document.querySelector(e):e;if(!n)throw new Error("InferJS: Target element not found.");if(this.noResultsText=t.noResultsText||"No results found",this.loadingText=t.loadingText||"Loading more...",this.showClearButton=t.showClearButton!==!1,this.useDefaultStyles=t.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",n instanceof HTMLInputElement?(this.input=n,(r=this.input.parentNode)==null||r.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(n.appendChild(this.wrapper),this.input=document.createElement("input"),this.input.type="text",t.placeholder&&(this.input.placeholder=t.placeholder),this.wrapper.appendChild(this.input)),this.input.setAttribute("autocomplete","off"),this.input.setAttribute("autocorrect","off"),this.input.setAttribute("autocapitalize","none"),this.input.setAttribute("spellcheck","false"),this.input.setAttribute("inputmode","search"),this.input.setAttribute("enterkeyhint","search"),this.input.classList.add("pro6pp-input"),t.inputClass){let i=t.inputClass.split(" ");this.input.classList.add(...i)}let s=document.createElement("div");s.className="pro6pp-input-addons",this.wrapper.appendChild(s),this.clearButton=document.createElement("button"),this.clearButton.type="button",this.clearButton.className="pro6pp-clear-button",this.clearButton.setAttribute("aria-label","Clear input"),this.clearButton.style.display="none",this.clearButton.innerHTML=`
159
205
  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
160
206
  <line x1="18" y1="6" x2="6" y2="18"></line>
161
207
  <line x1="6" y1="6" x2="18" y2="18"></line>
162
208
  </svg>
163
- `,i.appendChild(this.clearButton),this.dropdown=document.createElement("div"),this.dropdown.className="pro6pp-dropdown",this.dropdown.style.display="none",this.wrapper.appendChild(this.dropdown),this.list=document.createElement("ul"),this.list.className="pro6pp-list",this.list.setAttribute("role","listbox"),this.dropdown.appendChild(this.list),this.loadMoreButton=document.createElement("button"),this.loadMoreButton.type="button",this.loadMoreButton.className="pro6pp-load-more",this.loadMoreButton.textContent=this.loadMoreText,this.loadMoreButton.style.display="none",this.dropdown.appendChild(this.loadMoreButton),this.core=new y(b(f({},t),{onStateChange:n=>this.render(n),onSelect:n=>{typeof n=="string"?this.input.value=n:n&&typeof n=="object"&&(this.input.value=this.core.state.query),t.onSelect&&t.onSelect(n)}})),this.bindEvents()}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let t=document.createElement("style");t.id=e,t.textContent=v,document.head.appendChild(t)}}bindEvents(){this.input.addEventListener("input",e=>{let t=e.target.value;this.isOpen=!0,this.core.handleInput(t)}),this.input.addEventListener("keydown",e=>{this.core.handleKeyDown(e)}),this.clearButton.addEventListener("click",()=>{this.core.handleInput(""),this.input.focus()}),this.loadMoreButton.addEventListener("click",e=>{e.preventDefault(),this.core.loadMore()}),document.addEventListener("mousedown",e=>{this.wrapper.contains(e.target)||(this.isOpen=!1,this.dropdown.style.display="none")}),this.input.addEventListener("focus",()=>{this.isOpen=!0,this.render(this.core.state)})}render(e){this.input.value!==e.query&&(this.input.value=e.query),this.loader.style.display=e.isLoading?"block":"none",this.showClearButton&&(this.clearButton.style.display=e.query.length>0?"flex":"none"),this.list.innerHTML="";let t=[...e.cities,...e.streets,...e.suggestions],s=t.length>0,i=!e.isLoading&&!e.isError&&e.query.length>0&&!s&&!e.isValid;if(!(this.isOpen&&(s||e.isLoading||i))){this.dropdown.style.display="none";return}if(this.dropdown.style.display="flex",this.loadMoreButton.style.display=e.hasMore?"block":"none",e.isLoading&&!s){let n=document.createElement("li");n.className="pro6pp-no-results",this.list.appendChild(n);return}if(i){let n=document.createElement("li");n.className="pro6pp-no-results",n.textContent=this.noResultsText,this.list.appendChild(n);return}t.forEach((n,u)=>{if(!n.label)return;let l=document.createElement("li");l.className="pro6pp-item",u===e.selectedSuggestionIndex&&l.classList.add("pro6pp-item--active"),l.setAttribute("role","option"),l.setAttribute("aria-selected",u===e.selectedSuggestionIndex?"true":"false");let p=document.createElement("span");p.className="pro6pp-item__label",p.textContent=n.label,l.appendChild(p);let h=n.count!==void 0&&n.count!==null?n.count:"",o=n.subtitle||h;if(o!==""){let d=document.createElement("span");d.className="pro6pp-item__subtitle",d.textContent=`, ${o}`,l.appendChild(d)}if(n.value===void 0||n.value===null){let d=document.createElement("div");d.className="pro6pp-item__chevron",d.innerHTML=`
209
+ `,s.appendChild(this.clearButton),this.dropdown=document.createElement("div"),this.dropdown.className="pro6pp-dropdown",this.dropdown.style.display="none",this.wrapper.appendChild(this.dropdown),this.list=document.createElement("ul"),this.list.className="pro6pp-list",this.list.setAttribute("role","listbox"),this.dropdown.appendChild(this.list),this.dropdownLoader=document.createElement("div"),this.dropdownLoader.className="pro6pp-loader-item",this.dropdownLoader.style.display="none",this.dropdownLoader.innerHTML=`
210
+ <div class="pro6pp-mini-spinner"></div>
211
+ <span>${this.loadingText}</span>
212
+ `,this.dropdown.appendChild(this.dropdownLoader),this.core=new x(m(f({},t),{onStateChange:i=>{this.render(i),t.onStateChange&&t.onStateChange(i)},onSelect:i=>{typeof i=="string"?this.input.value=i:i&&typeof i=="object"&&(this.input.value=this.core.state.query),t.onSelect&&t.onSelect(i)}})),this.observer=new IntersectionObserver(i=>{i[0].isIntersecting&&this.core.state.hasMore&&!this.core.state.isLoading&&this.core.loadMore()},{threshold:.1}),this.bindEvents()}get value(){return this.core.state.value||null}set value(e){if(!e)return;let t=e.addition?` ${e.addition}`:"",n=e.postcode?`${e.postcode}, `:"",s=`${e.street}, ${e.street_number}${t}, ${n}${e.city}`;this.core.selectItem({label:s,value:e})}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.boundHandlers&&(this.input.removeEventListener("input",this.boundHandlers.onInput),this.input.removeEventListener("keydown",this.boundHandlers.onKeyDown),this.clearButton.removeEventListener("click",this.boundHandlers.onClearClick),document.removeEventListener("mousedown",this.boundHandlers.onDocumentMouseDown),this.input.removeEventListener("focus",this.boundHandlers.onFocus),this.boundHandlers=null),this.observer.disconnect(),this.wrapper.parentNode&&(this.wrapper.parentNode.insertBefore(this.input,this.wrapper),this.wrapper.remove()),this.input.classList.remove("pro6pp-input"),this.input.value="")}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let t=document.createElement("style");t.id=e,t.textContent=C,document.head.appendChild(t)}}bindEvents(){this.boundHandlers={onInput:e=>{let t=e.target.value;this.isOpen=!0,this.core.handleInput(t)},onKeyDown:e=>{this.core.handleKeyDown(e)},onClearClick:()=>{this.core.handleInput(""),this.input.focus()},onDocumentMouseDown:e=>{this.wrapper.contains(e.target)||(this.isOpen=!1,this.dropdown.style.display="none")},onFocus:()=>{this.isOpen=!0,this.render(this.core.state)}},this.input.addEventListener("input",this.boundHandlers.onInput),this.input.addEventListener("keydown",this.boundHandlers.onKeyDown),this.clearButton.addEventListener("click",this.boundHandlers.onClearClick),document.addEventListener("mousedown",this.boundHandlers.onDocumentMouseDown),this.input.addEventListener("focus",this.boundHandlers.onFocus)}render(e){this.input.value!==e.query&&(this.input.value=e.query),this.showClearButton&&(this.clearButton.style.display=e.query.length>0?"flex":"none"),this.list.innerHTML="";let t=[...e.cities,...e.streets,...e.suggestions],n=t.length>0,s=!e.isLoading&&!e.isError&&e.query.length>0&&!n&&!e.isValid;if(!(this.isOpen&&(n||e.isLoading||s))){this.dropdown.style.display="none";return}if(this.dropdown.style.display="block",e.isLoading&&n?this.dropdownLoader.style.display="flex":this.dropdownLoader.style.display="none",e.isLoading&&!n){let i=document.createElement("li");i.className="pro6pp-no-results",i.textContent="Searching...",this.list.appendChild(i),this.dropdownLoader.style.display="none";return}if(s){let i=document.createElement("li");i.className="pro6pp-no-results",i.textContent=this.noResultsText,this.list.appendChild(i);return}if(t.forEach((i,p)=>{if(!i.label)return;let u=document.createElement("li");u.className="pro6pp-item",p===e.selectedSuggestionIndex&&u.classList.add("pro6pp-item--active"),u.setAttribute("role","option"),u.setAttribute("aria-selected",p===e.selectedSuggestionIndex?"true":"false");let a=document.createElement("span");a.className="pro6pp-item__label",D(i.label,e.query).forEach(({text:d,match:E})=>{let S=document.createElement("span");S.className=E?"pro6pp-item__label--match":"pro6pp-item__label--unmatched",S.textContent=d,a.appendChild(S)}),u.appendChild(a);let l=i.count!==void 0&&i.count!==null?i.count:"",h=i.subtitle||l;if(h!==""){let d=document.createElement("span");d.className="pro6pp-item__subtitle",d.textContent=`, ${h}`,u.appendChild(d)}if(i.value===void 0||i.value===null){let d=document.createElement("div");d.className="pro6pp-item__chevron",d.innerHTML=`
164
213
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
165
214
  <polyline points="9 18 15 12 9 6"></polyline>
166
215
  </svg>
167
- `,l.appendChild(d)}l.onmousedown=d=>d.preventDefault(),l.onclick=d=>{d.stopPropagation(),this.core.selectItem(n)?(this.isOpen=!1,this.dropdown.style.display="none"):setTimeout(()=>this.input.focus(),0)},this.list.appendChild(l)})}};function F(a,e){return new x(a,e)}return D(R);})();
216
+ `,u.appendChild(d)}u.onmousedown=d=>d.preventDefault(),u.onclick=d=>{d.stopPropagation(),this.core.selectItem(i)?(this.isOpen=!1,this.dropdown.style.display="none"):setTimeout(()=>this.input.focus(),0)},this.list.appendChild(u)}),e.hasMore&&!e.isLoading){let i=document.createElement("li");i.style.height="1px",i.style.opacity="0",this.list.appendChild(i),this.observer.observe(i)}}};function q(o,e){return new v(o,e)}return O(K);})();