@studiometa/ui-mapbox 1.11.0 → 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.
- package/dist/AbstractMapboxControl.js +1 -1
- package/dist/AbstractMapboxControl.js.map +1 -1
- package/dist/AbstractMapboxMapChild.d.ts +32 -12
- package/dist/AbstractMapboxMapChild.js +24 -17
- package/dist/AbstractMapboxMapChild.js.map +1 -1
- package/dist/MapboxCluster.d.ts +19 -2
- package/dist/MapboxCluster.js +11 -9
- package/dist/MapboxCluster.js.map +1 -1
- package/dist/MapboxClusterItem.d.ts +11 -3
- package/dist/MapboxClusterItem.js +5 -6
- package/dist/MapboxClusterItem.js.map +1 -1
- package/dist/MapboxFullscreenControl.d.ts +8 -4
- package/dist/MapboxFullscreenControl.js +6 -2
- package/dist/MapboxFullscreenControl.js.map +1 -1
- package/dist/MapboxGeocoder.d.ts +9 -0
- package/dist/MapboxGeocoder.js +1 -2
- package/dist/MapboxGeocoder.js.map +1 -1
- package/dist/MapboxGeolocateControl.d.ts +8 -4
- package/dist/MapboxGeolocateControl.js +16 -12
- package/dist/MapboxGeolocateControl.js.map +1 -1
- package/dist/MapboxImage.d.ts +11 -1
- package/dist/MapboxImage.js +0 -1
- package/dist/MapboxImage.js.map +1 -1
- package/dist/MapboxImages.d.ts +9 -1
- package/dist/MapboxImages.js +1 -2
- package/dist/MapboxImages.js.map +1 -1
- package/dist/MapboxLayer.js.map +1 -1
- package/dist/MapboxMap.d.ts +17 -2
- package/dist/MapboxMap.js +4 -5
- package/dist/MapboxMap.js.map +1 -1
- package/dist/MapboxMarker.js.map +1 -1
- package/dist/MapboxNavigationControl.d.ts +8 -4
- package/dist/MapboxNavigationControl.js +13 -9
- package/dist/MapboxNavigationControl.js.map +1 -1
- package/dist/MapboxPopup.js.map +1 -1
- package/dist/MapboxSource.js +1 -1
- package/dist/MapboxSource.js.map +1 -1
- package/dist/StoreLocator.d.ts +76 -51
- package/dist/StoreLocator.js +111 -105
- package/dist/StoreLocator.js.map +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/dependencies.d.ts +6 -4
- package/dist/dependencies.js +6 -4
- package/dist/dependencies.js.map +1 -1
- package/dist/manifest.js +14 -84
- package/dist/manifest.js.map +1 -1
- package/dist/scripts/manifest-types.d.ts +3 -3
- package/package.json +3 -3
package/dist/StoreLocator.js
CHANGED
|
@@ -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 {
|
|
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
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* never called into. Register each component independently
|
|
46
|
-
* `registerComponent`,
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
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,12 @@ 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
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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
|
-
],
|
|
71
56
|
options: {
|
|
72
57
|
itemZoomLevel: {
|
|
73
58
|
type: Number,
|
|
@@ -114,13 +99,13 @@ var StoreLocator = class extends Base {
|
|
|
114
99
|
__popup;
|
|
115
100
|
/**
|
|
116
101
|
* Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on
|
|
117
|
-
*
|
|
118
|
-
* the new instance rather than staying subscribed to the
|
|
102
|
+
* unmount and when the cluster is replaced (so the orchestrator re-wires onto
|
|
103
|
+
* the new instance rather than staying subscribed to the unmounted one).
|
|
119
104
|
* @private
|
|
120
105
|
*/
|
|
121
106
|
__offCluster = [];
|
|
122
107
|
/**
|
|
123
|
-
* Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on
|
|
108
|
+
* Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on unmount.
|
|
124
109
|
* @private
|
|
125
110
|
*/
|
|
126
111
|
__offGeocoder = [];
|
|
@@ -144,41 +129,62 @@ var StoreLocator = class extends Base {
|
|
|
144
129
|
*/
|
|
145
130
|
__offMapConnected;
|
|
146
131
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* Whether the `MapboxCluster` listeners are already attached.
|
|
132
|
+
* The mounted `MapboxCluster` descendants, live and in DOM order.
|
|
133
|
+
*
|
|
134
|
+
* The collection answers "has the cluster mounted yet?" on its own: a cluster
|
|
135
|
+
* that mounts late, or one that replaces the wired one, reaches the
|
|
136
|
+
* `added`/`removed` callbacks with nothing to poll. The cluster still
|
|
137
|
+
* dispatches `MAPBOX_CLUSTER_CONNECTED` for `MapboxClusterItem`, which looks
|
|
138
|
+
* *up* for its cluster and has no watching counterpart to `$closest()`.
|
|
155
139
|
* @private
|
|
156
140
|
*/
|
|
157
|
-
|
|
141
|
+
__clusters = this.$watchChildren("MapboxCluster", {
|
|
142
|
+
added: (cluster) => this.__wireCluster(cluster),
|
|
143
|
+
removed: (cluster) => {
|
|
144
|
+
if (this.__cluster === cluster) {
|
|
145
|
+
this.__unwireCluster();
|
|
146
|
+
this.__wireCluster(this.__clusters.items[0]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
158
150
|
/**
|
|
159
|
-
*
|
|
151
|
+
* The mounted `MapboxGeocoder` descendants, live and in DOM order. The
|
|
152
|
+
* geocoder is optional, so nothing waits for it: it wires itself whenever it
|
|
153
|
+
* turns up.
|
|
160
154
|
* @private
|
|
161
155
|
*/
|
|
162
|
-
|
|
156
|
+
__geocoders = this.$watchChildren("MapboxGeocoder", {
|
|
157
|
+
added: (geocoder) => this.__wireGeocoder(geocoder),
|
|
158
|
+
removed: (geocoder) => {
|
|
159
|
+
if (this.__geocoder === geocoder) {
|
|
160
|
+
this.__unwireGeocoder();
|
|
161
|
+
this.__wireGeocoder(this.__geocoders.items[0]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
163
165
|
/**
|
|
164
|
-
* The
|
|
166
|
+
* The child `MapboxMap` component, once it has mounted.
|
|
167
|
+
*
|
|
168
|
+
* The getter does not warn when there is none: a wrapper mounts before the
|
|
169
|
+
* elements inside it and mount order is not guaranteed, so "no map yet" is
|
|
170
|
+
* the normal state on every healthy locator. A locator with genuinely no map
|
|
171
|
+
* in its markup is reported once instead, from
|
|
172
|
+
* {@link __warnWhenMapIsMissing}.
|
|
165
173
|
*/
|
|
166
174
|
get mapboxMap() {
|
|
167
|
-
|
|
168
|
-
if (!mapboxMap) this.$warn("Can not find a child MapboxMap component.");
|
|
169
|
-
return mapboxMap;
|
|
175
|
+
return this.$query("MapboxMap")[0];
|
|
170
176
|
}
|
|
171
177
|
/**
|
|
172
178
|
* The child `MapboxCluster`, discovered in the subtree.
|
|
173
179
|
*/
|
|
174
180
|
get cluster() {
|
|
175
|
-
return this.__cluster ?? this
|
|
181
|
+
return this.__cluster ?? this.__clusters.items[0];
|
|
176
182
|
}
|
|
177
183
|
/**
|
|
178
184
|
* The optional child `MapboxGeocoder`, discovered in the subtree.
|
|
179
185
|
*/
|
|
180
186
|
get geocoder() {
|
|
181
|
-
return this.__geocoder ?? this
|
|
187
|
+
return this.__geocoder ?? this.__geocoders.items[0];
|
|
182
188
|
}
|
|
183
189
|
/**
|
|
184
190
|
* The Mapbox `Map` instance. Only valid once the map has loaded.
|
|
@@ -206,7 +212,7 @@ var StoreLocator = class extends Base {
|
|
|
206
212
|
zoom: this.$options.itemZoomLevel
|
|
207
213
|
});
|
|
208
214
|
this.__openPopup(item);
|
|
209
|
-
this.$emit("map-select", item);
|
|
215
|
+
this.$emit("map-select", { item });
|
|
210
216
|
}
|
|
211
217
|
/**
|
|
212
218
|
* Clear the current selection, close the popup and emit a `map-deselect` event.
|
|
@@ -295,7 +301,7 @@ var StoreLocator = class extends Base {
|
|
|
295
301
|
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
302
|
}
|
|
297
303
|
this.__reorderList(inView);
|
|
298
|
-
this.$emit("map-filter", inView);
|
|
304
|
+
this.$emit("map-filter", { items: inView });
|
|
299
305
|
}
|
|
300
306
|
/**
|
|
301
307
|
* Reorder the in-view items so their DOM order matches the distance sort.
|
|
@@ -316,7 +322,7 @@ var StoreLocator = class extends Base {
|
|
|
316
322
|
* @private
|
|
317
323
|
*/
|
|
318
324
|
__handleItemClick = (event) => {
|
|
319
|
-
const
|
|
325
|
+
const { item } = event.detail ?? {};
|
|
320
326
|
if (item) this.selectItem(item);
|
|
321
327
|
};
|
|
322
328
|
/**
|
|
@@ -345,7 +351,7 @@ var StoreLocator = class extends Base {
|
|
|
345
351
|
* @private
|
|
346
352
|
*/
|
|
347
353
|
__handleGeocoderResult = (event) => {
|
|
348
|
-
const
|
|
354
|
+
const { result } = event.detail ?? {};
|
|
349
355
|
const map = this.__map;
|
|
350
356
|
if (!map || !result) return;
|
|
351
357
|
if (Array.isArray(result.bbox)) {
|
|
@@ -377,7 +383,9 @@ var StoreLocator = class extends Base {
|
|
|
377
383
|
this.__bindMapRemove(map);
|
|
378
384
|
map.off("moveend", this.__handleMoveEnd);
|
|
379
385
|
map.on("moveend", this.__handleMoveEnd);
|
|
380
|
-
this.
|
|
386
|
+
this.__wireCluster(this.__clusters.items[0]);
|
|
387
|
+
this.__wireGeocoder(this.__geocoders.items[0]);
|
|
388
|
+
this.__refresh();
|
|
381
389
|
};
|
|
382
390
|
/**
|
|
383
391
|
* Subscribe once to the ready map's own `remove` event so a map removed while
|
|
@@ -435,78 +443,80 @@ var StoreLocator = class extends Base {
|
|
|
435
443
|
this.__offMapConnected = () => document.removeEventListener(MAPBOX_MAP_CONNECTED, handler);
|
|
436
444
|
}
|
|
437
445
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
446
|
+
* Report a locator with no `MapboxMap` in its markup, once.
|
|
447
|
+
*
|
|
448
|
+
* The check reads the **element**, not the mounted instance: DOM ancestry is
|
|
449
|
+
* a fact that exists before anything mounts, so it is immune both to mount
|
|
450
|
+
* ordering and to the map's mount strategy — a `data-mount` that has not
|
|
451
|
+
* fired yet is not a missing map. `whenDOMSettled()` waits for
|
|
452
|
+
* the mutation batch that brought the locator in, which is the earliest
|
|
453
|
+
* moment the markup can be judged complete.
|
|
442
454
|
* @private
|
|
443
455
|
*/
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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);
|
|
456
|
+
async __warnWhenMapIsMissing() {
|
|
457
|
+
await whenDOMSettled();
|
|
458
|
+
if (this.$isMounted && !this.$el.querySelector("[data-component=\"MapboxMap\"]")) this.$warn("store-locator.no-map", "Can not find a child MapboxMap component.");
|
|
454
459
|
}
|
|
455
460
|
/**
|
|
456
|
-
* Detach the current cluster listeners
|
|
457
|
-
* `__wireChildren` binds afresh onto a replacement cluster.
|
|
461
|
+
* Detach the current cluster listeners so a replacement can be wired afresh.
|
|
458
462
|
* @private
|
|
459
463
|
*/
|
|
460
464
|
__unwireCluster() {
|
|
461
465
|
for (const off of this.__offCluster) off();
|
|
462
466
|
this.__offCluster = [];
|
|
463
|
-
this.__clusterWired = false;
|
|
464
467
|
this.__cluster = void 0;
|
|
465
468
|
}
|
|
466
469
|
/**
|
|
467
|
-
*
|
|
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.
|
|
470
|
+
* Detach the current geocoder listener.
|
|
473
471
|
* @private
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
472
|
+
*/
|
|
473
|
+
__unwireGeocoder() {
|
|
474
|
+
for (const off of this.__offGeocoder) off();
|
|
475
|
+
this.__offGeocoder = [];
|
|
476
|
+
this.__geocoder = void 0;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Attach the `MapboxCluster` listeners, once, to the first cluster in the
|
|
480
|
+
* subtree. A no-op while the orchestrator itself is unmounted: the collection
|
|
481
|
+
* outlives a mount cycle, so `mounted()` wires whatever it already holds.
|
|
482
|
+
* @private
|
|
483
|
+
*/
|
|
484
|
+
__wireCluster(cluster) {
|
|
485
|
+
if (!cluster || this.__cluster || !this.$isMounted) return;
|
|
486
|
+
this.__cluster = cluster;
|
|
487
|
+
this.__offCluster.push(cluster.$on("map-item-click", this.__handleItemClick));
|
|
488
|
+
this.__offCluster.push(cluster.$on("map-update", this.__handleClusterUpdate));
|
|
489
|
+
this.__refresh();
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Attach the optional `MapboxGeocoder` listener, once, to the first geocoder
|
|
493
|
+
* in the subtree.
|
|
494
|
+
* @private
|
|
495
|
+
*/
|
|
496
|
+
__wireGeocoder(geocoder) {
|
|
497
|
+
if (!geocoder || this.__geocoder || !this.$isMounted) return;
|
|
498
|
+
this.__geocoder = geocoder;
|
|
499
|
+
this.__offGeocoder.push(geocoder.$on("map-result", this.__handleGeocoderResult));
|
|
493
500
|
}
|
|
494
501
|
/**
|
|
495
|
-
* Mounted hook:
|
|
496
|
-
*
|
|
497
|
-
*
|
|
502
|
+
* Mounted hook: wire whatever the children collections already hold, bind the
|
|
503
|
+
* delegated sidebar click, resolve and bind the map, and install the standing
|
|
504
|
+
* `MAPBOX_MAP_CONNECTED` subscription so a late or replaced map rebinds
|
|
505
|
+
* instead of stranding the orchestrator.
|
|
498
506
|
*/
|
|
499
507
|
mounted() {
|
|
500
508
|
this.$el.addEventListener("click", this.__handleListClick);
|
|
509
|
+
this.__wireCluster(this.__clusters.items[0]);
|
|
510
|
+
this.__wireGeocoder(this.__geocoders.items[0]);
|
|
501
511
|
this.__bindMap();
|
|
502
512
|
this.__waitForConnectedMap();
|
|
503
|
-
this.
|
|
513
|
+
this.__warnWhenMapIsMissing();
|
|
504
514
|
}
|
|
505
515
|
/**
|
|
506
|
-
*
|
|
516
|
+
* Unmounted hook: detach every listener, close the popup and clear the cached
|
|
507
517
|
* references — even when the element has already been detached from the DOM.
|
|
508
518
|
*/
|
|
509
|
-
|
|
519
|
+
unmounted() {
|
|
510
520
|
for (const off of this.__offCluster) off();
|
|
511
521
|
for (const off of this.__offGeocoder) off();
|
|
512
522
|
this.__offCluster = [];
|
|
@@ -517,8 +527,6 @@ var StoreLocator = class extends Base {
|
|
|
517
527
|
this.__offMapRemove = void 0;
|
|
518
528
|
this.__offMapConnected?.();
|
|
519
529
|
this.__offMapConnected = void 0;
|
|
520
|
-
this.__offClusterConnected?.();
|
|
521
|
-
this.__offClusterConnected = void 0;
|
|
522
530
|
this.__map?.off("moveend", this.__handleMoveEnd);
|
|
523
531
|
this.$el.removeEventListener("click", this.__handleListClick);
|
|
524
532
|
this.__popup?.remove();
|
|
@@ -528,8 +536,6 @@ var StoreLocator = class extends Base {
|
|
|
528
536
|
this.__cluster = void 0;
|
|
529
537
|
this.__geocoder = void 0;
|
|
530
538
|
this.isLoaded = false;
|
|
531
|
-
this.__clusterWired = false;
|
|
532
|
-
this.__geocoderWired = false;
|
|
533
539
|
}
|
|
534
540
|
};
|
|
535
541
|
//#endregion
|
package/dist/StoreLocator.js.map
CHANGED
|
@@ -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;EAC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K;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 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;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AAK,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.map
CHANGED
|
@@ -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
|
|
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 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.\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"}
|
package/dist/dependencies.d.ts
CHANGED
|
@@ -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
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
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
|
*/
|
package/dist/dependencies.js
CHANGED
|
@@ -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
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
*/
|
package/dist/dependencies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.js","names":[],"sources":["../src/dependencies.ts"],"sourcesContent":["import type mapboxgl from 'mapbox-gl';\n\n/**\n * The `mapbox-gl` default export namespace (`Map`, `Marker`, `Popup`, `LngLat`,\n * the `*Control` constructors, ...). This is the shape every component consumes,\n * whether it was injected with {@link provideMapboxGl} or resolved through the\n * fallback dynamic import.\n */\nexport type MapboxGl = typeof mapboxgl;\n\n/**\n * Structural shape of the optional Mapbox geocoder control instances this\n * package builds. Declared locally so the optional `@mapbox/mapbox-gl-geocoder`\n * peer never leaks into the public type surface (and therefore never into the\n * emitted declarations), which would break consumers who install\n * `@studiometa/ui-mapbox` without the optional geocoder peer.\n */\nexport interface MapboxGeocoderControl {\n addTo(target: unknown): void;\n onRemove(): void;\n /**\n * Subscribe to a geocoder control event. Declared optional so the structural\n * type stays satisfiable by minimal test doubles and older control versions.\n */\n on?(type: string, callback: (event: { result: unknown }) => void): void;\n}\n\n/**\n * Structural constructor type for the optional Mapbox geocoder control, kept out\n * of the public peer type surface for the same reason as {@link MapboxGeocoderControl}.\n */\nexport interface MapboxGeocoderConstructor {\n new (options: Record<string, unknown>): MapboxGeocoderControl;\n}\n\nlet mapboxGlInstance: MapboxGl | undefined;\nlet mapboxGlPromise: Promise<MapboxGl> | undefined;\nlet mapboxGlProvided = false;\n\nlet geocoderConstructor: MapboxGeocoderConstructor | undefined;\nlet geocoderPromise: Promise<MapboxGeocoderConstructor> | undefined;\nlet geocoderProvided = false;\n\n/**\n * Inject the `mapbox-gl` module the components should use.\n *\n * Call once, before the components mount
|
|
1
|
+
{"version":3,"file":"dependencies.js","names":[],"sources":["../src/dependencies.ts"],"sourcesContent":["import type mapboxgl from 'mapbox-gl';\n\n/**\n * The `mapbox-gl` default export namespace (`Map`, `Marker`, `Popup`, `LngLat`,\n * the `*Control` constructors, ...). This is the shape every component consumes,\n * whether it was injected with {@link provideMapboxGl} or resolved through the\n * fallback dynamic import.\n */\nexport type MapboxGl = typeof mapboxgl;\n\n/**\n * Structural shape of the optional Mapbox geocoder control instances this\n * package builds. Declared locally so the optional `@mapbox/mapbox-gl-geocoder`\n * peer never leaks into the public type surface (and therefore never into the\n * emitted declarations), which would break consumers who install\n * `@studiometa/ui-mapbox` without the optional geocoder peer.\n */\nexport interface MapboxGeocoderControl {\n addTo(target: unknown): void;\n onRemove(): void;\n /**\n * Subscribe to a geocoder control event. Declared optional so the structural\n * type stays satisfiable by minimal test doubles and older control versions.\n */\n on?(type: string, callback: (event: { result: unknown }) => void): void;\n}\n\n/**\n * Structural constructor type for the optional Mapbox geocoder control, kept out\n * of the public peer type surface for the same reason as {@link MapboxGeocoderControl}.\n */\nexport interface MapboxGeocoderConstructor {\n new (options: Record<string, unknown>): MapboxGeocoderControl;\n}\n\nlet mapboxGlInstance: MapboxGl | undefined;\nlet mapboxGlPromise: Promise<MapboxGl> | undefined;\nlet mapboxGlProvided = false;\n\nlet geocoderConstructor: MapboxGeocoderConstructor | undefined;\nlet geocoderPromise: Promise<MapboxGeocoderConstructor> | undefined;\nlet geocoderProvided = false;\n\n/**\n * Inject the `mapbox-gl` module the components should use.\n *\n * Call once, before the components mount — e.g. right before the\n * `registerComponent()` or `registerManifest()` call that puts them on the\n * page. Once provided, `@studiometa/ui-mapbox` never imports `mapbox-gl` by\n * specifier — it uses this instance — so a host can supply its own build (a\n * specific version, a self-hosted worker for strict CSP, an import-map or CDN\n * module).\n *\n * @param {MapboxGl} instance The `mapbox-gl` default export namespace.\n */\nexport function provideMapboxGl(instance: MapboxGl): void {\n mapboxGlProvided = true;\n mapboxGlInstance = instance;\n mapboxGlPromise = Promise.resolve(instance);\n}\n\n/**\n * Inject the optional Mapbox geocoder control constructor the `MapboxGeocoder`\n * component should use, so the optional `@mapbox/mapbox-gl-geocoder` peer is\n * never imported by specifier either.\n *\n * @param {MapboxGeocoderConstructor} constructor The geocoder control constructor.\n */\nexport function provideMapboxGeocoder(constructor: MapboxGeocoderConstructor): void {\n geocoderProvided = true;\n geocoderConstructor = constructor;\n geocoderPromise = Promise.resolve(constructor);\n}\n\n/**\n * Resolve the `mapbox-gl` namespace: the injected instance when one was provided\n * through {@link provideMapboxGl}, otherwise a lazily loaded `import('mapbox-gl')`.\n *\n * The result is memoized, so `mapbox-gl` loads at most once and repeated calls\n * are cheap. The resolved instance is also cached for {@link getMapboxGl}.\n *\n * @returns {Promise<MapboxGl>}\n */\nexport function resolveMapboxGl(): Promise<MapboxGl> {\n if (!mapboxGlPromise) {\n mapboxGlPromise = import('mapbox-gl').then((module) => {\n const instance = ((module as { default?: MapboxGl }).default ?? module) as MapboxGl;\n // A provideMapboxGl() call may have won the race while this import was in\n // flight: never let the fallback overwrite an injected instance. Returning\n // the authoritative instance also keeps callers that awaited this promise\n // before the injection consistent with the provided one.\n if (!mapboxGlProvided) {\n mapboxGlInstance = instance;\n }\n return mapboxGlInstance as MapboxGl;\n });\n }\n\n return mapboxGlPromise;\n}\n\n/**\n * Resolve the optional Mapbox geocoder control constructor: the injected one\n * when provided through {@link provideMapboxGeocoder}, otherwise a lazily loaded\n * `import('@mapbox/mapbox-gl-geocoder')`. Memoized like {@link resolveMapboxGl}.\n *\n * @returns {Promise<MapboxGeocoderConstructor>}\n */\nexport function resolveMapboxGeocoder(): Promise<MapboxGeocoderConstructor> {\n if (!geocoderPromise) {\n geocoderPromise = import('@mapbox/mapbox-gl-geocoder').then((module) => {\n // Cast through `unknown`: the peer's real constructor signature is narrower\n // than the structural `MapboxGeocoderConstructor` kept out of the public\n // type surface, so the two do not directly overlap.\n const constructor = (module as unknown as { default: MapboxGeocoderConstructor }).default;\n // Same race guard as resolveMapboxGl(): a provideMapboxGeocoder() call that\n // landed while this import was in flight must not be overwritten.\n if (!geocoderProvided) {\n geocoderConstructor = constructor;\n }\n return geocoderConstructor as MapboxGeocoderConstructor;\n });\n }\n\n return geocoderPromise;\n}\n\n/**\n * Synchronously read the resolved `mapbox-gl` namespace.\n *\n * Only valid after {@link resolveMapboxGl} (or {@link provideMapboxGl}) has run;\n * it throws otherwise. Components read it on synchronous hot paths (building a\n * control, marker, popup or `LngLat`) that are only ever reached once the map —\n * and therefore `mapbox-gl` — is ready.\n *\n * @returns {MapboxGl}\n */\nexport function getMapboxGl(): MapboxGl {\n if (!mapboxGlInstance) {\n throw new Error(\n '[@studiometa/ui-mapbox] mapbox-gl has not been resolved yet. Await resolveMapboxGl() (or call provideMapboxGl()) before reading it synchronously.',\n );\n }\n\n return mapboxGlInstance;\n}\n"],"mappings":";AAmCA,IAAI;AACJ,IAAI;AACJ,IAAI,mBAAmB;AAEvB,IAAI;AACJ,IAAI;AACJ,IAAI,mBAAmB;;;;;;;;;;;;;AAcvB,SAAgB,gBAAgB,UAA0B;AACxD,oBAAmB;AACnB,oBAAmB;AACnB,mBAAkB,QAAQ,QAAQ,SAAS;;;;;;;;;AAU7C,SAAgB,sBAAsB,aAA8C;AAClF,oBAAmB;AACnB,uBAAsB;AACtB,mBAAkB,QAAQ,QAAQ,YAAY;;;;;;;;;;;AAYhD,SAAgB,kBAAqC;AACnD,KAAI,CAAC,gBACH,mBAAkB,OAAO,aAAa,MAAM,WAAW;EACrD,MAAM,WAAa,OAAkC,WAAW;AAKhE,MAAI,CAAC,iBACH,oBAAmB;AAErB,SAAO;GACP;AAGJ,QAAO;;;;;;;;;AAUT,SAAgB,wBAA4D;AAC1E,KAAI,CAAC,gBACH,mBAAkB,OAAO,8BAA8B,MAAM,WAAW;EAItE,MAAM,cAAe,OAA6D;AAGlF,MAAI,CAAC,iBACH,uBAAsB;AAExB,SAAO;GACP;AAGJ,QAAO;;;;;;;;;;;;AAaT,SAAgB,cAAwB;AACtC,KAAI,CAAC,iBACH,OAAM,IAAI,MACR,oJACD;AAGH,QAAO"}
|