diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.ts index 2625105c69..323145fca5 100644 --- a/apps/designer/app/canvas/shared/styles.ts +++ b/apps/designer/app/canvas/shared/styles.ts @@ -15,56 +15,10 @@ import { validStaticValueTypes, } from "@webstudio-is/react-sdk"; import { globalCss } from "@webstudio-is/design-system"; -import { useEffect, useRef } from "react"; +import { useEffect } from "react"; import { createCssEngine, type StyleRule } from "@webstudio-is/css-engine"; import { useIsomorphicLayoutEffect } from "react-use"; -const setCssVar = (id: string, property: string, value?: StyleValue) => { - const customProperty = `--${toVarNamespace(id, property)}`; - if (value === undefined) { - document.body.style.removeProperty(customProperty); - return; - } - document.body.style.setProperty(customProperty, toValue(value)); -}; - -const useUpdateStyle = () => { - const [selectedInstance] = useSelectedInstance(); - useSubscribe("updateStyle", ({ id, updates, breakpoint }) => { - // Only update styles if they match the selected instance - // It can potentially happen that we selected a difference instance right after we changed the style in style panel. - if (id !== selectedInstance?.id) return; - - for (const update of updates) { - setCssVar(id, update.property, undefined); - } - - store.createTransaction([rootInstanceContainer], (rootInstance) => { - if (rootInstance === undefined) { - return; - } - setInstanceStyleMutable(rootInstance, id, updates, breakpoint); - }); - }); -}; - -const usePreviewStyle = () => { - useSubscribe("previewStyle", ({ id, updates }) => { - for (const update of updates) { - setCssVar(id, update.property, update.value); - } - }); -}; - -// Once we rendered the tree in editing mode, we have rendered all styles in a