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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
move tree utils again back to project
Oleg Isonenbda114b4e3ce
diff --git a/apps/designer/app/canvas/canvas.tsx b/apps/designer/app/canvas/canvas.tsxindex f9ab92f35c..cab3e73493 100644--- a/apps/designer/app/canvas/canvas.tsx+++ b/apps/designer/app/canvas/canvas.tsx@@ -40,7 +40,7 @@ import {import { registerContainers } from "./shared/immerhin";import { usePublishScrollState } from "./shared/use-publish-scroll-state";import { useDragAndDrop } from "./shared/use-drag-drop";-import { setInstanceChildrenMutable } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import { CanvasData } from "~/shared/db";import { useSubscribeDesignerReady } from "./shared/use-designer-ready";import type { Asset } from "@webstudio-is/asset-uploader";@@ -55,7 +55,7 @@ const useElementsTree = () => {if (rootInstance === undefined) return;const { instanceId, updates } = change;- setInstanceChildrenMutable(instanceId, updates, rootInstance);+ utils.tree.setInstanceChildrenMutable(instanceId, updates, rootInstance);});}, []);diff --git a/apps/designer/app/canvas/features/text-editor/text-editor.stories.tsx b/apps/designer/app/canvas/features/text-editor/text-editor.stories.tsxindex 65b13fd6aa..e1896ea23d 100644--- a/apps/designer/app/canvas/features/text-editor/text-editor.stories.tsx+++ b/apps/designer/app/canvas/features/text-editor/text-editor.stories.tsx@@ -4,7 +4,7 @@ import type { ComponentStory, ComponentMeta } from "@storybook/react";import { action } from "@storybook/addon-actions";import { Box } from "@webstudio-is/design-system";import { useSubscribe, publish } from "~/shared/pubsub";-import { createInstance } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import type { TextToolbarState } from "~/designer/shared/nano-states";import { TextEditor } from "./text-editor";@@ -96,24 +96,24 @@ export const Basic: ComponentStory<typeof TextEditor> = ({ onChange }) => {}}><TextEditor- instance={createInstance({+ instance={utils.tree.createInstance({component: "TextBlock",children: ["Pragraph you can edit ",- createInstance({+ utils.tree.createInstance({component: "Bold",children: ["very bold text "],}),- createInstance({+ utils.tree.createInstance({component: "Bold",children: [- createInstance({+ utils.tree.createInstance({component: "Italic",children: ["with small italic"],}),],}),- createInstance({+ utils.tree.createInstance({component: "Bold",children: [" subtext"],}),diff --git a/apps/designer/app/canvas/shared/breakpoints.ts b/apps/designer/app/canvas/shared/breakpoints.tsindex 6d2a960d65..306b2429f2 100644--- a/apps/designer/app/canvas/shared/breakpoints.ts+++ b/apps/designer/app/canvas/shared/breakpoints.ts@@ -1,6 +1,6 @@import { useEffect, useRef } from "react";import store from "immerhin";-import type { Breakpoint } from "@webstudio-is/react-sdk";+import type { Breakpoint } from "@webstudio-is/css-data";import { useSubscribe } from "~/shared/pubsub";import { deleteCssRulesByBreakpoint } from "~/shared/css-utils";import {diff --git a/apps/designer/app/canvas/shared/copy-paste.ts b/apps/designer/app/canvas/shared/copy-paste.tsindex f29ec5cc44..68f2eca6b1 100644--- a/apps/designer/app/canvas/shared/copy-paste.ts+++ b/apps/designer/app/canvas/shared/copy-paste.ts@@ -4,7 +4,7 @@ import {allUserPropsContainer,} from "@webstudio-is/react-sdk";import { selectedInstanceContainer } from "./nano-states";-import { cloneInstance } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import { cloneProps } from "~/shared/props-utils";import { publish } from "~/shared/pubsub";@@ -19,7 +19,7 @@ export const copy = () => {export const paste = () => {if (currentInstance === undefined) return;- const instance = cloneInstance(currentInstance);+ const instance = utils.tree.cloneInstance(currentInstance);const props = currentProps? cloneProps(currentProps, { instanceId: instance.id }): undefined;diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.tsindex 0a14b629ee..2dba11d9d5 100644--- a/apps/designer/app/canvas/shared/instance.ts+++ b/apps/designer/app/canvas/shared/instance.ts@@ -9,23 +9,15 @@ import {getBrowserStyle,useAllUserProps,} from "@webstudio-is/react-sdk";+import { useSubscribe } from "~/shared/pubsub";import {- deleteInstanceMutable,- populateInstance,- findParentInstance,- findClosestSiblingInstance,- insertInstanceMutable,- findInstanceById,- reparentInstanceMutable,- getInstancePathWithPositions,+ utils,+ type HoveredInstanceData,type InstanceInsertionSpec,-} from "~/shared/tree-utils";-import store from "immerhin";-import {- HoveredInstanceData,type SelectedInstanceData,-} from "~/shared/canvas-components";+} from "@webstudio-is/project";+import store from "immerhin";import {useSelectedInstance,useSelectedElement,@@ -80,7 +72,10 @@ export const findInsertLocation = (return { parentId: rootInstance.id, position: "end" };}- const path = getInstancePathWithPositions(rootInstance, selectedInstanceId);+ const path = utils.tree.getInstancePathWithPositions(+ rootInstance,+ selectedInstanceId+ );path.reverse();const parentIndex = path.findIndex(@@ -107,8 +102,11 @@ export const useInsertInstance = () => {[rootInstanceContainer, allUserPropsContainer],(rootInstance, allUserProps) => {if (rootInstance === undefined) return;- const populatedInstance = populateInstance(instance, breakpoints[0].id);- const hasInserted = insertInstanceMutable(+ const populatedInstance = utils.tree.populateInstance(+ instance,+ breakpoints[0].id+ );+ const hasInserted = utils.tree.insertInstanceMutable(rootInstance,populatedInstance,dropTarget ?? findInsertLocation(rootInstance, selectedInstance?.id)@@ -130,7 +128,7 @@ export const useReparentInstance = () => {useSubscribe("reparentInstance", ({ instanceId, dropTarget }) => {store.createTransaction([rootInstanceContainer], (rootInstance) => {if (rootInstance === undefined) return;- reparentInstanceMutable(+ utils.tree.reparentInstanceMutable(rootInstance,instanceId,dropTarget.instanceId,@@ -144,7 +142,7 @@ export const useReparentInstance = () => {rootInstanceContainer.value !== undefined) {setSelectedInstance(- findInstanceById(rootInstanceContainer.value, instanceId)+ utils.tree.findInstanceById(rootInstanceContainer.value, instanceId));}});@@ -160,9 +158,12 @@ export const useDeleteInstance = () => {return;}- const parentInstance = findParentInstance(rootInstance, id);+ const parentInstance = utils.tree.findParentInstance(rootInstance, id);if (parentInstance !== undefined) {- const siblingInstance = findClosestSiblingInstance(parentInstance, id);+ const siblingInstance = utils.tree.findParentInstance(+ parentInstance,+ id+ );setSelectedInstance(siblingInstance || parentInstance);}}@@ -177,7 +178,7 @@ export const useDeleteInstance = () => {// Potentially we could also solve this by periodically removing unused props after while when instance was deletedstore.createTransaction([rootInstanceContainer], (rootInstance) => {if (rootInstance !== undefined) {- deleteInstanceMutable(rootInstance, id);+ utils.tree.deleteInstanceMutable(rootInstance, id);}});});@@ -312,7 +313,7 @@ export const useUpdateSelectedInstance = () => {useEffect(() => {let instance;if (rootInstance !== undefined && selectedInstance?.id) {- instance = findInstanceById(rootInstance, selectedInstance.id);+ instance = utils.tree.findInstanceById(rootInstance, selectedInstance.id);}// When it's a new inserted instance, it will be undefined, so we can't set it to undefined and remove it.if (instance !== undefined) setSelectedInstance(instance);diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.tsindex 7d719af167..44ae131406 100644--- a/apps/designer/app/canvas/shared/styles.ts+++ b/apps/designer/app/canvas/shared/styles.ts@@ -1,18 +1,18 @@import store from "immerhin";import { useSubscribe } from "~/shared/pubsub";-import { setInstanceStyleMutable } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import { useSelectedInstance } from "./nano-states";import { rootInstanceContainer } from "~/shared/nano-states";+import { idAttribute } from "@webstudio-is/react-sdk";import {validStaticValueTypes,- idAttribute,type Breakpoint,type ValidStaticStyleValue,type StyleValue,type CssRule,type StyleProperty,type Style,-} from "@webstudio-is/react-sdk";+} from "@webstudio-is/css-data";import { useEffect } from "react";import {createCssEngine,@@ -205,7 +205,7 @@ const useUpdateStyle = () => {if (rootInstance === undefined) {return;}- setInstanceStyleMutable(rootInstance, id, updates, breakpoint);+ utils.tree.setInstanceStyleMutable(rootInstance, id, updates, breakpoint);});});};diff --git a/apps/designer/app/canvas/shared/use-drag-drop.ts b/apps/designer/app/canvas/shared/use-drag-drop.tsindex b178ac4285..86b251ccfd 100644--- a/apps/designer/app/canvas/shared/use-drag-drop.ts+++ b/apps/designer/app/canvas/shared/use-drag-drop.ts@@ -3,11 +3,7 @@ import {useRootInstance,useTextEditingInstanceId,} from "~/shared/nano-states";-import {- getInstancePath,- createInstance,- findClosestNonInlineParent,-} from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import {findInstanceByElement,getInstanceElementById,@@ -104,7 +100,7 @@ export const useDragAndDrop = () => {return dropTarget;}- const path = getInstancePath(rootInstance, dropTarget.data.id);+ const path = utils.tree.getInstancePath(rootInstance, dropTarget.data.id);path.reverse();if (dropTarget.area !== "center") {@@ -184,7 +180,7 @@ export const useDragAndDrop = () => {// When trying to drag an inline instance, drag its parent insteadif (components[instance.component].isInlineOnly) {- const nonInlineParent = findClosestNonInlineParent(+ const nonInlineParent = utils.tree.findClosestNonInlineParent(rootInstance,instance.id);@@ -292,7 +288,9 @@ export const useDragAndDrop = () => {publish({type: "insertInstance",payload: {- instance: createInstance({ component: dragItem.component }),+ instance: utils.tree.createInstance({+ component: dragItem.component,+ }),dropTarget: {parentId: dropTarget.data.id,position: dropTarget.indexWithinChildren,diff --git a/apps/designer/app/canvas/shared/use-shortcuts.ts b/apps/designer/app/canvas/shared/use-shortcuts.tsindex 31a5823a1d..272e3651b3 100644--- a/apps/designer/app/canvas/shared/use-shortcuts.ts+++ b/apps/designer/app/canvas/shared/use-shortcuts.ts@@ -6,7 +6,7 @@ import { publish, useSubscribe } from "~/shared/pubsub";import { useSelectedInstance } from "./nano-states";import { copy, paste } from "./copy-paste";import { useTextEditingInstanceId } from "~/shared/nano-states";-import { type SelectedInstanceData } from "~/shared/canvas-components";+import { type SelectedInstanceData } from "@webstudio-is/project";declare module "~/shared/pubsub" {export interface PubsubMap {diff --git a/apps/designer/app/canvas/shared/use-track-selected-element.ts b/apps/designer/app/canvas/shared/use-track-selected-element.tsindex fbc3bbcda0..6efdf1f5c2 100644--- a/apps/designer/app/canvas/shared/use-track-selected-element.ts+++ b/apps/designer/app/canvas/shared/use-track-selected-element.ts@@ -6,10 +6,7 @@ import {useRootInstance,useTextEditingInstanceId,} from "~/shared/nano-states";-import {- findClosestNonInlineParent,- findInstanceById,-} from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import {getInstanceElementById,getInstanceIdFromElement,@@ -36,7 +33,7 @@ export const useTrackSelectedElement = () => {const selectInstance = useCallback((id) => {if (rootInstance === undefined) return;- const instance = findInstanceById(rootInstance, id);+ const instance = utils.tree.findInstanceById(rootInstance, id);setSelectedInstance(instance);},[setSelectedInstance, rootInstance]@@ -103,7 +100,8 @@ export const useTrackSelectedElement = () => {// Inline instances are not editable directly, only through parent instance.if (isInlineOnly) {const parent =- rootInstance && findClosestNonInlineParent(rootInstance, id);+ rootInstance &&+ utils.tree.findClosestNonInlineParent(rootInstance, id);if (parent && components[parent.component].isContentEditable) {selectInstance(parent.id);setEditingInstanceId(parent.id);diff --git a/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsx b/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsxindex 70abc6c14b..2652c0e840 100644--- a/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsx+++ b/apps/designer/app/designer/features/breakpoints/breakpoints-editor.tsx@@ -1,6 +1,6 @@import { useState } from "react";import useDebounce from "react-use/lib/useDebounce";-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import { type Publish } from "~/shared/pubsub";import { Button, TextField, Flex, Text } from "@webstudio-is/design-system";import { PlusIcon, TrashIcon } from "@webstudio-is/icons";diff --git a/apps/designer/app/designer/features/breakpoints/breakpoints.tsx b/apps/designer/app/designer/features/breakpoints/breakpoints.tsxindex 1e22c0d4e4..c0be3c6029 100644--- a/apps/designer/app/designer/features/breakpoints/breakpoints.tsx+++ b/apps/designer/app/designer/features/breakpoints/breakpoints.tsx@@ -1,5 +1,5 @@import { useEffect, useState } from "react";-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import { type Publish, useSubscribe } from "~/shared/pubsub";import {Text,diff --git a/apps/designer/app/designer/features/breakpoints/confirmation-dialog.tsx b/apps/designer/app/designer/features/breakpoints/confirmation-dialog.tsxindex a65536d794..3bddba7019 100644--- a/apps/designer/app/designer/features/breakpoints/confirmation-dialog.tsx+++ b/apps/designer/app/designer/features/breakpoints/confirmation-dialog.tsx@@ -1,4 +1,4 @@-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import { Button, Flex, Paragraph } from "@webstudio-is/design-system";type ConfirmationDialogProps = {diff --git a/apps/designer/app/designer/features/breakpoints/preview.tsx b/apps/designer/app/designer/features/breakpoints/preview.tsxindex bbc98f5580..374ea37170 100644--- a/apps/designer/app/designer/features/breakpoints/preview.tsx+++ b/apps/designer/app/designer/features/breakpoints/preview.tsx@@ -1,4 +1,4 @@-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import { Paragraph, Flex, Text } from "@webstudio-is/design-system";type PreviewProps = {diff --git a/apps/designer/app/designer/features/breakpoints/trigger-button.tsx b/apps/designer/app/designer/features/breakpoints/trigger-button.tsxindex f820a5a10e..f735140051 100644--- a/apps/designer/app/designer/features/breakpoints/trigger-button.tsx+++ b/apps/designer/app/designer/features/breakpoints/trigger-button.tsx@@ -1,5 +1,5 @@import { forwardRef, type ComponentProps, type ElementRef } from "react";-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import {useCanvasWidth,useZoom,diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsxindex c69d3fcddf..f89f8ba6fc 100644--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx@@ -6,7 +6,7 @@ import {import { type Publish } from "~/shared/pubsub";import { Control } from "./control";import { CollapsibleSection, ComponentInfo } from "~/designer/shared/inspector";-import type { SelectedInstanceData } from "~/shared/canvas-components";+import type { SelectedInstanceData } from "@webstudio-is/project";import {Box,Button,diff --git a/apps/designer/app/designer/features/props-panel/use-props-logic.test.ts b/apps/designer/app/designer/features/props-panel/use-props-logic.test.tsindex 6d359c1668..bb17c8ce38 100644--- a/apps/designer/app/designer/features/props-panel/use-props-logic.test.ts+++ b/apps/designer/app/designer/features/props-panel/use-props-logic.test.ts@@ -1,7 +1,7 @@import { renderHook, act } from "@testing-library/react-hooks";import { components, UserProp } from "@webstudio-is/react-sdk";import { nanoid } from "nanoid";-import { SelectedInstanceData } from "~/shared/canvas-components";+import type { SelectedInstanceData } from "@webstudio-is/project";import { usePropsLogic } from "./use-props-logic";const getSelectedInstanceData = (diff --git a/apps/designer/app/designer/features/props-panel/use-props-logic.ts b/apps/designer/app/designer/features/props-panel/use-props-logic.tsindex 012f8abf43..126c820477 100644--- a/apps/designer/app/designer/features/props-panel/use-props-logic.ts+++ b/apps/designer/app/designer/features/props-panel/use-props-logic.ts@@ -10,7 +10,7 @@ import produce from "immer";import uniqBy from "lodash/uniqBy";import debounce from "lodash/debounce";import { useRef, useState } from "react";-import type { SelectedInstanceData } from "~/shared/canvas-components";+import type { SelectedInstanceData } from "@webstudio-is/project";declare module "~/shared/pubsub" {export interface PubsubMap {diff --git a/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx b/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsxindex 8581d41c08..6d8800c0db 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/components.tsx@@ -2,10 +2,9 @@ import { type MouseEventHandler, useState } from "react";import { createPortal } from "react-dom";import { type Instance, components } from "@webstudio-is/react-sdk";import { useSubscribe, type Publish } from "~/shared/pubsub";-import { Flex } from "@webstudio-is/design-system";-import { useDrag, type Point } from "@webstudio-is/design-system";+import { Flex, useDrag, type Point } from "@webstudio-is/design-system";import { PlusIcon } from "@webstudio-is/icons";-import { createInstance } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";import type { TabName } from "../../types";import { ComponentThumb } from "./component-thumb";import { useCanvasRect, useZoom } from "~/designer/shared/nano-states";@@ -107,7 +106,7 @@ export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {type: "dragStart",payload: {origin: "panel",- dragItem: createInstance({ component: componentName }),+ dragItem: utils.tree.createInstance({ component: componentName }),},});},@@ -151,7 +150,7 @@ export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {onSetActiveTab("none");publish({type: "insertInstance",- payload: { instance: createInstance({ component }) },+ payload: { instance: utils.tree.createInstance({ component }) },});}}/>diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsxindex 41aa81f7ed..a762cfcf1e 100644--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx@@ -1,7 +1,7 @@import { CssValueInput } from "../../shared/css-value-input";import { getFinalValue } from "../../shared/get-final-value";import { ControlProps } from "../../style-sections";-import { type StyleValue } from "@webstudio-is/react-sdk";+import type { StyleValue } from "@webstudio-is/css-data";import { toValue } from "@webstudio-is/css-engine";import { useState } from "react";import { Box, Tooltip } from "@webstudio-is/design-system";diff --git a/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx b/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsxindex 6005155e93..51c3dc2d74 100644--- a/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx@@ -5,7 +5,7 @@ import {ToggleGroupRoot,ToggleGroupItem,} from "@webstudio-is/design-system";-import { StyleProperty } from "@webstudio-is/react-sdk";+import type { StyleProperty } from "@webstudio-is/css-data";import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";export type ToggleGroupControlProps = {diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsxindex e1e417d771..7f1bf655e0 100644--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx@@ -1,7 +1,7 @@import { Flex, Grid, IconButton } from "@webstudio-is/design-system";import { DotFilledIcon } from "@webstudio-is/icons";import { useIsFromCurrentBreakpoint } from "../../../shared/use-is-from-current-breakpoint";-import type { Style } from "@webstudio-is/react-sdk";+import type { Style } from "@webstudio-is/css-data";import type { CreateBatchUpdate } from "../../../shared/use-style-data";export const FlexGrid = ({diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsxindex d8f8f0821b..5f0ce47922 100644--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx@@ -1,7 +1,7 @@import { useState, useEffect } from "react";import { Flex, IconButton, Tooltip } from "@webstudio-is/design-system";import { LockOpenIcon, LockCloseIcon } from "@webstudio-is/icons";-import type { Style } from "@webstudio-is/react-sdk";+import type { Style } from "@webstudio-is/css-data";import type { CreateBatchUpdate } from "../../../shared/use-style-data";export const Lock = ({diff --git a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsxindex c5fe5662ee..86f81bea60 100644--- a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx@@ -1,9 +1,6 @@import { useEffect, useState } from "react";-import {- categories,- type StyleProperty,- type StyleValue,-} from "@webstudio-is/react-sdk";+import { categories } from "@webstudio-is/react-sdk";+import type { StyleProperty, StyleValue } from "@webstudio-is/css-data";import { Box } from "@webstudio-is/design-system";import { toValue } from "@webstudio-is/css-engine";import { SetProperty } from "../../shared/use-style-data";diff --git a/apps/designer/app/designer/features/style-panel/shared/configs.ts b/apps/designer/app/designer/features/style-panel/shared/configs.tsindex 32077e29aa..8ff27de91a 100644--- a/apps/designer/app/designer/features/style-panel/shared/configs.ts+++ b/apps/designer/app/designer/features/style-panel/shared/configs.ts@@ -1,9 +1,5 @@-import {- categories,- type Category,- type StyleProperty,- type AppliesTo,-} from "@webstudio-is/react-sdk";+import { categories, type Category } from "@webstudio-is/react-sdk";+import type { StyleProperty, AppliesTo } from "@webstudio-is/css-data";import { humanizeString } from "~/shared/string-utils";import {IconRecords,diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.stories.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.stories.tsxindex e050db2f8f..a73ce2c5f4 100644--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.stories.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.stories.tsx@@ -1,6 +1,6 @@import React from "react";import { Flex, TextField } from "@webstudio-is/design-system";-import { StyleValue } from "@webstudio-is/react-sdk";+import type { StyleValue } from "@webstudio-is/css-data";import { CssValueInput } from "./css-value-input";import { action } from "@storybook/addon-actions";diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsxindex 00ab4ac023..917b8788de 100644--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx@@ -12,12 +12,12 @@ import {styled,} from "@webstudio-is/design-system";import { ChevronDownIcon } from "@webstudio-is/icons";-import {- type KeywordValue,- type StyleProperty,- type UnsetValue,+import type {+ KeywordValue,+ StyleProperty,+ UnsetValue,StyleValue,-} from "@webstudio-is/react-sdk";+} from "@webstudio-is/css-data";import {type KeyboardEventHandler,type KeyboardEvent,diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/unit-select.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/unit-select.tsxindex 6012a7dfc0..94e20af099 100644--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/unit-select.tsx+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/unit-select.tsx@@ -1,5 +1,5 @@import { useState, useMemo } from "react";-import { type Unit, type UnitValue, StyleValue } from "@webstudio-is/react-sdk";+import type { Unit, UnitValue, StyleValue } from "@webstudio-is/css-data";import { toValue } from "@webstudio-is/css-engine";import * as SelectPrimitive from "@radix-ui/react-select";import {diff --git a/apps/designer/app/designer/features/style-panel/shared/dependencies.ts b/apps/designer/app/designer/features/style-panel/shared/dependencies.tsindex c2049cb281..de85a75c23 100644--- a/apps/designer/app/designer/features/style-panel/shared/dependencies.ts+++ b/apps/designer/app/designer/features/style-panel/shared/dependencies.ts@@ -1,4 +1,4 @@-import type { AppliesTo, StyleProperty } from "@webstudio-is/react-sdk";+import type { AppliesTo, StyleProperty } from "@webstudio-is/css-data";const displayInline = ["inline",diff --git a/apps/designer/app/designer/features/style-panel/shared/get-css-rule-for-breakpoint.ts b/apps/designer/app/designer/features/style-panel/shared/get-css-rule-for-breakpoint.tsindex 41deecf87d..4d5acd6546 100644--- a/apps/designer/app/designer/features/style-panel/shared/get-css-rule-for-breakpoint.ts+++ b/apps/designer/app/designer/features/style-panel/shared/get-css-rule-for-breakpoint.ts@@ -1,4 +1,4 @@-import { type CssRule, type Breakpoint } from "@webstudio-is/react-sdk";+import type { CssRule, Breakpoint } from "@webstudio-is/css-data";/*** Find a instance css rule that is set on the provided breakpoint.diff --git a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts b/apps/designer/app/designer/features/style-panel/shared/get-final-value.tsindex 07fb72ba94..bd0f47f32d 100644--- a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts+++ b/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts@@ -1,4 +1,4 @@-import type { Style, StyleValue, StyleProperty } from "@webstudio-is/react-sdk";+import type { Style, StyleValue, StyleProperty } from "@webstudio-is/css-data";import { toValue } from "@webstudio-is/css-engine";import type { InheritedStyle } from "./get-inherited-style";import { isValid } from "./parse-css-value";diff --git a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts b/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.tsindex 2e51cad73e..62e7202223 100644--- a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts+++ b/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts@@ -1,9 +1,6 @@import { properties } from "@webstudio-is/css-data";-import type {- StyleValue,- StyleProperty,- Instance,-} from "@webstudio-is/react-sdk";+import type { StyleValue, StyleProperty } from "@webstudio-is/css-data";+import type { Instance } from "@webstudio-is/react-sdk";export type InheritedStyle = {[property in StyleProperty]: {diff --git a/apps/designer/app/designer/features/style-panel/shared/parse-css-value.ts b/apps/designer/app/designer/features/style-panel/shared/parse-css-value.tsindex 3a01154a24..e127d845bf 100644--- a/apps/designer/app/designer/features/style-panel/shared/parse-css-value.ts+++ b/apps/designer/app/designer/features/style-panel/shared/parse-css-value.ts@@ -1,5 +1,5 @@import hyphenate from "hyphenate-style-name";-import type { StyleProperty, StyleValue, Unit } from "@webstudio-is/react-sdk";+import type { StyleProperty, StyleValue, Unit } from "@webstudio-is/css-data";import { units } from "@webstudio-is/css-data";const unitRegex = new RegExp(`${[...units, "number"].join("|")}`);diff --git a/apps/designer/app/designer/features/style-panel/shared/use-is-from-current-breakpoint.ts b/apps/designer/app/designer/features/style-panel/shared/use-is-from-current-breakpoint.tsindex 9379224360..ba69bcf057 100644--- a/apps/designer/app/designer/features/style-panel/shared/use-is-from-current-breakpoint.ts+++ b/apps/designer/app/designer/features/style-panel/shared/use-is-from-current-breakpoint.ts@@ -1,5 +1,5 @@import { useMemo } from "react";-import { type StyleProperty } from "@webstudio-is/react-sdk";+import type { StyleProperty } from "@webstudio-is/css-data";import {useSelectedBreakpoint,useSelectedInstanceData,diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.tsindex 5308398930..e24e632ddf 100644--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts@@ -1,9 +1,6 @@import { useState, useMemo, useEffect, useCallback } from "react";-import type {- SelectedInstanceData,- StyleUpdates,-} from "~/shared/canvas-components";-import { type StyleProperty } from "@webstudio-is/react-sdk";+import type { SelectedInstanceData, StyleUpdates } from "@webstudio-is/project";+import type { StyleProperty } from "@webstudio-is/css-data";import { type Publish } from "~/shared/pubsub";import { useSelectedBreakpoint } from "~/designer/shared/nano-states";import { parseCssValue } from "./parse-css-value";diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsxindex 63114299b3..d14044a532 100644--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx@@ -1,7 +1,7 @@import type { Publish } from "~/shared/pubsub";import { willRender } from "~/designer/shared/breakpoints";import { Box, Card, Paragraph, SearchField } from "@webstudio-is/design-system";-import type { SelectedInstanceData } from "~/shared/canvas-components";+import type { SelectedInstanceData } from "@webstudio-is/project";import { useStyleData } from "./shared/use-style-data";import { StyleSettings } from "./style-settings";import { useState } from "react";diff --git a/apps/designer/app/designer/features/style-panel/style-sections.tsx b/apps/designer/app/designer/features/style-panel/style-sections.tsxindex ed77fa82d3..db089bdbb6 100644--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx@@ -1,10 +1,7 @@import { Grid, type CSS } from "@webstudio-is/design-system";import type { StyleConfig } from "./shared/configs";-import {- type Style,- type StyleProperty,- type Category,-} from "@webstudio-is/react-sdk";+import type { Category } from "@webstudio-is/react-sdk";+import type { Style, StyleProperty } from "@webstudio-is/css-data";import type { SetProperty, CreateBatchUpdate } from "./shared/use-style-data";import type { InheritedStyle } from "./shared/get-inherited-style";import * as controls from "./controls";diff --git a/apps/designer/app/designer/features/style-panel/style-settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsxindex a66ee2083c..64f9e247ca 100644--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx@@ -1,10 +1,6 @@import hyphenate from "hyphenate-style-name";-import {- categories,- type CssRule,- type Category,- type Style,-} from "@webstudio-is/react-sdk";+import { categories, type Category } from "@webstudio-is/react-sdk";+import type { CssRule, Style } from "@webstudio-is/css-data";import { type StyleConfig, styleConfigs } from "./shared/configs";import { CollapsibleSection } from "~/designer/shared/inspector";@@ -19,7 +15,7 @@ import {type SetProperty,type CreateBatchUpdate,} from "./shared/use-style-data";-import { type SelectedInstanceData } from "~/shared/canvas-components";+import { type SelectedInstanceData } from "@webstudio-is/project";import { type RenderPropertyProps } from "./style-sections";// Finds a property/value by using any available form: property, label, valuediff --git a/apps/designer/app/designer/features/tree-preview/tree-preview.tsx b/apps/designer/app/designer/features/tree-preview/tree-preview.tsxindex ada3223755..dbf8a65d76 100644--- a/apps/designer/app/designer/features/tree-preview/tree-preview.tsx+++ b/apps/designer/app/designer/features/tree-preview/tree-preview.tsx@@ -3,14 +3,8 @@ import { type Instance } from "@webstudio-is/react-sdk";import { useMemo } from "react";import { Flex } from "@webstudio-is/design-system";import { useRootInstance, useDragAndDropState } from "~/shared/nano-states";-import {- reparentInstanceMutable,- insertInstanceMutable,- createInstance,- findInstanceById,- getInstancePath,-} from "~/shared/tree-utils";import { InstanceTreeNode } from "~/designer/shared/tree";+import { utils } from "@webstudio-is/project";export const TreePrevew = () => {const [rootInstance] = useRootInstance();@@ -31,20 +25,21 @@ export const TreePrevew = () => {}const isNew =- findInstanceById(rootInstance, dragItemInstance.id) === undefined;+ utils.tree.findInstanceById(rootInstance, dragItemInstance.id) ===+ undefined;const instance: Instance = produce((draft) => {if (isNew) {- insertInstanceMutable(+ utils.tree.insertInstanceMutable(draft,- createInstance({ component: dragItemInstance.component }),+ utils.tree.createInstance({ component: dragItemInstance.component }),{parentId: dropTargetInstanceId,position: dropTargetPosition,});} else {- reparentInstanceMutable(+ utils.tree.reparentInstanceMutable(draft,dragItemInstance.id,dropTargetInstanceId,@@ -53,10 +48,9 @@ export const TreePrevew = () => {}})(rootInstance);- const dropTargetPath = getInstancePath(- rootInstance,- dropTargetInstanceId- ).map((item) => item.id);+ const dropTargetPath = utils.tree+ .getInstancePath(rootInstance, dropTargetInstanceId)+ .map((item) => item.id);return {itemData: instance,diff --git a/apps/designer/app/designer/shared/breakpoints/will-render.ts b/apps/designer/app/designer/shared/breakpoints/will-render.tsindex d88ca03121..f179e2ea05 100644--- a/apps/designer/app/designer/shared/breakpoints/will-render.ts+++ b/apps/designer/app/designer/shared/breakpoints/will-render.ts@@ -1,4 +1,4 @@-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";export const willRender = (breakpoint: Breakpoint, canvasWidth: number) =>canvasWidth >= breakpoint.minWidth;diff --git a/apps/designer/app/designer/shared/inspector/component-info.tsx b/apps/designer/app/designer/shared/inspector/component-info.tsxindex 42b6600ef8..bd5a5b89cd 100644--- a/apps/designer/app/designer/shared/inspector/component-info.tsx+++ b/apps/designer/app/designer/shared/inspector/component-info.tsx@@ -1,6 +1,6 @@import { components } from "@webstudio-is/react-sdk";import { Flex, Text } from "@webstudio-is/design-system";-import type { SelectedInstanceData } from "~/shared/canvas-components";+import type { SelectedInstanceData } from "@webstudio-is/project";export const ComponentInfo = ({selectedInstanceData,diff --git a/apps/designer/app/designer/shared/instance/use-selected-instance-path.ts b/apps/designer/app/designer/shared/instance/use-selected-instance-path.tsindex 418a95bf28..686724e05e 100644--- a/apps/designer/app/designer/shared/instance/use-selected-instance-path.ts+++ b/apps/designer/app/designer/shared/instance/use-selected-instance-path.ts@@ -1,7 +1,7 @@import { Instance } from "@webstudio-is/react-sdk";import { useMemo } from "react";import { useRootInstance } from "~/shared/nano-states";-import { getInstancePath } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";export const useSelectedInstancePath = (selectedInstanceId?: Instance["id"]@@ -10,7 +10,7 @@ export const useSelectedInstancePath = (return useMemo(() =>selectedInstanceId !== undefined && rootInstance !== undefined- ? getInstancePath(rootInstance, selectedInstanceId)+ ? utils.tree.getInstancePath(rootInstance, selectedInstanceId): [],[selectedInstanceId, rootInstance]);diff --git a/apps/designer/app/designer/shared/nano-states/index.ts b/apps/designer/app/designer/shared/nano-states/index.tsindex 8bda3b91c4..8f3d746055 100644--- a/apps/designer/app/designer/shared/nano-states/index.ts+++ b/apps/designer/app/designer/shared/nano-states/index.ts@@ -1,9 +1,9 @@import { createValueContainer, useValue } from "react-nano-state";-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import {type SelectedInstanceData,type HoveredInstanceData,-} from "~/shared/canvas-components";+} from "@webstudio-is/project";import { type SyncStatus } from "~/shared/sync";import { Asset } from "@webstudio-is/asset-uploader";import { type Pages, type Project } from "@webstudio-is/project";diff --git a/apps/designer/app/designer/shared/tree/index.tsx b/apps/designer/app/designer/shared/tree/index.tsxindex 27e9a1f899..9d7cbacfdc 100644--- a/apps/designer/app/designer/shared/tree/index.tsx+++ b/apps/designer/app/designer/shared/tree/index.tsx@@ -8,16 +8,12 @@ import {type TreeItemRenderProps,} from "@webstudio-is/design-system";import { components, Instance } from "@webstudio-is/react-sdk";-import {- findInstanceById,- getInstancePath,- getInstancePathWithPositions,-} from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";const instanceRelatedProps = {- findItemById: findInstanceById,- getItemPath: getInstancePath,- getItemPathWithPositions: getInstancePathWithPositions,+ findItemById: utils.tree.findInstanceById,+ getItemPath: utils.tree.getInstancePath,+ getItemPathWithPositions: utils.tree.getInstancePathWithPositions,canLeaveParent(item: Instance) {return components[item.component].isInlineOnly !== true;},diff --git a/apps/designer/app/routes/rest/breakpoints.$projectId.ts b/apps/designer/app/routes/rest/breakpoints.$projectId.tsindex 3e699c3e15..1398151476 100644--- a/apps/designer/app/routes/rest/breakpoints.$projectId.ts+++ b/apps/designer/app/routes/rest/breakpoints.$projectId.ts@@ -1,5 +1,5 @@import type { LoaderFunction } from "@remix-run/node";-import { Breakpoint } from "@webstudio-is/react-sdk";+import type { Breakpoint } from "@webstudio-is/css-data";import { db } from "@webstudio-is/project/server";export type ErrorData = {diff --git a/apps/designer/app/routes/s/css.ts b/apps/designer/app/routes/s/css.tsindex 97d7a57feb..0bcd837737 100644--- a/apps/designer/app/routes/s/css.ts+++ b/apps/designer/app/routes/s/css.ts@@ -1,11 +1,11 @@import { ActionFunction, json } from "@remix-run/node";import { db } from "@webstudio-is/project/server";+import { utils } from "@webstudio-is/project";import { loadCanvasData } from "~/shared/db";import { getBuildParams } from "~/shared/router-utils";import env from "~/env.server";import { sentryException } from "~/shared/sentry";import { createCssEngine } from "@webstudio-is/css-engine";-import { getCssRules } from "~/shared/tree-utils";import { idAttribute } from "@webstudio-is/react-sdk";import { addGlobalRules } from "~/canvas/shared/styles";@@ -41,7 +41,7 @@ export const loader: ActionFunction = async ({ request }) => {engine.addMediaRule(breakpoint.id, breakpoint);}- const cssRules = getCssRules(canvasData.tree?.root);+ const cssRules = utils.tree.getCssRules(canvasData.tree?.root);for (const [instanceId, cssRule] of cssRules) {engine.addStyleRule(`[${idAttribute}="${instanceId}"]`, cssRule);}diff --git a/apps/designer/app/shared/canvas-components/index.ts b/apps/designer/app/shared/canvas-components/index.tsdeleted file mode 100644index e9f7edf109..0000000000--- a/apps/designer/app/shared/canvas-components/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./instance-data";diff --git a/apps/designer/app/shared/canvas-components/instance-data.ts b/apps/designer/app/shared/canvas-components/instance-data.tsdeleted file mode 100644index 9af88bd561..0000000000--- a/apps/designer/app/shared/canvas-components/instance-data.ts+++ /dev/null@@ -1,33 +0,0 @@-import {- type Instance,- type InstanceProps,- type CssRule,- type Style,- type StyleProperty,- type StyleValue,- type Breakpoint,-} from "@webstudio-is/react-sdk";--export type SelectedInstanceData = {- id: Instance["id"];- component: Instance["component"];- cssRules: Array<CssRule>;- browserStyle: Style;- props: InstanceProps;-};--export type HoveredInstanceData = {- id: Instance["id"];- component: Instance["component"];-};--type StyleUpdate = {- property: StyleProperty;- value: StyleValue;-};--export type StyleUpdates = {- id: Instance["id"];- updates: Array<StyleUpdate>;- breakpoint: Breakpoint;-};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.tsindex f78818eca3..8d53144806 100644--- 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@@ -1,4 +1,5 @@-import { type Instance, type Breakpoint } from "@webstudio-is/react-sdk";+import type { Instance } from "@webstudio-is/react-sdk";+import type { Breakpoint } from "@webstudio-is/css-data";export const deleteCssRulesByBreakpoint = (instance: Instance,diff --git a/apps/designer/app/shared/dom-utils/instance.ts b/apps/designer/app/shared/dom-utils/instance.tsindex 070cbceff2..6b64eda237 100644--- a/apps/designer/app/shared/dom-utils/instance.ts+++ b/apps/designer/app/shared/dom-utils/instance.ts@@ -1,5 +1,5 @@import { type Instance } from "@webstudio-is/react-sdk";-import { findInstanceById } from "~/shared/tree-utils";+import { utils } from "@webstudio-is/project";export const getInstanceElementById = (id: Instance["id"]) => {return document.getElementById(id);@@ -21,5 +21,5 @@ export const findInstanceByElement = (return undefined;}- return findInstanceById(rootInstance, id);+ return utils.tree.findInstanceById(rootInstance, id);};diff --git a/apps/designer/app/shared/nano-states/nano-states.ts b/apps/designer/app/shared/nano-states/nano-states.tsindex 96d155f3f6..6978a660da 100644--- a/apps/designer/app/shared/nano-states/nano-states.ts+++ b/apps/designer/app/shared/nano-states/nano-states.ts@@ -1,9 +1,10 @@import { createValueContainer, useValue } from "react-nano-state";-import { type Breakpoint, type Instance } from "@webstudio-is/react-sdk";-import {+import type { Instance } from "@webstudio-is/react-sdk";+import type {DropTargetChangePayload,DragStartPayload,} from "~/canvas/shared/use-drag-drop";+import type { Breakpoint } from "@webstudio-is/css-data";export const rootInstanceContainer = createValueContainer<Instance | undefineddiff --git a/apps/designer/app/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap b/apps/designer/app/shared/tree-utils/__snapshots__/delete-instance.test.ts.snapdeleted file mode 100644index e9b9078d9c..0000000000--- a/apps/designer/app/shared/tree-utils/__snapshots__/delete-instance.test.ts.snap+++ /dev/null@@ -1,33 +0,0 @@-// Jest Snapshot v1, https://goo.gl/fbAQLP--exports[`Delete instance div 1 > div 2 > [div 3] 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;--exports[`Delete instance div 1 > div 2, [div 3] 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;diff --git a/apps/designer/app/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap b/apps/designer/app/shared/tree-utils/__snapshots__/insert-instance.test.ts.snapdeleted file mode 100644index 99a82e1136..0000000000--- a/apps/designer/app/shared/tree-utils/__snapshots__/insert-instance.test.ts.snap+++ /dev/null@@ -1,90 +0,0 @@-// Jest Snapshot v1, https://goo.gl/fbAQLP--exports[`Insert instance after a nested div using "end": div 1 > div 2, [div 3] 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;--exports[`Insert instance after a nested div using index: div 1 > div 2, [div 3] 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;--exports[`Insert instance before a nested div using index: div 1 > [div 3], div 2 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;--exports[`Insert instance inside a nested div using "end": div 1 > div 2 > [div 3] 1`] = `-Object {- "children": Array [- Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;diff --git a/apps/designer/app/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap b/apps/designer/app/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snapdeleted file mode 100644index ecdb541cb2..0000000000--- a/apps/designer/app/shared/tree-utils/__snapshots__/reparent-instance.test.ts.snap+++ /dev/null@@ -1,58 +0,0 @@-// Jest Snapshot v1, https://goo.gl/fbAQLP--exports[`Reparent instance new parent 1`] = `-Object {- "children": Array [- Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "4",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;--exports[`Reparent instance same parent different position 1`] = `-Object {- "children": Array [- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "3",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "2",- },- Object {- "children": Array [],- "component": "Box",- "cssRules": Array [],- "id": "4",- },- ],- "component": "Box",- "cssRules": Array [],- "id": "1",-}-`;diff --git a/apps/designer/app/shared/tree-utils/clone-instance.test.ts b/apps/designer/app/shared/tree-utils/clone-instance.test.tsdeleted file mode 100644index 9bbc8bf24d..0000000000--- a/apps/designer/app/shared/tree-utils/clone-instance.test.ts+++ /dev/null@@ -1,42 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { cloneInstance } from "./clone-instance";--const getIds = (instance: Instance, ids: Array<Instance["id"]> = []) => {- ids.push(instance.id);- for (const child of instance.children) {- if (typeof child !== "string") getIds(child);- }- return ids;-};--describe("Clone instance", () => {- test("ensure new ids", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- },- ],- };-- const ids = getIds(instance);- const clone = cloneInstance(instance);- const clonedIds = getIds(clone);- ids.forEach((id, index) => {- expect(id).not.toBe(clonedIds[index]);- });- });-});diff --git a/apps/designer/app/shared/tree-utils/clone-instance.ts b/apps/designer/app/shared/tree-utils/clone-instance.tsdeleted file mode 100644index c3f549313b..0000000000--- a/apps/designer/app/shared/tree-utils/clone-instance.ts+++ /dev/null@@ -1,14 +0,0 @@-import ObjectId from "bson-objectid";-import produce from "immer";-import { type Instance } from "@webstudio-is/react-sdk";--const updateIds = (instance: Instance) => {- instance.id = ObjectId().toString();- for (const child of instance.children) {- if (typeof child === "string") continue;- updateIds(child);- }-};--export const cloneInstance = (instance: Instance): Instance =>- produce(updateIds)(instance);diff --git a/apps/designer/app/shared/tree-utils/create-instance.test.ts b/apps/designer/app/shared/tree-utils/create-instance.test.tsdeleted file mode 100644index 2da713f8d6..0000000000--- a/apps/designer/app/shared/tree-utils/create-instance.test.ts+++ /dev/null@@ -1,48 +0,0 @@-import { createInstance } from "./create-instance";--describe("create instance", () => {- test("instance without id should be auto generated", () => {- const createdInstance = createInstance({- component: "Box",- });-- expect(typeof createdInstance.id).toBe("string");- });-- test("instance without children should be empty by default", () => {- const createdInstance = createInstance({- component: "Box",- });- 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",- children: [- {- id: "1",- component: "Box",- cssRules: [],- children: [],- },- ],- cssRules: [],- });- expect(createdInstance.children).toEqual([- {- id: "1",- component: "Box",- cssRules: [],- children: [],- },- ]);- });-});diff --git a/apps/designer/app/shared/tree-utils/create-instance.ts b/apps/designer/app/shared/tree-utils/create-instance.tsdeleted file mode 100644index 7f02eaff37..0000000000--- a/apps/designer/app/shared/tree-utils/create-instance.ts+++ /dev/null@@ -1,30 +0,0 @@-import ObjectId from "bson-objectid";-import {- type CssRule,- type Instance,- components,-} from "@webstudio-is/react-sdk";--export const createInstanceId = () => {- return ObjectId().toString();-};--export const createInstance = ({- component,- id,- children,- cssRules,-}: {- component: Instance["component"];- id?: Instance["id"];- children?: Instance["children"];- cssRules?: Array<CssRule>;-}): Instance => {- const componentMeta = components[component];- return {- component,- id: id === undefined ? createInstanceId() : id,- cssRules: cssRules ?? [],- children: children === undefined ? componentMeta.children ?? [] : children,- };-};diff --git a/apps/designer/app/shared/tree-utils/delete-instance.test.ts b/apps/designer/app/shared/tree-utils/delete-instance.test.tsdeleted file mode 100644index 4091ffdf11..0000000000--- a/apps/designer/app/shared/tree-utils/delete-instance.test.ts+++ /dev/null@@ -1,55 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { deleteInstanceMutable } from "./delete-instance";--describe("Delete instance", () => {- test("div 1 > div 2 > [div 3]", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- },- ],- };-- deleteInstanceMutable(instance, "3");- expect(instance).toMatchSnapshot();- });-- test("div 1 > div 2, [div 3]", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- };-- deleteInstanceMutable(instance, "3");- expect(instance).toMatchSnapshot();- });-});diff --git a/apps/designer/app/shared/tree-utils/delete-instance.ts b/apps/designer/app/shared/tree-utils/delete-instance.tsdeleted file mode 100644index 6f0b3dcae6..0000000000--- a/apps/designer/app/shared/tree-utils/delete-instance.ts+++ /dev/null@@ -1,19 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";--export const deleteInstanceMutable = (- instance: Instance,- instanceId: Instance["id"]-): boolean => {- if (instance.id === instanceId) return true;-- for (const child of instance.children) {- if (typeof child === "string") continue;- const shouldDelete = deleteInstanceMutable(child, instanceId);- if (shouldDelete === true) {- const index = instance.children.indexOf(child);- instance.children.splice(index, 1);- return false;- }- }- return false;-};diff --git a/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.test.ts b/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.test.tsdeleted file mode 100644index 273abe8345..0000000000--- a/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.test.ts+++ /dev/null@@ -1,51 +0,0 @@-import { createInstance } from "./create-instance";-import { findClosestNonInlineParent } from "./find-closest-non-inline-parent";--describe("findClosestNonInlineParent", () => {- const italic = createInstance({ component: "Italic" });-- const boldWithItalic = createInstance({- component: "Bold",- children: [italic],- });-- test("when there's no non-inline parent, returns undefined", () => {- expect(- findClosestNonInlineParent(boldWithItalic, italic.id)- ).toBeUndefined();- expect(findClosestNonInlineParent(italic, italic.id)).toBeUndefined();- });-- test("when the given instance isn't in the tree, returns undefined", () => {- const root = createInstance({ component: "Body" });- expect(findClosestNonInlineParent(root, italic.id)).toBeUndefined();- });-- test("retrunrns the first non-inline parent", () => {- const root = createInstance({- component: "Body",- children: [- createInstance({- component: "Heading",- id: "the-heading",- children: [italic],- }),- ],- });- expect(findClosestNonInlineParent(root, italic.id)?.id).toBe("the-heading");- });-- test("retrunrns the first non-inline parent (nested)", () => {- const root = createInstance({- component: "Body",- children: [- createInstance({- component: "Heading",- id: "the-heading",- children: [boldWithItalic],- }),- ],- });- expect(findClosestNonInlineParent(root, italic.id)?.id).toBe("the-heading");- });-});diff --git a/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.ts b/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.tsdeleted file mode 100644index da5a74e182..0000000000--- a/apps/designer/app/shared/tree-utils/find-closest-non-inline-parent.ts+++ /dev/null@@ -1,11 +0,0 @@-import { Instance, components } from "@webstudio-is/react-sdk";-import { getInstancePath } from "./get-instance-path";--export const findClosestNonInlineParent = (- rootInstance: Instance,- instanceId: Instance["id"]-): Instance | undefined => {- const path = getInstancePath(rootInstance, instanceId);- path.reverse();- return path.find((item) => components[item.component].isInlineOnly === false);-};diff --git a/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.test.ts b/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.test.tsdeleted file mode 100644index c40bd0bb9c..0000000000--- a/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.test.ts+++ /dev/null@@ -1,42 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { findClosestSiblingInstance } from "./find-closest-sibling-instance";--describe("Find closest sibling instance", () => {- test("find", () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- "a",- {- component: "Box",- id: "4",- cssRules: [],- children: [],- },- "b",- {- component: "Box",- id: "5",- cssRules: [],- children: [],- },- ],- };-- expect(- findClosestSiblingInstance(rootInstance, "notFound")- ).toBeUndefined();- expect(findClosestSiblingInstance(rootInstance, "1")).toBeUndefined();- expect(findClosestSiblingInstance(rootInstance, "3")?.id).toBe("4");- expect(findClosestSiblingInstance(rootInstance, "4")?.id).toBe("5");- expect(findClosestSiblingInstance(rootInstance, "5")?.id).toBe("4");- });-});diff --git a/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.ts b/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.tsdeleted file mode 100644index e08cead7fb..0000000000--- a/apps/designer/app/shared/tree-utils/find-closest-sibling-instance.ts+++ /dev/null@@ -1,17 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";--export const findClosestSiblingInstance = (- instance: Instance,- instanceId: Instance["id"]-): Instance | undefined => {- if (instance.children.length === 0) return;- const children = instance.children.filter(- (instance) => typeof instance === "object"- ) as Array<Instance>;- const index = children.findIndex((instance) => instance.id === instanceId);- if (index === -1) return;- const nextInstance = children[index + 1];- if (nextInstance !== undefined) return nextInstance;- const previousInstance = children[index - 1];- return previousInstance;-};diff --git a/apps/designer/app/shared/tree-utils/find-instance.ts b/apps/designer/app/shared/tree-utils/find-instance.tsdeleted file mode 100644index c77b332305..0000000000--- a/apps/designer/app/shared/tree-utils/find-instance.ts+++ /dev/null@@ -1,19 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";--// @todo should be optimized because it will be a frequent operation on a potentially large tree.-export const findInstanceById = (- instance: Instance,- id: Instance["id"]-): Instance | undefined => {- if (instance.id === id) {- return instance;- }-- if (instance.children !== undefined) {- for (const child of instance.children) {- if (typeof child === "string") continue;- const foundInstance = findInstanceById(child, id);- if (foundInstance !== undefined) return foundInstance;- }- }-};diff --git a/apps/designer/app/shared/tree-utils/find-parent-instance.test.ts b/apps/designer/app/shared/tree-utils/find-parent-instance.test.tsdeleted file mode 100644index af14509cff..0000000000--- a/apps/designer/app/shared/tree-utils/find-parent-instance.test.ts+++ /dev/null@@ -1,31 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { findParentInstance } from "./find-parent-instance";--describe("Find parent instance", () => {- test("find", () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- },- ],- };-- expect(findParentInstance(rootInstance, "3")?.id).toBe("2");- expect(findParentInstance(rootInstance, "2")?.id).toBe("1");- expect(findParentInstance(rootInstance, "1")).toBe(undefined);- });-});diff --git a/apps/designer/app/shared/tree-utils/find-parent-instance.ts b/apps/designer/app/shared/tree-utils/find-parent-instance.tsdeleted file mode 100644index d17f7f10ef..0000000000--- a/apps/designer/app/shared/tree-utils/find-parent-instance.ts+++ /dev/null@@ -1,19 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";--export const findParentInstance = (- instance: Instance,- instanceId: Instance["id"]-): Instance | undefined => {- const find = (- childInstance: Instance,- parentInstance?: Instance- ): Instance | undefined => {- if (childInstance.id === instanceId) return parentInstance;- for (const child of childInstance.children) {- if (typeof child === "string") continue;- const foundInstance = find(child, childInstance);- if (foundInstance !== undefined) return foundInstance;- }- };- return find(instance);-};diff --git a/apps/designer/app/shared/tree-utils/get-instance-path.test.ts b/apps/designer/app/shared/tree-utils/get-instance-path.test.tsdeleted file mode 100644index c69fef0010..0000000000--- a/apps/designer/app/shared/tree-utils/get-instance-path.test.ts+++ /dev/null@@ -1,158 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import {- getInstancePath,- getInstancePathWithPositions,-} from "./get-instance-path";--const getIds = (array: Array<{ id: string }>) => array.map((item) => item.id);--describe("Get instance path", () => {- test("single possible path", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- },- ],- };- const path = getInstancePath(instance, "3");- expect(getIds(path)).toEqual(["1", "2", "3"]);- });-- test("two possible paths", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2a",- cssRules: [],- children: [- {- component: "Box",- id: "3a",- cssRules: [],- children: [],- },- ],- },- {- component: "Box",- id: "2b",- cssRules: [],- children: [- {- component: "Box",- id: "3b",- cssRules: [],- children: [],- },- ],- },- ],- };- const path1 = getInstancePath(instance, "3b");- expect(getIds(path1)).toEqual(["1", "2b", "3b"]);- const path2 = getInstancePath(instance, "3a");- expect(getIds(path2)).toEqual(["1", "2a", "3a"]);- });-});--const getIdAndPosition = (- array: Array<{ item: { id: string }; position: number }>-) => array.map((item) => [item.item.id, item.position]);--describe("Get instance path with positions", () => {- test("single possible path", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- ],- },- ],- };- const path = getInstancePathWithPositions(instance, "3");- expect(getIdAndPosition(path)).toEqual([- ["1", 0],- ["2", 0],- ["3", 0],- ]);- });-- test("two possible paths", () => {- const instance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2a",- cssRules: [],- children: [- {- component: "Box",- id: "3a",- cssRules: [],- children: [],- },- ],- },- {- component: "Box",- id: "2b",- cssRules: [],- children: [- {- component: "Box",- id: "3b",- cssRules: [],- children: [],- },- ],- },- ],- };- const path1 = getInstancePathWithPositions(instance, "3b");- expect(getIdAndPosition(path1)).toEqual([- ["1", 0],- ["2b", 1],- ["3b", 0],- ]);-- const path2 = getInstancePathWithPositions(instance, "3a");- expect(getIdAndPosition(path2)).toEqual([- ["1", 0],- ["2a", 0],- ["3a", 0],- ]);- });-});diff --git a/apps/designer/app/shared/tree-utils/get-instance-path.ts b/apps/designer/app/shared/tree-utils/get-instance-path.tsdeleted file mode 100644index 9b2600c8dc..0000000000--- a/apps/designer/app/shared/tree-utils/get-instance-path.ts+++ /dev/null@@ -1,52 +0,0 @@-import { Instance } from "@webstudio-is/react-sdk";--export const getInstancePath = (- instance: Instance,- instanceId: Instance["id"]-) => {- const path = [];-- const find = (instance: Instance) => {- if (instance.id === instanceId) return true;- for (const child of instance.children) {- if (typeof child === "string") continue;- const found = find(child);- if (found) {- path.push(child);- return true;- }- }- };-- if (find(instance)) {- path.push(instance);- }-- return path.reverse();-};--export const getInstancePathWithPositions = (- instance: Instance,- instanceId: Instance["id"]-) => {- const path = [];-- const find = (instance: Instance) => {- if (instance.id === instanceId) return true;- for (let index = 0; index < instance.children.length; index++) {- const child = instance.children[index];- if (typeof child === "string") continue;- const found = find(child);- if (found) {- path.push({ item: child, position: index });- return true;- }- }- };-- if (find(instance)) {- path.push({ item: instance, position: 0 });- }-- return path.reverse();-};diff --git a/apps/designer/app/shared/tree-utils/index.ts b/apps/designer/app/shared/tree-utils/index.tsdeleted file mode 100644index 59e0cb4158..0000000000--- a/apps/designer/app/shared/tree-utils/index.ts+++ /dev/null@@ -1,14 +0,0 @@-export * from "./create-instance";-export * from "./delete-instance";-export * from "./insert-instance";-export * from "./populate";-export * from "./find-instance";-export * from "./set-instance-style";-export * from "./set-instance-children";-export * from "./get-instance-path";-export * from "./find-closest-sibling-instance";-export * from "./find-parent-instance";-export * from "./clone-instance";-export * from "./reparent-instance";-export * from "./find-closest-non-inline-parent";-export * from "./get-css-rules";diff --git a/apps/designer/app/shared/tree-utils/insert-instance.test.ts b/apps/designer/app/shared/tree-utils/insert-instance.test.tsdeleted file mode 100644index 4562b883a8..0000000000--- a/apps/designer/app/shared/tree-utils/insert-instance.test.ts+++ /dev/null@@ -1,98 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { insertInstanceMutable } from "./insert-instance";-import { createInstance } from "./create-instance";--const instance = createInstance({ id: "3", component: "Box" });--describe("Insert instance", () => {- test(`inside a nested div using "end": div 1 > div 2 > [div 3]`, () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- ],- };-- const hasInserted = insertInstanceMutable(rootInstance, instance, {- parentId: "2",- position: "end",- });- expect(hasInserted).toBeTruthy();- expect(rootInstance).toMatchSnapshot();- });-- test("after a nested div using index: div 1 > div 2, [div 3]", () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- ],- };-- const hasInserted = insertInstanceMutable(rootInstance, instance, {- parentId: "1",- position: 1,- });- expect(hasInserted).toBeTruthy();- expect(rootInstance).toMatchSnapshot();- });-- test("before a nested div using index: div 1 > [div 3], div 2", () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- ],- };- const hasInserted = insertInstanceMutable(rootInstance, instance, {- parentId: "1",- position: 0,- });- expect(hasInserted).toBeTruthy();- expect(rootInstance).toMatchSnapshot();- });-- test(`after a nested div using "end": div 1 > div 2, [div 3]`, () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- ],- };-- const hasInserted = insertInstanceMutable(rootInstance, instance, {- parentId: "1",- position: "end",- });- expect(hasInserted).toBeTruthy();- expect(rootInstance).toMatchSnapshot();- });-});diff --git a/apps/designer/app/shared/tree-utils/insert-instance.ts b/apps/designer/app/shared/tree-utils/insert-instance.tsdeleted file mode 100644index e65f793877..0000000000--- a/apps/designer/app/shared/tree-utils/insert-instance.ts+++ /dev/null@@ -1,35 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";--export type InstanceInsertionSpec = {- parentId: Instance["id"];- position: number | "end";-};--export const insertInstanceMutable = (- rootInstance: Instance,- instance: Instance,- spec: InstanceInsertionSpec-): boolean => {- if (spec.parentId !== rootInstance.id) {- for (const child of rootInstance.children) {- if (typeof child === "string") continue;- const hasInserted = insertInstanceMutable(child, instance, spec);- if (hasInserted === true) return true;- }- return false;- }-- // Inserting inside the selected/hovered instance.- if (typeof spec.position === "number") {- rootInstance.children.splice(spec.position, 0, instance);- return true;- }-- // Inserting after all children- if (spec.position === "end") {- rootInstance.children.push(instance);- return true;- }-- return true;-};diff --git a/apps/designer/app/shared/tree-utils/populate.ts b/apps/designer/app/shared/tree-utils/populate.tsdeleted file mode 100644index 403a3e82ce..0000000000--- a/apps/designer/app/shared/tree-utils/populate.ts+++ /dev/null@@ -1,26 +0,0 @@-import {- type Instance,- type Breakpoint,- components,-} from "@webstudio-is/react-sdk";--/**- * Populate instance with:- * - defaultStyles- * @todo rewrite using immer- */-export const populateInstance = (- instance: Instance,- breakpoint: Breakpoint["id"]-): Instance => {- const populatedInstance = { ...instance };- const componentMeta = components[instance.component];- if (componentMeta !== undefined && "defaultStyle" in componentMeta) {- const cssRule = {- breakpoint,- style: componentMeta.defaultStyle ?? {},- };- populatedInstance.cssRules.push(cssRule);- }- return populatedInstance;-};diff --git a/apps/designer/app/shared/tree-utils/reparent-instance.test.ts b/apps/designer/app/shared/tree-utils/reparent-instance.test.tsdeleted file mode 100644index b5ad253864..0000000000--- a/apps/designer/app/shared/tree-utils/reparent-instance.test.ts+++ /dev/null@@ -1,67 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { reparentInstanceMutable } from "./reparent-instance";--describe("Reparent instance", () => {- test(`new parent`, () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- {- component: "Box",- id: "3",- cssRules: [],- children: [- {- component: "Box",- id: "4",- cssRules: [],- children: [],- },- ],- },- ],- };-- reparentInstanceMutable(rootInstance, "4", "2", 0);- expect(rootInstance).toMatchSnapshot();- });-- test(`same parent different position`, () => {- const rootInstance: Instance = {- component: "Box",- id: "1",- cssRules: [],- children: [- {- component: "Box",- id: "2",- cssRules: [],- children: [],- },- {- component: "Box",- id: "3",- cssRules: [],- children: [],- },- {- component: "Box",- id: "4",- cssRules: [],- children: [],- },- ],- };-- reparentInstanceMutable(rootInstance, "2", "1", 2);- expect(rootInstance).toMatchSnapshot();- });-});diff --git a/apps/designer/app/shared/tree-utils/reparent-instance.ts b/apps/designer/app/shared/tree-utils/reparent-instance.tsdeleted file mode 100644index 44345f8aba..0000000000--- a/apps/designer/app/shared/tree-utils/reparent-instance.ts+++ /dev/null@@ -1,45 +0,0 @@-import { type Instance } from "@webstudio-is/react-sdk";-import { findInstanceById } from "./find-instance";-import { findParentInstance } from "./find-parent-instance";-import { deleteInstanceMutable } from "./delete-instance";-import { insertInstanceMutable } from "./insert-instance";--export const reparentInstanceMutable = (- rootInstance: Instance,- instanceId: Instance["id"],- newParentId: Instance["id"],- newPosition: number | "end"-) => {- const instance = findInstanceById(rootInstance, instanceId);- if (instance === undefined) {- return;- }-- if (newPosition === "end") {- deleteInstanceMutable(rootInstance, instance.id);- insertInstanceMutable(rootInstance, instance, {- parentId: newParentId,- position: "end",- });- return;- }-- let newPositionAdjusted = newPosition;-- // If parent is the same, we need to adjust the position to account for the removal of the instance.- const currentParent = findParentInstance(rootInstance, instance.id);- if (currentParent !== undefined && currentParent.id === newParentId) {- const currentPosition = currentParent.children.findIndex(- (child) => typeof child !== "string" && child.id === instance.id- );- if (currentPosition < newPosition) {- newPositionAdjusted--;- }- }-- deleteInstanceMutable(rootInstance, instance.id);- insertInstanceMutable(rootInstance, instance, {- parentId: newParentId,- position: newPositionAdjusted,- });-};diff --git a/apps/designer/app/shared/tree-utils/set-instance-style.ts b/apps/designer/app/shared/tree-utils/set-instance-style.tsdeleted file mode 100644index 193bd482ec..0000000000--- a/apps/designer/app/shared/tree-utils/set-instance-style.ts+++ /dev/null@@ -1,25 +0,0 @@-import { Breakpoint, type Instance } from "@webstudio-is/react-sdk";-import { type StyleUpdates } from "~/shared/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) {- cssRule.style[update.property] = update.value;- }- return true;-};diff --git a/packages/css-data/package.json b/packages/css-data/package.jsonindex 8021032d33..487b134628 100644--- a/packages/css-data/package.json+++ b/packages/css-data/package.json@@ -12,7 +12,9 @@"build:mdn-data": "tsx ./bin/mdn-data.ts ./src","lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"},- "dependencies": {},+ "dependencies": {+ "zod": "^3.17.3"+ },"devDependencies": {"@webstudio-is/jest-config": "*","mdn-data": "2.0.23",diff --git a/packages/css-data/src/index.ts b/packages/css-data/src/index.tsindex f3a1b2bee9..01bda2c79f 100644--- a/packages/css-data/src/index.ts+++ b/packages/css-data/src/index.ts@@ -1,3 +1,4 @@export * from "./keyword-values";export * from "./properties";export * from "./units";+export * from "./schema";diff --git a/packages/react-sdk/src/css/schema.ts b/packages/css-data/src/schema.tssimilarity index 90%rename from packages/react-sdk/src/css/schema.tsrename to packages/css-data/src/schema.tsindex bc30828348..da933df1de 100644--- a/packages/react-sdk/src/css/schema.ts+++ b/packages/css-data/src/schema.ts@@ -1,6 +1,12 @@-import { units } from "@webstudio-is/css-data";+import { units } from "./units";+import { properties } from "./properties";import { z } from "zod";-import { StyleProperty } from "./types";++type Properties = typeof properties;++export type StyleProperty = keyof Properties;++export type AppliesTo = Properties[StyleProperty]["appliesTo"];export const Unit = z.union([z.enum(units), z.literal("number")]);diff --git a/packages/css-engine/package.json b/packages/css-engine/package.jsonindex 6144a149bd..e58aa13e52 100644--- a/packages/css-engine/package.json+++ b/packages/css-engine/package.json@@ -31,6 +31,7 @@"@storybook/react": "^6.5.6","@storybook/testing-library": "^0.0.13","@webstudio-is/jest-config": "*",+ "@webstudio-is/css-data": "*","tsup": "^6.1.3","typescript": "4.7.4","@types/react": "^17.0.24",diff --git a/packages/css-engine/src/core/css-engine.ts b/packages/css-engine/src/core/css-engine.tsindex f043972709..90700ef65d 100644--- a/packages/css-engine/src/core/css-engine.ts+++ b/packages/css-engine/src/core/css-engine.ts@@ -1,4 +1,4 @@-import { CssRule } from "@webstudio-is/react-sdk";+import type { CssRule } from "@webstudio-is/css-data";import {FontFaceRule,MediaRule,diff --git a/packages/css-engine/src/core/rules.ts b/packages/css-engine/src/core/rules.tsindex 46db116cf1..59a407d329 100644--- a/packages/css-engine/src/core/rules.ts+++ b/packages/css-engine/src/core/rules.ts@@ -1,8 +1,4 @@-import {- type Style,- type StyleProperty,- type StyleValue,-} from "@webstudio-is/react-sdk";+import type { Style, StyleProperty, StyleValue } from "@webstudio-is/css-data";import hyphenate from "hyphenate-style-name";import { toValue } from "./to-value";diff --git a/packages/css-engine/src/core/to-value.ts b/packages/css-engine/src/core/to-value.tsindex a87bd37773..7a0604336b 100644--- a/packages/css-engine/src/core/to-value.ts+++ b/packages/css-engine/src/core/to-value.ts@@ -1,4 +1,4 @@-import type { StyleValue } from "@webstudio-is/react-sdk";+import type { StyleValue } from "@webstudio-is/css-data";import { DEFAULT_FONT_FALLBACK, SYSTEM_FONTS } from "@webstudio-is/fonts";type ToCssOptions = {diff --git a/packages/css-engine/tsconfig.json b/packages/css-engine/tsconfig.jsonindex 26ae4e3c56..abf414ad94 100644--- a/packages/css-engine/tsconfig.json+++ b/packages/css-engine/tsconfig.json@@ -12,6 +12,10 @@},// this is auto-generated by update-ts-project-references.ts"references": [+ {+ "path": "../css-data"+ },+{"path": "../react-sdk"}diff --git a/packages/project/package.json b/packages/project/package.jsonindex 8d71161bde..239ec0da9c 100644--- a/packages/project/package.json+++ b/packages/project/package.json@@ -16,6 +16,7 @@"@webstudio-is/asset-uploader": "*","@webstudio-is/prisma-client": "*","@webstudio-is/react-sdk": "*",+ "@webstudio-is/css-data": "*","bson-objectid": "^2.0.2","immer": "^9.0.12","nanoid": "^3.2.0",diff --git a/packages/project/src/db/breakpoints.ts b/packages/project/src/db/breakpoints.tsindex e095f2a19f..056ea01d65 100644--- a/packages/project/src/db/breakpoints.ts+++ b/packages/project/src/db/breakpoints.ts@@ -1,14 +1,11 @@-import {- initialBreakpoints,- Breakpoint,- Breakpoints,-} from "@webstudio-is/react-sdk";+import { initialBreakpoints } from "@webstudio-is/react-sdk";import ObjectId from "bson-objectid";import { applyPatches, type Patch } from "immer";import {type Breakpoints as DbBreakpoints,prisma,} from "@webstudio-is/prisma-client";+import { type Breakpoint, Breakpoints } from "@webstudio-is/css-data";export const load = async (buildId: DbBreakpoints["buildId"]) => {const breakpoints = await prisma.breakpoints.findUnique({diff --git a/packages/project/src/db/build.ts b/packages/project/src/db/build.tsindex 46b0b4ca78..f80a94484b 100644--- a/packages/project/src/db/build.ts+++ b/packages/project/src/db/build.ts@@ -1,5 +1,5 @@import { prisma, Build as DbBuild } from "@webstudio-is/prisma-client";-import { type Breakpoint } from "@webstudio-is/react-sdk";+import { type Breakpoint } from "@webstudio-is/css-data";import { v4 as uuid } from "uuid";import * as db from ".";import { Build, Page, Pages } from "./types";diff --git a/packages/project/src/db/tree.ts b/packages/project/src/db/tree.tsindex e8cd8a4863..30c0e4db54 100644--- a/packages/project/src/db/tree.ts+++ b/packages/project/src/db/tree.ts@@ -1,8 +1,9 @@-import { type Breakpoint, type Tree, Instance } from "@webstudio-is/react-sdk";+import { type Tree, Instance } from "@webstudio-is/react-sdk";import { applyPatches, type Patch } from "immer";import { prisma } from "@webstudio-is/prisma-client";import { Tree as DbTree } from "@prisma/client";import { utils } from "../index";+import type { Breakpoint } from "@webstudio-is/css-data";export const createRootInstance = (breakpoints: Array<Breakpoint>) => {// Take the smallest breakpoint as defaultdiff --git a/packages/project/src/index.ts b/packages/project/src/index.tsindex aaa1997bbc..7e047cbfb8 100644--- a/packages/project/src/index.ts+++ b/packages/project/src/index.ts@@ -9,3 +9,5 @@ export const utils = {} as const;export * from "./db/types";+export * from "./shared/canvas-components";+export type { InstanceInsertionSpec } from "./shared/tree-utils";diff --git a/packages/project/src/shared/canvas-components/instance-data.ts b/packages/project/src/shared/canvas-components/instance-data.tsindex 9af88bd561..20ce1a74b8 100644--- a/packages/project/src/shared/canvas-components/instance-data.ts+++ b/packages/project/src/shared/canvas-components/instance-data.ts@@ -1,12 +1,11 @@-import {- type Instance,- type InstanceProps,- type CssRule,- type Style,- type StyleProperty,- type StyleValue,- type Breakpoint,-} from "@webstudio-is/react-sdk";+import type { Instance, InstanceProps } from "@webstudio-is/react-sdk";+import type {+ CssRule,+ Style,+ StyleProperty,+ StyleValue,+ Breakpoint,+} from "@webstudio-is/css-data";export type SelectedInstanceData = {id: Instance["id"];diff --git a/packages/project/src/shared/tree-utils/create-instance.ts b/packages/project/src/shared/tree-utils/create-instance.tsindex 00a88e0053..8995cef2bc 100644--- a/packages/project/src/shared/tree-utils/create-instance.ts+++ b/packages/project/src/shared/tree-utils/create-instance.ts@@ -1,9 +1,10 @@import ObjectId from "bson-objectid";-import {- type CssRule,- type Instance,- components,-} from "@webstudio-is/react-sdk";+import { type Instance, components } from "@webstudio-is/react-sdk";+import { CssRule } from "@webstudio-is/css-data";++export const createInstanceId = () => {+ return ObjectId().toString();+};export const createInstance = ({component,@@ -19,7 +20,7 @@ export const createInstance = ({const componentMeta = components[component];return {component,- id: id === undefined ? ObjectId().toString() : id,+ id: id === undefined ? createInstanceId() : id,cssRules: cssRules ?? [],children: children === undefined ? componentMeta.children ?? [] : children,};diff --git a/apps/designer/app/shared/tree-utils/get-css-rules.test.ts b/packages/project/src/shared/tree-utils/get-css-rules.test.tssimilarity index 100%rename from apps/designer/app/shared/tree-utils/get-css-rules.test.tsrename to packages/project/src/shared/tree-utils/get-css-rules.test.tsdiff --git a/apps/designer/app/shared/tree-utils/get-css-rules.ts b/packages/project/src/shared/tree-utils/get-css-rules.tssimilarity index 82%rename from apps/designer/app/shared/tree-utils/get-css-rules.tsrename to packages/project/src/shared/tree-utils/get-css-rules.tsindex 6baa10f63c..ece0f398f9 100644--- a/apps/designer/app/shared/tree-utils/get-css-rules.ts+++ b/packages/project/src/shared/tree-utils/get-css-rules.ts@@ -1,4 +1,5 @@-import type { CssRule, Instance } from "@webstudio-is/react-sdk";+import type { CssRule } from "@webstudio-is/css-data";+import type { Instance } from "@webstudio-is/react-sdk";const aggregateCssRules = (instance: Instance,diff --git a/packages/project/src/shared/tree-utils/index.ts b/packages/project/src/shared/tree-utils/index.tsindex da30e36aac..f31902559a 100644--- a/packages/project/src/shared/tree-utils/index.ts+++ b/packages/project/src/shared/tree-utils/index.ts@@ -10,3 +10,6 @@ export * from "./find-parent-instance";export * from "./clone-instance";export * from "./reparent-instance";export * from "./find-closest-non-inline-parent";+export * from "./get-css-rules";+export * from "./set-instance-children";+export * from "./find-instance";diff --git a/packages/project/src/shared/tree-utils/populate.ts b/packages/project/src/shared/tree-utils/populate.tsindex 4e30360c57..6da307af1e 100644--- a/packages/project/src/shared/tree-utils/populate.ts+++ b/packages/project/src/shared/tree-utils/populate.ts@@ -1,8 +1,5 @@-import {- type Instance,- type Breakpoint,- components,-} from "@webstudio-is/react-sdk";+import { Breakpoint } from "@webstudio-is/css-data";+import { type Instance, components } from "@webstudio-is/react-sdk";/*** Populate instance with:diff --git a/apps/designer/app/shared/tree-utils/set-instance-children.ts b/packages/project/src/shared/tree-utils/set-instance-children.tssimilarity index 100%rename from apps/designer/app/shared/tree-utils/set-instance-children.tsrename to packages/project/src/shared/tree-utils/set-instance-children.tsdiff --git a/packages/project/src/shared/tree-utils/set-instance-style.ts b/packages/project/src/shared/tree-utils/set-instance-style.tsindex 845dc36075..88f5ecabae 100644--- a/packages/project/src/shared/tree-utils/set-instance-style.ts+++ b/packages/project/src/shared/tree-utils/set-instance-style.ts@@ -1,5 +1,6 @@-import { Breakpoint, type Instance } from "@webstudio-is/react-sdk";-import { StyleUpdates } from "../canvas-components";+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 = (diff --git a/packages/project/tsconfig.json b/packages/project/tsconfig.jsonindex 95beb1f253..3bd05a70b5 100644--- a/packages/project/tsconfig.json+++ b/packages/project/tsconfig.json@@ -16,6 +16,10 @@"path": "../asset-uploader"},+ {+ "path": "../css-data"+ },+{"path": "../prisma-client"},diff --git a/packages/react-sdk/src/components/component-type.ts b/packages/react-sdk/src/components/component-type.tsindex 631763be77..48bf860dd0 100644--- a/packages/react-sdk/src/components/component-type.ts+++ b/packages/react-sdk/src/components/component-type.ts@@ -1,7 +1,7 @@-import type { Style } from "../css";import { z } from "zod";import React from "react";import { IconProps } from "@webstudio-is/icons";+import type { Style } from "@webstudio-is/css-data";export type WsComponentMeta<ComponentType> = {Component: ComponentType;diff --git a/packages/react-sdk/src/css/breakpoints.ts b/packages/react-sdk/src/css/breakpoints.tsindex d55ee75955..3b7357eb3b 100644--- a/packages/react-sdk/src/css/breakpoints.ts+++ b/packages/react-sdk/src/css/breakpoints.ts@@ -1,4 +1,4 @@-import { type Breakpoint } from "./schema";+import type { Breakpoint } from "@webstudio-is/css-data";export type BaseBreakpoint = Pick<Breakpoint, "label" | "minWidth">;diff --git a/packages/react-sdk/src/css/categories.ts b/packages/react-sdk/src/css/categories.tsindex 2b1e46467e..2289e58444 100644--- a/packages/react-sdk/src/css/categories.ts+++ b/packages/react-sdk/src/css/categories.ts@@ -1,4 +1,4 @@-import type { StyleProperty } from "./types";+import type { StyleProperty } from "@webstudio-is/css-data";const layout = ["display",diff --git a/packages/react-sdk/src/css/get-browser-style.ts b/packages/react-sdk/src/css/get-browser-style.tsindex aa1e378219..b38391e123 100644--- a/packages/react-sdk/src/css/get-browser-style.ts+++ b/packages/react-sdk/src/css/get-browser-style.ts@@ -1,6 +1,10 @@import { detectFont } from "detect-font";-import type { StyleProperty } from "./types";-import type { Style, StyleValue, Unit } from "./schema";+import type {+ StyleProperty,+ Style,+ StyleValue,+ Unit,+} from "@webstudio-is/css-data";import { properties, units } from "@webstudio-is/css-data";const unitRegex = new RegExp(`${units.join("|")}`);diff --git a/packages/react-sdk/src/css/index.ts b/packages/react-sdk/src/css/index.tsindex d93705b136..3802fb8bcb 100644--- a/packages/react-sdk/src/css/index.ts+++ b/packages/react-sdk/src/css/index.ts@@ -1,5 +1,3 @@-export * from "./types";-export * from "./schema";export * from "./get-browser-style";export * from "./categories";export * from "./breakpoints";diff --git a/packages/react-sdk/src/css/types.ts b/packages/react-sdk/src/css/types.tsdeleted file mode 100644index 058425582a..0000000000--- a/packages/react-sdk/src/css/types.ts+++ /dev/null@@ -1,7 +0,0 @@-import { properties } from "@webstudio-is/css-data";--type Properties = typeof properties;--export type StyleProperty = keyof Properties;--export type AppliesTo = Properties[StyleProperty]["appliesTo"];diff --git a/packages/react-sdk/src/db/instance.ts b/packages/react-sdk/src/db/instance.tsindex 3dfdda7122..2bf3904626 100644--- a/packages/react-sdk/src/db/instance.ts+++ b/packages/react-sdk/src/db/instance.ts@@ -1,6 +1,6 @@+import { CssRule } from "@webstudio-is/css-data";import { z } from "zod";import * as components from "../components";-import { CssRule } from "../css";// This should be used when passing a lot of data is potentially costly.// For example, when passing data from an iframe.diff --git a/packages/react-sdk/src/tree/root.ts b/packages/react-sdk/src/tree/root.tsindex aae3b24513..bb1841bdb6 100644--- a/packages/react-sdk/src/tree/root.ts+++ b/packages/react-sdk/src/tree/root.ts@@ -1,10 +1,10 @@import { useAllUserProps } from "../user-props/";import type { Tree, InstanceProps } from "../db";-import type { Breakpoint } from "../css";import { createElementsTree } from "./create-elements-tree";import { WrapperComponent } from "./wrapper-component";import type { Asset } from "@webstudio-is/asset-uploader";import { type ComponentProps } from "react";+import type { Breakpoint } from "@webstudio-is/css-data";export type Data = {tree: Tree | null;