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.

Drop css rules from instance (#775)

Bogdan Chadkin44a7083fde16
diff --git a/apps/designer/app/canvas/shared/breakpoints.ts b/apps/designer/app/canvas/shared/breakpoints.ts
index 190f463df0..29ef4572a1 100644
--- a/apps/designer/app/canvas/shared/breakpoints.ts
+++ b/apps/designer/app/canvas/shared/breakpoints.ts
@@ -1,7 +1,6 @@
import store from "immerhin";
import type { Breakpoint } from "@webstudio-is/css-data";
import { useSubscribe } from "~/shared/pubsub";
-import { deleteCssRulesByBreakpoint } from "~/shared/css-utils";
import {
breakpointsContainer,
rootInstanceContainer,
@@ -53,8 +52,6 @@ const useBreakpointDelete = () => {
breakpoints.splice(index, 1);
}
- deleteCssRulesByBreakpoint(rootInstance, breakpoint.id);
-
// delete breakpoint styles
filterMutable(styles, (style) => style.breakpointId !== breakpoint.id);
}
diff --git a/apps/designer/app/canvas/shared/instance.test.ts b/apps/designer/app/canvas/shared/instance.test.ts
index a826f355ba..e19d0f9dde 100644
--- a/apps/designer/app/canvas/shared/instance.test.ts
+++ b/apps/designer/app/canvas/shared/instance.test.ts
@@ -6,40 +6,34 @@ const tree: Instance = {
type: "instance",
component: "Body",
id: "root",
- cssRules: [],
children: [
{
type: "instance",
component: "Heading",
id: "heading1",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Box",
id: "box1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "box2",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Heading",
id: "heading2",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Heading",
id: "heading3",
- cssRules: [],
children: [],
},
],
diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.ts
index ad7b180466..0cf6d599a7 100644
--- a/apps/designer/app/canvas/shared/styles.ts
+++ b/apps/designer/app/canvas/shared/styles.ts
@@ -1,15 +1,10 @@
import { useEffect, useMemo } from "react";
import store from "immerhin";
import { useSubscribe } from "~/shared/pubsub";
-import {
- addGlobalRules,
- getPresetStyleRules,
- utils,
-} from "@webstudio-is/project";
+import { addGlobalRules, getPresetStyleRules } from "@webstudio-is/project";
import { useSelectedInstance } from "./nano-states";
import {
designTokensContainer,
- rootInstanceContainer,
useBreakpoints,
useDesignTokens,
usePresetStyles,
@@ -256,7 +251,7 @@ const setCssVar = (id: string, property: string, value?: StyleValue) => {
const useUpdateStyle = () => {
const [selectedInstance] = useSelectedInstance();
- useSubscribe("updateStyle", ({ id, updates, breakpoint }) => {
+ useSubscribe("updateStyle", ({ id, updates }) => {
// 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) {
@@ -266,13 +261,6 @@ const useUpdateStyle = () => {
for (const update of updates) {
setCssVar(id, update.property, undefined);
}
-
- store.createTransaction([rootInstanceContainer], (rootInstance) => {
- if (rootInstance === undefined) {
- return;
- }
- utils.tree.setInstanceStyleMutable(rootInstance, id, updates, breakpoint);
- });
});
};
diff --git a/apps/designer/app/designer/features/style-panel/shared/style-info.test.ts b/apps/designer/app/designer/features/style-panel/shared/style-info.test.ts
index ba529fffa4..10257ba23e 100644
--- a/apps/designer/app/designer/features/style-panel/shared/style-info.test.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/style-info.test.ts
@@ -74,19 +74,16 @@ const rootInstance: Instance = {
type: "instance",
id: "1",
component: "Body",
- cssRules: [],
children: [
{
type: "instance",
id: "2",
component: "Box",
- cssRules: [],
children: [
{
type: "instance",
id: "3",
component: "Box",
- cssRules: [],
children: [],
},
],
diff --git a/apps/designer/app/shared/css-utils/__snapshots__/delete-css-rules-by-breakpoint.test.ts.snap b/apps/designer/app/shared/css-utils/__snapshots__/delete-css-rules-by-breakpoint.test.ts.snap
deleted file mode 100644
index ef46dcf247..0000000000
--- a/apps/designer/app/shared/css-utils/__snapshots__/delete-css-rules-by-breakpoint.test.ts.snap
+++ /dev/null
@@ -1,32 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Delete breakpoint basic 1`] = `
-{
- "children": [
- {
- "children": [
- {
- "children": [],
- "component": "Box",
- "cssRules": [],
- "id": "3",
- "type": "instance",
- },
- ],
- "component": "Box",
- "cssRules": [
- {
- "breakpoint": "do not delete",
- "style": {},
- },
- ],
- "id": "2",
- "type": "instance",
- },
- ],
- "component": "Box",
- "cssRules": [],
- "id": "1",
- "type": "instance",
-}
-`;
diff --git a/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.test.ts b/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.test.ts
deleted file mode 100644
index 608f26dc68..0000000000
--- a/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.test.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { describe, test, expect } from "@jest/globals";
-import { type Instance } from "@webstudio-is/react-sdk";
-import { deleteCssRulesByBreakpoint } from "./delete-css-rules-by-breakpoint";
-
-describe("Delete breakpoint", () => {
- test("basic", () => {
- const instance: Instance = {
- type: "instance",
- component: "Box",
- id: "1",
- cssRules: [{ breakpoint: "delete this", style: {} }],
- children: [
- {
- type: "instance",
- component: "Box",
- id: "2",
- cssRules: [{ breakpoint: "do not delete", style: {} }],
- children: [
- {
- type: "instance",
- component: "Box",
- id: "3",
- cssRules: [{ breakpoint: "delete this", style: {} }],
- children: [],
- },
- ],
- },
- ],
- };
-
- deleteCssRulesByBreakpoint(instance, "delete this");
- expect(instance).toMatchSnapshot();
- });
-});
diff --git a/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.ts b/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.ts
deleted file mode 100644
index 259ed28ed3..0000000000
--- a/apps/designer/app/shared/css-utils/delete-css-rules-by-breakpoint.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type { Instance } from "@webstudio-is/react-sdk";
-import type { Breakpoint } from "@webstudio-is/css-data";
-
-export const deleteCssRulesByBreakpoint = (
- instance: Instance,
- breakpointId: Breakpoint["id"]
-) => {
- const cssRules = [...instance.cssRules];
- cssRules.forEach((cssRule, index) => {
- if (cssRule.breakpoint === breakpointId) {
- instance.cssRules.splice(index, 1);
- }
- });
-
- for (const child of instance.children) {
- if (child.type === "text") {
- continue;
- }
- deleteCssRulesByBreakpoint(child, breakpointId);
- }
-};
diff --git a/apps/designer/app/shared/css-utils/index.ts b/apps/designer/app/shared/css-utils/index.ts
index 53f6803340..b8234bcfae 100644
--- a/apps/designer/app/shared/css-utils/index.ts
+++ b/apps/designer/app/shared/css-utils/index.ts
@@ -1,2 +1 @@
-export * from "./delete-css-rules-by-breakpoint";
export * from "./generate-css-text";
diff --git a/packages/project/src/db/tree.ts b/packages/project/src/db/tree.ts
index 8f4fb48b69..b40946b846 100644
--- a/packages/project/src/db/tree.ts
+++ b/packages/project/src/db/tree.ts
@@ -16,11 +16,7 @@ import {
type Tree as DbTree,
} from "@webstudio-is/prisma-client";
import { utils } from "../index";
-import {
- SharedStyleValue,
- ImageValue,
- type CssRule,
-} from "@webstudio-is/css-data";
+import { SharedStyleValue, ImageValue } from "@webstudio-is/css-data";
import { z } from "zod";
import DataLoader from "dataloader";
import warnOnce from "warn-once";
@@ -126,7 +122,6 @@ const InstanceDbIn = z.lazy(() =>
id: z.string(),
component: z.string(),
children: z.array(z.union([InstanceDbIn, Text])),
- cssRules: z.array(CssRuleDbIn),
})
) as /* Instance is wrong type here, ImageValue is different after transform. We don't use it anyway */ z.ZodType<Instance>;
@@ -163,27 +158,14 @@ export const deleteById = async (treeId: Tree["id"]): Promise<void> => {
await prisma.tree.delete({ where: { id: treeId } });
};
-const addStylesToInstancesMutable = (instance: Instance, styles: Styles) => {
- const cssRulesMap = new Map<string, CssRule>();
- for (const style of styles) {
- if (instance.id !== style.instanceId) {
- continue;
- }
- let rule = cssRulesMap.get(style.breakpointId);
- if (rule === undefined) {
- rule = {
- breakpoint: style.breakpointId,
- style: {},
- };
- cssRulesMap.set(style.breakpointId, rule);
- }
- rule.style[style.property] = style.value;
- }
- instance.cssRules = Array.from(cssRulesMap.values());
+const deleteCssRulesFromInstancesMutable = (instance: Instance) => {
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ delete instance.cssRules;
for (const child of instance.children) {
if (child.type === "instance") {
- addStylesToInstancesMutable(child, styles);
+ deleteCssRulesFromInstancesMutable(child);
}
}
};
@@ -204,11 +186,12 @@ export const loadById = async (
const root = await InstanceDbOut.parseAsync(dbRoot);
+ deleteCssRulesFromInstancesMutable(root);
+
Instance.parse(root);
const presetStyles = PresetStyles.parse(JSON.parse(tree.presetStyles));
const styles = Styles.parse(JSON.parse(tree.styles));
- addStylesToInstancesMutable(root, styles);
return {
...tree,
diff --git a/packages/project/src/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap b/packages/project/src/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap
index b03c60384a..253f52c7c6 100644
--- a/packages/project/src/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap
+++ b/packages/project/src/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap
@@ -6,13 +6,11 @@ exports[`Delete instance div 1 > div 2 > [div 3] 1`] = `
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
@@ -24,13 +22,11 @@ exports[`Delete instance div 1 > div 2, [div 3] 1`] = `
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
diff --git a/packages/project/src/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap b/packages/project/src/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap
index 4ed18691f8..eb33b25040 100644
--- a/packages/project/src/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap
+++ b/packages/project/src/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap
@@ -6,20 +6,17 @@ exports[`Insert instance after a nested div using "end": div 1 > div 2, [div 3]
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
@@ -31,20 +28,17 @@ exports[`Insert instance after a nested div using index: div 1 > div 2, [div 3]
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
@@ -56,20 +50,17 @@ exports[`Insert instance before a nested div using index: div 1 > [div 3], div 2
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
@@ -83,19 +74,16 @@ exports[`Insert instance inside a nested div using "end": div 1 > div 2 > [div 3
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
diff --git a/packages/project/src/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap b/packages/project/src/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap
index 7f8414de21..2e42d526fe 100644
--- a/packages/project/src/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap
+++ b/packages/project/src/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap
@@ -8,26 +8,22 @@ exports[`Reparent instance new parent 1`] = `
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "4",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
@@ -39,27 +35,23 @@ exports[`Reparent instance same parent different position 1`] = `
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "3",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "2",
"type": "instance",
},
{
"children": [],
"component": "Box",
- "cssRules": [],
"id": "4",
"type": "instance",
},
],
"component": "Box",
- "cssRules": [],
"id": "1",
"type": "instance",
}
diff --git a/packages/project/src/shared/tree-utils/clone-instance.test.ts b/packages/project/src/shared/tree-utils/clone-instance.test.ts
index b6b74daccc..8a31c1cdd4 100644
--- a/packages/project/src/shared/tree-utils/clone-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/clone-instance.test.ts
@@ -18,19 +18,16 @@ describe("Clone instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/create-instance.test.ts b/packages/project/src/shared/tree-utils/create-instance.test.ts
index 01b3290988..c359b39898 100644
--- a/packages/project/src/shared/tree-utils/create-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/create-instance.test.ts
@@ -17,13 +17,6 @@ describe("create instance", () => {
expect(createdInstance.children.length).toBe(0);
});
- test("instance without style should be an object after creation", () => {
- const createdInstance = createInstance({
- component: "Box",
- });
- expect(Array.isArray(createdInstance.cssRules)).toBeTruthy();
- });
-
test("instance with children ", () => {
const createdInstance = createInstance({
component: "Box",
@@ -32,18 +25,15 @@ describe("create instance", () => {
type: "instance",
id: "1",
component: "Box",
- cssRules: [],
children: [],
},
],
- cssRules: [],
});
expect(createdInstance.children).toEqual([
{
type: "instance",
id: "1",
component: "Box",
- cssRules: [],
children: [],
},
]);
diff --git a/packages/project/src/shared/tree-utils/create-instance.ts b/packages/project/src/shared/tree-utils/create-instance.ts
index a2a28dbe3e..1f492c9551 100644
--- a/packages/project/src/shared/tree-utils/create-instance.ts
+++ b/packages/project/src/shared/tree-utils/create-instance.ts
@@ -1,6 +1,5 @@
import ObjectId from "bson-objectid";
import { type Instance, getComponentMeta } from "@webstudio-is/react-sdk";
-import { CssRule } from "@webstudio-is/css-data";
export const createInstanceId = () => {
return ObjectId().toString();
@@ -10,19 +9,16 @@ export const createInstance = ({
component,
id,
children,
- cssRules,
}: {
component: Instance["component"];
id?: Instance["id"];
children?: Instance["children"];
- cssRules?: Array<CssRule>;
}): Instance => {
const componentMeta = getComponentMeta(component);
return {
type: "instance",
component,
id: id === undefined ? createInstanceId() : id,
- cssRules: cssRules ?? [],
children:
children === undefined
? componentMeta.children?.map((value) => ({ type: "text", value })) ??
diff --git a/packages/project/src/shared/tree-utils/delete-instance.test.ts b/packages/project/src/shared/tree-utils/delete-instance.test.ts
index 5d85b77fea..d927629fa1 100644
--- a/packages/project/src/shared/tree-utils/delete-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/delete-instance.test.ts
@@ -8,19 +8,16 @@ describe("Delete instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
@@ -37,20 +34,17 @@ describe("Delete instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/find-closest-sibling-instance.test.ts b/packages/project/src/shared/tree-utils/find-closest-sibling-instance.test.ts
index 6dac370ead..67ccee8285 100644
--- a/packages/project/src/shared/tree-utils/find-closest-sibling-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/find-closest-sibling-instance.test.ts
@@ -8,13 +8,11 @@ describe("Find closest sibling instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
{ type: "text", value: "a" },
@@ -22,7 +20,6 @@ describe("Find closest sibling instance", () => {
type: "instance",
component: "Box",
id: "4",
- cssRules: [],
children: [],
},
{ type: "text", value: "b" },
@@ -30,7 +27,6 @@ describe("Find closest sibling instance", () => {
type: "instance",
component: "Box",
id: "5",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/find-parent-instance.test.ts b/packages/project/src/shared/tree-utils/find-parent-instance.test.ts
index 9782c04b8c..e78fe8d3de 100644
--- a/packages/project/src/shared/tree-utils/find-parent-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/find-parent-instance.test.ts
@@ -8,19 +8,16 @@ describe("Find parent instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/get-instance-path.test.ts b/packages/project/src/shared/tree-utils/get-instance-path.test.ts
index 9f6dccd616..1dbdd8da27 100644
--- a/packages/project/src/shared/tree-utils/get-instance-path.test.ts
+++ b/packages/project/src/shared/tree-utils/get-instance-path.test.ts
@@ -13,19 +13,16 @@ describe("Get instance path", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
@@ -41,19 +38,16 @@ describe("Get instance path", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2a",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3a",
- cssRules: [],
children: [],
},
],
@@ -62,13 +56,11 @@ describe("Get instance path", () => {
type: "instance",
component: "Box",
id: "2b",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3b",
- cssRules: [],
children: [],
},
],
@@ -92,19 +84,16 @@ describe("Get instance path with positions", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
],
@@ -124,19 +113,16 @@ describe("Get instance path with positions", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2a",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3a",
- cssRules: [],
children: [],
},
],
@@ -145,13 +131,11 @@ describe("Get instance path with positions", () => {
type: "instance",
component: "Box",
id: "2b",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "3b",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/index.ts b/packages/project/src/shared/tree-utils/index.ts
index b83053f11a..8c4a2f71e3 100644
--- a/packages/project/src/shared/tree-utils/index.ts
+++ b/packages/project/src/shared/tree-utils/index.ts
@@ -2,7 +2,6 @@ export * from "./create-instance";
export * from "./delete-instance";
export * from "./insert-instance";
export * from "./find-instance";
-export * from "./set-instance-style";
export * from "./get-instance-path";
export * from "./find-closest-sibling-instance";
export * from "./find-parent-instance";
diff --git a/packages/project/src/shared/tree-utils/insert-instance.test.ts b/packages/project/src/shared/tree-utils/insert-instance.test.ts
index 28f0f7f8b2..9ea0e23f8f 100644
--- a/packages/project/src/shared/tree-utils/insert-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/insert-instance.test.ts
@@ -11,13 +11,11 @@ describe("Insert instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
],
@@ -36,13 +34,11 @@ describe("Insert instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
],
@@ -61,13 +57,11 @@ describe("Insert instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
],
@@ -85,13 +79,11 @@ describe("Insert instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/reparent-instance.test.ts b/packages/project/src/shared/tree-utils/reparent-instance.test.ts
index e016d4848d..e6d8ba100c 100644
--- a/packages/project/src/shared/tree-utils/reparent-instance.test.ts
+++ b/packages/project/src/shared/tree-utils/reparent-instance.test.ts
@@ -8,26 +8,22 @@ describe("Reparent instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "4",
- cssRules: [],
children: [],
},
],
@@ -44,27 +40,23 @@ describe("Reparent instance", () => {
type: "instance",
component: "Box",
id: "1",
- cssRules: [],
children: [
{
type: "instance",
component: "Box",
id: "2",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Box",
id: "3",
- cssRules: [],
children: [],
},
{
type: "instance",
component: "Box",
id: "4",
- cssRules: [],
children: [],
},
],
diff --git a/packages/project/src/shared/tree-utils/set-instance-style.ts b/packages/project/src/shared/tree-utils/set-instance-style.ts
deleted file mode 100644
index 4a270e6072..0000000000
--- a/packages/project/src/shared/tree-utils/set-instance-style.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import type { Breakpoint } from "@webstudio-is/css-data";
-import type { Instance } from "@webstudio-is/react-sdk";
-import type { StyleUpdates } from "../canvas-components";
-import { findInstanceById } from "./find-instance";
-
-export const setInstanceStyleMutable = (
- rootInstance: Instance,
- id: Instance["id"],
- updates: StyleUpdates["updates"],
- breakpoint: Breakpoint
-) => {
- const instance = findInstanceById(rootInstance, id);
- if (instance === undefined) {
- return false;
- }
- let cssRule = instance.cssRules.find(
- (cssRule) => cssRule.breakpoint === breakpoint.id
- );
- if (cssRule === undefined) {
- cssRule = { style: {}, breakpoint: breakpoint.id };
- instance.cssRules.push(cssRule);
- }
-
- for (const update of updates) {
- if (update.operation === "delete") {
- delete cssRule.style[update.property];
- }
- if (update.operation === "set") {
- cssRule.style[update.property] = update.value;
- }
- }
- return true;
-};
diff --git a/packages/react-sdk/src/db/instance.ts b/packages/react-sdk/src/db/instance.ts
index ccb6e03bd1..d32b23ace2 100644
--- a/packages/react-sdk/src/db/instance.ts
+++ b/packages/react-sdk/src/db/instance.ts
@@ -1,4 +1,3 @@
-import { CssRule } from "@webstudio-is/css-data";
import { z } from "zod";
import { ComponentName, getComponentNames } from "../components";
@@ -7,7 +6,6 @@ import { ComponentName, getComponentNames } from "../components";
export type BaseInstance = {
id: string;
component: ComponentName;
- cssRules: Array<CssRule>;
};
export type Text = {
@@ -24,7 +22,6 @@ export const toBaseInstance = (instance: Instance): BaseInstance => {
return {
id: instance.id,
component: instance.component,
- cssRules: instance.cssRules,
};
};
@@ -41,6 +38,5 @@ export const Instance: z.ZodType<Instance> = z.lazy(() =>
id: z.string(),
component: z.enum(getComponentNames() as [ComponentName]),
children: z.array(z.union([Instance, Text])),
- cssRules: z.array(CssRule),
})
);