@yext/visual-editor 1.4.10 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SectionLibraryVisualEditorProvider-67ng4X9e.js +108670 -0
- package/dist/SectionLibraryVisualEditorProvider.css +1 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Address.tsx +251 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HeadingText.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursStatus.tsx +157 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursTable.tsx +164 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/MapboxStaticMap.tsx +205 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Phone.tsx +155 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/EmptyImageState.tsx +168 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/Image.tsx +275 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/styling.ts +66 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/index.ts +13 -0
- package/dist/cli/assets/directory-locator-source/components/sections/Breadcrumbs.tsx +298 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.test.tsx +872 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.tsx +260 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryCard.tsx +507 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryWrapper.tsx +491 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.test.tsx +226 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.tsx +98 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +691 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1551 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +541 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +43 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +1594 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +1157 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +304 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/MapPinIcon.tsx +160 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +267 -0
- package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +245 -0
- package/dist/cli/yextve.js +16888 -0
- package/dist/index.d.ts +556 -6260
- package/dist/locales/page/cs/visual-editor.json +85 -0
- package/dist/locales/page/da/visual-editor.json +73 -0
- package/dist/locales/page/de/visual-editor.json +73 -0
- package/dist/locales/page/en/visual-editor.json +73 -0
- package/dist/locales/page/en-GB/visual-editor.json +73 -0
- package/dist/locales/page/es/visual-editor.json +79 -0
- package/dist/locales/page/et/visual-editor.json +73 -0
- package/dist/locales/page/fi/visual-editor.json +73 -0
- package/dist/locales/page/fr/visual-editor.json +79 -0
- package/dist/locales/page/hr/visual-editor.json +79 -0
- package/dist/locales/page/hu/visual-editor.json +73 -0
- package/dist/locales/page/it/visual-editor.json +79 -0
- package/dist/locales/page/ja/visual-editor.json +73 -0
- package/dist/locales/page/lt/visual-editor.json +85 -0
- package/dist/locales/page/lv/visual-editor.json +77 -0
- package/dist/locales/page/nb/visual-editor.json +73 -0
- package/dist/locales/page/nl/visual-editor.json +73 -0
- package/dist/locales/page/pl/visual-editor.json +85 -0
- package/dist/locales/page/pt/visual-editor.json +79 -0
- package/dist/locales/page/ro/visual-editor.json +79 -0
- package/dist/locales/page/sk/visual-editor.json +85 -0
- package/dist/locales/page/sv/visual-editor.json +73 -0
- package/dist/locales/page/tr/visual-editor.json +73 -0
- package/dist/locales/page/zh/visual-editor.json +73 -0
- package/dist/locales/page/zh-TW/visual-editor.json +73 -0
- package/dist/locales/platform/cs/visual-editor.json +531 -0
- package/dist/locales/platform/da/visual-editor.json +519 -0
- package/dist/locales/platform/de/visual-editor.json +519 -0
- package/dist/locales/platform/en/visual-editor.json +519 -0
- package/dist/locales/platform/en-GB/visual-editor.json +519 -0
- package/dist/locales/platform/es/visual-editor.json +525 -0
- package/dist/locales/platform/et/visual-editor.json +519 -0
- package/dist/locales/platform/fi/visual-editor.json +519 -0
- package/dist/locales/platform/fr/visual-editor.json +525 -0
- package/dist/locales/platform/hr/visual-editor.json +525 -0
- package/dist/locales/platform/hu/visual-editor.json +519 -0
- package/dist/locales/platform/it/visual-editor.json +525 -0
- package/dist/locales/platform/ja/visual-editor.json +519 -0
- package/dist/locales/platform/lt/visual-editor.json +531 -0
- package/dist/locales/platform/lv/visual-editor.json +523 -0
- package/dist/locales/platform/nb/visual-editor.json +519 -0
- package/dist/locales/platform/nl/visual-editor.json +519 -0
- package/dist/locales/platform/pl/visual-editor.json +531 -0
- package/dist/locales/platform/pt/visual-editor.json +525 -0
- package/dist/locales/platform/ro/visual-editor.json +525 -0
- package/dist/locales/platform/sk/visual-editor.json +531 -0
- package/dist/locales/platform/sv/visual-editor.json +519 -0
- package/dist/locales/platform/tr/visual-editor.json +519 -0
- package/dist/locales/platform/zh/visual-editor.json +519 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +519 -0
- package/dist/locatorEntityTypes-s4dmT9l5.d.ts +1850 -0
- package/dist/plugin/internal/sectionLibraryValidation/builtInTranslationResources.d.ts +3 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/api.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/libraryMetadata.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/importRules.d.ts +13 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/validateCode.d.ts +10 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/xssRules.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/structure/structure.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/types.d.ts +48 -0
- package/dist/plugin/internal/sectionLibraryValidation/validateSectionLibrary.d.ts +8 -0
- package/dist/plugin/internal/sectionLibraryValidation/validationError.d.ts +6 -0
- package/dist/plugin/plugin.js +2233 -5786
- package/dist/plugin/types/entityFields.d.ts +21 -0
- package/dist/plugin/types/images.d.ts +62 -0
- package/dist/plugin/types/sectionLibrary.d.ts +94 -0
- package/dist/plugin/types/types.d.ts +204 -0
- package/dist/plugin/types/videos.d.ts +24 -0
- package/dist/plugin/utils/i18n/locales.d.ts +5 -0
- package/dist/plugin/utils/i18n/translationResources.d.ts +41 -0
- package/dist/plugin/utils/normalizeLocale.d.ts +8 -0
- package/dist/plugin/utils/plainText.d.ts +6 -0
- package/dist/plugin/vite-plugin/index.d.ts +2 -0
- package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +18 -0
- package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
- package/dist/plugin/vite-plugin/local-editor/data.d.ts +10 -0
- package/dist/plugin/vite-plugin/local-editor/entityFields.d.ts +13 -0
- package/dist/plugin/vite-plugin/local-editor/fixtureData.d.ts +12 -0
- package/dist/plugin/vite-plugin/local-editor/generatedFiles.d.ts +34 -0
- package/dist/plugin/vite-plugin/local-editor/server.d.ts +18 -0
- package/dist/plugin/vite-plugin/local-editor/types.d.ts +109 -0
- package/dist/plugin/vite-plugin/local-editor/utils.d.ts +16 -0
- package/dist/plugin/vite-plugin/plugin.d.ts +8 -0
- package/dist/plugin/vite-plugin/section-library/migrationRegistry.d.ts +6 -0
- package/dist/plugin/vite-plugin/section-library/sectionFrontmatter.d.ts +3 -0
- package/dist/plugin/vite-plugin/section-library/sectionLibraryGenerator.d.ts +21 -0
- package/dist/plugin/vite-plugin/section-library/sharedComponentRegistry.d.ts +16 -0
- package/dist/section-library-support.js +158 -0
- package/dist/sectionLibrarySupport.d.ts +282 -0
- package/dist/style.css +1 -1
- package/dist/visual-editor-9bLkRo2X.js +702 -0
- package/dist/visual-editor-B5f3AZF6.js +706 -0
- package/dist/visual-editor-BGZbJkMp.js +694 -0
- package/dist/visual-editor-BPVqHHz5.js +706 -0
- package/dist/visual-editor-BPvDMSb8.js +706 -0
- package/dist/visual-editor-BTT9n9b6.js +718 -0
- package/dist/visual-editor-BXSlgf31.js +694 -0
- package/dist/visual-editor-BXYlpe7B.js +145 -0
- package/dist/visual-editor-Bez9GftS.js +694 -0
- package/dist/visual-editor-Bk5QJccl.js +718 -0
- package/dist/visual-editor-BqtG2m0y.js +694 -0
- package/dist/visual-editor-Bxy81Ezy.js +145 -0
- package/dist/visual-editor-C00efXqJ.js +706 -0
- package/dist/visual-editor-C0vq2BRM.js +145 -0
- package/dist/visual-editor-CCgmYV5S.js +169 -0
- package/dist/visual-editor-CERViyTJ.js +145 -0
- package/dist/visual-editor-CZdmgAn0.js +706 -0
- package/dist/visual-editor-CcOCcCUQ.js +694 -0
- package/dist/visual-editor-CjORnP1D.js +169 -0
- package/dist/visual-editor-CmomGJB8.js +157 -0
- package/dist/visual-editor-Cymg8ID2.js +169 -0
- package/dist/visual-editor-D2Hk1nhM.js +145 -0
- package/dist/visual-editor-D2_8u6ZI.js +694 -0
- package/dist/visual-editor-D4vaqoBN.js +694 -0
- package/dist/visual-editor-D6n8EP_O.js +694 -0
- package/dist/visual-editor-D8MRFn5x.js +157 -0
- package/dist/visual-editor-DKG_E7X4.js +694 -0
- package/dist/visual-editor-DOXtCqRv.js +145 -0
- package/dist/visual-editor-DQEd3xwY.js +145 -0
- package/dist/visual-editor-DQq0_rUn.js +706 -0
- package/dist/visual-editor-DRXezaoB.js +694 -0
- package/dist/visual-editor-DUngIOnE.js +157 -0
- package/dist/visual-editor-DbgFzBNV.js +718 -0
- package/dist/visual-editor-DeZVZYfd.js +169 -0
- package/dist/visual-editor-DfJMZpiP.js +145 -0
- package/dist/visual-editor-DgAsQK9D.js +145 -0
- package/dist/visual-editor-Dhi__-7_.js +145 -0
- package/dist/visual-editor-DiLdoISr.js +718 -0
- package/dist/visual-editor-DjdqpJU-.js +145 -0
- package/dist/visual-editor-DnTPMRV4.js +694 -0
- package/dist/visual-editor-DvuH3jyL.js +157 -0
- package/dist/visual-editor-E0hASBXn.js +694 -0
- package/dist/visual-editor-TfVDfO5_.js +145 -0
- package/dist/visual-editor-W1OHU94y.js +694 -0
- package/dist/visual-editor-W_ZDmMFn.js +145 -0
- package/dist/visual-editor-b7ALusk8.js +145 -0
- package/dist/visual-editor-bauJ9beX.js +694 -0
- package/dist/visual-editor-erGXf3kS.js +157 -0
- package/dist/visual-editor-xnDHZFuO.js +153 -0
- package/dist/visual-editor-yiWZqIH0.js +157 -0
- package/dist/visual-editor.css +1 -0
- package/dist/visual-editor.js +15059 -136530
- package/package.json +45 -24
- package/dist/editor.css +0 -1
- package/dist/visual-editor--AAsqhQc.js +0 -231
- package/dist/visual-editor-32on_5DY.js +0 -243
- package/dist/visual-editor-49W0_Daf.js +0 -1002
- package/dist/visual-editor-8Lal-QZf.js +0 -219
- package/dist/visual-editor-B02CmTCX.js +0 -1002
- package/dist/visual-editor-BB0a_4dr.js +0 -243
- package/dist/visual-editor-BQa0UK-c.js +0 -1002
- package/dist/visual-editor-BRG83zQG.js +0 -1010
- package/dist/visual-editor-BVBPuEsB.js +0 -219
- package/dist/visual-editor-BcCzbooi.js +0 -243
- package/dist/visual-editor-BiemHMaD.js +0 -1014
- package/dist/visual-editor-Bkj-BZ8U.js +0 -1002
- package/dist/visual-editor-Bm_9l-r1.js +0 -1014
- package/dist/visual-editor-BsyZIlAm.js +0 -1002
- package/dist/visual-editor-BuUXmEr4.js +0 -1002
- package/dist/visual-editor-BxUYaP8B.js +0 -219
- package/dist/visual-editor-By1sH42E.js +0 -219
- package/dist/visual-editor-By9M5eN4.js +0 -231
- package/dist/visual-editor-C-MDqVaH.js +0 -219
- package/dist/visual-editor-C37Hro7w.js +0 -1026
- package/dist/visual-editor-C9I9pWeQ.js +0 -1014
- package/dist/visual-editor-CQOcLK3A.js +0 -1002
- package/dist/visual-editor-CSIc6-rm.js +0 -219
- package/dist/visual-editor-CaTT6blQ.js +0 -227
- package/dist/visual-editor-Cw95D-E7.js +0 -1014
- package/dist/visual-editor-CwW9rVaZ.js +0 -1002
- package/dist/visual-editor-CzC6S5LB.js +0 -1014
- package/dist/visual-editor-DAuNRkq8.js +0 -1026
- package/dist/visual-editor-DE8qwWp0.js +0 -1002
- package/dist/visual-editor-DEmVxnyc.js +0 -1014
- package/dist/visual-editor-DFQml8X8.js +0 -219
- package/dist/visual-editor-DHbDTZwW.js +0 -231
- package/dist/visual-editor-DR14jsjF.js +0 -219
- package/dist/visual-editor-DiO1-u9c.js +0 -243
- package/dist/visual-editor-Dk9cgdJp.js +0 -231
- package/dist/visual-editor-DlohF7nV.js +0 -219
- package/dist/visual-editor-DrbkrTPj.js +0 -231
- package/dist/visual-editor-Dwy8xGNv.js +0 -1002
- package/dist/visual-editor-Dz0yJDfm.js +0 -1026
- package/dist/visual-editor-InSI7qrX.js +0 -1026
- package/dist/visual-editor-KBcW6ZCw.js +0 -1002
- package/dist/visual-editor-Kgxgyjx4.js +0 -231
- package/dist/visual-editor-S4ACDl-Z.js +0 -1002
- package/dist/visual-editor-VLIdGBGJ.js +0 -1002
- package/dist/visual-editor-d-hTp0p2.js +0 -219
- package/dist/visual-editor-hqdcvtls.js +0 -219
- package/dist/visual-editor-llBar-sw.js +0 -1002
- package/dist/visual-editor-pb5PwMmE.js +0 -219
- package/dist/visual-editor-wSWVK8SW.js +0 -219
- package/dist/visual-editor-z-YqfQf7.js +0 -219
package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryCard.tsx
ADDED
|
@@ -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
|
+
};
|