@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,541 @@
1
+ import { FieldLabel, setDeep } from "@puckeditor/core";
2
+ import { type MultiSelectorValue } from "../../../fields/MultiSelectorField.tsx";
3
+ import { YextAutoField } from "../../../fields/YextAutoField.tsx";
4
+ import { TranslatableString } from "../../../types/types.ts";
5
+ import { msg, pt } from "../../../utils/i18n/platform.ts";
6
+ import { TranslatableAssetImage } from "../../../types/images.ts";
7
+ import {
8
+ backgroundColors,
9
+ ThemeColor,
10
+ } from "../../../utils/themeConfigOptions.ts";
11
+ import {
12
+ DEFAULT_ENTITY_TYPE,
13
+ getEntityTypeLabel,
14
+ getLocatorEntityTypeSourceMap,
15
+ isLocatorEntityType,
16
+ LocatorEntityType,
17
+ } from "../../../utils/locatorEntityTypes.ts";
18
+ import {
19
+ toPuckFields,
20
+ type YextCustomFieldRenderProps,
21
+ YextComponentConfig,
22
+ YextFields,
23
+ } from "../../../fields/fields.ts";
24
+ import { ImageStylingFields } from "../../contentBlocks/image/styling.ts";
25
+ import { getFacetFieldOptions, KEYWORDS_FIELD } from "./Filters.tsx";
26
+ import {
27
+ DEFAULT_LOCATOR_RESULT_CARD_PROPS,
28
+ DistanceDisplayOption,
29
+ LocatorResultCardProps,
30
+ } from "./LocatorResultCard.tsx";
31
+ import { ResultCardPropsField } from "./Results.tsx";
32
+ import { LocatorWrapper } from "./LocatorWrapper.tsx";
33
+ import {
34
+ DEFAULT_LOCATION_STYLE,
35
+ DEFAULT_MAKI_ICON_NAME,
36
+ DEFAULT_PIN_ICON_WIDTH,
37
+ LOCATOR_PIN_ICON_FIELD,
38
+ MAX_PIN_ICON_WIDTH,
39
+ makiIconOptions,
40
+ } from "./Map.tsx";
41
+ const DEFAULT_TITLE = "Find a Location";
42
+ const DEFAULT_DISTANCE_DISPLAY = "distanceFromUser";
43
+
44
+ export interface LocatorProps {
45
+ /**
46
+ * The visual theme for the map tiles, chosen from a predefined list of Mapbox styles.
47
+ * @defaultValue 'mapbox://styles/mapbox/streets-v12'
48
+ */
49
+ mapStyle?: string;
50
+
51
+ /**
52
+ * Props to customize the locator map pin styles.
53
+ * Controls map pin appearance depending on the result's entity type.
54
+ * The number of entries is locked to the locator entity types for the page set.
55
+ */
56
+ locationStyles: Array<{
57
+ /** The entity type this style applies to. */
58
+ entityType: LocatorEntityType;
59
+ /** Whether to render an icon in the pin. */
60
+ pinIcon?: {
61
+ type: "none" | "icon" | "customImage";
62
+ /** Defaults to the first available Maki icon when type is 'icon'. */
63
+ iconName?: string;
64
+ /** Image rendered within the pin when type is 'customImage'. */
65
+ image?: TranslatableAssetImage;
66
+ /**
67
+ * Width of the custom image rendered within the pin.
68
+ * @defaultValue 14
69
+ * */
70
+ width?: number;
71
+ /** Aspect ratio of the custom image rendered within the pin. */
72
+ aspectRatio?: number;
73
+ };
74
+ /** The color applied to the pin. */
75
+ pinColor?: ThemeColor;
76
+ }>;
77
+
78
+ /**
79
+ * Configuration for the filters available in the locator search experience.
80
+ */
81
+ filters: {
82
+ /**
83
+ * If 'true', displays a button to filter for locations that are currently open.
84
+ * @defaultValue false
85
+ */
86
+ openNowButton: boolean;
87
+ /**
88
+ * If 'true', displays several distance options to filter searches to only locations within
89
+ * a certain radius.
90
+ * @defaultValue false
91
+ */
92
+ showDistanceOptions: boolean;
93
+ /** Accent color for filter button and icons. */
94
+ accentColor?: ThemeColor;
95
+ /** Which fields are facetable in the search experience. */
96
+ facetFields?: MultiSelectorValue<string>;
97
+ /** The optional display name for the Keywords facet. */
98
+ keywordsDisplayName?: TranslatableString;
99
+ };
100
+
101
+ /**
102
+ * The starting location for the map.
103
+ */
104
+ mapStartingLocation?: {
105
+ latitude: string;
106
+ longitude: string;
107
+ };
108
+ /**
109
+ * Configuration for the locator page heading.
110
+ * Allows customizing the title text and its color.
111
+ */
112
+ pageHeading?: {
113
+ /** The title displayed at the top of the locator page. */
114
+ title: TranslatableString;
115
+ /**
116
+ * The color applied to the locator page title.
117
+ * @defaultValue inherited from theme
118
+ */
119
+ color?: ThemeColor;
120
+ };
121
+ /**
122
+ * Props to customize the locator result card component.
123
+ * Controls which fields are displayed and their styling depending on the result's entity type.
124
+ * The number of entries is locked to the locator entity types for the page set.
125
+ */
126
+ resultCard: Array<{
127
+ /** Props to customize the locator result card component. */
128
+ props: LocatorResultCardProps;
129
+ }>;
130
+ /** Controls which distance value to display on each locator result card. */
131
+ distanceDisplay?: DistanceDisplayOption;
132
+ }
133
+
134
+ const locatorFields: YextFields<LocatorProps> = {
135
+ mapStyle: {
136
+ type: "basicSelector",
137
+ label: msg("fields.mapStyle", "Map Style"),
138
+ options: [
139
+ {
140
+ label: msg("fields.options.default", "Default"),
141
+ value: "mapbox://styles/mapbox/streets-v12",
142
+ },
143
+ {
144
+ label: msg("fields.options.satellite", "Satellite"),
145
+ value: "mapbox://styles/mapbox/satellite-streets-v12",
146
+ },
147
+ {
148
+ label: msg("fields.options.light", "Light"),
149
+ value: "mapbox://styles/mapbox/light-v11",
150
+ },
151
+ {
152
+ label: msg("fields.options.dark", "Dark"),
153
+ value: "mapbox://styles/mapbox/dark-v11",
154
+ },
155
+ {
156
+ label: msg("fields.options.navigationDay", "Navigation (Day)"),
157
+ value: "mapbox://styles/mapbox/navigation-day-v1",
158
+ },
159
+ {
160
+ label: msg("fields.options.navigationNight", "Navigation (Night)"),
161
+ value: "mapbox://styles/mapbox/navigation-night-v1",
162
+ },
163
+ ],
164
+ },
165
+ locationStyles: {
166
+ type: "array",
167
+ label: msg("fields.pinStyles", "Location styles"),
168
+ getItemSummary: (item: LocatorProps["locationStyles"][number]) =>
169
+ getEntityTypeLabel(item.entityType),
170
+ arrayFields: {
171
+ entityType: {
172
+ label: msg("fields.entityType", "Entity Type"),
173
+ type: "text",
174
+ visible: false,
175
+ },
176
+ pinIcon: {
177
+ type: "custom",
178
+ render: ({
179
+ value,
180
+ onChange,
181
+ }: YextCustomFieldRenderProps<
182
+ LocatorProps["locationStyles"][number]["pinIcon"]
183
+ >) => {
184
+ const selectedType = value?.type ?? "none";
185
+ return (
186
+ <div className="flex flex-col gap-3">
187
+ <YextAutoField
188
+ field={{
189
+ type: "basicSelector",
190
+ label: msg("fields.pinIcon", "Pin Icon"),
191
+ options: [
192
+ {
193
+ label: msg("fields.options.none", "None"),
194
+ value: "none",
195
+ },
196
+ {
197
+ label: msg("fields.options.icon", "Icon"),
198
+ value: "icon",
199
+ },
200
+ {
201
+ label: msg("fields.options.customImage", "Custom image"),
202
+ value: "customImage",
203
+ },
204
+ ],
205
+ }}
206
+ value={selectedType}
207
+ onChange={(type) =>
208
+ onChange({
209
+ ...value,
210
+ type,
211
+ iconName:
212
+ type === "icon"
213
+ ? (value?.iconName ?? DEFAULT_MAKI_ICON_NAME)
214
+ : undefined,
215
+ })
216
+ }
217
+ />
218
+ {selectedType === "icon" && (
219
+ <YextAutoField
220
+ field={{
221
+ type: "basicSelector",
222
+ label: msg("fields.icon", "Icon"),
223
+ options: makiIconOptions,
224
+ }}
225
+ value={value?.iconName}
226
+ onChange={(iconName) =>
227
+ onChange({ ...value, type: "icon", iconName })
228
+ }
229
+ />
230
+ )}
231
+ {selectedType === "customImage" && (
232
+ <>
233
+ <YextAutoField
234
+ field={{
235
+ ...LOCATOR_PIN_ICON_FIELD,
236
+ }}
237
+ value={value?.image}
238
+ onChange={(image) =>
239
+ onChange({ ...value, type: "customImage", image })
240
+ }
241
+ />
242
+ <FieldLabel label={pt("fields.options.width", "Width")}>
243
+ <YextAutoField
244
+ field={{
245
+ type: "number",
246
+ min: 1,
247
+ max: MAX_PIN_ICON_WIDTH,
248
+ }}
249
+ value={value?.width ?? DEFAULT_PIN_ICON_WIDTH}
250
+ onChange={(width) =>
251
+ onChange({
252
+ ...value,
253
+ type: "customImage",
254
+ width,
255
+ })
256
+ }
257
+ />
258
+ </FieldLabel>
259
+ <YextAutoField
260
+ field={ImageStylingFields.aspectRatio}
261
+ value={value?.aspectRatio}
262
+ onChange={(aspectRatio) =>
263
+ onChange({
264
+ ...value,
265
+ type: "customImage",
266
+ aspectRatio,
267
+ })
268
+ }
269
+ />
270
+ </>
271
+ )}
272
+ </div>
273
+ );
274
+ },
275
+ },
276
+ pinColor: {
277
+ type: "basicSelector",
278
+ label: msg("fields.pinColor", "Pin Color"),
279
+ options: "BACKGROUND_COLOR",
280
+ },
281
+ },
282
+ defaultItemProps: {
283
+ entityType: DEFAULT_ENTITY_TYPE,
284
+ pinIcon: { type: "none" },
285
+ pinColor: backgroundColors.background6.value,
286
+ },
287
+ },
288
+ filters: {
289
+ label: msg("fields.filters", "Filters"),
290
+ type: "object",
291
+ objectFields: {
292
+ openNowButton: {
293
+ label: msg("fields.options.includeOpenNow", "Include Open Now Button"),
294
+ type: "radio",
295
+ options: [
296
+ { label: msg("fields.options.yes", "Yes"), value: true },
297
+ { label: msg("fields.options.no", "No"), value: false },
298
+ ],
299
+ },
300
+ showDistanceOptions: {
301
+ label: msg(
302
+ "fields.options.showDistanceOptions",
303
+ "Include Distance Options"
304
+ ),
305
+ type: "radio",
306
+ options: [
307
+ { label: msg("fields.options.yes", "Yes"), value: true },
308
+ { label: msg("fields.options.no", "No"), value: false },
309
+ ],
310
+ },
311
+ accentColor: {
312
+ type: "basicSelector",
313
+ label: msg("fields.accentColor", "Accent Color"),
314
+ options: "SITE_COLOR",
315
+ },
316
+ facetFields: {
317
+ type: "multiSelector",
318
+ label: msg("fields.dynamicFilters", "Dynamic Filters"),
319
+ dropdownLabel: msg("fields.field", "Field"),
320
+ options: () => {
321
+ const entityTypeSourceMap = getLocatorEntityTypeSourceMap();
322
+ const entityTypes =
323
+ Object.keys(entityTypeSourceMap).filter(isLocatorEntityType);
324
+ return getFacetFieldOptions(entityTypes);
325
+ },
326
+ placeholderOptionLabel: msg(
327
+ "fields.options.selectAField",
328
+ "Select a field"
329
+ ),
330
+ } as any, // TODO(SUMO-8378): remove 'as any' when puck fixes objectFields typing
331
+ keywordsDisplayName: {
332
+ type: "translatableString",
333
+ label: msg("fields.keywordsDisplayName", "Keywords Display Name"),
334
+ showFieldSelector: false,
335
+ visible: false,
336
+ },
337
+ },
338
+ },
339
+ mapStartingLocation: {
340
+ type: "object",
341
+ label: msg("fields.options.mapStartingLocation", "Map Starting Location"),
342
+ objectFields: {
343
+ latitude: {
344
+ label: msg("fields.latitude", "Latitude"),
345
+ type: "text",
346
+ },
347
+ longitude: {
348
+ label: msg("fields.longitude", "Longitude"),
349
+ type: "text",
350
+ },
351
+ },
352
+ },
353
+ pageHeading: {
354
+ type: "object",
355
+ label: msg("fields.pageHeading", "Page Heading"),
356
+ objectFields: {
357
+ title: {
358
+ type: "translatableString",
359
+ label: msg("fields.title", "Title"),
360
+ filter: { types: ["type.string"] },
361
+ },
362
+ color: {
363
+ type: "basicSelector",
364
+ label: msg("fields.color", "Color"),
365
+ options: "SITE_COLOR",
366
+ },
367
+ },
368
+ },
369
+ resultCard: {
370
+ type: "array",
371
+ label: msg("fields.resultCard", "Result Card"),
372
+ getItemSummary: (item: LocatorProps["resultCard"][number]) =>
373
+ getEntityTypeLabel(item.props.entityType),
374
+ arrayFields: {
375
+ props: {
376
+ type: "custom",
377
+ render: ({
378
+ value,
379
+ onChange,
380
+ }: YextCustomFieldRenderProps<
381
+ LocatorProps["resultCard"][number]["props"]
382
+ >) => <ResultCardPropsField value={value} onChange={onChange} />,
383
+ },
384
+ },
385
+ defaultItemProps: {
386
+ props: DEFAULT_LOCATOR_RESULT_CARD_PROPS,
387
+ },
388
+ },
389
+ distanceDisplay: {
390
+ type: "basicSelector",
391
+ label: msg("fields.distanceDisplay", "Distance Display"),
392
+ options: [
393
+ {
394
+ label: msg("fields.options.distanceFromUser", "Distance from User"),
395
+ value: "distanceFromUser",
396
+ },
397
+ {
398
+ label: msg("fields.options.distanceFromSearch", "Distance from Search"),
399
+ value: "distanceFromSearch",
400
+ },
401
+ {
402
+ label: msg("fields.options.bothDistances", "Both Distances"),
403
+ value: "bothDistances",
404
+ },
405
+ {
406
+ label: msg("fields.options.hidden", "Hidden"),
407
+ value: "hidden",
408
+ },
409
+ ],
410
+ },
411
+ };
412
+
413
+ /**
414
+ * Available on Locator templates.
415
+ */
416
+ export const LocatorComponent: YextComponentConfig<LocatorProps> = {
417
+ fields: locatorFields,
418
+ /**
419
+ * Locks array lengths for `locationStyles` and `resultCard` to the current
420
+ * locator entity types so each entity type has exactly one entry.
421
+ */
422
+ resolveFields: (data, params) => {
423
+ const entityDocument = params.metadata?.streamDocument;
424
+ const entityTypeSourceMap = entityDocument
425
+ ? getLocatorEntityTypeSourceMap(entityDocument)
426
+ : { [DEFAULT_ENTITY_TYPE]: undefined };
427
+ const entityTypes = Object.keys(
428
+ entityTypeSourceMap
429
+ ) as (keyof typeof entityTypeSourceMap)[];
430
+ const entityTypeCount = entityTypes.length;
431
+
432
+ let updatedFields: YextFields<LocatorProps> = { ...locatorFields };
433
+ updatedFields = setDeep(
434
+ updatedFields,
435
+ "locationStyles.min",
436
+ entityTypeCount
437
+ );
438
+ updatedFields = setDeep(
439
+ updatedFields,
440
+ "locationStyles.max",
441
+ entityTypeCount
442
+ );
443
+ updatedFields = setDeep(updatedFields, "resultCard.min", entityTypeCount);
444
+ updatedFields = setDeep(updatedFields, "resultCard.max", entityTypeCount);
445
+ updatedFields = setDeep(
446
+ updatedFields,
447
+ "filters.objectFields.keywordsDisplayName.visible",
448
+ data.props.filters?.facetFields?.selections.some(
449
+ (selection) => selection.value === KEYWORDS_FIELD
450
+ ) ?? false
451
+ );
452
+
453
+ return toPuckFields<LocatorProps>(updatedFields);
454
+ },
455
+ defaultProps: {
456
+ locationStyles: [],
457
+ resultCard: [],
458
+ filters: {
459
+ openNowButton: false,
460
+ showDistanceOptions: false,
461
+ },
462
+ pageHeading: {
463
+ title: { defaultValue: DEFAULT_TITLE },
464
+ },
465
+ distanceDisplay: DEFAULT_DISTANCE_DISPLAY,
466
+ },
467
+ label: msg("components.locator", "Locator"),
468
+ /**
469
+ * Reconciles `props.locationStyles` and `props.resultCard` so
470
+ * each list has exactly one entry per current locator entity type.
471
+ * Missing or mismatched entries are rebuilt from existing
472
+ * values and backfilled with defaults.
473
+ */
474
+ resolveData: (data, params) => {
475
+ const entityDocument = params.metadata?.streamDocument;
476
+ const entityTypeSourceMap = entityDocument
477
+ ? getLocatorEntityTypeSourceMap(entityDocument)
478
+ : { [DEFAULT_ENTITY_TYPE]: undefined };
479
+ const entityTypes = Object.keys(
480
+ entityTypeSourceMap
481
+ ) as (keyof typeof entityTypeSourceMap)[];
482
+
483
+ const previousLocationStyles = data.props.locationStyles ?? [];
484
+ const previousResultCard = data.props.resultCard ?? [];
485
+ const hasSameEntityTypes = (currentEntityTypes: string[]) =>
486
+ currentEntityTypes.length === entityTypes.length &&
487
+ entityTypes.every((entityType) =>
488
+ currentEntityTypes.includes(entityType)
489
+ );
490
+
491
+ const locationStylesByEntityType = new globalThis.Map(
492
+ previousLocationStyles
493
+ .filter((item) => !!item.entityType)
494
+ .map((item) => [item.entityType, item] as const)
495
+ );
496
+ const resultCardsByEntityType = new globalThis.Map(
497
+ previousResultCard
498
+ .filter((item) => !!item?.props?.entityType)
499
+ .map((item) => [item.props.entityType, item] as const)
500
+ );
501
+
502
+ const previousLocationStyleEntityTypes = previousLocationStyles.map(
503
+ (item) => item.entityType
504
+ );
505
+ const previousResultCardEntityTypes = previousResultCard.map(
506
+ (item) => item.props?.entityType
507
+ );
508
+
509
+ const shouldReconcileLocationStyles =
510
+ previousLocationStyles.length === 0 ||
511
+ !hasSameEntityTypes(previousLocationStyleEntityTypes);
512
+ const shouldReconcileResultCards =
513
+ previousResultCard.length === 0 ||
514
+ !hasSameEntityTypes(previousResultCardEntityTypes);
515
+
516
+ if (shouldReconcileLocationStyles) {
517
+ const newLocationStyles = entityTypes.map((entityType) => ({
518
+ ...DEFAULT_LOCATION_STYLE,
519
+ ...locationStylesByEntityType.get(entityType),
520
+ entityType,
521
+ }));
522
+ data = setDeep(data, "props.locationStyles", newLocationStyles);
523
+ }
524
+
525
+ if (shouldReconcileResultCards) {
526
+ const newResultCards = entityTypes.map((entityType) => {
527
+ const existing = resultCardsByEntityType.get(entityType);
528
+ return {
529
+ props: {
530
+ ...(existing?.props ?? DEFAULT_LOCATOR_RESULT_CARD_PROPS),
531
+ entityType,
532
+ },
533
+ };
534
+ });
535
+ data = setDeep(data, "props.resultCard", newResultCards);
536
+ }
537
+
538
+ return data;
539
+ },
540
+ render: (props) => <LocatorWrapper {...props} />,
541
+ };
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { LocatorComponent } from "./Locator.tsx";
3
+
4
+ const getKeywordsDisplayNameVisibility = (facetValues?: string[]) => {
5
+ const fields = LocatorComponent.resolveFields?.(
6
+ {
7
+ props: {
8
+ filters: {
9
+ facetFields: facetValues
10
+ ? {
11
+ selections: facetValues.map((value) => ({ value })),
12
+ }
13
+ : undefined,
14
+ },
15
+ },
16
+ } as any,
17
+ { metadata: {} } as any
18
+ ) as any;
19
+
20
+ return fields.filters.objectFields.keywordsDisplayName.visible;
21
+ };
22
+
23
+ describe("Locator fields", () => {
24
+ it.each([
25
+ {
26
+ name: "shows the display name when Keywords is selected",
27
+ facetValues: ["keywords", "services"],
28
+ expected: true,
29
+ },
30
+ {
31
+ name: "hides the display name when another facet is selected",
32
+ facetValues: ["services"],
33
+ expected: false,
34
+ },
35
+ {
36
+ name: "hides the display name when no facets are selected",
37
+ facetValues: undefined,
38
+ expected: false,
39
+ },
40
+ ])("$name", ({ facetValues, expected }) => {
41
+ expect(getKeywordsDisplayNameVisibility(facetValues)).toBe(expected);
42
+ });
43
+ });