Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ve 1931: Page traversal should persist the preview parameters #130

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/contentstack-live-preview-HOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import LivePreview from "./live-preview";
import { userInitData } from "./utils/defaults";
import { PublicLogger } from "./utils/public-logger";
import { handleWebCompare } from "./compare";
import { handlePageTraversal } from "./utils/handlePageTraversal";

export interface ICSLivePreview {
livePreview: LivePreview | null;
Expand Down Expand Up @@ -58,6 +59,7 @@ const ContentstackLivePreview: ICSLivePreview = {
return Promise.resolve(ContentstackLivePreview.livePreview);
} else {
handleWebCompare();
handlePageTraversal();

ContentstackLivePreview.livePreview = new LivePreview(
userConfig
Expand Down
17 changes: 8 additions & 9 deletions src/styles/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ export const loadCompareGlobalStyle = () => {
background: rgba(214, 36, 0, 0.2);
text-decoration: line-through 2px solid rgba(214, 36, 0, 1);
}
}
.cs-compare__void--added {
background: rgba(0, 122, 82, 0.2);
outline: 2px solid rgba(0, 122, 82);
}

&.cs-compare__void--added {
background: rgba(0, 122, 82, 0.2);
outline: 2px solid rgba(0, 122, 82);
}

&.cs-compare__void--removed {
background: rgba(214, 36, 0, 0.2);
outline: 2px solid rgba(214, 36, 0, 1);
}
.cs-compare__void--removed {
background: rgba(214, 36, 0, 0.2);
outline: 2px solid rgba(214, 36, 0, 1);
}
`;
};
4 changes: 3 additions & 1 deletion src/utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function registerCompareElement() {
}

if (!customElements.get(DIFF_WRAPPER)) {
customElements.define(DIFF_WRAPPER, Compare);
customElements.define(DIFF_WRAPPER, Compare, {
extends: "span",
});
}
}
17 changes: 17 additions & 0 deletions src/utils/handlePageTraversal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const handlePageTraversal = () => {
window.addEventListener("unload", () => {
const targetURL = (document.activeElement as HTMLAnchorElement).href;
if (targetURL) {
window.parent.postMessage(
{
from: "live-preview",
type: "url-change",
data: {
targetURL,
},
},
"*"
);
}
});
};
Loading