render global styles and font family together

This commit is contained in:
Oleg Isonen committed 2022-09-23 19:59:05 +03:00
1 parent 3ff24033cb
commit 02f81a6fd5
2 files changed
+18 -17

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ import store from "immerhin";
import type { Build } from "@webstudio-is/project";
import {
createElementsTree,
globalStyles,
useGlobalStyles,
type OnChangeChildren,
type Tree,
useAllUserProps,
@@ -117,7 +117,7 @@ export const Canvas = ({ data }: CanvasProps): JSX.Element | null => {
}
const isDesignerReady = useSubscribeDesignerReady();
useInitializeBreakpoints(data.breakpoints);
globalStyles();
useGlobalStyles({ assets: data.assets })();
useAllUserProps(data.props);
usePopulateRootInstance(data.tree);
// e.g. toggling preview is still needed in both modes
+16 -15
View File
@@ -9,7 +9,7 @@ import {
} from "./wrapper-component";
import { FONT_FORMATS, getFontFaces } from "@webstudio-is/fonts";
import type { Asset, FontAsset } from "@webstudio-is/asset-uploader";
import { useMemo } from "react";
import { useCallback } from "react";
export type Data = {
tree: Tree | null;
@@ -18,11 +18,20 @@ export type Data = {
assets: Array<Asset>;
};
export const globalStyles = globalCss({
html: {
height: "100%",
},
});
export const useGlobalStyles = ({ assets }: { assets: Array<Asset> }) => {
return useCallback(() => {
const fontAssets = assets.filter(
(asset) => asset.format in FONT_FORMATS
) as Array<FontAsset>;
return globalCss({
"@font-face": getFontFaces(fontAssets),
html: {
height: "100%",
},
})();
}, [assets]);
};
type RootProps = {
data: Data;
@@ -37,15 +46,7 @@ export const InstanceRoot = ({
throw new Error("Tree is null");
}
setBreakpoints(data.breakpoints);
globalStyles();
const assets = useMemo(() => {
return data.assets.filter(
(asset) => asset.format in FONT_FORMATS
) as Array<FontAsset>;
}, [data.assets]);
globalCss({
"@font-face": getFontFaces(assets),
})();
useGlobalStyles({ assets: data.assets })();
useAllUserProps(data.props);
return createElementsTree({
instance: data.tree.root,