@quantaroute/checkout 1.7.1 → 1.7.2
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/CHANGELOG.md +12 -0
- package/dist/lib/index.d.ts +60 -0
- package/dist/lib/quantaroute-checkout.es.js +195 -186
- package/dist/lib/quantaroute-checkout.umd.js +132 -123
- package/package.json +1 -1
- package/src/components/CheckoutWidget.tsx +6 -0
- package/src/components/MapPinSelector.tsx +250 -175
- package/src/core/map-runtime.ts +100 -0
- package/src/core/types.ts +21 -0
- package/src/index.ts +13 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Map as MapLibreMap,
|
|
3
|
+
MapMouseEvent,
|
|
4
|
+
Marker as MapLibreMarker,
|
|
5
|
+
} from 'maplibre-gl';
|
|
6
|
+
|
|
7
|
+
/** Subset of maplibre-gl used by the web MapPinSelector. */
|
|
8
|
+
export interface MapRuntime {
|
|
9
|
+
Map: new (
|
|
10
|
+
options: ConstructorParameters<typeof import('maplibre-gl').Map>[0]
|
|
11
|
+
) => MapLibreMap;
|
|
12
|
+
Marker: new (
|
|
13
|
+
options?: ConstructorParameters<typeof import('maplibre-gl').Marker>[0]
|
|
14
|
+
) => MapLibreMarker;
|
|
15
|
+
AttributionControl?: new (
|
|
16
|
+
options?: ConstructorParameters<
|
|
17
|
+
NonNullable<typeof import('maplibre-gl').AttributionControl>
|
|
18
|
+
>[0]
|
|
19
|
+
) => import('maplibre-gl').AttributionControl;
|
|
20
|
+
NavigationControl?: new (
|
|
21
|
+
options?: ConstructorParameters<
|
|
22
|
+
NonNullable<typeof import('maplibre-gl').NavigationControl>
|
|
23
|
+
>[0]
|
|
24
|
+
) => import('maplibre-gl').NavigationControl;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type { MapLibreMap, MapLibreMarker, MapMouseEvent };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How the host provides MapLibre GL JS.
|
|
31
|
+
* - `bundled`: import from `maplibre-gl` (default — Next.js, Vite apps with the peer installed)
|
|
32
|
+
* - `external`: read from `window.maplibregl` (CDN script loaded before the widget, e.g. Shopify)
|
|
33
|
+
*/
|
|
34
|
+
export type MapEmbedMode = 'bundled' | 'external';
|
|
35
|
+
|
|
36
|
+
/** Carto Positron — default basemap for standard web embeds. */
|
|
37
|
+
export const DEFAULT_MAP_STYLE_URL =
|
|
38
|
+
'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
|
|
39
|
+
|
|
40
|
+
/** OpenFreeMap Positron — free, no API key (used when Carto credentials are unavailable). */
|
|
41
|
+
export const OPENFREEMAP_POSITRON_STYLE_URL =
|
|
42
|
+
'https://tiles.openfreemap.org/styles/positron';
|
|
43
|
+
|
|
44
|
+
const MAPLIBRE_WAIT_MS = 8_000;
|
|
45
|
+
const MAPLIBRE_RETRY_MS = 100;
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
maplibregl?: MapRuntime;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getExternalMapRuntime(): MapRuntime | null {
|
|
54
|
+
if (typeof window === 'undefined') return null;
|
|
55
|
+
const maplibre = window.maplibregl;
|
|
56
|
+
if (
|
|
57
|
+
!maplibre ||
|
|
58
|
+
typeof maplibre.Map !== 'function' ||
|
|
59
|
+
typeof maplibre.Marker !== 'function'
|
|
60
|
+
) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return maplibre;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Poll `window.maplibregl` until available or timeout (for async CDN loads).
|
|
68
|
+
* Returns a cancel function for useEffect cleanup.
|
|
69
|
+
*/
|
|
70
|
+
export function waitForExternalMapRuntime(
|
|
71
|
+
onReady: (runtime: MapRuntime) => void,
|
|
72
|
+
onUnavailable: () => void,
|
|
73
|
+
waitMs: number = MAPLIBRE_WAIT_MS,
|
|
74
|
+
retryMs: number = MAPLIBRE_RETRY_MS
|
|
75
|
+
): () => void {
|
|
76
|
+
const startedAt = Date.now();
|
|
77
|
+
let retryTimer: number | null = null;
|
|
78
|
+
let cancelled = false;
|
|
79
|
+
|
|
80
|
+
const tryGet = () => {
|
|
81
|
+
if (cancelled) return;
|
|
82
|
+
const runtime = getExternalMapRuntime();
|
|
83
|
+
if (runtime) {
|
|
84
|
+
onReady(runtime);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (Date.now() - startedAt >= waitMs) {
|
|
88
|
+
onUnavailable();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
retryTimer = window.setTimeout(tryGet, retryMs);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
tryGet();
|
|
95
|
+
|
|
96
|
+
return () => {
|
|
97
|
+
cancelled = true;
|
|
98
|
+
if (retryTimer !== null) window.clearTimeout(retryTimer);
|
|
99
|
+
};
|
|
100
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MapEmbedMode } from './map-runtime';
|
|
2
3
|
import type { UtmParams } from './utm';
|
|
3
4
|
import type {
|
|
4
5
|
AddressRiskScore,
|
|
@@ -216,6 +217,16 @@ export interface MapPinSelectorProps {
|
|
|
216
217
|
* Brand accent colour (hex, e.g. `#7c3aed`). Sets map pin, buttons, focus rings via `--qr-primary` on web.
|
|
217
218
|
*/
|
|
218
219
|
brandColor?: string;
|
|
220
|
+
/**
|
|
221
|
+
* MapLibre style URL for the basemap. Defaults to Carto Positron.
|
|
222
|
+
* Use `OPENFREEMAP_POSITRON_STYLE_URL` when Carto credentials are unavailable.
|
|
223
|
+
*/
|
|
224
|
+
mapStyle?: string;
|
|
225
|
+
/**
|
|
226
|
+
* How MapLibre GL JS is loaded on web. `bundled` imports the peer dependency;
|
|
227
|
+
* `external` waits for `window.maplibregl` (CDN script loaded by the host).
|
|
228
|
+
*/
|
|
229
|
+
embedMode?: MapEmbedMode;
|
|
219
230
|
}
|
|
220
231
|
|
|
221
232
|
/** Pre-fill manual fields when verifying an imported saved address. */
|
|
@@ -297,6 +308,16 @@ export interface CheckoutWidgetProps {
|
|
|
297
308
|
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
298
309
|
*/
|
|
299
310
|
indiaBoundaryUrl?: string;
|
|
311
|
+
/**
|
|
312
|
+
* MapLibre style URL for the map step. Defaults to Carto Positron.
|
|
313
|
+
* Pass `OPENFREEMAP_POSITRON_STYLE_URL` when Carto basemaps require credentials.
|
|
314
|
+
*/
|
|
315
|
+
mapStyle?: string;
|
|
316
|
+
/**
|
|
317
|
+
* How MapLibre GL JS is loaded on web. `external` waits for `window.maplibregl`
|
|
318
|
+
* when the host loads MapLibre from a CDN (e.g. Shopify theme extensions).
|
|
319
|
+
*/
|
|
320
|
+
embedMode?: MapEmbedMode;
|
|
300
321
|
/**
|
|
301
322
|
* Show the smart search bar on the map step (default: true).
|
|
302
323
|
* Supports address search (API) and DigiPin lookup (100% offline).
|
package/src/index.ts
CHANGED
|
@@ -124,6 +124,19 @@ export { useDigiPin } from './hooks/useDigiPin';
|
|
|
124
124
|
export { captureUtmFromUrl, hasUtmParams } from './core/utm';
|
|
125
125
|
export type { UtmParams } from './core/utm';
|
|
126
126
|
export { getWebDeviceContext, detectDeviceType, detectPlatform } from './core/device';
|
|
127
|
+
export type {
|
|
128
|
+
MapRuntime,
|
|
129
|
+
MapEmbedMode,
|
|
130
|
+
MapLibreMap,
|
|
131
|
+
MapLibreMarker,
|
|
132
|
+
MapMouseEvent,
|
|
133
|
+
} from './core/map-runtime';
|
|
134
|
+
export {
|
|
135
|
+
DEFAULT_MAP_STYLE_URL,
|
|
136
|
+
OPENFREEMAP_POSITRON_STYLE_URL,
|
|
137
|
+
getExternalMapRuntime,
|
|
138
|
+
waitForExternalMapRuntime,
|
|
139
|
+
} from './core/map-runtime';
|
|
127
140
|
export type {
|
|
128
141
|
CheckoutWidgetProps,
|
|
129
142
|
CheckoutMobilePresentation,
|