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

Svelte5 migration + complete rewrite #6

Draft
wants to merge 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5509e16
project reset + working Map
romaindurand Oct 9, 2024
6555227
wip : migrating Map to svelte5 syntaxes
romaindurand Oct 9, 2024
c7181e3
wip
romaindurand Oct 10, 2024
0cd7366
wip : instance types + props reactivity
romaindurand Oct 16, 2024
dbcaf71
implement reactivity for all boolean map options
romaindurand Oct 18, 2024
78502eb
implement reactivity for all number map options
romaindurand Oct 21, 2024
c7ba601
wip : implement reactivity for all other props
romaindurand Oct 21, 2024
daf5bc0
implement reactivity for all other map options
romaindurand Oct 23, 2024
ca46cba
implement geolocation button
romaindurand Oct 23, 2024
b9d8139
execute svelte 5 migration script
romaindurand Oct 23, 2024
e5b3f42
init markers
romaindurand Oct 23, 2024
a704615
WIP : custom marker
romaindurand Oct 24, 2024
fe5436d
wip : markers options reactivity
romaindurand Oct 24, 2024
334f15e
DivIcon + Marker refactoring
romaindurand Oct 25, 2024
ee7dd69
implement reactivity for numeric marker options
romaindurand Oct 25, 2024
1a2512d
handle reactivity for icon + title marker option
romaindurand Oct 25, 2024
d00544c
format with trailing comma
romaindurand Oct 25, 2024
2891d51
marker reactivity done
romaindurand Oct 27, 2024
4de16c9
DivIcon instance, Popup + events wip , bindable map markers wip, gene…
romaindurand Oct 30, 2024
bd078b3
implement reactivity for number and string Popup options
romaindurand Oct 30, 2024
daf0b5b
wip : tuple popup options reactivity
romaindurand Oct 31, 2024
cd82d2f
handle popup tuple options reactivity
romaindurand Oct 31, 2024
59b2219
implements MarkerCluster
romaindurand Nov 3, 2024
2f99b87
rebuild lib using new svelte CLI
romaindurand Nov 3, 2024
9f4b086
Too many changes 💀
romaindurand Nov 5, 2024
1324e78
Context refactoring
romaindurand Nov 5, 2024
4c61ebd
small fixes to make the package usable in an external project (tested…
romaindurand Nov 5, 2024
b67a8db
wip : use symbols for context
romaindurand Nov 6, 2024
b5508da
create Icon component, init in-component documentation
romaindurand Nov 6, 2024
83d71ed
explicit use of window.L
romaindurand Nov 7, 2024
7f5c5ee
many changes
romaindurand Nov 7, 2024
17a2489
split LocateControl in its own component, bind MarkerClusterGroup eve…
romaindurand Nov 12, 2024
8fe895c
fir map load event + cosmetic tweaks
romaindurand Nov 14, 2024
4cf3ea2
custom cluster marker icon, implement Polyline
romaindurand Nov 14, 2024
4181e7b
1.0.0-next.0
romaindurand Nov 14, 2024
e76bfb0
svelte check fix
romaindurand Nov 14, 2024
99ed9c8
LeafletEvent with sourceTarget type, export all components
romaindurand Nov 14, 2024
85de501
1.0.0-next.1
romaindurand Nov 17, 2024
6a0fb12
LocateControl, rename components helper files, update readme wip
romaindurand Nov 20, 2024
92a5f4c
1.0.0-next.2
romaindurand Nov 20, 2024
ddb1136
handle tooltip
romaindurand Nov 20, 2024
291b2a3
reactive tooltip demo
romaindurand Nov 21, 2024
767fb49
TileLayer, TileLayerWMS
romaindurand Nov 21, 2024
786d4bf
image + video overlay
romaindurand Nov 22, 2024
ccc8db5
Circle, CircleMarker, LayersControl wip, Rectangle, SVGOverlay
romaindurand Nov 22, 2024
2a12f35
LaryersControl + base layers and overlays stores, Demo component (cod…
romaindurand Nov 26, 2024
225c0d2
add npm publish + overlay store for image and video overlays
romaindurand Nov 26, 2024
6d78254
github publish on stable versions only
romaindurand Nov 28, 2024
fb7eb8c
github action to publish next tags
romaindurand Nov 28, 2024
ed0aa92
1.0.0-next.3
romaindurand Nov 28, 2024
c82d26a
docs wip
romaindurand Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .eslintignore

This file was deleted.

31 changes: 0 additions & 31 deletions .eslintrc.cjs

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/npm-publish-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a 'next' tag is published
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Publish @radiofrance/svelte-leaflet

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+-next.[0-9]+'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run check

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# This workflow will run tests using node and then publish a package to GitHub Packages when a stable tag is published
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Publish @radiofrance/svelte-leaflet

on:
release:
types: [created]

push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand Down
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
.DS_Store
test-results
node_modules

# Output
.output
.vercel
/.svelte-kit
/build
/dist
/.svelte-kit
/package

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

/test-results/
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
# Package Managers
package-lock.json
pnpm-lock.yaml
yarn.lock
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"trailingComma": "all",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
28 changes: 28 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"workbench.editor.labelFormat": "default",
"workbench.editor.customLabels.patterns": {
// Page
"**/routes/**/*/+page.svelte": "${dirname} - Page",
"**/routes/+page.svelte": "(root) - Page",
// Layout
"**/routes/**/*/+layout.svelte": "${dirname} - Layout",
"**/routes/+layout.svelte": "(root) - Layout",
// Page Data
"**/routes/**/*/+page.[tj]s": "${dirname} - Page Data",
"**/routes/+page.[tj]s": "(root) - Page Data",
// Layout Data
"**/routes/**/*/+layout.[tj]s": "${dirname} - Layout Data",
"**/routes/+layout.[tj]s": "(root) - Layout Data",
// Page Server Data
"**/routes/**/*/+page.server.[tj]s": "${dirname} - Page Server Data",
"**/routes/+page.server.[tj]s": "(root) - Page Server Data",
// Page Layout Data
"**/routes/**/*/+layout.server.[tj]s": "${dirname} - Layout Server Data",
"**/routes/+layout.server.[tj]s": "(root) - Layout Server Data",
// Error Page
"**/routes/**/*/+error.svelte": "${dirname} - Error Page",
"**/routes/+error.svelte": "(root) - Error Page",
// Server Endpoint
"**/routes/**/*/+server.[tj]s": "${dirname} - Server Endpoint"
}
}
124 changes: 57 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,80 @@
# @radiofrance/svelte-leaflet

A library that wraps leaflet classes in domless/renderless svelte components.
Simple Leaflet maps for your Svelte projects.

## Install

`npm i -D @radiofrance/svelte-leaflet`

## Components

### Map

Renders a map Leaflet Map. The Map will take up 100% of its container's height and width.

#### Attributes

| Attribute | Type | Default | Notes |
| ------------- | ------------------------------------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------- |
| `options` | [MapOptions](https://leafletjs.com/reference.html#map-option) | `{}` | Map options |
| `tilesUrl` | string | `'https://tile.openstreetmap.org/{z}/{x}/{y}.png'` | more free tile services can be found at https://alexurquhart.github.io/free-tiles/ |
| `attribution` | string | `'©OpenStreetMap'` _(link to openstreetmap)_ | |

#### Events
## Features

All events are forwarded from the Map class, see the leaflet documentation for more information.
- Works in SSR pages
- TypeScript : events, props and options are fully typed
- Simple event usage with the `oneventname` syntax
- ![](./static/map-types.png)
- `event.sourceTarget` is correctly typed
- Fully reactive : update props and options, the components will update
- Customize `DivIcon`, `Popup` and more with Svelte components or HTML instead of strings
- Single dependency : no `leaflet` or `@types/leaflet` needed

- https://leafletjs.com/reference.html#map-event
## Compatibility

Example:
- Version 1.0.0 and above are compatible with Svelte 5.
- For Svelte 3 and 4, use version 0.1.x (not actively maintained).

```svelte
<Map {options} on:click={(e) => console.log(e.detail.latlng)} />
```

### Marker

Add a marker to the map.

- Can be used as a child of `<Map>` or `<MarkerClusterGroup>`
- A `<Popup>` component can be passed as the Marker child to display a popup when the marker is clicked.
- A component with `slot="icon"` attribute can be passed as the Marker child to display a custom icon.

#### Attributes

| Name | Type | Default | Notes |
| -------- | ----------------------------------------------------- | ---------- | --------------------------------------------- |
| `latlng` | [LatLng](https://leafletjs.com/reference.html#latlng) | _required_ | position of the marker |
| `size` | number | `25` | icon size (only used with a custom icon) |
| `id` | string | `''` | an identifier to link the maker with you data |

#### Events
## Install

All events are forwarded from the Marker class, see the leaflet documentation for more information.
`npm i -D @radiofrance/svelte-leaflet`

- https://leafletjs.com/reference.html#marker-event
## Components

### Popup
### UI Layers

`<Popup>` children will be displayed when the marker is clicked.
- ✅ Marker
- DivOverlay _(abstract class)_
- ✅ Popup
- ✅ Tooltip

- Use as a `<Marker>` child.
### Raster Layers

#### Attributes
- ✅ TileLayer
- ✅ TileLayer.WMS
- ✅ ImageOverlay
- ✅ VideoOverlay

| Name | Type | Default | Notes |
| --------- | ----------------------------------------------------------------- | ------- | ------------------------------------ |
| `options` | [PopupOptions](https://leafletjs.com/reference.html#popup-option) | `{}` | options to pass to the leaflet popup |
### Vector Layers

### MarkerClusterGroup
- Path
- ✅ Polyline
- ✅ Polygon
- ✅ Rectangle
- ✅ Circle
- ✅ CircleMarker
- ✅ SVGOverlay
- SVG _(this is a Renderer, won't be implemented)_
- Canvas _(this is a Renderer, won't be implemented)_

Enables clustering of child markers
### Other Layers

- Use as a `<Map>` child
- LayerGroup
- FeatureGroup
- GeoJSON
- GridLayer

#### Attributes
### Basic Types

| Name | Type | Default | Notes |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------- |
| `options` | [MarkerClusterGroupOptions](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/leaflet.markercluster/index.d.ts#L36) | `{}` | [MarkerClusterGroup options](https://github.com/leaflet/Leaflet.markercluster?tab=readme-ov-file#defaults) |
- LatLng
- LatLngBounds
- Point
- Bounds
- ✅ Icon
- ✅ DivIcon

### Polyline
### Controls

Allows to draw lines on the map
- ✅ Zoom
- Attribution
- Layers
- Scale

#### Attributes
### Extra

| Name | Type | Default | Notes |
| --------- | ----------------------------------------------------------------------- | ---------- | --------------------------------------- |
| `latlngs` | [LatLng[]](https://leafletjs.com/reference.html#latlng) | _required_ | array of points to draw the line |
| `options` | [PolylineOptions](https://leafletjs.com/reference.html#polyline-option) | `{}` | options to pass to the leaflet polyline |
- ✅ MarkerClusterGroup
- ✅ LocateControl
- ![locate control](./static//locate-control.png)
2 changes: 1 addition & 1 deletion tests/test.ts → e2e/demo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Getting started page', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByRole('link', { name: 'Getting started' }).click();
await page.getByRole('link', { name: 'Map' }).click();
await expect(page.getByText('It\'s the only component you')).toBeVisible();
await expect(page.getByText("It's the only component you")).toBeVisible();
await expect(page.getByText('A Map has an options props')).toBeVisible();
});

Expand Down
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import prettier from 'eslint-config-prettier';
import js from '@eslint/js';
import svelte from 'eslint-plugin-svelte';
import globals from 'globals';
import ts from 'typescript-eslint';

export default ts.config(
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs['flat/recommended'],
prettier,
...svelte.configs['flat/prettier'],
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
},
{
files: ['**/*.svelte'],

languageOptions: {
parserOptions: {
parser: ts.parser,
},
},
},
{
ignores: ['build/', '.svelte-kit/', 'dist/'],
},
);
14 changes: 0 additions & 14 deletions mdsvex.config.js

This file was deleted.

Loading