@mapslibvn/react-native 0.4.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.
@@ -0,0 +1,303 @@
1
+ import * as react from 'react';
2
+ import { RefObject, ReactNode, ReactElement } from 'react';
3
+ import { StyleProp, ViewStyle } from 'react-native';
4
+ import { MapRef, CameraRef, Anchor } from '@maplibre/maplibre-react-native';
5
+
6
+ /**
7
+ * Nguồn POI và profile archive (spec 07/09 mục 4). Đây là nguồn sự thật duy nhất cho API, SDK và
8
+ * pipeline: thêm profile mới = thêm một dòng vào POI_SOURCE_PROFILES + một lần export-tiles.
9
+ */
10
+ declare const POI_SOURCES: readonly ["osm", "overture", "fsq"];
11
+ type PoiSource = (typeof POI_SOURCES)[number];
12
+
13
+ /** Kiểu dữ liệu Places API (spec 6.1) dùng chung cho Worker và SDK. */
14
+ interface PlaceCategory {
15
+ code: string;
16
+ group: string;
17
+ name_vi: string;
18
+ name_en: string;
19
+ }
20
+ interface PlaceAddress {
21
+ housenumber?: string;
22
+ street?: string;
23
+ ward?: string;
24
+ province?: string;
25
+ text?: string;
26
+ }
27
+ interface Place {
28
+ id: string;
29
+ name: string;
30
+ category: PlaceCategory | null;
31
+ lat: number;
32
+ lng: number;
33
+ address: PlaceAddress;
34
+ contact?: Record<string, unknown> | null;
35
+ hours?: unknown;
36
+ quality_score: number | null;
37
+ status: 'active' | 'closed' | 'pending' | 'rejected';
38
+ updated_at: string;
39
+ }
40
+ interface PlaceSource {
41
+ source: 'osm' | 'overture' | 'fsq';
42
+ source_id: string;
43
+ role: 'primary' | 'secondary';
44
+ }
45
+ interface PlaceDetails extends Place {
46
+ sources: PlaceSource[];
47
+ attribution: {
48
+ text: string;
49
+ html: string;
50
+ };
51
+ }
52
+ type GeocodePrecision = 'rooftop' | 'alley' | 'interpolated' | 'street' | 'ward' | 'district' | 'province';
53
+ type AutocompleteType = 'poi' | 'street' | 'address' | 'area';
54
+ interface AutocompleteItem {
55
+ type: AutocompleteType;
56
+ id?: string;
57
+ name: string;
58
+ secondary: string;
59
+ lat: number;
60
+ lng: number;
61
+ precision?: GeocodePrecision;
62
+ score: number;
63
+ bbox?: [number, number, number, number];
64
+ /** Tên thay thế (OSM `alt_name`/`old_name`) đã khớp truy vấn, ví dụ "Công Lý" (spec 6.3). */
65
+ matched_alt?: string;
66
+ }
67
+ interface GeocodeMatched {
68
+ housenumber?: string;
69
+ street?: string;
70
+ ward?: string;
71
+ province?: string;
72
+ former?: {
73
+ ward?: string;
74
+ district?: string;
75
+ province?: string;
76
+ };
77
+ }
78
+ interface GeocodeItem {
79
+ lat: number;
80
+ lng: number;
81
+ precision: GeocodePrecision;
82
+ confidence: number;
83
+ matched: GeocodeMatched;
84
+ display_name: string;
85
+ bbox?: [number, number, number, number];
86
+ }
87
+ interface ReverseAddress {
88
+ approx_housenumber?: string;
89
+ street?: string;
90
+ ward?: string;
91
+ province?: string;
92
+ display_name: string;
93
+ }
94
+ interface ReverseResponse {
95
+ address: ReverseAddress;
96
+ nearest_poi: Place | null;
97
+ }
98
+ type EditKind = 'create' | 'update' | 'close' | 'reopen' | 'report';
99
+ /** Trường được phép sửa/khai khi đóng góp (spec 6.1 + 6.5). */
100
+ interface EditChanges {
101
+ name?: string;
102
+ lat?: number;
103
+ lng?: number;
104
+ category?: string;
105
+ housenumber?: string;
106
+ street?: string;
107
+ ward?: string;
108
+ province?: string;
109
+ address_text?: string;
110
+ contact?: {
111
+ phone?: string[];
112
+ website?: string[];
113
+ facebook?: string;
114
+ };
115
+ /** Chuỗi opening_hours OSM hoặc {osm: chuỗi}. */
116
+ hours?: string | {
117
+ osm: string;
118
+ };
119
+ }
120
+ interface SuggestEditRequest {
121
+ /** Bắt buộc trừ kind='create'. */
122
+ poi_id?: string;
123
+ kind: EditKind;
124
+ changes?: EditChanges;
125
+ photo_url?: string;
126
+ note?: string;
127
+ /** Chuỗi ổn định theo người dùng cuối do app nhúng cấp — server chỉ lưu bản băm. */
128
+ end_user_token: string;
129
+ }
130
+ interface SuggestEditResponse {
131
+ edit_id: number;
132
+ status: 'pending' | 'auto_approved';
133
+ /** POI đích; với kind='create' là id POI mới (pending cho tới khi được duyệt). */
134
+ poi_id: string | null;
135
+ }
136
+ /** POI đọc từ tile lớp `poi` khi người dùng bấm — SDK web và React Native dùng chung. */
137
+ interface PoiFeature {
138
+ id: string;
139
+ name: string;
140
+ category: string;
141
+ group: string;
142
+ lngLat: [number, number];
143
+ }
144
+
145
+ type Theme = 'light' | 'dark';
146
+ interface ClientOptions {
147
+ /** Khoá API dạng mlv_live_… */
148
+ apiKey: string;
149
+ /** Gốc API, ví dụ https://maps-api.example.com */
150
+ baseUrl: string;
151
+ /** Cho phép tiêm fetch cho test hoặc môi trường không có global fetch. */
152
+ fetch?: typeof globalThis.fetch;
153
+ /**
154
+ * Header thêm cho mọi request, ví dụ `X-Bundle-Id` cho khoá `mobile` (spec 6.4).
155
+ * Không ghi đè được `X-Api-Key`.
156
+ */
157
+ headers?: Record<string, string>;
158
+ /**
159
+ * Tập nguồn POI cho bản đồ và Places API (spec 07/09). Mặc định cả ba nguồn.
160
+ * Áp cho autocomplete/search/nearby/reverse và `styleUrl`; `getPlace`/`geocode` không lọc.
161
+ */
162
+ poiSources?: readonly PoiSource[];
163
+ }
164
+ interface AttributionResponse {
165
+ text: string;
166
+ html: string;
167
+ links: {
168
+ text: string;
169
+ href: string;
170
+ license?: string;
171
+ }[];
172
+ }
173
+ declare function createClient(options: ClientOptions): {
174
+ baseUrl: string;
175
+ attribution: () => Promise<AttributionResponse>;
176
+ styleUrl: (theme: Theme) => string;
177
+ autocomplete: (q: string, opts?: {
178
+ near?: [number, number];
179
+ limit?: number;
180
+ types?: AutocompleteType[];
181
+ }) => Promise<{
182
+ items: AutocompleteItem[];
183
+ }>;
184
+ search: (q: string, opts?: {
185
+ category?: string;
186
+ near?: [number, number];
187
+ radius?: number;
188
+ bbox?: [number, number, number, number];
189
+ limit?: number;
190
+ offset?: number;
191
+ }) => Promise<{
192
+ items: Place[];
193
+ total: number;
194
+ }>;
195
+ nearby: (opts: {
196
+ lat: number;
197
+ lng: number;
198
+ radius?: number;
199
+ category?: string;
200
+ limit?: number;
201
+ }) => Promise<{
202
+ items: Place[];
203
+ }>;
204
+ getPlace: (id: string) => Promise<PlaceDetails>;
205
+ geocode: (q: string, opts?: {
206
+ near?: [number, number];
207
+ limit?: number;
208
+ }) => Promise<{
209
+ items: GeocodeItem[];
210
+ }>;
211
+ reverse: (lat: number, lng: number) => Promise<ReverseResponse>;
212
+ /** Gửi đóng góp/sửa POI (spec 6.1). Khoá phải có scope edits:write. */
213
+ suggestEdit: (edit: SuggestEditRequest) => Promise<SuggestEditResponse>;
214
+ };
215
+ type MapsLibVNClient = ReturnType<typeof createClient>;
216
+
217
+ /**
218
+ * Biến đổi style JSON thuần (không cần Map đang chạy) — dùng cho React Native, nơi wrapper
219
+ * không có API đổi layout property của lớp có sẵn. Web dùng `applyLanguage` lúc chạy nhưng
220
+ * chia sẻ `nameExpression`/`isNameLabelLayer` từ đây.
221
+ */
222
+ type Lang = 'vi' | 'en';
223
+
224
+ /** Tay cầm map — tương ứng `MapsLibVNMap` của web: `native` thay `gl`. */
225
+ interface MapHandle {
226
+ /** Ref `Map` của @maplibre/maplibre-react-native — không giấu gì. */
227
+ native: RefObject<MapRef | null>;
228
+ camera: RefObject<CameraRef | null>;
229
+ /** Client @mapslibvn/core với cùng khoá. */
230
+ places: MapsLibVNClient;
231
+ flyTo(center: [number, number], zoom?: number): void;
232
+ fitBounds(bbox: [number, number, number, number], padding?: number): void;
233
+ /** [west, south, east, north] */
234
+ getBounds(): Promise<[number, number, number, number]>;
235
+ }
236
+
237
+ declare const DEFAULT_CENTER: [number, number];
238
+ declare const DEFAULT_ZOOM = 12;
239
+ interface MapsLibVNMapProps {
240
+ apiKey: string;
241
+ /** Gốc API MapsLibVN, ví dụ https://api.ai-solutions.io.vn */
242
+ apiBase: string;
243
+ /** Theme 'light' | 'dark' hoặc URL style tuỳ biến — giống @mapslibvn/react. */
244
+ style?: Theme | string;
245
+ /** Giá trị KHỞI TẠO camera; đổi sau khi mount không tạo lại map — dùng useMap().flyTo. */
246
+ center?: [number, number];
247
+ zoom?: number;
248
+ lang?: Lang;
249
+ /** Hiển thị lớp POI — mặc định true */
250
+ poiLayer?: boolean;
251
+ /** Tập nguồn POI cho bản đồ và Places API — mặc định cả ba; đổi sau khi mount tạo lại map. */
252
+ poiSources?: readonly PoiSource[];
253
+ /** Attribution gọn (không có tuỳ chọn tắt) */
254
+ compactAttribution?: boolean;
255
+ /** Bundle id / application id của app → header X-Bundle-Id cho khoá mobile */
256
+ bundleId?: string;
257
+ /** Style của khung View bọc ngoài */
258
+ containerStyle?: StyleProp<ViewStyle>;
259
+ onLoad?: (map: MapHandle) => void;
260
+ onPoiClick?: (poi: PoiFeature) => void;
261
+ onError?: (error: Error) => void;
262
+ testID?: string;
263
+ children?: ReactNode;
264
+ }
265
+ declare function MapsLibVNMap({ apiKey, apiBase, style, center, zoom, lang, poiLayer, poiSources, compactAttribution, bundleId, containerStyle, onLoad, onPoiClick, onError, testID, children, }: MapsLibVNMapProps): react.JSX.Element;
266
+ /** Map hiện hành — chỉ dùng bên trong <MapsLibVNMap>. */
267
+ declare function useMap(): MapHandle;
268
+
269
+ /** Màu ghim mặc định của MapLibre. */
270
+ declare const DEFAULT_MARKER_COLOR = "#3FB1CE";
271
+ interface MarkerProps {
272
+ lng: number;
273
+ lat: number;
274
+ /** Màu ghim mặc định; bỏ qua khi có children */
275
+ color?: string;
276
+ /** Điểm neo — mặc định 'center' (ghim tròn) */
277
+ anchor?: Anchor;
278
+ onPress?: () => void;
279
+ /** View tuỳ ý thay ghim mặc định */
280
+ children?: ReactElement;
281
+ testID?: string;
282
+ }
283
+ declare function Marker({ lng, lat, color, anchor, onPress, children, testID, }: MarkerProps): react.JSX.Element;
284
+
285
+ interface UsePlacesOptions {
286
+ near?: [number, number];
287
+ limit?: number;
288
+ debounceMs?: number;
289
+ /** Client tường minh — bắt buộc khi hook nằm ngoài <MapsLibVNMap>. */
290
+ client?: MapsLibVNClient;
291
+ }
292
+ interface UsePlacesResult {
293
+ items: AutocompleteItem[];
294
+ loading: boolean;
295
+ error: Error | null;
296
+ }
297
+ /** Autocomplete kiểu SWR: giữ items cũ khi tải và bỏ qua response của query đã huỷ. */
298
+ declare function usePlaces(query: string, options?: UsePlacesOptions): UsePlacesResult;
299
+
300
+ /** Dòng gọn khi `compactAttribution`; bấm vào mở hộp thoại native với đủ nguồn. */
301
+ declare const COMPACT_ATTRIBUTION = "\u00A9 MapsLibVN \u00B7 \u00A9 OpenStreetMap contributors";
302
+
303
+ export { type AutocompleteItem, COMPACT_ATTRIBUTION, DEFAULT_CENTER, DEFAULT_MARKER_COLOR, DEFAULT_ZOOM, type Lang, type MapHandle, type MapsLibVNClient, MapsLibVNMap, type MapsLibVNMapProps, Marker, type MarkerProps, type Place, type PoiFeature, type PoiSource, type Theme, type UsePlacesOptions, type UsePlacesResult, useMap, usePlaces };