@pro6pp/infer-js 0.0.2-beta.6 → 0.0.2-beta.8

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/README.md CHANGED
@@ -23,6 +23,10 @@ npm install @pro6pp/infer-js
23
23
 
24
24
  > **Note:** If you are using React, use [`@pro6pp/infer-react`](https://www.npmjs.com/package/@pro6pp/infer-react) instead.
25
25
 
26
+ #### Option 3: Direct download
27
+
28
+ You can also [download](https://unpkg.com/@pro6pp/infer-js@latest/dist/index.global.js) the latest `index.global.js` and place it in your project.
29
+
26
30
  ## Usage
27
31
 
28
32
  #### Option 1: CDN
@@ -72,22 +76,20 @@ attach(inputElement, {
72
76
  });
73
77
  ```
74
78
 
75
- ## API Configuration
76
-
77
- | Prop | Description | Default |
78
- | :-------------- | :------------------------------------------------------------ | :--------------------------- |
79
- | `authKey` | **(Required)** Your Pro6PP Authorization Key. | - |
80
- | `country` | **(Required)** The country to search in (`'NL'` or `'DE'`). | - |
81
- | `debounceMs` | Delay in milliseconds before the API search. Minimum of 50ms. | `150` |
82
- | `style` | Styling theme. Use `'none'` to disable default CSS. | `'default'` |
83
- | `placeholder` | Custom placeholder text for the input field. | - |
84
- | `inputClass` | Additional CSS classes to add to the input element. | - |
85
- | `noResultsText` | Text to display when no suggestions are found. | `'No results found'` |
86
- | `limit` | Maximum number of suggestions to request. | `1000` |
87
- | `apiUrl` | Base URL for the Pro6PP API. | `'https://api.pro6pp.nl/v2'` |
88
- | `fetcher` | Custom fetch implementation for requests. | `window.fetch` |
89
- | `onSelect` | Callback fired when a result is selected. | - |
90
- | `onStateChange` | Callback fired whenever the internal state updates. | - |
79
+ #### Option 3: Direct download
80
+
81
+ 1. [Download](https://unpkg.com/@pro6pp/infer-js@latest/dist/index.global.js) the latest `index.global.js`.
82
+ 2. Place it in your project and include it directly in your HTML.
83
+
84
+ ```html
85
+ <script src="path/to/index.global.js"></script>
86
+ <script>
87
+ const instance = Pro6PP.attach('#my-input', {
88
+ authKey: 'YOUR_AUTH_KEY',
89
+ country: 'NL',
90
+ });
91
+ </script>
92
+ ```
91
93
 
92
94
  ## Styling
93
95
 
@@ -0,0 +1,167 @@
1
+ "use strict";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});module.exports=D(R);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=`
2
+ .pro6pp-wrapper {
3
+ position: relative;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
+ box-sizing: border-box;
6
+ width: 100%;
7
+ }
8
+ .pro6pp-wrapper * {
9
+ box-sizing: border-box;
10
+ }
11
+ .pro6pp-input {
12
+ width: 100%;
13
+ padding: 10px 12px;
14
+ padding-right: 48px;
15
+ border: 1px solid #e0e0e0;
16
+ border-radius: 4px;
17
+ font-size: 16px;
18
+ line-height: 1.5;
19
+ transition: border-color 0.2s, box-shadow 0.2s;
20
+ }
21
+ .pro6pp-input:focus {
22
+ outline: none;
23
+ border-color: #3b82f6;
24
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
25
+ }
26
+
27
+ .pro6pp-input-addons {
28
+ position: absolute;
29
+ right: 6px;
30
+ top: 0;
31
+ bottom: 0;
32
+ display: flex;
33
+ align-items: center;
34
+ gap: 2px;
35
+ pointer-events: none;
36
+ }
37
+ .pro6pp-input-addons > * {
38
+ pointer-events: auto;
39
+ }
40
+
41
+ .pro6pp-clear-button {
42
+ background: none;
43
+ border: none;
44
+ width: 28px;
45
+ height: 28px;
46
+ cursor: pointer;
47
+ color: #a3a3a3;
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ 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);
60
+ }
61
+ .pro6pp-clear-button svg {
62
+ width: 18px;
63
+ height: 18px;
64
+ }
65
+
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;
75
+ }
76
+
77
+ .pro6pp-dropdown {
78
+ position: absolute;
79
+ top: 100%;
80
+ left: 0;
81
+ right: 0;
82
+ z-index: 9999;
83
+ 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;
89
+ overflow-y: auto;
90
+ display: flex;
91
+ flex-direction: column;
92
+ }
93
+ .pro6pp-list {
94
+ list-style: none !important;
95
+ padding: 0 !important;
96
+ margin: 0 !important;
97
+ flex-grow: 1;
98
+ }
99
+ .pro6pp-item {
100
+ padding: 12px 16px;
101
+ cursor: pointer;
102
+ display: flex;
103
+ flex-direction: row;
104
+ align-items: center;
105
+ color: #111827;
106
+ font-size: 14px;
107
+ line-height: 1.2;
108
+ white-space: nowrap;
109
+ overflow: hidden;
110
+ }
111
+ .pro6pp-item:hover, .pro6pp-item--active {
112
+ background-color: #f9fafb;
113
+ }
114
+ .pro6pp-item__label {
115
+ font-weight: 500;
116
+ flex-shrink: 0;
117
+ }
118
+ .pro6pp-item__subtitle {
119
+ font-size: 14px;
120
+ color: #6b7280;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ flex-shrink: 1;
124
+ }
125
+ .pro6pp-item__chevron {
126
+ margin-left: auto;
127
+ display: flex;
128
+ align-items: center;
129
+ color: #9ca3af;
130
+ padding-left: 8px;
131
+ }
132
+ .pro6pp-no-results {
133
+ padding: 16px;
134
+ color: #6b7280;
135
+ font-size: 14px;
136
+ text-align: center;
137
+ }
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;
150
+ }
151
+ .pro6pp-load-more:hover {
152
+ background-color: #f3f4f6;
153
+ }
154
+
155
+ @keyframes pro6pp-spin {
156
+ to { transform: rotate(360deg); }
157
+ }
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=`
159
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
160
+ <line x1="18" y1="6" x2="6" y2="18"></line>
161
+ <line x1="6" y1="6" x2="18" y2="18"></line>
162
+ </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=`
164
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
165
+ <polyline points="9 18 15 12 9 6"></polyline>
166
+ </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)}0&&(module.exports={InferJS,attach});
@@ -24,6 +24,16 @@ interface InferJSConfig extends InferConfig {
24
24
  * @default 'No results found'
25
25
  */
26
26
  noResultsText?: string;
27
+ /**
28
+ * The text to show on the load more button.
29
+ * @default 'Show more results...'
30
+ */
31
+ loadMoreText?: string;
32
+ /**
33
+ * If true, shows a clear button when the input is not empty.
34
+ * @default true
35
+ */
36
+ showClearButton?: boolean;
27
37
  }
28
38
  /**
29
39
  * The JS implementation of the Pro6PP Infer SDK.
@@ -33,10 +43,16 @@ declare class InferJS {
33
43
  private core;
34
44
  private input;
35
45
  private list;
46
+ private dropdown;
36
47
  private wrapper;
37
48
  private loader;
49
+ private clearButton;
50
+ private loadMoreButton;
38
51
  private useDefaultStyles;
39
52
  private noResultsText;
53
+ private loadMoreText;
54
+ private showClearButton;
55
+ private isOpen;
40
56
  /**
41
57
  * Initializes the Infer logic on a target element.
42
58
  * @param target Either a CSS selector string or a direct HTMLElement.
@@ -24,6 +24,16 @@ interface InferJSConfig extends InferConfig {
24
24
  * @default 'No results found'
25
25
  */
26
26
  noResultsText?: string;
27
+ /**
28
+ * The text to show on the load more button.
29
+ * @default 'Show more results...'
30
+ */
31
+ loadMoreText?: string;
32
+ /**
33
+ * If true, shows a clear button when the input is not empty.
34
+ * @default true
35
+ */
36
+ showClearButton?: boolean;
27
37
  }
28
38
  /**
29
39
  * The JS implementation of the Pro6PP Infer SDK.
@@ -33,10 +43,16 @@ declare class InferJS {
33
43
  private core;
34
44
  private input;
35
45
  private list;
46
+ private dropdown;
36
47
  private wrapper;
37
48
  private loader;
49
+ private clearButton;
50
+ private loadMoreButton;
38
51
  private useDefaultStyles;
39
52
  private noResultsText;
53
+ private loadMoreText;
54
+ private showClearButton;
55
+ private isOpen;
40
56
  /**
41
57
  * Initializes the Infer logic on a target element.
42
58
  * @param target Either a CSS selector string or a direct HTMLElement.
@@ -0,0 +1,167 @@
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=`
2
+ .pro6pp-wrapper {
3
+ position: relative;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
+ box-sizing: border-box;
6
+ width: 100%;
7
+ }
8
+ .pro6pp-wrapper * {
9
+ box-sizing: border-box;
10
+ }
11
+ .pro6pp-input {
12
+ width: 100%;
13
+ padding: 10px 12px;
14
+ padding-right: 48px;
15
+ border: 1px solid #e0e0e0;
16
+ border-radius: 4px;
17
+ font-size: 16px;
18
+ line-height: 1.5;
19
+ transition: border-color 0.2s, box-shadow 0.2s;
20
+ }
21
+ .pro6pp-input:focus {
22
+ outline: none;
23
+ border-color: #3b82f6;
24
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
25
+ }
26
+
27
+ .pro6pp-input-addons {
28
+ position: absolute;
29
+ right: 6px;
30
+ top: 0;
31
+ bottom: 0;
32
+ display: flex;
33
+ align-items: center;
34
+ gap: 2px;
35
+ pointer-events: none;
36
+ }
37
+ .pro6pp-input-addons > * {
38
+ pointer-events: auto;
39
+ }
40
+
41
+ .pro6pp-clear-button {
42
+ background: none;
43
+ border: none;
44
+ width: 28px;
45
+ height: 28px;
46
+ cursor: pointer;
47
+ color: #a3a3a3;
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ 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);
60
+ }
61
+ .pro6pp-clear-button svg {
62
+ width: 18px;
63
+ height: 18px;
64
+ }
65
+
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;
75
+ }
76
+
77
+ .pro6pp-dropdown {
78
+ position: absolute;
79
+ top: 100%;
80
+ left: 0;
81
+ right: 0;
82
+ z-index: 9999;
83
+ 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;
89
+ overflow-y: auto;
90
+ display: flex;
91
+ flex-direction: column;
92
+ }
93
+ .pro6pp-list {
94
+ list-style: none !important;
95
+ padding: 0 !important;
96
+ margin: 0 !important;
97
+ flex-grow: 1;
98
+ }
99
+ .pro6pp-item {
100
+ padding: 12px 16px;
101
+ cursor: pointer;
102
+ display: flex;
103
+ flex-direction: row;
104
+ align-items: center;
105
+ color: #111827;
106
+ font-size: 14px;
107
+ line-height: 1.2;
108
+ white-space: nowrap;
109
+ overflow: hidden;
110
+ }
111
+ .pro6pp-item:hover, .pro6pp-item--active {
112
+ background-color: #f9fafb;
113
+ }
114
+ .pro6pp-item__label {
115
+ font-weight: 500;
116
+ flex-shrink: 0;
117
+ }
118
+ .pro6pp-item__subtitle {
119
+ font-size: 14px;
120
+ color: #6b7280;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ flex-shrink: 1;
124
+ }
125
+ .pro6pp-item__chevron {
126
+ margin-left: auto;
127
+ display: flex;
128
+ align-items: center;
129
+ color: #9ca3af;
130
+ padding-left: 8px;
131
+ }
132
+ .pro6pp-no-results {
133
+ padding: 16px;
134
+ color: #6b7280;
135
+ font-size: 14px;
136
+ text-align: center;
137
+ }
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;
150
+ }
151
+ .pro6pp-load-more:hover {
152
+ background-color: #f3f4f6;
153
+ }
154
+
155
+ @keyframes pro6pp-spin {
156
+ to { transform: rotate(360deg); }
157
+ }
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=`
159
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
160
+ <line x1="18" y1="6" x2="6" y2="18"></line>
161
+ <line x1="6" y1="6" x2="18" y2="18"></line>
162
+ </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=`
164
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
165
+ <polyline points="9 18 15 12 9 6"></polyline>
166
+ </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);})();
@@ -0,0 +1,167 @@
1
+ var I=Object.defineProperty,E=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var S=(p,e,t)=>e in p?I(p,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[e]=t,f=(p,e)=>{for(var t in e||(e={}))T.call(e,t)&&S(p,t,e[t]);if(v)for(var t of v(e))M.call(e,t)&&S(p,t,e[t]);return p},m=(p,e)=>E(p,L(e));var g={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}$/},C={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},b=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,i)=>fetch(r,i)),this.onStateChange=e.onStateChange||(()=>{}),this.onSelect=e.onSelect||(()=>{}),this.state=f({},C);let s=e.debounceMs!==void 0?e.debounceMs:g.DEBOUNCE_MS,n=Math.max(s,g.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(r=>this.executeFetch(r),n)}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 i=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];i&&(this.selectItem(i),this.updateState({selectedSuggestionIndex:-1}));return}}let n=t.value;if(e.key===" "&&this.shouldAutoInsertComma(n)){e.preventDefault();let r=`${n.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 n=typeof e!="string"&&typeof e.value=="object"?e.value:void 0,r=!!n&&Object.keys(n).length>0;if(this.isSelecting=!0,this.state.stage==="final"||r){let u=t;if(n&&Object.keys(n).length>0){let{street:a,street_number:l,house_number:h,city:o}=n,c=l||h;a&&c&&o&&(u=`${a} ${c}, ${o}`)}return this.finishSelection(u,n),!0}let i=typeof e!="string"?e.subtitle:null;return this.processSelection(s,i),!1}shouldAutoInsertComma(e){if(!e.includes(",")&&w.DIGITS_1_3.test(e.trim()))return!0;if(this.state.stage==="house_number"){let s=this.getCurrentFragment(e);return w.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:n}=this.state,r=n;if(t&&(s==="city"||s==="street"||s==="mixed")){if(s==="city")r=`${t}, ${e}, `;else{let l=this.getQueryPrefix(n);r=l?`${l} ${e}, ${t}, `:`${e}, ${t}, `}this.updateQueryAndFetch(r);return}if(s==="direct"||s==="addition"){this.finishSelection(e);return}!n.includes(",")&&(s==="city"||s==="street"||s==="house_number_first")?r=`${e}, `:(r=this.replaceLastSegment(n,e),s!=="house_number"&&(r+=", ")),this.updateQueryAndFetch(r)}executeFetch(e,t=0){var l,h;let s=(e||"").toString();if(!s.trim()){(l=this.abortController)==null||l.abort(),this.resetState();return}t===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let n=(h=this.abortController)==null?void 0:h.signal,r=this.explicitApiUrl?this.explicitApiUrl:`${g.API_URL}/infer/${this.country.toLowerCase()}`,i=new URLSearchParams({country:this.country.toLowerCase(),query:s,limit:this.currentLimit.toString()});this.authKey&&i.set("authKey",this.authKey);let u=r.includes("?")?"&":"?",a=`${r}${u}${i.toString()}`;this.fetcher(a,{signal:n}).then(o=>{if(!o.ok){if(t<this.maxRetries&&(o.status>=500||o.status===429))return this.retry(e,t,n);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,n);this.updateState({isError:!0,isLoading:!1})}})}retry(e,t,s){if(s!=null&&s.aborted)return;let n=Math.pow(2,t)*200;setTimeout(()=>{s!=null&&s.aborted||this.executeFetch(e,t+1)},n)}mapResponseToState(e){var l,h;let t={stage:e.stage,isLoading:!1},s=!1,n=null,r=e.suggestions||[],i=[],u=new Set;for(let o of r){let c=`${o.label}|${o.subtitle||""}|${JSON.stringify(o.value||{})}`;u.has(c)||(u.add(c),i.push(o))}let a=i.length+(((l=e.cities)==null?void 0:l.length)||0)+(((h=e.streets)==null?void 0:h.length)||0);if(t.hasMore=a>=this.currentLimit,e.stage==="mixed")t.cities=e.cities||[],t.streets=e.streets||[],t.suggestions=[];else{t.suggestions=i,t.cities=[],t.streets=[];let o=i[0],c=o&&typeof o.value=="object"&&o.value!==null&&Object.keys(o.value).length>0;(e.stage==="final"||c)&&i.length===1&&(s=!0,n=o)}if(t.isValid=e.stage==="final",s&&n){t.query=n.label,t.suggestions=[],t.cities=[],t.streets=[],t.isValid=!0,t.hasMore=!1,this.isSelecting=!0,this.updateState(t);let o=typeof n.value=="object"?n.value:n.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(m(f({},C),{query:this.state.query}))}updateState(e){this.state=f(f({},this.state),e),this.onStateChange(this.state)}debounce(e,t){let s,n=(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>e.apply(this,r),t)};return n.cancel=()=>{s&&(clearTimeout(s),s=void 0)},n}};var y=`
2
+ .pro6pp-wrapper {
3
+ position: relative;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
+ box-sizing: border-box;
6
+ width: 100%;
7
+ }
8
+ .pro6pp-wrapper * {
9
+ box-sizing: border-box;
10
+ }
11
+ .pro6pp-input {
12
+ width: 100%;
13
+ padding: 10px 12px;
14
+ padding-right: 48px;
15
+ border: 1px solid #e0e0e0;
16
+ border-radius: 4px;
17
+ font-size: 16px;
18
+ line-height: 1.5;
19
+ transition: border-color 0.2s, box-shadow 0.2s;
20
+ }
21
+ .pro6pp-input:focus {
22
+ outline: none;
23
+ border-color: #3b82f6;
24
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
25
+ }
26
+
27
+ .pro6pp-input-addons {
28
+ position: absolute;
29
+ right: 6px;
30
+ top: 0;
31
+ bottom: 0;
32
+ display: flex;
33
+ align-items: center;
34
+ gap: 2px;
35
+ pointer-events: none;
36
+ }
37
+ .pro6pp-input-addons > * {
38
+ pointer-events: auto;
39
+ }
40
+
41
+ .pro6pp-clear-button {
42
+ background: none;
43
+ border: none;
44
+ width: 28px;
45
+ height: 28px;
46
+ cursor: pointer;
47
+ color: #a3a3a3;
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ 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);
60
+ }
61
+ .pro6pp-clear-button svg {
62
+ width: 18px;
63
+ height: 18px;
64
+ }
65
+
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;
75
+ }
76
+
77
+ .pro6pp-dropdown {
78
+ position: absolute;
79
+ top: 100%;
80
+ left: 0;
81
+ right: 0;
82
+ z-index: 9999;
83
+ 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;
89
+ overflow-y: auto;
90
+ display: flex;
91
+ flex-direction: column;
92
+ }
93
+ .pro6pp-list {
94
+ list-style: none !important;
95
+ padding: 0 !important;
96
+ margin: 0 !important;
97
+ flex-grow: 1;
98
+ }
99
+ .pro6pp-item {
100
+ padding: 12px 16px;
101
+ cursor: pointer;
102
+ display: flex;
103
+ flex-direction: row;
104
+ align-items: center;
105
+ color: #111827;
106
+ font-size: 14px;
107
+ line-height: 1.2;
108
+ white-space: nowrap;
109
+ overflow: hidden;
110
+ }
111
+ .pro6pp-item:hover, .pro6pp-item--active {
112
+ background-color: #f9fafb;
113
+ }
114
+ .pro6pp-item__label {
115
+ font-weight: 500;
116
+ flex-shrink: 0;
117
+ }
118
+ .pro6pp-item__subtitle {
119
+ font-size: 14px;
120
+ color: #6b7280;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ flex-shrink: 1;
124
+ }
125
+ .pro6pp-item__chevron {
126
+ margin-left: auto;
127
+ display: flex;
128
+ align-items: center;
129
+ color: #9ca3af;
130
+ padding-left: 8px;
131
+ }
132
+ .pro6pp-no-results {
133
+ padding: 16px;
134
+ color: #6b7280;
135
+ font-size: 14px;
136
+ text-align: center;
137
+ }
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;
150
+ }
151
+ .pro6pp-load-more:hover {
152
+ background-color: #f3f4f6;
153
+ }
154
+
155
+ @keyframes pro6pp-spin {
156
+ to { transform: rotate(360deg); }
157
+ }
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 i=t.inputClass.split(" ");this.input.classList.add(...i)}let n=document.createElement("div");n.className="pro6pp-input-addons",this.wrapper.appendChild(n),this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",n.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=`
159
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
160
+ <line x1="18" y1="6" x2="6" y2="18"></line>
161
+ <line x1="6" y1="6" x2="18" y2="18"></line>
162
+ </svg>
163
+ `,n.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 b(m(f({},t),{onStateChange:i=>this.render(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.bindEvents()}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let t=document.createElement("style");t.id=e,t.textContent=y,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,n=!e.isLoading&&!e.isError&&e.query.length>0&&!s&&!e.isValid;if(!(this.isOpen&&(s||e.isLoading||n))){this.dropdown.style.display="none";return}if(this.dropdown.style.display="flex",this.loadMoreButton.style.display=e.hasMore?"block":"none",e.isLoading&&!s){let i=document.createElement("li");i.className="pro6pp-no-results",this.list.appendChild(i);return}if(n){let i=document.createElement("li");i.className="pro6pp-no-results",i.textContent=this.noResultsText,this.list.appendChild(i);return}t.forEach((i,u)=>{if(!i.label)return;let a=document.createElement("li");a.className="pro6pp-item",u===e.selectedSuggestionIndex&&a.classList.add("pro6pp-item--active"),a.setAttribute("role","option"),a.setAttribute("aria-selected",u===e.selectedSuggestionIndex?"true":"false");let l=document.createElement("span");l.className="pro6pp-item__label",l.textContent=i.label,a.appendChild(l);let h=i.count!==void 0&&i.count!==null?i.count:"",o=i.subtitle||h;if(o!==""){let d=document.createElement("span");d.className="pro6pp-item__subtitle",d.textContent=`, ${o}`,a.appendChild(d)}if(i.value===void 0||i.value===null){let d=document.createElement("div");d.className="pro6pp-item__chevron",d.innerHTML=`
164
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
165
+ <polyline points="9 18 15 12 9 6"></polyline>
166
+ </svg>
167
+ `,a.appendChild(d)}a.onmousedown=d=>d.preventDefault(),a.onclick=d=>{d.stopPropagation(),this.core.selectItem(i)?(this.isOpen=!1,this.dropdown.style.display="none"):setTimeout(()=>this.input.focus(),0)},this.list.appendChild(a)})}};function H(p,e){return new x(p,e)}export{x as InferJS,H as attach};
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "sideEffects": [
19
19
  "*.css"
20
20
  ],
21
- "version": "0.0.2-beta.6",
21
+ "version": "0.0.2-beta.8",
22
22
  "main": "./dist/index.js",
23
23
  "module": "./dist/index.mjs",
24
24
  "types": "./dist/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "test:coverage": "vitest run --coverage"
44
44
  },
45
45
  "dependencies": {
46
- "@pro6pp/infer-core": "0.0.2-beta.6"
46
+ "@pro6pp/infer-core": "0.0.2-beta.8"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@testing-library/dom": "^10.4.1",
@@ -1,103 +0,0 @@
1
- "use strict";var Pro6PP=(()=>{var f=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(p,e)=>{for(var t in e)f(p,t,{get:e[t],enumerable:!0})},E=(p,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of x(e))!I.call(p,i)&&i!==t&&f(p,i,{get:()=>e[i],enumerable:!(n=v(e,i))||n.enumerable});return p};var w=p=>E(f({},"__esModule",{value:!0}),p);var L={};C(L,{InferJS:()=>h,attach:()=>T});var d={API_URL:"https://api.pro6pp.nl/v2",LIMIT:1e3,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50},y={DIGITS_1_3:/^[0-9]{1,3}$/},b={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,selectedSuggestionIndex:-1},c=class{constructor(e){this.abortController=null;this.isSelecting=!1;this.country=e.country,this.authKey=e.authKey,this.apiUrl=e.apiUrl||d.API_URL,this.limit=e.limit||d.LIMIT,this.fetcher=e.fetcher||((i,s)=>fetch(i,s)),this.onStateChange=e.onStateChange||(()=>{}),this.onSelect=e.onSelect||(()=>{}),this.state={...b};let t=e.debounceMs!==void 0?e.debounceMs:d.DEBOUNCE_MS,n=Math.max(t,d.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(i=>this.executeFetch(i),n)}handleInput(e){if(this.isSelecting){this.isSelecting=!1;return}let t=this.state.stage==="final"&&e!==this.state.query;this.updateState({query:e,isValid:!1,isLoading:!!e.trim(),selectedSuggestionIndex:-1}),t&&this.onSelect(null),this.debouncedFetch(e)}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 s=this.state.selectedSuggestionIndex+1;s>=n&&(s=0),this.updateState({selectedSuggestionIndex:s});return}if(e.key==="ArrowUp"){e.preventDefault();let s=this.state.selectedSuggestionIndex-1;s<0&&(s=n-1),this.updateState({selectedSuggestionIndex:s});return}if(e.key==="Enter"&&this.state.selectedSuggestionIndex>=0){e.preventDefault();let l=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];l&&(this.selectItem(l),this.updateState({selectedSuggestionIndex:-1}));return}}let i=t.value;if(e.key===" "&&this.shouldAutoInsertComma(i)){e.preventDefault();let s=`${i.trim()}, `;this.updateQueryAndFetch(s)}}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 i=typeof e!="string"&&typeof e.value=="object"?e.value:void 0,s=!!i&&Object.keys(i).length>0;if(this.isSelecting=!0,this.state.stage==="final"||s){let r=t;if(i&&Object.keys(i).length>0){let{street:o,street_number:u,house_number:m,city:a}=i,S=u||m;o&&S&&a&&(r=`${o} ${S}, ${a}`)}this.finishSelection(r,i);return}let l=typeof e!="string"?e.subtitle:null;this.processSelection(n,l)}shouldAutoInsertComma(e){if(!e.includes(",")&&y.DIGITS_1_3.test(e.trim()))return!0;if(this.state.stage==="house_number"){let n=this.getCurrentFragment(e);return y.DIGITS_1_3.test(n)}return!1}finishSelection(e,t){this.updateState({query:e,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final"}),this.onSelect(t||e),setTimeout(()=>{this.isSelecting=!1},0)}processSelection(e,t){let{stage:n,query:i}=this.state,s=i;if(t&&(n==="city"||n==="street"||n==="mixed")){if(n==="city")s=`${t}, ${e}, `;else{let u=this.getQueryPrefix(i);s=u?`${u} ${e}, ${t}, `:`${e}, ${t}, `}this.updateQueryAndFetch(s);return}if(n==="direct"||n==="addition"){this.finishSelection(e);return}!i.includes(",")&&(n==="city"||n==="street"||n==="house_number_first")?s=`${e}, `:(s=this.replaceLastSegment(i,e),n!=="house_number"&&(s+=", ")),this.updateQueryAndFetch(s)}executeFetch(e){let t=(e||"").toString();if(!t.trim()){this.abortController?.abort(),this.resetState();return}this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController;let n=new URL(`${this.apiUrl}/infer/${this.country.toLowerCase()}`),i={authKey:this.authKey,query:t,limit:this.limit.toString()};n.search=new URLSearchParams(i).toString(),this.fetcher(n.toString(),{signal:this.abortController.signal}).then(s=>{if(!s.ok)throw new Error("Network error");return s.json()}).then(s=>this.mapResponseToState(s)).catch(s=>{s.name!=="AbortError"&&this.updateState({isError:!0,isLoading:!1})})}mapResponseToState(e){let t={stage:e.stage,isLoading:!1},n=!1,i=null,s=e.suggestions||[],l=[],r=new Set;for(let o of s){let u=`${o.label}|${o.subtitle||""}|${JSON.stringify(o.value||{})}`;r.has(u)||(r.add(u),l.push(o))}if(e.stage==="mixed"?(t.cities=e.cities||[],t.streets=e.streets||[],t.suggestions=[]):(t.suggestions=l,t.cities=[],t.streets=[],e.stage==="final"&&l.length===1&&(n=!0,i=l[0])),t.isValid=e.stage==="final",n&&i){t.query=i.label,t.suggestions=[],t.cities=[],t.streets=[],t.isValid=!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}),this.debouncedFetch(e),setTimeout(()=>{this.isSelecting=!1},0)}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){return(e.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...b,query:this.state.query})}updateState(e){this.state={...this.state,...e},this.onStateChange(this.state)}debounce(e,t){let n,i=(...s)=>{n&&clearTimeout(n),n=setTimeout(()=>e.apply(this,s),t)};return i.cancel=()=>{n&&(clearTimeout(n),n=void 0)},i}};var g=`
2
- .pro6pp-wrapper {
3
- position: relative;
4
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
- box-sizing: border-box;
6
- width: 100%;
7
- }
8
- .pro6pp-wrapper * {
9
- box-sizing: border-box;
10
- }
11
- .pro6pp-input {
12
- width: 100%;
13
- padding: 10px 12px;
14
- border: 1px solid #e0e0e0;
15
- border-radius: 4px;
16
- font-size: 16px;
17
- line-height: 1.5;
18
- transition: border-color 0.2s, box-shadow 0.2s;
19
- }
20
- .pro6pp-input:focus {
21
- outline: none;
22
- border-color: #3b82f6;
23
- box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
24
- }
25
- .pro6pp-dropdown {
26
- position: absolute;
27
- top: 100%;
28
- left: 0;
29
- right: 0;
30
- z-index: 9999;
31
- margin-top: 4px;
32
- background: white;
33
- border: 1px solid #e0e0e0;
34
- border-radius: 4px;
35
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
36
- max-height: 300px;
37
- overflow-y: auto;
38
- list-style: none !important;
39
- padding: 0 !important;
40
- margin: 0 !important;
41
- }
42
- .pro6pp-item {
43
- padding: 10px 16px;
44
- cursor: pointer;
45
- display: flex;
46
- flex-direction: row;
47
- align-items: center;
48
- color: #000000;
49
- font-size: 14px;
50
- line-height: 1.2;
51
- white-space: nowrap;
52
- overflow: hidden;
53
- }
54
- .pro6pp-item:hover, .pro6pp-item--active {
55
- background-color: #f5f5f5;
56
- }
57
- .pro6pp-item__label {
58
- font-weight: 500;
59
- flex-shrink: 0;
60
- }
61
- .pro6pp-item__subtitle {
62
- font-size: 14px;
63
- color: #404040;
64
- overflow: hidden;
65
- text-overflow: ellipsis;
66
- flex-shrink: 1;
67
- }
68
- .pro6pp-item__chevron {
69
- margin-left: auto;
70
- display: flex;
71
- align-items: center;
72
- color: #a3a3a3;
73
- padding-left: 8px;
74
- }
75
- .pro6pp-no-results {
76
- padding: 12px;
77
- color: #555555;
78
- font-size: 14px;
79
- text-align: center;
80
- user-select: none;
81
- pointer-events: none;
82
- }
83
- .pro6pp-loader {
84
- position: absolute;
85
- right: 12px;
86
- top: 50%;
87
- transform: translateY(-50%);
88
- width: 16px;
89
- height: 16px;
90
- border: 2px solid #e0e0e0;
91
- border-top-color: #404040;
92
- border-radius: 50%;
93
- animation: pro6pp-spin 0.6s linear infinite;
94
- pointer-events: none;
95
- }
96
- @keyframes pro6pp-spin {
97
- to { transform: translateY(-50%) rotate(360deg); }
98
- }
99
- `;var h=class{constructor(e,t){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.useDefaultStyles=t.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",n instanceof HTMLInputElement?(this.input=n,this.input.parentNode?.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.useDefaultStyles&&this.input.classList.add("pro6pp-input"),t.inputClass){let i=t.inputClass.split(" ");this.input.classList.add(...i)}this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",this.wrapper.appendChild(this.loader),this.list=document.createElement("ul"),this.list.className="pro6pp-dropdown",this.list.style.display="none",this.list.setAttribute("role","listbox"),this.wrapper.appendChild(this.list),this.core=new c({...t,onStateChange:i=>this.render(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.bindEvents()}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let t=document.createElement("style");t.id=e,t.textContent=g,document.head.appendChild(t)}}bindEvents(){this.input.addEventListener("input",e=>{let t=e.target.value;this.core.handleInput(t)}),this.input.addEventListener("keydown",e=>{this.core.handleKeyDown(e)}),document.addEventListener("click",e=>{this.wrapper.contains(e.target)||(this.list.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.list.style.display="block")})}render(e){this.input.value!==e.query&&(this.input.value=e.query),this.loader.style.display=e.isLoading?"block":"none",this.list.innerHTML="";let t=[...e.cities.map(s=>({item:s,type:"city"})),...e.streets.map(s=>({item:s,type:"street"})),...e.suggestions.map(s=>({item:s,type:"suggestion"}))],n=t.length>0,i=!e.isLoading&&!e.isError&&e.query.length>0&&!n&&!e.isValid;if(!n&&!i){this.list.style.display="none";return}if(this.list.style.display="block",i){let s=document.createElement("li");s.className="pro6pp-no-results",s.textContent=this.noResultsText,this.list.appendChild(s);return}t.forEach(({item:s},l)=>{let r=document.createElement("li");r.className="pro6pp-item",l===e.selectedSuggestionIndex&&r.classList.add("pro6pp-item--active"),r.setAttribute("role","option"),r.setAttribute("aria-selected",l===e.selectedSuggestionIndex?"true":"false");let o=document.createElement("span");o.className="pro6pp-item__label",o.textContent=s.label,r.appendChild(o);let u=s.subtitle||s.count;if(u){let a=document.createElement("span");a.className="pro6pp-item__subtitle",a.textContent=`, ${u}`,r.appendChild(a)}if(s.value===void 0||s.value===null){let a=document.createElement("div");a.className="pro6pp-item__chevron",a.innerHTML=`
100
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
101
- <polyline points="9 18 15 12 9 6"></polyline>
102
- </svg>
103
- `,r.appendChild(a)}r.onmousedown=a=>a.preventDefault(),r.onclick=a=>{a.stopPropagation(),this.core.selectItem(s),e.isValid||this.input.focus()},this.list.appendChild(r)})}};function T(p,e){return new h(p,e)}return w(L);})();
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";var u=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var v=(l,e)=>{for(var t in e)u(l,t,{get:e[t],enumerable:!0})},E=(l,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!y.call(l,s)&&s!==t&&u(l,s,{get:()=>e[s],enumerable:!(r=m(e,s))||r.enumerable});return l};var C=l=>E(u({},"__esModule",{value:!0}),l);var w={};v(w,{InferJS:()=>o,attach:()=>g});module.exports=C(w);var a=require("@pro6pp/infer-core"),o=class{constructor(e,t){let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error("InferJS: Target element not found.");if(this.noResultsText=t.noResultsText||"No results found",this.useDefaultStyles=t.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",r instanceof HTMLInputElement?(this.input=r,this.input.parentNode?.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(r.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 s=t.inputClass.split(" ");this.input.classList.add(...s)}this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",this.wrapper.appendChild(this.loader),this.list=document.createElement("ul"),this.list.className="pro6pp-dropdown",this.list.style.display="none",this.list.setAttribute("role","listbox"),this.wrapper.appendChild(this.list),this.core=new a.InferCore({...t,onStateChange:s=>this.render(s),onSelect:s=>{typeof s=="string"?this.input.value=s:s&&typeof s=="object"&&(this.input.value=this.core.state.query),t.onSelect&&t.onSelect(s)}}),this.bindEvents()}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let t=document.createElement("style");t.id=e,t.textContent=a.DEFAULT_STYLES,document.head.appendChild(t)}}bindEvents(){this.input.addEventListener("input",e=>{let t=e.target.value;this.core.handleInput(t)}),this.input.addEventListener("keydown",e=>{this.core.handleKeyDown(e)}),document.addEventListener("click",e=>{this.wrapper.contains(e.target)||(this.list.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.list.style.display="block")})}render(e){this.input.value!==e.query&&(this.input.value=e.query),this.loader.style.display=e.isLoading?"block":"none",this.list.innerHTML="";let t=[...e.cities.map(i=>({item:i,type:"city"})),...e.streets.map(i=>({item:i,type:"street"})),...e.suggestions.map(i=>({item:i,type:"suggestion"}))],r=t.length>0,s=!e.isLoading&&!e.isError&&e.query.length>0&&!r&&!e.isValid;if(!r&&!s){this.list.style.display="none";return}if(this.list.style.display="block",s){let i=document.createElement("li");i.className="pro6pp-no-results",i.textContent=this.noResultsText,this.list.appendChild(i);return}t.forEach(({item:i},h)=>{let p=document.createElement("li");p.className="pro6pp-item",h===e.selectedSuggestionIndex&&p.classList.add("pro6pp-item--active"),p.setAttribute("role","option"),p.setAttribute("aria-selected",h===e.selectedSuggestionIndex?"true":"false");let d=document.createElement("span");d.className="pro6pp-item__label",d.textContent=i.label,p.appendChild(d);let c=i.subtitle||i.count;if(c){let n=document.createElement("span");n.className="pro6pp-item__subtitle",n.textContent=`, ${c}`,p.appendChild(n)}if(i.value===void 0||i.value===null){let n=document.createElement("div");n.className="pro6pp-item__chevron",n.innerHTML=`
2
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
- <polyline points="9 18 15 12 9 6"></polyline>
4
- </svg>
5
- `,p.appendChild(n)}p.onmousedown=n=>n.preventDefault(),p.onclick=n=>{n.stopPropagation(),this.core.selectItem(i),e.isValid||this.input.focus()},this.list.appendChild(p)})}};function g(l,e){return new o(l,e)}0&&(module.exports={InferJS,attach});
package/dist/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- import{InferCore as h,DEFAULT_STYLES as c}from"@pro6pp/infer-core";var o=class{constructor(e,t){let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error("InferJS: Target element not found.");if(this.noResultsText=t.noResultsText||"No results found",this.useDefaultStyles=t.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",r instanceof HTMLInputElement?(this.input=r,this.input.parentNode?.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(r.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 i=t.inputClass.split(" ");this.input.classList.add(...i)}this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",this.wrapper.appendChild(this.loader),this.list=document.createElement("ul"),this.list.className="pro6pp-dropdown",this.list.style.display="none",this.list.setAttribute("role","listbox"),this.wrapper.appendChild(this.list),this.core=new h({...t,onStateChange:i=>this.render(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.bindEvents()}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.input.addEventListener("input",e=>{let t=e.target.value;this.core.handleInput(t)}),this.input.addEventListener("keydown",e=>{this.core.handleKeyDown(e)}),document.addEventListener("click",e=>{this.wrapper.contains(e.target)||(this.list.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.list.style.display="block")})}render(e){this.input.value!==e.query&&(this.input.value=e.query),this.loader.style.display=e.isLoading?"block":"none",this.list.innerHTML="";let t=[...e.cities.map(s=>({item:s,type:"city"})),...e.streets.map(s=>({item:s,type:"street"})),...e.suggestions.map(s=>({item:s,type:"suggestion"}))],r=t.length>0,i=!e.isLoading&&!e.isError&&e.query.length>0&&!r&&!e.isValid;if(!r&&!i){this.list.style.display="none";return}if(this.list.style.display="block",i){let s=document.createElement("li");s.className="pro6pp-no-results",s.textContent=this.noResultsText,this.list.appendChild(s);return}t.forEach(({item:s},d)=>{let l=document.createElement("li");l.className="pro6pp-item",d===e.selectedSuggestionIndex&&l.classList.add("pro6pp-item--active"),l.setAttribute("role","option"),l.setAttribute("aria-selected",d===e.selectedSuggestionIndex?"true":"false");let p=document.createElement("span");p.className="pro6pp-item__label",p.textContent=s.label,l.appendChild(p);let u=s.subtitle||s.count;if(u){let n=document.createElement("span");n.className="pro6pp-item__subtitle",n.textContent=`, ${u}`,l.appendChild(n)}if(s.value===void 0||s.value===null){let n=document.createElement("div");n.className="pro6pp-item__chevron",n.innerHTML=`
2
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
- <polyline points="9 18 15 12 9 6"></polyline>
4
- </svg>
5
- `,l.appendChild(n)}l.onmousedown=n=>n.preventDefault(),l.onclick=n=>{n.stopPropagation(),this.core.selectItem(s),e.isValid||this.input.focus()},this.list.appendChild(l)})}};function E(a,e){return new o(a,e)}export{o as InferJS,E as attach};