@xgis/xgis-components 0.3.25 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { useMapViewStore, modeForSide, useBasemapStore, useBasemapTree, useComponentTranslate, BASEMAP_COMPONENT_ID, useTranslate, resolveActiveBasemapNode, useBasemapAvailability, basemapNodeIcon, BaseMapErrors, layerKey, SLOTS, useLayoutStore, Slot, SIDEPANEL_COMPONENT_ID, useUiStore, useTopicStore, useLayerStore, LAYERPANEL_COMPONENT_ID, MAPSWITCH_COMPONENT_ID, useConfigStore, wrapToRange, RADIANS_TO_DEGREES, useCapability, NAVIGATION_COMPONENT_ID, useParallelViewSync, activeEngine, useNavigationHistoryStore, extentCenter, selectSyncedGroup, wgs84ToEpsg3301, containsPoint, clampPointToBounds, epsg3301ToWgs84, translate, componentKey, DEGREES_TO_RADIANS, useGeolocationStore, useMapBusEmit, useUserMarkerStore, useZoomFloor, MAX_ZOOM, useMapBusEvent, NOTIFICATION_COMPONENT_ID, TOPICLIST_COMPONENT_ID } from '@xgis/xgis-common';
1
+ import { useMapViewStore, modeForSide, useBasemapStore, useBasemapTree, useComponentTranslate, BASEMAP_COMPONENT_ID, useTranslate, resolveActiveBasemapNode, useBasemapAvailability, basemapNodeIcon, BaseMapErrors, layerKey, SLOTS, useLayoutStore, Slot, SIDEPANEL_COMPONENT_ID, useUiStore, useTopicStore, useLayerStore, LAYERPANEL_COMPONENT_ID, MAPSWITCH_COMPONENT_ID, useConfigStore, wrapToRange, RADIANS_TO_DEGREES, useCapability, NAVIGATION_COMPONENT_ID, useParallelViewSync, useComponentSettingsStore, TOP_DOWN_PITCH, activeEngine, useNavigationHistoryStore, extentCenter, selectSyncedGroup, wgs84ToEpsg3301, containsPoint, clampPointToBounds, epsg3301ToWgs84, DEGREES_TO_RADIANS, TWO_PI, translate, componentKey, useGeolocationStore, useMapBusEmit, useUserMarkerStore, useZoomFloor, MAX_ZOOM, useMapBusEvent, NOTIFICATION_COMPONENT_ID, SEARCH_COMPONENT_ID, useI18nStore, TOPICLIST_COMPONENT_ID, isSafeExternalUrl, openExternalUrl, EXTERNAL_LINK_REL } from '@xgis/xgis-common';
2
2
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
3
- import { Tabs, Toggle, ButtonGroup, Button, Icon, Text, sendNotification, ToastContainer, CardButton, Card, Collapse, TextField, Row, Col, Select } from '@tedi-design-system/react/tedi';
3
+ import { Tabs, Toggle, ButtonGroup, Button, Icon, Text, sendNotification, ToastContainer, InputGroup, Input, Search, Suffix, Card, CardButton, Collapse, TextField, Row, Col, Select } from '@tedi-design-system/react/tedi';
4
4
  import { BaseMapSelection, MapAccordion, MapButton, ButtonGroup as ButtonGroup$1 } from '@tedi-design-system/react/community';
5
5
  import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
6
6
 
@@ -23,14 +23,14 @@ function BasemapIcon({ src, alt }) {
23
23
  );
24
24
  }
25
25
 
26
- function optionTooltip(status, failed, t) {
26
+ function optionTooltip(status, t) {
27
+ if (status?.reason === BaseMapErrors.SCALE) {
28
+ return void 0;
29
+ }
27
30
  if (status?.reason) {
28
31
  return t(`unavailable.${status.reason}`);
29
32
  }
30
- if (failed) {
31
- return t(`unavailable.${BaseMapErrors.SERVICE}`);
32
- }
33
- return "";
33
+ return void 0;
34
34
  }
35
35
  function nodeTitle(node, t) {
36
36
  const key = node.kind === "folder" ? `${node.id}.label` : layerKey(node.id, "name.label");
@@ -44,13 +44,10 @@ function BasemapView({ componentId }) {
44
44
  const activeBasemap3d = useBasemapStore((s) => s.activeBasemap3d);
45
45
  const opacity2d = useBasemapStore((s) => s.opacity2d);
46
46
  const opacity3d = useBasemapStore((s) => s.opacity3d);
47
- const failedBasemap2d = useBasemapStore((s) => s.failedBasemap2d);
48
- const failedBasemap3d = useBasemapStore((s) => s.failedBasemap3d);
49
47
  const engine = activeMap === "parallel" ? activeParallellMap : activeMap;
50
48
  const tree = useBasemapTree(engine, componentId);
51
49
  const activeBasemap = engine === "3d" ? activeBasemap3d : activeBasemap2d;
52
50
  const basemapOpacity = engine === "3d" ? opacity3d : opacity2d;
53
- const failedBasemap = engine === "3d" ? failedBasemap3d : failedBasemap2d;
54
51
  const setActiveBasemap = useBasemapStore((s) => s.setActiveBasemap);
55
52
  const setBasemapOpacity = useBasemapStore((s) => s.setBasemapOpacity);
56
53
  const t = useComponentTranslate(BASEMAP_COMPONENT_ID);
@@ -70,7 +67,6 @@ function BasemapView({ componentId }) {
70
67
  onTransparencyChange: handleOpacityChange,
71
68
  id: "basemap-button",
72
69
  title: t("title"),
73
- multiple: tree.length > 1,
74
70
  showTransparency: true,
75
71
  content: /* @__PURE__ */ jsx(
76
72
  BasemapIcon,
@@ -83,7 +79,7 @@ function BasemapView({ componentId }) {
83
79
  const id = node.id;
84
80
  const status = availability.get(id);
85
81
  const disabled = Boolean(status && !status.available && !status.pending);
86
- const tooltip = optionTooltip(status, id === failedBasemap, t);
82
+ const tooltip = optionTooltip(status, t);
87
83
  const title = nodeTitle(node, tRoot);
88
84
  return /* @__PURE__ */ jsx(
89
85
  BaseMapSelection.Option,
@@ -92,7 +88,6 @@ function BasemapView({ componentId }) {
92
88
  title,
93
89
  id,
94
90
  disabled,
95
- multiple: node.kind === "folder",
96
91
  selected: id === activeBasemap,
97
92
  tooltipText: tooltip,
98
93
  tooltipType: "error",
@@ -108,30 +103,26 @@ function BasemapView({ componentId }) {
108
103
  }
109
104
 
110
105
  const title$1 = "Base maps";
111
- const enMessages$5 = {
106
+ const enMessages$6 = {
112
107
  title: title$1,
113
108
  "unavailable.crsUnsupported": "Not available in 3D",
114
109
  "unavailable.capabilitiesFailed": "Base map service is unavailable",
115
- "unavailable.outOfScale": "Unavailable at the current zoom level",
116
110
  "unavailable.layerUnavailable": "Base map could not be loaded",
117
- "unavailable.serviceError": "Map service has errors",
118
111
  };
119
112
 
120
113
  const title = "Aluskaardid";
121
- const etMessages$5 = {
114
+ const etMessages$6 = {
122
115
  title,
123
116
  "unavailable.crsUnsupported": "Aluskaart ei toeta 3D vaadet",
124
117
  "unavailable.capabilitiesFailed": "Kaarditeenus ei ole kättesaadav",
125
- "unavailable.outOfScale": "Aluskaart ei ole nähtavusulatuses",
126
118
  "unavailable.layerUnavailable": "Aluskaardi laadimine ebaõnnestus",
127
- "unavailable.serviceError": "Kaarditeenuses esineb tõrkeid",
128
119
  };
129
120
 
130
121
  const BasemapComponent = {
131
122
  id: BASEMAP_COMPONENT_ID,
132
123
  messages: {
133
- et: etMessages$5,
134
- en: enMessages$5
124
+ et: etMessages$6,
125
+ en: enMessages$6
135
126
  },
136
127
  ui: {
137
128
  [SLOTS.BASEMAPS]: { Component: BasemapView }
@@ -168,12 +159,12 @@ const styles$3 = {
168
159
  panel: panel
169
160
  };
170
161
 
171
- const enMessages$4 = {
162
+ const enMessages$5 = {
172
163
  "tabs.aria": "Layer views",
173
164
  "tabs.topic": "Theme map",
174
165
  };
175
166
 
176
- const etMessages$4 = {
167
+ const etMessages$5 = {
177
168
  "tabs.aria": "Kihtide vaated",
178
169
  "tabs.topic": "Teemakaart",
179
170
  };
@@ -198,8 +189,8 @@ const SIDE_PANEL_SLOTS = {
198
189
  const SidePanelComponent = {
199
190
  id: SIDEPANEL_COMPONENT_ID,
200
191
  messages: {
201
- et: etMessages$4,
202
- en: enMessages$4
192
+ et: etMessages$5,
193
+ en: enMessages$5
203
194
  },
204
195
  ui: {
205
196
  [SLOTS.SIDE_PANEL]: { Component: SidePanelView }
@@ -234,12 +225,12 @@ function MobileSidePanel() {
234
225
  }
235
226
 
236
227
  const layers$1 = "Layers";
237
- const enMessages$3 = {
228
+ const enMessages$4 = {
238
229
  layers: layers$1,
239
230
  };
240
231
 
241
232
  const layers = "Kihid";
242
- const etMessages$3 = {
233
+ const etMessages$4 = {
243
234
  layers,
244
235
  };
245
236
 
@@ -294,8 +285,8 @@ function LayerPanelView(_props) {
294
285
  const LayerPanelComponent = {
295
286
  id: LAYERPANEL_COMPONENT_ID,
296
287
  messages: {
297
- et: etMessages$3,
298
- en: enMessages$3
288
+ et: etMessages$4,
289
+ en: enMessages$4
299
290
  },
300
291
  contributions: [{ target: SIDE_PANEL_SLOTS.LAYERS, Component: LayerPanelView }],
301
292
  bookmark: {
@@ -306,7 +297,7 @@ const LayerPanelComponent = {
306
297
 
307
298
  const ariaLabel$1 = "Map mode";
308
299
  const parallel$1 = "Parallel view";
309
- const enMessages$2 = {
300
+ const enMessages$3 = {
310
301
  ariaLabel: ariaLabel$1,
311
302
  "2d": "2D",
312
303
  "3d": "3D",
@@ -315,7 +306,7 @@ const enMessages$2 = {
315
306
 
316
307
  const ariaLabel = "Kaardirežiim";
317
308
  const parallel = "Paralleelvaade";
318
- const etMessages$2 = {
309
+ const etMessages$3 = {
319
310
  ariaLabel,
320
311
  "2d": "2D",
321
312
  "3d": "3D",
@@ -383,8 +374,8 @@ function MapSwitchButtons({ layout }) {
383
374
  const MapSwitchComponent = {
384
375
  id: MAPSWITCH_COMPONENT_ID,
385
376
  messages: {
386
- et: etMessages$2,
387
- en: enMessages$2
377
+ et: etMessages$3,
378
+ en: enMessages$3
388
379
  },
389
380
  ui: {
390
381
  [SLOTS.MAP_SWITCH]: { Component: MapSwitchButtons }
@@ -445,13 +436,18 @@ const styles$1 = {
445
436
  };
446
437
 
447
438
  const NORTH_ROTATION = 0;
448
- const TOP_DOWN_PITCH = -Math.PI / 2;
449
439
  const NORTH_ICON_REST_ROTATION_DEG = compassIconRotationDegrees(0);
450
440
  function CompassButtons(_props) {
451
441
  const t = useComponentTranslate(NAVIGATION_COMPONENT_ID);
452
442
  const rotation = useLiveRotation();
453
443
  const defaultView = useMapViewStore((s) => s.defaultView);
444
+ const rotationAllowed = useMapViewStore((s) => s.rotationAllowed);
454
445
  const { available, coupled, toggle } = useParallelViewSync();
446
+ const settings = useComponentSettingsStore(
447
+ (s) => s.getComponentSettings(NAVIGATION_COMPONENT_ID)
448
+ );
449
+ const showDefaultView = settings?.reset === true;
450
+ const showCompass = settings?.positioningCompass !== false && rotationAllowed;
455
451
  const compassDeg = rotationToCompassDegrees(rotation);
456
452
  const restoreInitialView = () => {
457
453
  const { rotation: rotation2, pitch } = defaultView;
@@ -504,14 +500,17 @@ function CompassButtons(_props) {
504
500
  onClick: toggle
505
501
  }
506
502
  ] : void 0;
503
+ if (!showDefaultView && !showCompass) {
504
+ return null;
505
+ }
507
506
  return /* @__PURE__ */ jsxs(
508
507
  ButtonGroup$1,
509
508
  {
510
509
  direction: "vertical",
511
510
  ariaLabel: t("orientationControls"),
512
- suffix: `${compassDeg}°`,
511
+ suffix: showCompass ? `${compassDeg}°` : void 0,
513
512
  children: [
514
- /* @__PURE__ */ jsx(
513
+ showDefaultView && /* @__PURE__ */ jsx(
515
514
  MapButton,
516
515
  {
517
516
  size: "small",
@@ -522,7 +521,7 @@ function CompassButtons(_props) {
522
521
  children: t("defaultView")
523
522
  }
524
523
  ),
525
- /* @__PURE__ */ jsx(
524
+ showCompass && /* @__PURE__ */ jsx(
526
525
  MapButton,
527
526
  {
528
527
  size: "small",
@@ -591,6 +590,12 @@ function useNavigationHistory() {
591
590
  function HistoryButtons(_props) {
592
591
  const t = useComponentTranslate(NAVIGATION_COMPONENT_ID);
593
592
  const { canGoBack, canGoForward, back, forward } = useNavigationHistory();
593
+ const settings = useComponentSettingsStore(
594
+ (s) => s.getComponentSettings(NAVIGATION_COMPONENT_ID)
595
+ );
596
+ if (settings?.history === false) {
597
+ return null;
598
+ }
594
599
  return /* @__PURE__ */ jsxs(ButtonGroup$1, { direction: "vertical", ariaLabel: t("historyControls"), children: [
595
600
  /* @__PURE__ */ jsx(
596
601
  MapButton,
@@ -639,7 +644,7 @@ const locationRationaleTooltip$1 = "Find your location";
639
644
  const restoreNorth$1 = "Restore north";
640
645
  const coupleViews$1 = "Lock map views";
641
646
  const decoupleViews$1 = "Unlock";
642
- const enMessages$1 = {
647
+ const enMessages$2 = {
643
648
  zoomIn: zoomIn$1,
644
649
  zoomOut: zoomOut$1,
645
650
  back: back$3,
@@ -682,7 +687,7 @@ const locationRationaleTooltip = "Positsioneeri";
682
687
  const restoreNorth = "Taasta põhjasuund";
683
688
  const coupleViews = "Lukusta kaardivaated";
684
689
  const decoupleViews = "Lukusta lahti";
685
- const etMessages$1 = {
690
+ const etMessages$2 = {
686
691
  zoomIn,
687
692
  zoomOut,
688
693
  back: back$2,
@@ -713,6 +718,9 @@ function hasMovedEnough(previous, next) {
713
718
  function headingToRadians(headingDegrees) {
714
719
  return headingDegrees * DEGREES_TO_RADIANS;
715
720
  }
721
+ function headingToMapRotation(headingDegrees) {
722
+ return wrapToRange(-headingToRadians(headingDegrees), TWO_PI);
723
+ }
716
724
  function geolocationErrorMessage(error) {
717
725
  const key = error.code === PERMISSION_DENIED ? "locationDenied" : "locationError";
718
726
  return translate(componentKey(NAVIGATION_COMPONENT_ID, key));
@@ -731,6 +739,11 @@ function constrainToBounds(position, constraintBbox) {
731
739
 
732
740
  const LOCATE_ZOOM = 14;
733
741
  const RATIONALE_FLAG = "xgis.gpsRationaleShown";
742
+ const POSITION_OPTIONS = {
743
+ enableHighAccuracy: true,
744
+ timeout: 1e4,
745
+ maximumAge: 5e3
746
+ };
734
747
  function hasShownRationale() {
735
748
  try {
736
749
  return localStorage.getItem(RATIONALE_FLAG) === "true";
@@ -752,6 +765,7 @@ function useGeolocation() {
752
765
  const setMarker = useUserMarkerStore((s) => s.setMarker);
753
766
  const setHeading = useUserMarkerStore((s) => s.setHeading);
754
767
  const trackingOutsideBounds = useRef(false);
768
+ const isFirstFix = useRef(true);
755
769
  const resolvePosition = useCallback(
756
770
  (position) => {
757
771
  const constraintBbox = useMapViewStore.getState().constraintBbox;
@@ -787,61 +801,52 @@ function useGeolocation() {
787
801
  useGeolocationStore.getState().setLocated(false);
788
802
  useGeolocationStore.getState().setTracking(false);
789
803
  }, [setHeading, setMarker, stopWatch]);
790
- const locate = useCallback(() => {
791
- showRationaleOnce();
792
- navigator.geolocation.getCurrentPosition(
793
- ({ coords }) => {
794
- const position = { lon: coords.longitude, lat: coords.latitude };
795
- trackingOutsideBounds.current = false;
796
- const bounded = resolvePosition(position);
797
- setMarker(position);
798
- useMapViewStore.getState().flyToPosition(bounded, LOCATE_ZOOM);
799
- useGeolocationStore.getState().setLocated(true);
800
- },
801
- (error) => {
802
- emit("showToast", { message: geolocationErrorMessage(error), severity: "error" });
803
- }
804
- );
805
- }, [emit, resolvePosition, setMarker, showRationaleOnce]);
806
- const handleTrackingPosition = useCallback(
804
+ const handlePositionUpdate = useCallback(
807
805
  ({ coords }) => {
808
806
  const position = { lon: coords.longitude, lat: coords.latitude };
809
807
  const bounded = resolvePosition(position);
810
808
  setMarker(position);
811
- const prevPosition = useGeolocationStore.getState().prevPosition;
812
- const moved = hasMovedEnough(prevPosition, position);
813
809
  const hasHeading = coords.heading !== null && !Number.isNaN(coords.heading);
814
810
  if (hasHeading) {
815
811
  setHeading(headingToRadians(coords.heading));
816
812
  }
817
- if (!moved) {
813
+ const firstFix = isFirstFix.current;
814
+ isFirstFix.current = false;
815
+ const tracking = useGeolocationStore.getState().isTracking;
816
+ if (!firstFix && !tracking) {
817
+ return;
818
+ }
819
+ const prevPosition = useGeolocationStore.getState().prevPosition;
820
+ if (!firstFix && !hasMovedEnough(prevPosition, position)) {
818
821
  return;
819
822
  }
820
823
  useMapViewStore.setState({ flyToPositionIntent: { position: bounded, zoom: LOCATE_ZOOM } });
821
824
  useGeolocationStore.getState().setPrevPosition(position);
825
+ if (tracking && hasHeading) {
826
+ useMapViewStore.setState({ rotation: headingToMapRotation(coords.heading) });
827
+ }
822
828
  },
823
829
  [resolvePosition, setHeading, setMarker]
824
830
  );
825
- const startTracking = useCallback(() => {
831
+ const locate = useCallback(() => {
826
832
  showRationaleOnce();
827
- const watchId = navigator.geolocation.watchPosition(handleTrackingPosition);
833
+ trackingOutsideBounds.current = false;
834
+ isFirstFix.current = true;
835
+ const watchId = navigator.geolocation.watchPosition(
836
+ handlePositionUpdate,
837
+ (error) => {
838
+ emit("showToast", { message: geolocationErrorMessage(error), severity: "error" });
839
+ },
840
+ POSITION_OPTIONS
841
+ );
828
842
  useGeolocationStore.getState().setWatchId(watchId);
829
- useNavigationHistoryStore.getState().setExternalControl(true);
830
- useGeolocationStore.getState().setTracking(true);
831
- }, [handleTrackingPosition, showRationaleOnce]);
832
- const stopTracking = useCallback(() => {
833
- stopWatch();
834
- setHeading(null);
835
- useNavigationHistoryStore.getState().setExternalControl(false);
836
- useGeolocationStore.getState().setTracking(false);
837
- }, [setHeading, stopWatch]);
843
+ useGeolocationStore.getState().setLocated(true);
844
+ }, [emit, handlePositionUpdate, showRationaleOnce]);
838
845
  const toggleTracking = useCallback(() => {
839
- if (isTracking) {
840
- stopTracking();
841
- return;
842
- }
843
- startTracking();
844
- }, [isTracking, startTracking, stopTracking]);
846
+ const tracking = !isTracking;
847
+ useNavigationHistoryStore.getState().setExternalControl(tracking);
848
+ useGeolocationStore.getState().setTracking(tracking);
849
+ }, [isTracking]);
845
850
  return {
846
851
  isLocated,
847
852
  isTracking,
@@ -854,6 +859,12 @@ function useGeolocation() {
854
859
  function LocationButtons(_props) {
855
860
  const t = useComponentTranslate(NAVIGATION_COMPONENT_ID);
856
861
  const { isLocated, isTracking, locate, toggleTracking, deactivate } = useGeolocation();
862
+ const settings = useComponentSettingsStore(
863
+ (s) => s.getComponentSettings(NAVIGATION_COMPONENT_ID)
864
+ );
865
+ if (settings?.positioning === false) {
866
+ return null;
867
+ }
857
868
  return /* @__PURE__ */ jsxs(ButtonGroup$1, { direction: "vertical", ariaLabel: t("locationControls"), children: [
858
869
  /* @__PURE__ */ jsx(
859
870
  MapButton,
@@ -862,8 +873,9 @@ function LocationButtons(_props) {
862
873
  hideLabel: true,
863
874
  icon: "my_location",
864
875
  tooltipContent: t("locationRationaleTooltip"),
865
- isActive: isLocated,
876
+ selected: isLocated,
866
877
  onClick: isLocated ? deactivate : locate,
878
+ "data-testid": "nav-locate",
867
879
  children: t("myLocation")
868
880
  }
869
881
  ),
@@ -873,8 +885,9 @@ function LocationButtons(_props) {
873
885
  size: "small",
874
886
  hideLabel: true,
875
887
  icon: "emergency_share",
876
- isActive: isTracking,
888
+ selected: isTracking,
877
889
  onClick: toggleTracking,
890
+ "data-testid": "nav-track",
878
891
  children: t("trackLocation")
879
892
  }
880
893
  )
@@ -886,6 +899,12 @@ function ZoomButtons(_props) {
886
899
  const zoom = useMapViewStore((s) => s.zoom);
887
900
  const setZoom = useMapViewStore((s) => s.setZoom);
888
901
  const zoomFloor = useZoomFloor();
902
+ const settings = useComponentSettingsStore(
903
+ (s) => s.getComponentSettings(NAVIGATION_COMPONENT_ID)
904
+ );
905
+ if (settings?.zoominout === false) {
906
+ return null;
907
+ }
889
908
  return /* @__PURE__ */ jsxs(ButtonGroup$1, { direction: "vertical", ariaLabel: t("zoomControls"), children: [
890
909
  /* @__PURE__ */ jsx(
891
910
  MapButton,
@@ -917,8 +936,8 @@ function ZoomButtons(_props) {
917
936
  const NavigationComponent = {
918
937
  id: NAVIGATION_COMPONENT_ID,
919
938
  messages: {
920
- et: etMessages$1,
921
- en: enMessages$1
939
+ et: etMessages$2,
940
+ en: enMessages$2
922
941
  },
923
942
  ui: {
924
943
  [SLOTS.NAVIGATION_ZOOM]: { Component: ZoomButtons },
@@ -955,6 +974,45 @@ const NotificationComponent = {
955
974
  }
956
975
  };
957
976
 
977
+ const search$1 = "Search";
978
+ const enMessages$1 = {
979
+ search: search$1,
980
+ };
981
+
982
+ const search = "Otsi";
983
+ const etMessages$1 = {
984
+ search,
985
+ };
986
+
987
+ function SearchView({ layout }) {
988
+ const t = useComponentTranslate(SEARCH_COMPONENT_ID);
989
+ const isDesktop = layout === "desktop";
990
+ return /* @__PURE__ */ jsxs(InputGroup, { id: "mocksearchgroup", label: "", children: [
991
+ /* @__PURE__ */ jsx(Input, { children: /* @__PURE__ */ jsx("div", { style: { maxWidth: 372, minWidth: 150 }, children: /* @__PURE__ */ jsx(Search, { id: "mocksearch", placeholder: t("search") }) }) }),
992
+ /* @__PURE__ */ jsx(Suffix, { children: /* @__PURE__ */ jsxs(Text, { color: "brand", children: [
993
+ /* @__PURE__ */ jsx(Icon, { name: "directions", display: "inline" }),
994
+ isDesktop && /* @__PURE__ */ jsx("span", { children: "Juhised" })
995
+ ] }) }),
996
+ /* @__PURE__ */ jsx(Suffix, { children: /* @__PURE__ */ jsxs(Text, { children: [
997
+ isDesktop && /* @__PURE__ */ jsx("span", { children: "Täpsem otsing " }),
998
+ /* @__PURE__ */ jsx(Icon, { name: "keyboard_arrow_down", display: "inline" })
999
+ ] }) })
1000
+ ] });
1001
+ }
1002
+
1003
+ const SearchComponent = {
1004
+ id: SEARCH_COMPONENT_ID,
1005
+ messages: {
1006
+ et: etMessages$1,
1007
+ en: enMessages$1
1008
+ },
1009
+ contributions: [{ target: SLOTS.SEARCH, Component: SearchView }],
1010
+ bookmark: {
1011
+ serialize: () => ({ render: true }),
1012
+ deserialize: () => void 0
1013
+ }
1014
+ };
1015
+
958
1016
  const label$1 = "Theme map";
959
1017
  const readMore$1 = "Read more";
960
1018
  const readLess$1 = "Close";
@@ -983,17 +1041,91 @@ const etMessages = {
983
1041
  back,
984
1042
  };
985
1043
 
986
- const menuPortal = "_menuPortal_131uw_1";
987
- const trigger = "_trigger_131uw_5";
988
- const picker = "_picker_131uw_9";
989
- const pickerList = "_pickerList_131uw_16";
990
- const pickerSearch = "_pickerSearch_131uw_22";
991
- const pickerEmpty = "_pickerEmpty_131uw_26";
992
- const row = "_row_131uw_30";
993
- const rowActive = "_rowActive_131uw_35";
994
- const rowOpenNotActive = "_rowOpenNotActive_131uw_39";
995
- const rowDescription = "_rowDescription_131uw_57";
996
- const pickerFooter = "_pickerFooter_131uw_61";
1044
+ const TOKEN_PATTERN = /\$([a-z]+)\$/gi;
1045
+ const TOKEN_RESOLVERS = {
1046
+ bbox: (bbox) => bbox.map(Math.round).join(",")
1047
+ };
1048
+ function resolveExternalAppLink(link, bbox) {
1049
+ return link.replace(TOKEN_PATTERN, (match, token) => {
1050
+ const resolve = TOKEN_RESOLVERS[token.toLowerCase()];
1051
+ if (!resolve) {
1052
+ return match;
1053
+ }
1054
+ return resolve(bbox);
1055
+ });
1056
+ }
1057
+ function localizedName(app, locale) {
1058
+ return app[`name_${locale}`] || app.name_et || app.name_en;
1059
+ }
1060
+ function useExternalApps() {
1061
+ const locale = useI18nStore((s) => s.locale);
1062
+ const settings = useComponentSettingsStore(
1063
+ (s) => s.getComponentSettings(TOPICLIST_COMPONENT_ID)
1064
+ );
1065
+ const apps = settings?.externalApps;
1066
+ return useMemo(() => {
1067
+ if (!apps?.length) {
1068
+ return [];
1069
+ }
1070
+ return apps.filter((app) => isSafeExternalUrl(app.link)).map((app) => ({
1071
+ link: app.link,
1072
+ name: localizedName(app, locale),
1073
+ target: app.target
1074
+ }));
1075
+ }, [apps, locale]);
1076
+ }
1077
+ function openExternalAppAtCurrentView(app) {
1078
+ const { bbox } = useMapViewStore.getState();
1079
+ openExternalUrl(resolveExternalAppLink(app.link, bbox), app.target);
1080
+ }
1081
+
1082
+ const EXTERNAL_ENTRY_PREFIX = "external:";
1083
+ function mergeTopicEntries(topics, apps, locale) {
1084
+ const entries = [
1085
+ ...topics.map((topic) => ({
1086
+ kind: "topic",
1087
+ id: topic.id,
1088
+ label: topic.title,
1089
+ topic
1090
+ })),
1091
+ ...apps.map((app, index) => ({
1092
+ kind: "externalApp",
1093
+ id: `${EXTERNAL_ENTRY_PREFIX}${index}:${app.link}`,
1094
+ label: app.name,
1095
+ app
1096
+ }))
1097
+ ];
1098
+ const collator = new Intl.Collator(locale);
1099
+ return entries.sort((a, b) => collator.compare(a.label, b.label));
1100
+ }
1101
+ function filterTopicEntries(entries, query) {
1102
+ const needle = query.trim().toLowerCase();
1103
+ if (!needle) {
1104
+ return [...entries];
1105
+ }
1106
+ return entries.filter((entry) => entry.label.toLowerCase().includes(needle));
1107
+ }
1108
+ function useTopicEntries(query) {
1109
+ const topics = useTopicStore((s) => s.topics);
1110
+ const apps = useExternalApps();
1111
+ const locale = useI18nStore((s) => s.locale);
1112
+ return useMemo(
1113
+ () => filterTopicEntries(mergeTopicEntries(topics, apps, locale), query),
1114
+ [topics, apps, locale, query]
1115
+ );
1116
+ }
1117
+
1118
+ const menuPortal = "_menuPortal_4myfw_1";
1119
+ const trigger = "_trigger_4myfw_5";
1120
+ const picker = "_picker_4myfw_9";
1121
+ const pickerList = "_pickerList_4myfw_16";
1122
+ const pickerSearch = "_pickerSearch_4myfw_22";
1123
+ const pickerEmpty = "_pickerEmpty_4myfw_26";
1124
+ const row = "_row_4myfw_30";
1125
+ const rowActive = "_rowActive_4myfw_35";
1126
+ const rowOpenNotActive = "_rowOpenNotActive_4myfw_39";
1127
+ const rowDescription = "_rowDescription_4myfw_64";
1128
+ const pickerFooter = "_pickerFooter_4myfw_68";
997
1129
  const styles = {
998
1130
  menuPortal: menuPortal,
999
1131
  trigger: trigger,
@@ -1029,54 +1161,63 @@ function rowClassName(isActive, isOpen) {
1029
1161
  }
1030
1162
  return styles.row;
1031
1163
  }
1032
- function TopicRow({ topic, isActive, onSelect }) {
1033
- const [isOpen, setIsOpen] = useState(false);
1164
+ function TopicRow({ entry, activeTopicId, isOpen, onSelect, onToggle }) {
1034
1165
  const t = useComponentTranslate(TOPICLIST_COMPONENT_ID);
1166
+ const isActive = entry.kind === "topic" && entry.topic.id === activeTopicId;
1167
+ const description = entry.kind === "topic" ? entry.topic.description : void 0;
1035
1168
  const background = rowBackground(isActive, isOpen);
1036
1169
  const textColor = isActive ? "white" : isOpen ? "info" : "primary";
1037
- const title = /* @__PURE__ */ jsx(CardButton, { onClick: () => onSelect(topic.id), children: /* @__PURE__ */ jsx(Card, { borderless: true, background, children: /* @__PURE__ */ jsx(Card.Content, { padding: { vertical: 0.75, horizontal: 1 }, background, children: /* @__PURE__ */ jsx(Text, { color: textColor, children: topic.title }) }) }) });
1038
- if (!topic.description) {
1039
- return /* @__PURE__ */ jsx("div", { className: rowClassName(isActive, false), "data-topic-id": topic.id, children: title });
1170
+ const card = /* @__PURE__ */ jsx(Card, { borderless: true, background, children: /* @__PURE__ */ jsx(Card.Content, { padding: { vertical: 0.75, horizontal: 1 }, background, children: /* @__PURE__ */ jsx(Text, { color: textColor, children: entry.label }) }) });
1171
+ const title = entry.kind === "externalApp" ? /* @__PURE__ */ jsx(
1172
+ CardButton,
1173
+ {
1174
+ as: "a",
1175
+ href: entry.app.link,
1176
+ target: entry.app.target,
1177
+ rel: EXTERNAL_LINK_REL,
1178
+ onClick: (event) => {
1179
+ event.preventDefault();
1180
+ openExternalAppAtCurrentView(entry.app);
1181
+ },
1182
+ children: card
1183
+ }
1184
+ ) : /* @__PURE__ */ jsx(CardButton, { onClick: () => onSelect(entry.topic.id), children: card });
1185
+ if (!description) {
1186
+ return /* @__PURE__ */ jsx("div", { className: rowClassName(isActive, false), "data-topic-id": entry.id, children: title });
1040
1187
  }
1041
- return /* @__PURE__ */ jsx("div", { className: rowClassName(isActive, isOpen), "data-topic-id": topic.id, children: /* @__PURE__ */ jsx(
1188
+ return /* @__PURE__ */ jsx("div", { className: rowClassName(isActive, isOpen), "data-topic-id": entry.id, children: /* @__PURE__ */ jsx(
1042
1189
  Collapse,
1043
1190
  {
1044
- id: `topic-description-${topic.id}`,
1191
+ id: `topic-description-${entry.id}`,
1045
1192
  title,
1046
1193
  open: isOpen,
1047
- onToggle: setIsOpen,
1194
+ onToggle,
1048
1195
  openText: t("readMore"),
1049
1196
  closeText: t("readLess"),
1050
1197
  inverted: isActive,
1051
1198
  underline: false,
1052
1199
  size: "small",
1053
- children: /* @__PURE__ */ jsx("div", { className: styles.rowDescription, children: /* @__PURE__ */ jsx(Text, { color: textColor, modifiers: "small", children: topic.description }) })
1200
+ children: /* @__PURE__ */ jsx("div", { className: styles.rowDescription, children: /* @__PURE__ */ jsx(Text, { color: textColor, modifiers: "small", children: description }) })
1054
1201
  }
1055
1202
  ) });
1056
1203
  }
1057
1204
 
1058
- function filterTopics(topics, query) {
1059
- const needle = query.trim().toLowerCase();
1060
- if (!needle) {
1061
- return [...topics];
1062
- }
1063
- return topics.filter((topic) => topic.title.toLowerCase().includes(needle));
1064
- }
1065
- function useFilteredTopics(query) {
1066
- const topics = useTopicStore((s) => s.topics);
1067
- return useMemo(() => filterTopics(topics, query), [topics, query]);
1068
- }
1069
-
1070
1205
  function TopicPicker() {
1071
1206
  const [query, setQuery] = useState("");
1207
+ const [openEntryId, setOpenEntryId] = useState(null);
1072
1208
  const activeTopicId = useTopicStore((s) => s.activeTopicId);
1073
1209
  const setActiveTopicId = useTopicStore((s) => s.setActiveTopicId);
1074
1210
  const setTopicPickerOpen = useUiStore((s) => s.setTopicPickerOpen);
1211
+ const setLayersSheetOpen = useUiStore((s) => s.setLayersSheetOpen);
1075
1212
  const t = useComponentTranslate(TOPICLIST_COMPONENT_ID);
1076
- const topics = useFilteredTopics(query);
1213
+ const entries = useTopicEntries(query);
1077
1214
  function handleSelect(topicId) {
1078
1215
  setActiveTopicId(topicId);
1079
- setTopicPickerOpen(false);
1216
+ setOpenEntryId(null);
1217
+ setLayersSheetOpen(false);
1218
+ }
1219
+ function handleToggle(entryId, open) {
1220
+ setOpenEntryId(open ? entryId : null);
1080
1221
  }
1081
1222
  return /* @__PURE__ */ jsxs("div", { className: styles.picker, "data-testid": "topic-picker", children: [
1082
1223
  /* @__PURE__ */ jsx("div", { className: styles.pickerSearch, children: /* @__PURE__ */ jsx(
@@ -1093,15 +1234,17 @@ function TopicPicker() {
1093
1234
  }
1094
1235
  ) }),
1095
1236
  /* @__PURE__ */ jsxs("div", { className: styles.pickerList, children: [
1096
- topics.length === 0 && /* @__PURE__ */ jsx(Text, { color: "secondary", className: styles.pickerEmpty, children: t("search.empty") }),
1097
- topics.map((topic) => /* @__PURE__ */ jsx(
1237
+ entries.length === 0 && /* @__PURE__ */ jsx(Text, { color: "secondary", className: styles.pickerEmpty, children: t("search.empty") }),
1238
+ entries.map((entry) => /* @__PURE__ */ jsx(
1098
1239
  TopicRow,
1099
1240
  {
1100
- topic,
1101
- isActive: topic.id === activeTopicId,
1102
- onSelect: handleSelect
1241
+ entry,
1242
+ activeTopicId,
1243
+ isOpen: entry.id === openEntryId,
1244
+ onSelect: handleSelect,
1245
+ onToggle: (open) => handleToggle(entry.id, open)
1103
1246
  },
1104
- topic.id
1247
+ entry.id
1105
1248
  ))
1106
1249
  ] }),
1107
1250
  /* @__PURE__ */ jsx("div", { className: styles.pickerFooter, children: /* @__PURE__ */ jsx(Button, { visualType: "link", iconLeft: "arrow_back", onClick: () => setTopicPickerOpen(false), children: t("back") }) })
@@ -1109,17 +1252,13 @@ function TopicPicker() {
1109
1252
  }
1110
1253
 
1111
1254
  function TopicSelect() {
1112
- const topics = useTopicStore((s) => s.topics);
1113
1255
  const activeTopicId = useTopicStore((s) => s.activeTopicId);
1114
1256
  const setActiveTopicId = useTopicStore((s) => s.setActiveTopicId);
1115
1257
  const t = useComponentTranslate(TOPICLIST_COMPONENT_ID);
1258
+ const entries = useTopicEntries("");
1116
1259
  const options = useMemo(
1117
- () => topics.map((item) => ({
1118
- value: item.id,
1119
- label: item.title,
1120
- customData: item
1121
- })),
1122
- [topics]
1260
+ () => entries.map((entry) => ({ value: entry.id, label: entry.label, customData: entry })),
1261
+ [entries]
1123
1262
  );
1124
1263
  const selectedOption = useMemo(
1125
1264
  () => options.find((option) => option.value === activeTopicId) ?? null,
@@ -1129,8 +1268,15 @@ function TopicSelect() {
1129
1268
  if (!selected) {
1130
1269
  return;
1131
1270
  }
1132
- const option = selected;
1133
- setActiveTopicId(option.value);
1271
+ const { customData } = selected;
1272
+ if (!customData) {
1273
+ return;
1274
+ }
1275
+ if (customData.kind === "externalApp") {
1276
+ openExternalAppAtCurrentView(customData.app);
1277
+ return;
1278
+ }
1279
+ setActiveTopicId(customData.topic.id);
1134
1280
  }
1135
1281
  return /* @__PURE__ */ jsx(Card, { borderless: true, children: /* @__PURE__ */ jsx(Card.Content, { padding: 0.5, children: /* @__PURE__ */ jsx(Row, { gutterY: 2, children: /* @__PURE__ */ jsxs(Col, { children: [
1136
1282
  /* @__PURE__ */ jsx(Text, { color: "secondary", children: t("label") }),
@@ -1186,11 +1332,12 @@ const XGIS_COMPONENTS = [
1186
1332
  SidePanelComponent,
1187
1333
  LayerPanelComponent,
1188
1334
  MapSwitchComponent,
1335
+ SearchComponent,
1189
1336
  NavigationComponent,
1190
1337
  TopicListComponent,
1191
1338
  BasemapComponent,
1192
1339
  NotificationComponent
1193
1340
  ];
1194
1341
 
1195
- export { BasemapComponent, LayerPanelComponent, MapSwitchComponent, NavigationComponent, NotificationComponent, SIDE_PANEL_SLOTS, SidePanelComponent, TopicListComponent, XGIS_COMPONENTS };
1342
+ export { BasemapComponent, LayerPanelComponent, MapSwitchComponent, NavigationComponent, NotificationComponent, SIDE_PANEL_SLOTS, SearchComponent, SidePanelComponent, TopicListComponent, XGIS_COMPONENTS };
1196
1343
  //# sourceMappingURL=index.js.map