@studiometa/ui-mapbox 1.11.1 → 2.0.0-alpha.1

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 (50) hide show
  1. package/README.md +12 -16
  2. package/dist/AbstractMapboxControl.js +1 -1
  3. package/dist/AbstractMapboxControl.js.map +1 -1
  4. package/dist/AbstractMapboxMapChild.d.ts +32 -12
  5. package/dist/AbstractMapboxMapChild.js +24 -17
  6. package/dist/AbstractMapboxMapChild.js.map +1 -1
  7. package/dist/MapboxCluster.d.ts +19 -2
  8. package/dist/MapboxCluster.js +11 -9
  9. package/dist/MapboxCluster.js.map +1 -1
  10. package/dist/MapboxClusterItem.d.ts +11 -3
  11. package/dist/MapboxClusterItem.js +5 -6
  12. package/dist/MapboxClusterItem.js.map +1 -1
  13. package/dist/MapboxFullscreenControl.d.ts +8 -4
  14. package/dist/MapboxFullscreenControl.js +6 -2
  15. package/dist/MapboxFullscreenControl.js.map +1 -1
  16. package/dist/MapboxGeocoder.d.ts +57 -5
  17. package/dist/MapboxGeocoder.js +73 -16
  18. package/dist/MapboxGeocoder.js.map +1 -1
  19. package/dist/MapboxGeolocateControl.d.ts +8 -4
  20. package/dist/MapboxGeolocateControl.js +16 -12
  21. package/dist/MapboxGeolocateControl.js.map +1 -1
  22. package/dist/MapboxImage.d.ts +11 -1
  23. package/dist/MapboxImage.js +0 -1
  24. package/dist/MapboxImage.js.map +1 -1
  25. package/dist/MapboxImages.d.ts +9 -1
  26. package/dist/MapboxImages.js +1 -2
  27. package/dist/MapboxImages.js.map +1 -1
  28. package/dist/MapboxLayer.js.map +1 -1
  29. package/dist/MapboxMap.d.ts +17 -2
  30. package/dist/MapboxMap.js +5 -5
  31. package/dist/MapboxMap.js.map +1 -1
  32. package/dist/MapboxMarker.js.map +1 -1
  33. package/dist/MapboxNavigationControl.d.ts +8 -4
  34. package/dist/MapboxNavigationControl.js +13 -9
  35. package/dist/MapboxNavigationControl.js.map +1 -1
  36. package/dist/MapboxPopup.js.map +1 -1
  37. package/dist/MapboxSource.js +1 -1
  38. package/dist/MapboxSource.js.map +1 -1
  39. package/dist/StoreLocator.d.ts +76 -51
  40. package/dist/StoreLocator.js +112 -105
  41. package/dist/StoreLocator.js.map +1 -1
  42. package/dist/catalog.js +22 -11
  43. package/dist/catalog.js.map +1 -1
  44. package/dist/dependencies.d.ts +6 -4
  45. package/dist/dependencies.js +6 -4
  46. package/dist/dependencies.js.map +1 -1
  47. package/dist/manifest.js +14 -84
  48. package/dist/manifest.js.map +1 -1
  49. package/dist/scripts/manifest-types.d.ts +8 -5
  50. package/package.json +3 -3
@@ -1,17 +1,9 @@
1
1
  import { MAPBOX_MAP_CONNECTED } from "./AbstractMapboxMapChild.js";
2
- import { MAPBOX_CLUSTER_CONNECTED } from "./MapboxCluster.js";
3
2
  import { getMapboxGl } from "./dependencies.js";
4
3
  import { Base } from "@studiometa/js-toolkit/Base";
5
- import { nextTick } from "@studiometa/js-toolkit/utils/nextTick";
4
+ import { whenDOMSettled } from "@studiometa/js-toolkit/whenDOMSettled";
6
5
  //#region src/StoreLocator.ts
7
6
  /**
8
- * Maximum number of `nextTick` retries used to wire the `MapboxCluster` and the
9
- * optional `MapboxGeocoder`. They are mounted asynchronously (the geocoder even
10
- * lazy-imports its module), so they may not be queryable yet on the `map-load`
11
- * event: we poll a few ticks before giving up.
12
- */
13
- const WIRE_CHILDREN_MAX_ATTEMPTS = 10;
14
- /**
15
7
  * Coordinate a "find a store near you" experience on top of a `MapboxMap`.
16
8
  *
17
9
  * `StoreLocator` is a thin **orchestrator**: it owns no map rendering and no item
@@ -37,17 +29,15 @@ const WIRE_CHILDREN_MAX_ATTEMPTS = 10;
37
29
  * and the `map-select` event.
38
30
  *
39
31
  * The orchestrator requires its `MapboxCluster` (and `MapboxMap`) to live within
40
- * its own subtree; it resolves them with `$query`, retries a few ticks for
41
- * asynchronously-mounted children, and — like the map children — subscribes to
42
- * the `MAPBOX_MAP_CONNECTED` / `MAPBOX_CLUSTER_CONNECTED` events so a late or
43
- * replaced map/cluster (re)binds instead of stranding the orchestrator on a
44
- * destroyed instance, and to the map's own `remove` event so a removed map is
45
- * never called into. Register each component independently (e.g. with
46
- * `registerComponent`, optionally behind a lazy `importWhen*` helper):
47
- * `StoreLocator`, `MapboxMap`, `MapboxCluster` and `MapboxClusterItem`.
48
- * Registration order does not matter because children resolve their map through
49
- * the connected-event retry, and the orchestrator declares no child components
50
- * so nothing is ever double-mounted.
32
+ * its own subtree. It watches both with `$watchChildren()`, so a cluster or
33
+ * geocoder that mounts late — or one that replaces the wired instance — is
34
+ * picked up without polling; it subscribes to `MAPBOX_MAP_CONNECTED` because a
35
+ * map announces its Mapbox instance *after* mounting, which a children
36
+ * collection cannot report; and it subscribes to the map's own `remove` event
37
+ * so a removed map is never called into. Register each component independently
38
+ * with `registerComponent`: `StoreLocator`, `MapboxMap`, `MapboxCluster` and
39
+ * `MapboxClusterItem`. Registration and mount order do not matter, and the
40
+ * orchestrator declares no child components so nothing is ever double-mounted.
51
41
  *
52
42
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
53
43
  */
@@ -57,17 +47,13 @@ var StoreLocator = class extends Base {
57
47
  *
58
48
  * No child components are declared: `MapboxMap`, `MapboxCluster`,
59
49
  * `MapboxClusterItem` and `MapboxGeocoder` are each registered independently
60
- * (e.g. with `registerComponent`, optionally behind a lazy `importWhen*`
61
- * helper) and mount on their own. The orchestrator discovers them through
62
- * `$query` once available — declaring them here would double-mount them.
50
+ * with `registerComponent` and mount on their own. The orchestrator discovers
51
+ * them through `$watchChildren()`; declaring them here would double-mount
52
+ * them, since the registry already mounts a declared element.
63
53
  */
64
54
  static config = {
65
55
  name: "StoreLocator",
66
- emits: [
67
- "map-select",
68
- "map-deselect",
69
- "map-filter"
70
- ],
56
+ mountStrategy: "visible",
71
57
  options: {
72
58
  itemZoomLevel: {
73
59
  type: Number,
@@ -114,13 +100,13 @@ var StoreLocator = class extends Base {
114
100
  __popup;
115
101
  /**
116
102
  * Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on
117
- * destroy and when the cluster is replaced (so the orchestrator re-wires onto
118
- * the new instance rather than staying subscribed to the destroyed one).
103
+ * unmount and when the cluster is replaced (so the orchestrator re-wires onto
104
+ * the new instance rather than staying subscribed to the unmounted one).
119
105
  * @private
120
106
  */
121
107
  __offCluster = [];
122
108
  /**
123
- * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on destroy.
109
+ * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on unmount.
124
110
  * @private
125
111
  */
126
112
  __offGeocoder = [];
@@ -144,41 +130,62 @@ var StoreLocator = class extends Base {
144
130
  */
145
131
  __offMapConnected;
146
132
  /**
147
- * Off handle for the standing document-level `MAPBOX_CLUSTER_CONNECTED` retry
148
- * subscription, so a cluster that mounts late — or replaces the wired one — is
149
- * (re)wired instead of stranding the orchestrator on a destroyed instance.
150
- * @private
151
- */
152
- __offClusterConnected;
153
- /**
154
- * Whether the `MapboxCluster` listeners are already attached.
133
+ * The mounted `MapboxCluster` descendants, live and in DOM order.
134
+ *
135
+ * The collection answers "has the cluster mounted yet?" on its own: a cluster
136
+ * that mounts late, or one that replaces the wired one, reaches the
137
+ * `added`/`removed` callbacks with nothing to poll. The cluster still
138
+ * dispatches `MAPBOX_CLUSTER_CONNECTED` for `MapboxClusterItem`, which looks
139
+ * *up* for its cluster and has no watching counterpart to `$closest()`.
155
140
  * @private
156
141
  */
157
- __clusterWired = false;
142
+ __clusters = this.$watchChildren("MapboxCluster", {
143
+ added: (cluster) => this.__wireCluster(cluster),
144
+ removed: (cluster) => {
145
+ if (this.__cluster === cluster) {
146
+ this.__unwireCluster();
147
+ this.__wireCluster(this.__clusters.items[0]);
148
+ }
149
+ }
150
+ });
158
151
  /**
159
- * Whether the `MapboxGeocoder` `map-result` listener is already attached.
152
+ * The mounted `MapboxGeocoder` descendants, live and in DOM order. The
153
+ * geocoder is optional, so nothing waits for it: it wires itself whenever it
154
+ * turns up.
160
155
  * @private
161
156
  */
162
- __geocoderWired = false;
157
+ __geocoders = this.$watchChildren("MapboxGeocoder", {
158
+ added: (geocoder) => this.__wireGeocoder(geocoder),
159
+ removed: (geocoder) => {
160
+ if (this.__geocoder === geocoder) {
161
+ this.__unwireGeocoder();
162
+ this.__wireGeocoder(this.__geocoders.items[0]);
163
+ }
164
+ }
165
+ });
163
166
  /**
164
- * The closest child `MapboxMap` component.
167
+ * The child `MapboxMap` component, once it has mounted.
168
+ *
169
+ * The getter does not warn when there is none: a wrapper mounts before the
170
+ * elements inside it and mount order is not guaranteed, so "no map yet" is
171
+ * the normal state on every healthy locator. A locator with genuinely no map
172
+ * in its markup is reported once instead, from
173
+ * {@link __warnWhenMapIsMissing}.
165
174
  */
166
175
  get mapboxMap() {
167
- const mapboxMap = this.$query("MapboxMap")[0];
168
- if (!mapboxMap) this.$warn("Can not find a child MapboxMap component.");
169
- return mapboxMap;
176
+ return this.$query("MapboxMap")[0];
170
177
  }
171
178
  /**
172
179
  * The child `MapboxCluster`, discovered in the subtree.
173
180
  */
174
181
  get cluster() {
175
- return this.__cluster ?? this.$query("MapboxCluster")[0];
182
+ return this.__cluster ?? this.__clusters.items[0];
176
183
  }
177
184
  /**
178
185
  * The optional child `MapboxGeocoder`, discovered in the subtree.
179
186
  */
180
187
  get geocoder() {
181
- return this.__geocoder ?? this.$query("MapboxGeocoder")[0];
188
+ return this.__geocoder ?? this.__geocoders.items[0];
182
189
  }
183
190
  /**
184
191
  * The Mapbox `Map` instance. Only valid once the map has loaded.
@@ -206,7 +213,7 @@ var StoreLocator = class extends Base {
206
213
  zoom: this.$options.itemZoomLevel
207
214
  });
208
215
  this.__openPopup(item);
209
- this.$emit("map-select", item);
216
+ this.$emit("map-select", { item });
210
217
  }
211
218
  /**
212
219
  * Clear the current selection, close the popup and emit a `map-deselect` event.
@@ -295,7 +302,7 @@ var StoreLocator = class extends Base {
295
302
  inView.sort((a, b) => center.distanceTo(new LngLat(a.lngLat[0], a.lngLat[1])) - center.distanceTo(new LngLat(b.lngLat[0], b.lngLat[1])));
296
303
  }
297
304
  this.__reorderList(inView);
298
- this.$emit("map-filter", inView);
305
+ this.$emit("map-filter", { items: inView });
299
306
  }
300
307
  /**
301
308
  * Reorder the in-view items so their DOM order matches the distance sort.
@@ -316,7 +323,7 @@ var StoreLocator = class extends Base {
316
323
  * @private
317
324
  */
318
325
  __handleItemClick = (event) => {
319
- const [item] = event.detail ?? [];
326
+ const { item } = event.detail ?? {};
320
327
  if (item) this.selectItem(item);
321
328
  };
322
329
  /**
@@ -345,7 +352,7 @@ var StoreLocator = class extends Base {
345
352
  * @private
346
353
  */
347
354
  __handleGeocoderResult = (event) => {
348
- const [result] = event.detail ?? [];
355
+ const { result } = event.detail ?? {};
349
356
  const map = this.__map;
350
357
  if (!map || !result) return;
351
358
  if (Array.isArray(result.bbox)) {
@@ -377,7 +384,9 @@ var StoreLocator = class extends Base {
377
384
  this.__bindMapRemove(map);
378
385
  map.off("moveend", this.__handleMoveEnd);
379
386
  map.on("moveend", this.__handleMoveEnd);
380
- this.__wireChildren();
387
+ this.__wireCluster(this.__clusters.items[0]);
388
+ this.__wireGeocoder(this.__geocoders.items[0]);
389
+ this.__refresh();
381
390
  };
382
391
  /**
383
392
  * Subscribe once to the ready map's own `remove` event so a map removed while
@@ -435,78 +444,80 @@ var StoreLocator = class extends Base {
435
444
  this.__offMapConnected = () => document.removeEventListener(MAPBOX_MAP_CONNECTED, handler);
436
445
  }
437
446
  /**
438
- * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and (re)wire when a
439
- * `MapboxCluster` inside this orchestrator connects. A cluster that replaces
440
- * the wired one drops the stale wiring and re-wires onto the new instance, so
441
- * list clicks, viewport filtering and selection keep working after a swap.
447
+ * Report a locator with no `MapboxMap` in its markup, once.
448
+ *
449
+ * The check reads the **element**, not the mounted instance: DOM ancestry is
450
+ * a fact that exists before anything mounts, so it is immune both to mount
451
+ * ordering and to the map's mount strategy — a `data-mount` that has not
452
+ * fired yet is not a missing map. `whenDOMSettled()` waits for
453
+ * the mutation batch that brought the locator in, which is the earliest
454
+ * moment the markup can be judged complete.
442
455
  * @private
443
456
  */
444
- __waitForConnectedCluster() {
445
- if (this.__offClusterConnected) return;
446
- const handler = (event) => {
447
- const cluster = event.detail;
448
- if (!cluster?.$el || !this.$el.contains(cluster.$el)) return;
449
- if (this.__cluster && this.__cluster !== cluster) this.__unwireCluster();
450
- if (!this.__clusterWired) this.__wireChildren();
451
- };
452
- document.addEventListener(MAPBOX_CLUSTER_CONNECTED, handler);
453
- this.__offClusterConnected = () => document.removeEventListener(MAPBOX_CLUSTER_CONNECTED, handler);
457
+ async __warnWhenMapIsMissing() {
458
+ await whenDOMSettled();
459
+ if (this.$isMounted && !this.$el.querySelector("[data-component=\"MapboxMap\"]")) this.$warn("store-locator.no-map", "Can not find a child MapboxMap component.");
454
460
  }
455
461
  /**
456
- * Detach the current cluster listeners and reset the wiring flag so
457
- * `__wireChildren` binds afresh onto a replacement cluster.
462
+ * Detach the current cluster listeners so a replacement can be wired afresh.
458
463
  * @private
459
464
  */
460
465
  __unwireCluster() {
461
466
  for (const off of this.__offCluster) off();
462
467
  this.__offCluster = [];
463
- this.__clusterWired = false;
464
468
  this.__cluster = void 0;
465
469
  }
466
470
  /**
467
- * Attach the `MapboxCluster`/`MapboxGeocoder` listeners once those children
468
- * are available. Both mount asynchronously (the geocoder even lazy-imports its
469
- * module), so we poll a bounded number of ticks until *each* is wired — the
470
- * cluster is required, the geocoder optional. A locator missing the geocoder
471
- * simply polls to the attempt cap (bounded and harmless). The standing
472
- * connected-event subscriptions cover anything that mounts after the cap.
471
+ * Detach the current geocoder listener.
473
472
  * @private
474
- * @param {number} attempt
475
- */
476
- __wireChildren(attempt = 0) {
477
- const { cluster, geocoder } = this;
478
- if (cluster && cluster.$isMounted && !this.__clusterWired) {
479
- this.__clusterWired = true;
480
- this.__cluster = cluster;
481
- this.__offCluster.push(cluster.$on("map-item-click", this.__handleItemClick));
482
- this.__offCluster.push(cluster.$on("map-update", this.__handleClusterUpdate));
483
- this.__refresh();
484
- }
485
- if (geocoder && !this.__geocoderWired) {
486
- this.__geocoderWired = true;
487
- this.__geocoder = geocoder;
488
- this.__offGeocoder.push(geocoder.$on("map-result", this.__handleGeocoderResult));
489
- }
490
- if ((!this.__clusterWired || !this.__geocoderWired) && attempt < WIRE_CHILDREN_MAX_ATTEMPTS) nextTick(() => {
491
- if (this.$isMounted) this.__wireChildren(attempt + 1);
492
- });
473
+ */
474
+ __unwireGeocoder() {
475
+ for (const off of this.__offGeocoder) off();
476
+ this.__offGeocoder = [];
477
+ this.__geocoder = void 0;
478
+ }
479
+ /**
480
+ * Attach the `MapboxCluster` listeners, once, to the first cluster in the
481
+ * subtree. A no-op while the orchestrator itself is unmounted: the collection
482
+ * outlives a mount cycle, so `mounted()` wires whatever it already holds.
483
+ * @private
484
+ */
485
+ __wireCluster(cluster) {
486
+ if (!cluster || this.__cluster || !this.$isMounted) return;
487
+ this.__cluster = cluster;
488
+ this.__offCluster.push(cluster.$on("map-item-click", this.__handleItemClick));
489
+ this.__offCluster.push(cluster.$on("map-update", this.__handleClusterUpdate));
490
+ this.__refresh();
491
+ }
492
+ /**
493
+ * Attach the optional `MapboxGeocoder` listener, once, to the first geocoder
494
+ * in the subtree.
495
+ * @private
496
+ */
497
+ __wireGeocoder(geocoder) {
498
+ if (!geocoder || this.__geocoder || !this.$isMounted) return;
499
+ this.__geocoder = geocoder;
500
+ this.__offGeocoder.push(geocoder.$on("map-result", this.__handleGeocoderResult));
493
501
  }
494
502
  /**
495
- * Mounted hook: bind the delegated sidebar click, resolve and bind the map,
496
- * and install the standing connected-event subscriptions so a late or replaced
497
- * map/cluster (re)binds instead of stranding the orchestrator.
503
+ * Mounted hook: wire whatever the children collections already hold, bind the
504
+ * delegated sidebar click, resolve and bind the map, and install the standing
505
+ * `MAPBOX_MAP_CONNECTED` subscription so a late or replaced map rebinds
506
+ * instead of stranding the orchestrator.
498
507
  */
499
508
  mounted() {
500
509
  this.$el.addEventListener("click", this.__handleListClick);
510
+ this.__wireCluster(this.__clusters.items[0]);
511
+ this.__wireGeocoder(this.__geocoders.items[0]);
501
512
  this.__bindMap();
502
513
  this.__waitForConnectedMap();
503
- this.__waitForConnectedCluster();
514
+ this.__warnWhenMapIsMissing();
504
515
  }
505
516
  /**
506
- * Destroyed hook: detach every listener, close the popup and clear the cached
517
+ * Unmounted hook: detach every listener, close the popup and clear the cached
507
518
  * references — even when the element has already been detached from the DOM.
508
519
  */
509
- destroyed() {
520
+ unmounted() {
510
521
  for (const off of this.__offCluster) off();
511
522
  for (const off of this.__offGeocoder) off();
512
523
  this.__offCluster = [];
@@ -517,8 +528,6 @@ var StoreLocator = class extends Base {
517
528
  this.__offMapRemove = void 0;
518
529
  this.__offMapConnected?.();
519
530
  this.__offMapConnected = void 0;
520
- this.__offClusterConnected?.();
521
- this.__offClusterConnected = void 0;
522
531
  this.__map?.off("moveend", this.__handleMoveEnd);
523
532
  this.$el.removeEventListener("click", this.__handleListClick);
524
533
  this.__popup?.remove();
@@ -528,8 +537,6 @@ var StoreLocator = class extends Base {
528
537
  this.__cluster = void 0;
529
538
  this.__geocoder = void 0;
530
539
  this.isLoaded = false;
531
- this.__clusterWired = false;
532
- this.__geocoderWired = false;
533
540
  }
534
541
  };
535
542
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"StoreLocator.js","names":[],"sources":["../src/StoreLocator.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { nextTick } from '@studiometa/js-toolkit/utils/nextTick';\nimport type { Map, LngLatLike, LngLatBoundsLike, Popup } from 'mapbox-gl';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxMap } from './MapboxMap.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\nimport { MAPBOX_CLUSTER_CONNECTED, type MapboxCluster } from './MapboxCluster.js';\nimport type { MapboxClusterItem } from './MapboxClusterItem.js';\nimport type { MapboxGeocoder } from './MapboxGeocoder.js';\n\n/**\n * Maximum number of `nextTick` retries used to wire the `MapboxCluster` and the\n * optional `MapboxGeocoder`. They are mounted asynchronously (the geocoder even\n * lazy-imports its module), so they may not be queryable yet on the `map-load`\n * event: we poll a few ticks before giving up.\n */\nconst WIRE_CHILDREN_MAX_ATTEMPTS = 10;\n\nexport interface StoreLocatorProps extends BaseProps {\n $options: {\n itemZoomLevel: number;\n noSort: boolean;\n fitOnUpdate: boolean;\n popupOptions: Record<string, unknown>;\n };\n}\n\n/**\n * Coordinate a \"find a store near you\" experience on top of a `MapboxMap`.\n *\n * `StoreLocator` is a thin **orchestrator**: it owns no map rendering and no item\n * registry of its own. It wraps a `MapboxMap` containing a\n * [`MapboxCluster`](./MapboxCluster.js) of\n * [`MapboxClusterItem`](./MapboxClusterItem.js)s (the declarative clustered map +\n * list source driver) plus an optional\n * [`MapboxGeocoder`](./MapboxGeocoder.js), and layers the search UX on top:\n * selection, viewport filtering and address search. The cluster keeps owning the\n * data (it derives the source from the registered items); the orchestrator only\n * reads that item set and reacts to it.\n *\n * Each store has three independent states, each with its own source of truth:\n *\n * 1. **Registered** — the item exists in the DOM. Owned by the `MapboxCluster`,\n * it drives the **map data** and only changes when the item set changes (e.g.\n * a `Fetch` swaps the list). The orchestrator is notified through the\n * cluster's `map-update` event.\n * 2. **In bounds** — the item's `lngLat` is inside the current viewport. Drives\n * **list visibility + distance sort only**, recomputed on map `moveend`, and\n * never touches the map data.\n * 3. **Selected** — the chosen item. Drives fly-to, the popup, `active` styling\n * and the `map-select` event.\n *\n * The orchestrator requires its `MapboxCluster` (and `MapboxMap`) to live within\n * its own subtree; it resolves them with `$query`, retries a few ticks for\n * asynchronously-mounted children, and — like the map children — subscribes to\n * the `MAPBOX_MAP_CONNECTED` / `MAPBOX_CLUSTER_CONNECTED` events so a late or\n * replaced map/cluster (re)binds instead of stranding the orchestrator on a\n * destroyed instance, and to the map's own `remove` event so a removed map is\n * never called into. Register each component independently (e.g. with\n * `registerComponent`, optionally behind a lazy `importWhen*` helper):\n * `StoreLocator`, `MapboxMap`, `MapboxCluster` and `MapboxClusterItem`.\n * Registration order does not matter because children resolve their map through\n * the connected-event retry, and the orchestrator declares no child components\n * so nothing is ever double-mounted.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & StoreLocatorProps> {\n /**\n * Config.\n *\n * No child components are declared: `MapboxMap`, `MapboxCluster`,\n * `MapboxClusterItem` and `MapboxGeocoder` are each registered independently\n * (e.g. with `registerComponent`, optionally behind a lazy `importWhen*`\n * helper) and mount on their own. The orchestrator discovers them through\n * `$query` once available — declaring them here would double-mount them.\n */\n static config: BaseConfig = {\n name: 'StoreLocator',\n emits: ['map-select', 'map-deselect', 'map-filter'],\n options: {\n itemZoomLevel: {\n type: Number,\n default: 14,\n },\n // Boolean options default to `false`, so sorting is ON by default;\n // `data-option-no-sort` disables the distance sort.\n noSort: Boolean,\n // Fit the map bounds to the item set whenever it changes.\n fitOnUpdate: Boolean,\n // Options forwarded to the `mapboxgl.Popup` opened on selection.\n popupOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n };\n\n /**\n * Whether the underlying map has finished loading.\n */\n isLoaded = false;\n\n /**\n * The Mapbox `Map` instance cached at load, so every listener and teardown\n * path reaches it without a fresh `$query` (which returns nothing once the\n * element is detached).\n * @private\n */\n __map?: Map;\n\n /**\n * The child `MapboxCluster`, cached at wire-time for detach-safe teardown.\n * @private\n */\n __cluster?: MapboxCluster;\n\n /**\n * The optional child `MapboxGeocoder`, cached at wire-time.\n * @private\n */\n __geocoder?: MapboxGeocoder;\n\n /**\n * The currently selected item, if any.\n * @private\n */\n __selected?: MapboxClusterItem;\n\n /**\n * The popup opened for the selected item, created lazily.\n * @private\n */\n __popup?: Popup;\n\n /**\n * Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on\n * destroy and when the cluster is replaced (so the orchestrator re-wires onto\n * the new instance rather than staying subscribed to the destroyed one).\n * @private\n */\n __offCluster: Array<() => void> = [];\n\n /**\n * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on destroy.\n * @private\n */\n __offGeocoder: Array<() => void> = [];\n\n /**\n * Off handle for the pending `map-load` subscription.\n * @private\n */\n __offMapLoad?: () => void;\n\n /**\n * Off handle for the ready map's own `remove` subscription, used to drop the\n * cached map the moment it is removed so no listener/teardown ever calls a\n * method on a dead map.\n * @private\n */\n __offMapRemove?: () => void;\n\n /**\n * Off handle for the standing document-level `MAPBOX_MAP_CONNECTED` retry\n * subscription, so a map that mounts (or a replacement that mounts after the\n * previous was removed) rebinds the orchestrator.\n * @private\n */\n __offMapConnected?: () => void;\n\n /**\n * Off handle for the standing document-level `MAPBOX_CLUSTER_CONNECTED` retry\n * subscription, so a cluster that mounts late — or replaces the wired one — is\n * (re)wired instead of stranding the orchestrator on a destroyed instance.\n * @private\n */\n __offClusterConnected?: () => void;\n\n /**\n * Whether the `MapboxCluster` listeners are already attached.\n * @private\n */\n __clusterWired = false;\n\n /**\n * Whether the `MapboxGeocoder` `map-result` listener is already attached.\n * @private\n */\n __geocoderWired = false;\n\n /**\n * The closest child `MapboxMap` component.\n */\n get mapboxMap() {\n const mapboxMap = this.$query<MapboxMap>('MapboxMap')[0];\n\n if (!mapboxMap) {\n this.$warn('Can not find a child MapboxMap component.');\n }\n\n return mapboxMap;\n }\n\n /**\n * The child `MapboxCluster`, discovered in the subtree.\n */\n get cluster(): MapboxCluster | undefined {\n return this.__cluster ?? this.$query<MapboxCluster>('MapboxCluster')[0];\n }\n\n /**\n * The optional child `MapboxGeocoder`, discovered in the subtree.\n */\n get geocoder(): MapboxGeocoder | undefined {\n return this.__geocoder ?? this.$query<MapboxGeocoder>('MapboxGeocoder')[0];\n }\n\n /**\n * The Mapbox `Map` instance. Only valid once the map has loaded.\n */\n get map() {\n return this.__map ?? this.mapboxMap?.map;\n }\n\n /**\n * The registered items, read from the cluster (their single source of truth).\n */\n get items(): readonly MapboxClusterItem[] {\n return this.__cluster?.items ?? [];\n }\n\n /**\n * Select an item: deactivate the previous one, fly to the item, open its\n * popup, mark it active and emit a `map-select` event.\n * @param {MapboxClusterItem} item\n */\n selectItem(item: MapboxClusterItem) {\n if (this.__selected && this.__selected !== item) {\n this.__selected.setActive(false);\n }\n\n item.setActive(true);\n this.__selected = item;\n\n this.__map?.flyTo({\n center: item.lngLat as LngLatLike,\n zoom: this.$options.itemZoomLevel,\n });\n\n this.__openPopup(item);\n this.$emit('map-select', item);\n }\n\n /**\n * Clear the current selection, close the popup and emit a `map-deselect` event.\n */\n deselect() {\n if (this.__selected) {\n this.__selected.setActive(false);\n this.__selected = undefined;\n }\n\n this.__popup?.remove();\n this.$emit('map-deselect');\n }\n\n /**\n * Open (or move) the selection popup on the given item, using its popup\n * content. A content-less item closes any open popup instead.\n *\n * NOTE: closing this popup through Mapbox's own close-button UI does NOT clear\n * the selection — `data-active`/`aria-current`/`__selected` stay set by design.\n * Popup visibility and selection are independent: dismissing the popup does not\n * deselect the store. Call `deselect()` explicitly to clear the selection.\n * @private\n * @param {MapboxClusterItem} item\n */\n __openPopup(item: MapboxClusterItem) {\n const map = this.__map;\n\n if (!map) {\n return;\n }\n\n const content = item.popupContent;\n\n if (!content) {\n this.__popup?.remove();\n return;\n }\n\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n this.__popup.setLngLat(item.lngLat as LngLatLike).setHTML(content).addTo(map);\n }\n\n /**\n * Fit the map to the whole item set (when `fitOnUpdate`) then recompute the\n * in-view list. Runs on an item-set change (the cluster's `map-update` event) and\n * when the cluster is first wired.\n * @private\n */\n __refresh() {\n if (this.$options.fitOnUpdate && this.items.length > 0) {\n this.__map?.fitBounds(this.__getItemsBounds(), { padding: 40 });\n }\n\n this.__filterItemsInView();\n }\n\n /**\n * Compute the bounding box of the whole registered item set as a\n * `[[minLng, minLat], [maxLng, maxLat]]` tuple.\n * @private\n * @returns {LngLatBoundsLike}\n */\n __getItemsBounds(): LngLatBoundsLike {\n let minLng = Infinity;\n let minLat = Infinity;\n let maxLng = -Infinity;\n let maxLat = -Infinity;\n\n for (const item of this.items) {\n const [lng, lat] = item.lngLat;\n minLng = Math.min(minLng, lng);\n minLat = Math.min(minLat, lat);\n maxLng = Math.max(maxLng, lng);\n maxLat = Math.max(maxLat, lat);\n }\n\n return [\n [minLng, minLat],\n [maxLng, maxLat],\n ];\n }\n\n /**\n * Recompute the visible/sorted list = registered ∩ in-bounds, distance-sorted.\n *\n * Reflects the in-bounds state on every item, reorders the in-view items in\n * their shared parent list (so DOM order matches distance) and emits `map-filter`\n * with the in-view items. Never touches the map data.\n * @private\n */\n __filterItemsInView() {\n const map = this.__map;\n\n if (!map) {\n return;\n }\n\n const bounds = map.getBounds();\n const center = map.getCenter();\n const inView: MapboxClusterItem[] = [];\n\n for (const item of this.items) {\n const isInBounds = Boolean(bounds?.contains(item.lngLat as LngLatLike));\n item.setInBounds(isInBounds);\n\n if (isInBounds) {\n inView.push(item);\n }\n }\n\n if (!this.$options.noSort && center) {\n const { LngLat } = getMapboxGl();\n inView.sort(\n (a, b) =>\n center.distanceTo(new LngLat(a.lngLat[0], a.lngLat[1])) -\n center.distanceTo(new LngLat(b.lngLat[0], b.lngLat[1])),\n );\n }\n\n this.__reorderList(inView);\n this.$emit('map-filter', inView);\n }\n\n /**\n * Reorder the in-view items so their DOM order matches the distance sort.\n * Appending a connected node moves it, keeping the list free of duplicates.\n * Items are reordered inside their own shared parent — the sidebar list\n * element — which is resolved per item so no `list` ref is required (a ref\n * declared on the sidebar would not bind anyway: the items live inside the\n * nested `MapboxCluster`, outside this orchestrator's ref scope).\n * @private\n * @param {MapboxClusterItem[]} items\n */\n __reorderList(items: MapboxClusterItem[]) {\n for (const item of items) {\n item.$el.parentElement?.append(item.$el);\n }\n }\n\n /**\n * Handle the cluster's `map-item-click`: select the item behind the clicked\n * unclustered point, if one was resolved.\n * @private\n */\n __handleItemClick = (event: Event) => {\n const [item] = (event as CustomEvent).detail ?? [];\n\n if (item) {\n this.selectItem(item as MapboxClusterItem);\n }\n };\n\n /**\n * Handle a click anywhere in the sidebar: resolve the nearest\n * `MapboxClusterItem` element back to its instance and select it. Delegated on\n * the root so it survives `Fetch`/facet list swaps.\n * @private\n */\n __handleListClick = (event: Event) => {\n const target = event.target as Element | null;\n const el = target?.closest?.('[data-component=\"MapboxClusterItem\"]');\n\n if (!el) {\n return;\n }\n\n const item = this.items.find((candidate) => candidate.$el === el);\n\n if (item) {\n this.selectItem(item);\n }\n };\n\n /**\n * Handle the cluster's `map-update` (the item set changed): re-fit and re-filter.\n * Drops a stale selection whose item is no longer registered.\n * @private\n */\n __handleClusterUpdate = () => {\n // The selected store may have been removed by the swap. Run the full\n // deselect cleanup — not just clearing `__selected` — so its popup is\n // removed from the map and `map-deselect` is emitted, instead of leaving the\n // removed store's popup stranded while the locator claims nothing is\n // selected.\n if (this.__selected && !this.items.includes(this.__selected)) {\n this.deselect();\n }\n\n this.__refresh();\n };\n\n /**\n * Handle a `MapboxGeocoder` `map-result`: frame the map on the geocoded location.\n * @private\n */\n __handleGeocoderResult = (event: Event) => {\n const [result] = (event as CustomEvent).detail ?? [];\n const map = this.__map;\n\n if (!map || !result) {\n return;\n }\n\n if (Array.isArray(result.bbox)) {\n const [minLng, minLat, maxLng, maxLat] = result.bbox;\n map.fitBounds([\n [minLng, minLat],\n [maxLng, maxLat],\n ]);\n } else if (result.center) {\n map.flyTo({ center: result.center as LngLatLike });\n }\n };\n\n /**\n * Recompute the in-view list whenever the viewport settles.\n * @private\n */\n __handleMoveEnd = () => {\n this.__filterItemsInView();\n };\n\n /**\n * React to the map being ready: cache it, subscribe to its `remove`, bind the\n * viewport listener and wire the children.\n *\n * Idempotent for the same map (a re-entrant `map-load` or connected event does\n * not double-bind `moveend`), and rebinds cleanly onto a replacement map.\n * @private\n */\n __handleMapLoad = () => {\n const map = this.mapboxMap?.map;\n\n if (!map) {\n return;\n }\n\n // Rebinding onto a replacement: drop the viewport listener from the previous\n // map before caching and binding the new one.\n if (this.__map && this.__map !== map) {\n this.__map.off('moveend', this.__handleMoveEnd);\n }\n\n this.isLoaded = true;\n this.__map = map;\n this.__bindMapRemove(map);\n map.off('moveend', this.__handleMoveEnd);\n map.on('moveend', this.__handleMoveEnd);\n this.__wireChildren();\n };\n\n /**\n * Subscribe once to the ready map's own `remove` event so a map removed while\n * the orchestrator stays mounted drops the cached (now dead) map instead of\n * calling `flyTo`/`getBounds`/`fitBounds`/`off` on it. A replacement map\n * announces itself through `MAPBOX_MAP_CONNECTED` and rebinds the orchestrator.\n * @private\n * @param {Map} map\n */\n __bindMapRemove(map: Map) {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n\n // Degrade gracefully for minimal map doubles without an event emitter.\n if (typeof map?.on !== 'function') {\n return;\n }\n\n const handler = () => {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n this.__map?.off('moveend', this.__handleMoveEnd);\n this.__map = undefined;\n this.isLoaded = false;\n };\n\n map.on('remove', handler);\n this.__offMapRemove = () => map.off('remove', handler);\n }\n\n /**\n * Resolve the child `MapboxMap` and bind to it — now if it is already loaded,\n * otherwise once on `map-load`. When none exists yet the standing\n * `MAPBOX_MAP_CONNECTED` subscription rebinds later.\n * @private\n */\n __bindMap() {\n const { mapboxMap } = this;\n\n if (!mapboxMap) {\n return;\n }\n\n if (mapboxMap.isLoaded) {\n this.__handleMapLoad();\n } else {\n this.__offMapLoad?.();\n this.__offMapLoad = mapboxMap.$on('map-load', this.__handleMapLoad, { once: true });\n }\n }\n\n /**\n * Subscribe once to `MAPBOX_MAP_CONNECTED` and (re)bind when a `MapboxMap`\n * inside this orchestrator connects — a late-mounted map, or a replacement for\n * one that was removed. Ignores maps outside this subtree (several independent\n * locators/maps can share a page).\n * @private\n */\n __waitForConnectedMap() {\n if (this.__offMapConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const mapboxMap = (event as CustomEvent<MapboxMap>).detail;\n\n // The map lives *inside* the orchestrator: filter to descendants.\n if (!mapboxMap?.$el || !this.$el.contains(mapboxMap.$el)) {\n return;\n }\n\n // Already bound to this exact, loaded map: nothing to do.\n if (this.__map && this.__map === mapboxMap.map) {\n return;\n }\n\n this.__bindMap();\n };\n\n document.addEventListener(MAPBOX_MAP_CONNECTED, handler);\n this.__offMapConnected = () => document.removeEventListener(MAPBOX_MAP_CONNECTED, handler);\n }\n\n /**\n * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and (re)wire when a\n * `MapboxCluster` inside this orchestrator connects. A cluster that replaces\n * the wired one drops the stale wiring and re-wires onto the new instance, so\n * list clicks, viewport filtering and selection keep working after a swap.\n * @private\n */\n __waitForConnectedCluster() {\n if (this.__offClusterConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const cluster = (event as CustomEvent<MapboxCluster>).detail;\n\n if (!cluster?.$el || !this.$el.contains(cluster.$el)) {\n return;\n }\n\n if (this.__cluster && this.__cluster !== cluster) {\n // A replacement cluster: drop the stale wiring and re-wire onto it.\n this.__unwireCluster();\n }\n\n if (!this.__clusterWired) {\n this.__wireChildren();\n }\n };\n\n document.addEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n this.__offClusterConnected = () =>\n document.removeEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n }\n\n /**\n * Detach the current cluster listeners and reset the wiring flag so\n * `__wireChildren` binds afresh onto a replacement cluster.\n * @private\n */\n __unwireCluster() {\n for (const off of this.__offCluster) {\n off();\n }\n this.__offCluster = [];\n this.__clusterWired = false;\n this.__cluster = undefined;\n }\n\n /**\n * Attach the `MapboxCluster`/`MapboxGeocoder` listeners once those children\n * are available. Both mount asynchronously (the geocoder even lazy-imports its\n * module), so we poll a bounded number of ticks until *each* is wired — the\n * cluster is required, the geocoder optional. A locator missing the geocoder\n * simply polls to the attempt cap (bounded and harmless). The standing\n * connected-event subscriptions cover anything that mounts after the cap.\n * @private\n * @param {number} attempt\n */\n __wireChildren(attempt = 0) {\n const { cluster, geocoder } = this;\n\n // The cluster becomes queryable as soon as it is constructed, but its\n // GeoJSON source is only added from its `mounted()` hook. Observing\n // `$isMounted` guarantees the source is ready before we wire and refresh.\n if (cluster && cluster.$isMounted && !this.__clusterWired) {\n this.__clusterWired = true;\n this.__cluster = cluster;\n this.__offCluster.push(cluster.$on('map-item-click', this.__handleItemClick));\n this.__offCluster.push(cluster.$on('map-update', this.__handleClusterUpdate));\n // Catch up on the cluster's current item set: it may have emitted its\n // seeded `map-update` before we subscribed.\n this.__refresh();\n }\n\n if (geocoder && !this.__geocoderWired) {\n this.__geocoderWired = true;\n this.__geocoder = geocoder;\n this.__offGeocoder.push(geocoder.$on('map-result', this.__handleGeocoderResult));\n }\n\n if ((!this.__clusterWired || !this.__geocoderWired) && attempt < WIRE_CHILDREN_MAX_ATTEMPTS) {\n nextTick(() => {\n if (this.$isMounted) {\n this.__wireChildren(attempt + 1);\n }\n });\n }\n }\n\n /**\n * Mounted hook: bind the delegated sidebar click, resolve and bind the map,\n * and install the standing connected-event subscriptions so a late or replaced\n * map/cluster (re)binds instead of stranding the orchestrator.\n */\n mounted() {\n this.$el.addEventListener('click', this.__handleListClick);\n\n this.__bindMap();\n this.__waitForConnectedMap();\n this.__waitForConnectedCluster();\n }\n\n /**\n * Destroyed hook: detach every listener, close the popup and clear the cached\n * references — even when the element has already been detached from the DOM.\n */\n destroyed() {\n for (const off of this.__offCluster) {\n off();\n }\n for (const off of this.__offGeocoder) {\n off();\n }\n this.__offCluster = [];\n this.__offGeocoder = [];\n\n this.__offMapLoad?.();\n this.__offMapLoad = undefined;\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n this.__offMapConnected?.();\n this.__offMapConnected = undefined;\n this.__offClusterConnected?.();\n this.__offClusterConnected = undefined;\n\n this.__map?.off('moveend', this.__handleMoveEnd);\n this.$el.removeEventListener('click', this.__handleListClick);\n\n this.__popup?.remove();\n this.__popup = undefined;\n this.__selected = undefined;\n this.__map = undefined;\n this.__cluster = undefined;\n this.__geocoder = undefined;\n this.isLoaded = false;\n this.__clusterWired = false;\n this.__geocoderWired = false;\n }\n}\n\nexport default StoreLocator;\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDnC,IAAa,eAAb,cAAmE,KAA4B;;;;;;;;;;CAU7F,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO;GAAC;GAAc;GAAgB;GAAa;EACnD,SAAS;GACP,eAAe;IACb,MAAM;IACN,SAAS;IACV;GAGD,QAAQ;GAER,aAAa;GAEb,cAAc;IACZ,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EACF;;;;CAKD,WAAW;;;;;;;CAQX;;;;;CAMA;;;;;CAMA;;;;;CAMA;;;;;CAMA;;;;;;;CAQA,eAAkC,EAAE;;;;;CAMpC,gBAAmC,EAAE;;;;;CAMrC;;;;;;;CAQA;;;;;;;CAQA;;;;;;;CAQA;;;;;CAMA,iBAAiB;;;;;CAMjB,kBAAkB;;;;CAKlB,IAAI,YAAY;EACd,MAAM,YAAY,KAAK,OAAkB,YAAY,CAAC;AAEtD,MAAI,CAAC,UACH,MAAK,MAAM,4CAA4C;AAGzD,SAAO;;;;;CAMT,IAAI,UAAqC;AACvC,SAAO,KAAK,aAAa,KAAK,OAAsB,gBAAgB,CAAC;;;;;CAMvE,IAAI,WAAuC;AACzC,SAAO,KAAK,cAAc,KAAK,OAAuB,iBAAiB,CAAC;;;;;CAM1E,IAAI,MAAM;AACR,SAAO,KAAK,SAAS,KAAK,WAAW;;;;;CAMvC,IAAI,QAAsC;AACxC,SAAO,KAAK,WAAW,SAAS,EAAE;;;;;;;CAQpC,WAAW,MAAyB;AAClC,MAAI,KAAK,cAAc,KAAK,eAAe,KACzC,MAAK,WAAW,UAAU,MAAM;AAGlC,OAAK,UAAU,KAAK;AACpB,OAAK,aAAa;AAElB,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UAAU,2BAC/D,gBAAe;AACb,OAAI,KAAK,WACP,MAAK,eAAe,UAAU,EAAE;IAElC;;;;;;;CASN,UAAU;AACR,OAAK,IAAI,iBAAiB,SAAS,KAAK,kBAAkB;AAE1D,OAAK,WAAW;AAChB,OAAK,uBAAuB;AAC5B,OAAK,2BAA2B;;;;;;CAOlC,YAAY;AACV,OAAK,MAAM,OAAO,KAAK,aACrB,MAAK;AAEP,OAAK,MAAM,OAAO,KAAK,cACrB,MAAK;AAEP,OAAK,eAAe,EAAE;AACtB,OAAK,gBAAgB,EAAE;AAEvB,OAAK,gBAAgB;AACrB,OAAK,eAAe,KAAA;AACpB,OAAK,kBAAkB;AACvB,OAAK,iBAAiB,KAAA;AACtB,OAAK,qBAAqB;AAC1B,OAAK,oBAAoB,KAAA;AACzB,OAAK,yBAAyB;AAC9B,OAAK,wBAAwB,KAAA;AAE7B,OAAK,OAAO,IAAI,WAAW,KAAK,gBAAgB;AAChD,OAAK,IAAI,oBAAoB,SAAS,KAAK,kBAAkB;AAE7D,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AACf,OAAK,aAAa,KAAA;AAClB,OAAK,QAAQ,KAAA;AACb,OAAK,YAAY,KAAA;AACjB,OAAK,aAAa,KAAA;AAClB,OAAK,WAAW;AAChB,OAAK,iBAAiB;AACtB,OAAK,kBAAkB"}
1
+ {"version":3,"file":"StoreLocator.js","names":[],"sources":["../src/StoreLocator.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport { whenDOMSettled } from '@studiometa/js-toolkit/whenDOMSettled';\nimport type { BaseProps, BaseConfig, ChildrenCollection } from '@studiometa/js-toolkit';\nimport type { Map, LngLatLike, LngLatBoundsLike, Popup } from 'mapbox-gl';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxMap } from './MapboxMap.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\nimport type { MapboxCluster } from './MapboxCluster.js';\nimport type { MapboxClusterItem } from './MapboxClusterItem.js';\nimport type { MapboxGeocoder } from './MapboxGeocoder.js';\n\nexport interface StoreLocatorProps extends BaseProps {\n $options: {\n itemZoomLevel: number;\n noSort: boolean;\n fitOnUpdate: boolean;\n popupOptions: Record<string, unknown>;\n };\n $emits: {\n 'map-select': { item: MapboxClusterItem };\n 'map-deselect': void;\n 'map-filter': { items: MapboxClusterItem[] };\n };\n}\n\n/**\n * Coordinate a \"find a store near you\" experience on top of a `MapboxMap`.\n *\n * `StoreLocator` is a thin **orchestrator**: it owns no map rendering and no item\n * registry of its own. It wraps a `MapboxMap` containing a\n * [`MapboxCluster`](./MapboxCluster.js) of\n * [`MapboxClusterItem`](./MapboxClusterItem.js)s (the declarative clustered map +\n * list source driver) plus an optional\n * [`MapboxGeocoder`](./MapboxGeocoder.js), and layers the search UX on top:\n * selection, viewport filtering and address search. The cluster keeps owning the\n * data (it derives the source from the registered items); the orchestrator only\n * reads that item set and reacts to it.\n *\n * Each store has three independent states, each with its own source of truth:\n *\n * 1. **Registered** — the item exists in the DOM. Owned by the `MapboxCluster`,\n * it drives the **map data** and only changes when the item set changes (e.g.\n * a `Fetch` swaps the list). The orchestrator is notified through the\n * cluster's `map-update` event.\n * 2. **In bounds** — the item's `lngLat` is inside the current viewport. Drives\n * **list visibility + distance sort only**, recomputed on map `moveend`, and\n * never touches the map data.\n * 3. **Selected** — the chosen item. Drives fly-to, the popup, `active` styling\n * and the `map-select` event.\n *\n * The orchestrator requires its `MapboxCluster` (and `MapboxMap`) to live within\n * its own subtree. It watches both with `$watchChildren()`, so a cluster or\n * geocoder that mounts late — or one that replaces the wired instance — is\n * picked up without polling; it subscribes to `MAPBOX_MAP_CONNECTED` because a\n * map announces its Mapbox instance *after* mounting, which a children\n * collection cannot report; and it subscribes to the map's own `remove` event\n * so a removed map is never called into. Register each component independently\n * with `registerComponent`: `StoreLocator`, `MapboxMap`, `MapboxCluster` and\n * `MapboxClusterItem`. Registration and mount order do not matter, and the\n * orchestrator declares no child components so nothing is ever double-mounted.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & StoreLocatorProps> {\n /**\n * Config.\n *\n * No child components are declared: `MapboxMap`, `MapboxCluster`,\n * `MapboxClusterItem` and `MapboxGeocoder` are each registered independently\n * with `registerComponent` and mount on their own. The orchestrator discovers\n * them through `$watchChildren()`; declaring them here would double-mount\n * them, since the registry already mounts a declared element.\n */\n static config: BaseConfig = {\n name: 'StoreLocator',\n mountStrategy: 'visible',\n options: {\n itemZoomLevel: {\n type: Number,\n default: 14,\n },\n // Boolean options default to `false`, so sorting is ON by default;\n // `data-option-no-sort` disables the distance sort.\n noSort: Boolean,\n // Fit the map bounds to the item set whenever it changes.\n fitOnUpdate: Boolean,\n // Options forwarded to the `mapboxgl.Popup` opened on selection.\n popupOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n };\n\n /**\n * Whether the underlying map has finished loading.\n */\n isLoaded = false;\n\n /**\n * The Mapbox `Map` instance cached at load, so every listener and teardown\n * path reaches it without a fresh `$query` (which returns nothing once the\n * element is detached).\n * @private\n */\n __map?: Map;\n\n /**\n * The child `MapboxCluster`, cached at wire-time for detach-safe teardown.\n * @private\n */\n __cluster?: MapboxCluster;\n\n /**\n * The optional child `MapboxGeocoder`, cached at wire-time.\n * @private\n */\n __geocoder?: MapboxGeocoder;\n\n /**\n * The currently selected item, if any.\n * @private\n */\n __selected?: MapboxClusterItem;\n\n /**\n * The popup opened for the selected item, created lazily.\n * @private\n */\n __popup?: Popup;\n\n /**\n * Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on\n * unmount and when the cluster is replaced (so the orchestrator re-wires onto\n * the new instance rather than staying subscribed to the unmounted one).\n * @private\n */\n __offCluster: Array<() => void> = [];\n\n /**\n * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on unmount.\n * @private\n */\n __offGeocoder: Array<() => void> = [];\n\n /**\n * Off handle for the pending `map-load` subscription.\n * @private\n */\n __offMapLoad?: () => void;\n\n /**\n * Off handle for the ready map's own `remove` subscription, used to drop the\n * cached map the moment it is removed so no listener/teardown ever calls a\n * method on a dead map.\n * @private\n */\n __offMapRemove?: () => void;\n\n /**\n * Off handle for the standing document-level `MAPBOX_MAP_CONNECTED` retry\n * subscription, so a map that mounts (or a replacement that mounts after the\n * previous was removed) rebinds the orchestrator.\n * @private\n */\n __offMapConnected?: () => void;\n\n /**\n * The mounted `MapboxCluster` descendants, live and in DOM order.\n *\n * The collection answers \"has the cluster mounted yet?\" on its own: a cluster\n * that mounts late, or one that replaces the wired one, reaches the\n * `added`/`removed` callbacks with nothing to poll. The cluster still\n * dispatches `MAPBOX_CLUSTER_CONNECTED` for `MapboxClusterItem`, which looks\n * *up* for its cluster and has no watching counterpart to `$closest()`.\n * @private\n */\n __clusters: ChildrenCollection<MapboxCluster> = this.$watchChildren<MapboxCluster>(\n 'MapboxCluster',\n {\n added: (cluster) => this.__wireCluster(cluster),\n removed: (cluster) => {\n if (this.__cluster === cluster) {\n this.__unwireCluster();\n this.__wireCluster(this.__clusters.items[0]);\n }\n },\n },\n );\n\n /**\n * The mounted `MapboxGeocoder` descendants, live and in DOM order. The\n * geocoder is optional, so nothing waits for it: it wires itself whenever it\n * turns up.\n * @private\n */\n __geocoders: ChildrenCollection<MapboxGeocoder> = this.$watchChildren<MapboxGeocoder>(\n 'MapboxGeocoder',\n {\n added: (geocoder) => this.__wireGeocoder(geocoder),\n removed: (geocoder) => {\n if (this.__geocoder === geocoder) {\n this.__unwireGeocoder();\n this.__wireGeocoder(this.__geocoders.items[0]);\n }\n },\n },\n );\n\n /**\n * The child `MapboxMap` component, once it has mounted.\n *\n * The getter does not warn when there is none: a wrapper mounts before the\n * elements inside it and mount order is not guaranteed, so \"no map yet\" is\n * the normal state on every healthy locator. A locator with genuinely no map\n * in its markup is reported once instead, from\n * {@link __warnWhenMapIsMissing}.\n */\n get mapboxMap(): MapboxMap | undefined {\n return this.$query<MapboxMap>('MapboxMap')[0];\n }\n\n /**\n * The child `MapboxCluster`, discovered in the subtree.\n */\n get cluster(): MapboxCluster | undefined {\n return this.__cluster ?? this.__clusters.items[0];\n }\n\n /**\n * The optional child `MapboxGeocoder`, discovered in the subtree.\n */\n get geocoder(): MapboxGeocoder | undefined {\n return this.__geocoder ?? this.__geocoders.items[0];\n }\n\n /**\n * The Mapbox `Map` instance. Only valid once the map has loaded.\n */\n get map() {\n return this.__map ?? this.mapboxMap?.map;\n }\n\n /**\n * The registered items, read from the cluster (their single source of truth).\n */\n get items(): readonly MapboxClusterItem[] {\n return this.__cluster?.items ?? [];\n }\n\n /**\n * Select an item: deactivate the previous one, fly to the item, open its\n * popup, mark it active and emit a `map-select` event.\n * @param {MapboxClusterItem} item\n */\n selectItem(item: MapboxClusterItem) {\n if (this.__selected && this.__selected !== item) {\n this.__selected.setActive(false);\n }\n\n item.setActive(true);\n this.__selected = item;\n\n this.__map?.flyTo({\n center: item.lngLat as LngLatLike,\n zoom: this.$options.itemZoomLevel,\n });\n\n this.__openPopup(item);\n this.$emit('map-select', { item });\n }\n\n /**\n * Clear the current selection, close the popup and emit a `map-deselect` event.\n */\n deselect() {\n if (this.__selected) {\n this.__selected.setActive(false);\n this.__selected = undefined;\n }\n\n this.__popup?.remove();\n this.$emit('map-deselect');\n }\n\n /**\n * Open (or move) the selection popup on the given item, using its popup\n * content. A content-less item closes any open popup instead.\n *\n * NOTE: closing this popup through Mapbox's own close-button UI does NOT clear\n * the selection — `data-active`/`aria-current`/`__selected` stay set by design.\n * Popup visibility and selection are independent: dismissing the popup does not\n * deselect the store. Call `deselect()` explicitly to clear the selection.\n * @private\n * @param {MapboxClusterItem} item\n */\n __openPopup(item: MapboxClusterItem) {\n const map = this.__map;\n\n if (!map) {\n return;\n }\n\n const content = item.popupContent;\n\n if (!content) {\n this.__popup?.remove();\n return;\n }\n\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n this.__popup\n .setLngLat(item.lngLat as LngLatLike)\n .setHTML(content)\n .addTo(map);\n }\n\n /**\n * Fit the map to the whole item set (when `fitOnUpdate`) then recompute the\n * in-view list. Runs on an item-set change (the cluster's `map-update` event) and\n * when the cluster is first wired.\n * @private\n */\n __refresh() {\n if (this.$options.fitOnUpdate && this.items.length > 0) {\n this.__map?.fitBounds(this.__getItemsBounds(), { padding: 40 });\n }\n\n this.__filterItemsInView();\n }\n\n /**\n * Compute the bounding box of the whole registered item set as a\n * `[[minLng, minLat], [maxLng, maxLat]]` tuple.\n * @private\n * @returns {LngLatBoundsLike}\n */\n __getItemsBounds(): LngLatBoundsLike {\n let minLng = Infinity;\n let minLat = Infinity;\n let maxLng = -Infinity;\n let maxLat = -Infinity;\n\n for (const item of this.items) {\n const [lng, lat] = item.lngLat;\n minLng = Math.min(minLng, lng);\n minLat = Math.min(minLat, lat);\n maxLng = Math.max(maxLng, lng);\n maxLat = Math.max(maxLat, lat);\n }\n\n return [\n [minLng, minLat],\n [maxLng, maxLat],\n ];\n }\n\n /**\n * Recompute the visible/sorted list = registered ∩ in-bounds, distance-sorted.\n *\n * Reflects the in-bounds state on every item, reorders the in-view items in\n * their shared parent list (so DOM order matches distance) and emits `map-filter`\n * with the in-view items. Never touches the map data.\n * @private\n */\n __filterItemsInView() {\n const map = this.__map;\n\n if (!map) {\n return;\n }\n\n const bounds = map.getBounds();\n const center = map.getCenter();\n const inView: MapboxClusterItem[] = [];\n\n for (const item of this.items) {\n const isInBounds = Boolean(bounds?.contains(item.lngLat as LngLatLike));\n item.setInBounds(isInBounds);\n\n if (isInBounds) {\n inView.push(item);\n }\n }\n\n if (!this.$options.noSort && center) {\n const { LngLat } = getMapboxGl();\n inView.sort(\n (a, b) =>\n center.distanceTo(new LngLat(a.lngLat[0], a.lngLat[1])) -\n center.distanceTo(new LngLat(b.lngLat[0], b.lngLat[1])),\n );\n }\n\n this.__reorderList(inView);\n this.$emit('map-filter', { items: inView });\n }\n\n /**\n * Reorder the in-view items so their DOM order matches the distance sort.\n * Appending a connected node moves it, keeping the list free of duplicates.\n * Items are reordered inside their own shared parent — the sidebar list\n * element — which is resolved per item so no `list` ref is required (a ref\n * declared on the sidebar would not bind anyway: the items live inside the\n * nested `MapboxCluster`, outside this orchestrator's ref scope).\n * @private\n * @param {MapboxClusterItem[]} items\n */\n __reorderList(items: MapboxClusterItem[]) {\n for (const item of items) {\n item.$el.parentElement?.append(item.$el);\n }\n }\n\n /**\n * Handle the cluster's `map-item-click`: select the item behind the clicked\n * unclustered point, if one was resolved.\n * @private\n */\n __handleItemClick = (event: Event) => {\n const { item } = (event as CustomEvent).detail ?? {};\n\n if (item) {\n this.selectItem(item as MapboxClusterItem);\n }\n };\n\n /**\n * Handle a click anywhere in the sidebar: resolve the nearest\n * `MapboxClusterItem` element back to its instance and select it. Delegated on\n * the root so it survives `Fetch`/facet list swaps.\n * @private\n */\n __handleListClick = (event: Event) => {\n const target = event.target as Element | null;\n const el = target?.closest?.('[data-component=\"MapboxClusterItem\"]');\n\n if (!el) {\n return;\n }\n\n const item = this.items.find((candidate) => candidate.$el === el);\n\n if (item) {\n this.selectItem(item);\n }\n };\n\n /**\n * Handle the cluster's `map-update` (the item set changed): re-fit and re-filter.\n * Drops a stale selection whose item is no longer registered.\n * @private\n */\n __handleClusterUpdate = () => {\n // The selected store may have been removed by the swap. Run the full\n // deselect cleanup — not just clearing `__selected` — so its popup is\n // removed from the map and `map-deselect` is emitted, instead of leaving the\n // removed store's popup stranded while the locator claims nothing is\n // selected.\n if (this.__selected && !this.items.includes(this.__selected)) {\n this.deselect();\n }\n\n this.__refresh();\n };\n\n /**\n * Handle a `MapboxGeocoder` `map-result`: frame the map on the geocoded location.\n * @private\n */\n __handleGeocoderResult = (event: Event) => {\n const { result } = (event as CustomEvent).detail ?? {};\n const map = this.__map;\n\n if (!map || !result) {\n return;\n }\n\n if (Array.isArray(result.bbox)) {\n const [minLng, minLat, maxLng, maxLat] = result.bbox;\n map.fitBounds([\n [minLng, minLat],\n [maxLng, maxLat],\n ]);\n } else if (result.center) {\n map.flyTo({ center: result.center as LngLatLike });\n }\n };\n\n /**\n * Recompute the in-view list whenever the viewport settles.\n * @private\n */\n __handleMoveEnd = () => {\n this.__filterItemsInView();\n };\n\n /**\n * React to the map being ready: cache it, subscribe to its `remove`, bind the\n * viewport listener and wire the children.\n *\n * Idempotent for the same map (a re-entrant `map-load` or connected event does\n * not double-bind `moveend`), and rebinds cleanly onto a replacement map.\n * @private\n */\n __handleMapLoad = () => {\n const map = this.mapboxMap?.map;\n\n if (!map) {\n return;\n }\n\n // Rebinding onto a replacement: drop the viewport listener from the previous\n // map before caching and binding the new one.\n if (this.__map && this.__map !== map) {\n this.__map.off('moveend', this.__handleMoveEnd);\n }\n\n this.isLoaded = true;\n this.__map = map;\n this.__bindMapRemove(map);\n map.off('moveend', this.__handleMoveEnd);\n map.on('moveend', this.__handleMoveEnd);\n this.__wireCluster(this.__clusters.items[0]);\n this.__wireGeocoder(this.__geocoders.items[0]);\n // Unconditionally, not only on a first wire: a cluster that wired before\n // the map loaded got a `__refresh()` with no map to fit or filter against,\n // and this is the first moment there is one.\n this.__refresh();\n };\n\n /**\n * Subscribe once to the ready map's own `remove` event so a map removed while\n * the orchestrator stays mounted drops the cached (now dead) map instead of\n * calling `flyTo`/`getBounds`/`fitBounds`/`off` on it. A replacement map\n * announces itself through `MAPBOX_MAP_CONNECTED` and rebinds the orchestrator.\n * @private\n * @param {Map} map\n */\n __bindMapRemove(map: Map) {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n\n // Degrade gracefully for minimal map doubles without an event emitter.\n if (typeof map?.on !== 'function') {\n return;\n }\n\n const handler = () => {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n this.__map?.off('moveend', this.__handleMoveEnd);\n this.__map = undefined;\n this.isLoaded = false;\n };\n\n map.on('remove', handler);\n this.__offMapRemove = () => map.off('remove', handler);\n }\n\n /**\n * Resolve the child `MapboxMap` and bind to it — now if it is already loaded,\n * otherwise once on `map-load`. When none exists yet the standing\n * `MAPBOX_MAP_CONNECTED` subscription rebinds later.\n * @private\n */\n __bindMap() {\n const { mapboxMap } = this;\n\n if (!mapboxMap) {\n return;\n }\n\n if (mapboxMap.isLoaded) {\n this.__handleMapLoad();\n } else {\n this.__offMapLoad?.();\n this.__offMapLoad = mapboxMap.$on('map-load', this.__handleMapLoad, { once: true });\n }\n }\n\n /**\n * Subscribe once to `MAPBOX_MAP_CONNECTED` and (re)bind when a `MapboxMap`\n * inside this orchestrator connects — a late-mounted map, or a replacement for\n * one that was removed. Ignores maps outside this subtree (several independent\n * locators/maps can share a page).\n * @private\n */\n __waitForConnectedMap() {\n if (this.__offMapConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const mapboxMap = (event as CustomEvent<MapboxMap>).detail;\n\n // The map lives *inside* the orchestrator: filter to descendants.\n if (!mapboxMap?.$el || !this.$el.contains(mapboxMap.$el)) {\n return;\n }\n\n // Already bound to this exact, loaded map: nothing to do.\n if (this.__map && this.__map === mapboxMap.map) {\n return;\n }\n\n this.__bindMap();\n };\n\n document.addEventListener(MAPBOX_MAP_CONNECTED, handler);\n this.__offMapConnected = () => document.removeEventListener(MAPBOX_MAP_CONNECTED, handler);\n }\n\n /**\n * Report a locator with no `MapboxMap` in its markup, once.\n *\n * The check reads the **element**, not the mounted instance: DOM ancestry is\n * a fact that exists before anything mounts, so it is immune both to mount\n * ordering and to the map's mount strategy — a `data-mount` that has not\n * fired yet is not a missing map. `whenDOMSettled()` waits for\n * the mutation batch that brought the locator in, which is the earliest\n * moment the markup can be judged complete.\n * @private\n */\n async __warnWhenMapIsMissing() {\n await whenDOMSettled();\n\n if (this.$isMounted && !this.$el.querySelector('[data-component=\"MapboxMap\"]')) {\n this.$warn('store-locator.no-map', 'Can not find a child MapboxMap component.');\n }\n }\n\n /**\n * Detach the current cluster listeners so a replacement can be wired afresh.\n * @private\n */\n __unwireCluster() {\n for (const off of this.__offCluster) {\n off();\n }\n this.__offCluster = [];\n this.__cluster = undefined;\n }\n\n /**\n * Detach the current geocoder listener.\n * @private\n */\n __unwireGeocoder() {\n for (const off of this.__offGeocoder) {\n off();\n }\n this.__offGeocoder = [];\n this.__geocoder = undefined;\n }\n\n /**\n * Attach the `MapboxCluster` listeners, once, to the first cluster in the\n * subtree. A no-op while the orchestrator itself is unmounted: the collection\n * outlives a mount cycle, so `mounted()` wires whatever it already holds.\n * @private\n */\n __wireCluster(cluster?: MapboxCluster) {\n if (!cluster || this.__cluster || !this.$isMounted) {\n return;\n }\n\n this.__cluster = cluster;\n this.__offCluster.push(cluster.$on('map-item-click', this.__handleItemClick));\n this.__offCluster.push(cluster.$on('map-update', this.__handleClusterUpdate));\n // Catch up on the cluster's current item set: it may have emitted its\n // seeded `map-update` before we subscribed.\n this.__refresh();\n }\n\n /**\n * Attach the optional `MapboxGeocoder` listener, once, to the first geocoder\n * in the subtree.\n * @private\n */\n __wireGeocoder(geocoder?: MapboxGeocoder) {\n if (!geocoder || this.__geocoder || !this.$isMounted) {\n return;\n }\n\n this.__geocoder = geocoder;\n this.__offGeocoder.push(geocoder.$on('map-result', this.__handleGeocoderResult));\n }\n\n /**\n * Mounted hook: wire whatever the children collections already hold, bind the\n * delegated sidebar click, resolve and bind the map, and install the standing\n * `MAPBOX_MAP_CONNECTED` subscription so a late or replaced map rebinds\n * instead of stranding the orchestrator.\n */\n mounted() {\n this.$el.addEventListener('click', this.__handleListClick);\n\n // The children collections outlive a mount cycle, so a remount re-wires\n // from whatever they already hold; anything mounting later arrives through\n // their `added` callbacks.\n this.__wireCluster(this.__clusters.items[0]);\n this.__wireGeocoder(this.__geocoders.items[0]);\n\n this.__bindMap();\n this.__waitForConnectedMap();\n this.__warnWhenMapIsMissing();\n }\n\n /**\n * Unmounted hook: detach every listener, close the popup and clear the cached\n * references — even when the element has already been detached from the DOM.\n */\n unmounted() {\n for (const off of this.__offCluster) {\n off();\n }\n for (const off of this.__offGeocoder) {\n off();\n }\n this.__offCluster = [];\n this.__offGeocoder = [];\n\n this.__offMapLoad?.();\n this.__offMapLoad = undefined;\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n this.__offMapConnected?.();\n this.__offMapConnected = undefined;\n\n this.__map?.off('moveend', this.__handleMoveEnd);\n this.$el.removeEventListener('click', this.__handleListClick);\n\n this.__popup?.remove();\n this.__popup = undefined;\n this.__selected = undefined;\n this.__map = undefined;\n this.__cluster = undefined;\n this.__geocoder = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default StoreLocator;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,IAAa,eAAb,cAAmE,KAA4B;;;;;;;;;;CAU7F,OAAO,SAAqB;EAC1B,MAAM;EACN,eAAe;EACf,SAAS;GACP,eAAe;IACb,MAAM;IACN,SAAS;IACV;GAGD,QAAQ;GAER,aAAa;GAEb,cAAc;IACZ,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EACF;;;;CAKD,WAAW;;;;;;;CAQX;;;;;CAMA;;;;;CAMA;;;;;CAMA;;;;;CAMA;;;;;;;CAQA,eAAkC,EAAE;;;;;CAMpC,gBAAmC,EAAE;;;;;CAMrC;;;;;;;CAQA;;;;;;;CAQA;;;;;;;;;;;CAYA,aAAgD,KAAK,eACnD,iBACA;EACE,QAAQ,YAAY,KAAK,cAAc,QAAQ;EAC/C,UAAU,YAAY;AACpB,OAAI,KAAK,cAAc,SAAS;AAC9B,SAAK,iBAAiB;AACtB,SAAK,cAAc,KAAK,WAAW,MAAM,GAAG;;;EAGjD,CACF;;;;;;;CAQD,cAAkD,KAAK,eACrD,kBACA;EACE,QAAQ,aAAa,KAAK,eAAe,SAAS;EAClD,UAAU,aAAa;AACrB,OAAI,KAAK,eAAe,UAAU;AAChC,SAAK,kBAAkB;AACvB,SAAK,eAAe,KAAK,YAAY,MAAM,GAAG;;;EAGnD,CACF;;;;;;;;;;CAWD,IAAI,YAAmC;AACrC,SAAO,KAAK,OAAkB,YAAY,CAAC;;;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AK,QAAQ,IAAI,kBAAkB,KAAK,kBAAkB,CAAC;AAC7E,OAAK,aAAa,KAAK,QAAQ,IAAI,cAAc,KAAK,sBAAsB,CAAC;AAG7E,OAAK,WAAW;;;;;;;CAQlB,eAAe,UAA2B;AACxC,MAAI,CAAC,YAAY,KAAK,cAAc,CAAC,KAAK,WACxC;AAGF,OAAK,aAAa;AAClB,OAAK,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,uBAAuB,CAAC;;;;;;;;CASlF,UAAU;AACR,OAAK,IAAI,iBAAiB,SAAS,KAAK,kBAAkB;AAK1D,OAAK,cAAc,KAAK,WAAW,MAAM,GAAG;AAC5C,OAAK,eAAe,KAAK,YAAY,MAAM,GAAG;AAE9C,OAAK,WAAW;AAChB,OAAK,uBAAuB;AAC5B,OAAK,wBAAwB;;;;;;CAO/B,YAAY;AACV,OAAK,MAAM,OAAO,KAAK,aACrB,MAAK;AAEP,OAAK,MAAM,OAAO,KAAK,cACrB,MAAK;AAEP,OAAK,eAAe,EAAE;AACtB,OAAK,gBAAgB,EAAE;AAEvB,OAAK,gBAAgB;AACrB,OAAK,eAAe,KAAA;AACpB,OAAK,kBAAkB;AACvB,OAAK,iBAAiB,KAAA;AACtB,OAAK,qBAAqB;AAC1B,OAAK,oBAAoB,KAAA;AAEzB,OAAK,OAAO,IAAI,WAAW,KAAK,gBAAgB;AAChD,OAAK,IAAI,oBAAoB,SAAS,KAAK,kBAAkB;AAE7D,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AACf,OAAK,aAAa,KAAA;AAClB,OAAK,QAAQ,KAAA;AACb,OAAK,YAAY,KAAA;AACjB,OAAK,aAAa,KAAA;AAClB,OAAK,WAAW"}
package/dist/catalog.js CHANGED
@@ -5,15 +5,18 @@ const catalog = {
5
5
  components: [
6
6
  {
7
7
  token: "MapboxCluster",
8
- group: "mapbox"
8
+ group: "mapbox",
9
+ strategy: "eager"
9
10
  },
10
11
  {
11
12
  token: "MapboxClusterItem",
12
- group: "mapbox"
13
+ group: "mapbox",
14
+ strategy: "eager"
13
15
  },
14
16
  {
15
17
  token: "MapboxFullscreenControl",
16
- group: "mapbox"
18
+ group: "mapbox",
19
+ strategy: "eager"
17
20
  },
18
21
  {
19
22
  token: "MapboxGeocoder",
@@ -21,19 +24,23 @@ const catalog = {
21
24
  },
22
25
  {
23
26
  token: "MapboxGeolocateControl",
24
- group: "mapbox"
27
+ group: "mapbox",
28
+ strategy: "eager"
25
29
  },
26
30
  {
27
31
  token: "MapboxImage",
28
- group: "mapbox"
32
+ group: "mapbox",
33
+ strategy: "eager"
29
34
  },
30
35
  {
31
36
  token: "MapboxImages",
32
- group: "mapbox"
37
+ group: "mapbox",
38
+ strategy: "eager"
33
39
  },
34
40
  {
35
41
  token: "MapboxLayer",
36
- group: "mapbox"
42
+ group: "mapbox",
43
+ strategy: "eager"
37
44
  },
38
45
  {
39
46
  token: "MapboxMap",
@@ -41,19 +48,23 @@ const catalog = {
41
48
  },
42
49
  {
43
50
  token: "MapboxMarker",
44
- group: "mapbox"
51
+ group: "mapbox",
52
+ strategy: "eager"
45
53
  },
46
54
  {
47
55
  token: "MapboxNavigationControl",
48
- group: "mapbox"
56
+ group: "mapbox",
57
+ strategy: "eager"
49
58
  },
50
59
  {
51
60
  token: "MapboxPopup",
52
- group: "mapbox"
61
+ group: "mapbox",
62
+ strategy: "eager"
53
63
  },
54
64
  {
55
65
  token: "MapboxSource",
56
- group: "mapbox"
66
+ group: "mapbox",
67
+ strategy: "eager"
57
68
  },
58
69
  {
59
70
  token: "StoreLocator",
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import type { ComponentCatalog, CuratedComponentMetadata } from '../../../scripts/manifest-types.js';\n\n// Mapbox GL and the optional geocoder are external (import-map resolved) and no longer served by\n// the CDN, so these components declare neither a CDN-served stylesheet nor a bundled integration\n// chunk — consumers load the Mapbox JavaScript and CSS from the source their import map points at.\nconst components: readonly CuratedComponentMetadata[] = [\n { token: 'MapboxCluster', group: 'mapbox' },\n { token: 'MapboxClusterItem', group: 'mapbox' },\n { token: 'MapboxFullscreenControl', group: 'mapbox' },\n { token: 'MapboxGeocoder', group: 'mapbox' },\n { token: 'MapboxGeolocateControl', group: 'mapbox' },\n { token: 'MapboxImage', group: 'mapbox' },\n { token: 'MapboxImages', group: 'mapbox' },\n { token: 'MapboxLayer', group: 'mapbox' },\n { token: 'MapboxMap', group: 'mapbox' },\n { token: 'MapboxMarker', group: 'mapbox' },\n { token: 'MapboxNavigationControl', group: 'mapbox' },\n { token: 'MapboxPopup', group: 'mapbox' },\n { token: 'MapboxSource', group: 'mapbox' },\n { token: 'StoreLocator', group: 'mapbox' },\n];\n\n/** The autoload catalog for every declarative `@studiometa/ui-mapbox` component. */\nexport const catalog: ComponentCatalog = {\n packageName: '@studiometa/ui-mapbox',\n strategy: 'visible',\n components,\n abstractExports: ['AbstractMapboxControl', 'AbstractMapboxMapChild'],\n};\n"],"mappings":";AAuBA,MAAa,UAA4B;CACvC,aAAa;CACb,UAAU;CACV,YArBsD;EACtD;GAAE,OAAO;GAAiB,OAAO;GAAU;EAC3C;GAAE,OAAO;GAAqB,OAAO;GAAU;EAC/C;GAAE,OAAO;GAA2B,OAAO;GAAU;EACrD;GAAE,OAAO;GAAkB,OAAO;GAAU;EAC5C;GAAE,OAAO;GAA0B,OAAO;GAAU;EACpD;GAAE,OAAO;GAAe,OAAO;GAAU;EACzC;GAAE,OAAO;GAAgB,OAAO;GAAU;EAC1C;GAAE,OAAO;GAAe,OAAO;GAAU;EACzC;GAAE,OAAO;GAAa,OAAO;GAAU;EACvC;GAAE,OAAO;GAAgB,OAAO;GAAU;EAC1C;GAAE,OAAO;GAA2B,OAAO;GAAU;EACrD;GAAE,OAAO;GAAe,OAAO;GAAU;EACzC;GAAE,OAAO;GAAgB,OAAO;GAAU;EAC1C;GAAE,OAAO;GAAgB,OAAO;GAAU;EAC3C;CAOC,iBAAiB,CAAC,yBAAyB,yBAAyB;CACrE"}
1
+ {"version":3,"file":"catalog.js","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["import type {\n ComponentCatalog,\n CuratedComponentMetadata,\n} from '../../../scripts/manifest-types.js';\n\n// Mapbox GL and the optional geocoder are external (import-map resolved) and not served by the\n// CDN, so these components declare neither a CDN-served stylesheet nor a bundled integration\n// chunk — consumers load the Mapbox JavaScript and CSS from the source their import map points at.\n//\n// The package default is `visible`, so a module loads when its element nears the viewport.\n// `MapboxMap` and `StoreLocator` keep it, which holds the heavy `mapbox-gl` import back until a\n// map nears the viewport. `MapboxGeocoder` keeps it too, so `@mapbox/mapbox-gl-geocoder` stays\n// lazy: its element holds the search input, or nothing when the control is added to the map, so\n// it never needs `hidden`.\n//\n// The other map children declare `eager`. They only need to exist: `MapboxMap` already gates\n// `mapbox-gl`, so their own modules are small. Many of them render nothing and carry `hidden`,\n// and a hidden element never intersects the viewport, so `visible` would never load them. The\n// registry only schedules a token declared on an element of the page, so `eager` imports a\n// module because its element exists, on a background scheduler task, not at page load.\nconst components: readonly CuratedComponentMetadata[] = [\n { token: 'MapboxCluster', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxClusterItem', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxFullscreenControl', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxGeocoder', group: 'mapbox' },\n { token: 'MapboxGeolocateControl', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxImage', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxImages', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxLayer', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxMap', group: 'mapbox' },\n { token: 'MapboxMarker', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxNavigationControl', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxPopup', group: 'mapbox', strategy: 'eager' },\n { token: 'MapboxSource', group: 'mapbox', strategy: 'eager' },\n { token: 'StoreLocator', group: 'mapbox' },\n];\n\n/** The autoload catalog for every declarative `@studiometa/ui-mapbox` component. */\nexport const catalog: ComponentCatalog = {\n packageName: '@studiometa/ui-mapbox',\n strategy: 'visible',\n components,\n abstractExports: ['AbstractMapboxControl', 'AbstractMapboxMapChild'],\n};\n"],"mappings":";AAsCA,MAAa,UAA4B;CACvC,aAAa;CACb,UAAU;CACV,YArBsD;EACtD;GAAE,OAAO;GAAiB,OAAO;GAAU,UAAU;GAAS;EAC9D;GAAE,OAAO;GAAqB,OAAO;GAAU,UAAU;GAAS;EAClE;GAAE,OAAO;GAA2B,OAAO;GAAU,UAAU;GAAS;EACxE;GAAE,OAAO;GAAkB,OAAO;GAAU;EAC5C;GAAE,OAAO;GAA0B,OAAO;GAAU,UAAU;GAAS;EACvE;GAAE,OAAO;GAAe,OAAO;GAAU,UAAU;GAAS;EAC5D;GAAE,OAAO;GAAgB,OAAO;GAAU,UAAU;GAAS;EAC7D;GAAE,OAAO;GAAe,OAAO;GAAU,UAAU;GAAS;EAC5D;GAAE,OAAO;GAAa,OAAO;GAAU;EACvC;GAAE,OAAO;GAAgB,OAAO;GAAU,UAAU;GAAS;EAC7D;GAAE,OAAO;GAA2B,OAAO;GAAU,UAAU;GAAS;EACxE;GAAE,OAAO;GAAe,OAAO;GAAU,UAAU;GAAS;EAC5D;GAAE,OAAO;GAAgB,OAAO;GAAU,UAAU;GAAS;EAC7D;GAAE,OAAO;GAAgB,OAAO;GAAU;EAC3C;CAOC,iBAAiB,CAAC,yBAAyB,yBAAyB;CACrE"}
@@ -36,10 +36,12 @@ interface MapboxGeocoderConstructor {
36
36
  /**
37
37
  * Inject the `mapbox-gl` module the components should use.
38
38
  *
39
- * Call once, before the components mount (e.g. right before `createApp`). Once
40
- * provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by specifier — it
41
- * uses this instance — so a host can supply its own build (a specific version, a
42
- * self-hosted worker for strict CSP, an import-map or CDN module).
39
+ * Call once, before the components mount — e.g. right before the
40
+ * `registerComponent()` or `registerManifest()` call that puts them on the
41
+ * page. Once provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by
42
+ * specifier — it uses this instance — so a host can supply its own build (a
43
+ * specific version, a self-hosted worker for strict CSP, an import-map or CDN
44
+ * module).
43
45
  *
44
46
  * @param {MapboxGl} instance The `mapbox-gl` default export namespace.
45
47
  */
@@ -8,10 +8,12 @@ let geocoderProvided = false;
8
8
  /**
9
9
  * Inject the `mapbox-gl` module the components should use.
10
10
  *
11
- * Call once, before the components mount (e.g. right before `createApp`). Once
12
- * provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by specifier — it
13
- * uses this instance — so a host can supply its own build (a specific version, a
14
- * self-hosted worker for strict CSP, an import-map or CDN module).
11
+ * Call once, before the components mount — e.g. right before the
12
+ * `registerComponent()` or `registerManifest()` call that puts them on the
13
+ * page. Once provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by
14
+ * specifier — it uses this instance — so a host can supply its own build (a
15
+ * specific version, a self-hosted worker for strict CSP, an import-map or CDN
16
+ * module).
15
17
  *
16
18
  * @param {MapboxGl} instance The `mapbox-gl` default export namespace.
17
19
  */