@yext/visual-editor 1.4.11 → 2.0.0-beta.2

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-fUGYIhyC.js +108668 -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 +16895 -0
  32. package/dist/index.d.ts +542 -6311
  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-2Y77HmqL.js +718 -0
  123. package/dist/visual-editor-7P4U2T4q.js +694 -0
  124. package/dist/visual-editor-AXgoU7J5.js +694 -0
  125. package/dist/visual-editor-B-8ROr4n.js +694 -0
  126. package/dist/visual-editor-BDozYwKy.js +702 -0
  127. package/dist/visual-editor-BGMk-qTN.js +718 -0
  128. package/dist/visual-editor-BIqNAAcB.js +718 -0
  129. package/dist/visual-editor-BPI_dyYw.js +694 -0
  130. package/dist/visual-editor-BXYlpe7B.js +145 -0
  131. package/dist/visual-editor-Bkgub-3w.js +694 -0
  132. package/dist/visual-editor-Bo-tmHFc.js +694 -0
  133. package/dist/visual-editor-BuYrclmi.js +706 -0
  134. package/dist/visual-editor-Bxy81Ezy.js +145 -0
  135. package/dist/visual-editor-C0vq2BRM.js +145 -0
  136. package/dist/visual-editor-CCLIvOCf.js +694 -0
  137. package/dist/visual-editor-CCgmYV5S.js +169 -0
  138. package/dist/visual-editor-CE2J5pWp.js +694 -0
  139. package/dist/visual-editor-CERViyTJ.js +145 -0
  140. package/dist/visual-editor-CY2YjlX9.js +706 -0
  141. package/dist/visual-editor-CcuA4NSE.js +694 -0
  142. package/dist/visual-editor-Cd8yeRID.js +718 -0
  143. package/dist/visual-editor-CjORnP1D.js +169 -0
  144. package/dist/visual-editor-CmomGJB8.js +157 -0
  145. package/dist/visual-editor-CpCR_bSp.js +706 -0
  146. package/dist/visual-editor-Cymg8ID2.js +169 -0
  147. package/dist/visual-editor-D2Hk1nhM.js +145 -0
  148. package/dist/visual-editor-D8MRFn5x.js +157 -0
  149. package/dist/visual-editor-D96X4hBl.js +706 -0
  150. package/dist/visual-editor-DOXtCqRv.js +145 -0
  151. package/dist/visual-editor-DQEd3xwY.js +145 -0
  152. package/dist/visual-editor-DUngIOnE.js +157 -0
  153. package/dist/visual-editor-Dd-aD1iL.js +694 -0
  154. package/dist/visual-editor-DeZVZYfd.js +169 -0
  155. package/dist/visual-editor-DfJMZpiP.js +145 -0
  156. package/dist/visual-editor-DgAsQK9D.js +145 -0
  157. package/dist/visual-editor-Dhi__-7_.js +145 -0
  158. package/dist/visual-editor-DjN3MVkl.js +694 -0
  159. package/dist/visual-editor-DjdqpJU-.js +145 -0
  160. package/dist/visual-editor-DqddYaYq.js +694 -0
  161. package/dist/visual-editor-DrCmls4W.js +694 -0
  162. package/dist/visual-editor-DvuH3jyL.js +157 -0
  163. package/dist/visual-editor-TfVDfO5_.js +145 -0
  164. package/dist/visual-editor-VcrEkFyd.js +706 -0
  165. package/dist/visual-editor-W_ZDmMFn.js +145 -0
  166. package/dist/visual-editor-b7ALusk8.js +145 -0
  167. package/dist/visual-editor-bauJ9beX.js +694 -0
  168. package/dist/visual-editor-erGXf3kS.js +157 -0
  169. package/dist/visual-editor-hVELayZs.js +706 -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 +15074 -137463
  174. package/package.json +46 -25
  175. package/dist/editor.css +0 -1
  176. package/dist/visual-editor-1QC8zZX_.js +0 -221
  177. package/dist/visual-editor-5C5XV5rL.js +0 -221
  178. package/dist/visual-editor-B8-FoFxc.js +0 -1049
  179. package/dist/visual-editor-BJgCpnYV.js +0 -1073
  180. package/dist/visual-editor-BKLiin5z.js +0 -1049
  181. package/dist/visual-editor-BWbqw_QE.js +0 -233
  182. package/dist/visual-editor-Bb6upvTE.js +0 -221
  183. package/dist/visual-editor-BcZCBLFh.js +0 -1049
  184. package/dist/visual-editor-BecDYKH8.js +0 -1049
  185. package/dist/visual-editor-BllAUu_T.js +0 -1073
  186. package/dist/visual-editor-BmaYFuCe.js +0 -233
  187. package/dist/visual-editor-BnPFkJlo.js +0 -221
  188. package/dist/visual-editor-BoIXa-xl.js +0 -245
  189. package/dist/visual-editor-BtDJICJp.js +0 -1073
  190. package/dist/visual-editor-BwxWyr_L.js +0 -221
  191. package/dist/visual-editor-Bz7BlR_j.js +0 -221
  192. package/dist/visual-editor-CC0RAmib.js +0 -1049
  193. package/dist/visual-editor-CDY9slY9.js +0 -1061
  194. package/dist/visual-editor-CFebs6R8.js +0 -1049
  195. package/dist/visual-editor-CNL0HyVh.js +0 -1049
  196. package/dist/visual-editor-CYnzwNwX.js +0 -229
  197. package/dist/visual-editor-CZH605TK.js +0 -233
  198. package/dist/visual-editor-Cada46ZF.js +0 -1049
  199. package/dist/visual-editor-CheComxC.js +0 -1061
  200. package/dist/visual-editor-CuA8h_Xv.js +0 -221
  201. package/dist/visual-editor-CuRmgs-p.js +0 -245
  202. package/dist/visual-editor-D9_YWQQY.js +0 -1073
  203. package/dist/visual-editor-D9w4wRG8.js +0 -245
  204. package/dist/visual-editor-D9xTiOC0.js +0 -221
  205. package/dist/visual-editor-DA7CixSl.js +0 -1061
  206. package/dist/visual-editor-DAnBQ9H_.js +0 -221
  207. package/dist/visual-editor-DF8RsMvq.js +0 -233
  208. package/dist/visual-editor-DLrKYx7j.js +0 -1061
  209. package/dist/visual-editor-DQJc_Xok.js +0 -233
  210. package/dist/visual-editor-DTZFGKm7.js +0 -221
  211. package/dist/visual-editor-DXebihTA.js +0 -233
  212. package/dist/visual-editor-DZ4U1fk-.js +0 -221
  213. package/dist/visual-editor-Dg7P-vDv.js +0 -1057
  214. package/dist/visual-editor-Dh2cuwWt.js +0 -1049
  215. package/dist/visual-editor-DpetyO9o.js +0 -1049
  216. package/dist/visual-editor-Duav2tXb.js +0 -1061
  217. package/dist/visual-editor-DvYsu_s9.js +0 -221
  218. package/dist/visual-editor-DwlX3nnZ.js +0 -221
  219. package/dist/visual-editor-Dz5s66Og.js +0 -221
  220. package/dist/visual-editor-E57fPJMD.js +0 -1049
  221. package/dist/visual-editor-Fy_uEJju.js +0 -1061
  222. package/dist/visual-editor-G8e2TllW.js +0 -1049
  223. package/dist/visual-editor-HkfpXRw7.js +0 -1049
  224. package/dist/visual-editor-ZKG4e_Ey.js +0 -1049
  225. package/dist/visual-editor-rZRnDwgU.js +0 -245
@@ -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
+ };