@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,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
+ };