Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bfa986f
feat: hide right sidebar title in Theme mode
jwartofsky-yext Mar 2, 2026
f8cd07e
cleaned up code
jwartofsky-yext Mar 2, 2026
8632d61
prevent leaving interactive mode while in theme editor
jwartofsky-yext Mar 2, 2026
b7e46f8
Update component screenshots for visual-editor
github-actions[bot] Mar 2, 2026
2ee2599
adjust comment
jwartofsky-yext Mar 2, 2026
e60adac
re-add block pointer events
jwartofsky-yext Mar 3, 2026
b275bb0
add cleanup and retry logic to pointer-blocking
jwartofsky-yext Mar 3, 2026
1348882
update screenshot to main
jwartofsky-yext Mar 3, 2026
8f9959e
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 3, 2026
9d1d607
prevent clicking links in Theme mode
jwartofsky-yext Mar 4, 2026
10b2dc1
move link blocking code
jwartofsky-yext Mar 4, 2026
0f00c6a
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 4, 2026
25d8ee8
move interactiveMode useEffect to InternalThemeEditor
jwartofsky-yext Mar 4, 2026
27cb375
move interactiveMode useEffect back to ThemeHeader
jwartofsky-yext Mar 4, 2026
9b2ad44
add jsdocs to previewFrameLinkBlocker
jwartofsky-yext Mar 4, 2026
0da19b6
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 5, 2026
a5a720f
address coderabbit comments and retest
jwartofsky-yext Mar 5, 2026
e0c6298
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 5, 2026
3ef54d4
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 5, 2026
9ef9ef0
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 6, 2026
03df53d
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 9, 2026
e263964
add actionable check to language dropdown
jwartofsky-yext Mar 9, 2026
2b6085e
remove langauge dropdown changes. Add checks to prevent interacting w…
jwartofsky-yext Mar 9, 2026
1b44c5c
revert language dropdown to main
jwartofsky-yext Mar 9, 2026
1e9bfe7
add random AI comment to trigger build again. Maybe it's helpful too
jwartofsky-yext Mar 9, 2026
84f04f5
Merge branch 'main' into fixJSONInThemeEditor
jwartofsky-yext Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { v4 as uuidv4 } from "uuid";
import { ThemeHistories, ThemeHistory } from "../types/themeData.ts";
import * as lzstring from "lz-string";
import { Metadata } from "../../editor/Editor.tsx";
import { createPreviewFrameLinkBlocker } from "../utils/previewFrameLinkBlocker.ts";

const devLogger = new DevLogger();
// Used because we want the sidebar to be hidden
Expand Down Expand Up @@ -71,6 +72,11 @@ export const InternalThemeEditor = ({
themeHistoriesRef.current = themeHistories;
}, [themeHistories]);

useEffect(() => {
// In theme mode, links should still be hoverable but never navigate.
return createPreviewFrameLinkBlocker();
}, []);

const handlePublishTheme = async () => {
devLogger.logFunc("saveThemeData");
if (!themeHistories) {
Expand Down
56 changes: 32 additions & 24 deletions packages/visual-editor/src/internal/puck/components/ThemeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ThemeConfig } from "../../../utils/themeResolver.ts";
import { updateThemeInEditor } from "../../../utils/applyTheme.ts";
import { UIButtonsToggle } from "../ui/UIButtonsToggle.tsx";
import { ClearLocalChangesButton } from "../ui/ClearLocalChangesButton.tsx";
import { InitialHistory, useGetPuck } from "@puckeditor/core";
import { InitialHistory, createUsePuck, useGetPuck } from "@puckeditor/core";
import { ThemeData, ThemeHistories } from "../../types/themeData.ts";
import { RotateCcw, RotateCw } from "lucide-react";
import { Separator } from "@radix-ui/react-separator";
Expand All @@ -21,6 +21,9 @@ import {
} from "../ui/Tooltip.tsx";
import { getPublishTooltipMessageFromHeadDeployStatus } from "../../utils/getPublishTooltipMessageFromHeadDeployStatus.ts";

const SIDEBAR_HIDE_STYLE_ID = "yext-theme-hide-sidebar-breadcrumbs";
const usePuck = createUsePuck();

type ThemeHeaderProps = {
onPublishTheme: () => Promise<void>;
isDevMode: boolean;
Expand Down Expand Up @@ -53,8 +56,9 @@ export const ThemeHeader = (props: ThemeHeaderProps) => {
} = props;

const getPuck = useGetPuck();

const previewMode = usePuck((s) => s.appState.ui.previewMode);
useEffect(() => {
// Initialize Puck history and set preview mode to "interactive" on mount
const {
dispatch,
history: { setHistories },
Expand All @@ -70,34 +74,38 @@ export const ThemeHeader = (props: ThemeHeaderProps) => {
}, [puckInitialHistory]);

useEffect(() => {
// Hide the components list and fields list titles
const fieldListTitle = document.querySelector<HTMLElement>(
"[class*='PuckLayout-rightSideBar'] > div[class*='SidebarSection--noBorderTop'] > div[class*='SidebarSection-title']"
);
if (fieldListTitle) {
fieldListTitle.style.display = "none";
}
const puckPreview =
Comment thread
jwartofsky-yext marked this conversation as resolved.
document.querySelector<HTMLIFrameElement>("#preview-frame");
if (
puckPreview?.contentDocument?.head &&
!puckPreview?.contentDocument.getElementById(
"yext-preview-disable-pointer-events"
)
) {
// add this style to preview iFrame to prevent clicking or hover effects.
const style = puckPreview.contentDocument.createElement("style");
style.id = "yext-preview-disable-pointer-events";
// Prevents the "Page" / breadcrumb from appearing over the right sidebar
if (!document.getElementById(SIDEBAR_HIDE_STYLE_ID)) {
const style = document.createElement("style");
style.id = SIDEBAR_HIDE_STYLE_ID;
style.innerHTML = `
* {
cursor: default !important;
pointer-events: none !important;
[class*='SidebarSection-breadcrumbs'] {
display: none !important;
}
[class*='SidebarSection-title'] {
display: none !important;
}
`;
puckPreview.contentDocument.head.appendChild(style);
document.head.appendChild(style);
}

return () => {
document.getElementById(SIDEBAR_HIDE_STYLE_ID)?.remove();
};
}, []);

useEffect(() => {
Comment thread
asanehisa marked this conversation as resolved.
// Keep theme mode in interactive preview so links/buttons are hoverable
// and Puck component selection is disabled.
if (previewMode !== "interactive") {
const { dispatch } = getPuck();
dispatch({
type: "setUi",
ui: { previewMode: "interactive" },
});
}
}, [previewMode, getPuck]);

const canUndo = (): boolean => {
if (!themeHistories) {
return false;
Expand Down
216 changes: 216 additions & 0 deletions packages/visual-editor/src/internal/utils/previewFrameLinkBlocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import { PUCK_PREVIEW_IFRAME_ID } from "../../utils/applyTheme.ts";

// Selector for interactive elements that should have their default navigation behavior blocked in preview mode, while still allowing hover/focus styles to apply.
const NON_ACTIONABLE_SELECTOR = [
"a",
"area",
"[role='link']",
"[role='menuitem']",
"[data-slot='dropdown-menu-trigger']",
"[data-slot='dropdown-menu-item']",
].join(", ");

/**
* Installs link-navigation blocking in a specific preview document while
* preserving hover and focus behavior.
*
* @param previewDocument - The iframe document that renders theme preview content.
* @returns A cleanup function that restores original link attributes and removes listeners/observers.
*/
export const createPreviewDocumentLinkBlocker = (previewDocument: Document) => {
const previewWindow = previewDocument.defaultView;

/**
* Returns true when the event target (or one of its ancestors) is a link-like
* element or a dropdown menu item/trigger that should not be actionable in preview.
*/
const isBlockedTarget = (event: Event) => {
const targetElement = event.target;
if (
!targetElement ||
typeof (targetElement as Element).closest !== "function"
) {
return false;
}

return !!(targetElement as Element).closest(NON_ACTIONABLE_SELECTOR);
};

/**
* Cancels action-triggering events for blocked interactive targets.
* Keyboard events are only blocked for activation keys.
*/
const preventLinkNavigation = (event: Event) => {
if (!isBlockedTarget(event)) {
return;
}

if (event.type === "keydown") {
const key = (event as KeyboardEvent).key;
if (key !== "Enter" && key !== " ") {
return;
}
}

event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
};

/**
* Removes href/target from links so the browser cannot navigate by default.
* Original values are stored in data attributes for later restoration.
*/
const disableAnchorNavigationAttributes = () => {
previewDocument.querySelectorAll("a[href], area[href]").forEach((el) => {
if (!el.hasAttribute("data-ve-original-href")) {
el.setAttribute("data-ve-original-href", el.getAttribute("href") ?? "");
}

el.removeAttribute("href");

if (el.hasAttribute("target")) {
el.setAttribute(
"data-ve-original-target",
el.getAttribute("target") ?? ""
);
el.removeAttribute("target");
}
});
};

disableAnchorNavigationAttributes();
const anchorObserver = new MutationObserver(() => {
disableAnchorNavigationAttributes();
});
anchorObserver.observe(previewDocument.documentElement, {
childList: true,
subtree: true,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const eventTypes = [
"click",
"auxclick",
"mousedown",
"mouseup",
"pointerdown",
"pointerup",
"touchstart",
"keydown",
] as const;

eventTypes.forEach((eventType) => {
previewDocument.addEventListener(eventType, preventLinkNavigation, true);
previewWindow?.addEventListener(eventType, preventLinkNavigation, true);
});

return () => {
anchorObserver.disconnect();

previewDocument
.querySelectorAll("a[data-ve-original-href], area[data-ve-original-href]")
.forEach((el) => {
const originalHref = el.getAttribute("data-ve-original-href");
if (originalHref !== null) {
el.setAttribute("href", originalHref);
}
el.removeAttribute("data-ve-original-href");

if (el.hasAttribute("data-ve-original-target")) {
const originalTarget = el.getAttribute("data-ve-original-target");
if (originalTarget !== null) {
el.setAttribute("target", originalTarget);
}
el.removeAttribute("data-ve-original-target");
}
});

eventTypes.forEach((eventType) => {
previewDocument.removeEventListener(
eventType,
preventLinkNavigation,
true
);
previewWindow?.removeEventListener(
eventType,
preventLinkNavigation,
true
);
});
};
};

/**
* Watches the preview iframe lifecycle and applies link-navigation blocking
* to whichever preview document is currently active.
*
* @returns A cleanup function that detaches iframe observers and listeners.
*/
export const createPreviewFrameLinkBlocker = () => {
let detachLinkNavigationBlock: (() => void) | undefined;
let activeFrame: HTMLIFrameElement | null = null;

/**
* Rebinds document-level blockers when the iframe loads a new document.
*/
const onPreviewFrameLoad = () => {
detachLinkNavigationBlock?.();
if (activeFrame?.contentDocument) {
detachLinkNavigationBlock = createPreviewDocumentLinkBlocker(
activeFrame.contentDocument
);
}
};

/**
* Attaches blocker behavior to a new iframe element and detaches from any
* previously tracked iframe.
*/
const attachToPreviewFrame = (frame: HTMLIFrameElement) => {
if (activeFrame === frame) {
return;
}

activeFrame?.removeEventListener("load", onPreviewFrameLoad);
detachLinkNavigationBlock?.();

activeFrame = frame;
activeFrame.addEventListener("load", onPreviewFrameLoad);
if (activeFrame.contentDocument) {
detachLinkNavigationBlock = createPreviewDocumentLinkBlocker(
activeFrame.contentDocument
);
}
};

/**
* Locates the preview iframe and ensures blocker behavior is attached.
*/
const syncPreviewFrame = () => {
const previewFrame = document.getElementById(
PUCK_PREVIEW_IFRAME_ID
) as HTMLIFrameElement | null;
if (!previewFrame) {
return;
}
Comment thread
jwartofsky-yext marked this conversation as resolved.

attachToPreviewFrame(previewFrame);
};

const iframeObserver = new MutationObserver(syncPreviewFrame);
iframeObserver.observe(document, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["href", "target"],
});

syncPreviewFrame();

return () => {
iframeObserver.disconnect();
activeFrame?.removeEventListener("load", onPreviewFrameLoad);
detachLinkNavigationBlock?.();
activeFrame = null;
};
};
Loading