ola-map-sdk 1.3.0 → 2.0.0
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/LICENSE +20 -20
- package/README.md +380 -215
- package/dist/chunk-22747AE4.js +978 -0
- package/dist/chunk-22747AE4.js.map +1 -0
- package/dist/chunk-5YVHNDSA.cjs +282 -0
- package/dist/chunk-5YVHNDSA.cjs.map +1 -0
- package/dist/chunk-6J7XUGWD.cjs +443 -0
- package/dist/chunk-6J7XUGWD.cjs.map +1 -0
- package/dist/chunk-7LV3RPED.js +440 -0
- package/dist/chunk-7LV3RPED.js.map +1 -0
- package/dist/chunk-D5T5ZDIQ.js +268 -0
- package/dist/chunk-D5T5ZDIQ.js.map +1 -0
- package/dist/chunk-SJJRTEQG.js +94 -0
- package/dist/chunk-SJJRTEQG.js.map +1 -0
- package/dist/chunk-WLUKC7YU.cjs +991 -0
- package/dist/chunk-WLUKC7YU.cjs.map +1 -0
- package/dist/chunk-XRJXKY7C.cjs +100 -0
- package/dist/chunk-XRJXKY7C.cjs.map +1 -0
- package/dist/client-Cd22y5wG.d.cts +782 -0
- package/dist/client-DsBMyuG9.d.ts +782 -0
- package/dist/common-Bt8xNzhK.d.cts +115 -0
- package/dist/common-Bt8xNzhK.d.ts +115 -0
- package/dist/index.cjs +115 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/maplibre/index.cjs +29 -0
- package/dist/maplibre/index.cjs.map +1 -0
- package/dist/maplibre/index.d.cts +63 -0
- package/dist/maplibre/index.d.ts +63 -0
- package/dist/maplibre/index.js +4 -0
- package/dist/maplibre/index.js.map +1 -0
- package/dist/next/index.cjs +173 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +65 -0
- package/dist/next/index.d.ts +65 -0
- package/dist/next/index.js +169 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.cjs +257 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +77 -0
- package/dist/react/index.d.ts +77 -0
- package/dist/react/index.js +251 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +111 -11
- package/src/client.js +0 -95
- package/src/endpoints/elevation.js +0 -58
- package/src/endpoints/geofencing.js +0 -118
- package/src/endpoints/places.js +0 -106
- package/src/endpoints/roads.js +0 -57
- package/src/endpoints/routing.js +0 -160
- package/src/endpoints/tiles.js +0 -115
- package/src/index.js +0 -5
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkWLUKC7YU_cjs = require('../chunk-WLUKC7YU.cjs');
|
|
5
|
+
require('../chunk-XRJXKY7C.cjs');
|
|
6
|
+
require('../chunk-6J7XUGWD.cjs');
|
|
7
|
+
require('../chunk-5YVHNDSA.cjs');
|
|
8
|
+
var react = require('react');
|
|
9
|
+
|
|
10
|
+
var OlaMapsContext = react.createContext(null);
|
|
11
|
+
function OlaMapsProvider({ client, config, children }) {
|
|
12
|
+
const resolvedClient = react.useMemo(() => {
|
|
13
|
+
if (client) return client;
|
|
14
|
+
if (!config) {
|
|
15
|
+
throw new Error("OlaMapsProvider requires either a `client` or `config` prop.");
|
|
16
|
+
}
|
|
17
|
+
return new chunkWLUKC7YU_cjs.OlaMapsClient(config);
|
|
18
|
+
}, [client, config]);
|
|
19
|
+
return react.createElement(OlaMapsContext.Provider, { value: resolvedClient }, children);
|
|
20
|
+
}
|
|
21
|
+
function useOlaMapsClient() {
|
|
22
|
+
const client = react.useContext(OlaMapsContext);
|
|
23
|
+
if (!client) {
|
|
24
|
+
throw new Error("useOlaMapsClient must be used within an <OlaMapsProvider>.");
|
|
25
|
+
}
|
|
26
|
+
return client;
|
|
27
|
+
}
|
|
28
|
+
function isAbortError(error) {
|
|
29
|
+
return error instanceof Error && error.name === "AbortError";
|
|
30
|
+
}
|
|
31
|
+
function useOlaAutocomplete(input, options = {}) {
|
|
32
|
+
const contextClient = react.useContext(OlaMapsContext);
|
|
33
|
+
const activeClient = options.client ?? contextClient;
|
|
34
|
+
if (!activeClient) {
|
|
35
|
+
throw new Error("useOlaAutocomplete requires <OlaMapsProvider> or options.client.");
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
debounceMs = 250,
|
|
39
|
+
minLength = 2,
|
|
40
|
+
enabled = true,
|
|
41
|
+
location,
|
|
42
|
+
radius,
|
|
43
|
+
strictbounds,
|
|
44
|
+
language,
|
|
45
|
+
types
|
|
46
|
+
} = options;
|
|
47
|
+
const locationKey = typeof location === "string" ? location : JSON.stringify(location ?? null);
|
|
48
|
+
const locationRef = react.useRef(location);
|
|
49
|
+
locationRef.current = location;
|
|
50
|
+
const [data, setData] = react.useState(null);
|
|
51
|
+
const [loading, setLoading] = react.useState(false);
|
|
52
|
+
const [error, setError] = react.useState(null);
|
|
53
|
+
const [reloadTick, setReloadTick] = react.useState(0);
|
|
54
|
+
const refetch = react.useCallback(() => {
|
|
55
|
+
setReloadTick((n) => n + 1);
|
|
56
|
+
}, []);
|
|
57
|
+
react.useEffect(() => {
|
|
58
|
+
const trimmed = input.trim();
|
|
59
|
+
if (!enabled || trimmed.length < minLength) {
|
|
60
|
+
setData(null);
|
|
61
|
+
setError(null);
|
|
62
|
+
setLoading(false);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
setLoading(true);
|
|
67
|
+
setError(null);
|
|
68
|
+
const timer = setTimeout(() => {
|
|
69
|
+
activeClient.places.autocomplete(
|
|
70
|
+
trimmed,
|
|
71
|
+
{ location: locationRef.current, radius, strictbounds, language, types },
|
|
72
|
+
{ signal: controller.signal }
|
|
73
|
+
).then((res) => {
|
|
74
|
+
if (!controller.signal.aborted) {
|
|
75
|
+
setData(res);
|
|
76
|
+
setError(null);
|
|
77
|
+
setLoading(false);
|
|
78
|
+
}
|
|
79
|
+
}).catch((err) => {
|
|
80
|
+
if (controller.signal.aborted || isAbortError(err)) return;
|
|
81
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
82
|
+
setLoading(false);
|
|
83
|
+
});
|
|
84
|
+
}, debounceMs);
|
|
85
|
+
return () => {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
controller.abort();
|
|
88
|
+
};
|
|
89
|
+
}, [
|
|
90
|
+
activeClient,
|
|
91
|
+
input,
|
|
92
|
+
enabled,
|
|
93
|
+
minLength,
|
|
94
|
+
debounceMs,
|
|
95
|
+
locationKey,
|
|
96
|
+
radius,
|
|
97
|
+
strictbounds,
|
|
98
|
+
language,
|
|
99
|
+
types,
|
|
100
|
+
reloadTick
|
|
101
|
+
]);
|
|
102
|
+
return {
|
|
103
|
+
predictions: data?.predictions ?? [],
|
|
104
|
+
data,
|
|
105
|
+
loading,
|
|
106
|
+
error,
|
|
107
|
+
refetch
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function useOlaDirections(origin, destination, options = {}) {
|
|
111
|
+
const contextClient = react.useContext(OlaMapsContext);
|
|
112
|
+
const activeClient = options.client ?? contextClient;
|
|
113
|
+
if (!activeClient) {
|
|
114
|
+
throw new Error("useOlaDirections requires <OlaMapsProvider> or options.client.");
|
|
115
|
+
}
|
|
116
|
+
const {
|
|
117
|
+
enabled = true,
|
|
118
|
+
alternatives,
|
|
119
|
+
steps,
|
|
120
|
+
overview,
|
|
121
|
+
language,
|
|
122
|
+
traffic_metadata,
|
|
123
|
+
waypoints,
|
|
124
|
+
mode,
|
|
125
|
+
route_preference
|
|
126
|
+
} = options;
|
|
127
|
+
const originKey = origin == null ? "" : JSON.stringify(origin);
|
|
128
|
+
const destKey = destination == null ? "" : JSON.stringify(destination);
|
|
129
|
+
const waypointsKey = waypoints == null ? "" : JSON.stringify(waypoints);
|
|
130
|
+
const originRef = react.useRef(origin);
|
|
131
|
+
const destRef = react.useRef(destination);
|
|
132
|
+
const waypointsRef = react.useRef(waypoints);
|
|
133
|
+
originRef.current = origin;
|
|
134
|
+
destRef.current = destination;
|
|
135
|
+
waypointsRef.current = waypoints;
|
|
136
|
+
const [data, setData] = react.useState(null);
|
|
137
|
+
const [loading, setLoading] = react.useState(false);
|
|
138
|
+
const [error, setError] = react.useState(null);
|
|
139
|
+
const [reloadTick, setReloadTick] = react.useState(0);
|
|
140
|
+
const refetch = react.useCallback(() => {
|
|
141
|
+
setReloadTick((n) => n + 1);
|
|
142
|
+
}, []);
|
|
143
|
+
react.useEffect(() => {
|
|
144
|
+
if (!enabled || !originKey || !destKey || originRef.current == null || destRef.current == null) {
|
|
145
|
+
setLoading(false);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const controller = new AbortController();
|
|
149
|
+
setLoading(true);
|
|
150
|
+
setError(null);
|
|
151
|
+
activeClient.routing.getDirections(
|
|
152
|
+
originRef.current,
|
|
153
|
+
destRef.current,
|
|
154
|
+
{
|
|
155
|
+
alternatives,
|
|
156
|
+
steps,
|
|
157
|
+
overview,
|
|
158
|
+
language,
|
|
159
|
+
traffic_metadata,
|
|
160
|
+
waypoints: waypointsRef.current,
|
|
161
|
+
mode,
|
|
162
|
+
route_preference
|
|
163
|
+
},
|
|
164
|
+
{ signal: controller.signal }
|
|
165
|
+
).then((res) => {
|
|
166
|
+
if (!controller.signal.aborted) {
|
|
167
|
+
setData(res);
|
|
168
|
+
setError(null);
|
|
169
|
+
setLoading(false);
|
|
170
|
+
}
|
|
171
|
+
}).catch((err) => {
|
|
172
|
+
if (controller.signal.aborted || isAbortError(err)) return;
|
|
173
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
174
|
+
setLoading(false);
|
|
175
|
+
});
|
|
176
|
+
return () => {
|
|
177
|
+
controller.abort();
|
|
178
|
+
};
|
|
179
|
+
}, [
|
|
180
|
+
activeClient,
|
|
181
|
+
enabled,
|
|
182
|
+
originKey,
|
|
183
|
+
destKey,
|
|
184
|
+
alternatives,
|
|
185
|
+
steps,
|
|
186
|
+
overview,
|
|
187
|
+
language,
|
|
188
|
+
traffic_metadata,
|
|
189
|
+
waypointsKey,
|
|
190
|
+
mode,
|
|
191
|
+
route_preference,
|
|
192
|
+
reloadTick
|
|
193
|
+
]);
|
|
194
|
+
return {
|
|
195
|
+
routes: data?.routes ?? [],
|
|
196
|
+
data,
|
|
197
|
+
loading,
|
|
198
|
+
error,
|
|
199
|
+
refetch
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function useOlaReverseGeocode(coordinate, options = {}) {
|
|
203
|
+
const contextClient = react.useContext(OlaMapsContext);
|
|
204
|
+
const activeClient = options.client ?? contextClient;
|
|
205
|
+
if (!activeClient) {
|
|
206
|
+
throw new Error("useOlaReverseGeocode requires <OlaMapsProvider> or options.client.");
|
|
207
|
+
}
|
|
208
|
+
const { enabled = true, language } = options;
|
|
209
|
+
const coordKey = coordinate == null ? "" : JSON.stringify(coordinate);
|
|
210
|
+
const coordRef = react.useRef(coordinate);
|
|
211
|
+
coordRef.current = coordinate;
|
|
212
|
+
const [data, setData] = react.useState(null);
|
|
213
|
+
const [loading, setLoading] = react.useState(false);
|
|
214
|
+
const [error, setError] = react.useState(null);
|
|
215
|
+
const [reloadTick, setReloadTick] = react.useState(0);
|
|
216
|
+
const refetch = react.useCallback(() => {
|
|
217
|
+
setReloadTick((n) => n + 1);
|
|
218
|
+
}, []);
|
|
219
|
+
react.useEffect(() => {
|
|
220
|
+
if (!enabled || !coordKey || coordRef.current == null) {
|
|
221
|
+
setLoading(false);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const controller = new AbortController();
|
|
225
|
+
setLoading(true);
|
|
226
|
+
setError(null);
|
|
227
|
+
activeClient.places.reverseGeocode(coordRef.current, { language }, { signal: controller.signal }).then((res) => {
|
|
228
|
+
if (!controller.signal.aborted) {
|
|
229
|
+
setData(res);
|
|
230
|
+
setError(null);
|
|
231
|
+
setLoading(false);
|
|
232
|
+
}
|
|
233
|
+
}).catch((err) => {
|
|
234
|
+
if (controller.signal.aborted || isAbortError(err)) return;
|
|
235
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
236
|
+
setLoading(false);
|
|
237
|
+
});
|
|
238
|
+
return () => {
|
|
239
|
+
controller.abort();
|
|
240
|
+
};
|
|
241
|
+
}, [activeClient, enabled, coordKey, language, reloadTick]);
|
|
242
|
+
return {
|
|
243
|
+
results: data?.results ?? [],
|
|
244
|
+
data,
|
|
245
|
+
loading,
|
|
246
|
+
error,
|
|
247
|
+
refetch
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
exports.OlaMapsProvider = OlaMapsProvider;
|
|
252
|
+
exports.useOlaAutocomplete = useOlaAutocomplete;
|
|
253
|
+
exports.useOlaDirections = useOlaDirections;
|
|
254
|
+
exports.useOlaMapsClient = useOlaMapsClient;
|
|
255
|
+
exports.useOlaReverseGeocode = useOlaReverseGeocode;
|
|
256
|
+
//# sourceMappingURL=index.cjs.map
|
|
257
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts"],"names":["createContext","useMemo","OlaMapsClient","createElement","useContext","useRef","useState","useCallback","useEffect"],"mappings":";;;;;;;;AAuBA,IAAM,cAAA,GAAiBA,oBAAoC,IAAI,CAAA;AAaxD,SAAS,eAAA,CAAgB,EAAE,MAAA,EAAQ,MAAA,EAAQ,UAAS,EAAyB;AAClF,EAAA,MAAM,cAAA,GAAiBC,cAAQ,MAAM;AACnC,IAAA,IAAI,QAAQ,OAAO,MAAA;AACnB,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,8DAA8D,CAAA;AAAA,IAChF;AACA,IAAA,OAAO,IAAIC,gCAAc,MAAM,CAAA;AAAA,EACjC,CAAA,EAAG,CAAC,MAAA,EAAQ,MAAM,CAAC,CAAA;AAEnB,EAAA,OAAOC,oBAAc,cAAA,CAAe,QAAA,EAAU,EAAE,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allback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { OlaMapsClient } from '../client.js';\nimport type { CoordinateInput, OlaMapsClientInput } from '../types/common.js';\nimport type {\n AutocompleteOptions,\n AutocompletePrediction,\n AutocompleteResponse,\n GeocodeResult,\n ReverseGeocodeOptions,\n ReverseGeocodeResponse,\n} from '../types/places.js';\nimport type { DirectionsOptions, DirectionsResponse, Route } from '../types/routing.js';\n\nconst OlaMapsContext = createContext<OlaMapsClient | null>(null);\n\nexport interface OlaMapsProviderProps {\n /** Pass a pre-instantiated `OlaMapsClient` OR `config` to create one automatically. */\n client?: OlaMapsClient;\n /** Client configuration (e.g. `{ baseUrl: '/api/ola-maps' }` or API key string). */\n config?: OlaMapsClientInput;\n children: ReactNode;\n}\n\n/**\n * Provide a shared `OlaMapsClient` instance to descendant React components and hooks.\n */\nexport function OlaMapsProvider({ client, config, children }: OlaMapsProviderProps) {\n const resolvedClient = useMemo(() => {\n if (client) return client;\n if (!config) {\n throw new Error('OlaMapsProvider requires either a `client` or `config` prop.');\n }\n return new OlaMapsClient(config);\n }, [client, config]);\n\n return createElement(OlaMapsContext.Provider, { value: resolvedClient }, children);\n}\n\n/**\n * Access the nearest `OlaMapsClient` provided by `<OlaMapsProvider>`.\n */\nexport function useOlaMapsClient(): OlaMapsClient {\n const client = useContext(OlaMapsContext);\n if (!client) {\n throw new Error('useOlaMapsClient must be used within an <OlaMapsProvider>.');\n }\n return client;\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n\nexport interface UseOlaAutocompleteOptions extends AutocompleteOptions {\n /** Debounce delay in milliseconds before firing a search request (default: 250). */\n debounceMs?: number;\n /** Minimum input length before querying Ola Maps (default: 2). */\n minLength?: number;\n /** Disable automatic querying when false (default: true). */\n enabled?: boolean;\n /** Optional explicit client override (defaults to context client). */\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaAutocompleteResult {\n predictions: AutocompletePrediction[];\n data: AutocompleteResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Debounced Places Autocomplete hook with automatic `AbortController` cancellation\n * on every keystroke and component unmount.\n */\nexport function useOlaAutocomplete(\n input: string,\n options: UseOlaAutocompleteOptions = {},\n): UseOlaAutocompleteResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaAutocomplete requires <OlaMapsProvider> or options.client.');\n }\n\n const {\n debounceMs = 250,\n minLength = 2,\n enabled = true,\n location,\n radius,\n strictbounds,\n language,\n types,\n } = options;\n\n const locationKey = typeof location === 'string' ? location : JSON.stringify(location ?? null);\n const locationRef = useRef(location);\n locationRef.current = location;\n\n const [data, setData] = useState<AutocompleteResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void locationKey;\n void reloadTick;\n\n const trimmed = input.trim();\n if (!enabled || trimmed.length < minLength) {\n setData(null);\n setError(null);\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n const timer = setTimeout(() => {\n activeClient.places\n .autocomplete(\n trimmed,\n { location: locationRef.current, radius, strictbounds, language, types },\n { signal: controller.signal },\n )\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n }, debounceMs);\n\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [\n activeClient,\n input,\n enabled,\n minLength,\n debounceMs,\n locationKey,\n radius,\n strictbounds,\n language,\n types,\n reloadTick,\n ]);\n\n return {\n predictions: data?.predictions ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n\nexport interface UseOlaDirectionsOptions extends DirectionsOptions {\n /** Disable automatic querying when false (default: true). */\n enabled?: boolean;\n /** Optional explicit client override (defaults to context client). */\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaDirectionsResult {\n routes: Route[];\n data: DirectionsResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Fetch turn-by-turn directions reactively with automatic `AbortController` cancellation.\n */\nexport function useOlaDirections(\n origin: CoordinateInput | null | undefined,\n destination: CoordinateInput | null | undefined,\n options: UseOlaDirectionsOptions = {},\n): UseOlaDirectionsResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaDirections requires <OlaMapsProvider> or options.client.');\n }\n\n const {\n enabled = true,\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypoints,\n mode,\n route_preference,\n } = options;\n\n const originKey = origin == null ? '' : JSON.stringify(origin);\n const destKey = destination == null ? '' : JSON.stringify(destination);\n const waypointsKey = waypoints == null ? '' : JSON.stringify(waypoints);\n\n const originRef = useRef(origin);\n const destRef = useRef(destination);\n const waypointsRef = useRef(waypoints);\n originRef.current = origin;\n destRef.current = destination;\n waypointsRef.current = waypoints;\n\n const [data, setData] = useState<DirectionsResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void reloadTick;\n\n if (\n !enabled ||\n !originKey ||\n !destKey ||\n originRef.current == null ||\n destRef.current == null\n ) {\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n void waypointsKey;\n\n activeClient.routing\n .getDirections(\n originRef.current,\n destRef.current,\n {\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypoints: waypointsRef.current,\n mode,\n route_preference,\n },\n { signal: controller.signal },\n )\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n\n return () => {\n controller.abort();\n };\n }, [\n activeClient,\n enabled,\n originKey,\n destKey,\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypointsKey,\n mode,\n route_preference,\n reloadTick,\n ]);\n\n return {\n routes: data?.routes ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n\nexport interface UseOlaReverseGeocodeOptions extends ReverseGeocodeOptions {\n enabled?: boolean;\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaReverseGeocodeResult {\n results: GeocodeResult[];\n data: ReverseGeocodeResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Reverse-geocode a coordinate reactively with automatic `AbortController` cancellation.\n */\nexport function useOlaReverseGeocode(\n coordinate: Exclude<CoordinateInput, string> | null | undefined,\n options: UseOlaReverseGeocodeOptions = {},\n): UseOlaReverseGeocodeResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaReverseGeocode requires <OlaMapsProvider> or options.client.');\n }\n\n const { enabled = true, language } = options;\n const coordKey = coordinate == null ? '' : JSON.stringify(coordinate);\n const coordRef = useRef(coordinate);\n coordRef.current = coordinate;\n\n const [data, setData] = useState<ReverseGeocodeResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void reloadTick;\n\n if (!enabled || !coordKey || coordRef.current == null) {\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n activeClient.places\n .reverseGeocode(coordRef.current, { language }, { signal: controller.signal })\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n\n return () => {\n controller.abort();\n };\n }, [activeClient, enabled, coordKey, language, reloadTick]);\n\n return {\n results: data?.results ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { O as OlaMapsClient, c as AutocompleteOptions, d as AutocompletePrediction, e as AutocompleteResponse, i as DirectionsOptions, Z as Route, j as DirectionsResponse, W as ReverseGeocodeOptions, u as GeocodeResult, X as ReverseGeocodeResponse } from '../client-Cd22y5wG.cjs';
|
|
4
|
+
import { e as OlaMapsClientInput, C as CoordinateInput } from '../common-Bt8xNzhK.cjs';
|
|
5
|
+
import '../maplibre/index.cjs';
|
|
6
|
+
|
|
7
|
+
interface OlaMapsProviderProps {
|
|
8
|
+
/** Pass a pre-instantiated `OlaMapsClient` OR `config` to create one automatically. */
|
|
9
|
+
client?: OlaMapsClient;
|
|
10
|
+
/** Client configuration (e.g. `{ baseUrl: '/api/ola-maps' }` or API key string). */
|
|
11
|
+
config?: OlaMapsClientInput;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provide a shared `OlaMapsClient` instance to descendant React components and hooks.
|
|
16
|
+
*/
|
|
17
|
+
declare function OlaMapsProvider({ client, config, children }: OlaMapsProviderProps): react.FunctionComponentElement<react.ProviderProps<OlaMapsClient | null>>;
|
|
18
|
+
/**
|
|
19
|
+
* Access the nearest `OlaMapsClient` provided by `<OlaMapsProvider>`.
|
|
20
|
+
*/
|
|
21
|
+
declare function useOlaMapsClient(): OlaMapsClient;
|
|
22
|
+
interface UseOlaAutocompleteOptions extends AutocompleteOptions {
|
|
23
|
+
/** Debounce delay in milliseconds before firing a search request (default: 250). */
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/** Minimum input length before querying Ola Maps (default: 2). */
|
|
26
|
+
minLength?: number;
|
|
27
|
+
/** Disable automatic querying when false (default: true). */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/** Optional explicit client override (defaults to context client). */
|
|
30
|
+
client?: OlaMapsClient;
|
|
31
|
+
}
|
|
32
|
+
interface UseOlaAutocompleteResult {
|
|
33
|
+
predictions: AutocompletePrediction[];
|
|
34
|
+
data: AutocompleteResponse | null;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
refetch: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Debounced Places Autocomplete hook with automatic `AbortController` cancellation
|
|
41
|
+
* on every keystroke and component unmount.
|
|
42
|
+
*/
|
|
43
|
+
declare function useOlaAutocomplete(input: string, options?: UseOlaAutocompleteOptions): UseOlaAutocompleteResult;
|
|
44
|
+
interface UseOlaDirectionsOptions extends DirectionsOptions {
|
|
45
|
+
/** Disable automatic querying when false (default: true). */
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
/** Optional explicit client override (defaults to context client). */
|
|
48
|
+
client?: OlaMapsClient;
|
|
49
|
+
}
|
|
50
|
+
interface UseOlaDirectionsResult {
|
|
51
|
+
routes: Route[];
|
|
52
|
+
data: DirectionsResponse | null;
|
|
53
|
+
loading: boolean;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
refetch: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Fetch turn-by-turn directions reactively with automatic `AbortController` cancellation.
|
|
59
|
+
*/
|
|
60
|
+
declare function useOlaDirections(origin: CoordinateInput | null | undefined, destination: CoordinateInput | null | undefined, options?: UseOlaDirectionsOptions): UseOlaDirectionsResult;
|
|
61
|
+
interface UseOlaReverseGeocodeOptions extends ReverseGeocodeOptions {
|
|
62
|
+
enabled?: boolean;
|
|
63
|
+
client?: OlaMapsClient;
|
|
64
|
+
}
|
|
65
|
+
interface UseOlaReverseGeocodeResult {
|
|
66
|
+
results: GeocodeResult[];
|
|
67
|
+
data: ReverseGeocodeResponse | null;
|
|
68
|
+
loading: boolean;
|
|
69
|
+
error: Error | null;
|
|
70
|
+
refetch: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reverse-geocode a coordinate reactively with automatic `AbortController` cancellation.
|
|
74
|
+
*/
|
|
75
|
+
declare function useOlaReverseGeocode(coordinate: Exclude<CoordinateInput, string> | null | undefined, options?: UseOlaReverseGeocodeOptions): UseOlaReverseGeocodeResult;
|
|
76
|
+
|
|
77
|
+
export { OlaMapsProvider, type OlaMapsProviderProps, type UseOlaAutocompleteOptions, type UseOlaAutocompleteResult, type UseOlaDirectionsOptions, type UseOlaDirectionsResult, type UseOlaReverseGeocodeOptions, type UseOlaReverseGeocodeResult, useOlaAutocomplete, useOlaDirections, useOlaMapsClient, useOlaReverseGeocode };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { O as OlaMapsClient, c as AutocompleteOptions, d as AutocompletePrediction, e as AutocompleteResponse, i as DirectionsOptions, Z as Route, j as DirectionsResponse, W as ReverseGeocodeOptions, u as GeocodeResult, X as ReverseGeocodeResponse } from '../client-DsBMyuG9.js';
|
|
4
|
+
import { e as OlaMapsClientInput, C as CoordinateInput } from '../common-Bt8xNzhK.js';
|
|
5
|
+
import '../maplibre/index.js';
|
|
6
|
+
|
|
7
|
+
interface OlaMapsProviderProps {
|
|
8
|
+
/** Pass a pre-instantiated `OlaMapsClient` OR `config` to create one automatically. */
|
|
9
|
+
client?: OlaMapsClient;
|
|
10
|
+
/** Client configuration (e.g. `{ baseUrl: '/api/ola-maps' }` or API key string). */
|
|
11
|
+
config?: OlaMapsClientInput;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provide a shared `OlaMapsClient` instance to descendant React components and hooks.
|
|
16
|
+
*/
|
|
17
|
+
declare function OlaMapsProvider({ client, config, children }: OlaMapsProviderProps): react.FunctionComponentElement<react.ProviderProps<OlaMapsClient | null>>;
|
|
18
|
+
/**
|
|
19
|
+
* Access the nearest `OlaMapsClient` provided by `<OlaMapsProvider>`.
|
|
20
|
+
*/
|
|
21
|
+
declare function useOlaMapsClient(): OlaMapsClient;
|
|
22
|
+
interface UseOlaAutocompleteOptions extends AutocompleteOptions {
|
|
23
|
+
/** Debounce delay in milliseconds before firing a search request (default: 250). */
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/** Minimum input length before querying Ola Maps (default: 2). */
|
|
26
|
+
minLength?: number;
|
|
27
|
+
/** Disable automatic querying when false (default: true). */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/** Optional explicit client override (defaults to context client). */
|
|
30
|
+
client?: OlaMapsClient;
|
|
31
|
+
}
|
|
32
|
+
interface UseOlaAutocompleteResult {
|
|
33
|
+
predictions: AutocompletePrediction[];
|
|
34
|
+
data: AutocompleteResponse | null;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
refetch: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Debounced Places Autocomplete hook with automatic `AbortController` cancellation
|
|
41
|
+
* on every keystroke and component unmount.
|
|
42
|
+
*/
|
|
43
|
+
declare function useOlaAutocomplete(input: string, options?: UseOlaAutocompleteOptions): UseOlaAutocompleteResult;
|
|
44
|
+
interface UseOlaDirectionsOptions extends DirectionsOptions {
|
|
45
|
+
/** Disable automatic querying when false (default: true). */
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
/** Optional explicit client override (defaults to context client). */
|
|
48
|
+
client?: OlaMapsClient;
|
|
49
|
+
}
|
|
50
|
+
interface UseOlaDirectionsResult {
|
|
51
|
+
routes: Route[];
|
|
52
|
+
data: DirectionsResponse | null;
|
|
53
|
+
loading: boolean;
|
|
54
|
+
error: Error | null;
|
|
55
|
+
refetch: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Fetch turn-by-turn directions reactively with automatic `AbortController` cancellation.
|
|
59
|
+
*/
|
|
60
|
+
declare function useOlaDirections(origin: CoordinateInput | null | undefined, destination: CoordinateInput | null | undefined, options?: UseOlaDirectionsOptions): UseOlaDirectionsResult;
|
|
61
|
+
interface UseOlaReverseGeocodeOptions extends ReverseGeocodeOptions {
|
|
62
|
+
enabled?: boolean;
|
|
63
|
+
client?: OlaMapsClient;
|
|
64
|
+
}
|
|
65
|
+
interface UseOlaReverseGeocodeResult {
|
|
66
|
+
results: GeocodeResult[];
|
|
67
|
+
data: ReverseGeocodeResponse | null;
|
|
68
|
+
loading: boolean;
|
|
69
|
+
error: Error | null;
|
|
70
|
+
refetch: () => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reverse-geocode a coordinate reactively with automatic `AbortController` cancellation.
|
|
74
|
+
*/
|
|
75
|
+
declare function useOlaReverseGeocode(coordinate: Exclude<CoordinateInput, string> | null | undefined, options?: UseOlaReverseGeocodeOptions): UseOlaReverseGeocodeResult;
|
|
76
|
+
|
|
77
|
+
export { OlaMapsProvider, type OlaMapsProviderProps, type UseOlaAutocompleteOptions, type UseOlaAutocompleteResult, type UseOlaDirectionsOptions, type UseOlaDirectionsResult, type UseOlaReverseGeocodeOptions, type UseOlaReverseGeocodeResult, useOlaAutocomplete, useOlaDirections, useOlaMapsClient, useOlaReverseGeocode };
|