@studiometa/ui-mapbox 2.0.0-alpha.0 → 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.
package/README.md CHANGED
@@ -21,20 +21,23 @@ npm install @mapbox/mapbox-gl-geocoder
21
21
 
22
22
  ## Usage
23
23
 
24
- Register each component your page uses: each one registers independently and resolves its parent map on its own. `mapbox-gl` is heavy (~230 kB gzipped), so the recommended default is to lazy-register each component with js-toolkit's `importWhen*` helpers and the per-component subpaths (each subpath's default export is the component class), keeping the dependency out of your main bundle until a map is actually on the page:
24
+ Register each component your page uses: each one registers independently and resolves its parent map on its own.
25
25
 
26
26
  ```js
27
- import { registerComponents, importWhenVisible } from '@studiometa/js-toolkit';
27
+ import { registerComponents } from '@studiometa/js-toolkit';
28
+ import { MapboxMap, MapboxMarker, MapboxPopup } from '@studiometa/ui-mapbox';
28
29
 
29
30
  // Register only the components your page uses; order doesn't matter.
30
- registerComponents(
31
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMap'), 'MapboxMap'),
32
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMarker'), 'MapboxMarker'),
33
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxPopup'), 'MapboxPopup'),
34
- );
31
+ registerComponents(MapboxMap, MapboxMarker, MapboxPopup);
35
32
  ```
36
33
 
37
- Other triggers are available too — `importWhenIdle`, `importOnInteraction` and `importOnMediaQuery` — see the [`importWhen*` helper docs](https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html). Then author the map declaratively in your markup:
34
+ `mapbox-gl` is heavy (~230 kB gzipped), but it is never in your main bundle: `MapboxMap` loads it with a dynamic `import()` when it mounts, and `MapboxMap` mounts only when the map nears the viewport. The autoload entry also defers the component modules. It registers a lazy entry for every component of the package, and imports a component module only when an element on the page declares its token:
35
+
36
+ ```js
37
+ import '@studiometa/ui-mapbox/autoload';
38
+ ```
39
+
40
+ Then author the map declaratively in your markup:
38
41
 
39
42
  ```html
40
43
  <div
@@ -48,14 +51,7 @@ Other triggers are available too — `importWhenIdle`, `importOnInteraction` and
48
51
  </div>
49
52
  ```
50
53
 
51
- If you do not need code-splitting, register eagerly instead — each component is exported by name from the package:
52
-
53
- ```js
54
- import { registerComponent } from '@studiometa/js-toolkit';
55
- import { MapboxMap } from '@studiometa/ui-mapbox';
56
-
57
- registerComponent(MapboxMap);
58
- ```
54
+ `MapboxMarker` renders nothing of its own, because it configures the map from its attributes, so its element carries `hidden`. The autoload manifest gives the map children the `eager` mount strategy, so they load because their element exists, `hidden` or not. `MapboxMap`, `StoreLocator` and `MapboxGeocoder` keep `visible`, which holds `mapbox-gl` and `@mapbox/mapbox-gl-geocoder` back until they near the viewport. Do not put `hidden` on a `MapboxGeocoder`: it holds the search input, or nothing when it is added to the map, and a hidden element never loads. Override any strategy per element with `data-mount`.
59
55
 
60
56
  Do not forget to include the `mapbox-gl` stylesheet so the map renders correctly.
61
57
 
@@ -7,7 +7,14 @@ import { Map } from "mapbox-gl";
7
7
  interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
8
8
  $options: {
9
9
  /**
10
- * Wether to add the geocoder to the map or to the component's root element.
10
+ * The Mapbox access token for the geocoding requests. Inside a `MapboxMap`,
11
+ * it falls back to the map's `accessToken`. An `accessToken` set in
12
+ * `options` wins over it, as one set in `mapOptions` does on `MapboxMap`.
13
+ */
14
+ accessToken: string;
15
+ /**
16
+ * Wether to add the geocoder to the parent map or to the component's root
17
+ * element. Requires a parent `MapboxMap`.
11
18
  */
12
19
  addToMap: boolean;
13
20
  /**
@@ -30,7 +37,15 @@ interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
30
37
  };
31
38
  }
32
39
  /**
33
- * Add a geocoder control to the map.
40
+ * Add a geocoder control to the map, or to the component's root element.
41
+ *
42
+ * Inside a `MapboxMap`, the control waits for the map and falls back to the
43
+ * map's `accessToken`. Only a control added to the map (`addToMap`) shows a
44
+ * marker for the picked result: the geocoder library skips the marker when it is
45
+ * rendered in an element. Without a parent map (and without `addToMap`), it works
46
+ * on its own: it renders in the root element as soon as it mounts, needs its own
47
+ * access token (the `accessToken` option, or `options.accessToken`), and never
48
+ * loads `mapbox-gl`.
34
49
  *
35
50
  * The Mapbox geocoder module is an optional peer dependency and is loaded on
36
51
  * demand with a dynamic `import()` when the component mounts, so the rest of the
@@ -53,17 +68,45 @@ declare class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMa
53
68
  */
54
69
  get control(): MapboxGeocoderControl | undefined;
55
70
  /**
56
- * Target element the geocoder is added to: the map when `addToMap` is set,
57
- * otherwise the component's own root element.
71
+ * Target element the geocoder is added to: the parent map when `addToMap` is
72
+ * set, otherwise the component's own root element.
58
73
  */
59
74
  get target(): Map | HTMLElement | string;
60
75
  /**
61
76
  * Mounted hook.
62
77
  *
63
78
  * Lazily loads the optional Mapbox geocoder module, then builds and adds the
64
- * control once the parent map is ready.
79
+ * control: once the parent map is ready, or right away without a parent map.
65
80
  */
66
81
  mounted(): Promise<void>;
82
+ /**
83
+ * The options the control is built with.
84
+ *
85
+ * The token comes from the `accessToken` option, or else from the fallback (the
86
+ * parent map's token). The raw `options` are spread over it, so an
87
+ * `accessToken` set there wins, as one set in `mapOptions` does on
88
+ * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`
89
+ * option reads as `''` when its attribute is missing.
90
+ * @private
91
+ * @param {string} [fallbackAccessToken] The parent map's access token.
92
+ */
93
+ __controlOptions(fallbackAccessToken?: string): Record<string, unknown>;
94
+ /**
95
+ * Add a control to the target, replacing the previous one, and re-emit its
96
+ * `result` event as a prefixed component event, so consumers (e.g. a
97
+ * `StoreLocator`) can react to a geocoded address.
98
+ *
99
+ * A previous control exists when the map is replaced (the ready callback
100
+ * re-runs) or when the instance is unmounted and mounted again while the
101
+ * geocoder import is pending (both `mounted()` calls resume). An
102
+ * element-targeted control (`addToMap` false) lives on `$el`, which survives
103
+ * both, so it must be removed first or the element would stack several
104
+ * geocoders. A map-targeted control went away with its (removed) map, so only
105
+ * its reference needs dropping.
106
+ * @private
107
+ * @param {MapboxGeocoderControl} control
108
+ */
109
+ __addControl(control: MapboxGeocoderControl): void;
67
110
  /**
68
111
  * Teardown hook.
69
112
  */
@@ -1,8 +1,17 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { getMapboxGl, resolveMapboxGeocoder } from "./dependencies.js";
3
+ import { selectorFor } from "@studiometa/js-toolkit/utils/selectorFor";
3
4
  //#region src/MapboxGeocoder.ts
4
5
  /**
5
- * Add a geocoder control to the map.
6
+ * Add a geocoder control to the map, or to the component's root element.
7
+ *
8
+ * Inside a `MapboxMap`, the control waits for the map and falls back to the
9
+ * map's `accessToken`. Only a control added to the map (`addToMap`) shows a
10
+ * marker for the picked result: the geocoder library skips the marker when it is
11
+ * rendered in an element. Without a parent map (and without `addToMap`), it works
12
+ * on its own: it renders in the root element as soon as it mounts, needs its own
13
+ * access token (the `accessToken` option, or `options.accessToken`), and never
14
+ * loads `mapbox-gl`.
6
15
  *
7
16
  * The Mapbox geocoder module is an optional peer dependency and is loaded on
8
17
  * demand with a dynamic `import()` when the component mounts, so the rest of the
@@ -16,7 +25,9 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
16
25
  */
17
26
  static config = {
18
27
  name: "MapboxGeocoder",
28
+ mountStrategy: "visible",
19
29
  options: {
30
+ accessToken: String,
20
31
  addToMap: Boolean,
21
32
  options: Object
22
33
  }
@@ -33,8 +44,8 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
33
44
  return this.__control;
34
45
  }
35
46
  /**
36
- * Target element the geocoder is added to: the map when `addToMap` is set,
37
- * otherwise the component's own root element.
47
+ * Target element the geocoder is added to: the parent map when `addToMap` is
48
+ * set, otherwise the component's own root element.
38
49
  */
39
50
  get target() {
40
51
  return this.$options.addToMap ? this.map : this.$el;
@@ -43,26 +54,73 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
43
54
  * Mounted hook.
44
55
  *
45
56
  * Lazily loads the optional Mapbox geocoder module, then builds and adds the
46
- * control once the parent map is ready.
57
+ * control: once the parent map is ready, or right away without a parent map.
47
58
  */
48
59
  async mounted() {
60
+ const standalone = !this.$options.addToMap && !this.$el.parentElement?.closest(selectorFor("MapboxMap"));
61
+ if (standalone && !this.__controlOptions().accessToken) {
62
+ this.$warn("mapbox-geocoder.missing-access-token", "A MapboxGeocoder without a parent MapboxMap needs an access token: set its `data-option-access-token`.");
63
+ return;
64
+ }
49
65
  const GeocoderControlClass = await resolveMapboxGeocoder();
50
66
  if (!this.$isMounted) return;
51
- this.whenMapReady(() => {
52
- if (this.__control) {
53
- if (!this.$options.addToMap) this.__control.onRemove();
54
- this.__control = void 0;
67
+ if (standalone) {
68
+ try {
69
+ this.__addControl(new GeocoderControlClass(this.__controlOptions()));
70
+ } catch (err) {
71
+ this.__handleError(err);
55
72
  }
56
- this.__control = new GeocoderControlClass({
57
- ...this.$options.options,
58
- mapboxgl: getMapboxGl(),
59
- accessToken: this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken
60
- });
61
- this.__control.on?.("result", (event) => this.$emit("map-result", { result: event.result }));
62
- this.__control.addTo(this.target);
73
+ return;
74
+ }
75
+ this.whenMapReady(() => {
76
+ this.__addControl(new GeocoderControlClass({
77
+ ...this.__controlOptions(this.__readyMapboxMap?.$options.accessToken),
78
+ mapboxgl: getMapboxGl()
79
+ }));
63
80
  });
64
81
  }
65
82
  /**
83
+ * The options the control is built with.
84
+ *
85
+ * The token comes from the `accessToken` option, or else from the fallback (the
86
+ * parent map's token). The raw `options` are spread over it, so an
87
+ * `accessToken` set there wins, as one set in `mapOptions` does on
88
+ * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`
89
+ * option reads as `''` when its attribute is missing.
90
+ * @private
91
+ * @param {string} [fallbackAccessToken] The parent map's access token.
92
+ */
93
+ __controlOptions(fallbackAccessToken) {
94
+ return {
95
+ accessToken: this.$options.accessToken || fallbackAccessToken,
96
+ ...this.$options.options
97
+ };
98
+ }
99
+ /**
100
+ * Add a control to the target, replacing the previous one, and re-emit its
101
+ * `result` event as a prefixed component event, so consumers (e.g. a
102
+ * `StoreLocator`) can react to a geocoded address.
103
+ *
104
+ * A previous control exists when the map is replaced (the ready callback
105
+ * re-runs) or when the instance is unmounted and mounted again while the
106
+ * geocoder import is pending (both `mounted()` calls resume). An
107
+ * element-targeted control (`addToMap` false) lives on `$el`, which survives
108
+ * both, so it must be removed first or the element would stack several
109
+ * geocoders. A map-targeted control went away with its (removed) map, so only
110
+ * its reference needs dropping.
111
+ * @private
112
+ * @param {MapboxGeocoderControl} control
113
+ */
114
+ __addControl(control) {
115
+ if (this.__control) {
116
+ if (!this.$options.addToMap) this.__control.onRemove();
117
+ this.__control = void 0;
118
+ }
119
+ control.on?.("result", (event) => this.$emit("map-result", { result: event.result }));
120
+ control.addTo(this.target);
121
+ this.__control = control;
122
+ }
123
+ /**
66
124
  * Teardown hook.
67
125
  */
68
126
  __onDestroyed() {
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { Map, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl, resolveMapboxGeocoder, type MapboxGeocoderControl } from './dependencies.js';\n\nexport interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * Wether to add the geocoder to the map or to the component's root element.\n */\n addToMap: boolean;\n /**\n * All MapboxGeocoder options, except the non serializable ones.\n *\n * Typed structurally (rather than with the optional geocoder peer types) to\n * keep the peer out of the public type surface. Refer to the Mapbox geocoder\n * package documentation (API.md#parameters) for the accepted options.\n */\n options: Record<string, unknown>;\n };\n /**\n * The geocoder's own event, declared in the props type. The geocoded result\n * travels as `detail.result`.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-result': { result: unknown };\n };\n}\n\n/**\n * Add a geocoder control to the map.\n *\n * The Mapbox geocoder module is an optional peer dependency and is loaded on\n * demand with a dynamic `import()` when the component mounts, so the rest of the\n * package keeps working without it installed.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxGeocoderProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxGeocoder',\n options: {\n addToMap: Boolean,\n options: Object,\n },\n };\n\n /**\n * Control instance, created once the lazily imported module resolves.\n * @private\n */\n __control?: MapboxGeocoderControl;\n\n /**\n * The Mapbox geocoder control instance, if it has been created yet.\n */\n get control(): MapboxGeocoderControl | undefined {\n return this.__control;\n }\n\n /**\n * Target element the geocoder is added to: the map when `addToMap` is set,\n * otherwise the component's own root element.\n */\n get target(): Map | HTMLElement | string {\n return this.$options.addToMap ? this.map : this.$el;\n }\n\n /**\n * Mounted hook.\n *\n * Lazily loads the optional Mapbox geocoder module, then builds and adds the\n * control once the parent map is ready.\n */\n async mounted() {\n const GeocoderControlClass = await resolveMapboxGeocoder();\n\n // The component may have been destroyed while the dynamic import was still\n // resolving. Bail out before creating and adding the control, otherwise it\n // would be attached after `__onDestroyed()` already ran (and saw `__control`\n // undefined), leaking an orphan control.\n if (!this.$isMounted) {\n return;\n }\n\n this.whenMapReady(() => {\n // The ready callback is standing: it re-runs on every map replacement. An\n // element-targeted control (`addToMap` false) lives on `$el`, which\n // survives the map swap, so a previous control must be removed first or\n // each replacement would stack another geocoder onto the element. A\n // map-targeted control went away with its (removed) map, so only its\n // reference needs dropping.\n if (this.__control) {\n if (!this.$options.addToMap) {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n\n const options = {\n ...this.$options.options,\n mapboxgl: getMapboxGl(),\n accessToken:\n this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken,\n };\n this.__control = new GeocoderControlClass(\n options as ConstructorParameters<typeof GeocoderControlClass>[0],\n );\n // Re-emit the control's `result` event as a prefixed component event so\n // consumers (e.g. a `StoreLocator`) can react to a geocoded address.\n this.__control.on?.('result', (event) => this.$emit('map-result', { result: event.result }));\n this.__control.addTo(this.target);\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n // The control may not exist yet: the dynamic import in `mounted()` might not\n // have resolved, or the geocoder module was never loaded.\n if (this.__control) {\n if (this.$options.addToMap) {\n this.__readyMap?.removeControl(this.__control as unknown as IControl);\n } else {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n }\n}\n\nexport default MapboxGeocoder;\n"],"mappings":";;;;;;;;;;;;AAyCA,IAAa,iBAAb,cAAqE,uBAEnE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,UAAU;GACV,SAAS;GACV;EACF;;;;;CAMD;;;;CAKA,IAAI,UAA6C;AAC/C,SAAO,KAAK;;;;;;CAOd,IAAI,SAAqC;AACvC,SAAO,KAAK,SAAS,WAAW,KAAK,MAAM,KAAK;;;;;;;;CASlD,MAAM,UAAU;EACd,MAAM,uBAAuB,MAAM,uBAAuB;AAM1D,MAAI,CAAC,KAAK,WACR;AAGF,OAAK,mBAAmB;AAOtB,OAAI,KAAK,WAAW;AAClB,QAAI,CAAC,KAAK,SAAS,SACjB,MAAK,UAAU,UAAU;AAE3B,SAAK,YAAY,KAAA;;AASnB,QAAK,YAAY,IAAI,qBANL;IACd,GAAG,KAAK,SAAS;IACjB,UAAU,aAAa;IACvB,aACE,KAAK,SAAS,QAAQ,eAAe,KAAK,kBAAkB,SAAS;IACxE,CAGA;AAGD,QAAK,UAAU,KAAK,WAAW,UAAU,KAAK,MAAM,cAAc,EAAE,QAAQ,MAAM,QAAQ,CAAC,CAAC;AAC5F,QAAK,UAAU,MAAM,KAAK,OAAO;IACjC;;;;;CAMJ,gBAAgB;AAGd,MAAI,KAAK,WAAW;AAClB,OAAI,KAAK,SAAS,SAChB,MAAK,YAAY,cAAc,KAAK,UAAiC;OAErE,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA"}
1
+ {"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { selectorFor } from '@studiometa/js-toolkit/utils/selectorFor';\nimport type { Map, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl, resolveMapboxGeocoder, type MapboxGeocoderControl } from './dependencies.js';\n\nexport interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * The Mapbox access token for the geocoding requests. Inside a `MapboxMap`,\n * it falls back to the map's `accessToken`. An `accessToken` set in\n * `options` wins over it, as one set in `mapOptions` does on `MapboxMap`.\n */\n accessToken: string;\n /**\n * Wether to add the geocoder to the parent map or to the component's root\n * element. Requires a parent `MapboxMap`.\n */\n addToMap: boolean;\n /**\n * All MapboxGeocoder options, except the non serializable ones.\n *\n * Typed structurally (rather than with the optional geocoder peer types) to\n * keep the peer out of the public type surface. Refer to the Mapbox geocoder\n * package documentation (API.md#parameters) for the accepted options.\n */\n options: Record<string, unknown>;\n };\n /**\n * The geocoder's own event, declared in the props type. The geocoded result\n * travels as `detail.result`.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-result': { result: unknown };\n };\n}\n\n/**\n * Add a geocoder control to the map, or to the component's root element.\n *\n * Inside a `MapboxMap`, the control waits for the map and falls back to the\n * map's `accessToken`. Only a control added to the map (`addToMap`) shows a\n * marker for the picked result: the geocoder library skips the marker when it is\n * rendered in an element. Without a parent map (and without `addToMap`), it works\n * on its own: it renders in the root element as soon as it mounts, needs its own\n * access token (the `accessToken` option, or `options.accessToken`), and never\n * loads `mapbox-gl`.\n *\n * The Mapbox geocoder module is an optional peer dependency and is loaded on\n * demand with a dynamic `import()` when the component mounts, so the rest of the\n * package keeps working without it installed.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxGeocoderProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxGeocoder',\n mountStrategy: 'visible',\n options: {\n accessToken: String,\n addToMap: Boolean,\n options: Object,\n },\n };\n\n /**\n * Control instance, created once the lazily imported module resolves.\n * @private\n */\n __control?: MapboxGeocoderControl;\n\n /**\n * The Mapbox geocoder control instance, if it has been created yet.\n */\n get control(): MapboxGeocoderControl | undefined {\n return this.__control;\n }\n\n /**\n * Target element the geocoder is added to: the parent map when `addToMap` is\n * set, otherwise the component's own root element.\n */\n get target(): Map | HTMLElement | string {\n return this.$options.addToMap ? this.map : this.$el;\n }\n\n /**\n * Mounted hook.\n *\n * Lazily loads the optional Mapbox geocoder module, then builds and adds the\n * control: once the parent map is ready, or right away without a parent map.\n */\n async mounted() {\n // Look for the parent map element rather than a mounted `MapboxMap`\n // instance: a lazily mounted map has no instance yet, and the geocoder must\n // wait for it instead of going standalone.\n const standalone =\n !this.$options.addToMap && !this.$el.parentElement?.closest(selectorFor('MapboxMap'));\n\n if (standalone && !this.__controlOptions().accessToken) {\n this.$warn(\n 'mapbox-geocoder.missing-access-token',\n 'A MapboxGeocoder without a parent MapboxMap needs an access token: set its `data-option-access-token`.',\n );\n return;\n }\n\n const GeocoderControlClass = await resolveMapboxGeocoder();\n\n // The component may have been destroyed while the dynamic import was still\n // resolving. Bail out before creating and adding the control, otherwise it\n // would be attached after `__onDestroyed()` already ran (and saw `__control`\n // undefined), leaking an orphan control.\n if (!this.$isMounted) {\n return;\n }\n\n if (standalone) {\n // Contain a throw like the map path does: without it, it would surface as\n // an unhandled rejection of `mounted()` with no `map-error` event.\n try {\n this.__addControl(new GeocoderControlClass(this.__controlOptions()));\n } catch (err) {\n this.__handleError(err);\n }\n return;\n }\n\n // The ready callback is standing: it re-runs on every map replacement.\n this.whenMapReady(() => {\n this.__addControl(\n new GeocoderControlClass({\n ...this.__controlOptions(this.__readyMapboxMap?.$options.accessToken),\n mapboxgl: getMapboxGl(),\n }),\n );\n });\n }\n\n /**\n * The options the control is built with.\n *\n * The token comes from the `accessToken` option, or else from the fallback (the\n * parent map's token). The raw `options` are spread over it, so an\n * `accessToken` set there wins, as one set in `mapOptions` does on\n * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`\n * option reads as `''` when its attribute is missing.\n * @private\n * @param {string} [fallbackAccessToken] The parent map's access token.\n */\n __controlOptions(fallbackAccessToken?: string): Record<string, unknown> {\n return {\n accessToken: this.$options.accessToken || fallbackAccessToken,\n ...this.$options.options,\n };\n }\n\n /**\n * Add a control to the target, replacing the previous one, and re-emit its\n * `result` event as a prefixed component event, so consumers (e.g. a\n * `StoreLocator`) can react to a geocoded address.\n *\n * A previous control exists when the map is replaced (the ready callback\n * re-runs) or when the instance is unmounted and mounted again while the\n * geocoder import is pending (both `mounted()` calls resume). An\n * element-targeted control (`addToMap` false) lives on `$el`, which survives\n * both, so it must be removed first or the element would stack several\n * geocoders. A map-targeted control went away with its (removed) map, so only\n * its reference needs dropping.\n * @private\n * @param {MapboxGeocoderControl} control\n */\n __addControl(control: MapboxGeocoderControl) {\n if (this.__control) {\n if (!this.$options.addToMap) {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n\n control.on?.('result', (event) => this.$emit('map-result', { result: event.result }));\n control.addTo(this.target);\n // Keep the control only once it is added: teardown calls `onRemove()` on it,\n // which throws on a control that never rendered.\n this.__control = control;\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n // The control may not exist yet: the dynamic import in `mounted()` might not\n // have resolved, the geocoder module was never loaded, or a geocoder without\n // a parent map had no access token.\n if (this.__control) {\n if (this.$options.addToMap) {\n this.__readyMap?.removeControl(this.__control as unknown as IControl);\n } else {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n }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M,KAAK,OAAO;AAG1B,OAAK,YAAY;;;;;CAMnB,gBAAgB;AAId,MAAI,KAAK,WAAW;AAClB,OAAI,KAAK,SAAS,SAChB,MAAK,YAAY,cAAc,KAAK,UAAiC;OAErE,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA"}
package/dist/MapboxMap.js CHANGED
@@ -39,6 +39,7 @@ var MapboxMap = class extends Base {
39
39
  */
40
40
  static config = {
41
41
  name: "MapboxMap",
42
+ mountStrategy: "visible",
42
43
  refs: ["container"],
43
44
  options: {
44
45
  accessToken: String,
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\n/** One forwarded mapbox event name, prefixed the way the component re-emits it. */\ntype ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n /**\n * The map lifecycle: `map-load` once the Mapbox instance is ready, plus one\n * `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original\n * mapbox event.\n */\n $emits: { 'map-load': { map: Map } } & Record<ForwardedMapEvent, { event: unknown }>;\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` declares no child components. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', { map });\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, { event: e });\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Unmounted hook.\n */\n unmounted() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AA2BD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,YAAY;EACnB,SAAS;GACP,aAAa;GACb,MAAM;GACN,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAKD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EAOF;;;;CAKD,WAAW;;;;;;CAOX;;;;;;;CAQA,oBAAuC,EAAE;;;;;;;;;CAUzC,IAAI,MAAuB;AACzB,SAAO,KAAK;;;;;;;;CASd,MAAM,UAAU;EACd,MAAM,WAAW,MAAM,iBAAiB;AAIxC,MAAI,CAAC,KAAK,WACR;EAGF,MAAM,MAAM,IAAI,SAAS,IAAI;GAC3B,aAAa,KAAK,SAAS;GAC3B,MAAM,KAAK,SAAS;GACpB,QAAQ,KAAK,SAAS;GACtB,GAAG,KAAK,SAAS;GACjB,WAAW,KAAK,MAAM,aAAa,KAAK;GACzC,CAAC;AACF,OAAK,QAAQ;EAEb,MAAM,eAAe;AACnB,QAAK,WAAW;AAChB,QAAK,MAAM,YAAY,EAAE,KAAK,CAAC;;AAEjC,MAAI,GAAG,QAAQ,OAAO;AACtB,OAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,QAAQ,OAAO,CAAC;AAElE,OAAK,MAAM,SAAS,sBAAsB;GACxC,MAAM,WAAW,MAAe;AAC9B,SAAK,MAAM,OAAO,SAAS,EAAE,OAAO,GAAG,CAAC;;AAE1C,OAAI,GAAG,OAAO,QAAQ;AACtB,QAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAMpE,WAAS,cAAc,IAAI,YAAY,sBAAsB,EAAE,QAAQ,MAAM,CAAC,CAAC;;;;;CAMjF,YAAY;AAGV,OAAK,MAAM,OAAO,KAAK,kBACrB,MAAK;AAEP,OAAK,oBAAoB,EAAE;AAE3B,OAAK,OAAO,QAAQ;AACpB,OAAK,QAAQ,KAAA;AACb,OAAK,WAAW"}
1
+ {"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\n/** One forwarded mapbox event name, prefixed the way the component re-emits it. */\ntype ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n /**\n * The map lifecycle: `map-load` once the Mapbox instance is ready, plus one\n * `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original\n * mapbox event.\n */\n $emits: { 'map-load': { map: Map } } & Record<ForwardedMapEvent, { event: unknown }>;\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n mountStrategy: 'visible',\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` declares no child components. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', { map });\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, { event: e });\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Unmounted hook.\n */\n unmounted() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AA2BD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,eAAe;EACf,MAAM,CAAC,YAAY;EACnB,SAAS;GACP,aAAa;GACb,MAAM;GACN,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAKD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EAOF;;;;CAKD,WAAW;;;;;;CAOX;;;;;;;CAQA,oBAAuC,EAAE;;;;;;;;;CAUzC,IAAI,MAAuB;AACzB,SAAO,KAAK;;;;;;;;CASd,MAAM,UAAU;EACd,MAAM,WAAW,MAAM,iBAAiB;AAIxC,MAAI,CAAC,KAAK,WACR;EAGF,MAAM,MAAM,IAAI,SAAS,IAAI;GAC3B,aAAa,KAAK,SAAS;GAC3B,MAAM,KAAK,SAAS;GACpB,QAAQ,KAAK,SAAS;GACtB,GAAG,KAAK,SAAS;GACjB,WAAW,KAAK,MAAM,aAAa,KAAK;GACzC,CAAC;AACF,OAAK,QAAQ;EAEb,MAAM,eAAe;AACnB,QAAK,WAAW;AAChB,QAAK,MAAM,YAAY,EAAE,KAAK,CAAC;;AAEjC,MAAI,GAAG,QAAQ,OAAO;AACtB,OAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,QAAQ,OAAO,CAAC;AAElE,OAAK,MAAM,SAAS,sBAAsB;GACxC,MAAM,WAAW,MAAe;AAC9B,SAAK,MAAM,OAAO,SAAS,EAAE,OAAO,GAAG,CAAC;;AAE1C,OAAI,GAAG,OAAO,QAAQ;AACtB,QAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAMpE,WAAS,cAAc,IAAI,YAAY,sBAAsB,EAAE,QAAQ,MAAM,CAAC,CAAC;;;;;CAMjF,YAAY;AAGV,OAAK,MAAM,OAAO,KAAK,kBACrB,MAAK;AAEP,OAAK,oBAAoB,EAAE;AAE3B,OAAK,OAAO,QAAQ;AACpB,OAAK,QAAQ,KAAA;AACb,OAAK,WAAW"}
@@ -53,6 +53,7 @@ var StoreLocator = class extends Base {
53
53
  */
54
54
  static config = {
55
55
  name: "StoreLocator",
56
+ mountStrategy: "visible",
56
57
  options: {
57
58
  itemZoomLevel: {
58
59
  type: Number,
@@ -1 +1 @@
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 Store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ACR,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"}
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;;;;;CAM7C,IAAI,UAAqC;AACvC,SAAO,KAAK,aAAa,KAAK,WAAW,MAAM;;;;;CAMjD,IAAI,WAAuC;AACzC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,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 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"}
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"}
package/dist/manifest.js CHANGED
@@ -1,15 +1,15 @@
1
1
  //#region src/manifest.ts
2
2
  const manifest = {
3
3
  MapboxCluster: {
4
- mountStrategy: "visible",
4
+ mountStrategy: "eager",
5
5
  load: () => import("./MapboxCluster.js").then(({ MapboxCluster }) => MapboxCluster)
6
6
  },
7
7
  MapboxClusterItem: {
8
- mountStrategy: "visible",
8
+ mountStrategy: "eager",
9
9
  load: () => import("./MapboxClusterItem.js").then(({ MapboxClusterItem }) => MapboxClusterItem)
10
10
  },
11
11
  MapboxFullscreenControl: {
12
- mountStrategy: "visible",
12
+ mountStrategy: "eager",
13
13
  load: () => import("./MapboxFullscreenControl.js").then(({ MapboxFullscreenControl }) => MapboxFullscreenControl)
14
14
  },
15
15
  MapboxGeocoder: {
@@ -17,19 +17,19 @@ const manifest = {
17
17
  load: () => import("./MapboxGeocoder.js").then(({ MapboxGeocoder }) => MapboxGeocoder)
18
18
  },
19
19
  MapboxGeolocateControl: {
20
- mountStrategy: "visible",
20
+ mountStrategy: "eager",
21
21
  load: () => import("./MapboxGeolocateControl.js").then(({ MapboxGeolocateControl }) => MapboxGeolocateControl)
22
22
  },
23
23
  MapboxImage: {
24
- mountStrategy: "visible",
24
+ mountStrategy: "eager",
25
25
  load: () => import("./MapboxImage.js").then(({ MapboxImage }) => MapboxImage)
26
26
  },
27
27
  MapboxImages: {
28
- mountStrategy: "visible",
28
+ mountStrategy: "eager",
29
29
  load: () => import("./MapboxImages.js").then(({ MapboxImages }) => MapboxImages)
30
30
  },
31
31
  MapboxLayer: {
32
- mountStrategy: "visible",
32
+ mountStrategy: "eager",
33
33
  load: () => import("./MapboxLayer.js").then(({ MapboxLayer }) => MapboxLayer)
34
34
  },
35
35
  MapboxMap: {
@@ -37,19 +37,19 @@ const manifest = {
37
37
  load: () => import("./MapboxMap.js").then(({ MapboxMap }) => MapboxMap)
38
38
  },
39
39
  MapboxMarker: {
40
- mountStrategy: "visible",
40
+ mountStrategy: "eager",
41
41
  load: () => import("./MapboxMarker.js").then(({ MapboxMarker }) => MapboxMarker)
42
42
  },
43
43
  MapboxNavigationControl: {
44
- mountStrategy: "visible",
44
+ mountStrategy: "eager",
45
45
  load: () => import("./MapboxNavigationControl.js").then(({ MapboxNavigationControl }) => MapboxNavigationControl)
46
46
  },
47
47
  MapboxPopup: {
48
- mountStrategy: "visible",
48
+ mountStrategy: "eager",
49
49
  load: () => import("./MapboxPopup.js").then(({ MapboxPopup }) => MapboxPopup)
50
50
  },
51
51
  MapboxSource: {
52
- mountStrategy: "visible",
52
+ mountStrategy: "eager",
53
53
  load: () => import("./MapboxSource.js").then(({ MapboxSource }) => MapboxSource)
54
54
  },
55
55
  StoreLocator: {
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.js","names":[],"sources":["../src/manifest.ts"],"sourcesContent":["// This file is generated by scripts/generate-manifests.ts. Do not edit.\nimport type { ComponentManifest } from '@studiometa/js-toolkit';\n\nexport const manifest: ComponentManifest = {\n MapboxCluster: {\n mountStrategy: 'visible',\n load: () => import('./MapboxCluster.js').then(({ MapboxCluster }) => MapboxCluster),\n },\n MapboxClusterItem: {\n mountStrategy: 'visible',\n load: () => import('./MapboxClusterItem.js').then(({ MapboxClusterItem }) => MapboxClusterItem),\n },\n MapboxFullscreenControl: {\n mountStrategy: 'visible',\n load: () =>\n import('./MapboxFullscreenControl.js').then(\n ({ MapboxFullscreenControl }) => MapboxFullscreenControl,\n ),\n },\n MapboxGeocoder: {\n mountStrategy: 'visible',\n load: () => import('./MapboxGeocoder.js').then(({ MapboxGeocoder }) => MapboxGeocoder),\n },\n MapboxGeolocateControl: {\n mountStrategy: 'visible',\n load: () =>\n import('./MapboxGeolocateControl.js').then(\n ({ MapboxGeolocateControl }) => MapboxGeolocateControl,\n ),\n },\n MapboxImage: {\n mountStrategy: 'visible',\n load: () => import('./MapboxImage.js').then(({ MapboxImage }) => MapboxImage),\n },\n MapboxImages: {\n mountStrategy: 'visible',\n load: () => import('./MapboxImages.js').then(({ MapboxImages }) => MapboxImages),\n },\n MapboxLayer: {\n mountStrategy: 'visible',\n load: () => import('./MapboxLayer.js').then(({ MapboxLayer }) => MapboxLayer),\n },\n MapboxMap: {\n mountStrategy: 'visible',\n load: () => import('./MapboxMap.js').then(({ MapboxMap }) => MapboxMap),\n },\n MapboxMarker: {\n mountStrategy: 'visible',\n load: () => import('./MapboxMarker.js').then(({ MapboxMarker }) => MapboxMarker),\n },\n MapboxNavigationControl: {\n mountStrategy: 'visible',\n load: () =>\n import('./MapboxNavigationControl.js').then(\n ({ MapboxNavigationControl }) => MapboxNavigationControl,\n ),\n },\n MapboxPopup: {\n mountStrategy: 'visible',\n load: () => import('./MapboxPopup.js').then(({ MapboxPopup }) => MapboxPopup),\n },\n MapboxSource: {\n mountStrategy: 'visible',\n load: () => import('./MapboxSource.js').then(({ MapboxSource }) => MapboxSource),\n },\n StoreLocator: {\n mountStrategy: 'visible',\n load: () => import('./StoreLocator.js').then(({ StoreLocator }) => StoreLocator),\n },\n};\n"],"mappings":";AAGA,MAAa,WAA8B;CACzC,eAAe;EACb,eAAe;EACf,YAAY,OAAO,sBAAsB,MAAM,EAAE,oBAAoB,cAAc;EACpF;CACD,mBAAmB;EACjB,eAAe;EACf,YAAY,OAAO,0BAA0B,MAAM,EAAE,wBAAwB,kBAAkB;EAChG;CACD,yBAAyB;EACvB,eAAe;EACf,YACE,OAAO,gCAAgC,MACpC,EAAE,8BAA8B,wBAClC;EACJ;CACD,gBAAgB;EACd,eAAe;EACf,YAAY,OAAO,uBAAuB,MAAM,EAAE,qBAAqB,eAAe;EACvF;CACD,wBAAwB;EACtB,eAAe;EACf,YACE,OAAO,+BAA+B,MACnC,EAAE,6BAA6B,uBACjC;EACJ;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,WAAW;EACT,eAAe;EACf,YAAY,OAAO,kBAAkB,MAAM,EAAE,gBAAgB,UAAU;EACxE;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,yBAAyB;EACvB,eAAe;EACf,YACE,OAAO,gCAAgC,MACpC,EAAE,8BAA8B,wBAClC;EACJ;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACF"}
1
+ {"version":3,"file":"manifest.js","names":[],"sources":["../src/manifest.ts"],"sourcesContent":["// This file is generated by scripts/generate-manifests.ts. Do not edit.\nimport type { ComponentManifest } from '@studiometa/js-toolkit';\n\nexport const manifest: ComponentManifest = {\n MapboxCluster: {\n mountStrategy: 'eager',\n load: () => import('./MapboxCluster.js').then(({ MapboxCluster }) => MapboxCluster),\n },\n MapboxClusterItem: {\n mountStrategy: 'eager',\n load: () => import('./MapboxClusterItem.js').then(({ MapboxClusterItem }) => MapboxClusterItem),\n },\n MapboxFullscreenControl: {\n mountStrategy: 'eager',\n load: () =>\n import('./MapboxFullscreenControl.js').then(\n ({ MapboxFullscreenControl }) => MapboxFullscreenControl,\n ),\n },\n MapboxGeocoder: {\n mountStrategy: 'visible',\n load: () => import('./MapboxGeocoder.js').then(({ MapboxGeocoder }) => MapboxGeocoder),\n },\n MapboxGeolocateControl: {\n mountStrategy: 'eager',\n load: () =>\n import('./MapboxGeolocateControl.js').then(\n ({ MapboxGeolocateControl }) => MapboxGeolocateControl,\n ),\n },\n MapboxImage: {\n mountStrategy: 'eager',\n load: () => import('./MapboxImage.js').then(({ MapboxImage }) => MapboxImage),\n },\n MapboxImages: {\n mountStrategy: 'eager',\n load: () => import('./MapboxImages.js').then(({ MapboxImages }) => MapboxImages),\n },\n MapboxLayer: {\n mountStrategy: 'eager',\n load: () => import('./MapboxLayer.js').then(({ MapboxLayer }) => MapboxLayer),\n },\n MapboxMap: {\n mountStrategy: 'visible',\n load: () => import('./MapboxMap.js').then(({ MapboxMap }) => MapboxMap),\n },\n MapboxMarker: {\n mountStrategy: 'eager',\n load: () => import('./MapboxMarker.js').then(({ MapboxMarker }) => MapboxMarker),\n },\n MapboxNavigationControl: {\n mountStrategy: 'eager',\n load: () =>\n import('./MapboxNavigationControl.js').then(\n ({ MapboxNavigationControl }) => MapboxNavigationControl,\n ),\n },\n MapboxPopup: {\n mountStrategy: 'eager',\n load: () => import('./MapboxPopup.js').then(({ MapboxPopup }) => MapboxPopup),\n },\n MapboxSource: {\n mountStrategy: 'eager',\n load: () => import('./MapboxSource.js').then(({ MapboxSource }) => MapboxSource),\n },\n StoreLocator: {\n mountStrategy: 'visible',\n load: () => import('./StoreLocator.js').then(({ StoreLocator }) => StoreLocator),\n },\n};\n"],"mappings":";AAGA,MAAa,WAA8B;CACzC,eAAe;EACb,eAAe;EACf,YAAY,OAAO,sBAAsB,MAAM,EAAE,oBAAoB,cAAc;EACpF;CACD,mBAAmB;EACjB,eAAe;EACf,YAAY,OAAO,0BAA0B,MAAM,EAAE,wBAAwB,kBAAkB;EAChG;CACD,yBAAyB;EACvB,eAAe;EACf,YACE,OAAO,gCAAgC,MACpC,EAAE,8BAA8B,wBAClC;EACJ;CACD,gBAAgB;EACd,eAAe;EACf,YAAY,OAAO,uBAAuB,MAAM,EAAE,qBAAqB,eAAe;EACvF;CACD,wBAAwB;EACtB,eAAe;EACf,YACE,OAAO,+BAA+B,MACnC,EAAE,6BAA6B,uBACjC;EACJ;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,WAAW;EACT,eAAe;EACf,YAAY,OAAO,kBAAkB,MAAM,EAAE,gBAAgB,UAAU;EACxE;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,yBAAyB;EACvB,eAAe;EACf,YACE,OAAO,gCAAgC,MACpC,EAAE,8BAA8B,wBAClC;EACJ;CACD,aAAa;EACX,eAAe;EACf,YAAY,OAAO,oBAAoB,MAAM,EAAE,kBAAkB,YAAY;EAC9E;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACD,cAAc;EACZ,eAAe;EACf,YAAY,OAAO,qBAAqB,MAAM,EAAE,mBAAmB,aAAa;EACjF;CACF"}
@@ -11,7 +11,8 @@ import { MountStrategy } from "@studiometa/js-toolkit";
11
11
  */
12
12
  /**
13
13
  * Curated authoring metadata for a single component, consumed by the manifest generator. The
14
- * `subpath` and `exportName` default to the `token` when omitted.
14
+ * `subpath` and `exportName` default to the `token` when omitted, and `strategy` defaults to the
15
+ * one the catalog declares for the whole package.
15
16
  */
16
17
  interface CuratedComponentMetadata {
17
18
  token: string;
@@ -21,10 +22,12 @@ interface CuratedComponentMetadata {
21
22
  integrations?: readonly string[];
22
23
  subpath?: string;
23
24
  exportName?: string;
25
+ strategy?: MountStrategy;
24
26
  }
25
27
  /**
26
28
  * The authoring catalog for a component package: the list of its components, the default strategy
27
- * they share, and the abstract exports that are intentionally excluded from the manifest.
29
+ * a component inherits when it declares none of its own, and the abstract exports that are
30
+ * intentionally excluded from the manifest.
28
31
  */
29
32
  interface ComponentCatalog {
30
33
  packageName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/ui-mapbox",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "Vanilla js-toolkit components to build Mapbox GL maps declaratively",
5
5
  "publishConfig": {
6
6
  "access": "public"