@pro6pp/infer-core 0.0.2-beta.10 → 0.0.2-beta.11
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/dist/index.cjs +40 -9
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +41 -10
- package/dist/index.js +41 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(
|
|
1
|
+
"use strict";var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(n,t,e)=>t in n?h(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var w=(n,t)=>{for(var e in t)h(n,e,{get:t[e],enumerable:!0})},T=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of v(t))!I.call(n,r)&&r!==e&&h(n,r,{get:()=>t[r],enumerable:!(i=y(t,r))||i.enumerable});return n};var L=n=>T(h({},"__esModule",{value:!0}),n);var l=(n,t,e)=>C(n,typeof t!="symbol"?t+"":t,e);var F={};w(F,{DEFAULT_STYLES:()=>x,INITIAL_STATE:()=>f,InferCore:()=>m,getHighlightSegments:()=>A});module.exports=L(F);var c={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},b={DIGITS_1_3:/^[0-9]{1,3}$/},f={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},m=class{constructor(t){l(this,"country");l(this,"authKey");l(this,"explicitApiUrl");l(this,"baseLimit");l(this,"currentLimit");l(this,"maxRetries");l(this,"fetcher");l(this,"onStateChange");l(this,"onSelect");l(this,"state");l(this,"abortController",null);l(this,"debouncedFetch");this.country=t.country,this.authKey=t.authKey,this.explicitApiUrl=t.apiUrl,this.baseLimit=t.limit||c.LIMIT,this.currentLimit=this.baseLimit;let e=t.maxRetries!==void 0?t.maxRetries:c.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(e,10)),this.fetcher=t.fetcher||((s,a)=>fetch(s,a)),this.onStateChange=t.onStateChange||(()=>{}),this.onSelect=t.onSelect||(()=>{}),this.state={...f};let i=t.debounceMs!==void 0?t.debounceMs:c.DEBOUNCE_MS,r=Math.max(i,c.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(s=>this.executeFetch(s),r)}handleInput(t){this.currentLimit=this.baseLimit;let e=this.state.stage==="final"&&t!==this.state.query;this.updateState({query:t,isValid:!1,isLoading:!!t.trim(),selectedSuggestionIndex:-1,hasMore:!1}),e&&this.onSelect(null),this.debouncedFetch(t)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(t){let e=t.target;if(!e)return;let i=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(i>0){if(t.key==="ArrowDown"){t.preventDefault();let s=this.state.selectedSuggestionIndex+1;s>=i&&(s=0),this.updateState({selectedSuggestionIndex:s});return}if(t.key==="ArrowUp"){t.preventDefault();let s=this.state.selectedSuggestionIndex-1;s<0&&(s=i-1),this.updateState({selectedSuggestionIndex:s});return}if(t.key==="Enter"&&this.state.selectedSuggestionIndex>=0){t.preventDefault();let a=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];a&&(this.selectItem(a),this.updateState({selectedSuggestionIndex:-1}));return}}let r=e.value;if(t.key===" "&&this.shouldAutoInsertComma(r)){t.preventDefault();let s=`${r.trim()}, `;this.updateQueryAndFetch(s)}}selectItem(t){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let e=typeof t=="string"?t:t.label,i=e;typeof t!="string"&&typeof t.value=="string"&&(i=t.value);let r=typeof t!="string"&&typeof t.value=="object"?t.value:void 0,s=!!r&&Object.keys(r).length>0;if(this.state.stage==="final"||s){let p=e;if(r&&Object.keys(r).length>0){let{street:u,street_number:o,city:d,addition:g}=r;if(u&&o&&d){let S=g?` ${g}`:"";p=`${u} ${o}${S}, ${d}`}}return this.finishSelection(p,r),!0}let a=typeof t!="string"?t.subtitle:null;return this.processSelection(i,a),!1}shouldAutoInsertComma(t){if(!t.includes(",")&&b.DIGITS_1_3.test(t.trim()))return!0;if(this.state.stage==="street_number"){let i=this.getCurrentFragment(t);return b.DIGITS_1_3.test(i)}return!1}finishSelection(t,e){this.updateState({query:t,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final",hasMore:!1}),this.onSelect(e||t)}processSelection(t,e){let{stage:i,query:r}=this.state,s=r;if(e&&(i==="city"||i==="street"||i==="mixed")){if(i==="city")s=`${e}, ${t}, `;else{let o=this.getQueryPrefix(r);!o||!o.includes(e)?s=o?`${o} ${t}, ${e}, `:`${t}, ${e}, `:s=o?`${o} ${t}, `:`${t}, `}this.updateQueryAndFetch(s);return}if(i==="direct"||i==="addition"){this.finishSelection(t);return}!r.includes(",")&&(i==="city"||i==="street"||i==="street_number_first")?s=`${t}, `:(s=this.replaceLastSegment(r,t),i!=="street_number"&&(s+=", ")),this.updateQueryAndFetch(s)}executeFetch(t,e=0){let i=(t||"").toString();if(!i.trim()){this.abortController?.abort(),this.resetState();return}e===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let r=this.abortController?.signal,s=this.explicitApiUrl?this.explicitApiUrl:`${c.API_URL}/infer/${this.country.toLowerCase()}`,a=new URLSearchParams({country:this.country.toLowerCase(),query:i,limit:this.currentLimit.toString()});this.authKey&&a.set("authKey",this.authKey);let p=s.includes("?")?"&":"?",u=`${s}${p}${a.toString()}`;this.fetcher(u,{signal:r}).then(o=>{if(!o.ok){if(e<this.maxRetries&&(o.status>=500||o.status===429))return this.retry(t,e,r);throw new Error("Network error")}return o.json()}).then(o=>{o&&this.mapResponseToState(o)}).catch(o=>{if(o.name!=="AbortError"){if(e<this.maxRetries)return this.retry(t,e,r);this.updateState({isError:!0,isLoading:!1})}})}retry(t,e,i){if(i?.aborted)return;let r=Math.pow(2,e)*200;setTimeout(()=>{i?.aborted||this.executeFetch(t,e+1)},r)}mapResponseToState(t){let e={stage:t.stage,isLoading:!1},i=t.suggestions||[],r=[],s=new Set;for(let p of i){let u=`${p.label}|${p.subtitle||""}|${JSON.stringify(p.value||{})}`;s.has(u)||(s.add(u),r.push(p))}let a=r.length+(t.cities?.length||0)+(t.streets?.length||0);e.hasMore=a>=this.currentLimit,t.stage==="mixed"?(e.cities=t.cities||[],e.streets=t.streets||[],e.suggestions=[]):(e.suggestions=r,e.cities=[],e.streets=[]),e.isValid=t.stage==="final",this.updateState(e),e.isValid&&r.length===1&&this.selectItem(r[0])}updateQueryAndFetch(t){this.updateState({query:t,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(t)}replaceLastSegment(t,e){let i=t.lastIndexOf(",");return i===-1?e:`${t.slice(0,i+1)} ${e}`.trim()}getQueryPrefix(t){let e=t.lastIndexOf(",");return e===-1?"":t.slice(0,e+1).trimEnd()}getCurrentFragment(t){return(t.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...f,query:this.state.query})}updateState(t){this.state={...this.state,...t},this.onStateChange(this.state)}debounce(t,e){let i,r=(...s)=>{i&&clearTimeout(i),i=setTimeout(()=>t.apply(this,s),e)};return r.cancel=()=>{i&&(clearTimeout(i),i=void 0)},r}};function A(n,t){if(!t||!n)return[{text:n,match:!1}];let e=[],i=n.toLowerCase(),r=t.toLowerCase(),s=0,a=0;for(let o=0;o<n.length;o++){if(!(s<t.length&&i[o]===r[s]))continue;o>a&&e.push({text:n.slice(a,o),match:!1}),e.push({text:n[o],match:!0}),s++,a=o+1}return a<n.length&&e.push({text:n.slice(a),match:!1}),s===t.length?e:[{text:n,match:!1}]}var x=`
|
|
2
2
|
.pro6pp-wrapper {
|
|
3
3
|
position: relative;
|
|
4
4
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
appearance: none;
|
|
21
21
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
.pro6pp-input::placeholder {
|
|
25
|
+
font-size: 16px;
|
|
26
|
+
color: #a3a3a3;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
.pro6pp-input:focus {
|
|
24
30
|
outline: none;
|
|
25
31
|
border-color: #3b82f6;
|
|
@@ -42,8 +48,8 @@
|
|
|
42
48
|
.pro6pp-clear-button {
|
|
43
49
|
background: none;
|
|
44
50
|
border: none;
|
|
45
|
-
width:
|
|
46
|
-
height:
|
|
51
|
+
width: 32px;
|
|
52
|
+
height: 32px;
|
|
47
53
|
cursor: pointer;
|
|
48
54
|
color: #a3a3a3;
|
|
49
55
|
display: flex;
|
|
@@ -88,7 +94,7 @@
|
|
|
88
94
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
89
95
|
z-index: 9999;
|
|
90
96
|
padding: 0;
|
|
91
|
-
max-height:
|
|
97
|
+
max-height: 280px;
|
|
92
98
|
overflow-y: auto;
|
|
93
99
|
display: flex;
|
|
94
100
|
flex-direction: column;
|
|
@@ -96,7 +102,7 @@
|
|
|
96
102
|
|
|
97
103
|
@media (max-height: 500px) {
|
|
98
104
|
.pro6pp-dropdown {
|
|
99
|
-
max-height:
|
|
105
|
+
max-height: 180px;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
|
|
@@ -112,7 +118,8 @@
|
|
|
112
118
|
cursor: pointer;
|
|
113
119
|
display: flex;
|
|
114
120
|
align-items: center;
|
|
115
|
-
font-size:
|
|
121
|
+
font-size: 15px;
|
|
122
|
+
line-height: 1.4;
|
|
116
123
|
color: #374151;
|
|
117
124
|
border-bottom: 1px solid #f3f4f6;
|
|
118
125
|
transition: background-color 0.1s;
|
|
@@ -135,18 +142,24 @@
|
|
|
135
142
|
|
|
136
143
|
.pro6pp-item__label {
|
|
137
144
|
font-weight: 500;
|
|
138
|
-
flex-shrink:
|
|
145
|
+
flex-shrink: 1;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
white-space: nowrap;
|
|
139
149
|
}
|
|
150
|
+
|
|
140
151
|
.pro6pp-item__subtitle {
|
|
141
|
-
font-size:
|
|
152
|
+
font-size: 13px;
|
|
142
153
|
color: #6b7280;
|
|
143
|
-
flex-
|
|
154
|
+
flex-shrink: 0;
|
|
144
155
|
}
|
|
156
|
+
|
|
145
157
|
.pro6pp-item__chevron {
|
|
146
158
|
color: #d1d5db;
|
|
147
159
|
display: flex;
|
|
148
160
|
align-items: center;
|
|
149
161
|
margin-left: auto;
|
|
162
|
+
padding-left: 8px;
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
.pro6pp-no-results {
|
|
@@ -170,6 +183,24 @@
|
|
|
170
183
|
touch-action: manipulation;
|
|
171
184
|
}
|
|
172
185
|
|
|
186
|
+
@media (max-width: 640px) {
|
|
187
|
+
.pro6pp-input {
|
|
188
|
+
font-size: 16px;
|
|
189
|
+
padding: 10px 12px;
|
|
190
|
+
}
|
|
191
|
+
.pro6pp-item {
|
|
192
|
+
padding: 10px 12px;
|
|
193
|
+
font-size: 14px;
|
|
194
|
+
}
|
|
195
|
+
.pro6pp-item__subtitle {
|
|
196
|
+
font-size: 12px;
|
|
197
|
+
}
|
|
198
|
+
.pro6pp-load-more {
|
|
199
|
+
padding: 12px;
|
|
200
|
+
font-size: 13px;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
173
204
|
.pro6pp-load-more:active {
|
|
174
205
|
background-color: #f3f4f6;
|
|
175
206
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -221,6 +221,6 @@ declare class InferCore {
|
|
|
221
221
|
*/
|
|
222
222
|
declare function getHighlightSegments(text: string, query: string): HighlightSegment[];
|
|
223
223
|
|
|
224
|
-
declare const DEFAULT_STYLES = "\n .pro6pp-wrapper {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif;\n box-sizing: border-box;\n width: 100%;\n -webkit-tap-highlight-color: transparent;\n }\n .pro6pp-wrapper * {\n box-sizing: border-box;\n }\n .pro6pp-input {\n width: 100%;\n padding: 12px 14px;\n padding-right: 48px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n font-size: 16px;\n line-height: 1.5;\n appearance: none;\n transition: border-color 0.2s, box-shadow 0.2s;\n }\n .pro6pp-input:focus {\n outline: none;\n border-color: #3b82f6;\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n }\n\n .pro6pp-input-addons {\n position: absolute;\n right: 4px;\n top: 0;\n bottom: 0;\n display: flex;\n align-items: center;\n pointer-events: none;\n }\n .pro6pp-input-addons > * {\n pointer-events: auto;\n }\n\n .pro6pp-clear-button {\n background: none;\n border: none;\n width:
|
|
224
|
+
declare const DEFAULT_STYLES = "\n .pro6pp-wrapper {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif;\n box-sizing: border-box;\n width: 100%;\n -webkit-tap-highlight-color: transparent;\n }\n .pro6pp-wrapper * {\n box-sizing: border-box;\n }\n .pro6pp-input {\n width: 100%;\n padding: 12px 14px;\n padding-right: 48px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n font-size: 16px;\n line-height: 1.5;\n appearance: none;\n transition: border-color 0.2s, box-shadow 0.2s;\n }\n\n .pro6pp-input::placeholder {\n font-size: 16px;\n color: #a3a3a3;\n }\n\n .pro6pp-input:focus {\n outline: none;\n border-color: #3b82f6;\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n }\n\n .pro6pp-input-addons {\n position: absolute;\n right: 4px;\n top: 0;\n bottom: 0;\n display: flex;\n align-items: center;\n pointer-events: none;\n }\n .pro6pp-input-addons > * {\n pointer-events: auto;\n }\n\n .pro6pp-clear-button {\n background: none;\n border: none;\n width: 32px;\n height: 32px;\n cursor: pointer;\n color: #a3a3a3;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n transition: color 0.2s, background-color 0.2s;\n touch-action: manipulation;\n }\n\n @media (hover: hover) {\n .pro6pp-clear-button:hover {\n color: #1f2937;\n background-color: #f3f4f6;\n }\n }\n\n .pro6pp-clear-button:active {\n background-color: #f3f4f6;\n }\n\n .pro6pp-loader {\n width: 20px;\n height: 20px;\n margin: 0 8px;\n border: 2px solid #e0e0e0;\n border-top-color: #6b7280;\n border-radius: 50%;\n animation: pro6pp-spin 0.6s linear infinite;\n flex-shrink: 0;\n }\n\n .pro6pp-dropdown {\n position: absolute;\n top: 100%;\n left: 0;\n right: 0;\n margin-top: 4px;\n background: #ffffff;\n border: 1px solid #e5e7eb;\n border-radius: 6px;\n box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);\n z-index: 9999;\n padding: 0;\n max-height: 280px;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n }\n\n @media (max-height: 500px) {\n .pro6pp-dropdown {\n max-height: 180px;\n }\n }\n\n .pro6pp-list {\n list-style: none;\n margin: 0;\n padding: 0;\n width: 100%;\n }\n\n .pro6pp-item {\n padding: 12px 14px;\n cursor: pointer;\n display: flex;\n align-items: center;\n font-size: 15px;\n line-height: 1.4;\n color: #374151;\n border-bottom: 1px solid #f3f4f6;\n transition: background-color 0.1s;\n flex-shrink: 0;\n }\n\n .pro6pp-item:last-child {\n border-bottom: none;\n }\n\n @media (hover: hover) {\n .pro6pp-item:hover, .pro6pp-item--active {\n background-color: #f9fafb;\n }\n }\n\n .pro6pp-item:active {\n background-color: #f3f4f6;\n }\n\n .pro6pp-item__label {\n font-weight: 500;\n flex-shrink: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .pro6pp-item__subtitle {\n font-size: 13px;\n color: #6b7280;\n flex-shrink: 0;\n }\n\n .pro6pp-item__chevron {\n color: #d1d5db;\n display: flex;\n align-items: center;\n margin-left: auto;\n padding-left: 8px;\n }\n\n .pro6pp-no-results {\n padding: 24px 16px;\n color: #6b7280;\n font-size: 15px;\n text-align: center;\n }\n\n .pro6pp-load-more {\n width: 100%;\n padding: 14px;\n background: #f9fafb;\n border: none;\n border-top: 1px solid #e0e0e0;\n color: #3b82f6;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n flex-shrink: 0;\n touch-action: manipulation;\n }\n\n @media (max-width: 640px) {\n .pro6pp-input {\n font-size: 16px;\n padding: 10px 12px;\n }\n .pro6pp-item {\n padding: 10px 12px;\n font-size: 14px;\n }\n .pro6pp-item__subtitle {\n font-size: 12px;\n }\n .pro6pp-load-more {\n padding: 12px;\n font-size: 13px;\n }\n }\n\n .pro6pp-load-more:active {\n background-color: #f3f4f6;\n }\n\n @keyframes pro6pp-spin {\n to { transform: rotate(360deg); }\n }\n";
|
|
225
225
|
|
|
226
226
|
export { type AddressValue, type CountryCode, DEFAULT_STYLES, type Fetcher, type HighlightSegment, INITIAL_STATE, type InferConfig, InferCore, type InferResult, type InferState, type Stage, getHighlightSegments };
|
package/dist/index.d.ts
CHANGED
|
@@ -221,6 +221,6 @@ declare class InferCore {
|
|
|
221
221
|
*/
|
|
222
222
|
declare function getHighlightSegments(text: string, query: string): HighlightSegment[];
|
|
223
223
|
|
|
224
|
-
declare const DEFAULT_STYLES = "\n .pro6pp-wrapper {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif;\n box-sizing: border-box;\n width: 100%;\n -webkit-tap-highlight-color: transparent;\n }\n .pro6pp-wrapper * {\n box-sizing: border-box;\n }\n .pro6pp-input {\n width: 100%;\n padding: 12px 14px;\n padding-right: 48px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n font-size: 16px;\n line-height: 1.5;\n appearance: none;\n transition: border-color 0.2s, box-shadow 0.2s;\n }\n .pro6pp-input:focus {\n outline: none;\n border-color: #3b82f6;\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n }\n\n .pro6pp-input-addons {\n position: absolute;\n right: 4px;\n top: 0;\n bottom: 0;\n display: flex;\n align-items: center;\n pointer-events: none;\n }\n .pro6pp-input-addons > * {\n pointer-events: auto;\n }\n\n .pro6pp-clear-button {\n background: none;\n border: none;\n width:
|
|
224
|
+
declare const DEFAULT_STYLES = "\n .pro6pp-wrapper {\n position: relative;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif;\n box-sizing: border-box;\n width: 100%;\n -webkit-tap-highlight-color: transparent;\n }\n .pro6pp-wrapper * {\n box-sizing: border-box;\n }\n .pro6pp-input {\n width: 100%;\n padding: 12px 14px;\n padding-right: 48px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n font-size: 16px;\n line-height: 1.5;\n appearance: none;\n transition: border-color 0.2s, box-shadow 0.2s;\n }\n\n .pro6pp-input::placeholder {\n font-size: 16px;\n color: #a3a3a3;\n }\n\n .pro6pp-input:focus {\n outline: none;\n border-color: #3b82f6;\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n }\n\n .pro6pp-input-addons {\n position: absolute;\n right: 4px;\n top: 0;\n bottom: 0;\n display: flex;\n align-items: center;\n pointer-events: none;\n }\n .pro6pp-input-addons > * {\n pointer-events: auto;\n }\n\n .pro6pp-clear-button {\n background: none;\n border: none;\n width: 32px;\n height: 32px;\n cursor: pointer;\n color: #a3a3a3;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n transition: color 0.2s, background-color 0.2s;\n touch-action: manipulation;\n }\n\n @media (hover: hover) {\n .pro6pp-clear-button:hover {\n color: #1f2937;\n background-color: #f3f4f6;\n }\n }\n\n .pro6pp-clear-button:active {\n background-color: #f3f4f6;\n }\n\n .pro6pp-loader {\n width: 20px;\n height: 20px;\n margin: 0 8px;\n border: 2px solid #e0e0e0;\n border-top-color: #6b7280;\n border-radius: 50%;\n animation: pro6pp-spin 0.6s linear infinite;\n flex-shrink: 0;\n }\n\n .pro6pp-dropdown {\n position: absolute;\n top: 100%;\n left: 0;\n right: 0;\n margin-top: 4px;\n background: #ffffff;\n border: 1px solid #e5e7eb;\n border-radius: 6px;\n box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);\n z-index: 9999;\n padding: 0;\n max-height: 280px;\n overflow-y: auto;\n display: flex;\n flex-direction: column;\n }\n\n @media (max-height: 500px) {\n .pro6pp-dropdown {\n max-height: 180px;\n }\n }\n\n .pro6pp-list {\n list-style: none;\n margin: 0;\n padding: 0;\n width: 100%;\n }\n\n .pro6pp-item {\n padding: 12px 14px;\n cursor: pointer;\n display: flex;\n align-items: center;\n font-size: 15px;\n line-height: 1.4;\n color: #374151;\n border-bottom: 1px solid #f3f4f6;\n transition: background-color 0.1s;\n flex-shrink: 0;\n }\n\n .pro6pp-item:last-child {\n border-bottom: none;\n }\n\n @media (hover: hover) {\n .pro6pp-item:hover, .pro6pp-item--active {\n background-color: #f9fafb;\n }\n }\n\n .pro6pp-item:active {\n background-color: #f3f4f6;\n }\n\n .pro6pp-item__label {\n font-weight: 500;\n flex-shrink: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .pro6pp-item__subtitle {\n font-size: 13px;\n color: #6b7280;\n flex-shrink: 0;\n }\n\n .pro6pp-item__chevron {\n color: #d1d5db;\n display: flex;\n align-items: center;\n margin-left: auto;\n padding-left: 8px;\n }\n\n .pro6pp-no-results {\n padding: 24px 16px;\n color: #6b7280;\n font-size: 15px;\n text-align: center;\n }\n\n .pro6pp-load-more {\n width: 100%;\n padding: 14px;\n background: #f9fafb;\n border: none;\n border-top: 1px solid #e0e0e0;\n color: #3b82f6;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n flex-shrink: 0;\n touch-action: manipulation;\n }\n\n @media (max-width: 640px) {\n .pro6pp-input {\n font-size: 16px;\n padding: 10px 12px;\n }\n .pro6pp-item {\n padding: 10px 12px;\n font-size: 14px;\n }\n .pro6pp-item__subtitle {\n font-size: 12px;\n }\n .pro6pp-load-more {\n padding: 12px;\n font-size: 13px;\n }\n }\n\n .pro6pp-load-more:active {\n background-color: #f3f4f6;\n }\n\n @keyframes pro6pp-spin {\n to { transform: rotate(360deg); }\n }\n";
|
|
225
225
|
|
|
226
226
|
export { type AddressValue, type CountryCode, DEFAULT_STYLES, type Fetcher, type HighlightSegment, INITIAL_STATE, type InferConfig, InferCore, type InferResult, type InferState, type Stage, getHighlightSegments };
|
package/dist/index.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Pro6PPCore=(()=>{var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(
|
|
1
|
+
"use strict";var Pro6PPCore=(()=>{var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var C=(n,t,e)=>t in n?h(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var w=(n,t)=>{for(var e in t)h(n,e,{get:t[e],enumerable:!0})},T=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of v(t))!I.call(n,r)&&r!==e&&h(n,r,{get:()=>t[r],enumerable:!(i=y(t,r))||i.enumerable});return n};var L=n=>T(h({},"__esModule",{value:!0}),n);var l=(n,t,e)=>C(n,typeof t!="symbol"?t+"":t,e);var F={};w(F,{DEFAULT_STYLES:()=>x,INITIAL_STATE:()=>f,InferCore:()=>m,getHighlightSegments:()=>A});var c={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},b={DIGITS_1_3:/^[0-9]{1,3}$/},f={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},m=class{constructor(t){l(this,"country");l(this,"authKey");l(this,"explicitApiUrl");l(this,"baseLimit");l(this,"currentLimit");l(this,"maxRetries");l(this,"fetcher");l(this,"onStateChange");l(this,"onSelect");l(this,"state");l(this,"abortController",null);l(this,"debouncedFetch");this.country=t.country,this.authKey=t.authKey,this.explicitApiUrl=t.apiUrl,this.baseLimit=t.limit||c.LIMIT,this.currentLimit=this.baseLimit;let e=t.maxRetries!==void 0?t.maxRetries:c.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(e,10)),this.fetcher=t.fetcher||((s,a)=>fetch(s,a)),this.onStateChange=t.onStateChange||(()=>{}),this.onSelect=t.onSelect||(()=>{}),this.state={...f};let i=t.debounceMs!==void 0?t.debounceMs:c.DEBOUNCE_MS,r=Math.max(i,c.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(s=>this.executeFetch(s),r)}handleInput(t){this.currentLimit=this.baseLimit;let e=this.state.stage==="final"&&t!==this.state.query;this.updateState({query:t,isValid:!1,isLoading:!!t.trim(),selectedSuggestionIndex:-1,hasMore:!1}),e&&this.onSelect(null),this.debouncedFetch(t)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(t){let e=t.target;if(!e)return;let i=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(i>0){if(t.key==="ArrowDown"){t.preventDefault();let s=this.state.selectedSuggestionIndex+1;s>=i&&(s=0),this.updateState({selectedSuggestionIndex:s});return}if(t.key==="ArrowUp"){t.preventDefault();let s=this.state.selectedSuggestionIndex-1;s<0&&(s=i-1),this.updateState({selectedSuggestionIndex:s});return}if(t.key==="Enter"&&this.state.selectedSuggestionIndex>=0){t.preventDefault();let a=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];a&&(this.selectItem(a),this.updateState({selectedSuggestionIndex:-1}));return}}let r=e.value;if(t.key===" "&&this.shouldAutoInsertComma(r)){t.preventDefault();let s=`${r.trim()}, `;this.updateQueryAndFetch(s)}}selectItem(t){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let e=typeof t=="string"?t:t.label,i=e;typeof t!="string"&&typeof t.value=="string"&&(i=t.value);let r=typeof t!="string"&&typeof t.value=="object"?t.value:void 0,s=!!r&&Object.keys(r).length>0;if(this.state.stage==="final"||s){let p=e;if(r&&Object.keys(r).length>0){let{street:u,street_number:o,city:d,addition:g}=r;if(u&&o&&d){let S=g?` ${g}`:"";p=`${u} ${o}${S}, ${d}`}}return this.finishSelection(p,r),!0}let a=typeof t!="string"?t.subtitle:null;return this.processSelection(i,a),!1}shouldAutoInsertComma(t){if(!t.includes(",")&&b.DIGITS_1_3.test(t.trim()))return!0;if(this.state.stage==="street_number"){let i=this.getCurrentFragment(t);return b.DIGITS_1_3.test(i)}return!1}finishSelection(t,e){this.updateState({query:t,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final",hasMore:!1}),this.onSelect(e||t)}processSelection(t,e){let{stage:i,query:r}=this.state,s=r;if(e&&(i==="city"||i==="street"||i==="mixed")){if(i==="city")s=`${e}, ${t}, `;else{let o=this.getQueryPrefix(r);!o||!o.includes(e)?s=o?`${o} ${t}, ${e}, `:`${t}, ${e}, `:s=o?`${o} ${t}, `:`${t}, `}this.updateQueryAndFetch(s);return}if(i==="direct"||i==="addition"){this.finishSelection(t);return}!r.includes(",")&&(i==="city"||i==="street"||i==="street_number_first")?s=`${t}, `:(s=this.replaceLastSegment(r,t),i!=="street_number"&&(s+=", ")),this.updateQueryAndFetch(s)}executeFetch(t,e=0){let i=(t||"").toString();if(!i.trim()){this.abortController?.abort(),this.resetState();return}e===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let r=this.abortController?.signal,s=this.explicitApiUrl?this.explicitApiUrl:`${c.API_URL}/infer/${this.country.toLowerCase()}`,a=new URLSearchParams({country:this.country.toLowerCase(),query:i,limit:this.currentLimit.toString()});this.authKey&&a.set("authKey",this.authKey);let p=s.includes("?")?"&":"?",u=`${s}${p}${a.toString()}`;this.fetcher(u,{signal:r}).then(o=>{if(!o.ok){if(e<this.maxRetries&&(o.status>=500||o.status===429))return this.retry(t,e,r);throw new Error("Network error")}return o.json()}).then(o=>{o&&this.mapResponseToState(o)}).catch(o=>{if(o.name!=="AbortError"){if(e<this.maxRetries)return this.retry(t,e,r);this.updateState({isError:!0,isLoading:!1})}})}retry(t,e,i){if(i?.aborted)return;let r=Math.pow(2,e)*200;setTimeout(()=>{i?.aborted||this.executeFetch(t,e+1)},r)}mapResponseToState(t){let e={stage:t.stage,isLoading:!1},i=t.suggestions||[],r=[],s=new Set;for(let p of i){let u=`${p.label}|${p.subtitle||""}|${JSON.stringify(p.value||{})}`;s.has(u)||(s.add(u),r.push(p))}let a=r.length+(t.cities?.length||0)+(t.streets?.length||0);e.hasMore=a>=this.currentLimit,t.stage==="mixed"?(e.cities=t.cities||[],e.streets=t.streets||[],e.suggestions=[]):(e.suggestions=r,e.cities=[],e.streets=[]),e.isValid=t.stage==="final",this.updateState(e),e.isValid&&r.length===1&&this.selectItem(r[0])}updateQueryAndFetch(t){this.updateState({query:t,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(t)}replaceLastSegment(t,e){let i=t.lastIndexOf(",");return i===-1?e:`${t.slice(0,i+1)} ${e}`.trim()}getQueryPrefix(t){let e=t.lastIndexOf(",");return e===-1?"":t.slice(0,e+1).trimEnd()}getCurrentFragment(t){return(t.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...f,query:this.state.query})}updateState(t){this.state={...this.state,...t},this.onStateChange(this.state)}debounce(t,e){let i,r=(...s)=>{i&&clearTimeout(i),i=setTimeout(()=>t.apply(this,s),e)};return r.cancel=()=>{i&&(clearTimeout(i),i=void 0)},r}};function A(n,t){if(!t||!n)return[{text:n,match:!1}];let e=[],i=n.toLowerCase(),r=t.toLowerCase(),s=0,a=0;for(let o=0;o<n.length;o++){if(!(s<t.length&&i[o]===r[s]))continue;o>a&&e.push({text:n.slice(a,o),match:!1}),e.push({text:n[o],match:!0}),s++,a=o+1}return a<n.length&&e.push({text:n.slice(a),match:!1}),s===t.length?e:[{text:n,match:!1}]}var x=`
|
|
2
2
|
.pro6pp-wrapper {
|
|
3
3
|
position: relative;
|
|
4
4
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
appearance: none;
|
|
21
21
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
.pro6pp-input::placeholder {
|
|
25
|
+
font-size: 16px;
|
|
26
|
+
color: #a3a3a3;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
.pro6pp-input:focus {
|
|
24
30
|
outline: none;
|
|
25
31
|
border-color: #3b82f6;
|
|
@@ -42,8 +48,8 @@
|
|
|
42
48
|
.pro6pp-clear-button {
|
|
43
49
|
background: none;
|
|
44
50
|
border: none;
|
|
45
|
-
width:
|
|
46
|
-
height:
|
|
51
|
+
width: 32px;
|
|
52
|
+
height: 32px;
|
|
47
53
|
cursor: pointer;
|
|
48
54
|
color: #a3a3a3;
|
|
49
55
|
display: flex;
|
|
@@ -88,7 +94,7 @@
|
|
|
88
94
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
89
95
|
z-index: 9999;
|
|
90
96
|
padding: 0;
|
|
91
|
-
max-height:
|
|
97
|
+
max-height: 280px;
|
|
92
98
|
overflow-y: auto;
|
|
93
99
|
display: flex;
|
|
94
100
|
flex-direction: column;
|
|
@@ -96,7 +102,7 @@
|
|
|
96
102
|
|
|
97
103
|
@media (max-height: 500px) {
|
|
98
104
|
.pro6pp-dropdown {
|
|
99
|
-
max-height:
|
|
105
|
+
max-height: 180px;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
|
|
@@ -112,7 +118,8 @@
|
|
|
112
118
|
cursor: pointer;
|
|
113
119
|
display: flex;
|
|
114
120
|
align-items: center;
|
|
115
|
-
font-size:
|
|
121
|
+
font-size: 15px;
|
|
122
|
+
line-height: 1.4;
|
|
116
123
|
color: #374151;
|
|
117
124
|
border-bottom: 1px solid #f3f4f6;
|
|
118
125
|
transition: background-color 0.1s;
|
|
@@ -135,18 +142,24 @@
|
|
|
135
142
|
|
|
136
143
|
.pro6pp-item__label {
|
|
137
144
|
font-weight: 500;
|
|
138
|
-
flex-shrink:
|
|
145
|
+
flex-shrink: 1;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
white-space: nowrap;
|
|
139
149
|
}
|
|
150
|
+
|
|
140
151
|
.pro6pp-item__subtitle {
|
|
141
|
-
font-size:
|
|
152
|
+
font-size: 13px;
|
|
142
153
|
color: #6b7280;
|
|
143
|
-
flex-
|
|
154
|
+
flex-shrink: 0;
|
|
144
155
|
}
|
|
156
|
+
|
|
145
157
|
.pro6pp-item__chevron {
|
|
146
158
|
color: #d1d5db;
|
|
147
159
|
display: flex;
|
|
148
160
|
align-items: center;
|
|
149
161
|
margin-left: auto;
|
|
162
|
+
padding-left: 8px;
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
.pro6pp-no-results {
|
|
@@ -170,6 +183,24 @@
|
|
|
170
183
|
touch-action: manipulation;
|
|
171
184
|
}
|
|
172
185
|
|
|
186
|
+
@media (max-width: 640px) {
|
|
187
|
+
.pro6pp-input {
|
|
188
|
+
font-size: 16px;
|
|
189
|
+
padding: 10px 12px;
|
|
190
|
+
}
|
|
191
|
+
.pro6pp-item {
|
|
192
|
+
padding: 10px 12px;
|
|
193
|
+
font-size: 14px;
|
|
194
|
+
}
|
|
195
|
+
.pro6pp-item__subtitle {
|
|
196
|
+
font-size: 12px;
|
|
197
|
+
}
|
|
198
|
+
.pro6pp-load-more {
|
|
199
|
+
padding: 12px;
|
|
200
|
+
font-size: 13px;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
173
204
|
.pro6pp-load-more:active {
|
|
174
205
|
background-color: #f3f4f6;
|
|
175
206
|
}
|
|
@@ -177,4 +208,4 @@
|
|
|
177
208
|
@keyframes pro6pp-spin {
|
|
178
209
|
to { transform: rotate(360deg); }
|
|
179
210
|
}
|
|
180
|
-
`;return
|
|
211
|
+
`;return L(F);})();
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var l=(a,t,e)=>S(a,typeof t!="symbol"?t+"":t,e);var c={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},g={DIGITS_1_3:/^[0-9]{1,3}$/},f={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},m=class{constructor(t){l(this,"country");l(this,"authKey");l(this,"explicitApiUrl");l(this,"baseLimit");l(this,"currentLimit");l(this,"maxRetries");l(this,"fetcher");l(this,"onStateChange");l(this,"onSelect");l(this,"state");l(this,"abortController",null);l(this,"debouncedFetch");this.country=t.country,this.authKey=t.authKey,this.explicitApiUrl=t.apiUrl,this.baseLimit=t.limit||c.LIMIT,this.currentLimit=this.baseLimit;let e=t.maxRetries!==void 0?t.maxRetries:c.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(e,10)),this.fetcher=t.fetcher||((r,
|
|
1
|
+
var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var l=(a,t,e)=>S(a,typeof t!="symbol"?t+"":t,e);var c={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},g={DIGITS_1_3:/^[0-9]{1,3}$/},f={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},m=class{constructor(t){l(this,"country");l(this,"authKey");l(this,"explicitApiUrl");l(this,"baseLimit");l(this,"currentLimit");l(this,"maxRetries");l(this,"fetcher");l(this,"onStateChange");l(this,"onSelect");l(this,"state");l(this,"abortController",null);l(this,"debouncedFetch");this.country=t.country,this.authKey=t.authKey,this.explicitApiUrl=t.apiUrl,this.baseLimit=t.limit||c.LIMIT,this.currentLimit=this.baseLimit;let e=t.maxRetries!==void 0?t.maxRetries:c.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(e,10)),this.fetcher=t.fetcher||((r,n)=>fetch(r,n)),this.onStateChange=t.onStateChange||(()=>{}),this.onSelect=t.onSelect||(()=>{}),this.state={...f};let i=t.debounceMs!==void 0?t.debounceMs:c.DEBOUNCE_MS,s=Math.max(i,c.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(r=>this.executeFetch(r),s)}handleInput(t){this.currentLimit=this.baseLimit;let e=this.state.stage==="final"&&t!==this.state.query;this.updateState({query:t,isValid:!1,isLoading:!!t.trim(),selectedSuggestionIndex:-1,hasMore:!1}),e&&this.onSelect(null),this.debouncedFetch(t)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(t){let e=t.target;if(!e)return;let i=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(i>0){if(t.key==="ArrowDown"){t.preventDefault();let r=this.state.selectedSuggestionIndex+1;r>=i&&(r=0),this.updateState({selectedSuggestionIndex:r});return}if(t.key==="ArrowUp"){t.preventDefault();let r=this.state.selectedSuggestionIndex-1;r<0&&(r=i-1),this.updateState({selectedSuggestionIndex:r});return}if(t.key==="Enter"&&this.state.selectedSuggestionIndex>=0){t.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 s=e.value;if(t.key===" "&&this.shouldAutoInsertComma(s)){t.preventDefault();let r=`${s.trim()}, `;this.updateQueryAndFetch(r)}}selectItem(t){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let e=typeof t=="string"?t:t.label,i=e;typeof t!="string"&&typeof t.value=="string"&&(i=t.value);let s=typeof t!="string"&&typeof t.value=="object"?t.value:void 0,r=!!s&&Object.keys(s).length>0;if(this.state.stage==="final"||r){let p=e;if(s&&Object.keys(s).length>0){let{street:u,street_number:o,city:d,addition:h}=s;if(u&&o&&d){let b=h?` ${h}`:"";p=`${u} ${o}${b}, ${d}`}}return this.finishSelection(p,s),!0}let n=typeof t!="string"?t.subtitle:null;return this.processSelection(i,n),!1}shouldAutoInsertComma(t){if(!t.includes(",")&&g.DIGITS_1_3.test(t.trim()))return!0;if(this.state.stage==="street_number"){let i=this.getCurrentFragment(t);return g.DIGITS_1_3.test(i)}return!1}finishSelection(t,e){this.updateState({query:t,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final",hasMore:!1}),this.onSelect(e||t)}processSelection(t,e){let{stage:i,query:s}=this.state,r=s;if(e&&(i==="city"||i==="street"||i==="mixed")){if(i==="city")r=`${e}, ${t}, `;else{let o=this.getQueryPrefix(s);!o||!o.includes(e)?r=o?`${o} ${t}, ${e}, `:`${t}, ${e}, `:r=o?`${o} ${t}, `:`${t}, `}this.updateQueryAndFetch(r);return}if(i==="direct"||i==="addition"){this.finishSelection(t);return}!s.includes(",")&&(i==="city"||i==="street"||i==="street_number_first")?r=`${t}, `:(r=this.replaceLastSegment(s,t),i!=="street_number"&&(r+=", ")),this.updateQueryAndFetch(r)}executeFetch(t,e=0){let i=(t||"").toString();if(!i.trim()){this.abortController?.abort(),this.resetState();return}e===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let s=this.abortController?.signal,r=this.explicitApiUrl?this.explicitApiUrl:`${c.API_URL}/infer/${this.country.toLowerCase()}`,n=new URLSearchParams({country:this.country.toLowerCase(),query:i,limit:this.currentLimit.toString()});this.authKey&&n.set("authKey",this.authKey);let p=r.includes("?")?"&":"?",u=`${r}${p}${n.toString()}`;this.fetcher(u,{signal:s}).then(o=>{if(!o.ok){if(e<this.maxRetries&&(o.status>=500||o.status===429))return this.retry(t,e,s);throw new Error("Network error")}return o.json()}).then(o=>{o&&this.mapResponseToState(o)}).catch(o=>{if(o.name!=="AbortError"){if(e<this.maxRetries)return this.retry(t,e,s);this.updateState({isError:!0,isLoading:!1})}})}retry(t,e,i){if(i?.aborted)return;let s=Math.pow(2,e)*200;setTimeout(()=>{i?.aborted||this.executeFetch(t,e+1)},s)}mapResponseToState(t){let e={stage:t.stage,isLoading:!1},i=t.suggestions||[],s=[],r=new Set;for(let p of i){let u=`${p.label}|${p.subtitle||""}|${JSON.stringify(p.value||{})}`;r.has(u)||(r.add(u),s.push(p))}let n=s.length+(t.cities?.length||0)+(t.streets?.length||0);e.hasMore=n>=this.currentLimit,t.stage==="mixed"?(e.cities=t.cities||[],e.streets=t.streets||[],e.suggestions=[]):(e.suggestions=s,e.cities=[],e.streets=[]),e.isValid=t.stage==="final",this.updateState(e),e.isValid&&s.length===1&&this.selectItem(s[0])}updateQueryAndFetch(t){this.updateState({query:t,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(t)}replaceLastSegment(t,e){let i=t.lastIndexOf(",");return i===-1?e:`${t.slice(0,i+1)} ${e}`.trim()}getQueryPrefix(t){let e=t.lastIndexOf(",");return e===-1?"":t.slice(0,e+1).trimEnd()}getCurrentFragment(t){return(t.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...f,query:this.state.query})}updateState(t){this.state={...this.state,...t},this.onStateChange(this.state)}debounce(t,e){let i,s=(...r)=>{i&&clearTimeout(i),i=setTimeout(()=>t.apply(this,r),e)};return s.cancel=()=>{i&&(clearTimeout(i),i=void 0)},s}};function w(a,t){if(!t||!a)return[{text:a,match:!1}];let e=[],i=a.toLowerCase(),s=t.toLowerCase(),r=0,n=0;for(let o=0;o<a.length;o++){if(!(r<t.length&&i[o]===s[r]))continue;o>n&&e.push({text:a.slice(n,o),match:!1}),e.push({text:a[o],match:!0}),r++,n=o+1}return n<a.length&&e.push({text:a.slice(n),match:!1}),r===t.length?e:[{text:a,match:!1}]}var y=`
|
|
2
2
|
.pro6pp-wrapper {
|
|
3
3
|
position: relative;
|
|
4
4
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
@@ -20,6 +20,12 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
20
20
|
appearance: none;
|
|
21
21
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
.pro6pp-input::placeholder {
|
|
25
|
+
font-size: 16px;
|
|
26
|
+
color: #a3a3a3;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
.pro6pp-input:focus {
|
|
24
30
|
outline: none;
|
|
25
31
|
border-color: #3b82f6;
|
|
@@ -42,8 +48,8 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
42
48
|
.pro6pp-clear-button {
|
|
43
49
|
background: none;
|
|
44
50
|
border: none;
|
|
45
|
-
width:
|
|
46
|
-
height:
|
|
51
|
+
width: 32px;
|
|
52
|
+
height: 32px;
|
|
47
53
|
cursor: pointer;
|
|
48
54
|
color: #a3a3a3;
|
|
49
55
|
display: flex;
|
|
@@ -88,7 +94,7 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
88
94
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
89
95
|
z-index: 9999;
|
|
90
96
|
padding: 0;
|
|
91
|
-
max-height:
|
|
97
|
+
max-height: 280px;
|
|
92
98
|
overflow-y: auto;
|
|
93
99
|
display: flex;
|
|
94
100
|
flex-direction: column;
|
|
@@ -96,7 +102,7 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
96
102
|
|
|
97
103
|
@media (max-height: 500px) {
|
|
98
104
|
.pro6pp-dropdown {
|
|
99
|
-
max-height:
|
|
105
|
+
max-height: 180px;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
|
|
@@ -112,7 +118,8 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
112
118
|
cursor: pointer;
|
|
113
119
|
display: flex;
|
|
114
120
|
align-items: center;
|
|
115
|
-
font-size:
|
|
121
|
+
font-size: 15px;
|
|
122
|
+
line-height: 1.4;
|
|
116
123
|
color: #374151;
|
|
117
124
|
border-bottom: 1px solid #f3f4f6;
|
|
118
125
|
transition: background-color 0.1s;
|
|
@@ -135,18 +142,24 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
135
142
|
|
|
136
143
|
.pro6pp-item__label {
|
|
137
144
|
font-weight: 500;
|
|
138
|
-
flex-shrink:
|
|
145
|
+
flex-shrink: 1;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
text-overflow: ellipsis;
|
|
148
|
+
white-space: nowrap;
|
|
139
149
|
}
|
|
150
|
+
|
|
140
151
|
.pro6pp-item__subtitle {
|
|
141
|
-
font-size:
|
|
152
|
+
font-size: 13px;
|
|
142
153
|
color: #6b7280;
|
|
143
|
-
flex-
|
|
154
|
+
flex-shrink: 0;
|
|
144
155
|
}
|
|
156
|
+
|
|
145
157
|
.pro6pp-item__chevron {
|
|
146
158
|
color: #d1d5db;
|
|
147
159
|
display: flex;
|
|
148
160
|
align-items: center;
|
|
149
161
|
margin-left: auto;
|
|
162
|
+
padding-left: 8px;
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
.pro6pp-no-results {
|
|
@@ -170,6 +183,24 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
170
183
|
touch-action: manipulation;
|
|
171
184
|
}
|
|
172
185
|
|
|
186
|
+
@media (max-width: 640px) {
|
|
187
|
+
.pro6pp-input {
|
|
188
|
+
font-size: 16px;
|
|
189
|
+
padding: 10px 12px;
|
|
190
|
+
}
|
|
191
|
+
.pro6pp-item {
|
|
192
|
+
padding: 10px 12px;
|
|
193
|
+
font-size: 14px;
|
|
194
|
+
}
|
|
195
|
+
.pro6pp-item__subtitle {
|
|
196
|
+
font-size: 12px;
|
|
197
|
+
}
|
|
198
|
+
.pro6pp-load-more {
|
|
199
|
+
padding: 12px;
|
|
200
|
+
font-size: 13px;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
173
204
|
.pro6pp-load-more:active {
|
|
174
205
|
background-color: #f3f4f6;
|
|
175
206
|
}
|
|
@@ -177,4 +208,4 @@ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configura
|
|
|
177
208
|
@keyframes pro6pp-spin {
|
|
178
209
|
to { transform: rotate(360deg); }
|
|
179
210
|
}
|
|
180
|
-
`;export{y as DEFAULT_STYLES,f as INITIAL_STATE,m as InferCore,
|
|
211
|
+
`;export{y as DEFAULT_STYLES,f as INITIAL_STATE,m as InferCore,w as getHighlightSegments};
|
package/package.json
CHANGED