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

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
@@ -74,20 +74,23 @@ attach(inputElement, {
74
74
 
75
75
  ## API Configuration
76
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. | - |
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
+ | `maxRetries` | Maximum retry attempts for transient network errors. Valid range: `0` to `10`. | `0` |
83
+ | `showClearButton` | If `true`, shows a button to clear the input field. | `true` |
84
+ | `loadMoreText` | The text to display on the pagination button. | `'Show more results...'` |
85
+ | `style` | Styling theme. Use `'none'` to disable default CSS. | `'default'` |
86
+ | `placeholder` | Custom placeholder text for the input field. | - |
87
+ | `inputClass` | Additional CSS classes to add to the input element. | - |
88
+ | `noResultsText` | Text to display when no suggestions are found. | `'No results found'` |
89
+ | `limit` | Maximum number of suggestions to request. | `1000` |
90
+ | `apiUrl` | Base URL for the Pro6PP API. | `'https://api.pro6pp.nl/v2'` |
91
+ | `fetcher` | Custom fetch implementation for requests. | `window.fetch` |
92
+ | `onSelect` | Callback fired when a result is selected. | - |
93
+ | `onStateChange` | Callback fired whenever the internal state updates. | - |
91
94
 
92
95
  ## Styling
93
96
 
package/dist/index.d.mts CHANGED
@@ -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,15 @@ 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;
40
55
  /**
41
56
  * Initializes the Infer logic on a target element.
42
57
  * @param target Either a CSS selector string or a direct HTMLElement.
package/dist/index.d.ts CHANGED
@@ -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,15 @@ 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;
40
55
  /**
41
56
  * Initializes the Infer logic on a target element.
42
57
  * @param target Either a CSS selector string or a direct HTMLElement.
@@ -1,4 +1,4 @@
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=`
1
+ "use strict";var Pro6PP=(()=>{var m=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var C=(p,e)=>{for(var t in e)m(p,t,{get:e[t],enumerable:!0})},I=(p,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!w.call(p,n)&&n!==t&&m(p,n,{get:()=>e[n],enumerable:!(s=v(e,n))||s.enumerable});return p};var E=p=>I(m({},"__esModule",{value:!0}),p);var L={};C(L,{InferJS:()=>f,attach:()=>T});var h={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},y={DIGITS_1_3:/^[0-9]{1,3}$/},x={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!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||h.API_URL,this.baseLimit=e.limit||h.LIMIT,this.currentLimit=this.baseLimit;let t=e.maxRetries!==void 0?e.maxRetries:h.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(t,10)),this.fetcher=e.fetcher||((i,o)=>fetch(i,o)),this.onStateChange=e.onStateChange||(()=>{}),this.onSelect=e.onSelect||(()=>{}),this.state={...x};let s=e.debounceMs!==void 0?e.debounceMs:h.DEBOUNCE_MS,n=Math.max(s,h.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(i=>this.executeFetch(i),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 i=this.state.selectedSuggestionIndex+1;i>=s&&(i=0),this.updateState({selectedSuggestionIndex:i});return}if(e.key==="ArrowUp"){e.preventDefault();let i=this.state.selectedSuggestionIndex-1;i<0&&(i=s-1),this.updateState({selectedSuggestionIndex:i});return}if(e.key==="Enter"&&this.state.selectedSuggestionIndex>=0){e.preventDefault();let o=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];o&&(this.selectItem(o),this.updateState({selectedSuggestionIndex:-1}));return}}let n=t.value;if(e.key===" "&&this.shouldAutoInsertComma(n)){e.preventDefault();let i=`${n.trim()}, `;this.updateQueryAndFetch(i)}}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,i=!!n&&Object.keys(n).length>0;if(this.isSelecting=!0,this.state.stage==="final"||i){let r=t;if(n&&Object.keys(n).length>0){let{street:u,street_number:l,house_number:d,city:g}=n,a=l||d;u&&a&&g&&(r=`${u} ${a}, ${g}`)}this.finishSelection(r,n);return}let o=typeof e!="string"?e.subtitle:null;this.processSelection(s,o)}shouldAutoInsertComma(e){if(!e.includes(",")&&y.DIGITS_1_3.test(e.trim()))return!0;if(this.state.stage==="house_number"){let s=this.getCurrentFragment(e);return y.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),setTimeout(()=>{this.isSelecting=!1},0)}processSelection(e,t){let{stage:s,query:n}=this.state,i=n;if(t&&(s==="city"||s==="street"||s==="mixed")){if(s==="city")i=`${t}, ${e}, `;else{let l=this.getQueryPrefix(n);i=l?`${l} ${e}, ${t}, `:`${e}, ${t}, `}this.updateQueryAndFetch(i);return}if(s==="direct"||s==="addition"){this.finishSelection(e);return}!n.includes(",")&&(s==="city"||s==="street"||s==="house_number_first")?i=`${e}, `:(i=this.replaceLastSegment(n,e),s!=="house_number"&&(i+=", ")),this.updateQueryAndFetch(i)}executeFetch(e,t=0){let s=(e||"").toString();if(!s.trim()){this.abortController?.abort(),this.resetState();return}t===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let n=this.abortController?.signal,i=new URL(`${this.apiUrl}/infer/${this.country.toLowerCase()}`),o={authKey:this.authKey,query:s,limit:this.currentLimit.toString()};i.search=new URLSearchParams(o).toString(),this.fetcher(i.toString(),{signal:n}).then(r=>{if(!r.ok){if(t<this.maxRetries&&(r.status>=500||r.status===429))return this.retry(e,t,n);throw new Error("Network error")}return r.json()}).then(r=>{r&&this.mapResponseToState(r)}).catch(r=>{if(r.name!=="AbortError"){if(t<this.maxRetries)return this.retry(e,t,n);this.updateState({isError:!0,isLoading:!1})}})}retry(e,t,s){if(s?.aborted)return;let n=Math.pow(2,t)*200;setTimeout(()=>{s?.aborted||this.executeFetch(e,t+1)},n)}mapResponseToState(e){let t={stage:e.stage,isLoading:!1},s=!1,n=null,i=e.suggestions||[],o=[],r=new Set;for(let l of i){let d=`${l.label}|${l.subtitle||""}|${JSON.stringify(l.value||{})}`;r.has(d)||(r.add(d),o.push(l))}let u=o.length+(e.cities?.length||0)+(e.streets?.length||0);if(t.hasMore=u>=this.currentLimit,e.stage==="mixed"?(t.cities=e.cities||[],t.streets=e.streets||[],t.suggestions=[]):(t.suggestions=o,t.cities=[],t.streets=[],e.stage==="final"&&o.length===1&&(s=!0,n=o[0])),t.isValid=e.stage==="final",s&&n){t.query=n.label,t.suggestions=[],t.cities=[],t.streets=[],t.isValid=!0,t.hasMore=!1,this.updateState(t);let l=typeof n.value=="object"?n.value:n.label;this.onSelect(l)}else this.updateState(t)}updateQueryAndFetch(e){this.updateState({query:e,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(e),setTimeout(()=>{this.isSelecting=!1},0)}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){return(e.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...x,query:this.state.query})}updateState(e){this.state={...this.state,...e},this.onStateChange(this.state)}debounce(e,t){let s,n=(...i)=>{s&&clearTimeout(s),s=setTimeout(()=>e.apply(this,i),t)};return n.cancel=()=>{s&&(clearTimeout(s),s=void 0)},n}};var b=`
2
2
  .pro6pp-wrapper {
3
3
  position: relative;
4
4
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
@@ -11,6 +11,7 @@
11
11
  .pro6pp-input {
12
12
  width: 100%;
13
13
  padding: 10px 12px;
14
+ padding-right: 48px;
14
15
  border: 1px solid #e0e0e0;
15
16
  border-radius: 4px;
16
17
  font-size: 16px;
@@ -22,6 +23,57 @@
22
23
  border-color: #3b82f6;
23
24
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
24
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
+
25
77
  .pro6pp-dropdown {
26
78
  position: absolute;
27
79
  top: 100%;
@@ -32,27 +84,32 @@
32
84
  background: white;
33
85
  border: 1px solid #e0e0e0;
34
86
  border-radius: 4px;
35
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
87
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
36
88
  max-height: 300px;
37
89
  overflow-y: auto;
90
+ display: flex;
91
+ flex-direction: column;
92
+ }
93
+ .pro6pp-list {
38
94
  list-style: none !important;
39
95
  padding: 0 !important;
40
96
  margin: 0 !important;
97
+ flex-grow: 1;
41
98
  }
42
99
  .pro6pp-item {
43
- padding: 10px 16px;
100
+ padding: 12px 16px;
44
101
  cursor: pointer;
45
102
  display: flex;
46
103
  flex-direction: row;
47
104
  align-items: center;
48
- color: #000000;
105
+ color: #111827;
49
106
  font-size: 14px;
50
107
  line-height: 1.2;
51
108
  white-space: nowrap;
52
109
  overflow: hidden;
53
110
  }
54
111
  .pro6pp-item:hover, .pro6pp-item--active {
55
- background-color: #f5f5f5;
112
+ background-color: #f9fafb;
56
113
  }
57
114
  .pro6pp-item__label {
58
115
  font-weight: 500;
@@ -60,7 +117,7 @@
60
117
  }
61
118
  .pro6pp-item__subtitle {
62
119
  font-size: 14px;
63
- color: #404040;
120
+ color: #6b7280;
64
121
  overflow: hidden;
65
122
  text-overflow: ellipsis;
66
123
  flex-shrink: 1;
@@ -69,35 +126,42 @@
69
126
  margin-left: auto;
70
127
  display: flex;
71
128
  align-items: center;
72
- color: #a3a3a3;
129
+ color: #9ca3af;
73
130
  padding-left: 8px;
74
131
  }
75
132
  .pro6pp-no-results {
76
- padding: 12px;
77
- color: #555555;
133
+ padding: 16px;
134
+ color: #6b7280;
78
135
  font-size: 14px;
79
136
  text-align: center;
80
- user-select: none;
81
- pointer-events: none;
82
137
  }
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;
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;
95
153
  }
154
+
96
155
  @keyframes pro6pp-spin {
97
- to { transform: translateY(-50%) rotate(360deg); }
156
+ to { transform: rotate(360deg); }
98
157
  }
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=`
158
+ `;var f=class{constructor(e,t){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,this.input.parentNode?.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 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=b,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)}),this.clearButton.addEventListener("click",()=>{this.core.handleInput(""),this.input.focus()}),this.loadMoreButton.addEventListener("click",e=>{e.preventDefault(),this.core.loadMore()}),document.addEventListener("click",e=>{this.wrapper.contains(e.target)||(this.dropdown.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.dropdown.style.display="flex")})}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(!s&&!n){this.dropdown.style.display="none";return}if(this.dropdown.style.display="flex",this.loadMoreButton.style.display=e.hasMore?"block":"none",n){let i=document.createElement("li");i.className="pro6pp-no-results",i.textContent=this.noResultsText,this.list.appendChild(i);return}t.forEach((i,o)=>{if(!i.label)return;let r=document.createElement("li");r.className="pro6pp-item",o===e.selectedSuggestionIndex&&r.classList.add("pro6pp-item--active"),r.setAttribute("role","option"),r.setAttribute("aria-selected",o===e.selectedSuggestionIndex?"true":"false");let u=document.createElement("span");u.className="pro6pp-item__label",u.textContent=i.label,r.appendChild(u);let l=i.count!==void 0&&i.count!==null?i.count:"",d=i.subtitle||l;if(d!==""){let a=document.createElement("span");a.className="pro6pp-item__subtitle",a.textContent=`, ${d}`,r.appendChild(a)}if(i.value===void 0||i.value===null){let a=document.createElement("div");a.className="pro6pp-item__chevron",a.innerHTML=`
100
164
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
101
165
  <polyline points="9 18 15 12 9 6"></polyline>
102
166
  </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);})();
167
+ `,r.appendChild(a)}r.onmousedown=a=>a.preventDefault(),r.onclick=a=>{a.stopPropagation(),this.core.selectItem(i),e.isValid||this.input.focus()},this.list.appendChild(r)})}};function T(p,e){return new f(p,e)}return E(L);})();
package/dist/index.js CHANGED
@@ -1,5 +1,10 @@
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=`
1
+ "use strict";var u=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)u(i,t,{get:e[t],enumerable:!0})},C=(i,e,t,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of f(e))!v.call(i,s)&&s!==t&&u(i,s,{get:()=>e[s],enumerable:!(l=y(e,s))||l.enumerable});return i};var E=i=>C(u({},"__esModule",{value:!0}),i);var B={};w(B,{InferJS:()=>a,attach:()=>x});module.exports=E(B);var p=require("@pro6pp/infer-core"),a=class{constructor(e,t){let l=typeof e=="string"?document.querySelector(e):e;if(!l)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",l instanceof HTMLInputElement?(this.input=l,this.input.parentNode?.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(l.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 s=document.createElement("div");s.className="pro6pp-input-addons",this.wrapper.appendChild(s),this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",s.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=`
2
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
+ <line x1="18" y1="6" x2="6" y2="18"></line>
4
+ <line x1="6" y1="6" x2="18" y2="18"></line>
5
+ </svg>
6
+ `,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.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 p.InferCore({...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=p.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)}),this.clearButton.addEventListener("click",()=>{this.core.handleInput(""),this.input.focus()}),this.loadMoreButton.addEventListener("click",e=>{e.preventDefault(),this.core.loadMore()}),document.addEventListener("click",e=>{this.wrapper.contains(e.target)||(this.dropdown.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.dropdown.style.display="flex")})}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],l=t.length>0,s=!e.isLoading&&!e.isError&&e.query.length>0&&!l&&!e.isValid;if(!l&&!s){this.dropdown.style.display="none";return}if(this.dropdown.style.display="flex",this.loadMoreButton.style.display=e.hasMore?"block":"none",s){let n=document.createElement("li");n.className="pro6pp-no-results",n.textContent=this.noResultsText,this.list.appendChild(n);return}t.forEach((n,h)=>{if(!n.label)return;let r=document.createElement("li");r.className="pro6pp-item",h===e.selectedSuggestionIndex&&r.classList.add("pro6pp-item--active"),r.setAttribute("role","option"),r.setAttribute("aria-selected",h===e.selectedSuggestionIndex?"true":"false");let d=document.createElement("span");d.className="pro6pp-item__label",d.textContent=n.label,r.appendChild(d);let m=n.count!==void 0&&n.count!==null?n.count:"",c=n.subtitle||m;if(c!==""){let o=document.createElement("span");o.className="pro6pp-item__subtitle",o.textContent=`, ${c}`,r.appendChild(o)}if(n.value===void 0||n.value===null){let o=document.createElement("div");o.className="pro6pp-item__chevron",o.innerHTML=`
2
7
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
8
  <polyline points="9 18 15 12 9 6"></polyline>
4
9
  </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});
10
+ `,r.appendChild(o)}r.onmousedown=o=>o.preventDefault(),r.onclick=o=>{o.stopPropagation(),this.core.selectItem(n),e.isValid||this.input.focus()},this.list.appendChild(r)})}};function x(i,e){return new a(i,e)}0&&(module.exports={InferJS,attach});
package/dist/index.mjs CHANGED
@@ -1,5 +1,10 @@
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=`
1
+ import{InferCore as c,DEFAULT_STYLES as m}from"@pro6pp/infer-core";var a=class{constructor(e,n){let i=typeof e=="string"?document.querySelector(e):e;if(!i)throw new Error("InferJS: Target element not found.");if(this.noResultsText=n.noResultsText||"No results found",this.loadMoreText=n.loadMoreText||"Show more results...",this.showClearButton=n.showClearButton!==!1,this.useDefaultStyles=n.style!=="none",this.useDefaultStyles&&this.injectStyles(),this.wrapper=document.createElement("div"),this.wrapper.className="pro6pp-wrapper",i instanceof HTMLInputElement?(this.input=i,this.input.parentNode?.insertBefore(this.wrapper,this.input),this.wrapper.appendChild(this.input)):(i.appendChild(this.wrapper),this.input=document.createElement("input"),this.input.type="text",n.placeholder&&(this.input.placeholder=n.placeholder),this.wrapper.appendChild(this.input)),this.useDefaultStyles&&this.input.classList.add("pro6pp-input"),n.inputClass){let t=n.inputClass.split(" ");this.input.classList.add(...t)}let l=document.createElement("div");l.className="pro6pp-input-addons",this.wrapper.appendChild(l),this.loader=document.createElement("div"),this.loader.className="pro6pp-loader",this.loader.style.display="none",l.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=`
2
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
+ <line x1="18" y1="6" x2="6" y2="18"></line>
4
+ <line x1="6" y1="6" x2="18" y2="18"></line>
5
+ </svg>
6
+ `,l.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 c({...n,onStateChange:t=>this.render(t),onSelect:t=>{typeof t=="string"?this.input.value=t:t&&typeof t=="object"&&(this.input.value=this.core.state.query),n.onSelect&&n.onSelect(t)}}),this.bindEvents()}injectStyles(){let e="pro6pp-styles";if(!document.getElementById(e)){let n=document.createElement("style");n.id=e,n.textContent=m,document.head.appendChild(n)}}bindEvents(){this.input.addEventListener("input",e=>{let n=e.target.value;this.core.handleInput(n)}),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("click",e=>{this.wrapper.contains(e.target)||(this.dropdown.style.display="none")}),this.input.addEventListener("focus",()=>{this.list.children.length>0&&(this.dropdown.style.display="flex")})}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 n=[...e.cities,...e.streets,...e.suggestions],i=n.length>0,l=!e.isLoading&&!e.isError&&e.query.length>0&&!i&&!e.isValid;if(!i&&!l){this.dropdown.style.display="none";return}if(this.dropdown.style.display="flex",this.loadMoreButton.style.display=e.hasMore?"block":"none",l){let t=document.createElement("li");t.className="pro6pp-no-results",t.textContent=this.noResultsText,this.list.appendChild(t);return}n.forEach((t,d)=>{if(!t.label)return;let o=document.createElement("li");o.className="pro6pp-item",d===e.selectedSuggestionIndex&&o.classList.add("pro6pp-item--active"),o.setAttribute("role","option"),o.setAttribute("aria-selected",d===e.selectedSuggestionIndex?"true":"false");let r=document.createElement("span");r.className="pro6pp-item__label",r.textContent=t.label,o.appendChild(r);let h=t.count!==void 0&&t.count!==null?t.count:"",u=t.subtitle||h;if(u!==""){let s=document.createElement("span");s.className="pro6pp-item__subtitle",s.textContent=`, ${u}`,o.appendChild(s)}if(t.value===void 0||t.value===null){let s=document.createElement("div");s.className="pro6pp-item__chevron",s.innerHTML=`
2
7
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3
8
  <polyline points="9 18 15 12 9 6"></polyline>
4
9
  </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};
10
+ `,o.appendChild(s)}o.onmousedown=s=>s.preventDefault(),o.onclick=s=>{s.stopPropagation(),this.core.selectItem(t),e.isValid||this.input.focus()},this.list.appendChild(o)})}};function C(p,e){return new a(p,e)}export{a as InferJS,C 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.7",
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.7"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@testing-library/dom": "^10.4.1",