@swr-data-lab/components 2.0.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.
@@ -0,0 +1,13 @@
1
+ <script lang="ts">// See: https://maplibre.org/maplibre-gl-js/docs/API/classes/GeoJSONSource/
2
+ import {} from 'maplibre-gl';
3
+ import MapSource from '../Source/MapSource.svelte';
4
+ const { maxZoom = 24, id, data, attribution = '' } = $props();
5
+ const sourceSpec = {
6
+ type: 'geojson',
7
+ data,
8
+ maxzoom: maxZoom,
9
+ attribution
10
+ };
11
+ </script>
12
+
13
+ <MapSource {id} {sourceSpec} />
@@ -0,0 +1,15 @@
1
+ interface GeoJSONSourceProps {
2
+ id: string;
3
+ /**
4
+ * GeoJSON object or URL
5
+ */
6
+ data: GeoJSON.GeoJSON | string;
7
+ /**
8
+ * Attribution string for your data, usually rendered using an `<AttributionControl>`
9
+ */
10
+ attribution?: string;
11
+ maxZoom?: number;
12
+ }
13
+ declare const GeoJsonSource: import("svelte").Component<GeoJSONSourceProps, {}, "">;
14
+ type GeoJsonSource = ReturnType<typeof GeoJsonSource>;
15
+ export default GeoJsonSource;
@@ -0,0 +1,2 @@
1
+ export default GeoJSONSource;
2
+ import GeoJSONSource from './GeoJSONSource.svelte';
@@ -0,0 +1,2 @@
1
+ import GeoJSONSource from './GeoJSONSource.svelte';
2
+ export default GeoJSONSource;
@@ -1,9 +1,12 @@
1
1
  <script lang="ts">import maplibre, {} from 'maplibre-gl';
2
2
  import { onMount, onDestroy, getContext, hasContext } from 'svelte';
3
- import { createMapContext } from '../context.svelte.js';
3
+ import { createMapContext, MapContext } from '../context.svelte.js';
4
4
  import {} from '../types';
5
5
  import FallbackStyle from './FallbackStyle';
6
- let { children, options, style = FallbackStyle, minZoom = 0, maxZoom = 14.99, zoom = $bindable(), center = $bindable(), pitch = $bindable(0), bearing = $bindable(0), loading = $bindable(true), projection = { type: 'mercator' }, allowRotation = false, allowZoom = true, showDebug = false, initialLocation: receivedInitialLocation } = $props();
6
+ let { children, options, style = FallbackStyle, minZoom = 0, maxZoom = 14.99, zoom = $bindable(), center = $bindable(), pitch = $bindable(0), bearing = $bindable(0), loading = $bindable(true), projection = { type: 'mercator' }, allowRotation = false, allowZoom = true, showDebug = false, initialLocation: receivedInitialLocation,
7
+ // Future: This should become bindable.readonly when that becomes
8
+ // available, see: https://github.com/sveltejs/svelte/issues/7712
9
+ mapContext = $bindable(), onmoveend, onmovestart } = $props();
7
10
  let container;
8
11
  // Merge initial location with default object so individual
9
12
  // properties (like pitch) can be omitted by the caller
@@ -14,7 +17,7 @@ let initialLocation = {
14
17
  pitch: 0,
15
18
  ...receivedInitialLocation
16
19
  };
17
- const mapContext = createMapContext();
20
+ mapContext = createMapContext();
18
21
  if (getContext('initialLocation') !== undefined && getContext('initialLocation') !== false) {
19
22
  initialLocation = getContext('initialLocation');
20
23
  }
@@ -43,6 +46,12 @@ onMount(() => {
43
46
  pitch = mapContext.map?.getPitch();
44
47
  bearing = mapContext.map?.getBearing();
45
48
  });
49
+ if (onmoveend) {
50
+ mapContext.map.on('moveend', onmoveend);
51
+ }
52
+ if (onmovestart) {
53
+ mapContext.map.on('movestart', onmovestart);
54
+ }
46
55
  });
47
56
  onDestroy(async () => {
48
57
  if (mapContext.map)
@@ -1,5 +1,6 @@
1
- import maplibre, { type ProjectionSpecification, type StyleSpecification } from 'maplibre-gl';
1
+ import maplibre, { type MapLibreEvent, type ProjectionSpecification, type StyleSpecification } from 'maplibre-gl';
2
2
  import { type Snippet } from 'svelte';
3
+ import { MapContext } from '../context.svelte.js';
3
4
  import { type Location } from '../types';
4
5
  interface MapProps {
5
6
  style?: StyleSpecification | string;
@@ -16,8 +17,11 @@ interface MapProps {
16
17
  projection?: ProjectionSpecification;
17
18
  showDebug?: boolean;
18
19
  options?: any;
20
+ mapContext?: MapContext;
21
+ onmovestart?: (e: MapLibreEvent) => null;
22
+ onmoveend?: (e: MapLibreEvent) => null;
19
23
  children?: Snippet;
20
24
  }
21
- declare const Map: import("svelte").Component<MapProps, {}, "center" | "zoom" | "pitch" | "bearing" | "loading">;
25
+ declare const Map: import("svelte").Component<MapProps, {}, "center" | "zoom" | "pitch" | "bearing" | "loading" | "mapContext">;
22
26
  type Map = ReturnType<typeof Map>;
23
27
  export default Map;
@@ -10,7 +10,7 @@ const layerSpec = {
10
10
  id,
11
11
  type,
12
12
  source: sourceId,
13
- 'source-layer': sourceLayer,
13
+ 'source-layer': sourceLayer || '',
14
14
  layout: $state.snapshot(layout) ?? {},
15
15
  paint: $state.snapshot(paint) ?? {},
16
16
  minzoom: minZoom,
@@ -2,7 +2,7 @@ import type { CircleLayoutProps, CirclePaintProps, FillLayoutProps, FillPaintPro
2
2
  interface VectorLayerProps {
3
3
  id: string;
4
4
  sourceId: string;
5
- sourceLayer: string;
5
+ sourceLayer?: string;
6
6
  type: 'line' | 'fill' | 'circle' | 'symbol';
7
7
  placeBelow: string;
8
8
  visible?: boolean;
@@ -1,12 +1,12 @@
1
- <script lang="ts">import {} from 'svelte';
2
- import {} from 'maplibre-gl';
1
+ <script lang="ts">import {} from 'maplibre-gl';
3
2
  import MapSource from '../Source/MapSource.svelte';
4
- const { minZoom = 0, maxZoom = 24, id, url } = $props();
3
+ const { minZoom = 0, maxZoom = 24, id, url, attribution = '' } = $props();
5
4
  const sourceSpec = {
6
5
  type: 'vector',
7
6
  tiles: [url],
8
7
  maxzoom: maxZoom,
9
- minzoom: minZoom
8
+ minzoom: minZoom,
9
+ attribution
10
10
  };
11
11
  </script>
12
12
 
@@ -1,10 +1,12 @@
1
- import { type Snippet } from 'svelte';
2
1
  interface VectorTileSourceProps {
3
2
  id: string;
4
3
  url: string;
5
4
  minZoom?: number;
6
5
  maxZoom?: number;
7
- children?: Snippet;
6
+ /**
7
+ * Attribution string for your data, usually rendered using an `<AttributionControl>`
8
+ */
9
+ attribution?: string;
8
10
  }
9
11
  declare const VectorTileSource: import("svelte").Component<VectorTileSourceProps, {}, "">;
10
12
  type VectorTileSource = ReturnType<typeof VectorTileSource>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@swr-data-lab/components",
3
3
  "description": "SWR Data Lab component library",
4
- "version": "2.0.0",
4
+ "version": "2.2.0",
5
5
  "author": "SWR Data Lab",
6
6
  "license": "UNLICENSED",
7
7
  "type": "module",
@@ -49,6 +49,7 @@
49
49
  "@sveltejs/kit": "^2.22.2",
50
50
  "@sveltejs/package": "^2.3.12",
51
51
  "@sveltejs/vite-plugin-svelte": "^5.1.0",
52
+ "@types/geojson": "^7946.0.16",
52
53
  "@versatiles/style": "^5.6.0",
53
54
  "@vitest/browser": "^3.2.4",
54
55
  "@vitest/coverage-v8": "^3.2.4",
@@ -61,9 +62,9 @@
61
62
  "sass-embedded": "^1.89.2",
62
63
  "semantic-release": "^24.2.6",
63
64
  "storybook": "^9.0.15",
64
- "svelte-preprocess": "^6.0.3",
65
65
  "svelte": "^5.23.0",
66
66
  "svelte-check": "^4.0.0",
67
+ "svelte-preprocess": "^6.0.3",
67
68
  "typescript": "^5.8.3",
68
69
  "vite": "^6.0.0",
69
70
  "vitest": "^3.1.1",