@beyonk/svelte-mapbox 12.1.0 → 12.1.3

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.
@@ -5,18 +5,21 @@ on:
5
5
  tags:
6
6
  - 'v*'
7
7
 
8
+ permissions:
9
+ id-token: write
10
+ contents: read
11
+
8
12
  jobs:
9
13
  publish-npm:
10
14
  if: startsWith(github.ref, 'refs/tags/v')
11
15
  runs-on: ubuntu-latest
12
16
  steps:
13
17
  - name: checkout
14
- uses: actions/checkout@v4
18
+ uses: actions/checkout@v6
15
19
 
16
20
  - name: set up node and pnpm
17
21
  run: |
18
22
  corepack enable
19
- pnpm config set '//registry.npmjs.org/:_authToken' "${{secrets.NPM_TOKEN}}"
20
23
  pnpm i
21
24
 
22
25
  - name: publish
package/README.md CHANGED
@@ -173,7 +173,7 @@ The Geocoder is an autocompleting place lookup, which returns a lat and lng for
173
173
  </script>
174
174
  ```
175
175
 
176
- The geocoder has five events you can subscribe to: `onloading`, `onresult`, `onresults`, `onclear`, and `onerror` which are [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on)
176
+ The geocoder has six events you can subscribe to: `onloading`, `onresult`, `onresults`, `onclear`, `onerror`, and `onchange` which are [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on)
177
177
 
178
178
  The most important event is `onresult` which is fired when a user selects an autocomplete result.
179
179
 
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@beyonk/svelte-mapbox",
3
- "version": "12.1.0",
3
+ "version": "12.1.3",
4
4
  "devDependencies": {
5
- "@beyonk/eslint-config": "^8.0.2",
5
+ "@beyonk/eslint-config": "^9.1.4",
6
6
  "@eslint/eslintrc": "^3.1.0",
7
7
  "@eslint/js": "^9.14.0",
8
- "@sveltejs/kit": "^2.55.0",
9
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
8
+ "@sveltejs/kit": "^2.64.0",
9
+ "@sveltejs/vite-plugin-svelte": "^7.1.2",
10
10
  "eslint": "^9.14.0",
11
11
  "eslint-plugin-svelte": "^2.46.0",
12
- "svelte": "^5.55.0",
13
- "svelte2tsx": "^0.7.23",
14
- "typescript": "^5.6.3",
15
- "vite": "^8.0.2"
12
+ "svelte": "^5.56.3",
13
+ "svelte2tsx": "^0.7.56",
14
+ "typescript": "^6.0.3",
15
+ "vite": "^8.0.16",
16
+ "node": "runtime:>=25.0.0"
16
17
  },
17
18
  "peerDependencies": {
18
19
  "svelte": ">=4.0.0"
@@ -20,8 +21,19 @@
20
21
  "exports": {
21
22
  ".": "./src/lib/components.js"
22
23
  },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/beyonk/svelte-mapbox.git"
27
+ },
23
28
  "types": "./components.d.ts",
24
29
  "type": "module",
30
+ "devEngines": {
31
+ "runtime": {
32
+ "name": "node",
33
+ "version": ">=25.0.0",
34
+ "onFail": "download"
35
+ }
36
+ },
25
37
  "scripts": {
26
38
  "dev": "vite dev --port 3030",
27
39
  "build": "vite build",
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ unrs-resolver: true
@@ -4,7 +4,11 @@ function load (assets, cb) {
4
4
 
5
5
  if (existing) {
6
6
  if (type === 'script') {
7
- cb()
7
+ if (window.mapboxgl) {
8
+ cb()
9
+ } else {
10
+ existing.addEventListener('load', () => cb(), { once: true })
11
+ }
8
12
  }
9
13
  return
10
14
  }
@@ -1,4 +1,5 @@
1
1
  <script>
2
+ import { untrack } from 'svelte'
2
3
  import geocoderAttachment from './geocoder-attachment.js'
3
4
 
4
5
  let {
@@ -7,7 +8,7 @@
7
8
  version = 'v5.1.0',
8
9
  types = [ 'country', 'region', 'postcode', 'district', 'place', 'locality', 'neighborhood', 'address' ],
9
10
  placeholder = 'Search',
10
- value = null,
11
+ value = $bindable(null),
11
12
  customStylesheetUrl = false,
12
13
  geocoder = $bindable(),
13
14
  onresults,
@@ -16,6 +17,7 @@
16
17
  onerror,
17
18
  onclear,
18
19
  onload,
20
+ onchange,
19
21
  ...rest
20
22
  } = $props()
21
23
 
@@ -27,17 +29,22 @@
27
29
  types: types.join(','),
28
30
  placeholder,
29
31
  customStylesheetUrl,
30
- value
32
+ value: untrack(() => value)
31
33
  }, options))
32
34
 
33
35
  function init (detail) {
34
36
  geocoder = detail.geocoder
35
37
  }
38
+
39
+ function updateValue (detail) {
40
+ value = detail.query
41
+ onchange?.(detail)
42
+ }
36
43
  </script>
37
44
 
38
45
  <div
39
46
  id={fieldId}
40
- {@attach geocoderAttachment(optionsWithDefaults, { onresults, onresult, onloading, onerror, onclear, onload })}
47
+ {@attach geocoderAttachment(optionsWithDefaults, { onresults, onresult, onloading, onerror, onclear, onload, onchange: updateValue })}
41
48
  onready={init}
42
49
  {...rest}
43
50
  ></div>
@@ -1,8 +1,10 @@
1
1
  import { load } from '../asset-loader.js'
2
2
 
3
- export default function geocoderAttachment (options, { onresults, onresult, onloading, onerror, onclear, onready }) {
3
+ export default function geocoderAttachment (options, { onresults, onresult, onloading, onerror, onclear, onready, onchange }) {
4
4
  return (element) => {
5
5
  let geocoderInstance
6
+ let inputElement
7
+ let handleChange
6
8
 
7
9
  const resources = [
8
10
  { type: 'script', value: `//api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/${options.version}/mapbox-gl-geocoder.min.js`, id: 'byk-gc-js' }
@@ -26,7 +28,6 @@ export default function geocoderAttachment (options, { onresults, onresult, onlo
26
28
  onresults?.(ev)
27
29
  })
28
30
  geocoderInstance.on('result', (ev) => {
29
- console.log('result', onresult, ev)
30
31
  onresult?.(ev)
31
32
  })
32
33
  geocoderInstance.on('loading', (ev) => {
@@ -41,9 +42,18 @@ export default function geocoderAttachment (options, { onresults, onresult, onlo
41
42
  geocoderInstance.on('load', (ev) => {
42
43
  onready?.({ ...ev, geocoder: geocoderInstance })
43
44
  })
45
+
46
+ inputElement = element.querySelector('input')
47
+ handleChange = (ev) => {
48
+ onchange({ query: ev.target.value })
49
+ }
50
+ inputElement.addEventListener('change', handleChange)
44
51
  })
45
52
 
46
53
  return () => {
54
+ if (inputElement) {
55
+ inputElement.removeEventListener('change', handleChange)
56
+ }
47
57
  geocoderInstance && geocoderInstance.remove && geocoderInstance.remove()
48
58
  }
49
59
  }
@@ -37,7 +37,7 @@
37
37
  accessToken,
38
38
  style,
39
39
  center,
40
- zoom,
40
+ zoom: untrack(() => zoom),
41
41
  zoomRate,
42
42
  wheelZoomRate,
43
43
  version,
@@ -3,8 +3,6 @@
3
3
  import { contextKey } from '../mapbox.js'
4
4
 
5
5
  const { getMap, getMapbox } = getContext(contextKey)
6
- const map = getMap()
7
- const mapbox = getMapbox()
8
6
 
9
7
  function randomColour () {
10
8
  return Math.round(Math.random() * 255)
@@ -38,9 +36,12 @@
38
36
  })
39
37
 
40
38
  onMount(() => {
39
+ const map = getMap()
40
+ const mapbox = getMapbox()
41
+
41
42
  const namedParams = Object.assign(
42
43
  { offset: markerOffset },
43
- element.hasChildNodes() ? { element } : { color }
44
+ element.children.length > 0 || element.textContent.trim().length > 0 ? { element } : { color }
44
45
  )
45
46
  marker = new mapbox.Marker(Object.assign(namedParams, markerOptions))
46
47
 
@@ -107,7 +107,6 @@
107
107
  bind:value={placeName}
108
108
  accessToken={PUBLIC_MAPBOX_TOKEN}
109
109
  onresult={({ result }) => {
110
- console.log('sets center', result.center)
111
110
  mapComponent.setCenter(result.center, 14)
112
111
  place = result
113
112
  }}