react-bkoi-gl 2.1.0 → 2.2.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 +90 -7
- package/dist/index.cjs +8218 -387
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +8217 -388
- package/dist/index.js.map +1 -1
- package/dist/styles/index.d.ts +1 -1
- package/dist/styles/react-bkoi-gl.css +49 -2
- package/package.json +36 -42
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<h1 align="center">react-bkoi-gl | <a href="https://docs.barikoi.com/npm/npm-intro">Docs</a></h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/v/react-bkoi-gl.svg" alt="npm version"></a>
|
|
5
|
-
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/dw/react-bkoi-gl" alt="npm downloads"></a>
|
|
6
|
-
<a href="https://bundlephobia.com/package/react-bkoi-gl"><img src="https://img.shields.io/bundlephobia/min/react-bkoi-gl" alt="Bundle Size"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/v/react-bkoi-gl.svg?logo=npm&logoColor=white" alt="npm version"></a>
|
|
7
5
|
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white" alt="TypeScript"></a>
|
|
8
|
-
<a href="https://
|
|
9
|
-
<a href="https://
|
|
6
|
+
<a href="https://react.dev/"><img src="https://img.shields.io/badge/React-%E2%89%A518-149eca?logo=react&logoColor=white" alt="React ≥18"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/react-bkoi-gl"><img src="https://img.shields.io/npm/dw/react-bkoi-gl.svg?label=downloads" alt="npm weekly downloads"></a>
|
|
8
|
+
<a href="https://github.com/barikoi/react-bkoi-gl/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/react-bkoi-gl.svg?label=license" alt="license"></a>
|
|
10
9
|
</p>
|
|
11
10
|
|
|
12
11
|
## Description
|
|
@@ -28,7 +27,7 @@ Powered by <a href="https://barikoi.com/">Barikoi - Maps for Businesses</a>
|
|
|
28
27
|
|
|
29
28
|
## Installation
|
|
30
29
|
|
|
31
|
-
Using `react-bkoi-gl` requires `react >=
|
|
30
|
+
Using `react-bkoi-gl` requires `react >= 18` (the library uses the `useId` and `useSyncExternalStore` React 18 APIs). Map rendering is bundled — no separate map engine install needed.
|
|
32
31
|
|
|
33
32
|
```bash
|
|
34
33
|
npm install react-bkoi-gl
|
|
@@ -54,6 +53,18 @@ To access Barikoi's API services, you need to:
|
|
|
54
53
|
2. Verify with your phone number
|
|
55
54
|
3. Claim your API key
|
|
56
55
|
|
|
56
|
+
### API Key Security
|
|
57
|
+
|
|
58
|
+
Your Barikoi API key is embedded in the `mapStyle` URL passed to `<Map>`, so it is exposed to the browser. Treat it accordingly:
|
|
59
|
+
|
|
60
|
+
- **Restrict keys by domain.** In the Barikoi Developer Dashboard, limit each key to the exact origins that will use it (e.g. `example.com`, `www.example.com`). A domain-restricted key is useless if it leaks.
|
|
61
|
+
- **Use separate keys per environment** (local dev, staging, production) so you can rotate production keys without disrupting development.
|
|
62
|
+
- **Load keys from configuration, not source.** Inject the key via an environment variable or your host's secret manager; never hardcode a production key in source control.
|
|
63
|
+
- **Rotate immediately on exposure.** If a key is committed to a public repo, appears in logs, or is shared accidentally, disable it in the dashboard and issue a replacement, then update the deployed `mapStyle` URL.
|
|
64
|
+
- **Monitor usage.** Review request volume in the dashboard for unexpected spikes that can indicate key theft.
|
|
65
|
+
|
|
66
|
+
> A browser-embedded key cannot be fully hidden. **Domain restriction and rotation are your primary defenses** — not obscurity.
|
|
67
|
+
|
|
57
68
|
## Quick Start
|
|
58
69
|
|
|
59
70
|
```tsx
|
|
@@ -86,6 +97,76 @@ function App() {
|
|
|
86
97
|
|
|
87
98
|
---
|
|
88
99
|
|
|
100
|
+
## Requirements
|
|
101
|
+
|
|
102
|
+
| Requirement | Version |
|
|
103
|
+
|-------------|---------|
|
|
104
|
+
| `react`, `react-dom` | `>=18.0.0` (uses `useId`, `useSyncExternalStore`) |
|
|
105
|
+
| Node | `>=18.18.0` (build/dev only) |
|
|
106
|
+
|
|
107
|
+
Map rendering is bundled — no separate map engine install needed.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Next.js & SSR
|
|
112
|
+
|
|
113
|
+
`react-bkoi-gl` renders into a `<canvas>` and must run client-side. In Next.js App Router, mark consumer components with `"use client"`:
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
// app/MapView.tsx
|
|
117
|
+
"use client";
|
|
118
|
+
|
|
119
|
+
import { Map } from "react-bkoi-gl";
|
|
120
|
+
import "react-bkoi-gl/styles";
|
|
121
|
+
|
|
122
|
+
export default function MapView() {
|
|
123
|
+
return (
|
|
124
|
+
<Map
|
|
125
|
+
mapStyle={`https://map.barikoi.com/styles/osm-liberty/style.json?key=${process.env.NEXT_PUBLIC_BARIKOI_API_KEY}`}
|
|
126
|
+
initialViewState={{ longitude: 90.3938, latitude: 23.8216, zoom: 12 }}
|
|
127
|
+
style={{ width: "100%", height: "100vh" }}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The library uses `useId`, `useSyncExternalStore`, and `useLayoutEffect` — all client-only hooks. SSR will warn or crash without the directive.
|
|
134
|
+
|
|
135
|
+
For Pages Router, dynamic-import with `ssr: false`:
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import dynamic from "next/dynamic";
|
|
139
|
+
const MapView = dynamic(() => import("../components/MapView"), { ssr: false });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Logging
|
|
145
|
+
|
|
146
|
+
All `console.warn` / `console.error` calls route through an injectable `logger`, so you can capture warnings in production or feed them to your telemetry provider.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { setLogger } from "react-bkoi-gl";
|
|
150
|
+
|
|
151
|
+
setLogger({
|
|
152
|
+
warn: (msg, ...args) => Sentry.captureMessage(String(msg)),
|
|
153
|
+
error: (err, ...args) => Sentry.captureException(err),
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Non-fatal warnings (transient rendering errors before the style finishes loading, etc.) are also surfaced via the `<Map onWarning={...}>` prop when you want per-instance handling.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Accessibility
|
|
162
|
+
|
|
163
|
+
- The map canvas gets `role="region"` and `aria-label="Map"` automatically.
|
|
164
|
+
- For keyboard navigation (arrow keys to pan, `+`/`-` to zoom), keep the `keyboard` prop enabled (default: `true`).
|
|
165
|
+
- `GlobeControl`, `MinimapControl`, `NavigationControl`, etc. set `type="button"`, `aria-label`, and `title` automatically. Custom elements passed to `GlobeControl` via `buttonElement` must be `<button>` or have `role="button"`, otherwise they are refused with a console warning.
|
|
166
|
+
- `MinimapControl` announces collapse/expand state via a visually-hidden `aria-live="polite"` region.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
89
170
|
## Components
|
|
90
171
|
|
|
91
172
|
Build maps by composing the `Map` component with layers, sources, UI controls, and hooks.
|
|
@@ -134,7 +215,6 @@ The core component that renders a Barikoi map. All other components must be chil
|
|
|
134
215
|
| `mapStyle` | `string \| StyleSpecification` | Required | Map style URL or style object |
|
|
135
216
|
| `initialViewState` | `object` | - | Initial view state (longitude, latitude, zoom, etc.) |
|
|
136
217
|
| `viewState` | `object` | - | Controlled view state |
|
|
137
|
-
| `mapLib` | `MapLib \| Promise<MapLib>` | - | Custom map library instance |
|
|
138
218
|
| `reuseMaps` | `boolean` | `false` | Reuse map instances for performance |
|
|
139
219
|
| `id` | `string` | - | Container element ID |
|
|
140
220
|
| `style` | `CSSProperties` | - | Container CSS styles |
|
|
@@ -144,6 +224,9 @@ The core component that renders a Barikoi map. All other components must be chil
|
|
|
144
224
|
| `onMoveEnd` | `(e: ViewStateChangeEvent) => void` | - | Move end handler |
|
|
145
225
|
| `onZoomEnd` | `(e: ViewStateChangeEvent) => void` | - | Zoom end handler |
|
|
146
226
|
| `onError` | `(e: ErrorEvent) => void` | - | Error handler |
|
|
227
|
+
| `onWarning` | `(e: ErrorEvent) => void` | - | Non-fatal warning handler (e.g. transient `queryRenderedFeatures` errors before style load). Falls back to `console.warn` when omitted. |
|
|
228
|
+
| `showBarikoiLogo` | `boolean` | `true` | Render the Barikoi logo control (bottom-left). |
|
|
229
|
+
| `showAttribution` | `boolean` | `true` | Render the attribution control (bottom-right). Attribution is required by the OSM/MapLibre license terms — keep this enabled unless you provide attribution elsewhere. |
|
|
147
230
|
|
|
148
231
|
And all [MapLibre Map options](https://maplibre.org/maplibre-gl-js/docs/API/types/MapOptions/).
|
|
149
232
|
|