@yext/visual-editor 1.4.10 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/dist/SectionLibraryVisualEditorProvider-67ng4X9e.js +108670 -0
  2. package/dist/SectionLibraryVisualEditorProvider.css +1 -0
  3. package/dist/cli/assets/directory-locator-source/components/contentBlocks/Address.tsx +251 -0
  4. package/dist/cli/assets/directory-locator-source/components/contentBlocks/HeadingText.tsx +147 -0
  5. package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursStatus.tsx +157 -0
  6. package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursTable.tsx +164 -0
  7. package/dist/cli/assets/directory-locator-source/components/contentBlocks/MapboxStaticMap.tsx +205 -0
  8. package/dist/cli/assets/directory-locator-source/components/contentBlocks/Phone.tsx +155 -0
  9. package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/EmptyImageState.tsx +168 -0
  10. package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/Image.tsx +275 -0
  11. package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/styling.ts +66 -0
  12. package/dist/cli/assets/directory-locator-source/components/contentBlocks/index.ts +13 -0
  13. package/dist/cli/assets/directory-locator-source/components/sections/Breadcrumbs.tsx +298 -0
  14. package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.test.tsx +872 -0
  15. package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.tsx +260 -0
  16. package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryCard.tsx +507 -0
  17. package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryWrapper.tsx +491 -0
  18. package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.test.tsx +226 -0
  19. package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.tsx +98 -0
  20. package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +147 -0
  21. package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +691 -0
  22. package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1551 -0
  23. package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +541 -0
  24. package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +43 -0
  25. package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +1594 -0
  26. package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +1157 -0
  27. package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +304 -0
  28. package/dist/cli/assets/directory-locator-source/components/sections/locator/MapPinIcon.tsx +160 -0
  29. package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +267 -0
  30. package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +245 -0
  31. package/dist/cli/yextve.js +16888 -0
  32. package/dist/index.d.ts +556 -6260
  33. package/dist/locales/page/cs/visual-editor.json +85 -0
  34. package/dist/locales/page/da/visual-editor.json +73 -0
  35. package/dist/locales/page/de/visual-editor.json +73 -0
  36. package/dist/locales/page/en/visual-editor.json +73 -0
  37. package/dist/locales/page/en-GB/visual-editor.json +73 -0
  38. package/dist/locales/page/es/visual-editor.json +79 -0
  39. package/dist/locales/page/et/visual-editor.json +73 -0
  40. package/dist/locales/page/fi/visual-editor.json +73 -0
  41. package/dist/locales/page/fr/visual-editor.json +79 -0
  42. package/dist/locales/page/hr/visual-editor.json +79 -0
  43. package/dist/locales/page/hu/visual-editor.json +73 -0
  44. package/dist/locales/page/it/visual-editor.json +79 -0
  45. package/dist/locales/page/ja/visual-editor.json +73 -0
  46. package/dist/locales/page/lt/visual-editor.json +85 -0
  47. package/dist/locales/page/lv/visual-editor.json +77 -0
  48. package/dist/locales/page/nb/visual-editor.json +73 -0
  49. package/dist/locales/page/nl/visual-editor.json +73 -0
  50. package/dist/locales/page/pl/visual-editor.json +85 -0
  51. package/dist/locales/page/pt/visual-editor.json +79 -0
  52. package/dist/locales/page/ro/visual-editor.json +79 -0
  53. package/dist/locales/page/sk/visual-editor.json +85 -0
  54. package/dist/locales/page/sv/visual-editor.json +73 -0
  55. package/dist/locales/page/tr/visual-editor.json +73 -0
  56. package/dist/locales/page/zh/visual-editor.json +73 -0
  57. package/dist/locales/page/zh-TW/visual-editor.json +73 -0
  58. package/dist/locales/platform/cs/visual-editor.json +531 -0
  59. package/dist/locales/platform/da/visual-editor.json +519 -0
  60. package/dist/locales/platform/de/visual-editor.json +519 -0
  61. package/dist/locales/platform/en/visual-editor.json +519 -0
  62. package/dist/locales/platform/en-GB/visual-editor.json +519 -0
  63. package/dist/locales/platform/es/visual-editor.json +525 -0
  64. package/dist/locales/platform/et/visual-editor.json +519 -0
  65. package/dist/locales/platform/fi/visual-editor.json +519 -0
  66. package/dist/locales/platform/fr/visual-editor.json +525 -0
  67. package/dist/locales/platform/hr/visual-editor.json +525 -0
  68. package/dist/locales/platform/hu/visual-editor.json +519 -0
  69. package/dist/locales/platform/it/visual-editor.json +525 -0
  70. package/dist/locales/platform/ja/visual-editor.json +519 -0
  71. package/dist/locales/platform/lt/visual-editor.json +531 -0
  72. package/dist/locales/platform/lv/visual-editor.json +523 -0
  73. package/dist/locales/platform/nb/visual-editor.json +519 -0
  74. package/dist/locales/platform/nl/visual-editor.json +519 -0
  75. package/dist/locales/platform/pl/visual-editor.json +531 -0
  76. package/dist/locales/platform/pt/visual-editor.json +525 -0
  77. package/dist/locales/platform/ro/visual-editor.json +525 -0
  78. package/dist/locales/platform/sk/visual-editor.json +531 -0
  79. package/dist/locales/platform/sv/visual-editor.json +519 -0
  80. package/dist/locales/platform/tr/visual-editor.json +519 -0
  81. package/dist/locales/platform/zh/visual-editor.json +519 -0
  82. package/dist/locales/platform/zh-TW/visual-editor.json +519 -0
  83. package/dist/locatorEntityTypes-s4dmT9l5.d.ts +1850 -0
  84. package/dist/plugin/internal/sectionLibraryValidation/builtInTranslationResources.d.ts +3 -0
  85. package/dist/plugin/internal/sectionLibraryValidation/stages/api/api.d.ts +7 -0
  86. package/dist/plugin/internal/sectionLibraryValidation/stages/api/libraryMetadata.d.ts +7 -0
  87. package/dist/plugin/internal/sectionLibraryValidation/stages/code/importRules.d.ts +13 -0
  88. package/dist/plugin/internal/sectionLibraryValidation/stages/code/validateCode.d.ts +10 -0
  89. package/dist/plugin/internal/sectionLibraryValidation/stages/code/xssRules.d.ts +7 -0
  90. package/dist/plugin/internal/sectionLibraryValidation/stages/structure/structure.d.ts +7 -0
  91. package/dist/plugin/internal/sectionLibraryValidation/types.d.ts +48 -0
  92. package/dist/plugin/internal/sectionLibraryValidation/validateSectionLibrary.d.ts +8 -0
  93. package/dist/plugin/internal/sectionLibraryValidation/validationError.d.ts +6 -0
  94. package/dist/plugin/plugin.js +2233 -5786
  95. package/dist/plugin/types/entityFields.d.ts +21 -0
  96. package/dist/plugin/types/images.d.ts +62 -0
  97. package/dist/plugin/types/sectionLibrary.d.ts +94 -0
  98. package/dist/plugin/types/types.d.ts +204 -0
  99. package/dist/plugin/types/videos.d.ts +24 -0
  100. package/dist/plugin/utils/i18n/locales.d.ts +5 -0
  101. package/dist/plugin/utils/i18n/translationResources.d.ts +41 -0
  102. package/dist/plugin/utils/normalizeLocale.d.ts +8 -0
  103. package/dist/plugin/utils/plainText.d.ts +6 -0
  104. package/dist/plugin/vite-plugin/index.d.ts +2 -0
  105. package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +18 -0
  106. package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
  107. package/dist/plugin/vite-plugin/local-editor/data.d.ts +10 -0
  108. package/dist/plugin/vite-plugin/local-editor/entityFields.d.ts +13 -0
  109. package/dist/plugin/vite-plugin/local-editor/fixtureData.d.ts +12 -0
  110. package/dist/plugin/vite-plugin/local-editor/generatedFiles.d.ts +34 -0
  111. package/dist/plugin/vite-plugin/local-editor/server.d.ts +18 -0
  112. package/dist/plugin/vite-plugin/local-editor/types.d.ts +109 -0
  113. package/dist/plugin/vite-plugin/local-editor/utils.d.ts +16 -0
  114. package/dist/plugin/vite-plugin/plugin.d.ts +8 -0
  115. package/dist/plugin/vite-plugin/section-library/migrationRegistry.d.ts +6 -0
  116. package/dist/plugin/vite-plugin/section-library/sectionFrontmatter.d.ts +3 -0
  117. package/dist/plugin/vite-plugin/section-library/sectionLibraryGenerator.d.ts +21 -0
  118. package/dist/plugin/vite-plugin/section-library/sharedComponentRegistry.d.ts +16 -0
  119. package/dist/section-library-support.js +158 -0
  120. package/dist/sectionLibrarySupport.d.ts +282 -0
  121. package/dist/style.css +1 -1
  122. package/dist/visual-editor-9bLkRo2X.js +702 -0
  123. package/dist/visual-editor-B5f3AZF6.js +706 -0
  124. package/dist/visual-editor-BGZbJkMp.js +694 -0
  125. package/dist/visual-editor-BPVqHHz5.js +706 -0
  126. package/dist/visual-editor-BPvDMSb8.js +706 -0
  127. package/dist/visual-editor-BTT9n9b6.js +718 -0
  128. package/dist/visual-editor-BXSlgf31.js +694 -0
  129. package/dist/visual-editor-BXYlpe7B.js +145 -0
  130. package/dist/visual-editor-Bez9GftS.js +694 -0
  131. package/dist/visual-editor-Bk5QJccl.js +718 -0
  132. package/dist/visual-editor-BqtG2m0y.js +694 -0
  133. package/dist/visual-editor-Bxy81Ezy.js +145 -0
  134. package/dist/visual-editor-C00efXqJ.js +706 -0
  135. package/dist/visual-editor-C0vq2BRM.js +145 -0
  136. package/dist/visual-editor-CCgmYV5S.js +169 -0
  137. package/dist/visual-editor-CERViyTJ.js +145 -0
  138. package/dist/visual-editor-CZdmgAn0.js +706 -0
  139. package/dist/visual-editor-CcOCcCUQ.js +694 -0
  140. package/dist/visual-editor-CjORnP1D.js +169 -0
  141. package/dist/visual-editor-CmomGJB8.js +157 -0
  142. package/dist/visual-editor-Cymg8ID2.js +169 -0
  143. package/dist/visual-editor-D2Hk1nhM.js +145 -0
  144. package/dist/visual-editor-D2_8u6ZI.js +694 -0
  145. package/dist/visual-editor-D4vaqoBN.js +694 -0
  146. package/dist/visual-editor-D6n8EP_O.js +694 -0
  147. package/dist/visual-editor-D8MRFn5x.js +157 -0
  148. package/dist/visual-editor-DKG_E7X4.js +694 -0
  149. package/dist/visual-editor-DOXtCqRv.js +145 -0
  150. package/dist/visual-editor-DQEd3xwY.js +145 -0
  151. package/dist/visual-editor-DQq0_rUn.js +706 -0
  152. package/dist/visual-editor-DRXezaoB.js +694 -0
  153. package/dist/visual-editor-DUngIOnE.js +157 -0
  154. package/dist/visual-editor-DbgFzBNV.js +718 -0
  155. package/dist/visual-editor-DeZVZYfd.js +169 -0
  156. package/dist/visual-editor-DfJMZpiP.js +145 -0
  157. package/dist/visual-editor-DgAsQK9D.js +145 -0
  158. package/dist/visual-editor-Dhi__-7_.js +145 -0
  159. package/dist/visual-editor-DiLdoISr.js +718 -0
  160. package/dist/visual-editor-DjdqpJU-.js +145 -0
  161. package/dist/visual-editor-DnTPMRV4.js +694 -0
  162. package/dist/visual-editor-DvuH3jyL.js +157 -0
  163. package/dist/visual-editor-E0hASBXn.js +694 -0
  164. package/dist/visual-editor-TfVDfO5_.js +145 -0
  165. package/dist/visual-editor-W1OHU94y.js +694 -0
  166. package/dist/visual-editor-W_ZDmMFn.js +145 -0
  167. package/dist/visual-editor-b7ALusk8.js +145 -0
  168. package/dist/visual-editor-bauJ9beX.js +694 -0
  169. package/dist/visual-editor-erGXf3kS.js +157 -0
  170. package/dist/visual-editor-xnDHZFuO.js +153 -0
  171. package/dist/visual-editor-yiWZqIH0.js +157 -0
  172. package/dist/visual-editor.css +1 -0
  173. package/dist/visual-editor.js +15059 -136530
  174. package/package.json +45 -24
  175. package/dist/editor.css +0 -1
  176. package/dist/visual-editor--AAsqhQc.js +0 -231
  177. package/dist/visual-editor-32on_5DY.js +0 -243
  178. package/dist/visual-editor-49W0_Daf.js +0 -1002
  179. package/dist/visual-editor-8Lal-QZf.js +0 -219
  180. package/dist/visual-editor-B02CmTCX.js +0 -1002
  181. package/dist/visual-editor-BB0a_4dr.js +0 -243
  182. package/dist/visual-editor-BQa0UK-c.js +0 -1002
  183. package/dist/visual-editor-BRG83zQG.js +0 -1010
  184. package/dist/visual-editor-BVBPuEsB.js +0 -219
  185. package/dist/visual-editor-BcCzbooi.js +0 -243
  186. package/dist/visual-editor-BiemHMaD.js +0 -1014
  187. package/dist/visual-editor-Bkj-BZ8U.js +0 -1002
  188. package/dist/visual-editor-Bm_9l-r1.js +0 -1014
  189. package/dist/visual-editor-BsyZIlAm.js +0 -1002
  190. package/dist/visual-editor-BuUXmEr4.js +0 -1002
  191. package/dist/visual-editor-BxUYaP8B.js +0 -219
  192. package/dist/visual-editor-By1sH42E.js +0 -219
  193. package/dist/visual-editor-By9M5eN4.js +0 -231
  194. package/dist/visual-editor-C-MDqVaH.js +0 -219
  195. package/dist/visual-editor-C37Hro7w.js +0 -1026
  196. package/dist/visual-editor-C9I9pWeQ.js +0 -1014
  197. package/dist/visual-editor-CQOcLK3A.js +0 -1002
  198. package/dist/visual-editor-CSIc6-rm.js +0 -219
  199. package/dist/visual-editor-CaTT6blQ.js +0 -227
  200. package/dist/visual-editor-Cw95D-E7.js +0 -1014
  201. package/dist/visual-editor-CwW9rVaZ.js +0 -1002
  202. package/dist/visual-editor-CzC6S5LB.js +0 -1014
  203. package/dist/visual-editor-DAuNRkq8.js +0 -1026
  204. package/dist/visual-editor-DE8qwWp0.js +0 -1002
  205. package/dist/visual-editor-DEmVxnyc.js +0 -1014
  206. package/dist/visual-editor-DFQml8X8.js +0 -219
  207. package/dist/visual-editor-DHbDTZwW.js +0 -231
  208. package/dist/visual-editor-DR14jsjF.js +0 -219
  209. package/dist/visual-editor-DiO1-u9c.js +0 -243
  210. package/dist/visual-editor-Dk9cgdJp.js +0 -231
  211. package/dist/visual-editor-DlohF7nV.js +0 -219
  212. package/dist/visual-editor-DrbkrTPj.js +0 -231
  213. package/dist/visual-editor-Dwy8xGNv.js +0 -1002
  214. package/dist/visual-editor-Dz0yJDfm.js +0 -1026
  215. package/dist/visual-editor-InSI7qrX.js +0 -1026
  216. package/dist/visual-editor-KBcW6ZCw.js +0 -1002
  217. package/dist/visual-editor-Kgxgyjx4.js +0 -231
  218. package/dist/visual-editor-S4ACDl-Z.js +0 -1002
  219. package/dist/visual-editor-VLIdGBGJ.js +0 -1002
  220. package/dist/visual-editor-d-hTp0p2.js +0 -219
  221. package/dist/visual-editor-hqdcvtls.js +0 -219
  222. package/dist/visual-editor-llBar-sw.js +0 -1002
  223. package/dist/visual-editor-pb5PwMmE.js +0 -219
  224. package/dist/visual-editor-wSWVK8SW.js +0 -219
  225. package/dist/visual-editor-z-YqfQf7.js +0 -219
@@ -0,0 +1,304 @@
1
+ import {
2
+ Coordinate,
3
+ MapboxMap,
4
+ MapMarkerOptions,
5
+ OnDragHandler,
6
+ PinComponentProps,
7
+ } from "@yext/search-ui-react";
8
+ import { Result } from "@yext/search-headless-react";
9
+ import React from "react";
10
+ import { useTranslation } from "react-i18next";
11
+ import { ImageField } from "../../../fields/ImageField.tsx";
12
+ import { useDocument } from "../../../hooks/useDocument.tsx";
13
+ import { msg } from "../../../utils/i18n/platform.ts";
14
+ import {
15
+ backgroundColors,
16
+ ThemeColor,
17
+ } from "../../../utils/themeConfigOptions.ts";
18
+ import { StreamDocument } from "../../../utils/types/StreamDocument.ts";
19
+ import { Body } from "../../atoms/body.tsx";
20
+ import { MapPinIcon } from "./MapPinIcon.tsx";
21
+ import { isVisualEditorTestEnv } from "../../testing/utils.ts";
22
+ import { Location } from "./LocatorResultCard.tsx";
23
+
24
+ export const DEFAULT_MAP_CENTER: Coordinate = {
25
+ latitude: 40.741611,
26
+ longitude: -74.005371,
27
+ }; // New York City
28
+ export const DEFAULT_RADIUS = 25;
29
+ export const DEFAULT_PIN_ICON_WIDTH = 14;
30
+ export const DEFAULT_LOCATION_STYLE = {
31
+ pinIcon: { type: "none" },
32
+ pinColor: backgroundColors.background6.value,
33
+ };
34
+ export const MAX_PIN_ICON_WIDTH = 27;
35
+ const PIN_ICON_MAX_FILE_SIZE_BYTES = 128 * 1024;
36
+
37
+ export type LocationStyleConfig = Record<
38
+ string,
39
+ {
40
+ color?: ThemeColor;
41
+ icon?: string;
42
+ customImage?: {
43
+ url: string;
44
+ width?: number;
45
+ aspectRatio?: number;
46
+ };
47
+ }
48
+ >;
49
+
50
+ export const LOCATOR_PIN_ICON_FIELD: ImageField = {
51
+ type: "image",
52
+ label: msg("fields.icon", "Icon"),
53
+ hideAltTextField: true,
54
+ maxFileSizeBytes: PIN_ICON_MAX_FILE_SIZE_BYTES,
55
+ };
56
+
57
+ export const getConfiguredMapCenterOrDefault = (mapStartingLocation?: {
58
+ latitude: string;
59
+ longitude: string;
60
+ }): Coordinate => {
61
+ if (mapStartingLocation?.latitude && mapStartingLocation.longitude) {
62
+ try {
63
+ return parseMapStartingLocation(mapStartingLocation);
64
+ } catch (e) {
65
+ console.error(e);
66
+ }
67
+ }
68
+
69
+ return DEFAULT_MAP_CENTER;
70
+ };
71
+
72
+ const makiIconModules = import.meta.glob(
73
+ "../../../node_modules/@mapbox/maki/icons/*.svg",
74
+ {
75
+ eager: true,
76
+ import: "default",
77
+ }
78
+ ) as Record<string, string>;
79
+
80
+ const makiIconEntries = Object.entries(makiIconModules).map(([path, icon]) => {
81
+ const name = path.split("/").pop()?.replace(".svg", "") || path;
82
+ return [name, icon] as const;
83
+ });
84
+
85
+ export const makiIconMap: Record<string, string> =
86
+ Object.fromEntries(makiIconEntries);
87
+
88
+ const formatMakiIconLabel = (name: string) =>
89
+ name.replace(/[-_]/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
90
+
91
+ export const makiIconOptions = makiIconEntries.map(([name, icon]) => ({
92
+ label: formatMakiIconLabel(name),
93
+ value: name,
94
+ icon,
95
+ }));
96
+
97
+ export const DEFAULT_MAKI_ICON_NAME = makiIconOptions[0]?.value;
98
+
99
+ export const LoadingMapPlaceholder = () => {
100
+ const { t } = useTranslation();
101
+
102
+ return (
103
+ <div className="flex items-center justify-center w-full h-full">
104
+ <div className="border border-gray-300 rounded-lg p-6 bg-white shadow-md">
105
+ <Body className="text-gray-700" variant="lg">
106
+ {t("loadingMap", "Loading Map...")}
107
+ </Body>
108
+ </div>
109
+ </div>
110
+ );
111
+ };
112
+
113
+ const LocatorTestMap = () => {
114
+ return (
115
+ <div
116
+ className="relative h-full w-full overflow-hidden"
117
+ style={{
118
+ background:
119
+ "linear-gradient(135deg, #dcfce7 0%, #dbeafe 55%, #fde68a 100%)",
120
+ }}
121
+ >
122
+ <div
123
+ aria-hidden="true"
124
+ className="absolute inset-0 opacity-30"
125
+ style={{
126
+ backgroundImage:
127
+ "linear-gradient(rgba(255,255,255,0.2) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.2) 1px, transparent 1px)",
128
+ backgroundPosition: "0 0, 0 0",
129
+ backgroundSize: "48px 48px",
130
+ }}
131
+ />
132
+ </div>
133
+ );
134
+ };
135
+
136
+ interface MapProps {
137
+ mapStyle?: string;
138
+ centerCoords?: Coordinate;
139
+ onDragHandler?: OnDragHandler;
140
+ scrollToResult?: (result: Result<Location> | undefined) => void;
141
+ markerOptionsOverride?: (selected: boolean) => MapMarkerOptions;
142
+ locationStyleConfig?: LocationStyleConfig;
143
+ }
144
+
145
+ export const LocatorMap: React.FC<MapProps> = ({
146
+ mapStyle,
147
+ centerCoords,
148
+ onDragHandler,
149
+ scrollToResult,
150
+ markerOptionsOverride,
151
+ locationStyleConfig,
152
+ }) => {
153
+ const entityDocument: StreamDocument = useDocument();
154
+
155
+ const documentIsUndefined = typeof document === "undefined";
156
+ const iframe = documentIsUndefined
157
+ ? undefined
158
+ : (document.getElementById("preview-frame") as HTMLIFrameElement);
159
+
160
+ const locatorMapDiv = documentIsUndefined
161
+ ? null
162
+ : ((iframe?.contentDocument || document)?.getElementById(
163
+ "locatorMapDiv"
164
+ ) as HTMLDivElement | null);
165
+
166
+ const mapPadding = React.useMemo(
167
+ () => getMapboxMapPadding(locatorMapDiv),
168
+ [locatorMapDiv]
169
+ );
170
+ const mapboxOptions = React.useMemo(
171
+ () => ({
172
+ center: centerCoords,
173
+ fitBoundsOptions: { padding: mapPadding },
174
+ ...(mapStyle ? { style: mapStyle } : {}),
175
+ }),
176
+ [centerCoords, mapPadding, mapStyle]
177
+ );
178
+ const PinComponent = React.useMemo(
179
+ () =>
180
+ function PinComponent<T>(pinProps: PinComponentProps<T>) {
181
+ return (
182
+ <LocatorMapPin
183
+ {...pinProps}
184
+ locationStyleConfig={locationStyleConfig}
185
+ />
186
+ );
187
+ },
188
+ [locationStyleConfig]
189
+ );
190
+
191
+ if (isVisualEditorTestEnv()) {
192
+ return <LocatorTestMap />;
193
+ }
194
+
195
+ // During page generation we don't exist in a browser context
196
+ //@ts-expect-error MapboxGL is not loaded in iframe content window
197
+ if (iframe?.contentDocument && !iframe.contentWindow?.mapboxgl) {
198
+ // We are in an iframe, and mapboxgl is not loaded in yet
199
+ return <LoadingMapPlaceholder />;
200
+ }
201
+
202
+ let mapboxApiKey = entityDocument._env?.YEXT_MAPBOX_API_KEY;
203
+ if (
204
+ iframe?.contentDocument &&
205
+ entityDocument._env?.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY
206
+ ) {
207
+ // If we are in the layout editor, use the non-URL-restricted Mapbox API key
208
+ mapboxApiKey = entityDocument._env.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY;
209
+ }
210
+
211
+ return (
212
+ <MapboxMap
213
+ mapboxAccessToken={mapboxApiKey || ""}
214
+ mapboxOptions={mapboxOptions}
215
+ onDrag={onDragHandler}
216
+ PinComponent={PinComponent}
217
+ iframeWindow={iframe?.contentWindow ?? undefined}
218
+ allowUpdates={!!iframe?.contentDocument}
219
+ onPinClick={scrollToResult}
220
+ markerOptionsOverride={markerOptionsOverride}
221
+ />
222
+ );
223
+ };
224
+
225
+ type LocatorMapPinProps<T> = PinComponentProps<T> & {
226
+ locationStyleConfig?: LocationStyleConfig;
227
+ };
228
+
229
+ const LocatorMapPin = <T,>({
230
+ result,
231
+ selected,
232
+ locationStyleConfig,
233
+ }: LocatorMapPinProps<T>) => {
234
+ const entityType = result.entityType;
235
+ const entityLocationStyle = entityType
236
+ ? locationStyleConfig?.[entityType]
237
+ : undefined;
238
+
239
+ return (
240
+ <MapPinIcon
241
+ color={entityLocationStyle?.color}
242
+ resultIndex={result.index}
243
+ icon={entityLocationStyle?.customImage?.url ?? entityLocationStyle?.icon}
244
+ iconWidth={
245
+ entityLocationStyle?.customImage?.width ?? DEFAULT_PIN_ICON_WIDTH
246
+ }
247
+ disableContrastIcon={!!entityLocationStyle?.customImage}
248
+ aspectRatio={entityLocationStyle?.customImage?.aspectRatio}
249
+ selected={selected}
250
+ />
251
+ );
252
+ };
253
+
254
+ export const getMapboxMapPadding = (divElement: HTMLDivElement | null) => {
255
+ if (!divElement) {
256
+ return 50;
257
+ }
258
+
259
+ const { width, height } = divElement.getBoundingClientRect();
260
+ const mapVerticalPadding = Math.max(50, height * 0.2);
261
+ const mapHorizontalPadding = Math.max(50, width * 0.2);
262
+ return {
263
+ top: mapVerticalPadding,
264
+ bottom: mapVerticalPadding,
265
+ left: mapHorizontalPadding,
266
+ right: mapHorizontalPadding,
267
+ };
268
+ };
269
+
270
+ export const parseMapStartingLocation = (mapStartingLocation: {
271
+ latitude: string;
272
+ longitude: string;
273
+ }): Coordinate => {
274
+ const lat = parseFloat(mapStartingLocation.latitude);
275
+ const lng = parseFloat(mapStartingLocation.longitude);
276
+
277
+ const err: string[] = [];
278
+ if (isNaN(lat) || lat < -90 || lat > 90) {
279
+ err.push("Latitude must be a number between -90 and 90.");
280
+ }
281
+ if (isNaN(lng) || lng < -180 || lng > 180) {
282
+ err.push("Longitude must be a number between -180 and 180.");
283
+ }
284
+ if (err.length) {
285
+ throw new Error(err.join("\n"));
286
+ }
287
+
288
+ return {
289
+ latitude: lat,
290
+ longitude: lng,
291
+ };
292
+ };
293
+
294
+ /** Checks whether a given lat and lng are valid coordinates */
295
+ export function areValidCoordinates(lat: number, lng: number): boolean {
296
+ return (
297
+ !isNaN(lat) &&
298
+ !isNaN(lng) &&
299
+ lat >= -90 &&
300
+ lat <= 90 &&
301
+ lng >= -180 &&
302
+ lng <= 180
303
+ );
304
+ }
@@ -0,0 +1,160 @@
1
+ import * as React from "react";
2
+ import { useTranslation } from "react-i18next";
3
+ import { ThemeColor } from "../../../utils/themeConfigOptions.ts";
4
+ import { getThemeColorCssValue } from "../../../utils/colors.ts";
5
+
6
+ const resolveCssVarColor = (
7
+ element: Element,
8
+ varName: string
9
+ ): string | undefined => {
10
+ return window.getComputedStyle(element).getPropertyValue(varName).trim();
11
+ };
12
+
13
+ const resolveContrastColor = (
14
+ element: Element,
15
+ textToken: string
16
+ ): string | undefined => {
17
+ if (textToken === "black") {
18
+ return "#000000";
19
+ }
20
+
21
+ if (textToken === "white") {
22
+ return "#FFFFFF";
23
+ }
24
+
25
+ if (textToken) {
26
+ return resolveCssVarColor(element, `--colors-${textToken}`);
27
+ }
28
+
29
+ return undefined;
30
+ };
31
+
32
+ // Renders a Mapbox-style pin with theme-aware fill and contrast-aware icon/number in the center.
33
+ export const MapPinIcon = ({
34
+ color,
35
+ resultIndex,
36
+ icon,
37
+ iconWidth,
38
+ disableContrastIcon,
39
+ aspectRatio,
40
+ selected,
41
+ }: {
42
+ color?: ThemeColor;
43
+ resultIndex?: number;
44
+ icon?: string;
45
+ iconWidth: number;
46
+ disableContrastIcon?: boolean;
47
+ aspectRatio?: number;
48
+ selected?: boolean;
49
+ }) => {
50
+ const { t } = useTranslation();
51
+ const pinHeight = 41;
52
+ const pinWidth = 27;
53
+ const pinScale = 1.5;
54
+
55
+ const centerX = 13.5;
56
+ const centerY = 13.5;
57
+ const iconHeight = aspectRatio ? iconWidth / aspectRatio : iconWidth;
58
+
59
+ const backgroundToken = color?.selectedColor;
60
+ const textToken = color?.contrastingColor;
61
+ const svgRef = React.useRef<SVGSVGElement>(null);
62
+ const [contrastColor, setContrastColor] = React.useState<string | undefined>(
63
+ undefined
64
+ );
65
+
66
+ React.useLayoutEffect(() => {
67
+ // Resolve icon/text contrast color using the theme's text token
68
+ if (svgRef.current && textToken) {
69
+ setContrastColor(resolveContrastColor(svgRef.current, textToken));
70
+ }
71
+ }, [textToken]);
72
+
73
+ // SVG children use currentColor for the pin fill; apply contrast for text/icon.
74
+ const svgStyle = React.useMemo<React.CSSProperties | undefined>(
75
+ () =>
76
+ backgroundToken
77
+ ? { color: getThemeColorCssValue(backgroundToken) }
78
+ : undefined,
79
+ [backgroundToken]
80
+ );
81
+
82
+ const ariaLabel =
83
+ typeof resultIndex === "number"
84
+ ? t("showPinDetails", {
85
+ number: resultIndex,
86
+ defaultValue: "Show pin {{number}} details",
87
+ })
88
+ : t("showPinDetailsDefault", {
89
+ defaultValue: "Show pin details",
90
+ });
91
+
92
+ return (
93
+ <button
94
+ type="button"
95
+ aria-label={ariaLabel}
96
+ className="components block cursor-pointer appearance-none border-0 bg-transparent p-0"
97
+ >
98
+ <svg
99
+ ref={svgRef}
100
+ style={svgStyle}
101
+ display="block"
102
+ height={selected ? pinScale * pinHeight : pinHeight}
103
+ width={selected ? pinScale * pinWidth : pinWidth}
104
+ viewBox="0 0 27 41"
105
+ aria-hidden="true"
106
+ focusable="false"
107
+ >
108
+ <defs>
109
+ <radialGradient id="shadowGradient">
110
+ <stop offset="10%" stopOpacity="0.4"></stop>
111
+ <stop offset="100%" stopOpacity="0.05"></stop>
112
+ </radialGradient>
113
+ </defs>
114
+ <ellipse
115
+ cx="13.5"
116
+ cy="34.8"
117
+ rx="10.5"
118
+ ry="5.25"
119
+ fill="url(#shadowGradient)"
120
+ ></ellipse>
121
+ <path
122
+ fill="currentColor"
123
+ d="M27,13.5C27,19.07 20.25,27 14.75,34.5C14.02,35.5 12.98,35.5 12.25,34.5C6.75,27 0,19.22 0,13.5C0,6.04 6.04,0 13.5,0C20.96,0 27,6.04 27,13.5Z"
124
+ ></path>
125
+ <path
126
+ opacity="0.25"
127
+ d="M13.5,0C6.04,0 0,6.04 0,13.5C0,19.22 6.75,27 12.25,34.5C13,35.52 14.02,35.5 14.75,34.5C20.25,27 27,19.07 27,13.5C27,6.04 20.96,0 13.5,0ZM13.5,1C20.42,1 26,6.58 26,13.5C26,15.9 24.5,19.18 22.22,22.74C19.95,26.3 16.71,30.14 13.94,33.91C13.74,34.18 13.61,34.32 13.5,34.44C13.39,34.32 13.26,34.18 13.06,33.91C10.28,30.13 7.41,26.31 5.02,22.77C2.62,19.23 1,15.95 1,13.5C1,6.58 6.58,1 13.5,1Z"
128
+ ></path>
129
+ {icon ? (
130
+ <image
131
+ href={icon}
132
+ x={centerX - iconWidth / 2}
133
+ y={centerY - iconHeight / 2}
134
+ width={iconWidth}
135
+ height={iconHeight}
136
+ filter={
137
+ contrastColor === "#000000" || disableContrastIcon
138
+ ? "invert(0)"
139
+ : "invert(1)"
140
+ }
141
+ preserveAspectRatio="xMidYMid slice"
142
+ />
143
+ ) : (
144
+ !!resultIndex && (
145
+ <text
146
+ textAnchor="middle"
147
+ fontWeight="bold"
148
+ fontSize={iconWidth}
149
+ x="50%"
150
+ y="50%"
151
+ fill={contrastColor ?? "white"}
152
+ >
153
+ {resultIndex}
154
+ </text>
155
+ )
156
+ )}
157
+ </svg>
158
+ </button>
159
+ );
160
+ };