Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to monorepo #2459

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist/
node_modules/
test/src/utils/mapbox-gl-mock/*.js
test/
modules/**/test/
**/vite.config.js
examples/vite.config.local.js
10 changes: 6 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {getESLintConfig} = require('ocular-dev-tools/configuration');
const {getESLintConfig} = require('@vis.gl/dev-tools/configuration');

module.exports = getESLintConfig({
react: '16.8.2',
Expand All @@ -25,12 +25,14 @@ module.exports = getESLintConfig({
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'import/named': 0,
'@typescript-eslint/no-empty-function': ['warn', {allow: ['arrowFunctions']}],
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/restrict-plus-operands': 0
'@typescript-eslint/restrict-plus-operands': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-shadow': 1,
'@typescript-eslint/no-redundant-type-constituents': 1
}
}
]
Expand Down
57 changes: 42 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,58 @@ on:
- v*

jobs:
release-notes:
check_branch:
runs-on: ubuntu-22.04
outputs:
should_build: ${{ steps.permitted.outputs.result }}

if: github.repository_owner == 'visgl'
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Fetch remote branches
run: |
git fetch origin --depth=1

- name: Check if on permitted branch
id: permitted
run: |
result=
if git branch -a --contains $GITHUB_SHA | grep -q 'remotes/origin/master$'; then
result=true
elif git branch -a --contains $GITHUB_SHA | grep -q 'remotes/origin/.*-release$'; then
result=true
fi
echo "result=${result}" >> "$GITHUB_OUTPUT"

release:
runs-on: ubuntu-22.04
needs: check_branch
permissions:
contents: write

if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_build }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Use Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
- uses: volta-cli/action@2d68418f32546fd191eb666e232b321d5726484d # v4.1.1
with:
node-version: '18.x'
cache: 'yarn'

- name: Publish release
run: |
body=$(node scripts/github-release.js) &&
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/visgl/react-map-gl/releases \
-d "${body}" \
-H "Authorization: token ${GITHUB_TOKEN}"
- name: Install dependencies
run: yarn

- name: Build packages
run: npm run build

- name: Run tests from transpiled code
run: npx ocular-test dist

- name: Login to NPM
run: npm config set "//registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}"

- name: Publish to NPM
run: npx ocular-publish from-git
Pessimistress marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Use Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
- uses: volta-cli/action@2d68418f32546fd191eb666e232b321d5726484d # v4.1.1
with:
node-version: '18.x'
cache: "yarn"

- name: Install dependencies
run: |
Expand All @@ -27,6 +25,7 @@ jobs:
env:
VITE_MAPBOX_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }}
run: |
yarn lint
yarn test ci

- name: Coveralls
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ npm-debug.log
package-lock.json
examples/**/yarn.lock
test/**/yarn.lock
*/**/package-lock.json
**/package-lock.json
**/tsconfig.tsbuildinfo
yarn-error.log
.DS_Store
.reify-cache
tsconfig.tsbuildinfo

.idea
19 changes: 10 additions & 9 deletions .ocularrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/** @typedef {import('@vis.gl/dev-tools').OcularConfig} OcularConfig */
import {resolve} from 'path';

/** @type {OcularConfig} */
export default {
lint: {
paths: ['src', 'test', 'examples']
paths: ['modules', 'test', 'examples']
},

typescript: {
project: 'tsconfig.build.json'
coverage: {
test: 'browser'
},

aliases: {
'react-map-gl/test': resolve('./test'),
'react-map-gl': resolve('./src')
},
nodeAliases: {
'react-dom': resolve('./test/src/utils/react-dom-mock.js')
},

browserTest: {
Expand All @@ -24,6 +21,10 @@ export default {
entry: {
test: 'test/node.js',
'test-browser': 'test/browser.js',
size: ['test/size/all.js', 'test/size/map.js']
size: [
'test/size/mapbox-legacy.js',
'test/size/maplibre.js',
'test/size/mapbox.js'
]
}
};
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ npm install react-map-gl mapbox-gl
// Using Maplibre
import * as React from 'react';
import Map from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';

function App() {
return (
Expand All @@ -56,11 +57,13 @@ _or_
```js
// Using Mapbox
import * as React from 'react';
import Map from 'react-map-gl';
import Map from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';

function App() {
return (
<Map
// https://visgl.github.io/react-map-gl/docs/get-started/mapbox-tokens
mapboxAccessToken="<Mapbox access token>"
initialViewState={{
longitude: -100,
Expand All @@ -76,18 +79,6 @@ function App() {

Learn more with in our [Getting Started](https://visgl.github.io/react-map-gl/docs/get-started) guide.

### Using Mapbox Tokens

**Starting with v2.0, mapbox-gl requires a Mapbox token for any usage, with or without the Mapbox data service. See [about Mapbox tokens](/docs/get-started/mapbox-tokens.md) for your options.**

To show maps from a service such as Mapbox you will need to register on their website in order to retrieve an access token required by the map component, which will be used to identify you and start serving up map tiles. The service will be free until a certain level of traffic is exceeded.

There are several ways to provide a token to your app, as showcased in some of the example folders:

* Provide a `mapboxAccessToken` prop to the map component
* Set the `MapboxAccessToken` environment variable (or set `REACT_APP_MAPBOX_ACCESS_TOKEN` if you are using Create React App)
* Provide it in the URL, e.g `?access_token=TOKEN`


### Contribute

Expand Down
6 changes: 0 additions & 6 deletions babel.config.cjs

This file was deleted.

38 changes: 15 additions & 23 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@

# Introduction

<p align="center">
These docs are for
<a href="https://github.com/visgl/react-map-gl/tree/7.0-release/docs">
<img src="https://img.shields.io/badge/v7.0-brightgreen.svg?style=flat-square" />
</a>
Looking for an old version?
<a href="https://github.com/visgl/react-map-gl/tree/6.1-release/docs">
<img src="https://img.shields.io/badge/v6.1-brightgreen.svg?style=flat-square" />
</a>
<a href="https://github.com/visgl/react-map-gl/tree/5.3-release/docs">
<img src="https://img.shields.io/badge/v5.3-brightgreen.svg?style=flat-square" />
</a>
</p>
> These docs are for v8.0. For v7, see [here](https://github.com/visgl/react-map-gl/tree/7.1-release/docs).

react-map-gl is a suite of [React](http://facebook.github.io/react/) components for
[mapbox-gl](https://github.com/mapbox/mapbox-gl-js), [maplibre-gl](https://maplibre.org/maplibre-gl-js/docs/) or compatible libraries.
[mapbox-gl](https://www.npmjs.com/package/mapbox-gl), [maplibre-gl](https://www.npmjs.com/package/maplibre-gl) or compatible libraries.

| Library | Description |
| --- | --- |
| [MapLibre GL JS](https://github.com/MapLibre/maplibre-gl-js) | An open fork of mapbox-gl v1, that can be used without a mapbox token. |
| [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js) | The previous version of mapbox GL JS. This version is free open source and can be used with non-mapbox basemaps without a mapbox token. |
| [Mapbox GL JS v2](https://github.com/mapbox/mapbox-gl-js) | The latest version of Mapbox GL JS. Note that version 2 is not free open source, and a mapbox token is required and billable events are generated even if you do not use mapbox hosted basemaps. |
| Other mapbox-gl forks | It may be possible to use react-map-gl with other mapbox forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. |
| [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) | An Open-source TypeScript library for publishing web maps. |
| [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) | A JavaScript library for interactive, customizable vector maps on the web. |
| [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js/tree/release-v1.13.3) | The last free-open-source version of Mapbox GL JS. This version can be used without a Mapbox token if you do not use Mapbox hosted basemaps. |
| Other compatible forks | It may be possible to use react-map-gl with mapbox-gl/maplibre-gl forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. |

For basemaps:
- You can load map data from Mapbox's own service.
- You can create and host your own map data using one of the many [open source tools](https://github.com/mapbox/awesome-vector-tiles).
If you need help choosing a base map library that is right for you:

- Decide where to get your vector map data.
+ `mapbox-gl` is designed to work seamlessly with Mapbox's own data service. You will need a billable Mapbox token to use it.
+ There are a number of [map data providers](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) who support `maplibre-gl`, with a variaty of data quality and price options.
+ You can create and host your own map tiles and use them with `maplibre-gl` for (almost) free, if you are comfortable of using [open source tools](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) and setting up a cloud storage account.
- Visit Mapbox and MapLibre websites for examples and documentation. Each library offer unique features that may not exist in another.

New to react-map-gl? [Get Started](./get-started/get-started.md)

Expand All @@ -44,10 +36,10 @@ This does not scale when we have many components that need to synchronize with e

Ultimately, in the spirit of the [reactive programming paradigm](https://en.wikipedia.org/wiki/Reactive_programming), data always flows **down**. As long as the map manages its own state, as mapbox-gl is designed to do, we risk the components going out of sync.

react-map-gl creates a fully reactive wrapper for mapbox-gl. The [Map](./api-reference/map.md) component can be fully [controlled](https://reactjs.org/docs/forms.html#controlled-components), that is, the map's camera would never deviate from the props that it's assigned. Read more about this core behavior in [state management](./get-started/state-management.md).
react-map-gl creates a fully reactive wrapper for mapbox-gl/maplibre-gl. The [Map](./api-reference/maplibre/map.md) component can be fully [controlled](https://reactjs.org/docs/forms.html#controlled-components), that is, the map's camera would never deviate from the props that it's assigned. Read more about this core behavior in [state management](./get-started/state-management.md).

## Limitations

In v7.0, react-map-gl was fully rewritten to better align its API with the underlying Mapbox GL JS library. Wherever the reactive usage patterns permits, the wrapper's props and methods are 1:1 mappings to their native API equivelants.

It is possible to call the native methods directly from the `Map` instance obtained via [getMap](./api-reference/map.md#gemap). However, doing so may result in the map's state to deviate from its props. For example, calling `map.setMaxZoom` directly will cause the map's constraint settings to differ from the value of the `maxZoom` prop. Generally speaking, calling a native method is disencouraged if the same thing can be achieved through the React interface. If a third-party plugin does so, then it may lead to some unexpected behaviors.
It is possible to call the native methods directly from the `Map` instance obtained via [getMap](./api-reference/maplibre/map.md#gemap). However, doing so may result in the map's state to deviate from its props. For example, calling `map.setMaxZoom` directly will cause the map's constraint settings to differ from the value of the `maxZoom` prop. Generally speaking, calling a native method is disencouraged if the same thing can be achieved through the React interface. If a third-party plugin does so, then it may lead to some unexpected behaviors.
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# AttributionControl

React component that wraps the base library's `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/AttributionControl/)).


import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs groupId="map-library">
<TabItem value="mapbox" label="Mapbox">
React component that wraps mapbox-gl's [AttributionControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) class.

```tsx
import * as React from 'react';
import Map, {AttributionControl} from 'react-map-gl';
import Map, {AttributionControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';

function App() {
return <Map
Expand All @@ -30,37 +24,11 @@ function App() {
}
```

</TabItem>
<TabItem value="maplibre" label="Maplibre">

```tsx
import * as React from 'react';
import Map, {AttributionControl} from 'react-map-gl/maplibre';

function App() {
return <Map
initialViewState={{
longitude: -100,
latitude: 40,
zoom: 3.5
}}
mapStyle="https://api.maptiler.com/maps/streets/style.json?key=get_your_own_key"
// disable the default attribution
attributionControl={false}
>
<AttributionControl customAttribution="Map design by me" />
</Map>;
}
```

</TabItem>
</Tabs>

## Properties

### Reactive Properties

#### `style`: CSSProperties {#style}
#### `style`: CSSProperties {#style}

CSS style override that applies to the control's container.

Expand All @@ -75,7 +43,7 @@ Any options supported by the `AttributionControl` class ([Mapbox](https://docs.m

Plus the following:

#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}

Default: `'bottom-right'`

Expand Down
Loading
Loading