@yext/visual-editor 0.0.30 → 0.0.32
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/index.d.cts +22 -7
- package/dist/index.d.ts +22 -7
- package/dist/plugin/plugin.cjs +174 -0
- package/dist/plugin/plugin.js +218 -0
- package/dist/style.css +1 -1
- package/dist/visual-editor.cjs +111 -77
- package/dist/visual-editor.js +12292 -10742
- package/package.json +15 -7
package/dist/index.d.cts
CHANGED
|
@@ -34,7 +34,8 @@ type YextFieldDefinition = {
|
|
|
34
34
|
declare const usePlatformBridgeEntityFields: () => YextSchemaField[] | null;
|
|
35
35
|
declare const useEntityFields: () => YextSchemaField[] | null;
|
|
36
36
|
|
|
37
|
-
declare const
|
|
37
|
+
declare const TemplatePropsContext: React.Context<any>;
|
|
38
|
+
declare const useTemplateProps: <T>() => T;
|
|
38
39
|
declare const useDocument: <T>() => T;
|
|
39
40
|
|
|
40
41
|
declare const TailwindConfigContext: React.Context<any>;
|
|
@@ -198,7 +199,7 @@ declare const getFontWeightOverrideOptions: (options: getFontWeightParams) => Pr
|
|
|
198
199
|
|
|
199
200
|
type AllOrNothing<T extends Record<string, any>> = T | Partial<Record<keyof T, never>>;
|
|
200
201
|
type UniversalProps<T> = {
|
|
201
|
-
|
|
202
|
+
templateProps: T;
|
|
202
203
|
children: React__default.ReactNode;
|
|
203
204
|
};
|
|
204
205
|
type EditorProps$1 = {
|
|
@@ -206,7 +207,7 @@ type EditorProps$1 = {
|
|
|
206
207
|
tailwindConfig: TailwindConfig;
|
|
207
208
|
};
|
|
208
209
|
type VisualEditorProviderProps<T> = UniversalProps<T> & AllOrNothing<EditorProps$1>;
|
|
209
|
-
declare const VisualEditorProvider: <T>({
|
|
210
|
+
declare const VisualEditorProvider: <T>({ templateProps, entityFields, tailwindConfig, children, }: VisualEditorProviderProps<T>) => react_jsx_runtime.JSX.Element;
|
|
210
211
|
|
|
211
212
|
/**
|
|
212
213
|
* Check that the string is a valid slug.
|
|
@@ -276,6 +277,11 @@ declare const BorderRadiusSelector: (label?: string) => Field;
|
|
|
276
277
|
|
|
277
278
|
declare const SpacingSelector: (spacingType: "padding" | "gap", label?: string) => Field;
|
|
278
279
|
|
|
280
|
+
declare const BasicSelector: (label: string, options: {
|
|
281
|
+
label: string;
|
|
282
|
+
value: any;
|
|
283
|
+
}[]) => Field;
|
|
284
|
+
|
|
279
285
|
declare const bodyVariants: (props?: ({
|
|
280
286
|
fontSize?: "default" | "base" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | null | undefined;
|
|
281
287
|
fontWeight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
@@ -312,7 +318,7 @@ declare const CTA: {
|
|
|
312
318
|
};
|
|
313
319
|
|
|
314
320
|
declare const headingVariants: (props?: ({
|
|
315
|
-
level?: 2 | 1 | 3 |
|
|
321
|
+
level?: 2 | 1 | 3 | 4 | 5 | 6 | null | undefined;
|
|
316
322
|
fontSize?: "default" | "base" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | null | undefined;
|
|
317
323
|
weight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
318
324
|
color?: "default" | "text" | "accent" | "secondary" | "primary" | "background" | null | undefined;
|
|
@@ -398,6 +404,7 @@ interface CardProps {
|
|
|
398
404
|
};
|
|
399
405
|
cta: {
|
|
400
406
|
entityField: YextEntityField<CTAProps>;
|
|
407
|
+
linkType: CTAProps["linkType"];
|
|
401
408
|
variant: CTAProps["variant"];
|
|
402
409
|
fontSize: CTAProps["fontSize"];
|
|
403
410
|
};
|
|
@@ -411,6 +418,7 @@ interface CTAWrapperProps {
|
|
|
411
418
|
size: CTAProps["size"];
|
|
412
419
|
borderRadius: CTAProps["borderRadius"];
|
|
413
420
|
fontSize: CTAProps["fontSize"];
|
|
421
|
+
linkType: CTAProps["linkType"];
|
|
414
422
|
className?: CTAProps["className"];
|
|
415
423
|
}
|
|
416
424
|
declare const CTAWrapperComponent: ComponentConfig<CTAWrapperProps>;
|
|
@@ -432,10 +440,10 @@ declare const layoutVariants: (props?: ({
|
|
|
432
440
|
verticalPadding?: "0" | "1" | "2" | "3" | "4" | "default" | "none" | "5" | "6" | "7" | "8" | "12" | "16" | "24" | "14" | "20" | "0.5" | "1.5" | "2.5" | "10" | "3.5" | "9" | "11" | null | undefined;
|
|
433
441
|
horizontalPadding?: "0" | "1" | "2" | "3" | "4" | "default" | "none" | "5" | "6" | "7" | "8" | "12" | "16" | "24" | "14" | "20" | "0.5" | "1.5" | "2.5" | "10" | "3.5" | "9" | "11" | null | undefined;
|
|
434
442
|
backgroundColor?: "default" | "text" | "accent" | "none" | "inherit" | "secondary" | "primary" | "background" | null | undefined;
|
|
435
|
-
} &
|
|
443
|
+
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
436
444
|
declare const innerLayoutVariants: (props?: ({
|
|
437
445
|
maxContentWidth?: "default" | "none" | "lg" | "xl" | "xxl" | null | undefined;
|
|
438
|
-
} &
|
|
446
|
+
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
439
447
|
|
|
440
448
|
interface FlexProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof layoutVariants>, VariantProps<typeof innerLayoutVariants> {
|
|
441
449
|
justifyContent: "start" | "center" | "end";
|
|
@@ -503,6 +511,7 @@ declare const HoursStatusComponent: ComponentConfig<HoursStatusProps>;
|
|
|
503
511
|
declare const phoneVariants: (props?: ({
|
|
504
512
|
fontWeight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
505
513
|
color?: "default" | "text" | "accent" | "secondary" | "primary" | "background" | null | undefined;
|
|
514
|
+
includeHyperlink?: boolean | null | undefined;
|
|
506
515
|
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
507
516
|
interface PhoneProps extends VariantProps<typeof phoneVariants> {
|
|
508
517
|
phone: YextEntityField<string>;
|
|
@@ -535,6 +544,7 @@ interface PromoProps {
|
|
|
535
544
|
entityField: YextEntityField<CTAProps>;
|
|
536
545
|
variant: CTAProps["variant"];
|
|
537
546
|
fontSize: CTAProps["fontSize"];
|
|
547
|
+
linkType: CTAProps["linkType"];
|
|
538
548
|
};
|
|
539
549
|
}
|
|
540
550
|
declare const PromoComponent: ComponentConfig<PromoProps>;
|
|
@@ -556,4 +566,9 @@ type BreadcrumbsProps = {
|
|
|
556
566
|
};
|
|
557
567
|
declare const Breadcrumbs: ComponentConfig<BreadcrumbsProps>;
|
|
558
568
|
|
|
559
|
-
|
|
569
|
+
interface DirectoryProps {
|
|
570
|
+
separator?: string;
|
|
571
|
+
}
|
|
572
|
+
declare const Directory: ComponentConfig<DirectoryProps>;
|
|
573
|
+
|
|
574
|
+
export { AddressComponent as Address, type AddressProps, Banner, type BannerProps, BasicSelector, Body, type BodyProps, BodyTextComponent as BodyText, type BodyTextProps, BorderRadiusSelector, Breadcrumbs, type BreadcrumbsProps, Button, type ButtonProps, CTA, type CTAProps, CTAWrapperComponent as CTAWrapper, type CTAWrapperProps, CardComponent as Card, type CardProps, Directory, type DirectoryProps, Editor, EmailsComponent as Emails, type EmailsProps, EntityField, FlexContainerComponent as Flex, type FlexProps, type FontRegistry, FontSizeSelector, Footer, type FooterProps, GetDirectionsComponent as GetDirections, type GetDirectionsProps, GridSectionComponent as Grid, type GridProps, Header, type HeaderProps, Heading, type HeadingProps, HeadingTextComponent as HeadingText, type HeadingTextProps, HoursStatusComponent as HoursStatus, type HoursStatusProps, HoursTableComponent as HoursTable, type HoursTableProps, ImageWrapperComponent as ImageWrapper, type ImageWrapperProps, NumberFieldWithDefaultOption, type NumberFieldWithDefaultOptionProps, type NumberOrDefault, PhoneComponent as Phone, type PhoneProps, PromoComponent as Promo, type PromoProps, type RenderYextEntityFieldSelectorProps, Section, type SectionProps, SpacingSelector, TailwindConfigContext, TemplatePropsContext, TextListComponent as TextList, type TextListProps, type ThemeConfig, VisualEditorProvider, type YextEntityField, YextEntityFieldSelector, type YextFieldDefinition, type YextSchemaField, applyAnalytics, applyTheme, bodyVariants, buttonVariants, constructFontSelectOptions, defaultFonts, getBorderRadiusOptions, getFontSizeOptions, getFontWeightOptions, getFontWeightOverrideOptions, getPageMetadata, getSpacingOptions, headingVariants, normalizeSlug, resolveYextEntityField, sectionVariants, themeManagerCn, themeManagerTwMergeConfiguration, themeResolver, useDocument, useEntityFields, usePlatformBridgeDocument, usePlatformBridgeEntityFields, useTailwindConfig, useTemplateProps, validateSlug };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,8 @@ type YextFieldDefinition = {
|
|
|
34
34
|
declare const usePlatformBridgeEntityFields: () => YextSchemaField[] | null;
|
|
35
35
|
declare const useEntityFields: () => YextSchemaField[] | null;
|
|
36
36
|
|
|
37
|
-
declare const
|
|
37
|
+
declare const TemplatePropsContext: React.Context<any>;
|
|
38
|
+
declare const useTemplateProps: <T>() => T;
|
|
38
39
|
declare const useDocument: <T>() => T;
|
|
39
40
|
|
|
40
41
|
declare const TailwindConfigContext: React.Context<any>;
|
|
@@ -198,7 +199,7 @@ declare const getFontWeightOverrideOptions: (options: getFontWeightParams) => Pr
|
|
|
198
199
|
|
|
199
200
|
type AllOrNothing<T extends Record<string, any>> = T | Partial<Record<keyof T, never>>;
|
|
200
201
|
type UniversalProps<T> = {
|
|
201
|
-
|
|
202
|
+
templateProps: T;
|
|
202
203
|
children: React__default.ReactNode;
|
|
203
204
|
};
|
|
204
205
|
type EditorProps$1 = {
|
|
@@ -206,7 +207,7 @@ type EditorProps$1 = {
|
|
|
206
207
|
tailwindConfig: TailwindConfig;
|
|
207
208
|
};
|
|
208
209
|
type VisualEditorProviderProps<T> = UniversalProps<T> & AllOrNothing<EditorProps$1>;
|
|
209
|
-
declare const VisualEditorProvider: <T>({
|
|
210
|
+
declare const VisualEditorProvider: <T>({ templateProps, entityFields, tailwindConfig, children, }: VisualEditorProviderProps<T>) => react_jsx_runtime.JSX.Element;
|
|
210
211
|
|
|
211
212
|
/**
|
|
212
213
|
* Check that the string is a valid slug.
|
|
@@ -276,6 +277,11 @@ declare const BorderRadiusSelector: (label?: string) => Field;
|
|
|
276
277
|
|
|
277
278
|
declare const SpacingSelector: (spacingType: "padding" | "gap", label?: string) => Field;
|
|
278
279
|
|
|
280
|
+
declare const BasicSelector: (label: string, options: {
|
|
281
|
+
label: string;
|
|
282
|
+
value: any;
|
|
283
|
+
}[]) => Field;
|
|
284
|
+
|
|
279
285
|
declare const bodyVariants: (props?: ({
|
|
280
286
|
fontSize?: "default" | "base" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | null | undefined;
|
|
281
287
|
fontWeight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
@@ -312,7 +318,7 @@ declare const CTA: {
|
|
|
312
318
|
};
|
|
313
319
|
|
|
314
320
|
declare const headingVariants: (props?: ({
|
|
315
|
-
level?: 2 | 1 | 3 |
|
|
321
|
+
level?: 2 | 1 | 3 | 4 | 5 | 6 | null | undefined;
|
|
316
322
|
fontSize?: "default" | "base" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | null | undefined;
|
|
317
323
|
weight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
318
324
|
color?: "default" | "text" | "accent" | "secondary" | "primary" | "background" | null | undefined;
|
|
@@ -398,6 +404,7 @@ interface CardProps {
|
|
|
398
404
|
};
|
|
399
405
|
cta: {
|
|
400
406
|
entityField: YextEntityField<CTAProps>;
|
|
407
|
+
linkType: CTAProps["linkType"];
|
|
401
408
|
variant: CTAProps["variant"];
|
|
402
409
|
fontSize: CTAProps["fontSize"];
|
|
403
410
|
};
|
|
@@ -411,6 +418,7 @@ interface CTAWrapperProps {
|
|
|
411
418
|
size: CTAProps["size"];
|
|
412
419
|
borderRadius: CTAProps["borderRadius"];
|
|
413
420
|
fontSize: CTAProps["fontSize"];
|
|
421
|
+
linkType: CTAProps["linkType"];
|
|
414
422
|
className?: CTAProps["className"];
|
|
415
423
|
}
|
|
416
424
|
declare const CTAWrapperComponent: ComponentConfig<CTAWrapperProps>;
|
|
@@ -432,10 +440,10 @@ declare const layoutVariants: (props?: ({
|
|
|
432
440
|
verticalPadding?: "0" | "1" | "2" | "3" | "4" | "default" | "none" | "5" | "6" | "7" | "8" | "12" | "16" | "24" | "14" | "20" | "0.5" | "1.5" | "2.5" | "10" | "3.5" | "9" | "11" | null | undefined;
|
|
433
441
|
horizontalPadding?: "0" | "1" | "2" | "3" | "4" | "default" | "none" | "5" | "6" | "7" | "8" | "12" | "16" | "24" | "14" | "20" | "0.5" | "1.5" | "2.5" | "10" | "3.5" | "9" | "11" | null | undefined;
|
|
434
442
|
backgroundColor?: "default" | "text" | "accent" | "none" | "inherit" | "secondary" | "primary" | "background" | null | undefined;
|
|
435
|
-
} &
|
|
443
|
+
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
436
444
|
declare const innerLayoutVariants: (props?: ({
|
|
437
445
|
maxContentWidth?: "default" | "none" | "lg" | "xl" | "xxl" | null | undefined;
|
|
438
|
-
} &
|
|
446
|
+
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
439
447
|
|
|
440
448
|
interface FlexProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof layoutVariants>, VariantProps<typeof innerLayoutVariants> {
|
|
441
449
|
justifyContent: "start" | "center" | "end";
|
|
@@ -503,6 +511,7 @@ declare const HoursStatusComponent: ComponentConfig<HoursStatusProps>;
|
|
|
503
511
|
declare const phoneVariants: (props?: ({
|
|
504
512
|
fontWeight?: "default" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | null | undefined;
|
|
505
513
|
color?: "default" | "text" | "accent" | "secondary" | "primary" | "background" | null | undefined;
|
|
514
|
+
includeHyperlink?: boolean | null | undefined;
|
|
506
515
|
} & class_variance_authority_dist_types_js.ClassProp) | undefined) => string;
|
|
507
516
|
interface PhoneProps extends VariantProps<typeof phoneVariants> {
|
|
508
517
|
phone: YextEntityField<string>;
|
|
@@ -535,6 +544,7 @@ interface PromoProps {
|
|
|
535
544
|
entityField: YextEntityField<CTAProps>;
|
|
536
545
|
variant: CTAProps["variant"];
|
|
537
546
|
fontSize: CTAProps["fontSize"];
|
|
547
|
+
linkType: CTAProps["linkType"];
|
|
538
548
|
};
|
|
539
549
|
}
|
|
540
550
|
declare const PromoComponent: ComponentConfig<PromoProps>;
|
|
@@ -556,4 +566,9 @@ type BreadcrumbsProps = {
|
|
|
556
566
|
};
|
|
557
567
|
declare const Breadcrumbs: ComponentConfig<BreadcrumbsProps>;
|
|
558
568
|
|
|
559
|
-
|
|
569
|
+
interface DirectoryProps {
|
|
570
|
+
separator?: string;
|
|
571
|
+
}
|
|
572
|
+
declare const Directory: ComponentConfig<DirectoryProps>;
|
|
573
|
+
|
|
574
|
+
export { AddressComponent as Address, type AddressProps, Banner, type BannerProps, BasicSelector, Body, type BodyProps, BodyTextComponent as BodyText, type BodyTextProps, BorderRadiusSelector, Breadcrumbs, type BreadcrumbsProps, Button, type ButtonProps, CTA, type CTAProps, CTAWrapperComponent as CTAWrapper, type CTAWrapperProps, CardComponent as Card, type CardProps, Directory, type DirectoryProps, Editor, EmailsComponent as Emails, type EmailsProps, EntityField, FlexContainerComponent as Flex, type FlexProps, type FontRegistry, FontSizeSelector, Footer, type FooterProps, GetDirectionsComponent as GetDirections, type GetDirectionsProps, GridSectionComponent as Grid, type GridProps, Header, type HeaderProps, Heading, type HeadingProps, HeadingTextComponent as HeadingText, type HeadingTextProps, HoursStatusComponent as HoursStatus, type HoursStatusProps, HoursTableComponent as HoursTable, type HoursTableProps, ImageWrapperComponent as ImageWrapper, type ImageWrapperProps, NumberFieldWithDefaultOption, type NumberFieldWithDefaultOptionProps, type NumberOrDefault, PhoneComponent as Phone, type PhoneProps, PromoComponent as Promo, type PromoProps, type RenderYextEntityFieldSelectorProps, Section, type SectionProps, SpacingSelector, TailwindConfigContext, TemplatePropsContext, TextListComponent as TextList, type TextListProps, type ThemeConfig, VisualEditorProvider, type YextEntityField, YextEntityFieldSelector, type YextFieldDefinition, type YextSchemaField, applyAnalytics, applyTheme, bodyVariants, buttonVariants, constructFontSelectOptions, defaultFonts, getBorderRadiusOptions, getFontSizeOptions, getFontWeightOptions, getFontWeightOverrideOptions, getPageMetadata, getSpacingOptions, headingVariants, normalizeSlug, resolveYextEntityField, sectionVariants, themeManagerCn, themeManagerTwMergeConfiguration, themeResolver, useDocument, useEntityFields, usePlatformBridgeDocument, usePlatformBridgeEntityFields, useTailwindConfig, useTemplateProps, validateSlug };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("node:path"),r=require("fs-extra"),c=`/** THIS FILE IS AUTOGENERATED AND SHOULD NOT BE EDITED */
|
|
2
|
+
import "@yext/visual-editor/style.css";
|
|
3
|
+
import {
|
|
4
|
+
Template,
|
|
5
|
+
GetPath,
|
|
6
|
+
TemplateProps,
|
|
7
|
+
TemplateRenderProps,
|
|
8
|
+
GetHeadConfig,
|
|
9
|
+
HeadConfig,
|
|
10
|
+
TagType,
|
|
11
|
+
} from "@yext/pages";
|
|
12
|
+
import { Render } from "@measured/puck";
|
|
13
|
+
import { mainConfig } from "../ve.config";
|
|
14
|
+
import {
|
|
15
|
+
applyTheme,
|
|
16
|
+
VisualEditorProvider,
|
|
17
|
+
normalizeSlug,
|
|
18
|
+
getPageMetadata,
|
|
19
|
+
applyAnalytics,
|
|
20
|
+
} from "@yext/visual-editor";
|
|
21
|
+
import { themeConfig } from "../../theme.config";
|
|
22
|
+
import { buildSchema } from "../utils/buildSchema";
|
|
23
|
+
import { AnalyticsProvider } from "@yext/pages-components";
|
|
24
|
+
|
|
25
|
+
export const getHeadConfig: GetHeadConfig<TemplateRenderProps> = ({
|
|
26
|
+
document,
|
|
27
|
+
}): HeadConfig => {
|
|
28
|
+
const { title, description } = getPageMetadata(document);
|
|
29
|
+
const faviconUrl = document?._site?.favicon?.url;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
title: title,
|
|
33
|
+
charset: "UTF-8",
|
|
34
|
+
viewport: "width=device-width, initial-scale=1",
|
|
35
|
+
tags: [
|
|
36
|
+
{
|
|
37
|
+
type: "link",
|
|
38
|
+
attributes: {
|
|
39
|
+
rel: "icon",
|
|
40
|
+
type: "image/x-icon",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
...(description
|
|
44
|
+
? [
|
|
45
|
+
{
|
|
46
|
+
type: "meta" as TagType,
|
|
47
|
+
attributes: {
|
|
48
|
+
name: "description",
|
|
49
|
+
content: description,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
: []),
|
|
54
|
+
...(faviconUrl
|
|
55
|
+
? [
|
|
56
|
+
{
|
|
57
|
+
type: "link" as TagType,
|
|
58
|
+
attributes: {
|
|
59
|
+
rel: "icon",
|
|
60
|
+
type: "image/x-icon",
|
|
61
|
+
href: faviconUrl,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
: []),
|
|
66
|
+
],
|
|
67
|
+
other: [
|
|
68
|
+
applyAnalytics(document),
|
|
69
|
+
applyTheme(document, themeConfig),
|
|
70
|
+
buildSchema(document),
|
|
71
|
+
].join("\\n"),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const getPath: GetPath<TemplateProps> = ({ document }) => {
|
|
76
|
+
if (!document?.__?.layout) {
|
|
77
|
+
// temporary: guard for generated repo-based static page
|
|
78
|
+
return \`static-\${Math.floor(Math.random() * (10000 - 1))}\`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (document.slug) {
|
|
82
|
+
return document.slug;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const localePath = document.locale !== "en" ? \`\${document.locale}/\` : "";
|
|
86
|
+
const path = document.address
|
|
87
|
+
? \`\${localePath}\${document.address.region}/\${document.address.city}/\${document.address.line1}\`
|
|
88
|
+
: \`\${localePath}\${document.id}\`;
|
|
89
|
+
|
|
90
|
+
return normalizeSlug(path);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const Location: Template<TemplateRenderProps> = (props) => {
|
|
94
|
+
const { document } = props;
|
|
95
|
+
// temporary: guard for generated repo-based static page
|
|
96
|
+
if (!document?.__?.layout) {
|
|
97
|
+
return <></>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<AnalyticsProvider
|
|
102
|
+
apiKey={document?._env?.YEXT_PUBLIC_EVENTS_API_KEY}
|
|
103
|
+
templateData={props}
|
|
104
|
+
currency="USD"
|
|
105
|
+
>
|
|
106
|
+
<VisualEditorProvider templateProps={props}>
|
|
107
|
+
<Render config={mainConfig} data={JSON.parse(document.__.layout)} />
|
|
108
|
+
</VisualEditorProvider>
|
|
109
|
+
</AnalyticsProvider>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default Location;
|
|
114
|
+
`,l=`/** THIS FILE IS AUTOGENERATED AND SHOULD NOT BE EDITED */
|
|
115
|
+
import {
|
|
116
|
+
applyTheme,
|
|
117
|
+
Editor,
|
|
118
|
+
usePlatformBridgeDocument,
|
|
119
|
+
usePlatformBridgeEntityFields,
|
|
120
|
+
VisualEditorProvider,
|
|
121
|
+
} from "@yext/visual-editor";
|
|
122
|
+
import { componentRegistry } from "../ve.config";
|
|
123
|
+
import {
|
|
124
|
+
GetPath,
|
|
125
|
+
TemplateProps,
|
|
126
|
+
TemplateConfig,
|
|
127
|
+
HeadConfig,
|
|
128
|
+
TemplateRenderProps,
|
|
129
|
+
GetHeadConfig,
|
|
130
|
+
} from "@yext/pages";
|
|
131
|
+
import { themeConfig } from "../../theme.config";
|
|
132
|
+
import tailwindConfig from "../../tailwind.config";
|
|
133
|
+
|
|
134
|
+
// Editor is avaliable at /edit
|
|
135
|
+
export const getPath: GetPath<TemplateProps> = () => {
|
|
136
|
+
return "edit";
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const config: TemplateConfig = {
|
|
140
|
+
name: "edit",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const getHeadConfig: GetHeadConfig<TemplateRenderProps> = ({
|
|
144
|
+
document,
|
|
145
|
+
}): HeadConfig => {
|
|
146
|
+
return {
|
|
147
|
+
other: applyTheme(document, themeConfig),
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Render the editor
|
|
152
|
+
const Edit: () => JSX.Element = () => {
|
|
153
|
+
const entityDocument = usePlatformBridgeDocument();
|
|
154
|
+
const entityFields = usePlatformBridgeEntityFields();
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<VisualEditorProvider
|
|
158
|
+
templateProps={{
|
|
159
|
+
document: entityDocument,
|
|
160
|
+
}}
|
|
161
|
+
entityFields={entityFields}
|
|
162
|
+
tailwindConfig={tailwindConfig}
|
|
163
|
+
>
|
|
164
|
+
<Editor
|
|
165
|
+
document={entityDocument}
|
|
166
|
+
componentRegistry={componentRegistry}
|
|
167
|
+
themeConfig={themeConfig}
|
|
168
|
+
/>
|
|
169
|
+
</VisualEditorProvider>
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export default Edit;
|
|
174
|
+
`,m={"src/templates/main.tsx":c,"src/templates/edit.tsx":l},p=()=>{let e=!1;const a=[],s=()=>{Object.entries(m).forEach(([n,o])=>{const i=d.join(process.cwd(),n);a.push(i),r.mkdirSync(d.dirname(i),{recursive:!0}),r.writeFileSync(i,o)})},t=()=>{a.forEach(n=>{r.rmSync(n,{force:!0})})};return process.on("SIGINT",()=>{t(),process.nextTick(()=>process.exit(0))}),process.on("SIGTERM",()=>{t(),process.nextTick(()=>process.exit(0))}),{name:"vite-plugin-yext-visual-editor",config(n,{command:o}){e=o==="build"},configureServer(n){e||(s(),n.httpServer?.on("close",()=>{t()}))},buildStart(){e&&s()},buildEnd(){e&&t()},closeBundle(){e&&t()}}};exports.yextVisualEditorPlugin=p;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import d from "node:path";
|
|
2
|
+
import r from "fs-extra";
|
|
3
|
+
const c = `/** THIS FILE IS AUTOGENERATED AND SHOULD NOT BE EDITED */
|
|
4
|
+
import "@yext/visual-editor/style.css";
|
|
5
|
+
import {
|
|
6
|
+
Template,
|
|
7
|
+
GetPath,
|
|
8
|
+
TemplateProps,
|
|
9
|
+
TemplateRenderProps,
|
|
10
|
+
GetHeadConfig,
|
|
11
|
+
HeadConfig,
|
|
12
|
+
TagType,
|
|
13
|
+
} from "@yext/pages";
|
|
14
|
+
import { Render } from "@measured/puck";
|
|
15
|
+
import { mainConfig } from "../ve.config";
|
|
16
|
+
import {
|
|
17
|
+
applyTheme,
|
|
18
|
+
VisualEditorProvider,
|
|
19
|
+
normalizeSlug,
|
|
20
|
+
getPageMetadata,
|
|
21
|
+
applyAnalytics,
|
|
22
|
+
} from "@yext/visual-editor";
|
|
23
|
+
import { themeConfig } from "../../theme.config";
|
|
24
|
+
import { buildSchema } from "../utils/buildSchema";
|
|
25
|
+
import { AnalyticsProvider } from "@yext/pages-components";
|
|
26
|
+
|
|
27
|
+
export const getHeadConfig: GetHeadConfig<TemplateRenderProps> = ({
|
|
28
|
+
document,
|
|
29
|
+
}): HeadConfig => {
|
|
30
|
+
const { title, description } = getPageMetadata(document);
|
|
31
|
+
const faviconUrl = document?._site?.favicon?.url;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
title: title,
|
|
35
|
+
charset: "UTF-8",
|
|
36
|
+
viewport: "width=device-width, initial-scale=1",
|
|
37
|
+
tags: [
|
|
38
|
+
{
|
|
39
|
+
type: "link",
|
|
40
|
+
attributes: {
|
|
41
|
+
rel: "icon",
|
|
42
|
+
type: "image/x-icon",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
...(description
|
|
46
|
+
? [
|
|
47
|
+
{
|
|
48
|
+
type: "meta" as TagType,
|
|
49
|
+
attributes: {
|
|
50
|
+
name: "description",
|
|
51
|
+
content: description,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
]
|
|
55
|
+
: []),
|
|
56
|
+
...(faviconUrl
|
|
57
|
+
? [
|
|
58
|
+
{
|
|
59
|
+
type: "link" as TagType,
|
|
60
|
+
attributes: {
|
|
61
|
+
rel: "icon",
|
|
62
|
+
type: "image/x-icon",
|
|
63
|
+
href: faviconUrl,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
68
|
+
],
|
|
69
|
+
other: [
|
|
70
|
+
applyAnalytics(document),
|
|
71
|
+
applyTheme(document, themeConfig),
|
|
72
|
+
buildSchema(document),
|
|
73
|
+
].join("\\n"),
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const getPath: GetPath<TemplateProps> = ({ document }) => {
|
|
78
|
+
if (!document?.__?.layout) {
|
|
79
|
+
// temporary: guard for generated repo-based static page
|
|
80
|
+
return \`static-\${Math.floor(Math.random() * (10000 - 1))}\`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (document.slug) {
|
|
84
|
+
return document.slug;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const localePath = document.locale !== "en" ? \`\${document.locale}/\` : "";
|
|
88
|
+
const path = document.address
|
|
89
|
+
? \`\${localePath}\${document.address.region}/\${document.address.city}/\${document.address.line1}\`
|
|
90
|
+
: \`\${localePath}\${document.id}\`;
|
|
91
|
+
|
|
92
|
+
return normalizeSlug(path);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const Location: Template<TemplateRenderProps> = (props) => {
|
|
96
|
+
const { document } = props;
|
|
97
|
+
// temporary: guard for generated repo-based static page
|
|
98
|
+
if (!document?.__?.layout) {
|
|
99
|
+
return <></>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<AnalyticsProvider
|
|
104
|
+
apiKey={document?._env?.YEXT_PUBLIC_EVENTS_API_KEY}
|
|
105
|
+
templateData={props}
|
|
106
|
+
currency="USD"
|
|
107
|
+
>
|
|
108
|
+
<VisualEditorProvider templateProps={props}>
|
|
109
|
+
<Render config={mainConfig} data={JSON.parse(document.__.layout)} />
|
|
110
|
+
</VisualEditorProvider>
|
|
111
|
+
</AnalyticsProvider>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export default Location;
|
|
116
|
+
`, m = `/** THIS FILE IS AUTOGENERATED AND SHOULD NOT BE EDITED */
|
|
117
|
+
import {
|
|
118
|
+
applyTheme,
|
|
119
|
+
Editor,
|
|
120
|
+
usePlatformBridgeDocument,
|
|
121
|
+
usePlatformBridgeEntityFields,
|
|
122
|
+
VisualEditorProvider,
|
|
123
|
+
} from "@yext/visual-editor";
|
|
124
|
+
import { componentRegistry } from "../ve.config";
|
|
125
|
+
import {
|
|
126
|
+
GetPath,
|
|
127
|
+
TemplateProps,
|
|
128
|
+
TemplateConfig,
|
|
129
|
+
HeadConfig,
|
|
130
|
+
TemplateRenderProps,
|
|
131
|
+
GetHeadConfig,
|
|
132
|
+
} from "@yext/pages";
|
|
133
|
+
import { themeConfig } from "../../theme.config";
|
|
134
|
+
import tailwindConfig from "../../tailwind.config";
|
|
135
|
+
|
|
136
|
+
// Editor is avaliable at /edit
|
|
137
|
+
export const getPath: GetPath<TemplateProps> = () => {
|
|
138
|
+
return "edit";
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const config: TemplateConfig = {
|
|
142
|
+
name: "edit",
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const getHeadConfig: GetHeadConfig<TemplateRenderProps> = ({
|
|
146
|
+
document,
|
|
147
|
+
}): HeadConfig => {
|
|
148
|
+
return {
|
|
149
|
+
other: applyTheme(document, themeConfig),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Render the editor
|
|
154
|
+
const Edit: () => JSX.Element = () => {
|
|
155
|
+
const entityDocument = usePlatformBridgeDocument();
|
|
156
|
+
const entityFields = usePlatformBridgeEntityFields();
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<VisualEditorProvider
|
|
160
|
+
templateProps={{
|
|
161
|
+
document: entityDocument,
|
|
162
|
+
}}
|
|
163
|
+
entityFields={entityFields}
|
|
164
|
+
tailwindConfig={tailwindConfig}
|
|
165
|
+
>
|
|
166
|
+
<Editor
|
|
167
|
+
document={entityDocument}
|
|
168
|
+
componentRegistry={componentRegistry}
|
|
169
|
+
themeConfig={themeConfig}
|
|
170
|
+
/>
|
|
171
|
+
</VisualEditorProvider>
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export default Edit;
|
|
176
|
+
`, l = {
|
|
177
|
+
"src/templates/main.tsx": c,
|
|
178
|
+
"src/templates/edit.tsx": m
|
|
179
|
+
}, f = () => {
|
|
180
|
+
let e = !1;
|
|
181
|
+
const a = [], s = () => {
|
|
182
|
+
Object.entries(l).forEach(([n, o]) => {
|
|
183
|
+
const i = d.join(process.cwd(), n);
|
|
184
|
+
a.push(i), r.mkdirSync(d.dirname(i), { recursive: !0 }), r.writeFileSync(i, o);
|
|
185
|
+
});
|
|
186
|
+
}, t = () => {
|
|
187
|
+
a.forEach((n) => {
|
|
188
|
+
r.rmSync(n, { force: !0 });
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
return process.on("SIGINT", () => {
|
|
192
|
+
t(), process.nextTick(() => process.exit(0));
|
|
193
|
+
}), process.on("SIGTERM", () => {
|
|
194
|
+
t(), process.nextTick(() => process.exit(0));
|
|
195
|
+
}), {
|
|
196
|
+
name: "vite-plugin-yext-visual-editor",
|
|
197
|
+
config(n, { command: o }) {
|
|
198
|
+
e = o === "build";
|
|
199
|
+
},
|
|
200
|
+
configureServer(n) {
|
|
201
|
+
e || (s(), n.httpServer?.on("close", () => {
|
|
202
|
+
t();
|
|
203
|
+
}));
|
|
204
|
+
},
|
|
205
|
+
buildStart() {
|
|
206
|
+
e && s();
|
|
207
|
+
},
|
|
208
|
+
buildEnd() {
|
|
209
|
+
e && t();
|
|
210
|
+
},
|
|
211
|
+
closeBundle() {
|
|
212
|
+
e && t();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
export {
|
|
217
|
+
f as yextVisualEditorPlugin
|
|
218
|
+
};
|