Skip to content

Commit

Permalink
rename to active styles
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaing committed Oct 25, 2023
1 parent deb38db commit e5543bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/studio-ui/src/components/IFramePortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createPortal } from "react-dom";
import { Dispatch, PropsWithChildren, SetStateAction, useRef } from "react";
import useStudioStore from "../store/useStudioStore";
import { twMerge } from "tailwind-merge";
import useInjectUserStyles from "../hooks/useInjectUserStyles";
import useInjectActiveStyles from "../hooks/useInjectActiveStyles";
import useViewportOption from "../hooks/useViewportOption";

export default function IFramePortal(
Expand All @@ -15,7 +15,7 @@ export default function IFramePortal(
const previewRef = useRef<HTMLDivElement>(null);
const iframeDocument = props.iframeEl?.contentWindow?.document;
const [viewport] = useStudioStore((store) => [store.pagePreview.viewport]);
useInjectUserStyles(iframeDocument);
useInjectActiveStyles(iframeDocument);
const iframeCSS = twMerge(
"mr-auto ml-auto",
viewport.css,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { StudioStore } from "../store/models/StudioStore";
* styling of the current active page and component tree. Styling is cleared
* from the iframe before each injection.
*/
export default function useInjectUserStyles(
export default function useInjectActiveStyles(
iframeDocument: Document | undefined
) {
const [userStyleImports, loadedStyleFilepaths] = useStudioStore(
const [activeStylesFilepaths, loadedStyleFilepaths] = useStudioStore(
(store) => [
getUserStyleImports(store),
getFilepathsOfActiveStyles(store),
store.loadedStyles.loadedStyleFilepaths,
],
isEqual
Expand All @@ -25,7 +25,7 @@ export default function useInjectUserStyles(
if (!iframeDocument) {
return;
}
userStyleImports.forEach((styleFilepath) => {
activeStylesFilepaths.forEach((styleFilepath) => {
injectStyleIntoIframe(iframeDocument, styleFilepath);
});

Expand All @@ -39,11 +39,11 @@ export default function useInjectUserStyles(
* called before all user styles are added to Studio's
* document head.
*/
}, [iframeDocument, userStyleImports, loadedStyleFilepaths]);
}, [iframeDocument, activeStylesFilepaths, loadedStyleFilepaths]);
}

function getUserStyleImports(store: StudioStore): string[] {
const pageStyles = store.pages.getActivePageState()?.styleImports ?? [];
function getFilepathsOfActiveStyles(store: StudioStore): string[] {
const activePageStyles = store.pages.getActivePageState()?.styleImports ?? [];
const componentTree = store.actions.getComponentTree();
const getComponentMetadata = store.actions.getComponentMetadata;

Expand All @@ -54,7 +54,7 @@ function getUserStyleImports(store: StudioStore): string[] {
componentTreeStyles.add(styleFilepath);
});
});
return [...componentTreeStyles, ...pageStyles];
return [...componentTreeStyles, ...activePageStyles];
}

function clearStylingFromIframe(iframeDocument: Document) {
Expand Down

0 comments on commit e5543bc

Please sign in to comment.