@mapslibvn/react 0.4.0 → 0.5.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/README.md CHANGED
@@ -1,6 +1,72 @@
1
1
  # @mapslibvn/react
2
2
 
3
- React bindings cho MapsLibVN: `<MapsLibVNMap>`, `<Marker>`, `useMap()` và `usePlaces()`.
3
+ [![npm version](https://img.shields.io/npm/v/@mapslibvn/react.svg)](https://www.npmjs.com/package/@mapslibvn/react)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@mapslibvn/react.svg)](https://www.npmjs.com/package/@mapslibvn/react)
5
+ [![minzipped size](https://img.shields.io/bundlephobia/minzip/@mapslibvn/react)](https://bundlephobia.com/package/@mapslibvn/react)
6
+ [![license](https://img.shields.io/npm/l/@mapslibvn/react.svg)](https://www.npmjs.com/package/@mapslibvn/react)
7
+
8
+ **Idiomatic React bindings for MapsLibVN.** Drop a Vietnam-ready map, search box and turn-by-turn navigation into any React app with `<MapsLibVNMap>`, `<Marker>`, `useMap()`, `usePlaces()` and `useNavigation()` — no imperative MapLibre plumbing required.
9
+
10
+ Built on top of [`@mapslibvn/web`](https://www.npmjs.com/package/@mapslibvn/web) and [`@mapslibvn/core`](https://www.npmjs.com/package/@mapslibvn/core), so every feature of the underlying engine (Vietnamese search, POI sources, navigation) is available through familiar React patterns.
11
+
12
+ ## Why teams pick it
13
+
14
+ - ⚛️ **Declarative by default** — `<MapsLibVNMap>` mounts a real MapLibre map, exposes it through `useMap()`, and only renders `children` (markers, overlays) once the map is ready.
15
+ - 🧠 **Smart re-renders** — changing `apiKey`, `style`, `center` or `zoom` recreates the map; changing `onLoad`, `onPoiClick`, `className` or `children` does not, so inline handlers are safe to pass every render.
16
+ - 🔎 **`usePlaces()` autocomplete hook** — debounced, cancels stale requests, keeps previous results while loading (SWR-style), and needs only 2 characters to start searching.
17
+ - 🧭 **`useNavigation()`** — subscribe to turn-by-turn `status` and `progress` from anywhere in your component tree, backed by the same navigation engine as the web SDK.
18
+ - 🇻🇳 **All of `@mapslibvn/core`'s Vietnamese search smarts** — diacritics-insensitive matching, address parsing, and configurable POI sources (OSM / Overture / Foursquare) — available through simple props.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @mapslibvn/react maplibre-gl@^6.4.1 react
24
+ ```
25
+
26
+ Requires React 18+ and a WebGL2-capable browser. Load MapLibre's CSS once at your app's entry point.
27
+
28
+ ## Quick start
29
+
30
+ ```tsx
31
+ import { MapsLibVNMap, Marker } from '@mapslibvn/react';
32
+ import 'maplibre-gl/dist/maplibre-gl.css';
33
+
34
+ export function BanDo() {
35
+ return (
36
+ <MapsLibVNMap
37
+ apiKey="mlv_live_…"
38
+ apiBase="https://api.ai-solutions.io.vn"
39
+ containerStyle={{ height: 400 }}
40
+ >
41
+ <Marker lng={106.6981} lat={10.7725} />
42
+ </MapsLibVNMap>
43
+ );
44
+ }
45
+ ```
46
+
47
+ The parent element needs a real height. Don't hide or disable attribution; Web keys must be origin-restricted.
48
+
49
+ 📖 Docs: <https://mapslibvn-docs.pages.dev/react/>
50
+
51
+ 📦 Part of the MapsLibVN SDK family: [`@mapslibvn/core`](https://www.npmjs.com/package/@mapslibvn/core) · [`@mapslibvn/web`](https://www.npmjs.com/package/@mapslibvn/web) · [`@mapslibvn/react-native`](https://www.npmjs.com/package/@mapslibvn/react-native)
52
+
53
+ Source license: MIT; see `THIRD_PARTY_NOTICES.md` for dependency and data licenses.
54
+
55
+ ---
56
+
57
+ ## Tiếng Việt
58
+
59
+ **Binding React chuẩn phong cách cho MapsLibVN.** Đưa bản đồ, ô tìm kiếm và dẫn đường "Việt Nam trước" vào bất kỳ app React nào chỉ với `<MapsLibVNMap>`, `<Marker>`, `useMap()`, `usePlaces()` và `useNavigation()` — không cần tự tay nối dây MapLibre theo kiểu mệnh lệnh.
60
+
61
+ Xây trên nền [`@mapslibvn/web`](https://www.npmjs.com/package/@mapslibvn/web) và [`@mapslibvn/core`](https://www.npmjs.com/package/@mapslibvn/core), nên mọi tính năng của engine bên dưới (tìm kiếm tiếng Việt, chọn nguồn POI, dẫn đường) đều dùng được qua các pattern React quen thuộc.
62
+
63
+ ## Vì sao nên chọn
64
+
65
+ - ⚛️ **Khai báo (declarative) theo mặc định** — `<MapsLibVNMap>` dựng một bản đồ MapLibre thật, đưa ra ngoài qua `useMap()`, và chỉ render `children` (marker, lớp phủ) sau khi bản đồ đã sẵn sàng.
66
+ - 🧠 **Re-render thông minh** — đổi `apiKey`, `style`, `center` hay `zoom` sẽ tạo lại bản đồ; đổi `onLoad`, `onPoiClick`, `className` hay `children` thì không, nên truyền handler dạng inline mỗi lần render vẫn an toàn.
67
+ - 🔎 **Hook autocomplete `usePlaces()`** — có debounce, huỷ request cũ khi có request mới, giữ kết quả cũ trong lúc tải (kiểu SWR), chỉ cần 2 ký tự là bắt đầu tìm.
68
+ - 🧭 **`useNavigation()`** — theo dõi `status` và `progress` dẫn đường từ bất kỳ đâu trong cây component, dùng chung engine dẫn đường với SDK web.
69
+ - 🇻🇳 **Trọn vẹn khả năng tìm kiếm tiếng Việt của `@mapslibvn/core`** — khớp không phân biệt dấu, phân tích địa chỉ, và chọn nguồn POI (OSM / Overture / Foursquare) — tất cả chỉ qua vài prop đơn giản.
4
70
 
5
71
  ## Cài đặt
6
72
 
@@ -10,7 +76,7 @@ npm install @mapslibvn/react maplibre-gl@^6.4.1 react
10
76
 
11
77
  Yêu cầu React 18+ và trình duyệt hỗ trợ WebGL2. Nạp CSS của MapLibre một lần ở điểm vào ứng dụng.
12
78
 
13
- ## dụ
79
+ ## Bắt đầu nhanh
14
80
 
15
81
  ```tsx
16
82
  import { MapsLibVNMap, Marker } from '@mapslibvn/react';
@@ -29,9 +95,10 @@ export function BanDo() {
29
95
  }
30
96
  ```
31
97
 
32
- Phần tử cha phải có chiều cao thật. Không tắt hoặc che attribution; khóa Web phải giới hạn đúng
33
- origin.
98
+ Phần tử cha phải có chiều cao thật. Không tắt hoặc che attribution; khóa Web phải giới hạn đúng origin.
99
+
100
+ 📖 Tài liệu: <https://mapslibvn-docs.pages.dev/react/>
34
101
 
35
- Tài liệu: <https://mapslibvn-docs.pages.dev/react/>
102
+ 📦 Nằm trong họ SDK MapsLibVN: [`@mapslibvn/core`](https://www.npmjs.com/package/@mapslibvn/core) · [`@mapslibvn/web`](https://www.npmjs.com/package/@mapslibvn/web) · [`@mapslibvn/react-native`](https://www.npmjs.com/package/@mapslibvn/react-native)
36
103
 
37
104
  Giấy phép mã nguồn: MIT; xem `THIRD_PARTY_NOTICES.md` cho giấy phép phụ thuộc và dữ liệu.
@@ -9,7 +9,7 @@ MapsLibVN **không liên kết với, không được tài trợ hay chứng th
9
9
  nhãn hiệu của bên thứ ba; tên đó xuất hiện ở đây và trong tài liệu chỉ để mô tả nguồn gốc kỹ
10
10
  thuật của thư viện mà MapsLibVN sử dụng.
11
11
 
12
- Cập nhật: 04/09/2026.
12
+ Cập nhật: 12/09/2026.
13
13
 
14
14
  ## 1. Thư viện được đóng gói hoặc là peer dependency của SDK
15
15
 
@@ -20,6 +20,8 @@ Cập nhật: 04/09/2026.
20
20
  | react, react-dom | 18.3.1 (peer, chỉ `@mapslibvn/react`) | MIT | |
21
21
  | @maplibre/maplibre-react-native | 11.3.8 (peer, chỉ `@mapslibvn/react-native`) | MIT | bộ vẽ bản đồ native iOS/Android |
22
22
  | react, react-native | react ≥ 19.1, react-native ≥ 0.80 (peer, chỉ `@mapslibvn/react-native`) | MIT | |
23
+ | expo-location, expo-task-manager | 57.0.17 (peer **tuỳ chọn**, chỉ entry `@mapslibvn/react-native/expo`) | MIT | định vị tiền cảnh và nền cho dẫn đường |
24
+ | expo-speech, expo-audio, expo-keep-awake | 57.0.3 / 57.0.5 / 57.0.1 (peer **tuỳ chọn**, chỉ entry `@mapslibvn/react-native/expo`) | MIT | đọc câu chỉ dẫn, phiên âm thanh khi nền, giữ màn hình sáng |
23
25
 
24
26
  Nguyên văn giấy phép ở mục 4.
25
27
 
@@ -385,9 +387,38 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
385
387
  Gói này nhúng MapLibre Native (Android, iOS) khi build app — xem thông báo giấy phép trong
386
388
  chính gói đó cho các thành phần native.
387
389
 
390
+ ### 4.9 expo-location, expo-task-manager, expo-speech, expo-audio, expo-keep-awake — MIT
391
+
392
+ ```
393
+ The MIT License (MIT)
394
+
395
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
396
+
397
+ Permission is hereby granted, free of charge, to any person obtaining a copy
398
+ of this software and associated documentation files (the "Software"), to deal
399
+ in the Software without restriction, including without limitation the rights
400
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
401
+ copies of the Software, and to permit persons to whom the Software is
402
+ furnished to do so, subject to the following conditions:
403
+
404
+ The above copyright notice and this permission notice shall be included in all
405
+ copies or substantial portions of the Software.
406
+
407
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
408
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
409
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
410
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
411
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
412
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
413
+ SOFTWARE.
414
+ ```
415
+
416
+ Các gói này là peer dependency **tuỳ chọn**: chỉ app import `@mapslibvn/react-native/expo` (dẫn
417
+ đường) mới cài; SDK không đóng gói mã của chúng.
418
+
388
419
  ## 5. Công cụ phía máy chủ (không phân phối, liệt kê để minh bạch)
389
420
 
390
421
  Planetiler (Apache-2.0), tippecanoe (BSD-2-Clause), osmium-tool (GPL-3.0 — dùng như công cụ
391
422
  dòng lệnh, không liên kết mã), pyosmium (BSD-2-Clause), DuckDB (MIT), PostgreSQL
392
- (PostgreSQL License), PostGIS (GPL-2.0 — chạy như dịch vụ), Hono (MIT), cloudflared
423
+ (PostgreSQL License), PostGIS (GPL-2.0 — chạy như dịch vụ), Valhalla (MIT — engine chỉ đường, chạy như dịch vụ riêng trên máy chủ, không liên kết mã), Hono (MIT), cloudflared
393
424
  (Apache-2.0), Astro Starlight (MIT), Vitest (MIT), Playwright (Apache-2.0).
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
- import { CreateMapOptions, PoiFeature, MapsLibVNMap as MapsLibVNMap$1, MarkerOptions } from '@mapslibvn/web';
4
- import { MapsLibVNClient, AutocompleteItem } from '@mapslibvn/core';
5
- export { AutocompleteItem, MapsLibVNClient, Place, PoiSource } from '@mapslibvn/core';
3
+ import { CreateMapOptions, PoiFeature, MapsLibVNMap as MapsLibVNMap$1, MarkerOptions, NavigationStartOptions } from '@mapslibvn/web';
4
+ export { NavigationStartOptions } from '@mapslibvn/web';
5
+ import { MapsLibVNClient, AutocompleteItem, NavigationStatus, NavigationProgress } from '@mapslibvn/core';
6
+ export { Announcement, AutocompleteItem, MapsLibVNClient, NavigationProgress, NavigationStatus, Place, PoiSource, RouteProvider } from '@mapslibvn/core';
6
7
 
7
8
  interface MapsLibVNMapProps extends Omit<CreateMapOptions, 'container'> {
8
9
  className?: string;
@@ -33,4 +34,15 @@ interface UsePlacesResult {
33
34
  /** Autocomplete kiểu SWR: giữ items cũ khi tải và bỏ qua response của query đã huỷ. */
34
35
  declare function usePlaces(query: string, options?: UsePlacesOptions): UsePlacesResult;
35
36
 
36
- export { MapsLibVNMap, type MapsLibVNMapProps, Marker, type UsePlacesOptions, type UsePlacesResult, useMap, usePlaces };
37
+ interface UseNavigationResult {
38
+ status: NavigationStatus;
39
+ progress: NavigationProgress | null;
40
+ start(opts: NavigationStartOptions): void;
41
+ stop(): void;
42
+ recenter(): void;
43
+ reroute(): Promise<void>;
44
+ }
45
+ /** Trạng thái dẫn đường của bản đồ trong context, re-render theo `status` và `progress` (spec B 5.6). */
46
+ declare function useNavigation(): UseNavigationResult;
47
+
48
+ export { MapsLibVNMap, type MapsLibVNMapProps, Marker, type UseNavigationResult, type UsePlacesOptions, type UsePlacesResult, useMap, useNavigation, usePlaces };
package/dist/index.js CHANGED
@@ -141,9 +141,48 @@ function usePlaces(query, options = {}) {
141
141
  }, [client, query, nearKey, options.limit, options.debounceMs]);
142
142
  return { items, loading, error };
143
143
  }
144
+
145
+ // src/use-navigation.ts
146
+ import { useCallback, useSyncExternalStore } from "react";
147
+ function useNavigation() {
148
+ const nav = useMap().navigation;
149
+ const subscribeStatus = useCallback(
150
+ (onChange) => {
151
+ nav.on("status", onChange);
152
+ return () => nav.off("status", onChange);
153
+ },
154
+ [nav]
155
+ );
156
+ const subscribeProgress = useCallback(
157
+ (onChange) => {
158
+ nav.on("progress", onChange);
159
+ return () => nav.off("progress", onChange);
160
+ },
161
+ [nav]
162
+ );
163
+ const status = useSyncExternalStore(
164
+ subscribeStatus,
165
+ () => nav.status,
166
+ () => nav.status
167
+ );
168
+ const progress = useSyncExternalStore(
169
+ subscribeProgress,
170
+ () => nav.state,
171
+ () => nav.state
172
+ );
173
+ return {
174
+ status,
175
+ progress,
176
+ start: (opts) => nav.start(opts),
177
+ stop: () => nav.stop(),
178
+ recenter: () => nav.recenter(),
179
+ reroute: () => nav.reroute()
180
+ };
181
+ }
144
182
  export {
145
183
  MapsLibVNMap,
146
184
  Marker,
147
185
  useMap,
186
+ useNavigation,
148
187
  usePlaces
149
188
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapslibvn/react",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "React bindings MapsLibVN: <MapsLibVNMap>, <Marker>, useMap, usePlaces",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,13 +24,13 @@
24
24
  "react": ">=18"
25
25
  },
26
26
  "dependencies": {
27
- "@mapslibvn/core": "0.4.0",
28
- "@mapslibvn/web": "0.4.0"
27
+ "@mapslibvn/core": "0.5.0",
28
+ "@mapslibvn/web": "0.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/react": "^18.3.0",
31
+ "@types/react": "^19.3.0",
32
32
  "maplibre-gl": "^6.8.0",
33
- "react": "^18.3.0",
33
+ "react": "^19.3.0",
34
34
  "tsup": "^8.3.0",
35
35
  "typescript": "^5.6.0"
36
36
  },