@quantaroute/checkout 1.3.0 → 1.3.1

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/src/core/types.ts CHANGED
@@ -83,29 +83,6 @@ export interface CompleteAddress {
83
83
  formattedAddress: string;
84
84
  }
85
85
 
86
- // ─── Map Style ───────────────────────────────────────────────────────────────
87
-
88
- /**
89
- * Built-in basemap style presets.
90
- *
91
- * | Preset | Provider | Character |
92
- * |--------------------------|---------------|----------------------------------|
93
- * | `'carto-positron'` | Carto | Clean, minimal, light (default) |
94
- * | `'openfreemap-liberty'` | OpenFreeMap | Colorful OSM-flavored |
95
- * | `'openfreemap-positron'` | OpenFreeMap | Clean light, open-source |
96
- * | `'openfreemap-bright'` | OpenFreeMap | Vibrant, high contrast |
97
- *
98
- * You can also pass any MapLibre-compatible style URL string directly.
99
- *
100
- * OpenFreeMap is free and open-source with no API key or rate limits.
101
- * See https://openfreemap.org
102
- */
103
- export type BuiltInMapStyle =
104
- | 'carto-positron'
105
- | 'openfreemap-liberty'
106
- | 'openfreemap-positron'
107
- | 'openfreemap-bright';
108
-
109
86
  // ─── Component Props ─────────────────────────────────────────────────────────
110
87
 
111
88
  export interface MapPinSelectorProps {
@@ -115,13 +92,6 @@ export interface MapPinSelectorProps {
115
92
  /** Map height. String on web ('380px'), number on native (380). */
116
93
  mapHeight?: string | number;
117
94
  theme?: 'light' | 'dark';
118
- /**
119
- * Basemap style. Pass a preset name or any MapLibre-compatible style URL.
120
- * Defaults to `'carto-positron'`.
121
- * @example mapStyle="openfreemap-liberty"
122
- * @example mapStyle="https://my-server.com/style.json"
123
- */
124
- mapStyle?: BuiltInMapStyle | string;
125
95
  /**
126
96
  * URL to an India boundary GeoJSON file (FeatureCollection).
127
97
  * When provided, a thin grey outline of India's border is drawn on the map
@@ -130,6 +100,18 @@ export interface MapPinSelectorProps {
130
100
  * Example: indiaBoundaryUrl="/geojson/india.geojson"
131
101
  */
132
102
  indiaBoundaryUrl?: string;
103
+ /**
104
+ * Show the search bar above the map (default: true).
105
+ * Supports two modes automatically:
106
+ * – Address search → calls /v1/digipin/autocomplete (debounced 400ms)
107
+ * – DigiPin input → decoded offline, zero API call, instant flyTo
108
+ * Pass apiKey to enable address search. DigiPin search always works offline.
109
+ */
110
+ enableSearch?: boolean;
111
+ /** Required when enableSearch is true — used to call the autocomplete API. */
112
+ apiKey?: string;
113
+ /** API base URL for autocomplete. Defaults to https://api.quantaroute.com */
114
+ apiBaseUrl?: string;
133
115
  }
134
116
 
135
117
  export interface AddressFormProps {
@@ -170,13 +152,6 @@ export interface CheckoutWidgetProps {
170
152
  mapHeight?: string | number;
171
153
  /** Widget header title. Defaults to 'Add Delivery Address'. */
172
154
  title?: string;
173
- /**
174
- * Basemap style. Pass a preset name or any MapLibre-compatible style URL.
175
- * Defaults to `'carto-positron'`.
176
- * @example mapStyle="openfreemap-liberty"
177
- * @example mapStyle="https://my-server.com/style.json"
178
- */
179
- mapStyle?: BuiltInMapStyle | string;
180
155
  /**
181
156
  * URL to an India boundary GeoJSON file (FeatureCollection).
182
157
  * When provided, a thin grey outline is drawn on the map for legal compliance.
@@ -184,4 +159,11 @@ export interface CheckoutWidgetProps {
184
159
  * Example: indiaBoundaryUrl="/geojson/india.geojson"
185
160
  */
186
161
  indiaBoundaryUrl?: string;
162
+ /**
163
+ * Show the smart search bar on the map step (default: true).
164
+ * Supports address search (API) and DigiPin lookup (100% offline).
165
+ * As India Post promotes DigiPin, buyers can just type their 10-char code
166
+ * and the map instantly flies to their ~4m × 4m location — zero API cost.
167
+ */
168
+ enableSearch?: boolean;
187
169
  }
package/src/index.ts CHANGED
@@ -39,8 +39,13 @@ export {
39
39
  } from './core/digipin';
40
40
 
41
41
  // ── API client ────────────────────────────────────────────────────────────────
42
- export { lookupLocation, reverseGeocode } from './core/api';
43
- export type { AddressComponents, ReverseGeocodeResponse } from './core/api';
42
+ export { lookupLocation, reverseGeocode, autocompleteAddress, looksLikeDigiPin } from './core/api';
43
+ export type {
44
+ AddressComponents,
45
+ ReverseGeocodeResponse,
46
+ AutocompleteSuggestion,
47
+ AutocompleteResponse,
48
+ } from './core/api';
44
49
 
45
50
  // ── Hooks ─────────────────────────────────────────────────────────────────────
46
51
  export { useGeolocation } from './hooks/useGeolocation';
@@ -188,6 +188,181 @@
188
188
  height: 16px;
189
189
  }
190
190
 
191
+ /* ── Search bar ──────────────────────────────────────────── */
192
+ .qr-search-bar {
193
+ padding: 10px 12px 6px;
194
+ background: var(--qr-bg);
195
+ border-bottom: 1px solid var(--qr-border);
196
+ position: relative;
197
+ z-index: 30;
198
+ }
199
+
200
+ .qr-search-bar__input-wrap {
201
+ display: flex;
202
+ align-items: center;
203
+ gap: 8px;
204
+ background: var(--qr-bg-subtle);
205
+ border: 1.5px solid var(--qr-border);
206
+ border-radius: var(--qr-radius-sm);
207
+ padding: 0 10px;
208
+ transition: border-color var(--qr-transition), box-shadow var(--qr-transition);
209
+ }
210
+
211
+ .qr-search-bar__input-wrap:focus-within {
212
+ border-color: var(--qr-primary);
213
+ box-shadow: 0 0 0 3px rgba(14,165,233,.12);
214
+ background: var(--qr-bg);
215
+ }
216
+
217
+ .qr-search-bar__icon {
218
+ width: 15px;
219
+ height: 15px;
220
+ color: var(--qr-text-muted);
221
+ flex-shrink: 0;
222
+ }
223
+
224
+ .qr-search-bar__input {
225
+ flex: 1;
226
+ border: none;
227
+ outline: none;
228
+ background: transparent;
229
+ font-family: var(--qr-font);
230
+ font-size: 13px;
231
+ color: var(--qr-text);
232
+ padding: 9px 0;
233
+ /* Remove browser default search-input clear button */
234
+ -webkit-appearance: none;
235
+ appearance: none;
236
+ }
237
+
238
+ .qr-search-bar__input::placeholder {
239
+ color: var(--qr-text-faint);
240
+ }
241
+
242
+ /* Remove native × on search type */
243
+ .qr-search-bar__input::-webkit-search-decoration,
244
+ .qr-search-bar__input::-webkit-search-cancel-button {
245
+ -webkit-appearance: none;
246
+ }
247
+
248
+ .qr-search-bar__spinner {
249
+ flex-shrink: 0;
250
+ border-color: rgba(14,165,233,.25);
251
+ border-top-color: var(--qr-primary);
252
+ }
253
+
254
+ .qr-search-bar__clear {
255
+ flex-shrink: 0;
256
+ background: none;
257
+ border: none;
258
+ cursor: pointer;
259
+ color: var(--qr-text-faint);
260
+ font-size: 18px;
261
+ line-height: 1;
262
+ padding: 0 2px;
263
+ opacity: 0.7;
264
+ transition: opacity var(--qr-transition);
265
+ }
266
+
267
+ .qr-search-bar__clear:hover {
268
+ opacity: 1;
269
+ }
270
+
271
+ /* Error message under input */
272
+ .qr-search-bar__error {
273
+ margin: 4px 2px 0;
274
+ font-size: 11px;
275
+ color: var(--qr-error);
276
+ }
277
+
278
+ /* ── Dropdown ────────────────────────────────────────────── */
279
+ .qr-search-bar__dropdown {
280
+ position: absolute;
281
+ top: calc(100% - 6px);
282
+ left: 12px;
283
+ right: 12px;
284
+ background: var(--qr-bg);
285
+ border: 1.5px solid var(--qr-border);
286
+ border-top: none;
287
+ border-radius: 0 0 var(--qr-radius-sm) var(--qr-radius-sm);
288
+ box-shadow: 0 8px 24px rgba(0,0,0,.12);
289
+ list-style: none;
290
+ margin: 0;
291
+ padding: 4px 0;
292
+ z-index: 200;
293
+ max-height: 240px;
294
+ overflow-y: auto;
295
+ -webkit-overflow-scrolling: touch;
296
+ }
297
+
298
+ .qr-search-bar__suggestion {
299
+ display: flex;
300
+ align-items: flex-start;
301
+ gap: 9px;
302
+ padding: 9px 12px;
303
+ cursor: pointer;
304
+ transition: background var(--qr-transition);
305
+ }
306
+
307
+ .qr-search-bar__suggestion:hover,
308
+ .qr-search-bar__suggestion:focus {
309
+ background: var(--qr-bg-subtle);
310
+ outline: none;
311
+ }
312
+
313
+ .qr-search-bar__suggestion-icon {
314
+ width: 14px;
315
+ height: 14px;
316
+ flex-shrink: 0;
317
+ color: var(--qr-primary);
318
+ margin-top: 2px;
319
+ }
320
+
321
+ .qr-search-bar__suggestion-text {
322
+ display: flex;
323
+ flex-direction: column;
324
+ gap: 1px;
325
+ min-width: 0;
326
+ }
327
+
328
+ .qr-search-bar__suggestion-name {
329
+ font-size: 13px;
330
+ font-weight: 500;
331
+ color: var(--qr-text);
332
+ white-space: nowrap;
333
+ overflow: hidden;
334
+ text-overflow: ellipsis;
335
+ }
336
+
337
+ .qr-search-bar__suggestion-sub {
338
+ font-size: 11px;
339
+ color: var(--qr-text-muted);
340
+ white-space: nowrap;
341
+ overflow: hidden;
342
+ text-overflow: ellipsis;
343
+ }
344
+
345
+ /* ── DigiPin hint below input ────────────────────────────── */
346
+ .qr-search-bar__hint {
347
+ margin: 5px 2px 2px;
348
+ font-size: 11px;
349
+ color: var(--qr-text-faint);
350
+ display: flex;
351
+ align-items: center;
352
+ gap: 5px;
353
+ }
354
+
355
+ .qr-search-bar__hint-chip {
356
+ background: var(--qr-primary-light);
357
+ color: var(--qr-primary);
358
+ font-size: 10px;
359
+ font-weight: 700;
360
+ letter-spacing: 0.04em;
361
+ padding: 1px 6px;
362
+ border-radius: 100px;
363
+ white-space: nowrap;
364
+ }
365
+
191
366
  /* ── Map area ────────────────────────────────────────────── */
192
367
  .qr-map-wrapper {
193
368
  display: flex;
@@ -820,6 +820,93 @@ export const styles = StyleSheet.create({
820
820
  fontWeight: '500',
821
821
  },
822
822
 
823
+ // ── Search bar ──────────────────────────────────────────────────────────────
824
+ searchBar: {
825
+ paddingHorizontal: 12,
826
+ paddingTop: 10,
827
+ paddingBottom: 6,
828
+ backgroundColor: COLORS.bg,
829
+ borderBottomWidth: 1,
830
+ borderBottomColor: COLORS.border,
831
+ },
832
+ searchBarDark: {
833
+ backgroundColor: COLORS.bgDark,
834
+ borderBottomColor: COLORS.borderDark,
835
+ },
836
+ searchInputWrap: {
837
+ flexDirection: 'row',
838
+ alignItems: 'center',
839
+ backgroundColor: COLORS.bgSubtle,
840
+ borderWidth: 1.5,
841
+ borderColor: COLORS.border,
842
+ borderRadius: 8,
843
+ paddingHorizontal: 10,
844
+ },
845
+ searchInputWrapDark: {
846
+ backgroundColor: COLORS.bgSubtleDark,
847
+ borderColor: COLORS.borderDark,
848
+ },
849
+ searchInput: {
850
+ flex: 1,
851
+ paddingVertical: 9,
852
+ fontSize: 13,
853
+ color: COLORS.text,
854
+ },
855
+ searchInputDark: {
856
+ color: COLORS.textDark,
857
+ },
858
+ searchSpinner: {
859
+ marginLeft: 6,
860
+ },
861
+ searchError: {
862
+ marginTop: 4,
863
+ marginLeft: 2,
864
+ fontSize: 11,
865
+ color: COLORS.error,
866
+ },
867
+ searchDropdown: {
868
+ maxHeight: 220,
869
+ borderWidth: 1.5,
870
+ borderColor: COLORS.border,
871
+ borderRadius: 8,
872
+ marginTop: 4,
873
+ backgroundColor: COLORS.bg,
874
+ },
875
+ searchDropdownDark: {
876
+ borderColor: COLORS.borderDark,
877
+ backgroundColor: COLORS.bgDark,
878
+ },
879
+ searchSuggestion: {
880
+ paddingHorizontal: 12,
881
+ paddingVertical: 10,
882
+ borderBottomWidth: StyleSheet.hairlineWidth,
883
+ borderBottomColor: COLORS.border,
884
+ },
885
+ searchSuggestionDark: {
886
+ borderBottomColor: COLORS.borderDark,
887
+ },
888
+ searchSuggestionName: {
889
+ fontSize: 13,
890
+ fontWeight: '500',
891
+ color: COLORS.text,
892
+ },
893
+ searchSuggestionSub: {
894
+ fontSize: 11,
895
+ color: COLORS.textMuted,
896
+ marginTop: 1,
897
+ },
898
+ searchHint: {
899
+ marginTop: 5,
900
+ marginLeft: 2,
901
+ fontSize: 11,
902
+ color: COLORS.textFaint,
903
+ },
904
+ searchHintChip: {
905
+ fontSize: 10,
906
+ fontWeight: '700',
907
+ color: COLORS.primary,
908
+ },
909
+
823
910
  // ── Generic text helpers ────────────────────────────────────────────────────
824
911
  textLight: {
825
912
  color: COLORS.textDark,
@@ -1,74 +0,0 @@
1
- import type { BuiltInMapStyle } from './types';
2
-
3
- // ─── Style registry ───────────────────────────────────────────────────────────
4
-
5
- interface StyleEntry {
6
- url: string;
7
- /** HTML attribution string (web). Plain text for native. */
8
- attributionHtml: string;
9
- attributionPlain: string;
10
- }
11
-
12
- const STYLE_REGISTRY: Record<BuiltInMapStyle, StyleEntry> = {
13
- 'carto-positron': {
14
- url: 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json',
15
- attributionHtml:
16
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors' +
17
- ' &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
18
- attributionPlain: '© OpenStreetMap contributors © CARTO',
19
- },
20
- 'openfreemap-liberty': {
21
- url: 'https://tiles.openfreemap.org/styles/liberty',
22
- attributionHtml:
23
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors' +
24
- ' &nbsp;© <a href="https://openmaptiles.org" target="_blank" rel="noopener">OpenMapTiles</a>' +
25
- ' &nbsp;<a href="https://openfreemap.org" target="_blank" rel="noopener">OpenFreeMap</a>',
26
- attributionPlain: '© OpenStreetMap contributors © OpenMapTiles · OpenFreeMap',
27
- },
28
- 'openfreemap-positron': {
29
- url: 'https://tiles.openfreemap.org/styles/positron',
30
- attributionHtml:
31
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors' +
32
- ' &nbsp;© <a href="https://openmaptiles.org" target="_blank" rel="noopener">OpenMapTiles</a>' +
33
- ' &nbsp;<a href="https://openfreemap.org" target="_blank" rel="noopener">OpenFreeMap</a>',
34
- attributionPlain: '© OpenStreetMap contributors © OpenMapTiles · OpenFreeMap',
35
- },
36
- 'openfreemap-bright': {
37
- url: 'https://tiles.openfreemap.org/styles/bright',
38
- attributionHtml:
39
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors' +
40
- ' &nbsp;© <a href="https://openmaptiles.org" target="_blank" rel="noopener">OpenMapTiles</a>' +
41
- ' &nbsp;<a href="https://openfreemap.org" target="_blank" rel="noopener">OpenFreeMap</a>',
42
- attributionPlain: '© OpenStreetMap contributors © OpenMapTiles · OpenFreeMap',
43
- },
44
- };
45
-
46
- // ─── Resolver ─────────────────────────────────────────────────────────────────
47
-
48
- const DEFAULT_STYLE: BuiltInMapStyle = 'carto-positron';
49
-
50
- function isBuiltIn(value: string): value is BuiltInMapStyle {
51
- return value in STYLE_REGISTRY;
52
- }
53
-
54
- /**
55
- * Resolves a mapStyle prop value to its concrete style URL and attribution.
56
- * If the value is a preset name, returns the registered entry.
57
- * If the value is a custom URL string, returns that URL with generic OSM attribution.
58
- * If undefined, falls back to the default preset (carto-positron).
59
- */
60
- export function resolveMapStyle(mapStyle: BuiltInMapStyle | string | undefined): StyleEntry {
61
- if (!mapStyle || mapStyle === DEFAULT_STYLE) {
62
- return STYLE_REGISTRY[DEFAULT_STYLE];
63
- }
64
- if (isBuiltIn(mapStyle)) {
65
- return STYLE_REGISTRY[mapStyle];
66
- }
67
- // Custom URL — caller is responsible for setting correct attribution via their style JSON
68
- return {
69
- url: mapStyle,
70
- attributionHtml:
71
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors',
72
- attributionPlain: '© OpenStreetMap contributors',
73
- };
74
- }