@yext/visual-editor 1.4.11 → 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 +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-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 +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,491 @@
1
+ import React from "react";
2
+ import { FieldLabel, PuckComponent, Slot } from "@puckeditor/core";
3
+ import {
4
+ backgroundColors,
5
+ ThemeColor,
6
+ ThemeOptions,
7
+ } from "../../../utils/themeConfigOptions.ts";
8
+ import { Body } from "../../atoms/body.tsx";
9
+ import { MaybeLink } from "../../atoms/maybeLink.tsx";
10
+ import { msg, pt } from "../../../utils/i18n/platform.ts";
11
+ import { PageSection } from "../../atoms/pageSection.tsx";
12
+ import { CardContextProvider } from "../../../hooks/useCardContext.tsx";
13
+ import {
14
+ isDirectoryGrid,
15
+ sortAlphabetically,
16
+ } from "../../../utils/directory/utils.ts";
17
+ import {
18
+ createDefaultLinkOverrideFieldValue,
19
+ defaultDirectoryCardSlotData,
20
+ DirectoryCardProps,
21
+ } from "./DirectoryCard.tsx";
22
+ import { StreamDocument } from "../../../utils/types/StreamDocument.ts";
23
+ import { resolveDirectoryListChildren } from "../../../utils/urls/resolveDirectoryListChildren.ts";
24
+ import { getThemeValue } from "../../../utils/getThemeValue.ts";
25
+ import { useDocument } from "../../../hooks/useDocument.tsx";
26
+ import {
27
+ createDirectoryChildReference,
28
+ DirectoryChildrenProvider,
29
+ getSortedDirectoryChildren,
30
+ } from "./directoryChildReference.tsx";
31
+ import {
32
+ YextComponentConfig,
33
+ type YextCustomFieldRenderProps,
34
+ type YextFieldDefinition,
35
+ YextFields,
36
+ } from "../../../fields/fields.ts";
37
+ import { createSlottedItemSource } from "../../../utils/itemSource/index.ts";
38
+ import { syncLinkedSlotMappedCards } from "../../../utils/cardSlots/slotMappedCards.ts";
39
+ import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
40
+ import { YextAutoField } from "../../../fields/YextAutoField.tsx";
41
+ import {
42
+ Tooltip,
43
+ TooltipArrow,
44
+ TooltipContent,
45
+ TooltipProvider,
46
+ TooltipTrigger,
47
+ } from "../../../internal/puck/ui/Tooltip.tsx";
48
+ import { FaInfoCircle } from "react-icons/fa";
49
+ import { useTemplateMetadata } from "../../../internal/hooks/useMessageReceivers.ts";
50
+
51
+ export type DirectoryGridProps = {
52
+ data: typeof directoryCardsSource.value;
53
+ styles: {
54
+ backgroundColor?: ThemeColor;
55
+ };
56
+ /** @internal */
57
+ manualSlots?: {
58
+ CardSlot: Slot;
59
+ };
60
+ slots: {
61
+ CardSlot: Slot;
62
+ };
63
+ };
64
+
65
+ const DirectoryFieldTooltip = () => {
66
+ const templateMetadata = useTemplateMetadata();
67
+ return (
68
+ <TooltipProvider delayDuration={0}>
69
+ <Tooltip>
70
+ <TooltipTrigger asChild>
71
+ <button
72
+ type="button"
73
+ className="ve-flex ve-h-4 ve-w-4 ve-items-center ve-justify-center ve-text-gray-500 hover:ve-text-gray-700"
74
+ >
75
+ <FaInfoCircle className="ve-h-4 ve-w-4" />
76
+ </button>
77
+ </TooltipTrigger>
78
+ <TooltipContent className="ve-max-w-[260px] ve-text-left">
79
+ {pt(
80
+ "linkOverrideDirectoryTooltip",
81
+ "Use a custom URL path for each card's title link. If the value is empty, the generated directory URL will be used.",
82
+ {
83
+ entityType: templateMetadata.entityTypeDisplayName,
84
+ }
85
+ )}
86
+ <TooltipArrow fill="ve-bg-popover" />
87
+ </TooltipContent>
88
+ </Tooltip>
89
+ </TooltipProvider>
90
+ );
91
+ };
92
+
93
+ const linkOverrideField: YextFieldDefinition<
94
+ DirectoryCardProps["data"]["linkOverride"]
95
+ > = {
96
+ type: "custom",
97
+ render: ({
98
+ value,
99
+ onChange,
100
+ }: YextCustomFieldRenderProps<
101
+ DirectoryCardProps["data"]["linkOverride"]
102
+ >) => {
103
+ const enabled = value?.enabled ?? false;
104
+ const normalizeLink = value?.normalizeLink ?? false;
105
+ const label = pt("fields.overrideLink", "Override Link");
106
+
107
+ return (
108
+ <FieldLabel label={label} icon={<DirectoryFieldTooltip />}>
109
+ <div className="ve-flex ve-flex-col ve-gap-3">
110
+ <YextAutoField
111
+ field={{
112
+ type: "radio",
113
+ options: [
114
+ { label: pt("fields.options.yes", "Yes"), value: true },
115
+ { label: pt("fields.options.no", "No"), value: false },
116
+ ],
117
+ }}
118
+ value={enabled}
119
+ onChange={(nextEnabled) =>
120
+ onChange({
121
+ ...createDefaultLinkOverrideFieldValue(),
122
+ ...value,
123
+ enabled: nextEnabled,
124
+ })
125
+ }
126
+ />
127
+ {enabled && (
128
+ <>
129
+ <YextAutoField
130
+ field={{
131
+ type: "entityField",
132
+ label: msg("fields.linkPath", "Link Path"),
133
+ filter: {
134
+ types: ["type.string"],
135
+ },
136
+ showApplyAllOption: true,
137
+ }}
138
+ value={value}
139
+ onChange={(nextValue) =>
140
+ onChange({
141
+ ...nextValue,
142
+ enabled: true,
143
+ })
144
+ }
145
+ />
146
+ <FieldLabel label={pt("fields.normalizeLink", "Normalize Link")}>
147
+ <YextAutoField
148
+ field={{
149
+ type: "radio",
150
+ options: [
151
+ { label: pt("fields.options.yes", "Yes"), value: true },
152
+ { label: pt("fields.options.no", "No"), value: false },
153
+ ],
154
+ }}
155
+ value={normalizeLink}
156
+ onChange={(nextNormalizeLink) =>
157
+ onChange({
158
+ ...value,
159
+ normalizeLink: nextNormalizeLink,
160
+ })
161
+ }
162
+ />
163
+ </FieldLabel>
164
+ </>
165
+ )}
166
+ </div>
167
+ </FieldLabel>
168
+ );
169
+ },
170
+ };
171
+
172
+ const directoryCardsSource = createSlottedItemSource<
173
+ DirectoryCardProps["data"],
174
+ DirectoryCardProps
175
+ >({
176
+ label: msg("components.directoryChildren", "Directory Children"),
177
+ itemLabel: "Directory Card",
178
+ cardName: "DirectoryCard",
179
+ defaultItemProps: () =>
180
+ defaultDirectoryCardSlotData("DirectoryCard", 0).props,
181
+ mappingFields: {
182
+ cardTitle: {
183
+ type: "entityField",
184
+ label: msg("fields.name", "Name"),
185
+ filter: {
186
+ types: ["type.string"],
187
+ },
188
+ },
189
+ linkOverride: linkOverrideField,
190
+ showAddress: {
191
+ type: "radio",
192
+ label: msg("fields.showAddress", "Show Address"),
193
+ options: ThemeOptions.SHOW_HIDE,
194
+ },
195
+ showHoursStatus: {
196
+ type: "radio",
197
+ label: msg("fields.showHoursStatus", "Show Hours Status"),
198
+ options: ThemeOptions.SHOW_HIDE,
199
+ },
200
+ showPhoneNumber: {
201
+ type: "radio",
202
+ label: msg("fields.showPhone", "Show Phone"),
203
+ options: ThemeOptions.SHOW_HIDE,
204
+ },
205
+ },
206
+ });
207
+
208
+ // The linked entity slot helper allows field selection and constant values
209
+ // however the directory should be locked to the dm_directoryChildren field.
210
+ const getNormalizedDirectoryGridData = (
211
+ value: typeof directoryCardsSource.value | undefined
212
+ ): typeof directoryCardsSource.value => ({
213
+ ...directoryCardsSource.defaultValue,
214
+ ...value,
215
+ field: "dm_directoryChildren",
216
+ constantValueEnabled: false,
217
+ constantValue: [],
218
+ mappings: {
219
+ ...directoryCardsSource.defaultValue.mappings!,
220
+ ...value?.mappings,
221
+ cardTitle: {
222
+ ...directoryCardsSource.defaultValue.mappings!.cardTitle,
223
+ ...value?.mappings?.cardTitle,
224
+ field: value?.mappings?.cardTitle?.field || "name",
225
+ },
226
+ linkOverride: {
227
+ ...createDefaultLinkOverrideFieldValue(),
228
+ ...value?.mappings?.linkOverride,
229
+ },
230
+ showAddress: value?.mappings?.showAddress ?? true,
231
+ showHoursStatus: value?.mappings?.showHoursStatus ?? true,
232
+ showPhoneNumber: value?.mappings?.showPhoneNumber ?? true,
233
+ },
234
+ });
235
+
236
+ export const DirectoryList = ({
237
+ streamDocument,
238
+ directoryChildren,
239
+ relativePrefixToRoot,
240
+ backgroundColor,
241
+ linkColor,
242
+ }: {
243
+ streamDocument: StreamDocument;
244
+ directoryChildren: {
245
+ id: string;
246
+ name: string;
247
+ slug: string;
248
+ meta?: {
249
+ entityType?: {
250
+ id: "dm_country" | "dm_region" | "dm_city";
251
+ };
252
+ };
253
+ dm_addressCountryDisplayName?: string;
254
+ dm_addressRegionDisplayName?: string;
255
+ }[];
256
+ relativePrefixToRoot: string;
257
+ backgroundColor: ThemeColor;
258
+ linkColor?: ThemeColor;
259
+ }) => {
260
+ const sortedDirectoryChildren = sortAlphabetically(
261
+ [...directoryChildren],
262
+ "name"
263
+ );
264
+ const linkTextTransformValue = (
265
+ getThemeValue("--textTransform-link-textTransform", streamDocument) ?? ""
266
+ ).toLowerCase();
267
+ const shouldTitleCase =
268
+ linkTextTransformValue === "none" || linkTextTransformValue === "normal";
269
+
270
+ return (
271
+ <PageSection verticalPadding="sm" background={backgroundColor}>
272
+ <ul className="grid lg:grid-cols-4 md:grid-cols-3 sm:grid-cols-2 grid-cols-1">
273
+ {sortedDirectoryChildren.map((child, idx) => {
274
+ const childSlug = resolveDirectoryListChildren(streamDocument, child);
275
+ let label;
276
+ switch (child?.meta?.entityType?.id) {
277
+ case "dm_country":
278
+ label = child.dm_addressCountryDisplayName ?? child.name;
279
+ break;
280
+ case "dm_region":
281
+ label = child.dm_addressRegionDisplayName ?? child.name;
282
+ break;
283
+ case "dm_city":
284
+ label = child.name;
285
+ break;
286
+ default:
287
+ label = child.name;
288
+ }
289
+
290
+ return (
291
+ <li key={idx}>
292
+ <MaybeLink
293
+ eventName={`child${idx}`}
294
+ variant="directoryLink"
295
+ color={linkColor}
296
+ href={
297
+ relativePrefixToRoot
298
+ ? relativePrefixToRoot + childSlug
299
+ : childSlug
300
+ }
301
+ >
302
+ <Body
303
+ style={{
304
+ textTransform: shouldTitleCase
305
+ ? ("capitalize" as React.CSSProperties["textTransform"])
306
+ : ("var(--textTransform-link-textTransform)" as React.CSSProperties["textTransform"]),
307
+ }}
308
+ >
309
+ {label}
310
+ </Body>
311
+ </MaybeLink>
312
+ </li>
313
+ );
314
+ })}
315
+ </ul>
316
+ </PageSection>
317
+ );
318
+ };
319
+
320
+ const directoryGridFields: YextFields<DirectoryGridProps> = {
321
+ data: {
322
+ ...directoryCardsSource.field,
323
+ disableConstantValueToggle: true,
324
+ fixedRepeatedField: "dm_directoryChildren",
325
+ hideRequirementsTooltip: true,
326
+ },
327
+ styles: {
328
+ type: "object",
329
+ label: msg("fields.styles", "Styles"),
330
+ objectFields: {
331
+ backgroundColor: {
332
+ type: "basicSelector",
333
+ label: msg("fields.backgroundColor", "Background Color"),
334
+ options: "BACKGROUND_COLOR",
335
+ },
336
+ },
337
+ },
338
+ slots: {
339
+ type: "object",
340
+ objectFields: {
341
+ CardSlot: { type: "slot", allow: [] },
342
+ },
343
+ visible: false,
344
+ },
345
+ manualSlots: {
346
+ type: "object",
347
+ objectFields: {
348
+ CardSlot: { type: "slot", allow: [] },
349
+ },
350
+ visible: false,
351
+ },
352
+ };
353
+
354
+ const DirectoryGridWrapper: PuckComponent<DirectoryGridProps> = (props) => {
355
+ const { styles, slots } = props;
356
+ const streamDocument = useDocument<StreamDocument>();
357
+ const sortedDirectoryChildren = React.useMemo(
358
+ () => getSortedDirectoryChildren(streamDocument.dm_directoryChildren),
359
+ [streamDocument.dm_directoryChildren]
360
+ );
361
+
362
+ return (
363
+ <DirectoryChildrenProvider directoryChildren={sortedDirectoryChildren}>
364
+ <CardContextProvider>
365
+ <PageSection
366
+ verticalPadding="sm"
367
+ background={styles.backgroundColor}
368
+ className={"flex min-h-0 min-w-0 mx-auto"}
369
+ >
370
+ <slots.CardSlot
371
+ className="flex min-h-0 min-w-0 mx-auto flex-col sm:grid sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-8"
372
+ allow={[]}
373
+ style={{ height: "auto" }}
374
+ />
375
+ </PageSection>
376
+ </CardContextProvider>
377
+ </DirectoryChildrenProvider>
378
+ );
379
+ };
380
+
381
+ export const DirectoryGrid: YextComponentConfig<DirectoryGridProps> = {
382
+ label: msg("components.directoryGrid", "Directory Grid"),
383
+ fields: directoryGridFields,
384
+ defaultProps: {
385
+ ...directoryCardsSource.defaultWrapperProps,
386
+ data: getNormalizedDirectoryGridData(directoryCardsSource.defaultValue),
387
+ styles: {
388
+ backgroundColor: backgroundColors.background1.value,
389
+ },
390
+ },
391
+ resolveData: (data, params) => {
392
+ const streamDocument = params.metadata.streamDocument;
393
+
394
+ if (
395
+ !streamDocument?.dm_directoryChildren ||
396
+ !isDirectoryGrid(streamDocument.dm_directoryChildren)
397
+ ) {
398
+ return data;
399
+ }
400
+
401
+ const sortedDirectoryChildren = getSortedDirectoryChildren(
402
+ streamDocument.dm_directoryChildren
403
+ );
404
+ const normalizedData = getNormalizedDirectoryGridData(data.props.data);
405
+ const titleField = normalizedData.mappings?.cardTitle.constantValueEnabled
406
+ ? ""
407
+ : normalizedData.mappings?.cardTitle.field || "name";
408
+ const titleItems = directoryCardsSource.resolveItems(normalizedData, {
409
+ ...streamDocument,
410
+ dm_directoryChildren: sortedDirectoryChildren,
411
+ });
412
+ const firstCardProps = data.props.slots?.CardSlot?.[0]?.props;
413
+ const updatedCards = syncLinkedSlotMappedCards({
414
+ items: sortedDirectoryChildren.map((child, index) => ({
415
+ child,
416
+ childIndex: index,
417
+ })),
418
+ currentCards: data.props.slots.CardSlot,
419
+ createCard: (id, index) =>
420
+ defaultDirectoryCardSlotData(
421
+ id,
422
+ index,
423
+ createDirectoryChildReference(sortedDirectoryChildren[index], index),
424
+ firstCardProps?.styles,
425
+ firstCardProps?.slots
426
+ ),
427
+ toParentData: ({ child, childIndex }) => ({
428
+ childRef: createDirectoryChildReference(child, childIndex),
429
+ }),
430
+ normalizeId: (id) => `DirectoryCard-${id}`,
431
+ }).map((card, index) => {
432
+ const cardTitle =
433
+ titleItems[index]?.cardTitle !== undefined
434
+ ? resolveComponentData(
435
+ titleItems[index].cardTitle,
436
+ streamDocument.locale || "en",
437
+ streamDocument,
438
+ { output: "plainText" }
439
+ )
440
+ : "[[name]]";
441
+ const cardSlots = card.props.slots ?? {};
442
+
443
+ return {
444
+ ...card,
445
+ props: {
446
+ ...card.props,
447
+ field: titleField,
448
+ data: {
449
+ ...card.props.data,
450
+ cardTitle,
451
+ linkOverride: normalizedData.mappings?.linkOverride,
452
+ showAddress: normalizedData.mappings?.showAddress,
453
+ showHoursStatus: normalizedData.mappings?.showHoursStatus,
454
+ showPhoneNumber: normalizedData.mappings?.showPhoneNumber,
455
+ },
456
+ slots: {
457
+ ...cardSlots,
458
+ HeadingSlot: (cardSlots.HeadingSlot ?? []).map(
459
+ (headingSlot, headingIndex) =>
460
+ headingIndex === 0
461
+ ? {
462
+ ...headingSlot,
463
+ props: {
464
+ ...headingSlot.props,
465
+ parentData: {
466
+ field: titleField,
467
+ text: cardTitle,
468
+ },
469
+ },
470
+ }
471
+ : headingSlot
472
+ ),
473
+ },
474
+ },
475
+ };
476
+ });
477
+
478
+ return {
479
+ ...data,
480
+ props: {
481
+ ...data.props,
482
+ data: normalizedData,
483
+ slots: {
484
+ ...data.props.slots,
485
+ CardSlot: updatedCards,
486
+ },
487
+ },
488
+ };
489
+ },
490
+ render: (props) => <DirectoryGridWrapper {...props} />,
491
+ };
@@ -0,0 +1,226 @@
1
+ import React from "react";
2
+ import { describe, expect, it } from "vitest";
3
+ import { Config, resolveAllData } from "@puckeditor/core";
4
+ import { Directory } from "./Directory.tsx";
5
+ import { SlotsCategoryComponents } from "../../testing/SlotComponents.tsx";
6
+ import { defaultDirectoryCardSlotData } from "./DirectoryCard.tsx";
7
+ import { backgroundColors } from "../../../utils/themeConfigOptions.ts";
8
+
9
+ const cityDocument = {
10
+ locale: "en",
11
+ _site: {
12
+ name: "Example Business",
13
+ },
14
+ __: {
15
+ isPrimaryLocale: true,
16
+ },
17
+ _pageset: JSON.stringify({
18
+ config: {
19
+ urlTemplate: {
20
+ primary: "[[address.region]]/[[address.city]]/[[address.line1]]",
21
+ },
22
+ },
23
+ }),
24
+ dm_directoryChildren: [
25
+ {
26
+ address: {
27
+ city: "Arlington",
28
+ countryCode: "US",
29
+ line1: "1101 Wilson Blvd",
30
+ postalCode: "22209",
31
+ region: "VA",
32
+ },
33
+ mainPhone: "+12025551010",
34
+ hours: {
35
+ monday: { openIntervals: [{ start: "09:00", end: "17:00" }] },
36
+ },
37
+ name: "Galaxy Grill Rosslyn",
38
+ timezone: "America/New_York",
39
+ },
40
+ {
41
+ address: {
42
+ city: "Arlington",
43
+ countryCode: "US",
44
+ line1: "4320 Fairfax Dr",
45
+ postalCode: "22201",
46
+ region: "VA",
47
+ },
48
+ mainPhone: "+12025551011",
49
+ name: "Galaxy Grill Ballston",
50
+ timezone: "America/New_York",
51
+ },
52
+ ],
53
+ name: "Arlington",
54
+ meta: { entityType: { id: "dm_city", uid: 456 }, locale: "en" },
55
+ };
56
+
57
+ const directoryProps = {
58
+ styles: {
59
+ backgroundColor: {
60
+ bgColor: "bg-palette-primary-dark",
61
+ textColor: "text-white",
62
+ },
63
+ },
64
+ slots: {
65
+ TitleSlot: [],
66
+ SiteNameSlot: [],
67
+ BreadcrumbsSlot: [],
68
+ DirectoryGrid: [
69
+ {
70
+ type: "DirectoryGrid",
71
+ props: {
72
+ slots: {
73
+ CardSlot: [],
74
+ },
75
+ },
76
+ },
77
+ ],
78
+ },
79
+ };
80
+
81
+ describe("directoryChildReference", () => {
82
+ it("stores directory cards as child references and keeps card titles in the title slot", async () => {
83
+ const puckConfig: Config = {
84
+ components: { Directory, ...SlotsCategoryComponents },
85
+ root: {
86
+ render: () => React.createElement(React.Fragment),
87
+ },
88
+ };
89
+
90
+ const resolvedData = await resolveAllData(
91
+ {
92
+ root: {
93
+ props: {},
94
+ },
95
+ content: [
96
+ {
97
+ type: "Directory",
98
+ props: directoryProps,
99
+ },
100
+ ],
101
+ },
102
+ puckConfig,
103
+ {
104
+ streamDocument: cityDocument,
105
+ }
106
+ );
107
+
108
+ const cards =
109
+ resolvedData.content[0]?.props?.slots?.DirectoryGrid?.[0]?.props?.slots
110
+ ?.CardSlot ?? [];
111
+ const firstCard = cards[0];
112
+
113
+ expect(cards).toHaveLength(2);
114
+ expect(firstCard?.props?.parentData).toEqual({
115
+ childRef: { childIndex: 0 },
116
+ });
117
+ expect(firstCard?.props?.parentData?.profile).toBeUndefined();
118
+ expect(firstCard?.props?.data).toEqual(
119
+ expect.objectContaining({
120
+ cardTitle: "Galaxy Grill Ballston",
121
+ })
122
+ );
123
+ expect(firstCard?.props?.field).toBe("name");
124
+ expect(firstCard?.props?.slots?.HeadingSlot?.[0]?.type).toBe(
125
+ "HeadingTextSlot"
126
+ );
127
+ expect(
128
+ firstCard?.props?.slots?.HeadingSlot?.[0]?.props?.data?.text
129
+ ).toEqual({
130
+ field: "",
131
+ constantValue: {
132
+ defaultValue: "[[name]]",
133
+ },
134
+ constantValueEnabled: true,
135
+ });
136
+ expect(
137
+ firstCard?.props?.slots?.HeadingSlot?.[0]?.props?.parentData
138
+ ).toEqual({
139
+ field: "name",
140
+ text: "Galaxy Grill Ballston",
141
+ });
142
+ expect(
143
+ firstCard?.props?.slots?.AddressSlot?.[0]?.props?.data?.address?.field
144
+ ).toBe("address");
145
+ expect(
146
+ firstCard?.props?.slots?.PhoneSlot?.[0]?.props?.data?.number?.field
147
+ ).toBe("mainPhone");
148
+ expect(
149
+ firstCard?.props?.slots?.HoursSlot?.[0]?.props?.data?.hours?.field
150
+ ).toBe("hours");
151
+ });
152
+
153
+ it("preserves slot styles when directory cards are re-resolved", async () => {
154
+ const puckConfig: Config = {
155
+ components: { Directory, ...SlotsCategoryComponents },
156
+ root: {
157
+ render: () => React.createElement(React.Fragment),
158
+ },
159
+ };
160
+ const seededCard = defaultDirectoryCardSlotData("DirectoryCard-seeded", 0);
161
+ seededCard.props.slots.HeadingSlot[0]!.props.styles.color =
162
+ backgroundColors.color1.value;
163
+ seededCard.props.slots.AddressSlot[0]!.props.styles.color =
164
+ backgroundColors.color2.value;
165
+ seededCard.props.slots.PhoneSlot[0]!.props.styles.color =
166
+ backgroundColors.color3.value;
167
+ seededCard.props.slots.HoursSlot[0]!.props.styles.timeFormat = "24h";
168
+ seededCard.props.slots.HoursSlot[0]!.props.styles.bodyVariant = "sm";
169
+
170
+ const resolvedData = await resolveAllData(
171
+ {
172
+ root: {
173
+ props: {},
174
+ },
175
+ content: [
176
+ {
177
+ type: "Directory",
178
+ props: {
179
+ ...directoryProps,
180
+ slots: {
181
+ ...directoryProps.slots,
182
+ DirectoryGrid: [
183
+ {
184
+ type: "DirectoryGrid",
185
+ props: {
186
+ slots: {
187
+ CardSlot: [seededCard],
188
+ },
189
+ },
190
+ },
191
+ ],
192
+ },
193
+ },
194
+ },
195
+ ],
196
+ },
197
+ puckConfig,
198
+ {
199
+ streamDocument: cityDocument,
200
+ }
201
+ );
202
+
203
+ const cards =
204
+ resolvedData.content[0]?.props?.slots?.DirectoryGrid?.[0]?.props?.slots
205
+ ?.CardSlot ?? [];
206
+
207
+ expect(cards).toHaveLength(2);
208
+ for (const card of cards) {
209
+ expect(
210
+ card?.props?.slots?.HeadingSlot?.[0]?.props?.styles?.color
211
+ ).toEqual(backgroundColors.color1.value);
212
+ expect(
213
+ card?.props?.slots?.AddressSlot?.[0]?.props?.styles?.color
214
+ ).toEqual(backgroundColors.color2.value);
215
+ expect(card?.props?.slots?.PhoneSlot?.[0]?.props?.styles?.color).toEqual(
216
+ backgroundColors.color3.value
217
+ );
218
+ expect(
219
+ card?.props?.slots?.HoursSlot?.[0]?.props?.styles?.timeFormat
220
+ ).toBe("24h");
221
+ expect(
222
+ card?.props?.slots?.HoursSlot?.[0]?.props?.styles?.bodyVariant
223
+ ).toBe("sm");
224
+ }
225
+ });
226
+ });