@yext/visual-editor 1.4.14 → 2.0.0-beta.10
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-DN65KSX7.js +119824 -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 +298 -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 +499 -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 +277 -0
- package/dist/cli/yextve.js +16992 -0
- package/dist/createYextFieldTransforms-CrIkiJ_X.d.ts +2157 -0
- package/dist/index.d.ts +534 -6352
- 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 +651 -0
- package/dist/locales/platform/da/visual-editor.json +625 -0
- package/dist/locales/platform/de/visual-editor.json +625 -0
- package/dist/locales/platform/en/visual-editor.json +625 -0
- package/dist/locales/platform/en-GB/visual-editor.json +625 -0
- package/dist/locales/platform/es/visual-editor.json +638 -0
- package/dist/locales/platform/et/visual-editor.json +625 -0
- package/dist/locales/platform/fi/visual-editor.json +625 -0
- package/dist/locales/platform/fr/visual-editor.json +638 -0
- package/dist/locales/platform/hr/visual-editor.json +638 -0
- package/dist/locales/platform/hu/visual-editor.json +625 -0
- package/dist/locales/platform/it/visual-editor.json +638 -0
- package/dist/locales/platform/ja/visual-editor.json +625 -0
- package/dist/locales/platform/lt/visual-editor.json +651 -0
- package/dist/locales/platform/lv/visual-editor.json +633 -0
- package/dist/locales/platform/nb/visual-editor.json +625 -0
- package/dist/locales/platform/nl/visual-editor.json +625 -0
- package/dist/locales/platform/pl/visual-editor.json +651 -0
- package/dist/locales/platform/pt/visual-editor.json +638 -0
- package/dist/locales/platform/ro/visual-editor.json +638 -0
- package/dist/locales/platform/sk/visual-editor.json +651 -0
- package/dist/locales/platform/sv/visual-editor.json +625 -0
- package/dist/locales/platform/tr/visual-editor.json +625 -0
- package/dist/locales/platform/zh/visual-editor.json +625 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +625 -0
- package/dist/plugin/internal/layoutGeneration/limits.d.ts +28 -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 +7013 -5873
- package/dist/plugin/types/entityFields.d.ts +21 -0
- package/dist/plugin/types/generationPrompts.d.ts +19 -0
- package/dist/plugin/types/generationSettings.d.ts +12 -0
- package/dist/plugin/types/images.d.ts +62 -0
- package/dist/plugin/types/sectionLibrary.d.ts +101 -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/layout-generation/generationLogger.d.ts +5 -0
- package/dist/plugin/vite-plugin/layout-generation/generationReports.d.ts +13 -0
- package/dist/plugin/vite-plugin/layout-generation/middleware.d.ts +14 -0
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +9 -0
- package/dist/plugin/vite-plugin/layout-generation/prompts.d.ts +17 -0
- package/dist/plugin/vite-plugin/layout-generation/settings.d.ts +3 -0
- package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +20 -0
- package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
- package/dist/plugin/vite-plugin/local-editor/data.d.ts +12 -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 +33 -0
- package/dist/plugin/vite-plugin/local-editor/server.d.ts +34 -0
- package/dist/plugin/vite-plugin/local-editor/types.d.ts +125 -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 +178 -0
- package/dist/sectionLibrarySupport.d.ts +703 -0
- package/dist/style.css +1 -1
- package/dist/visual-editor-6mKs9VUe.js +842 -0
- package/dist/visual-editor-BK6fTU7k.js +804 -0
- package/dist/visual-editor-BXYlpe7B.js +145 -0
- package/dist/visual-editor-BruRrJYN.js +804 -0
- package/dist/visual-editor-Bs3wAslG.js +804 -0
- package/dist/visual-editor-Bxy81Ezy.js +145 -0
- package/dist/visual-editor-C0vq2BRM.js +145 -0
- package/dist/visual-editor-C9TLeAzP.js +804 -0
- package/dist/visual-editor-CCgmYV5S.js +169 -0
- package/dist/visual-editor-CERViyTJ.js +145 -0
- package/dist/visual-editor-CHWtMtlu.js +823 -0
- package/dist/visual-editor-CcfUKpnd.js +804 -0
- package/dist/visual-editor-CjORnP1D.js +169 -0
- package/dist/visual-editor-ClC6hoz3.js +804 -0
- package/dist/visual-editor-CmomGJB8.js +157 -0
- package/dist/visual-editor-CtQwadxQ.js +842 -0
- package/dist/visual-editor-Cymg8ID2.js +169 -0
- package/dist/visual-editor-D2Hk1nhM.js +145 -0
- package/dist/visual-editor-D7VeTRK_.js +816 -0
- package/dist/visual-editor-D8MRFn5x.js +157 -0
- package/dist/visual-editor-DOXtCqRv.js +145 -0
- package/dist/visual-editor-DQEd3xwY.js +145 -0
- package/dist/visual-editor-DTE5kxrA.js +804 -0
- package/dist/visual-editor-DUngIOnE.js +157 -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-DjTEbi-1.js +842 -0
- package/dist/visual-editor-DjdqpJU-.js +145 -0
- package/dist/visual-editor-DkHhrFsX.js +804 -0
- package/dist/visual-editor-DtL-Zuv_.js +804 -0
- package/dist/visual-editor-Duishbsa.js +842 -0
- package/dist/visual-editor-DvuH3jyL.js +157 -0
- package/dist/visual-editor-LXMNWXry.js +823 -0
- package/dist/visual-editor-QpGupjY5.js +823 -0
- package/dist/visual-editor-TfVDfO5_.js +145 -0
- package/dist/visual-editor-W_ZDmMFn.js +145 -0
- package/dist/visual-editor-_TatCCAS.js +804 -0
- package/dist/visual-editor-b7ALusk8.js +145 -0
- package/dist/visual-editor-erGXf3kS.js +157 -0
- package/dist/visual-editor-gEaWoNRu.js +804 -0
- package/dist/visual-editor-gjpr-NAN.js +804 -0
- package/dist/visual-editor-qJW0uCiQ.js +804 -0
- package/dist/visual-editor-sOPDMkOR.js +823 -0
- package/dist/visual-editor-tPb7n5l8.js +823 -0
- package/dist/visual-editor-vomNdlNO.js +804 -0
- package/dist/visual-editor-xnDHZFuO.js +153 -0
- package/dist/visual-editor-yiWZqIH0.js +157 -0
- package/dist/visual-editor-zKhC7_0C.js +823 -0
- package/dist/visual-editor.css +1 -0
- package/dist/visual-editor.js +18578 -137536
- package/package.json +50 -26
- package/dist/editor.css +0 -1
- package/dist/visual-editor-6pnSx-yp.js +0 -223
- package/dist/visual-editor-9ZW3nq5u.js +0 -247
- package/dist/visual-editor-B1RXDqNi.js +0 -1063
- package/dist/visual-editor-BAahiZ1l.js +0 -223
- package/dist/visual-editor-BC2LjdoF.js +0 -223
- package/dist/visual-editor-BPnfBfk1.js +0 -1051
- package/dist/visual-editor-BQiE5eVW.js +0 -1051
- package/dist/visual-editor-BTv-6Pnk.js +0 -1051
- package/dist/visual-editor-BUWp03gX.js +0 -235
- package/dist/visual-editor-Bb3c6iGV.js +0 -223
- package/dist/visual-editor-BipczqTj.js +0 -1075
- package/dist/visual-editor-BlIUd_n_.js +0 -1051
- package/dist/visual-editor-BoPLXEu2.js +0 -223
- package/dist/visual-editor-Bzmpi_9a.js +0 -1063
- package/dist/visual-editor-C38IiBTR.js +0 -235
- package/dist/visual-editor-C9tacnim.js +0 -247
- package/dist/visual-editor-CVa3iu5h.js +0 -1051
- package/dist/visual-editor-CXTL8Ik0.js +0 -1051
- package/dist/visual-editor-CYeahjFX.js +0 -231
- package/dist/visual-editor-CZ2SM6Jc.js +0 -1063
- package/dist/visual-editor-CZDmQI-A.js +0 -1063
- package/dist/visual-editor-C_cHJ6BN.js +0 -1051
- package/dist/visual-editor-Cf3nFbw3.js +0 -235
- package/dist/visual-editor-CiR0metz.js +0 -1051
- package/dist/visual-editor-CoX_NnS-.js +0 -223
- package/dist/visual-editor-Cu8II23Y.js +0 -223
- package/dist/visual-editor-CvXFxocc.js +0 -1063
- package/dist/visual-editor-Cxu6nkib.js +0 -1051
- package/dist/visual-editor-D-3VVfjR.js +0 -223
- package/dist/visual-editor-D-ktbg7q.js +0 -223
- package/dist/visual-editor-D9G5eAAU.js +0 -1051
- package/dist/visual-editor-D9MrqEya.js +0 -223
- package/dist/visual-editor-DAKXBbjV.js +0 -1075
- package/dist/visual-editor-DBmJk7ZR.js +0 -235
- package/dist/visual-editor-DG-c2LU9.js +0 -1051
- package/dist/visual-editor-DI_Vk989.js +0 -1051
- package/dist/visual-editor-DOOYgnjP.js +0 -235
- package/dist/visual-editor-DRx3Ax_O.js +0 -1075
- package/dist/visual-editor-DZ66sria.js +0 -1051
- package/dist/visual-editor-DZTPhYcr.js +0 -247
- package/dist/visual-editor-DcH7WJVI.js +0 -223
- package/dist/visual-editor-DdYXgEbR.js +0 -1059
- package/dist/visual-editor-DeWzgcue.js +0 -1063
- package/dist/visual-editor-Dm5ZNn8C.js +0 -223
- package/dist/visual-editor-DqLCIWPQ.js +0 -1051
- package/dist/visual-editor-NoU28r5Y.js +0 -223
- package/dist/visual-editor-WjrJ9nPc.js +0 -235
- package/dist/visual-editor-_h-sdbID.js +0 -223
- package/dist/visual-editor-r4gSQqFM.js +0 -1075
- package/dist/visual-editor-ujQ29mao.js +0 -247
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Coordinate,
|
|
3
|
+
MapboxMap,
|
|
4
|
+
MapMarkerOptions,
|
|
5
|
+
OnDragHandler,
|
|
6
|
+
PinComponentProps,
|
|
7
|
+
} from "@yext/search-ui-react";
|
|
8
|
+
import { Result } from "@yext/search-headless-react";
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { useTranslation } from "react-i18next";
|
|
11
|
+
import { ImageField } from "../../../fields/ImageField.tsx";
|
|
12
|
+
import { useDocument } from "../../../hooks/useDocument.tsx";
|
|
13
|
+
import { msg } from "../../../utils/i18n/platform.ts";
|
|
14
|
+
import {
|
|
15
|
+
backgroundColors,
|
|
16
|
+
ThemeColor,
|
|
17
|
+
} from "../../../utils/themeConfigOptions.ts";
|
|
18
|
+
import { StreamDocument } from "../../../utils/types/StreamDocument.ts";
|
|
19
|
+
import { Body } from "../../atoms/body.tsx";
|
|
20
|
+
import { MapPinIcon } from "./MapPinIcon.tsx";
|
|
21
|
+
import { isVisualEditorTestEnv } from "../../testing/utils.ts";
|
|
22
|
+
import { Location } from "./LocatorResultCard.tsx";
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_MAP_CENTER: Coordinate = {
|
|
25
|
+
latitude: 40.741611,
|
|
26
|
+
longitude: -74.005371,
|
|
27
|
+
}; // New York City
|
|
28
|
+
export const DEFAULT_RADIUS = 25;
|
|
29
|
+
export const DEFAULT_PIN_ICON_WIDTH = 14;
|
|
30
|
+
export const DEFAULT_LOCATION_STYLE = {
|
|
31
|
+
pinIcon: { type: "none" },
|
|
32
|
+
pinColor: backgroundColors.background6.value,
|
|
33
|
+
};
|
|
34
|
+
export const MAX_PIN_ICON_WIDTH = 27;
|
|
35
|
+
const PIN_ICON_MAX_FILE_SIZE_BYTES = 128 * 1024;
|
|
36
|
+
|
|
37
|
+
export type LocationStyleConfig = Record<
|
|
38
|
+
string,
|
|
39
|
+
{
|
|
40
|
+
color?: ThemeColor;
|
|
41
|
+
icon?: string;
|
|
42
|
+
customImage?: {
|
|
43
|
+
url: string;
|
|
44
|
+
width?: number;
|
|
45
|
+
aspectRatio?: number;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
export const LOCATOR_PIN_ICON_FIELD: ImageField = {
|
|
51
|
+
type: "image",
|
|
52
|
+
label: msg("fields.icon", "Icon"),
|
|
53
|
+
hideAltTextField: true,
|
|
54
|
+
maxFileSizeBytes: PIN_ICON_MAX_FILE_SIZE_BYTES,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const getConfiguredMapCenterOrDefault = (mapStartingLocation?: {
|
|
58
|
+
latitude: string;
|
|
59
|
+
longitude: string;
|
|
60
|
+
}): Coordinate => {
|
|
61
|
+
if (mapStartingLocation?.latitude && mapStartingLocation.longitude) {
|
|
62
|
+
try {
|
|
63
|
+
return parseMapStartingLocation(mapStartingLocation);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return DEFAULT_MAP_CENTER;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const makiIconModules = import.meta.glob(
|
|
73
|
+
"../../../node_modules/@mapbox/maki/icons/*.svg",
|
|
74
|
+
{
|
|
75
|
+
eager: true,
|
|
76
|
+
import: "default",
|
|
77
|
+
}
|
|
78
|
+
) as Record<string, string>;
|
|
79
|
+
|
|
80
|
+
const makiIconEntries = Object.entries(makiIconModules).map(([path, icon]) => {
|
|
81
|
+
const name = path.split("/").pop()?.replace(".svg", "") || path;
|
|
82
|
+
return [name, icon] as const;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const makiIconMap: Record<string, string> =
|
|
86
|
+
Object.fromEntries(makiIconEntries);
|
|
87
|
+
|
|
88
|
+
const formatMakiIconLabel = (name: string) =>
|
|
89
|
+
name.replace(/[-_]/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
90
|
+
|
|
91
|
+
export const makiIconOptions = makiIconEntries.map(([name, icon]) => ({
|
|
92
|
+
label: formatMakiIconLabel(name),
|
|
93
|
+
value: name,
|
|
94
|
+
icon,
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
export const DEFAULT_MAKI_ICON_NAME = makiIconOptions[0]?.value;
|
|
98
|
+
|
|
99
|
+
export const LoadingMapPlaceholder = () => {
|
|
100
|
+
const { t } = useTranslation();
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div className="flex items-center justify-center w-full h-full">
|
|
104
|
+
<div className="border border-gray-300 rounded-lg p-6 bg-white shadow-md">
|
|
105
|
+
<Body className="text-gray-700" variant="lg">
|
|
106
|
+
{t("loadingMap", "Loading Map...")}
|
|
107
|
+
</Body>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const LocatorTestMap = () => {
|
|
114
|
+
return (
|
|
115
|
+
<div
|
|
116
|
+
className="relative h-full w-full overflow-hidden"
|
|
117
|
+
style={{
|
|
118
|
+
background:
|
|
119
|
+
"linear-gradient(135deg, #dcfce7 0%, #dbeafe 55%, #fde68a 100%)",
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
<div
|
|
123
|
+
aria-hidden="true"
|
|
124
|
+
className="absolute inset-0 opacity-30"
|
|
125
|
+
style={{
|
|
126
|
+
backgroundImage:
|
|
127
|
+
"linear-gradient(rgba(255,255,255,0.2) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.2) 1px, transparent 1px)",
|
|
128
|
+
backgroundPosition: "0 0, 0 0",
|
|
129
|
+
backgroundSize: "48px 48px",
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
interface MapProps {
|
|
137
|
+
mapStyle?: string;
|
|
138
|
+
centerCoords?: Coordinate;
|
|
139
|
+
onDragHandler?: OnDragHandler;
|
|
140
|
+
scrollToResult?: (result: Result<Location> | undefined) => void;
|
|
141
|
+
markerOptionsOverride?: (selected: boolean) => MapMarkerOptions;
|
|
142
|
+
locationStyleConfig?: LocationStyleConfig;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const LocatorMap: React.FC<MapProps> = ({
|
|
146
|
+
mapStyle,
|
|
147
|
+
centerCoords,
|
|
148
|
+
onDragHandler,
|
|
149
|
+
scrollToResult,
|
|
150
|
+
markerOptionsOverride,
|
|
151
|
+
locationStyleConfig,
|
|
152
|
+
}) => {
|
|
153
|
+
const entityDocument: StreamDocument = useDocument();
|
|
154
|
+
|
|
155
|
+
const documentIsUndefined = typeof document === "undefined";
|
|
156
|
+
const iframe = documentIsUndefined
|
|
157
|
+
? undefined
|
|
158
|
+
: (document.getElementById("preview-frame") as HTMLIFrameElement);
|
|
159
|
+
|
|
160
|
+
const locatorMapDiv = documentIsUndefined
|
|
161
|
+
? null
|
|
162
|
+
: ((iframe?.contentDocument || document)?.getElementById(
|
|
163
|
+
"locatorMapDiv"
|
|
164
|
+
) as HTMLDivElement | null);
|
|
165
|
+
|
|
166
|
+
const mapPadding = React.useMemo(
|
|
167
|
+
() => getMapboxMapPadding(locatorMapDiv),
|
|
168
|
+
[locatorMapDiv]
|
|
169
|
+
);
|
|
170
|
+
const mapboxOptions = React.useMemo(
|
|
171
|
+
() => ({
|
|
172
|
+
center: centerCoords,
|
|
173
|
+
fitBoundsOptions: { padding: mapPadding },
|
|
174
|
+
...(mapStyle ? { style: mapStyle } : {}),
|
|
175
|
+
}),
|
|
176
|
+
[centerCoords, mapPadding, mapStyle]
|
|
177
|
+
);
|
|
178
|
+
const PinComponent = React.useMemo(
|
|
179
|
+
() =>
|
|
180
|
+
function PinComponent<T>(pinProps: PinComponentProps<T>) {
|
|
181
|
+
return (
|
|
182
|
+
<LocatorMapPin
|
|
183
|
+
{...pinProps}
|
|
184
|
+
locationStyleConfig={locationStyleConfig}
|
|
185
|
+
/>
|
|
186
|
+
);
|
|
187
|
+
},
|
|
188
|
+
[locationStyleConfig]
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
if (isVisualEditorTestEnv()) {
|
|
192
|
+
return <LocatorTestMap />;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// During page generation we don't exist in a browser context
|
|
196
|
+
//@ts-expect-error MapboxGL is not loaded in iframe content window
|
|
197
|
+
if (iframe?.contentDocument && !iframe.contentWindow?.mapboxgl) {
|
|
198
|
+
// We are in an iframe, and mapboxgl is not loaded in yet
|
|
199
|
+
return <LoadingMapPlaceholder />;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let mapboxApiKey = entityDocument._env?.YEXT_MAPBOX_API_KEY;
|
|
203
|
+
if (
|
|
204
|
+
iframe?.contentDocument &&
|
|
205
|
+
entityDocument._env?.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY
|
|
206
|
+
) {
|
|
207
|
+
// If we are in the layout editor, use the non-URL-restricted Mapbox API key
|
|
208
|
+
mapboxApiKey = entityDocument._env.YEXT_EDIT_LAYOUT_MODE_MAPBOX_API_KEY;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<MapboxMap
|
|
213
|
+
mapboxAccessToken={mapboxApiKey || ""}
|
|
214
|
+
mapboxOptions={mapboxOptions}
|
|
215
|
+
onDrag={onDragHandler}
|
|
216
|
+
PinComponent={PinComponent}
|
|
217
|
+
iframeWindow={iframe?.contentWindow ?? undefined}
|
|
218
|
+
allowUpdates={!!iframe?.contentDocument}
|
|
219
|
+
onPinClick={scrollToResult}
|
|
220
|
+
markerOptionsOverride={markerOptionsOverride}
|
|
221
|
+
/>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
type LocatorMapPinProps<T> = PinComponentProps<T> & {
|
|
226
|
+
locationStyleConfig?: LocationStyleConfig;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const LocatorMapPin = <T,>({
|
|
230
|
+
result,
|
|
231
|
+
selected,
|
|
232
|
+
locationStyleConfig,
|
|
233
|
+
}: LocatorMapPinProps<T>) => {
|
|
234
|
+
const entityType = result.entityType;
|
|
235
|
+
const entityLocationStyle = entityType
|
|
236
|
+
? locationStyleConfig?.[entityType]
|
|
237
|
+
: undefined;
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<MapPinIcon
|
|
241
|
+
color={entityLocationStyle?.color}
|
|
242
|
+
resultIndex={result.index}
|
|
243
|
+
icon={entityLocationStyle?.customImage?.url ?? entityLocationStyle?.icon}
|
|
244
|
+
iconWidth={
|
|
245
|
+
entityLocationStyle?.customImage?.width ?? DEFAULT_PIN_ICON_WIDTH
|
|
246
|
+
}
|
|
247
|
+
disableContrastIcon={!!entityLocationStyle?.customImage}
|
|
248
|
+
aspectRatio={entityLocationStyle?.customImage?.aspectRatio}
|
|
249
|
+
selected={selected}
|
|
250
|
+
/>
|
|
251
|
+
);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const getMapboxMapPadding = (divElement: HTMLDivElement | null) => {
|
|
255
|
+
if (!divElement) {
|
|
256
|
+
return 50;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const { width, height } = divElement.getBoundingClientRect();
|
|
260
|
+
const mapVerticalPadding = Math.max(50, height * 0.2);
|
|
261
|
+
const mapHorizontalPadding = Math.max(50, width * 0.2);
|
|
262
|
+
return {
|
|
263
|
+
top: mapVerticalPadding,
|
|
264
|
+
bottom: mapVerticalPadding,
|
|
265
|
+
left: mapHorizontalPadding,
|
|
266
|
+
right: mapHorizontalPadding,
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export const parseMapStartingLocation = (mapStartingLocation: {
|
|
271
|
+
latitude: string;
|
|
272
|
+
longitude: string;
|
|
273
|
+
}): Coordinate => {
|
|
274
|
+
const lat = parseFloat(mapStartingLocation.latitude);
|
|
275
|
+
const lng = parseFloat(mapStartingLocation.longitude);
|
|
276
|
+
|
|
277
|
+
const err: string[] = [];
|
|
278
|
+
if (isNaN(lat) || lat < -90 || lat > 90) {
|
|
279
|
+
err.push("Latitude must be a number between -90 and 90.");
|
|
280
|
+
}
|
|
281
|
+
if (isNaN(lng) || lng < -180 || lng > 180) {
|
|
282
|
+
err.push("Longitude must be a number between -180 and 180.");
|
|
283
|
+
}
|
|
284
|
+
if (err.length) {
|
|
285
|
+
throw new Error(err.join("\n"));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
latitude: lat,
|
|
290
|
+
longitude: lng,
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** Checks whether a given lat and lng are valid coordinates */
|
|
295
|
+
export function areValidCoordinates(lat: number, lng: number): boolean {
|
|
296
|
+
return (
|
|
297
|
+
!isNaN(lat) &&
|
|
298
|
+
!isNaN(lng) &&
|
|
299
|
+
lat >= -90 &&
|
|
300
|
+
lat <= 90 &&
|
|
301
|
+
lng >= -180 &&
|
|
302
|
+
lng <= 180
|
|
303
|
+
);
|
|
304
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useTranslation } from "react-i18next";
|
|
3
|
+
import { ThemeColor } from "../../../utils/themeConfigOptions.ts";
|
|
4
|
+
import { getThemeColorCssValue } from "../../../utils/colors.ts";
|
|
5
|
+
|
|
6
|
+
const resolveCssVarColor = (
|
|
7
|
+
element: Element,
|
|
8
|
+
varName: string
|
|
9
|
+
): string | undefined => {
|
|
10
|
+
return window.getComputedStyle(element).getPropertyValue(varName).trim();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const resolveContrastColor = (
|
|
14
|
+
element: Element,
|
|
15
|
+
textToken: string
|
|
16
|
+
): string | undefined => {
|
|
17
|
+
if (textToken === "black") {
|
|
18
|
+
return "#000000";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (textToken === "white") {
|
|
22
|
+
return "#FFFFFF";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (textToken) {
|
|
26
|
+
return resolveCssVarColor(element, `--colors-${textToken}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Renders a Mapbox-style pin with theme-aware fill and contrast-aware icon/number in the center.
|
|
33
|
+
export const MapPinIcon = ({
|
|
34
|
+
color,
|
|
35
|
+
resultIndex,
|
|
36
|
+
icon,
|
|
37
|
+
iconWidth,
|
|
38
|
+
disableContrastIcon,
|
|
39
|
+
aspectRatio,
|
|
40
|
+
selected,
|
|
41
|
+
}: {
|
|
42
|
+
color?: ThemeColor;
|
|
43
|
+
resultIndex?: number;
|
|
44
|
+
icon?: string;
|
|
45
|
+
iconWidth: number;
|
|
46
|
+
disableContrastIcon?: boolean;
|
|
47
|
+
aspectRatio?: number;
|
|
48
|
+
selected?: boolean;
|
|
49
|
+
}) => {
|
|
50
|
+
const { t } = useTranslation();
|
|
51
|
+
const pinHeight = 41;
|
|
52
|
+
const pinWidth = 27;
|
|
53
|
+
const pinScale = 1.5;
|
|
54
|
+
|
|
55
|
+
const centerX = 13.5;
|
|
56
|
+
const centerY = 13.5;
|
|
57
|
+
const iconHeight = aspectRatio ? iconWidth / aspectRatio : iconWidth;
|
|
58
|
+
|
|
59
|
+
const backgroundToken = color?.selectedColor;
|
|
60
|
+
const textToken = color?.contrastingColor;
|
|
61
|
+
const svgRef = React.useRef<SVGSVGElement>(null);
|
|
62
|
+
const [contrastColor, setContrastColor] = React.useState<string | undefined>(
|
|
63
|
+
undefined
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
React.useLayoutEffect(() => {
|
|
67
|
+
// Resolve icon/text contrast color using the theme's text token
|
|
68
|
+
if (svgRef.current && textToken) {
|
|
69
|
+
setContrastColor(resolveContrastColor(svgRef.current, textToken));
|
|
70
|
+
}
|
|
71
|
+
}, [textToken]);
|
|
72
|
+
|
|
73
|
+
// SVG children use currentColor for the pin fill; apply contrast for text/icon.
|
|
74
|
+
const svgStyle = React.useMemo<React.CSSProperties | undefined>(
|
|
75
|
+
() =>
|
|
76
|
+
backgroundToken
|
|
77
|
+
? { color: getThemeColorCssValue(backgroundToken) }
|
|
78
|
+
: undefined,
|
|
79
|
+
[backgroundToken]
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const ariaLabel =
|
|
83
|
+
typeof resultIndex === "number"
|
|
84
|
+
? t("showPinDetails", {
|
|
85
|
+
number: resultIndex,
|
|
86
|
+
defaultValue: "Show pin {{number}} details",
|
|
87
|
+
})
|
|
88
|
+
: t("showPinDetailsDefault", {
|
|
89
|
+
defaultValue: "Show pin details",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
aria-label={ariaLabel}
|
|
96
|
+
className="components block cursor-pointer appearance-none border-0 bg-transparent p-0"
|
|
97
|
+
>
|
|
98
|
+
<svg
|
|
99
|
+
ref={svgRef}
|
|
100
|
+
style={svgStyle}
|
|
101
|
+
display="block"
|
|
102
|
+
height={selected ? pinScale * pinHeight : pinHeight}
|
|
103
|
+
width={selected ? pinScale * pinWidth : pinWidth}
|
|
104
|
+
viewBox="0 0 27 41"
|
|
105
|
+
aria-hidden="true"
|
|
106
|
+
focusable="false"
|
|
107
|
+
>
|
|
108
|
+
<defs>
|
|
109
|
+
<radialGradient id="shadowGradient">
|
|
110
|
+
<stop offset="10%" stopOpacity="0.4"></stop>
|
|
111
|
+
<stop offset="100%" stopOpacity="0.05"></stop>
|
|
112
|
+
</radialGradient>
|
|
113
|
+
</defs>
|
|
114
|
+
<ellipse
|
|
115
|
+
cx="13.5"
|
|
116
|
+
cy="34.8"
|
|
117
|
+
rx="10.5"
|
|
118
|
+
ry="5.25"
|
|
119
|
+
fill="url(#shadowGradient)"
|
|
120
|
+
></ellipse>
|
|
121
|
+
<path
|
|
122
|
+
fill="currentColor"
|
|
123
|
+
d="M27,13.5C27,19.07 20.25,27 14.75,34.5C14.02,35.5 12.98,35.5 12.25,34.5C6.75,27 0,19.22 0,13.5C0,6.04 6.04,0 13.5,0C20.96,0 27,6.04 27,13.5Z"
|
|
124
|
+
></path>
|
|
125
|
+
<path
|
|
126
|
+
opacity="0.25"
|
|
127
|
+
d="M13.5,0C6.04,0 0,6.04 0,13.5C0,19.22 6.75,27 12.25,34.5C13,35.52 14.02,35.5 14.75,34.5C20.25,27 27,19.07 27,13.5C27,6.04 20.96,0 13.5,0ZM13.5,1C20.42,1 26,6.58 26,13.5C26,15.9 24.5,19.18 22.22,22.74C19.95,26.3 16.71,30.14 13.94,33.91C13.74,34.18 13.61,34.32 13.5,34.44C13.39,34.32 13.26,34.18 13.06,33.91C10.28,30.13 7.41,26.31 5.02,22.77C2.62,19.23 1,15.95 1,13.5C1,6.58 6.58,1 13.5,1Z"
|
|
128
|
+
></path>
|
|
129
|
+
{icon ? (
|
|
130
|
+
<image
|
|
131
|
+
href={icon}
|
|
132
|
+
x={centerX - iconWidth / 2}
|
|
133
|
+
y={centerY - iconHeight / 2}
|
|
134
|
+
width={iconWidth}
|
|
135
|
+
height={iconHeight}
|
|
136
|
+
filter={
|
|
137
|
+
contrastColor === "#000000" || disableContrastIcon
|
|
138
|
+
? "invert(0)"
|
|
139
|
+
: "invert(1)"
|
|
140
|
+
}
|
|
141
|
+
preserveAspectRatio="xMidYMid slice"
|
|
142
|
+
/>
|
|
143
|
+
) : (
|
|
144
|
+
!!resultIndex && (
|
|
145
|
+
<text
|
|
146
|
+
textAnchor="middle"
|
|
147
|
+
fontWeight="bold"
|
|
148
|
+
fontSize={iconWidth}
|
|
149
|
+
x="50%"
|
|
150
|
+
y="50%"
|
|
151
|
+
fill={contrastColor ?? "white"}
|
|
152
|
+
>
|
|
153
|
+
{resultIndex}
|
|
154
|
+
</text>
|
|
155
|
+
)
|
|
156
|
+
)}
|
|
157
|
+
</svg>
|
|
158
|
+
</button>
|
|
159
|
+
);
|
|
160
|
+
};
|