Skip to content

Commit

Permalink
Merge pull request #324 from pantheon-systems/ag/pcc-1699/iframe-prev…
Browse files Browse the repository at this point in the history
…iew-sdk-updates

[PCC 1699] Deprecate injected preview bar
  • Loading branch information
kevinstubbs authored Dec 9, 2024
2 parents 7b65bd9 + 0b99e57 commit 6e45b6d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 471 deletions.
6 changes: 6 additions & 0 deletions .changeset/plenty-rice-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pantheon-systems/pcc-react-sdk": minor
---

The injected preview bar is deprecated in favor of the integrated preview bar in
the dashboard preview interface
4 changes: 0 additions & 4 deletions packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@pantheon-systems/pcc-sdk-core": "workspace:*",
"framer-motion": "^10.18.0",
"goober": "^2.1.14",
"graphql": "^16.8.1",
"lodash": "^4.17.21",
"query-string": "^8.2.0",
"react-laag": "^2.0.5",
"react-markdown": "^8.0.7",
"rehype-raw": "^6.1.1",
"remark-heading-id": "^1.0.1",
Expand Down
50 changes: 0 additions & 50 deletions packages/react-sdk/src/components/ArticleRenderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
} from "@pantheon-systems/pcc-sdk-core/types";
import { Element } from "hast";
import React, { useEffect } from "react";
import { createPortal } from "react-dom";
import { getTextContent } from "../../utils/react-element";
import { PreviewBar, PreviewBarExternalProps } from "../Preview/Preview";
import MarkdownRenderer from "./Markdown";
import PantheonTreeRenderer from "./PantheonTreeRenderer";
import PantheonTreeV2Renderer from "./PantheonTreeV2Renderer";
Expand Down Expand Up @@ -52,7 +50,6 @@ interface Props {
content: string,
) => React.ReactNode;
smartComponentMap?: SmartComponentMap;
previewBarProps?: PreviewBarExternalProps;
componentMap?: ComponentMap;
renderBody?: (bodyElement: React.ReactElement) => React.ReactNode;
__experimentalFlags?: {
Expand All @@ -63,36 +60,17 @@ interface Props {
};
}

function getOrCreatePortalTarget(
targetOverride: globalThis.Element | null | undefined,
) {
const pccGeneratedPortalTargetKey = "__pcc-portal-target__";
let portalTarget =
targetOverride || document.getElementById(pccGeneratedPortalTargetKey);

if (!portalTarget) {
portalTarget = document.createElement("div");
portalTarget.id = pccGeneratedPortalTargetKey;
document.body.prepend(portalTarget);
}

return portalTarget;
}

const ArticleRenderer = ({
article,
bodyClassName,
containerClassName,
headerClassName,
renderTitle,
smartComponentMap,
previewBarProps,
componentMap,
renderBody,
__experimentalFlags,
}: Props) => {
const [renderCSR, setRenderCSR] = React.useState(false);

useEffect(() => {
if (__experimentalFlags?.useUnintrusiveTitleRendering !== true) {
console.warn(
Expand All @@ -101,33 +79,15 @@ const ArticleRenderer = ({
}
}, [__experimentalFlags]);

useEffect(() => {
setRenderCSR(true);
}, []);

if (!article?.content) {
return null;
}

const portalTarget =
renderCSR && typeof document !== "undefined"
? getOrCreatePortalTarget(previewBarProps?.portalTarget)
: null;
const contentType = article?.contentType;

if (contentType === "TEXT_MARKDOWN") {
return (
<div className={containerClassName}>
{renderCSR &&
article != null &&
portalTarget != null &&
article.publishingLevel === "REALTIME"
? createPortal(
<PreviewBar {...previewBarProps} article={article} />,
portalTarget,
)
: null}

{article?.content ? (
<MarkdownRenderer
smartComponentMap={smartComponentMap}
Expand Down Expand Up @@ -202,16 +162,6 @@ const ArticleRenderer = ({

return (
<div className={containerClassName}>
{renderCSR &&
article != null &&
portalTarget != null &&
article.publishingLevel === "REALTIME"
? createPortal(
<PreviewBar {...previewBarProps} article={article} />,
portalTarget,
)
: null}

{titleElement != null ? (
<div className={headerClassName}>
{renderTitle
Expand Down
106 changes: 0 additions & 106 deletions packages/react-sdk/src/components/Preview/LivePreviewIndicator.tsx

This file was deleted.

Loading

0 comments on commit 6e45b6d

Please sign in to comment.