@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,691 @@
1
+ import {
2
+ FieldValueFilter,
3
+ FieldValueStaticFilter,
4
+ Matcher,
5
+ NearFilterValue,
6
+ SelectableStaticFilter,
7
+ useSearchState,
8
+ } from "@yext/search-headless-react";
9
+ import {
10
+ AppliedFilters,
11
+ Facets,
12
+ NumericalFacet,
13
+ StandardFacet,
14
+ } from "@yext/search-ui-react";
15
+ import React from "react";
16
+ import { type MultiSelectorOption } from "../../../fields/MultiSelectorField.tsx";
17
+ import { useCollapse } from "react-collapsed";
18
+ import { useTranslation } from "react-i18next";
19
+ import { FaChevronUp, FaDotCircle, FaRegCircle, FaTimes } from "react-icons/fa";
20
+ import { type TranslatableString } from "../../../types/types.ts";
21
+ import { getPreferredDistanceUnit } from "../../../utils/i18n/distance.ts";
22
+ import { msg } from "../../../utils/i18n/platform.ts";
23
+ import { LocatorEntityType } from "../../../utils/locatorEntityTypes.ts";
24
+ import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
25
+ import { Body } from "../../atoms/body.tsx";
26
+ import { translateDistanceUnit } from "./Results.tsx";
27
+
28
+ export const LOCATION_FIELD = "builtin.location";
29
+ export const COUNTRY_CODE_FIELD = "address.countryCode";
30
+ export const HOURS_FIELD = "builtin.hours";
31
+ export const KEYWORDS_FIELD = "keywords";
32
+
33
+ interface FilterModalProps {
34
+ showFilterModal: boolean;
35
+ showOpenNowOption: boolean; // whether to show the Open Now filter option
36
+ isOpenNowSelected: boolean; // whether the Open Now filter is currently selected by the user
37
+ showDistanceOptions: boolean; // whether to show the Distance filter option
38
+ selectedDistanceOption: number | null;
39
+ handleCloseModalClick: () => void;
40
+ handleOpenNowClick: (selected: boolean) => void;
41
+ handleDistanceClick: (
42
+ distance: number,
43
+ distanceUnit: "mile" | "kilometer"
44
+ ) => void;
45
+ handleClearFiltersClick: () => void;
46
+ accentColorCssValue: string;
47
+ closeButtonRef: React.Ref<HTMLButtonElement>;
48
+ keywordsDisplayName?: TranslatableString;
49
+ }
50
+
51
+ export const FilterModal = ({
52
+ showFilterModal,
53
+ showOpenNowOption,
54
+ isOpenNowSelected,
55
+ showDistanceOptions,
56
+ selectedDistanceOption,
57
+ handleCloseModalClick,
58
+ handleOpenNowClick,
59
+ handleDistanceClick,
60
+ handleClearFiltersClick,
61
+ accentColorCssValue,
62
+ closeButtonRef,
63
+ keywordsDisplayName,
64
+ }: FilterModalProps) => {
65
+ const { t, i18n } = useTranslation();
66
+ const popupRef = React.useRef<HTMLDivElement>(null);
67
+ const facets = useSearchState((state) => state.filters.facets);
68
+ const facetOverrides = facets?.map((facet) => {
69
+ const isNumericalFacet = facet.options.some(
70
+ (option) =>
71
+ option.matcher === Matcher.Between &&
72
+ typeof option.value === "object" &&
73
+ option.value !== null &&
74
+ ("start" in option.value || "end" in option.value)
75
+ );
76
+ const FacetOverride = isNumericalFacet ? NumericalFacet : StandardFacet;
77
+ const displayName =
78
+ facet.fieldId === KEYWORDS_FIELD && keywordsDisplayName
79
+ ? resolveComponentData(keywordsDisplayName, i18n.language) || undefined
80
+ : undefined;
81
+
82
+ return (
83
+ <FacetOverride
84
+ key={facet.fieldId}
85
+ fieldId={facet.fieldId}
86
+ label={displayName}
87
+ />
88
+ );
89
+ });
90
+
91
+ return showFilterModal ? (
92
+ <div
93
+ id="locator-filter-modal"
94
+ role="dialog"
95
+ aria-modal="true"
96
+ aria-labelledby="locator-filter-modal-title"
97
+ className="absolute md:top-4 -top-20 z-50 md:w-80 w-full flex flex-col bg-white md:left-full md:ml-2 rounded-md shadow-lg max-h-[calc(100%-2rem)]"
98
+ style={
99
+ {
100
+ "--locator-filter-accent-color": accentColorCssValue,
101
+ } as React.CSSProperties
102
+ }
103
+ ref={popupRef}
104
+ >
105
+ <div className="inline-flex justify-between items-center px-6 py-4 gap-4">
106
+ <Body className="font-bold" id="locator-filter-modal-title">
107
+ {t("refineYourSearch", "Refine Your Search")}
108
+ </Body>
109
+ <button
110
+ ref={closeButtonRef}
111
+ style={{ color: accentColorCssValue }}
112
+ onClick={handleCloseModalClick}
113
+ aria-label={t("close", "Close")}
114
+ >
115
+ <FaTimes />
116
+ </button>
117
+ </div>
118
+ <div className="px-6 border-b border-gray-300">
119
+ <AppliedFilters
120
+ hiddenFields={[LOCATION_FIELD, COUNTRY_CODE_FIELD]}
121
+ customCssClasses={{
122
+ removableFilter: "text-md font-normal",
123
+ clearAllButton: "hidden",
124
+ }}
125
+ />
126
+ </div>
127
+ <div className="flex flex-col p-6 gap-6 overflow-y-auto">
128
+ <div className="flex flex-col gap-8">
129
+ {showOpenNowOption && (
130
+ <OpenNowFilter
131
+ isSelected={isOpenNowSelected}
132
+ onChange={handleOpenNowClick}
133
+ />
134
+ )}
135
+ {showDistanceOptions && (
136
+ <DistanceFilter
137
+ onChange={handleDistanceClick}
138
+ selectedDistanceOption={selectedDistanceOption}
139
+ accentColorCssValue={accentColorCssValue}
140
+ />
141
+ )}
142
+ <Facets
143
+ customCssClasses={{
144
+ divider: "bg-white",
145
+ titleLabel: "font-bold text-md font-body-fontFamily",
146
+ optionInput:
147
+ "h-4 w-4 [accent-color:var(--locator-filter-accent-color)]",
148
+ optionLabel: "text-md font-body-fontFamily font-body-fontWeight",
149
+ option: "space-x-4 font-body-fontFamily",
150
+ }}
151
+ >
152
+ {facetOverrides}
153
+ </Facets>
154
+ </div>
155
+ </div>
156
+ <div className="border-y border-gray-300 justify-center align-middle">
157
+ <button
158
+ className="w-full py-4 text-center font-bold font-body-fontFamily text-body-fontSize"
159
+ style={{ color: accentColorCssValue }}
160
+ onClick={handleClearFiltersClick}
161
+ >
162
+ {t("clearAll", "Clear All")}
163
+ </button>
164
+ </div>
165
+ </div>
166
+ ) : null;
167
+ };
168
+
169
+ interface OpenNowFilterProps {
170
+ isSelected: boolean;
171
+ onChange: (selected: boolean) => void;
172
+ }
173
+
174
+ const OpenNowFilter = ({ isSelected, onChange }: OpenNowFilterProps) => {
175
+ const { t } = useTranslation();
176
+ const { isExpanded, getToggleProps, getCollapseProps } = useCollapse({
177
+ defaultExpanded: true,
178
+ });
179
+ const iconClassName = isExpanded
180
+ ? "w-3 text-gray-400"
181
+ : "w-3 text-gray-400 transform rotate-180";
182
+
183
+ const openNowCheckBoxId = "openNowCheckBox";
184
+ return (
185
+ <div className="flex flex-col gap-4">
186
+ <button
187
+ className="w-full flex justify-between items-center font-bold font-body-fontFamily text-body-fontSize"
188
+ {...getToggleProps()}
189
+ >
190
+ {t("hours", "Hours")}
191
+ <FaChevronUp className={iconClassName} />
192
+ </button>
193
+ <div className="flex flex-row gap-1" {...getCollapseProps()}>
194
+ <div className="inline-flex items-center gap-4">
195
+ <input
196
+ type="checkbox"
197
+ id={openNowCheckBoxId}
198
+ checked={isSelected}
199
+ className={
200
+ "w-4 h-4 form-checkbox cursor-pointer border border-gray-300" +
201
+ " rounded-sm text-primary focus:ring-primary [accent-color:var(--locator-filter-accent-color)]"
202
+ }
203
+ onChange={() => onChange(!isSelected)}
204
+ />
205
+ <label htmlFor={openNowCheckBoxId}>
206
+ <Body>{t("openNow", "Open Now")}</Body>
207
+ </label>
208
+ </div>
209
+ </div>
210
+ </div>
211
+ );
212
+ };
213
+
214
+ interface DistanceFilterProps {
215
+ onChange: (distance: number, unit: "mile" | "kilometer") => void;
216
+ selectedDistanceOption: number | null;
217
+ accentColorCssValue: string;
218
+ }
219
+
220
+ const DistanceFilter = ({
221
+ onChange,
222
+ selectedDistanceOption,
223
+ accentColorCssValue,
224
+ }: DistanceFilterProps) => {
225
+ const { t, i18n } = useTranslation();
226
+ const { isExpanded, getToggleProps, getCollapseProps } = useCollapse({
227
+ defaultExpanded: true,
228
+ });
229
+ const iconClassName = isExpanded
230
+ ? "w-3 text-gray-400"
231
+ : "w-3 text-gray-400 transform rotate-180";
232
+ const distanceOptions = [5, 10, 25, 50];
233
+ const unit = getPreferredDistanceUnit(i18n.language);
234
+
235
+ return (
236
+ <div className="flex flex-col gap-4">
237
+ <button
238
+ className="w-full flex justify-between items-center font-bold font-body-fontFamily text-body-fontSize"
239
+ {...getToggleProps()}
240
+ >
241
+ {t("distance", "Distance")}
242
+ <FaChevronUp className={iconClassName} />
243
+ </button>
244
+ <div {...getCollapseProps()}>
245
+ {distanceOptions.map((distanceOption) => (
246
+ <div
247
+ className="flex flex-row gap-4 items-center"
248
+ id={`distanceOption-${distanceOption}`}
249
+ key={distanceOption}
250
+ >
251
+ <button
252
+ className="inline-flex bg-white"
253
+ onClick={() => onChange(distanceOption, unit)}
254
+ aria-label={`${t("selectDistanceLessThan", "Select distance less than")} ${distanceOption} ${translateDistanceUnit(t, unit, distanceOption)}`}
255
+ >
256
+ <div style={{ color: accentColorCssValue }}>
257
+ {selectedDistanceOption === distanceOption ? (
258
+ <FaDotCircle />
259
+ ) : (
260
+ <FaRegCircle />
261
+ )}
262
+ </div>
263
+ </button>
264
+ <Body className="inline-flex">
265
+ {`< ${distanceOption} ${translateDistanceUnit(t, unit, distanceOption)}`}
266
+ </Body>
267
+ </div>
268
+ ))}
269
+ </div>
270
+ </div>
271
+ );
272
+ };
273
+
274
+ export function getFacetFieldOptions(
275
+ entityTypes: LocatorEntityType[]
276
+ ): MultiSelectorOption<string>[] {
277
+ const facetFields: MultiSelectorOption<string>[] = [];
278
+ const addedValues: Set<string> = new Set<string>();
279
+ entityTypes.forEach((entityType) =>
280
+ getFacetFieldOptionsForEntityType(entityType).forEach((option) => {
281
+ if (option?.value && !addedValues.has(option.value)) {
282
+ facetFields.push(option);
283
+ addedValues.add(option.value);
284
+ }
285
+ })
286
+ );
287
+ return facetFields.sort((a, b) => a.label.localeCompare(b.label));
288
+ }
289
+
290
+ function getFacetFieldOptionsForEntityType(
291
+ entityType: LocatorEntityType
292
+ ): MultiSelectorOption<string>[] {
293
+ let filterOptions: MultiSelectorOption<string>[] = [
294
+ {
295
+ label: msg("fields.options.facets.city", "City"),
296
+ value: "address.city",
297
+ },
298
+ {
299
+ label: msg("fields.options.facets.postalCode", "Postal Code"),
300
+ value: "address.postalCode",
301
+ },
302
+ {
303
+ label: msg("fields.options.facets.region", "Region"),
304
+ value: "address.region",
305
+ },
306
+ {
307
+ label: msg("fields.options.facets.brandName", "Brand Name"),
308
+ value: "brandReference.name",
309
+ },
310
+ ];
311
+ switch (entityType) {
312
+ case "location":
313
+ filterOptions = filterOptions.concat(
314
+ {
315
+ label: msg("fields.options.facets.associations", "Associations"),
316
+ value: "associations",
317
+ },
318
+ {
319
+ label: msg("fields.options.facets.brands", "Brands"),
320
+ value: "brands",
321
+ },
322
+ {
323
+ label: msg("fields.options.facets.keywords", "Keywords"),
324
+ value: KEYWORDS_FIELD,
325
+ },
326
+ {
327
+ label: msg("fields.options.facets.languages", "Languages"),
328
+ value: "languages",
329
+ },
330
+ {
331
+ label: msg("fields.options.facets.paymentOptions", "Payment Options"),
332
+ value: "paymentOptions",
333
+ },
334
+ {
335
+ label: msg("fields.options.facets.products", "Products"),
336
+ value: "products",
337
+ },
338
+ {
339
+ label: msg("fields.options.facets.services", "Services"),
340
+ value: "services",
341
+ },
342
+ {
343
+ label: msg("fields.options.facets.specialties", "Specialties"),
344
+ value: "specialities",
345
+ }
346
+ );
347
+ break;
348
+ case "restaurant":
349
+ filterOptions = filterOptions.concat(
350
+ {
351
+ label: msg(
352
+ "fields.options.facets.acceptsReservations",
353
+ "Accepts Reservations"
354
+ ),
355
+ value: "acceptsReservations",
356
+ },
357
+ {
358
+ label: msg("fields.options.facets.associations", "Associations"),
359
+ value: "associations",
360
+ },
361
+ {
362
+ label: msg("fields.options.facets.brands", "Brands"),
363
+ value: "brands",
364
+ },
365
+ {
366
+ label: msg("fields.options.facets.keywords", "Keywords"),
367
+ value: KEYWORDS_FIELD,
368
+ },
369
+ {
370
+ label: msg("fields.options.facets.languages", "Languages"),
371
+ value: "languages",
372
+ },
373
+ {
374
+ label: msg("fields.options.facets.mealsServed", "Meals Served"),
375
+ value: "mealsServed",
376
+ },
377
+ {
378
+ label: msg("fields.options.facets.neighborhood", "Neighborhood"),
379
+ value: "neighborhood",
380
+ },
381
+ {
382
+ label: msg("fields.options.facets.paymentOptions", "Payment Options"),
383
+ value: "paymentOptions",
384
+ },
385
+ {
386
+ label: msg(
387
+ "fields.options.facets.pickupAndDeliveryServices",
388
+ "Pickup and Delivery Services"
389
+ ),
390
+ value: "pickupAndDeliveryServices",
391
+ },
392
+ {
393
+ label: msg("fields.options.facets.priceRange", "Price Range"),
394
+ value: "priceRange",
395
+ },
396
+ {
397
+ label: msg("fields.options.facets.services", "Services"),
398
+ value: "services",
399
+ },
400
+ {
401
+ label: msg("fields.options.facets.specialties", "Specialties"),
402
+ value: "specialities",
403
+ }
404
+ );
405
+ break;
406
+ case "healthcareFacility":
407
+ filterOptions = filterOptions.concat(
408
+ {
409
+ label: msg(
410
+ "fields.options.facets.acceptingNewPatients",
411
+ "Accepting New Patients"
412
+ ),
413
+ value: "acceptingNewPatients",
414
+ },
415
+ {
416
+ label: msg(
417
+ "fields.options.facets.conditionsTreated",
418
+ "Conditions Treated"
419
+ ),
420
+ value: "conditionsTreated",
421
+ },
422
+ {
423
+ label: msg(
424
+ "fields.options.facets.insuranceAccepted",
425
+ "Insurance Accepted"
426
+ ),
427
+ value: "insuranceAccepted",
428
+ },
429
+ {
430
+ label: msg("fields.options.facets.paymentOptions", "Payment Options"),
431
+ value: "paymentOptions",
432
+ },
433
+ {
434
+ label: msg("fields.options.facets.services", "Services"),
435
+ value: "services",
436
+ }
437
+ );
438
+ break;
439
+ case "healthcareProfessional":
440
+ filterOptions = filterOptions.concat(
441
+ {
442
+ label: msg(
443
+ "fields.options.facets.acceptingNewPatients",
444
+ "Accepting New Patients"
445
+ ),
446
+ value: "acceptingNewPatients",
447
+ },
448
+ {
449
+ label: msg(
450
+ "fields.options.facets.admittingHospitals",
451
+ "Admitting Hospitals"
452
+ ),
453
+ value: "admittingHospitals",
454
+ },
455
+ {
456
+ label: msg("fields.options.facets.brands", "Brands"),
457
+ value: "brands",
458
+ },
459
+ {
460
+ label: msg("fields.options.facets.certifications", "Certifications"),
461
+ value: "certifications",
462
+ },
463
+ {
464
+ label: msg(
465
+ "fields.options.facets.conditionsTreated",
466
+ "Conditions Treated"
467
+ ),
468
+ value: "conditionsTreated",
469
+ },
470
+ {
471
+ label: msg("fields.options.facets.degrees", "Degrees"),
472
+ value: "degrees",
473
+ },
474
+ {
475
+ label: msg("fields.options.facets.gender", "Gender"),
476
+ value: "gender",
477
+ },
478
+ {
479
+ label: msg(
480
+ "fields.options.facets.insuranceAccepted",
481
+ "Insurance Accepted"
482
+ ),
483
+ value: "insuranceAccepted",
484
+ },
485
+ {
486
+ label: msg("fields.options.facets.languages", "Languages"),
487
+ value: "languages",
488
+ },
489
+ {
490
+ label: msg("fields.options.facets.neighborhood", "Neighborhood"),
491
+ value: "neighborhood",
492
+ },
493
+ {
494
+ label: msg("fields.options.facets.officeName", "Office Name"),
495
+ value: "officeName",
496
+ },
497
+ {
498
+ label: msg("fields.options.facets.services", "Services"),
499
+ value: "services",
500
+ }
501
+ );
502
+ break;
503
+ case "hotel":
504
+ filterOptions = filterOptions.concat(
505
+ { label: msg("fields.options.facets.bar", "Bar"), value: "bar" },
506
+ {
507
+ label: msg("fields.options.facets.catsAllowed", "Cats Allowed"),
508
+ value: "catsAllowed",
509
+ },
510
+ {
511
+ label: msg("fields.options.facets.dogsAllowed", "Dogs Allowed"),
512
+ value: "dogsAllowed",
513
+ },
514
+ {
515
+ label: msg("fields.options.facets.parking", "Parking"),
516
+ value: "parking",
517
+ },
518
+ { label: msg("fields.options.facets.pools", "Pools"), value: "pools" }
519
+ );
520
+ break;
521
+ case "financialProfessional":
522
+ filterOptions = filterOptions.concat(
523
+ {
524
+ label: msg("fields.options.facets.certifications", "Certifications"),
525
+ value: "certifications",
526
+ },
527
+ {
528
+ label: msg("fields.options.facets.interests", "Interests"),
529
+ value: "interests",
530
+ },
531
+ {
532
+ label: msg("fields.options.facets.languages", "Languages"),
533
+ value: "languages",
534
+ },
535
+ {
536
+ label: msg("fields.options.facets.services", "Services"),
537
+ value: "services",
538
+ },
539
+ {
540
+ label: msg("fields.options.facets.specialties", "Specialties"),
541
+ value: "specialties",
542
+ },
543
+ {
544
+ label: msg(
545
+ "fields.options.facets.yearsOfExperience",
546
+ "Years of Experience"
547
+ ),
548
+ value: "yearsOfExperience",
549
+ }
550
+ );
551
+ break;
552
+ default:
553
+ break;
554
+ }
555
+ return filterOptions;
556
+ }
557
+
558
+ /**
559
+ * Returns true if the given filter is a "near" filter on the builtin.location field; otherwise,
560
+ * returns false.
561
+ */
562
+ const isLocationNearFilter = (filter: SelectableStaticFilter) =>
563
+ filter.filter.kind === "fieldValue" &&
564
+ filter.filter.fieldId === LOCATION_FIELD &&
565
+ filter.filter.matcher === Matcher.Near;
566
+
567
+ /**
568
+ * Returns true if the given filter is an "open at" filter on the builtin.hours field; otherwise,
569
+ * returns false.
570
+ */
571
+ const isOpenNowFilter = (filter: SelectableStaticFilter) =>
572
+ filter.filter.kind === "fieldValue" &&
573
+ filter.filter.fieldId === HOURS_FIELD &&
574
+ filter.filter.matcher === Matcher.OpenAt;
575
+
576
+ /**
577
+ * Builds a "near" static filter on the builtin.location field from a previous near filter
578
+ * value, with optional overrides for display name and radius
579
+ */
580
+ export function buildNearLocationFilterFromPrevious(
581
+ previousValue: NearFilterValue,
582
+ displayName?: string,
583
+ radius?: number
584
+ ): SelectableStaticFilter {
585
+ return {
586
+ selected: true,
587
+ displayName,
588
+ filter: {
589
+ kind: "fieldValue",
590
+ fieldId: LOCATION_FIELD,
591
+ value: {
592
+ ...previousValue,
593
+ radius: radius ?? previousValue.radius,
594
+ },
595
+ matcher: Matcher.Near,
596
+ },
597
+ };
598
+ }
599
+
600
+ /**
601
+ * Builds a "near" static filter on the builtin.location field from given coordinates, with
602
+ * optional radius and display name.
603
+ */
604
+ export function buildNearLocationFilterFromCoords(
605
+ lat: number,
606
+ lng: number,
607
+ radius: number,
608
+ displayName?: string
609
+ ): SelectableStaticFilter {
610
+ return {
611
+ selected: true,
612
+ displayName,
613
+ filter: {
614
+ kind: "fieldValue",
615
+ fieldId: LOCATION_FIELD,
616
+ value: {
617
+ lat,
618
+ lng,
619
+ radius,
620
+ },
621
+ matcher: Matcher.Near,
622
+ },
623
+ };
624
+ }
625
+
626
+ /**
627
+ * Builds an "equals" static filter on the builtin.location field from a previous equals filter,
628
+ * with a new display name.
629
+ */
630
+ export function buildEqualsLocationFilter(
631
+ filter: FieldValueFilter,
632
+ newDisplayName: string
633
+ ): SelectableStaticFilter {
634
+ return {
635
+ displayName: newDisplayName,
636
+ selected: true,
637
+ filter: {
638
+ kind: "fieldValue",
639
+ fieldId: filter.fieldId,
640
+ value: filter.value,
641
+ matcher: Matcher.Equals,
642
+ },
643
+ };
644
+ }
645
+
646
+ /**
647
+ * Helper function to iterate through a list of static filters and update all near filters on the
648
+ * location field to have the new radius.
649
+ */
650
+ export function updateRadiusInNearFiltersOnLocationField(
651
+ filters: SelectableStaticFilter[],
652
+ newRadius: number
653
+ ): SelectableStaticFilter[] {
654
+ return filters.map((filter) => {
655
+ if (isLocationNearFilter(filter)) {
656
+ const previousFilter = filter.filter as FieldValueStaticFilter;
657
+ const previousValue = previousFilter.value as NearFilterValue;
658
+ return {
659
+ ...filter,
660
+ filter: {
661
+ ...previousFilter,
662
+ value: {
663
+ ...previousValue,
664
+ radius: newRadius,
665
+ },
666
+ },
667
+ } as SelectableStaticFilter;
668
+ }
669
+
670
+ return filter;
671
+ });
672
+ }
673
+
674
+ /**
675
+ * Helper function to iterate through a list of static filters and set the selected field to
676
+ * false on any Open Now filters.
677
+ */
678
+ export function deselectOpenNowFilters(
679
+ filters: SelectableStaticFilter[]
680
+ ): SelectableStaticFilter[] {
681
+ return filters.map((filter) => {
682
+ if (isOpenNowFilter(filter)) {
683
+ return {
684
+ ...filter,
685
+ selected: false,
686
+ };
687
+ }
688
+
689
+ return filter;
690
+ });
691
+ }