Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

move flush css function to the corresponding packages

Oleg Isonen82884ef248a1
diff --git a/apps/designer/app/critical-css.ts b/apps/designer/app/critical-css.ts
index adef6a6865..28145afd71 100644
--- a/apps/designer/app/critical-css.ts
+++ b/apps/designer/app/critical-css.ts
@@ -1,32 +1,16 @@
import {
insertCriticalCss as insert,
- getCssText as getCanvasCssText,
- resetCss as resetCanvasCss,
+ flushCss as flushCanvasCss,
} from "@webstudio-is/react-sdk";
-import {
- getCssText as getDesignerCssText,
- reset as resetDesignerCss,
-} from "@webstudio-is/design-system";
+import { flushCss as flushDesignerCss } from "@webstudio-is/design-system";
import config from "./config";
-const flushCanvas = () => {
- const css = getCanvasCssText();
- resetCanvasCss();
- return css;
-};
-
-const flushDesigner = () => {
- const css = getDesignerCssText();
- resetDesignerCss();
- return css;
-};
-
const flushFunctions = {
- [config.previewPath]: flushCanvas,
- [config.canvasPath]: flushCanvas,
- [config.designerPath]: flushDesigner,
- [config.dashboardPath]: flushDesigner,
- [config.loginPath]: flushDesigner,
+ [config.previewPath]: flushCanvasCss,
+ [config.canvasPath]: flushCanvasCss,
+ [config.designerPath]: flushDesignerCss,
+ [config.dashboardPath]: flushDesignerCss,
+ [config.loginPath]: flushDesignerCss,
};
const getFlushFunction = (url: string) => {
@@ -37,7 +21,7 @@ const getFlushFunction = (url: string) => {
return flushFunctions[path];
}
}
- return getCanvasCssText;
+ return flushCanvasCss;
};
/**
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index ec369e4873..54bb4137dc 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -1,16 +1,4 @@
-export {
- config,
- createTheme,
- css,
- darkTheme,
- getCssText,
- globalCss,
- keyframes,
- reset,
- styled,
- theme,
- type CSS,
-} from "./stitches.config";
+export * from "./stitches.config";
export * from "./components/toast";
export * as Collapsible from "@radix-ui/react-collapsible";
diff --git a/packages/design-system/src/stitches.config.ts b/packages/design-system/src/stitches.config.ts
index e159c2e7d7..b1906c6d94 100644
--- a/packages/design-system/src/stitches.config.ts
+++ b/packages/design-system/src/stitches.config.ts
@@ -118,7 +118,7 @@ import {
import type * as Stitches from "@stitches/react";
export type { VariantProps } from "@stitches/react";
-export const {
+const {
styled,
css,
theme,
@@ -414,6 +414,14 @@ export const {
export type CSS = Stitches.CSS<typeof config>;
+export { styled, css, theme, globalCss, keyframes, config };
+
+export const flushCss = () => {
+ const css = getCssText();
+ reset();
+ return css;
+};
+
export const darkTheme = createTheme({
colors: {
...grayDark,
diff --git a/packages/react-sdk/src/stitches/critical-css.tsx b/packages/react-sdk/src/stitches/critical-css.tsx
index efd45dda7e..77f6268bae 100644
--- a/packages/react-sdk/src/stitches/critical-css.tsx
+++ b/packages/react-sdk/src/stitches/critical-css.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { getCssText as getCssTextDefault } from "./css";
+import { flushCss as flushCssDefault } from "./css";
const criticalCssMarker = "__critical-css__";
@@ -8,7 +8,7 @@ export const CriticalCss = (): JSX.Element | null =>
export const insertCriticalCss = (
markup: string,
- getCssText: typeof getCssTextDefault = getCssTextDefault
+ flushCss: typeof flushCssDefault = flushCssDefault
): string => {
- return markup.replace(criticalCssMarker, `<style>${getCssText()}</style>`);
+ return markup.replace(criticalCssMarker, `<style>${flushCss()}</style>`);
};
diff --git a/packages/react-sdk/src/stitches/css.ts b/packages/react-sdk/src/stitches/css.ts
index 6baf04d7c1..af71864036 100644
--- a/packages/react-sdk/src/stitches/css.ts
+++ b/packages/react-sdk/src/stitches/css.ts
@@ -29,12 +29,11 @@ export const globalCss: typeof globalCssImport = (...args) => {
return getCachedConfig().globalCss(...args);
};
-export const getCssText = (): string => {
- return getCachedConfig().getCssText();
-};
-
-export const resetCss = () => {
- getCachedConfig().reset();
+export const flushCss = () => {
+ const config = getCachedConfig();
+ const css = config.getCssText();
+ config.reset();
+ return css;
};
export const setBreakpoints = (breakpoints: Array<Breakpoint>) => {