@yext/visual-editor 1.4.14 → 2.0.0-beta.10

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 (234) hide show
  1. package/dist/SectionLibraryVisualEditorProvider-DN65KSX7.js +119824 -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 +298 -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 +499 -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 +277 -0
  31. package/dist/cli/yextve.js +16992 -0
  32. package/dist/createYextFieldTransforms-CrIkiJ_X.d.ts +2157 -0
  33. package/dist/index.d.ts +534 -6352
  34. package/dist/locales/page/cs/visual-editor.json +85 -0
  35. package/dist/locales/page/da/visual-editor.json +73 -0
  36. package/dist/locales/page/de/visual-editor.json +73 -0
  37. package/dist/locales/page/en/visual-editor.json +73 -0
  38. package/dist/locales/page/en-GB/visual-editor.json +73 -0
  39. package/dist/locales/page/es/visual-editor.json +79 -0
  40. package/dist/locales/page/et/visual-editor.json +73 -0
  41. package/dist/locales/page/fi/visual-editor.json +73 -0
  42. package/dist/locales/page/fr/visual-editor.json +79 -0
  43. package/dist/locales/page/hr/visual-editor.json +79 -0
  44. package/dist/locales/page/hu/visual-editor.json +73 -0
  45. package/dist/locales/page/it/visual-editor.json +79 -0
  46. package/dist/locales/page/ja/visual-editor.json +73 -0
  47. package/dist/locales/page/lt/visual-editor.json +85 -0
  48. package/dist/locales/page/lv/visual-editor.json +77 -0
  49. package/dist/locales/page/nb/visual-editor.json +73 -0
  50. package/dist/locales/page/nl/visual-editor.json +73 -0
  51. package/dist/locales/page/pl/visual-editor.json +85 -0
  52. package/dist/locales/page/pt/visual-editor.json +79 -0
  53. package/dist/locales/page/ro/visual-editor.json +79 -0
  54. package/dist/locales/page/sk/visual-editor.json +85 -0
  55. package/dist/locales/page/sv/visual-editor.json +73 -0
  56. package/dist/locales/page/tr/visual-editor.json +73 -0
  57. package/dist/locales/page/zh/visual-editor.json +73 -0
  58. package/dist/locales/page/zh-TW/visual-editor.json +73 -0
  59. package/dist/locales/platform/cs/visual-editor.json +651 -0
  60. package/dist/locales/platform/da/visual-editor.json +625 -0
  61. package/dist/locales/platform/de/visual-editor.json +625 -0
  62. package/dist/locales/platform/en/visual-editor.json +625 -0
  63. package/dist/locales/platform/en-GB/visual-editor.json +625 -0
  64. package/dist/locales/platform/es/visual-editor.json +638 -0
  65. package/dist/locales/platform/et/visual-editor.json +625 -0
  66. package/dist/locales/platform/fi/visual-editor.json +625 -0
  67. package/dist/locales/platform/fr/visual-editor.json +638 -0
  68. package/dist/locales/platform/hr/visual-editor.json +638 -0
  69. package/dist/locales/platform/hu/visual-editor.json +625 -0
  70. package/dist/locales/platform/it/visual-editor.json +638 -0
  71. package/dist/locales/platform/ja/visual-editor.json +625 -0
  72. package/dist/locales/platform/lt/visual-editor.json +651 -0
  73. package/dist/locales/platform/lv/visual-editor.json +633 -0
  74. package/dist/locales/platform/nb/visual-editor.json +625 -0
  75. package/dist/locales/platform/nl/visual-editor.json +625 -0
  76. package/dist/locales/platform/pl/visual-editor.json +651 -0
  77. package/dist/locales/platform/pt/visual-editor.json +638 -0
  78. package/dist/locales/platform/ro/visual-editor.json +638 -0
  79. package/dist/locales/platform/sk/visual-editor.json +651 -0
  80. package/dist/locales/platform/sv/visual-editor.json +625 -0
  81. package/dist/locales/platform/tr/visual-editor.json +625 -0
  82. package/dist/locales/platform/zh/visual-editor.json +625 -0
  83. package/dist/locales/platform/zh-TW/visual-editor.json +625 -0
  84. package/dist/plugin/internal/layoutGeneration/limits.d.ts +28 -0
  85. package/dist/plugin/internal/sectionLibraryValidation/builtInTranslationResources.d.ts +3 -0
  86. package/dist/plugin/internal/sectionLibraryValidation/stages/api/api.d.ts +7 -0
  87. package/dist/plugin/internal/sectionLibraryValidation/stages/api/libraryMetadata.d.ts +7 -0
  88. package/dist/plugin/internal/sectionLibraryValidation/stages/code/importRules.d.ts +13 -0
  89. package/dist/plugin/internal/sectionLibraryValidation/stages/code/validateCode.d.ts +10 -0
  90. package/dist/plugin/internal/sectionLibraryValidation/stages/code/xssRules.d.ts +7 -0
  91. package/dist/plugin/internal/sectionLibraryValidation/stages/structure/structure.d.ts +7 -0
  92. package/dist/plugin/internal/sectionLibraryValidation/types.d.ts +48 -0
  93. package/dist/plugin/internal/sectionLibraryValidation/validateSectionLibrary.d.ts +8 -0
  94. package/dist/plugin/internal/sectionLibraryValidation/validationError.d.ts +6 -0
  95. package/dist/plugin/plugin.js +7013 -5873
  96. package/dist/plugin/types/entityFields.d.ts +21 -0
  97. package/dist/plugin/types/generationPrompts.d.ts +19 -0
  98. package/dist/plugin/types/generationSettings.d.ts +12 -0
  99. package/dist/plugin/types/images.d.ts +62 -0
  100. package/dist/plugin/types/sectionLibrary.d.ts +101 -0
  101. package/dist/plugin/types/types.d.ts +204 -0
  102. package/dist/plugin/types/videos.d.ts +24 -0
  103. package/dist/plugin/utils/i18n/locales.d.ts +5 -0
  104. package/dist/plugin/utils/i18n/translationResources.d.ts +41 -0
  105. package/dist/plugin/utils/normalizeLocale.d.ts +8 -0
  106. package/dist/plugin/utils/plainText.d.ts +6 -0
  107. package/dist/plugin/vite-plugin/index.d.ts +2 -0
  108. package/dist/plugin/vite-plugin/layout-generation/generationLogger.d.ts +5 -0
  109. package/dist/plugin/vite-plugin/layout-generation/generationReports.d.ts +13 -0
  110. package/dist/plugin/vite-plugin/layout-generation/middleware.d.ts +14 -0
  111. package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +9 -0
  112. package/dist/plugin/vite-plugin/layout-generation/prompts.d.ts +17 -0
  113. package/dist/plugin/vite-plugin/layout-generation/settings.d.ts +3 -0
  114. package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +20 -0
  115. package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
  116. package/dist/plugin/vite-plugin/local-editor/data.d.ts +12 -0
  117. package/dist/plugin/vite-plugin/local-editor/entityFields.d.ts +13 -0
  118. package/dist/plugin/vite-plugin/local-editor/fixtureData.d.ts +12 -0
  119. package/dist/plugin/vite-plugin/local-editor/generatedFiles.d.ts +33 -0
  120. package/dist/plugin/vite-plugin/local-editor/server.d.ts +34 -0
  121. package/dist/plugin/vite-plugin/local-editor/types.d.ts +125 -0
  122. package/dist/plugin/vite-plugin/local-editor/utils.d.ts +16 -0
  123. package/dist/plugin/vite-plugin/plugin.d.ts +8 -0
  124. package/dist/plugin/vite-plugin/section-library/migrationRegistry.d.ts +6 -0
  125. package/dist/plugin/vite-plugin/section-library/sectionFrontmatter.d.ts +3 -0
  126. package/dist/plugin/vite-plugin/section-library/sectionLibraryGenerator.d.ts +21 -0
  127. package/dist/plugin/vite-plugin/section-library/sharedComponentRegistry.d.ts +16 -0
  128. package/dist/section-library-support.js +178 -0
  129. package/dist/sectionLibrarySupport.d.ts +703 -0
  130. package/dist/style.css +1 -1
  131. package/dist/visual-editor-6mKs9VUe.js +842 -0
  132. package/dist/visual-editor-BK6fTU7k.js +804 -0
  133. package/dist/visual-editor-BXYlpe7B.js +145 -0
  134. package/dist/visual-editor-BruRrJYN.js +804 -0
  135. package/dist/visual-editor-Bs3wAslG.js +804 -0
  136. package/dist/visual-editor-Bxy81Ezy.js +145 -0
  137. package/dist/visual-editor-C0vq2BRM.js +145 -0
  138. package/dist/visual-editor-C9TLeAzP.js +804 -0
  139. package/dist/visual-editor-CCgmYV5S.js +169 -0
  140. package/dist/visual-editor-CERViyTJ.js +145 -0
  141. package/dist/visual-editor-CHWtMtlu.js +823 -0
  142. package/dist/visual-editor-CcfUKpnd.js +804 -0
  143. package/dist/visual-editor-CjORnP1D.js +169 -0
  144. package/dist/visual-editor-ClC6hoz3.js +804 -0
  145. package/dist/visual-editor-CmomGJB8.js +157 -0
  146. package/dist/visual-editor-CtQwadxQ.js +842 -0
  147. package/dist/visual-editor-Cymg8ID2.js +169 -0
  148. package/dist/visual-editor-D2Hk1nhM.js +145 -0
  149. package/dist/visual-editor-D7VeTRK_.js +816 -0
  150. package/dist/visual-editor-D8MRFn5x.js +157 -0
  151. package/dist/visual-editor-DOXtCqRv.js +145 -0
  152. package/dist/visual-editor-DQEd3xwY.js +145 -0
  153. package/dist/visual-editor-DTE5kxrA.js +804 -0
  154. package/dist/visual-editor-DUngIOnE.js +157 -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-DjTEbi-1.js +842 -0
  160. package/dist/visual-editor-DjdqpJU-.js +145 -0
  161. package/dist/visual-editor-DkHhrFsX.js +804 -0
  162. package/dist/visual-editor-DtL-Zuv_.js +804 -0
  163. package/dist/visual-editor-Duishbsa.js +842 -0
  164. package/dist/visual-editor-DvuH3jyL.js +157 -0
  165. package/dist/visual-editor-LXMNWXry.js +823 -0
  166. package/dist/visual-editor-QpGupjY5.js +823 -0
  167. package/dist/visual-editor-TfVDfO5_.js +145 -0
  168. package/dist/visual-editor-W_ZDmMFn.js +145 -0
  169. package/dist/visual-editor-_TatCCAS.js +804 -0
  170. package/dist/visual-editor-b7ALusk8.js +145 -0
  171. package/dist/visual-editor-erGXf3kS.js +157 -0
  172. package/dist/visual-editor-gEaWoNRu.js +804 -0
  173. package/dist/visual-editor-gjpr-NAN.js +804 -0
  174. package/dist/visual-editor-qJW0uCiQ.js +804 -0
  175. package/dist/visual-editor-sOPDMkOR.js +823 -0
  176. package/dist/visual-editor-tPb7n5l8.js +823 -0
  177. package/dist/visual-editor-vomNdlNO.js +804 -0
  178. package/dist/visual-editor-xnDHZFuO.js +153 -0
  179. package/dist/visual-editor-yiWZqIH0.js +157 -0
  180. package/dist/visual-editor-zKhC7_0C.js +823 -0
  181. package/dist/visual-editor.css +1 -0
  182. package/dist/visual-editor.js +18578 -137536
  183. package/package.json +50 -26
  184. package/dist/editor.css +0 -1
  185. package/dist/visual-editor-6pnSx-yp.js +0 -223
  186. package/dist/visual-editor-9ZW3nq5u.js +0 -247
  187. package/dist/visual-editor-B1RXDqNi.js +0 -1063
  188. package/dist/visual-editor-BAahiZ1l.js +0 -223
  189. package/dist/visual-editor-BC2LjdoF.js +0 -223
  190. package/dist/visual-editor-BPnfBfk1.js +0 -1051
  191. package/dist/visual-editor-BQiE5eVW.js +0 -1051
  192. package/dist/visual-editor-BTv-6Pnk.js +0 -1051
  193. package/dist/visual-editor-BUWp03gX.js +0 -235
  194. package/dist/visual-editor-Bb3c6iGV.js +0 -223
  195. package/dist/visual-editor-BipczqTj.js +0 -1075
  196. package/dist/visual-editor-BlIUd_n_.js +0 -1051
  197. package/dist/visual-editor-BoPLXEu2.js +0 -223
  198. package/dist/visual-editor-Bzmpi_9a.js +0 -1063
  199. package/dist/visual-editor-C38IiBTR.js +0 -235
  200. package/dist/visual-editor-C9tacnim.js +0 -247
  201. package/dist/visual-editor-CVa3iu5h.js +0 -1051
  202. package/dist/visual-editor-CXTL8Ik0.js +0 -1051
  203. package/dist/visual-editor-CYeahjFX.js +0 -231
  204. package/dist/visual-editor-CZ2SM6Jc.js +0 -1063
  205. package/dist/visual-editor-CZDmQI-A.js +0 -1063
  206. package/dist/visual-editor-C_cHJ6BN.js +0 -1051
  207. package/dist/visual-editor-Cf3nFbw3.js +0 -235
  208. package/dist/visual-editor-CiR0metz.js +0 -1051
  209. package/dist/visual-editor-CoX_NnS-.js +0 -223
  210. package/dist/visual-editor-Cu8II23Y.js +0 -223
  211. package/dist/visual-editor-CvXFxocc.js +0 -1063
  212. package/dist/visual-editor-Cxu6nkib.js +0 -1051
  213. package/dist/visual-editor-D-3VVfjR.js +0 -223
  214. package/dist/visual-editor-D-ktbg7q.js +0 -223
  215. package/dist/visual-editor-D9G5eAAU.js +0 -1051
  216. package/dist/visual-editor-D9MrqEya.js +0 -223
  217. package/dist/visual-editor-DAKXBbjV.js +0 -1075
  218. package/dist/visual-editor-DBmJk7ZR.js +0 -235
  219. package/dist/visual-editor-DG-c2LU9.js +0 -1051
  220. package/dist/visual-editor-DI_Vk989.js +0 -1051
  221. package/dist/visual-editor-DOOYgnjP.js +0 -235
  222. package/dist/visual-editor-DRx3Ax_O.js +0 -1075
  223. package/dist/visual-editor-DZ66sria.js +0 -1051
  224. package/dist/visual-editor-DZTPhYcr.js +0 -247
  225. package/dist/visual-editor-DcH7WJVI.js +0 -223
  226. package/dist/visual-editor-DdYXgEbR.js +0 -1059
  227. package/dist/visual-editor-DeWzgcue.js +0 -1063
  228. package/dist/visual-editor-Dm5ZNn8C.js +0 -223
  229. package/dist/visual-editor-DqLCIWPQ.js +0 -1051
  230. package/dist/visual-editor-NoU28r5Y.js +0 -223
  231. package/dist/visual-editor-WjrJ9nPc.js +0 -235
  232. package/dist/visual-editor-_h-sdbID.js +0 -223
  233. package/dist/visual-editor-r4gSQqFM.js +0 -1075
  234. package/dist/visual-editor-ujQ29mao.js +0 -247
@@ -0,0 +1,507 @@
1
+ import { PuckComponent, Slot } from "@puckeditor/core";
2
+ import React from "react";
3
+ import { useCardContext } from "../../../hooks/useCardContext.tsx";
4
+ import {
5
+ TemplatePropsContext,
6
+ useTemplateProps,
7
+ } from "../../../hooks/useDocument.tsx";
8
+ import { useGetCardSlots } from "../../../hooks/useGetCardSlots.tsx";
9
+ import { msg } from "../../../utils/i18n/platform.ts";
10
+ import {
11
+ backgroundColors,
12
+ ThemeColor,
13
+ } from "../../../utils/themeConfigOptions.ts";
14
+ import { deepMerge } from "../../../utils/themeResolver.ts";
15
+ import { bindSlots } from "../../../utils/cardSlots/bindSlots.ts";
16
+ import {
17
+ mergeMeta,
18
+ resolveUrlTemplateOfChild,
19
+ } from "../../../utils/urls/resolveUrlTemplate.ts";
20
+ import { TranslatableString } from "../../../types/types.ts";
21
+ import { Background } from "../../atoms/background.tsx";
22
+ import { MaybeLink } from "../../atoms/maybeLink.tsx";
23
+ import { AddressProps } from "../../contentBlocks/Address.tsx";
24
+ import { HeadingTextProps } from "../../contentBlocks/HeadingText.tsx";
25
+ import { HoursStatusProps } from "../../contentBlocks/HoursStatus.tsx";
26
+ import { PhoneProps } from "../../contentBlocks/Phone.tsx";
27
+ import {
28
+ DirectoryChildReference,
29
+ getSortedDirectoryChildren,
30
+ resolveDirectoryChildFromReference,
31
+ useDirectoryChildren,
32
+ } from "./directoryChildReference.tsx";
33
+ import { YextComponentConfig, YextFields } from "../../../fields/fields.ts";
34
+ import { YextEntityField } from "../../../editor/yextEntityFieldUtils.ts";
35
+ import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
36
+ import { normalizeSlug } from "../../../utils/slugifier.ts";
37
+
38
+ const defaultCardTitle: YextEntityField<TranslatableString> = {
39
+ field: "name",
40
+ constantValue: { defaultValue: "[[name]]" },
41
+ constantValueEnabled: false,
42
+ };
43
+
44
+ // DirectoryCardLinkOverrideField is a yes/no toggle
45
+ // that displays an entity field selector when set to yes.
46
+ export type DirectoryCardLinkOverrideFieldValue =
47
+ YextEntityField<TranslatableString> & {
48
+ enabled: boolean;
49
+ normalizeLink: boolean;
50
+ };
51
+
52
+ export const createDefaultLinkOverrideFieldValue =
53
+ (): DirectoryCardLinkOverrideFieldValue => ({
54
+ enabled: false,
55
+ normalizeLink: false,
56
+ field: "",
57
+ constantValue: {
58
+ defaultValue: "",
59
+ hasLocalizedValue: "true",
60
+ },
61
+ constantValueEnabled: false,
62
+ });
63
+
64
+ const isHeadingTextField = (
65
+ value: unknown
66
+ ): value is HeadingTextProps["data"]["text"] =>
67
+ typeof value === "object" &&
68
+ value !== null &&
69
+ ("field" in value || "constantValue" in value);
70
+
71
+ export const defaultDirectoryCardSlotData = (
72
+ id: string,
73
+ index: number,
74
+ childRef?: DirectoryChildReference,
75
+ existingCardStyle?: DirectoryCardProps["styles"],
76
+ existingSlots?: DirectoryCardProps["slots"]
77
+ ) => {
78
+ const existingHeadingText =
79
+ existingSlots?.HeadingSlot?.[0]?.props?.data?.text;
80
+ const existingHeadingStyles = existingSlots?.HeadingSlot?.[0]?.props?.styles;
81
+ const existingAddressStyles = existingSlots?.AddressSlot?.[0]?.props?.styles;
82
+ const existingPhoneStyles = existingSlots?.PhoneSlot?.[0]?.props?.styles;
83
+ const existingHoursStyles = existingSlots?.HoursSlot?.[0]?.props?.styles;
84
+ const headingTextField = isHeadingTextField(existingHeadingText)
85
+ ? existingHeadingText
86
+ : {
87
+ field: "",
88
+ constantValue: existingHeadingText ?? defaultCardTitle.constantValue,
89
+ constantValueEnabled: true,
90
+ };
91
+
92
+ return {
93
+ type: "DirectoryCard",
94
+ props: {
95
+ id,
96
+ index,
97
+ data: {
98
+ cardTitle: defaultCardTitle,
99
+ linkOverride: createDefaultLinkOverrideFieldValue(),
100
+ showAddress: true,
101
+ showHoursStatus: true,
102
+ showPhoneNumber: true,
103
+ },
104
+ styles: {
105
+ backgroundColor:
106
+ existingCardStyle?.backgroundColor ??
107
+ backgroundColors.background1.value,
108
+ },
109
+ slots: {
110
+ HeadingSlot: [
111
+ {
112
+ type: "HeadingTextSlot",
113
+ props: {
114
+ ...(id && { id: `${id}-heading` }),
115
+ data: {
116
+ text: headingTextField,
117
+ },
118
+ styles: {
119
+ ...existingHeadingStyles,
120
+ level: existingHeadingStyles?.level ?? 3,
121
+ align: existingHeadingStyles?.align ?? "left",
122
+ },
123
+ } satisfies HeadingTextProps,
124
+ },
125
+ ],
126
+ AddressSlot: [
127
+ {
128
+ type: "AddressSlot",
129
+ props: {
130
+ ...(id && { id: `${id}-address` }),
131
+ data: {
132
+ address: {
133
+ field: "address",
134
+ constantValue: {
135
+ line1: "",
136
+ city: "",
137
+ postalCode: "",
138
+ countryCode: "",
139
+ },
140
+ },
141
+ },
142
+ styles: {
143
+ ...existingAddressStyles,
144
+ showRegion: existingAddressStyles?.showRegion ?? true,
145
+ showCountry: existingAddressStyles?.showCountry ?? true,
146
+ showGetDirectionsLink:
147
+ existingAddressStyles?.showGetDirectionsLink ?? false,
148
+ ctaVariant: existingAddressStyles?.ctaVariant ?? "link",
149
+ },
150
+ parentData: {
151
+ field: "profile.address",
152
+ },
153
+ } satisfies AddressProps,
154
+ },
155
+ ],
156
+ PhoneSlot: [
157
+ {
158
+ type: "PhoneSlot",
159
+ props: {
160
+ ...(id && { id: `${id}-phone` }),
161
+ data: {
162
+ number: {
163
+ constantValue: "",
164
+ field: "mainPhone",
165
+ },
166
+ label: {
167
+ constantValue: "",
168
+ hasLocalizedValue: "true",
169
+ field: "",
170
+ },
171
+ },
172
+ styles: {
173
+ ...existingPhoneStyles,
174
+ phoneFormat: existingPhoneStyles?.phoneFormat ?? "domestic",
175
+ includePhoneHyperlink:
176
+ existingPhoneStyles?.includePhoneHyperlink ?? true,
177
+ includeIcon: existingPhoneStyles?.includeIcon ?? false,
178
+ },
179
+ parentData: {
180
+ field: "profile.mainPhone",
181
+ },
182
+ } satisfies PhoneProps,
183
+ },
184
+ ],
185
+ HoursSlot: [
186
+ {
187
+ type: "HoursStatusSlot",
188
+ props: {
189
+ ...(id && { id: `${id}-hours` }),
190
+ data: {
191
+ hours: {
192
+ constantValue: {},
193
+ field: "hours",
194
+ },
195
+ },
196
+ styles: {
197
+ ...existingHoursStyles,
198
+ dayOfWeekFormat: existingHoursStyles?.dayOfWeekFormat ?? "long",
199
+ showDayNames: existingHoursStyles?.showDayNames ?? true,
200
+ showCurrentStatus:
201
+ existingHoursStyles?.showCurrentStatus ?? true,
202
+ className:
203
+ existingHoursStyles?.className ??
204
+ "mb-2 font-semibold font-body-fontFamily text-body-fontSize h-full",
205
+ },
206
+ parentData: {
207
+ field: "profile.hours",
208
+ },
209
+ } satisfies HoursStatusProps,
210
+ },
211
+ ],
212
+ },
213
+ ...(childRef
214
+ ? {
215
+ parentData: {
216
+ childRef,
217
+ },
218
+ }
219
+ : {}),
220
+ },
221
+ };
222
+ };
223
+
224
+ export type DirectoryCardProps = {
225
+ /** @internal */
226
+ field?: string;
227
+
228
+ data: {
229
+ cardTitle: YextEntityField<TranslatableString>;
230
+ linkOverride: DirectoryCardLinkOverrideFieldValue;
231
+ showAddress: boolean;
232
+ showHoursStatus: boolean;
233
+ showPhoneNumber: boolean;
234
+ };
235
+
236
+ /** Styling for all the cards. */
237
+ styles: {
238
+ /** The background color of each directory card */
239
+ backgroundColor?: ThemeColor;
240
+ };
241
+
242
+ /** @internal */
243
+ slots: {
244
+ HeadingSlot: Slot;
245
+ AddressSlot: Slot;
246
+ PhoneSlot: Slot;
247
+ HoursSlot: Slot;
248
+ };
249
+
250
+ /** @internal */
251
+ parentData?: {
252
+ childRef: DirectoryChildReference;
253
+ };
254
+
255
+ /** @internal */
256
+ index?: number;
257
+ };
258
+
259
+ const DirectoryCardComponent: PuckComponent<DirectoryCardProps> = (props) => {
260
+ const { data, styles, slots, parentData, index, puck } = props;
261
+ const { document: streamDocument, relativePrefixToRoot } = useTemplateProps();
262
+ const directoryChildrenFromContext = useDirectoryChildren();
263
+ const sortedDirectoryChildren = React.useMemo(
264
+ () =>
265
+ directoryChildrenFromContext.length
266
+ ? directoryChildrenFromContext
267
+ : getSortedDirectoryChildren(streamDocument.dm_directoryChildren),
268
+ [directoryChildrenFromContext, streamDocument.dm_directoryChildren]
269
+ );
270
+ const resolvedChild = React.useMemo(
271
+ () =>
272
+ resolveDirectoryChildFromReference(
273
+ sortedDirectoryChildren,
274
+ parentData?.childRef
275
+ ),
276
+ [parentData?.childRef, sortedDirectoryChildren]
277
+ );
278
+ // Give nested slots a child-scoped document context instead of duplicating
279
+ // child values into each slot's parentData.
280
+ const childDocumentContext = React.useMemo(
281
+ () =>
282
+ resolvedChild
283
+ ? {
284
+ document: {
285
+ ...streamDocument,
286
+ ...mergeMeta(resolvedChild, streamDocument),
287
+ },
288
+ relativePrefixToRoot,
289
+ }
290
+ : {
291
+ document: streamDocument,
292
+ relativePrefixToRoot,
293
+ },
294
+ [resolvedChild, relativePrefixToRoot, streamDocument]
295
+ );
296
+
297
+ const linkOverrideValue = data.linkOverride.enabled
298
+ ? resolveComponentData(
299
+ data.linkOverride,
300
+ streamDocument.locale || "en",
301
+ childDocumentContext.document
302
+ )
303
+ : "";
304
+ const resolvedLinkOverride =
305
+ typeof linkOverrideValue === "string"
306
+ ? data.linkOverride.normalizeLink
307
+ ? normalizeSlug(linkOverrideValue)
308
+ : linkOverrideValue
309
+ : "";
310
+
311
+ // If there is a value for link override, it should be used.
312
+ // Otherwise, construct the url based on the entity page's url template.
313
+ let resolvedUrl: undefined | string;
314
+ if (resolvedLinkOverride) {
315
+ resolvedUrl = resolvedLinkOverride;
316
+ } else if (resolvedChild) {
317
+ resolvedUrl = resolveUrlTemplateOfChild(
318
+ resolvedChild,
319
+ streamDocument,
320
+ relativePrefixToRoot
321
+ );
322
+ }
323
+
324
+ const { sharedCardProps, setSharedCardProps } = useCardContext<{
325
+ cardStyles: DirectoryCardProps["styles"];
326
+ slotStyles: Record<string, DirectoryCardProps["styles"]>;
327
+ }>();
328
+
329
+ const { slotStyles, getPuck, slotProps } =
330
+ useGetCardSlots<DirectoryCardProps>(props.id);
331
+
332
+ // sharedCardProps useEffect
333
+ // When the context changes, dispatch an update to sync the changes to puck
334
+ React.useEffect(() => {
335
+ if (!puck.isEditing || !sharedCardProps || !getPuck) {
336
+ return;
337
+ }
338
+
339
+ if (
340
+ JSON.stringify(sharedCardProps?.cardStyles) === JSON.stringify(styles) &&
341
+ JSON.stringify(slotStyles) === JSON.stringify(sharedCardProps?.slotStyles)
342
+ ) {
343
+ return;
344
+ }
345
+
346
+ const { dispatch, getSelectorForId } = getPuck();
347
+ const selector = getSelectorForId(props.id);
348
+ if (!selector || !slotProps) {
349
+ return;
350
+ }
351
+
352
+ const newSlotData: DirectoryCardProps["slots"] = {
353
+ HeadingSlot: [],
354
+ PhoneSlot: [],
355
+ HoursSlot: [],
356
+ AddressSlot: [],
357
+ };
358
+ Object.entries(slotProps).forEach(([key, value]) => {
359
+ const nextSlotValue = deepMerge(
360
+ { props: { styles: { ...sharedCardProps?.slotStyles?.[key] } } },
361
+ value[0]
362
+ );
363
+ newSlotData[key as keyof DirectoryCardProps["slots"]] = [
364
+ {
365
+ ...nextSlotValue,
366
+ },
367
+ ];
368
+ });
369
+
370
+ // oxlint-disable-next-line no-unused-vars: remove props.puck before dispatching to avoid writing it to the saved data
371
+ const { puck: _, editMode: __, ...otherProps } = props;
372
+ dispatch({
373
+ type: "replace" as const,
374
+ destinationIndex: selector.index,
375
+ destinationZone: selector.zone,
376
+ data: {
377
+ type: "DirectoryCard",
378
+ props: {
379
+ ...otherProps,
380
+ data: props.data,
381
+ styles: {
382
+ backgroundColor:
383
+ sharedCardProps?.cardStyles.backgroundColor ||
384
+ backgroundColors.background1.value,
385
+ },
386
+ slots: newSlotData,
387
+ } satisfies DirectoryCardProps,
388
+ },
389
+ });
390
+ }, [sharedCardProps]);
391
+
392
+ // styles and slotStyles useEffect
393
+ // When the card's shared props or the card's slots' shared props change, update the context
394
+ React.useEffect(() => {
395
+ if (!puck.isEditing || !slotProps) {
396
+ return;
397
+ }
398
+
399
+ if (
400
+ JSON.stringify(sharedCardProps?.cardStyles) === JSON.stringify(styles) &&
401
+ JSON.stringify(sharedCardProps?.slotStyles) === JSON.stringify(slotStyles)
402
+ ) {
403
+ return;
404
+ }
405
+
406
+ setSharedCardProps({
407
+ cardStyles: styles,
408
+ slotStyles: slotStyles,
409
+ });
410
+ }, [styles, slotStyles]);
411
+
412
+ return (
413
+ <Background
414
+ className="h-full flex flex-col p-8 border border-gray-400 rounded gap-4"
415
+ background={styles.backgroundColor}
416
+ >
417
+ <TemplatePropsContext.Provider value={childDocumentContext}>
418
+ <div className="mb-2 max-w-full w-full">
419
+ <MaybeLink
420
+ eventName={`link${index}`}
421
+ alwaysHideCaret={true}
422
+ className="text-wrap break-words block w-full"
423
+ href={resolvedUrl}
424
+ disabled={puck.isEditing}
425
+ >
426
+ <slots.HeadingSlot style={{ height: "auto" }} />
427
+ </MaybeLink>
428
+ </div>
429
+ {data.showHoursStatus && resolvedChild?.hours && (
430
+ <slots.HoursSlot style={{ height: "auto" }} />
431
+ )}
432
+ {data.showPhoneNumber && resolvedChild?.mainPhone && (
433
+ <slots.PhoneSlot style={{ height: "auto" }} />
434
+ )}
435
+ {data.showAddress && resolvedChild?.address && (
436
+ <div className="font-body-fontFamily font-body-fontWeight text-body-fontSize">
437
+ <slots.AddressSlot style={{ height: "auto" }} />
438
+ </div>
439
+ )}
440
+ </TemplatePropsContext.Provider>
441
+ </Background>
442
+ );
443
+ };
444
+
445
+ const directoryCardFields: YextFields<DirectoryCardProps> = {
446
+ // The data fields are configured by directoryCardsSource.mappingFields in DirectoryWrapper.tsx.
447
+ data: {
448
+ type: "custom",
449
+ visible: false,
450
+ render: () => <></>,
451
+ },
452
+ styles: {
453
+ type: "object",
454
+ label: msg("fields.styles", "Styles"),
455
+ objectFields: {
456
+ backgroundColor: {
457
+ type: "basicSelector",
458
+ label: msg("fields.backgroundColor", "Background Color"),
459
+ options: "BACKGROUND_COLOR",
460
+ },
461
+ },
462
+ },
463
+ slots: {
464
+ type: "object",
465
+ objectFields: {
466
+ HeadingSlot: { type: "slot" },
467
+ AddressSlot: { type: "slot" },
468
+ PhoneSlot: { type: "slot" },
469
+ HoursSlot: { type: "slot" },
470
+ },
471
+ visible: false,
472
+ },
473
+ };
474
+
475
+ export const DirectoryCard: YextComponentConfig<DirectoryCardProps> = {
476
+ label: msg("slots.directoryCard", "Directory Card"),
477
+ fields: directoryCardFields,
478
+ defaultProps: {
479
+ data: {
480
+ cardTitle: defaultCardTitle,
481
+ linkOverride: createDefaultLinkOverrideFieldValue(),
482
+ showAddress: true,
483
+ showHoursStatus: true,
484
+ showPhoneNumber: true,
485
+ },
486
+ styles: {
487
+ backgroundColor: backgroundColors.background1.value,
488
+ },
489
+ slots: {
490
+ HeadingSlot: [],
491
+ PhoneSlot: [],
492
+ HoursSlot: [],
493
+ AddressSlot: [],
494
+ },
495
+ },
496
+ resolveData: (data) =>
497
+ bindSlots(data, {
498
+ HeadingSlot:
499
+ typeof data.props.data?.cardTitle === "string"
500
+ ? ({
501
+ field: data.props.field ?? "name",
502
+ text: data.props.data.cardTitle,
503
+ } satisfies HeadingTextProps["parentData"])
504
+ : undefined,
505
+ }),
506
+ render: (props) => <DirectoryCardComponent {...props} />,
507
+ };