@studiometa/ui-mapbox 1.11.1 → 2.0.0-alpha.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.
Files changed (48) hide show
  1. package/dist/AbstractMapboxControl.js +1 -1
  2. package/dist/AbstractMapboxControl.js.map +1 -1
  3. package/dist/AbstractMapboxMapChild.d.ts +32 -12
  4. package/dist/AbstractMapboxMapChild.js +24 -17
  5. package/dist/AbstractMapboxMapChild.js.map +1 -1
  6. package/dist/MapboxCluster.d.ts +19 -2
  7. package/dist/MapboxCluster.js +11 -9
  8. package/dist/MapboxCluster.js.map +1 -1
  9. package/dist/MapboxClusterItem.d.ts +11 -3
  10. package/dist/MapboxClusterItem.js +5 -6
  11. package/dist/MapboxClusterItem.js.map +1 -1
  12. package/dist/MapboxFullscreenControl.d.ts +8 -4
  13. package/dist/MapboxFullscreenControl.js +6 -2
  14. package/dist/MapboxFullscreenControl.js.map +1 -1
  15. package/dist/MapboxGeocoder.d.ts +9 -0
  16. package/dist/MapboxGeocoder.js +1 -2
  17. package/dist/MapboxGeocoder.js.map +1 -1
  18. package/dist/MapboxGeolocateControl.d.ts +8 -4
  19. package/dist/MapboxGeolocateControl.js +16 -12
  20. package/dist/MapboxGeolocateControl.js.map +1 -1
  21. package/dist/MapboxImage.d.ts +11 -1
  22. package/dist/MapboxImage.js +0 -1
  23. package/dist/MapboxImage.js.map +1 -1
  24. package/dist/MapboxImages.d.ts +9 -1
  25. package/dist/MapboxImages.js +1 -2
  26. package/dist/MapboxImages.js.map +1 -1
  27. package/dist/MapboxLayer.js.map +1 -1
  28. package/dist/MapboxMap.d.ts +17 -2
  29. package/dist/MapboxMap.js +4 -5
  30. package/dist/MapboxMap.js.map +1 -1
  31. package/dist/MapboxMarker.js.map +1 -1
  32. package/dist/MapboxNavigationControl.d.ts +8 -4
  33. package/dist/MapboxNavigationControl.js +13 -9
  34. package/dist/MapboxNavigationControl.js.map +1 -1
  35. package/dist/MapboxPopup.js.map +1 -1
  36. package/dist/MapboxSource.js +1 -1
  37. package/dist/MapboxSource.js.map +1 -1
  38. package/dist/StoreLocator.d.ts +76 -51
  39. package/dist/StoreLocator.js +111 -105
  40. package/dist/StoreLocator.js.map +1 -1
  41. package/dist/catalog.js.map +1 -1
  42. package/dist/dependencies.d.ts +6 -4
  43. package/dist/dependencies.js +6 -4
  44. package/dist/dependencies.js.map +1 -1
  45. package/dist/manifest.js +14 -84
  46. package/dist/manifest.js.map +1 -1
  47. package/dist/scripts/manifest-types.d.ts +3 -3
  48. package/package.json +3 -3
@@ -1,19 +1,23 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
3
  //#region src/MapboxNavigationControl.ts
5
4
  /**
6
5
  * Add a navigation control to the map.
6
+ *
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
8
8
  */
9
- var MapboxNavigationControl = class extends withExtraConfig(AbstractMapboxControl, {
10
- name: "MapboxNavigationControl",
11
- options: {
12
- showCompass: Boolean,
13
- showZoom: Boolean,
14
- visualizePitch: Boolean
15
- }
16
- }) {
9
+ var MapboxNavigationControl = class extends AbstractMapboxControl {
10
+ /**
11
+ * Config.
12
+ */
13
+ static config = {
14
+ name: "MapboxNavigationControl",
15
+ options: {
16
+ showCompass: Boolean,
17
+ showZoom: Boolean,
18
+ visualizePitch: Boolean
19
+ }
20
+ };
17
21
  /**
18
22
  * Create the mapbox NavigationControl instance.
19
23
  * @protected
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../src/MapboxNavigationControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit/withExtraConfig';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n}) {\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAoBA,IAAa,0BAAb,cAA6C,gBAAgB,uBAAuB;CAClF,MAAM;CACN,SAAS;EACP,aAAa;EACb,UAAU;EACV,gBAAgB;EACjB;CACF,CAAC,CAAC;;;;;CAKD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
1
+ {"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../src/MapboxNavigationControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxNavigationControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n };\n\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAkBA,IAAa,0BAAb,cAA8E,sBAE5E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,aAAa;GACb,UAAU;GACV,gBAAgB;GACjB;EACF;;;;;CAMD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxPopup.js","names":[],"sources":["../src/MapboxPopup.ts"],"sourcesContent":["import { type BaseConfig, type BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
1
+ {"version":3,"file":"MapboxPopup.js","names":[],"sources":["../src/MapboxPopup.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
@@ -35,7 +35,7 @@ var MapboxSource = class extends AbstractMapboxMapChild {
35
35
  data
36
36
  };
37
37
  } catch (err) {
38
- this.$warn("Invalid JSON in the `geojson` ref:", err);
38
+ this.$error("mapbox-source.invalid-geojson", "Invalid JSON in the `geojson` ref.", err);
39
39
  return source;
40
40
  }
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxSource.js","names":[],"sources":["../src/MapboxSource.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { SourceSpecification, GeoJSONSourceSpecification, GeoJSONSource } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxSourceProps extends AbstractMapboxMapChildProps {\n $refs: {\n geojson?: HTMLScriptElement;\n };\n $options: {\n id: string;\n /**\n * The source specification, e.g. `{ type: 'geojson', data }`.\n * @see https://docs.mapbox.com/style-spec/reference/sources/\n */\n source: SourceSpecification;\n };\n}\n\n/**\n * Add a source to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxSourceProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxSource',\n refs: ['geojson'],\n options: {\n id: String,\n source: Object,\n },\n };\n\n /**\n * Resolve the source specification.\n *\n * When a `geojson` ref — a `<script data-ref=\"geojson\" type=\"application/json\">`\n * element — is present, its content is parsed as inline GeoJSON and injected\n * as the source spec's `data`. Otherwise the `source` option is used as is.\n */\n get source(): SourceSpecification {\n const { source } = this.$options;\n const script = this.$refs.geojson;\n const content = script?.textContent?.trim();\n\n // Only inject inline data when the script ref holds actual content. A\n // missing, empty or whitespace-only ref is treated as \"no inline data\" and\n // the `source` option is used as is instead of injecting `data: null`.\n if (!content) {\n return source;\n }\n\n try {\n const data = JSON.parse(content) as GeoJSONSourceSpecification['data'];\n return { ...source, data } as SourceSpecification;\n } catch (err) {\n this.$warn('Invalid JSON in the `geojson` ref:', err);\n return source;\n }\n }\n\n /**\n * Whether this instance owns the source under its id. Only a source this\n * instance owns — along with the layers tied to it — may be removed on\n * teardown; a source declared by someone else outside the family is left\n * untouched, and a source a newer sibling has since adopted is left to that\n * sibling.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this source.\n * @private\n */\n get __ownershipKey(): string {\n return `source:${this.$options.id}`;\n }\n\n /**\n * Mounted hook.\n *\n * Adopt-or-add: when the id is free, add the source and claim ownership. When\n * a source with this id already exists, adding it again would throw a\n * duplicate-id error, so instead update its data (for GeoJSON) and — when the\n * existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap\n * mounted the replacement before the original tore down) — take over\n * ownership. A source declared outside the family is left untouched and not\n * owned.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { id } = this.$options;\n const { source } = this;\n\n if (!map.getSource(id)) {\n map.addSource(id, source);\n // Own the id, keyed to the very source object just added: the liveness\n // probe reports the entry stale the moment this source is removed (a\n // `setStyle` wipe, an external `removeSource`) or replaced under the same\n // id, so it can never misclassify a stranger's later source (H6).\n const added = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);\n this.__added = true;\n return;\n }\n\n // The id is taken. Only adopt it from another family instance; an\n // externally declared source stays untouched. `getMapboxOwner` validates\n // the existing owner's liveness, so a stale entry left by a wiped/removed\n // source does not read as owned and is not adopted here.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n if (source.type === 'geojson' && 'data' in source) {\n const existing = map.getSource<GeoJSONSource>(id);\n existing?.setData(source.data as GeoJSONSourceSpecification['data']);\n }\n\n const existing = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);\n this.__added = true;\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Only remove a source this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getSource(id)\n ) {\n // Remove every layer tied to the source before removing the source itself,\n // otherwise Mapbox throws because layers still reference a missing source.\n //\n // H7 (PR #567 review): this also removes layers owned by still-mounted\n // `MapboxLayer` instances. Those layers now keep a standing `sourcedata`\n // recovery watch (see `MapboxLayer.__handleSourceData`), so when a source\n // with the same id is later re-added they re-commit themselves rather than\n // vanishing permanently. The removal here is unavoidable (Mapbox rejects\n // removing a source still referenced by a layer); recovery is the layer's\n // job. The common `Fetch` swap (source AND layers replaced together) is\n // likewise fine: the replacement layers re-commit on their own.\n for (const layer of map.getStyle().layers) {\n if ('source' in layer && layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n\n map.removeSource(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxSource;\n"],"mappings":";;;;;;;AA0BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,UAAU;EACjB,SAAS;GACP,IAAI;GACJ,QAAQ;GACT;EACF;;;;;;;;CASD,IAAI,SAA8B;EAChC,MAAM,EAAE,WAAW,KAAK;EAExB,MAAM,UADS,KAAK,MAAM,SACF,aAAa,MAAM;AAK3C,MAAI,CAAC,QACH,QAAO;AAGT,MAAI;GACF,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,UAAO;IAAE,GAAG;IAAQ;IAAM;WACnB,KAAK;AACZ,QAAK,MAAM,sCAAsC,IAAI;AACrD,UAAO;;;;;;;;;;;CAYX,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,UAAU,KAAK,SAAS;;;;;;;;;;;;;CAcjC,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK;GACpB,MAAM,EAAE,WAAW;AAEnB,OAAI,CAAC,IAAI,UAAU,GAAG,EAAE;AACtB,QAAI,UAAU,IAAI,OAAO;IAKzB,MAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,MAAM;AACvF,SAAK,UAAU;AACf;;AAOF,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,OAAO,SAAS,aAAa,UAAU,OACxB,KAAI,UAAyB,GAAG,EACvC,QAAQ,OAAO,KAA2C;IAGtE,MAAM,WAAW,IAAI,UAAU,GAAG;AAClC,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,SAAS;AAC1F,SAAK,UAAU;;IAEjB;;;;;CAMJ,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,UAAU,GAAG,EAClB;AAYA,QAAK,MAAM,SAAS,IAAI,UAAU,CAAC,OACjC,KAAI,YAAY,SAAS,MAAM,WAAW,GACxC,KAAI,YAAY,MAAM,GAAG;AAI7B,OAAI,aAAa,GAAG;AACpB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
1
+ {"version":3,"file":"MapboxSource.js","names":[],"sources":["../src/MapboxSource.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { SourceSpecification, GeoJSONSourceSpecification, GeoJSONSource } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxSourceProps extends AbstractMapboxMapChildProps {\n $refs: {\n geojson?: HTMLScriptElement;\n };\n $options: {\n id: string;\n /**\n * The source specification, e.g. `{ type: 'geojson', data }`.\n * @see https://docs.mapbox.com/style-spec/reference/sources/\n */\n source: SourceSpecification;\n };\n}\n\n/**\n * Add a source to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxSourceProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxSource',\n refs: ['geojson'],\n options: {\n id: String,\n source: Object,\n },\n };\n\n /**\n * Resolve the source specification.\n *\n * When a `geojson` ref — a `<script data-ref=\"geojson\" type=\"application/json\">`\n * element — is present, its content is parsed as inline GeoJSON and injected\n * as the source spec's `data`. Otherwise the `source` option is used as is.\n */\n get source(): SourceSpecification {\n const { source } = this.$options;\n const script = this.$refs.geojson;\n const content = script?.textContent?.trim();\n\n // Only inject inline data when the script ref holds actual content. A\n // missing, empty or whitespace-only ref is treated as \"no inline data\" and\n // the `source` option is used as is instead of injecting `data: null`.\n if (!content) {\n return source;\n }\n\n try {\n const data = JSON.parse(content) as GeoJSONSourceSpecification['data'];\n return { ...source, data } as SourceSpecification;\n } catch (err) {\n this.$error('mapbox-source.invalid-geojson', 'Invalid JSON in the `geojson` ref.', err);\n return source;\n }\n }\n\n /**\n * Whether this instance owns the source under its id. Only a source this\n * instance owns — along with the layers tied to it — may be removed on\n * teardown; a source declared by someone else outside the family is left\n * untouched, and a source a newer sibling has since adopted is left to that\n * sibling.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this source.\n * @private\n */\n get __ownershipKey(): string {\n return `source:${this.$options.id}`;\n }\n\n /**\n * Mounted hook.\n *\n * Adopt-or-add: when the id is free, add the source and claim ownership. When\n * a source with this id already exists, adding it again would throw a\n * duplicate-id error, so instead update its data (for GeoJSON) and — when the\n * existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap\n * mounted the replacement before the original tore down) — take over\n * ownership. A source declared outside the family is left untouched and not\n * owned.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { id } = this.$options;\n const { source } = this;\n\n if (!map.getSource(id)) {\n map.addSource(id, source);\n // Own the id, keyed to the very source object just added: the liveness\n // probe reports the entry stale the moment this source is removed (a\n // `setStyle` wipe, an external `removeSource`) or replaced under the same\n // id, so it can never misclassify a stranger's later source (H6).\n const added = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);\n this.__added = true;\n return;\n }\n\n // The id is taken. Only adopt it from another family instance; an\n // externally declared source stays untouched. `getMapboxOwner` validates\n // the existing owner's liveness, so a stale entry left by a wiped/removed\n // source does not read as owned and is not adopted here.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n if (source.type === 'geojson' && 'data' in source) {\n const existing = map.getSource<GeoJSONSource>(id);\n existing?.setData(source.data as GeoJSONSourceSpecification['data']);\n }\n\n const existing = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);\n this.__added = true;\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Only remove a source this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getSource(id)\n ) {\n // Remove every layer tied to the source before removing the source itself,\n // otherwise Mapbox throws because layers still reference a missing source.\n //\n // H7 (PR #567 review): this also removes layers owned by still-mounted\n // `MapboxLayer` instances. Those layers now keep a standing `sourcedata`\n // recovery watch (see `MapboxLayer.__handleSourceData`), so when a source\n // with the same id is later re-added they re-commit themselves rather than\n // vanishing permanently. The removal here is unavoidable (Mapbox rejects\n // removing a source still referenced by a layer); recovery is the layer's\n // job. The common `Fetch` swap (source AND layers replaced together) is\n // likewise fine: the replacement layers re-commit on their own.\n for (const layer of map.getStyle().layers) {\n if ('source' in layer && layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n\n map.removeSource(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxSource;\n"],"mappings":";;;;;;;AA0BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,UAAU;EACjB,SAAS;GACP,IAAI;GACJ,QAAQ;GACT;EACF;;;;;;;;CASD,IAAI,SAA8B;EAChC,MAAM,EAAE,WAAW,KAAK;EAExB,MAAM,UADS,KAAK,MAAM,SACF,aAAa,MAAM;AAK3C,MAAI,CAAC,QACH,QAAO;AAGT,MAAI;GACF,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,UAAO;IAAE,GAAG;IAAQ;IAAM;WACnB,KAAK;AACZ,QAAK,OAAO,iCAAiC,sCAAsC,IAAI;AACvF,UAAO;;;;;;;;;;;CAYX,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,UAAU,KAAK,SAAS;;;;;;;;;;;;;CAcjC,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK;GACpB,MAAM,EAAE,WAAW;AAEnB,OAAI,CAAC,IAAI,UAAU,GAAG,EAAE;AACtB,QAAI,UAAU,IAAI,OAAO;IAKzB,MAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,MAAM;AACvF,SAAK,UAAU;AACf;;AAOF,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,OAAO,SAAS,aAAa,UAAU,OACxB,KAAI,UAAyB,GAAG,EACvC,QAAQ,OAAO,KAA2C;IAGtE,MAAM,WAAW,IAAI,UAAU,GAAG;AAClC,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,SAAS;AAC1F,SAAK,UAAU;;IAEjB;;;;;CAMJ,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,UAAU,GAAG,EAClB;AAYA,QAAK,MAAM,SAAS,IAAI,UAAU,CAAC,OACjC,KAAI,YAAY,SAAS,MAAM,WAAW,GACxC,KAAI,YAAY,MAAM,GAAG;AAI7B,OAAI,aAAa,GAAG;AACpB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
@@ -2,7 +2,7 @@ import { MapboxMap } from "./MapboxMap.js";
2
2
  import { MapboxClusterItem } from "./MapboxClusterItem.js";
3
3
  import { MapboxCluster } from "./MapboxCluster.js";
4
4
  import { MapboxGeocoder } from "./MapboxGeocoder.js";
5
- import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
5
+ import { BaseConfig, BaseProps, ChildrenCollection } from "@studiometa/js-toolkit";
6
6
  import { LngLatBoundsLike, Map, Popup } from "mapbox-gl";
7
7
  import { Base } from "@studiometa/js-toolkit/Base";
8
8
 
@@ -14,6 +14,15 @@ interface StoreLocatorProps extends BaseProps {
14
14
  fitOnUpdate: boolean;
15
15
  popupOptions: Record<string, unknown>;
16
16
  };
17
+ $emits: {
18
+ 'map-select': {
19
+ item: MapboxClusterItem;
20
+ };
21
+ 'map-deselect': void;
22
+ 'map-filter': {
23
+ items: MapboxClusterItem[];
24
+ };
25
+ };
17
26
  }
18
27
  /**
19
28
  * Coordinate a "find a store near you" experience on top of a `MapboxMap`.
@@ -41,17 +50,15 @@ interface StoreLocatorProps extends BaseProps {
41
50
  * and the `map-select` event.
42
51
  *
43
52
  * The orchestrator requires its `MapboxCluster` (and `MapboxMap`) to live within
44
- * its own subtree; it resolves them with `$query`, retries a few ticks for
45
- * asynchronously-mounted children, and — like the map children — subscribes to
46
- * the `MAPBOX_MAP_CONNECTED` / `MAPBOX_CLUSTER_CONNECTED` events so a late or
47
- * replaced map/cluster (re)binds instead of stranding the orchestrator on a
48
- * destroyed instance, and to the map's own `remove` event so a removed map is
49
- * never called into. Register each component independently (e.g. with
50
- * `registerComponent`, optionally behind a lazy `importWhen*` helper):
51
- * `StoreLocator`, `MapboxMap`, `MapboxCluster` and `MapboxClusterItem`.
52
- * Registration order does not matter because children resolve their map through
53
- * the connected-event retry, and the orchestrator declares no child components
54
- * so nothing is ever double-mounted.
53
+ * its own subtree. It watches both with `$watchChildren()`, so a cluster or
54
+ * geocoder that mounts late — or one that replaces the wired instance — is
55
+ * picked up without polling; it subscribes to `MAPBOX_MAP_CONNECTED` because a
56
+ * map announces its Mapbox instance *after* mounting, which a children
57
+ * collection cannot report; and it subscribes to the map's own `remove` event
58
+ * so a removed map is never called into. Register each component independently
59
+ * with `registerComponent`: `StoreLocator`, `MapboxMap`, `MapboxCluster` and
60
+ * `MapboxClusterItem`. Registration and mount order do not matter, and the
61
+ * orchestrator declares no child components so nothing is ever double-mounted.
55
62
  *
56
63
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
57
64
  */
@@ -61,9 +68,9 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
61
68
  *
62
69
  * No child components are declared: `MapboxMap`, `MapboxCluster`,
63
70
  * `MapboxClusterItem` and `MapboxGeocoder` are each registered independently
64
- * (e.g. with `registerComponent`, optionally behind a lazy `importWhen*`
65
- * helper) and mount on their own. The orchestrator discovers them through
66
- * `$query` once available — declaring them here would double-mount them.
71
+ * with `registerComponent` and mount on their own. The orchestrator discovers
72
+ * them through `$watchChildren()`; declaring them here would double-mount
73
+ * them, since the registry already mounts a declared element.
67
74
  */
68
75
  static config: BaseConfig;
69
76
  /**
@@ -99,13 +106,13 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
99
106
  __popup?: Popup;
100
107
  /**
101
108
  * Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on
102
- * destroy and when the cluster is replaced (so the orchestrator re-wires onto
103
- * the new instance rather than staying subscribed to the destroyed one).
109
+ * unmount and when the cluster is replaced (so the orchestrator re-wires onto
110
+ * the new instance rather than staying subscribed to the unmounted one).
104
111
  * @private
105
112
  */
106
113
  __offCluster: Array<() => void>;
107
114
  /**
108
- * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on destroy.
115
+ * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on unmount.
109
116
  * @private
110
117
  */
111
118
  __offGeocoder: Array<() => void>;
@@ -129,26 +136,33 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
129
136
  */
130
137
  __offMapConnected?: () => void;
131
138
  /**
132
- * Off handle for the standing document-level `MAPBOX_CLUSTER_CONNECTED` retry
133
- * subscription, so a cluster that mounts late — or replaces the wired one — is
134
- * (re)wired instead of stranding the orchestrator on a destroyed instance.
135
- * @private
136
- */
137
- __offClusterConnected?: () => void;
138
- /**
139
- * Whether the `MapboxCluster` listeners are already attached.
139
+ * The mounted `MapboxCluster` descendants, live and in DOM order.
140
+ *
141
+ * The collection answers "has the cluster mounted yet?" on its own: a cluster
142
+ * that mounts late, or one that replaces the wired one, reaches the
143
+ * `added`/`removed` callbacks with nothing to poll. The cluster still
144
+ * dispatches `MAPBOX_CLUSTER_CONNECTED` for `MapboxClusterItem`, which looks
145
+ * *up* for its cluster and has no watching counterpart to `$closest()`.
140
146
  * @private
141
147
  */
142
- __clusterWired: boolean;
148
+ __clusters: ChildrenCollection<MapboxCluster>;
143
149
  /**
144
- * Whether the `MapboxGeocoder` `map-result` listener is already attached.
150
+ * The mounted `MapboxGeocoder` descendants, live and in DOM order. The
151
+ * geocoder is optional, so nothing waits for it: it wires itself whenever it
152
+ * turns up.
145
153
  * @private
146
154
  */
147
- __geocoderWired: boolean;
155
+ __geocoders: ChildrenCollection<MapboxGeocoder>;
148
156
  /**
149
- * The closest child `MapboxMap` component.
157
+ * The child `MapboxMap` component, once it has mounted.
158
+ *
159
+ * The getter does not warn when there is none: a wrapper mounts before the
160
+ * elements inside it and mount order is not guaranteed, so "no map yet" is
161
+ * the normal state on every healthy locator. A locator with genuinely no map
162
+ * in its markup is reported once instead, from
163
+ * {@link __warnWhenMapIsMissing}.
150
164
  */
151
- get mapboxMap(): MapboxMap<BaseProps>;
165
+ get mapboxMap(): MapboxMap | undefined;
152
166
  /**
153
167
  * The child `MapboxCluster`, discovered in the subtree.
154
168
  */
@@ -284,41 +298,52 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
284
298
  */
285
299
  __waitForConnectedMap(): void;
286
300
  /**
287
- * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and (re)wire when a
288
- * `MapboxCluster` inside this orchestrator connects. A cluster that replaces
289
- * the wired one drops the stale wiring and re-wires onto the new instance, so
290
- * list clicks, viewport filtering and selection keep working after a swap.
301
+ * Report a locator with no `MapboxMap` in its markup, once.
302
+ *
303
+ * The check reads the **element**, not the mounted instance: DOM ancestry is
304
+ * a fact that exists before anything mounts, so it is immune both to mount
305
+ * ordering and to the map's mount strategy — a `data-mount` that has not
306
+ * fired yet is not a missing map. `whenDOMSettled()` waits for
307
+ * the mutation batch that brought the locator in, which is the earliest
308
+ * moment the markup can be judged complete.
291
309
  * @private
292
310
  */
293
- __waitForConnectedCluster(): void;
311
+ __warnWhenMapIsMissing(): Promise<void>;
294
312
  /**
295
- * Detach the current cluster listeners and reset the wiring flag so
296
- * `__wireChildren` binds afresh onto a replacement cluster.
313
+ * Detach the current cluster listeners so a replacement can be wired afresh.
297
314
  * @private
298
315
  */
299
316
  __unwireCluster(): void;
300
317
  /**
301
- * Attach the `MapboxCluster`/`MapboxGeocoder` listeners once those children
302
- * are available. Both mount asynchronously (the geocoder even lazy-imports its
303
- * module), so we poll a bounded number of ticks until *each* is wired — the
304
- * cluster is required, the geocoder optional. A locator missing the geocoder
305
- * simply polls to the attempt cap (bounded and harmless). The standing
306
- * connected-event subscriptions cover anything that mounts after the cap.
318
+ * Detach the current geocoder listener.
319
+ * @private
320
+ */
321
+ __unwireGeocoder(): void;
322
+ /**
323
+ * Attach the `MapboxCluster` listeners, once, to the first cluster in the
324
+ * subtree. A no-op while the orchestrator itself is unmounted: the collection
325
+ * outlives a mount cycle, so `mounted()` wires whatever it already holds.
326
+ * @private
327
+ */
328
+ __wireCluster(cluster?: MapboxCluster): void;
329
+ /**
330
+ * Attach the optional `MapboxGeocoder` listener, once, to the first geocoder
331
+ * in the subtree.
307
332
  * @private
308
- * @param {number} attempt
309
333
  */
310
- __wireChildren(attempt?: number): void;
334
+ __wireGeocoder(geocoder?: MapboxGeocoder): void;
311
335
  /**
312
- * Mounted hook: bind the delegated sidebar click, resolve and bind the map,
313
- * and install the standing connected-event subscriptions so a late or replaced
314
- * map/cluster (re)binds instead of stranding the orchestrator.
336
+ * Mounted hook: wire whatever the children collections already hold, bind the
337
+ * delegated sidebar click, resolve and bind the map, and install the standing
338
+ * `MAPBOX_MAP_CONNECTED` subscription so a late or replaced map rebinds
339
+ * instead of stranding the orchestrator.
315
340
  */
316
341
  mounted(): void;
317
342
  /**
318
- * Destroyed hook: detach every listener, close the popup and clear the cached
343
+ * Unmounted hook: detach every listener, close the popup and clear the cached
319
344
  * references — even when the element has already been detached from the DOM.
320
345
  */
321
- destroyed(): void;
346
+ unmounted(): void;
322
347
  }
323
348
  //#endregion
324
349
  export { StoreLocator, StoreLocator as default, StoreLocatorProps };