@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,275 @@
1
+ import { PuckComponent, setDeep } from "@puckeditor/core";
2
+ import { ComplexImageType, ImageType } from "@yext/pages-components";
3
+ import {
4
+ AssetImageType,
5
+ isLocalizedAssetImage,
6
+ resolveLocalizedAssetImage,
7
+ TranslatableAssetImage,
8
+ } from "../../../types/images.ts";
9
+ import { EntityField } from "../../../editor/EntityField.tsx";
10
+ import {
11
+ Image,
12
+ ImgSizesByBreakpoint,
13
+ imgSizesHelper,
14
+ } from "../../atoms/image.tsx";
15
+ import { MaybeLink } from "../../atoms/maybeLink.tsx";
16
+ import { TranslatableString } from "../../../types/types.ts";
17
+ import { YextEntityField } from "../../../editor/YextEntityFieldSelector.tsx";
18
+ import { msg, pt } from "../../../utils/i18n/platform.ts";
19
+ import { resolveComponentData } from "../../../utils/resolveComponentData.tsx";
20
+ import { resolveDataFromParent } from "../../../editor/ParentData.tsx";
21
+ import { useDocument } from "../../../hooks/useDocument.tsx";
22
+ import * as React from "react";
23
+ import { useTranslation } from "react-i18next";
24
+ import { EmptyImageState } from "./EmptyImageState.tsx";
25
+ import { ImageStylingFields, ImageStylingProps } from "./styling.ts";
26
+ import { YextComponentConfig, YextFields } from "../../../fields/fields.ts";
27
+
28
+ const PLACEHOLDER_IMAGE_URL = "https://placehold.co/640x360";
29
+ const DEFAULT_LINK = "#";
30
+ const LINK_REGEX_VALIDATION = /^(https?:\/\/[^\s]+|\/[^\s]*|#[^\s]*)$/;
31
+
32
+ export interface ImageWrapperProps {
33
+ data: {
34
+ /** The image to display. */
35
+ image: YextEntityField<
36
+ ImageType | ComplexImageType | TranslatableAssetImage
37
+ >;
38
+ link?: TranslatableString;
39
+ };
40
+
41
+ /** Size and aspect ratio of the image. */
42
+ styles: ImageStylingProps;
43
+
44
+ /** @internal Controlled data from the parent section. */
45
+ parentData?: {
46
+ field: string;
47
+ image: ImageType | ComplexImageType | TranslatableAssetImage | undefined;
48
+ };
49
+
50
+ /** Additional CSS classes to apply to the image. */
51
+ className?: string;
52
+
53
+ sizes?: ImgSizesByBreakpoint;
54
+
55
+ hideWidthProp?: boolean;
56
+
57
+ /** @internal If true, shows the imageConstrain prop. */
58
+ showImageConstrain?: boolean;
59
+ }
60
+
61
+ export const ImageWrapperFields: YextFields<ImageWrapperProps> = {
62
+ data: {
63
+ type: "object",
64
+ label: msg("fields.data", "Data"),
65
+ objectFields: {
66
+ image: {
67
+ type: "entityField",
68
+ label: msg("fields.options.image", "Image"),
69
+ filter: {
70
+ types: ["type.image"],
71
+ },
72
+ },
73
+ link: {
74
+ type: "translatableString",
75
+ label: msg("fields.link", "Link"),
76
+ },
77
+ },
78
+ },
79
+ styles: {
80
+ type: "object",
81
+ label: msg("fields.styles", "Styles"),
82
+ objectFields: {
83
+ ...ImageStylingFields,
84
+ },
85
+ },
86
+ showImageConstrain: {
87
+ label: msg("fields.showImageConstrain", "Show Image Constrain"),
88
+ type: "radio",
89
+ options: [
90
+ { label: msg("fields.options.show", "Show"), value: true },
91
+ { label: msg("fields.options.hide", "Hide"), value: false },
92
+ ],
93
+ visible: false,
94
+ },
95
+ };
96
+
97
+ export const getImageUrl = (
98
+ image: ImageType | ComplexImageType | TranslatableAssetImage | undefined,
99
+ locale: string
100
+ ): string | undefined => {
101
+ if (!image) {
102
+ return undefined;
103
+ }
104
+
105
+ if (isLocalizedAssetImage(image)) {
106
+ return resolveLocalizedAssetImage(image, locale)?.url;
107
+ }
108
+
109
+ if ("image" in image) {
110
+ return image.image?.url;
111
+ }
112
+
113
+ return image.url;
114
+ };
115
+
116
+ const ImageWrapperComponent: PuckComponent<ImageWrapperProps> = (props) => {
117
+ const {
118
+ data,
119
+ styles,
120
+ parentData,
121
+ className,
122
+ puck,
123
+ sizes = {
124
+ base: styles.width ? `min(100vw, width)` : "100vw",
125
+ md: styles.width
126
+ ? `min(width, calc((maxWidth - 32px) / 2))`
127
+ : "maxWidth / 2",
128
+ },
129
+ hideWidthProp,
130
+ showImageConstrain = false,
131
+ } = props;
132
+ const { i18n } = useTranslation();
133
+ const streamDocument = useDocument();
134
+ const resolvedImage = React.useMemo(() => {
135
+ return parentData
136
+ ? parentData?.image
137
+ : resolveComponentData(data.image, i18n.language, streamDocument);
138
+ }, [parentData, data.image, i18n.language, streamDocument]);
139
+
140
+ const imageUrl = getImageUrl(resolvedImage, i18n.language);
141
+ const isEmpty =
142
+ !resolvedImage ||
143
+ !imageUrl ||
144
+ (typeof imageUrl === "string" && imageUrl.trim() === "");
145
+
146
+ const inputLink = resolveComponentData(
147
+ data.link ?? { defaultValue: DEFAULT_LINK },
148
+ i18n.language,
149
+ streamDocument
150
+ );
151
+
152
+ const resolvedLink =
153
+ typeof inputLink === "string" &&
154
+ LINK_REGEX_VALIDATION.test(inputLink.trim()) &&
155
+ inputLink.trim() !== DEFAULT_LINK
156
+ ? inputLink.trim()
157
+ : undefined;
158
+
159
+ if (isEmpty) {
160
+ return (
161
+ <EmptyImageState
162
+ isEmpty={isEmpty}
163
+ isEditing={puck.isEditing ?? false}
164
+ constantValueEnabled={data.image.constantValueEnabled ?? false}
165
+ constantValue={data.image.constantValue as AssetImageType | undefined}
166
+ fieldId={parentData ? parentData.field : data.image.field}
167
+ containerStyle={{
168
+ ...(hideWidthProp
169
+ ? {}
170
+ : styles.width
171
+ ? { width: `${styles.width}px` }
172
+ : {}),
173
+ ...(styles.aspectRatio ? { aspectRatio: styles.aspectRatio } : {}),
174
+ }}
175
+ containerClassName={
176
+ className || "max-w-full rounded-image-borderRadius w-full h-full"
177
+ }
178
+ fullHeight
179
+ dragRef={puck.dragRef ?? undefined}
180
+ hasParentData={!!parentData}
181
+ />
182
+ );
183
+ }
184
+
185
+ const transformedSizes = imgSizesHelper(sizes, `${styles.width}px`);
186
+
187
+ return (
188
+ <EntityField
189
+ displayName={pt("fields.image", "Image")}
190
+ fieldId={parentData ? parentData.field : data.image.field}
191
+ constantValueEnabled={!parentData && data.image.constantValueEnabled}
192
+ fullHeight
193
+ ref={puck.dragRef}
194
+ >
195
+ <div className="w-full">
196
+ <MaybeLink
197
+ className="w-auto"
198
+ eventName="logoLink"
199
+ href={resolvedLink}
200
+ alwaysHideCaret={true}
201
+ >
202
+ <Image
203
+ image={resolvedImage}
204
+ aspectRatio={styles.aspectRatio}
205
+ imageFillType={styles.imageFillType}
206
+ width={
207
+ hideWidthProp ||
208
+ (showImageConstrain && styles.imageConstrain === "fill")
209
+ ? undefined
210
+ : styles.width
211
+ }
212
+ className={
213
+ className || "max-w-full rounded-image-borderRadius w-full"
214
+ }
215
+ sizes={transformedSizes}
216
+ />
217
+ </MaybeLink>
218
+ </div>
219
+ </EntityField>
220
+ );
221
+ };
222
+
223
+ export const imageDefaultProps = {
224
+ data: {
225
+ image: {
226
+ field: "",
227
+ constantValue: {
228
+ url: PLACEHOLDER_IMAGE_URL,
229
+ height: 360,
230
+ width: 640,
231
+ },
232
+ constantValueEnabled: true,
233
+ },
234
+ link: { defaultValue: DEFAULT_LINK },
235
+ },
236
+ styles: {
237
+ aspectRatio: 1.78,
238
+ imageFillType: "fill" as const,
239
+ width: 640,
240
+ },
241
+ allowWidthProp: true,
242
+ };
243
+
244
+ export const ImageWrapper: YextComponentConfig<ImageWrapperProps> = {
245
+ label: msg("components.image", "Image"),
246
+ inline: true,
247
+ fields: ImageWrapperFields,
248
+ defaultProps: imageDefaultProps,
249
+ resolveFields: (data, params) => {
250
+ let fields = resolveDataFromParent(ImageWrapperFields, data);
251
+ const parentType = params.parent?.type;
252
+
253
+ if (
254
+ data.props.hideWidthProp ||
255
+ data.props.styles.imageConstrain === "fill"
256
+ ) {
257
+ fields = setDeep(fields, "styles.objectFields.width.visible", false);
258
+ } else {
259
+ fields = setDeep(fields, "styles.objectFields.width.visible", true);
260
+ }
261
+
262
+ fields = setDeep(
263
+ fields,
264
+ "styles.objectFields.imageConstrain.visible",
265
+ !!data.props.showImageConstrain
266
+ );
267
+
268
+ if (parentType !== "PrimaryHeaderSlot") {
269
+ return setDeep(fields, "data.objectFields.link.visible", false);
270
+ }
271
+
272
+ return fields;
273
+ },
274
+ render: (props) => <ImageWrapperComponent {...props} />,
275
+ };
@@ -0,0 +1,66 @@
1
+ import { YextFields } from "../../../fields/fields.ts";
2
+ import { ImageFillType } from "../../../types/images.ts";
3
+ import { msg } from "../../../utils/i18n/platform.ts";
4
+
5
+ /** Props for displaying an image */
6
+ export interface ImageStylingProps {
7
+ /** The aspect ratio of the image */
8
+ aspectRatio: number;
9
+ width?: number;
10
+ imageConstrain?: "fill" | "fixed";
11
+ imageFillType?: ImageFillType;
12
+ }
13
+
14
+ export const ImageStylingFields: YextFields<ImageStylingProps> = {
15
+ imageConstrain: {
16
+ label: msg("fields.imageConstrain", "Image Constrain"),
17
+ type: "radio",
18
+ options: [
19
+ {
20
+ label: msg("fields.options.fillContainer", "Fill Container"),
21
+ value: "fill",
22
+ },
23
+ {
24
+ label: msg("fields.options.fixedWidth", "Fixed Width"),
25
+ value: "fixed",
26
+ },
27
+ ],
28
+ visible: false,
29
+ },
30
+ imageFillType: {
31
+ type: "basicSelector",
32
+ label: msg("fields.imageFillType", "Image Fill Type"),
33
+ options: [
34
+ { label: msg("fields.options.fill", "Fill"), value: "fill" },
35
+ { label: msg("fields.options.fit", "Fit"), value: "fit" },
36
+ ],
37
+ },
38
+ width: {
39
+ type: "number",
40
+ label: msg("fields.options.width", "Width"),
41
+ min: 0,
42
+ },
43
+ aspectRatio: {
44
+ type: "basicSelector",
45
+ label: msg("fields.options.aspectRatio", "Aspect Ratio"),
46
+ options: [
47
+ { label: "1:1", value: 1 },
48
+ { label: "5:4", value: 1.25 },
49
+ { label: "4:3", value: 1.33 },
50
+ { label: "3:2", value: 1.5 },
51
+ { label: "5:3", value: 1.67 },
52
+ { label: "16:9", value: 1.78 },
53
+ { label: "2:1", value: 2 },
54
+ { label: "3:1", value: 3 },
55
+ { label: "4:1", value: 4 },
56
+ { label: "4:5", value: 0.8 },
57
+ { label: "3:4", value: 0.75 },
58
+ { label: "2:3", value: 0.67 },
59
+ { label: "3:5", value: 0.6 },
60
+ { label: "9:16", value: 0.56 },
61
+ { label: "1:2", value: 0.5 },
62
+ { label: "1:3", value: 0.33 },
63
+ { label: "1:4", value: 0.25 },
64
+ ],
65
+ },
66
+ };
@@ -0,0 +1,13 @@
1
+ export { Address, type AddressProps } from "./Address.tsx";
2
+ export { HeadingText, type HeadingTextProps } from "./HeadingText.tsx";
3
+ export { HoursStatus, type HoursStatusProps } from "./HoursStatus.tsx";
4
+ export { HoursTable, type HoursTableProps } from "./HoursTable.tsx";
5
+ export { ImageWrapper, type ImageWrapperProps } from "./image/Image.tsx";
6
+ export {
7
+ mapboxStaticMapStyleOptions,
8
+ mapStyleField,
9
+ MapboxStaticMapComponent,
10
+ MapboxStaticMap,
11
+ type MapboxStaticProps,
12
+ } from "./MapboxStaticMap.tsx";
13
+ export { Phone, type PhoneProps } from "./Phone.tsx";
@@ -0,0 +1,298 @@
1
+ import { useTranslation } from "react-i18next";
2
+ import { useTemplateProps } from "../../hooks/useDocument.tsx";
3
+ import { MaybeLink } from "../atoms/maybeLink.tsx";
4
+ import { PageSection } from "../atoms/pageSection.tsx";
5
+ import { VisibilityWrapper } from "../atoms/visibilityWrapper.tsx";
6
+ import { msg } from "../../utils/i18n/platform.ts";
7
+ import { TranslatableString } from "../../types/types.ts";
8
+ import {
9
+ ThemeColor,
10
+ backgroundColors,
11
+ ThemeOptions,
12
+ } from "../../utils/themeConfigOptions.ts";
13
+ import { resolveComponentData } from "../../utils/resolveComponentData.tsx";
14
+ import { setDeep } from "@puckeditor/core";
15
+ import { AnalyticsScopeProvider } from "@yext/pages-components";
16
+ import { ComponentErrorBoundary } from "../../internal/components/ComponentErrorBoundary.tsx";
17
+ import { resolveBreadcrumbs } from "../../utils/urls/resolveBreadcrumbs.ts";
18
+ import { YextEntityField } from "../../editor/YextEntityFieldSelector.tsx";
19
+ import {
20
+ toPuckFields,
21
+ YextComponentConfig,
22
+ YextFields,
23
+ } from "../../fields/fields.ts";
24
+
25
+ export interface BreadcrumbsData {
26
+ /**
27
+ * The display label for the first link in the breadcrumb trail (the top-level directory page).
28
+ * @defaultValue "Directory Root"
29
+ */
30
+ directoryRoot: TranslatableString;
31
+
32
+ /**
33
+ * The display label for the last link in the breadcrumb trail (the current page).
34
+ * @defaultValue Name
35
+ */
36
+ currentPage: YextEntityField<TranslatableString>;
37
+ }
38
+
39
+ export interface BreadcrumbsStyles {
40
+ /**
41
+ * The background color of the section.
42
+ * @defaultValue Background Color 1
43
+ */
44
+ backgroundColor?: ThemeColor;
45
+
46
+ /**
47
+ * The link color of breadcrumbs.
48
+ */
49
+ linkColor?: ThemeColor;
50
+
51
+ /**
52
+ * Whether to show the current page's link in the breadcrumb trail (last link).
53
+ * @defaultValue true
54
+ */
55
+ showCurrentPage: boolean;
56
+ }
57
+
58
+ /**
59
+ * @public Defines the complete set of properties for the BreadcrumbsSection component.
60
+ */
61
+ export interface BreadcrumbsSectionProps {
62
+ /**
63
+ * This object contains the content used by the component.
64
+ * @propCategory Data Props
65
+ */
66
+ data: BreadcrumbsData;
67
+
68
+ /**
69
+ * This object contains properties for customizing the component's appearance.
70
+ * @propCategory Style Props
71
+ */
72
+ styles: BreadcrumbsStyles;
73
+
74
+ /**
75
+ * @internal
76
+ */
77
+ analytics: {
78
+ scope?: string;
79
+ };
80
+
81
+ /**
82
+ * If 'true', the component is visible on the live page; if 'false', it's hidden.
83
+ * @defaultValue true
84
+ */
85
+ liveVisibility: boolean;
86
+ }
87
+
88
+ const breadcrumbsSectionFields: YextFields<BreadcrumbsSectionProps> = {
89
+ data: {
90
+ type: "object",
91
+ label: msg("fields.data", "Data"),
92
+ objectFields: {
93
+ directoryRoot: {
94
+ type: "translatableString",
95
+ label: msg(
96
+ "fields.directoryRootLinkLabel",
97
+ "Directory Root Link Label"
98
+ ),
99
+ filter: { types: ["type.string"] },
100
+ },
101
+ currentPage: {
102
+ type: "entityField",
103
+ label: msg("fields.currentPageLinkLabel", "Current Page Link Label"),
104
+ filter: { types: ["type.string"] },
105
+ },
106
+ },
107
+ },
108
+ styles: {
109
+ type: "object",
110
+ label: msg("fields.styles", "Styles"),
111
+ objectFields: {
112
+ backgroundColor: {
113
+ type: "basicSelector",
114
+ label: msg("fields.backgroundColor", "Background Color"),
115
+ options: "BACKGROUND_COLOR",
116
+ },
117
+ linkColor: {
118
+ type: "basicSelector",
119
+ label: msg("fields.linkColor", "Link Color"),
120
+ options: "SITE_COLOR",
121
+ },
122
+ showCurrentPage: {
123
+ label: msg(
124
+ "fields.showCurrentPagesLinkLabel",
125
+ "Show Current Page's Link Label"
126
+ ),
127
+ type: "radio",
128
+ options: ThemeOptions.SHOW_HIDE,
129
+ },
130
+ },
131
+ },
132
+ analytics: {
133
+ type: "object",
134
+ label: msg("fields.analytics", "Analytics"),
135
+ visible: false,
136
+ objectFields: {
137
+ scope: {
138
+ label: msg("fields.scope", "Scope"),
139
+ type: "text",
140
+ },
141
+ },
142
+ },
143
+ liveVisibility: {
144
+ label: msg("fields.visibleOnLivePage", "Visible on Live Page"),
145
+ type: "radio",
146
+ options: [
147
+ { label: msg("fields.options.show", "Show"), value: true },
148
+ { label: msg("fields.options.hide", "Hide"), value: false },
149
+ ],
150
+ },
151
+ };
152
+
153
+ // BreadcrumbsComponent renders breadcrumbs for DM related pages.
154
+ // If there are no dm_directoryParents nor dm_directoryChildren,
155
+ // then displays nothing. In the case of a root DM page, there are
156
+ // no dm_directoryParents but there are dm_directoryChildren so
157
+ // that root entity's name will be in the breadcrumbs.
158
+ export const BreadcrumbsComponent = ({
159
+ data,
160
+ styles,
161
+ }: BreadcrumbsSectionProps) => {
162
+ const { t, i18n } = useTranslation();
163
+ const separator = "/";
164
+ const { document: streamDocument, relativePrefixToRoot } = useTemplateProps();
165
+ const breadcrumbs = resolveBreadcrumbs(streamDocument);
166
+ const directoryRoot = resolveComponentData(
167
+ data.directoryRoot,
168
+ i18n.language,
169
+ streamDocument
170
+ );
171
+ const currentPage = resolveComponentData(
172
+ data.currentPage,
173
+ i18n.language,
174
+ streamDocument
175
+ );
176
+ const breadcrumbsToRender = breadcrumbs
177
+ .map((breadcrumb, index) => ({ ...breadcrumb, index }))
178
+ .filter(
179
+ ({ index }) => styles.showCurrentPage || index < breadcrumbs.length - 1
180
+ );
181
+
182
+ if (!breadcrumbsToRender.length) {
183
+ return null;
184
+ }
185
+
186
+ return (
187
+ <PageSection
188
+ as={"nav"}
189
+ verticalPadding="sm"
190
+ aria-label={t("breadcrumb", "Breadcrumb")}
191
+ background={styles?.backgroundColor}
192
+ >
193
+ <ol className="inline p-0 m-0 list-none">
194
+ {breadcrumbsToRender.map(({ name, slug, index }) => {
195
+ const isRoot = index === 0;
196
+ const isCurrentPage = index === breadcrumbs.length - 1;
197
+ // Root pages have a single breadcrumb, so the first and last crumb are the same item.
198
+ const isRootPage = isRoot && isCurrentPage;
199
+ const href = relativePrefixToRoot
200
+ ? relativePrefixToRoot + slug
201
+ : slug;
202
+ let label = name;
203
+ if (isCurrentPage && currentPage) {
204
+ label = currentPage;
205
+ }
206
+ if ((isRootPage || isRoot) && directoryRoot) {
207
+ label = directoryRoot;
208
+ }
209
+
210
+ return (
211
+ <li key={index} className="contents whitespace-normal break-words">
212
+ {!isRoot && (
213
+ <span className="mx-2" aria-hidden>
214
+ {separator}
215
+ </span>
216
+ )}
217
+
218
+ {/* encourage the browser to break after a full breadcrumb, if necessary */}
219
+ <wbr />
220
+
221
+ <MaybeLink
222
+ eventName={`link${index}`}
223
+ href={isCurrentPage ? "" : href}
224
+ className="inline text-body-sm-fontSize font-link-fontWeight font-link-fontFamily whitespace-normal break-words"
225
+ color={styles?.linkColor}
226
+ alwaysHideCaret
227
+ >
228
+ {label}
229
+ </MaybeLink>
230
+ </li>
231
+ );
232
+ })}
233
+ </ol>
234
+ </PageSection>
235
+ );
236
+ };
237
+
238
+ /**
239
+ * The Breadcrumbs component automatically generates and displays a navigational hierarchy based on a page's position within a Yext directory structure. It renders a list of links showing the path from the main directory root to the current page, helping users understand their location on the site.
240
+ * Available on Location templates.
241
+ */
242
+ export const BreadcrumbsSection: YextComponentConfig<BreadcrumbsSectionProps> =
243
+ {
244
+ label: msg("components.breadcrumbs", "Breadcrumbs"),
245
+ fields: breadcrumbsSectionFields,
246
+ resolveFields: (_data, params) => {
247
+ const streamDocument = params.metadata?.streamDocument;
248
+ if (!streamDocument) {
249
+ return toPuckFields<BreadcrumbsSectionProps>(breadcrumbsSectionFields);
250
+ }
251
+
252
+ // On root pages there is only one breadcrumb, so "currentPage" duplicates "directoryRoot".
253
+ const breadcrumbCount = resolveBreadcrumbs(streamDocument).length;
254
+ return setDeep(
255
+ toPuckFields<BreadcrumbsSectionProps>(breadcrumbsSectionFields),
256
+ "data.objectFields.currentPage.visible",
257
+ breadcrumbCount !== 1
258
+ );
259
+ },
260
+ defaultProps: {
261
+ data: {
262
+ directoryRoot: { defaultValue: "Directory Root" },
263
+ currentPage: {
264
+ constantValue: { defaultValue: "[[name]]" },
265
+ field: "name",
266
+ constantValueEnabled: false,
267
+ },
268
+ },
269
+ styles: {
270
+ backgroundColor: backgroundColors.background1.value,
271
+ showCurrentPage: true,
272
+ },
273
+ analytics: {
274
+ scope: "breadcrumbs",
275
+ },
276
+ liveVisibility: true,
277
+ },
278
+ render: (props) => {
279
+ return (
280
+ <ComponentErrorBoundary
281
+ isEditing={props.puck.isEditing}
282
+ resetKeys={[props]}
283
+ >
284
+ <AnalyticsScopeProvider
285
+ name={props?.analytics?.scope ?? "breadcrumbs"}
286
+ >
287
+ <VisibilityWrapper
288
+ liveVisibility={props.liveVisibility}
289
+ isEditing={props.puck.isEditing}
290
+ iconSize="md"
291
+ >
292
+ <BreadcrumbsComponent {...props} />
293
+ </VisibilityWrapper>
294
+ </AnalyticsScopeProvider>
295
+ </ComponentErrorBoundary>
296
+ );
297
+ },
298
+ };