From 611174a044edde87bcd0ea94a8656d7934d54d44 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 5 Sep 2024 16:25:38 +0200 Subject: [PATCH] experimental: migrate size section to style object model (#4073) Ref https://github.com/webstudio-is/webstudio/issues/1536 https://github.com/webstudio-is/webstudio/issues/3399 Most changes is object position switching to new style engine. Screenshot 2024-09-05 at 15 58 13 --- .../controls/position/position-control.tsx | 40 +++++++-------- .../style-panel/sections/size/size.tsx | 50 ++++--------------- 2 files changed, 27 insertions(+), 63 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx index 7c2fb86603..6dbff953db 100644 --- a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx +++ b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx @@ -1,15 +1,19 @@ import { propertyDescriptions } from "@webstudio-is/css-data"; import { TupleValue, - type StyleValue, TupleValueItem, + type StyleValue, + type StyleProperty, } from "@webstudio-is/css-engine"; import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system"; -import type { ControlProps } from "../types"; +import type { ComputedStyleDecl } from "~/shared/style-object-model"; import { styleConfigByName } from "../../shared/configs"; -import { getStyleSource } from "../../shared/style-info"; import { CssValueInputContainer } from "../../shared/css-value-input"; -import type { SetValue } from "../../shared/use-style-data"; +import { + deleteProperty, + setProperty, + type SetValue, +} from "../../shared/use-style-data"; import { PropertyInlineLabel } from "../../property-label"; const toPosition = (value: TupleValue) => { @@ -46,16 +50,14 @@ const toTuple = ( }; export const PositionControl = ({ - currentStyle, property, - setProperty, - deleteProperty, - isAdvanced, -}: ControlProps) => { + styleDecl, +}: { + property: StyleProperty; + styleDecl: ComputedStyleDecl; +}) => { const { items } = styleConfigByName(property); - const styleInfo = currentStyle[property]; - const value = toTuple(styleInfo?.value); - const styleSource = getStyleSource(styleInfo); + const value = toTuple(styleDecl.cascadedValue); const keywords = items.map((item) => ({ type: "keyword" as const, value: item.name, @@ -82,7 +84,6 @@ export const PositionControl = ({ } properties={[property]} /> - @@ -108,31 +107,26 @@ export const PositionControl = ({ description="Left position offset" properties={[property]} /> - - - diff --git a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx index f1dd703590..c480f01bb9 100644 --- a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx @@ -7,13 +7,7 @@ import { Separator, styled, } from "@webstudio-is/design-system"; -import type { SectionProps } from "../shared/section"; -import { - PositionControl, - SelectControl, - TextControl, - type ControlProps, -} from "../../controls"; +import { PositionControl, SelectControl, TextControl } from "../../controls"; import { EyeconOpenIcon, EyeconClosedIcon, @@ -24,10 +18,11 @@ import { import { StyleSection } from "../../shared/style-section"; import { theme } from "@webstudio-is/design-system"; import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control"; -import { getStyleSourceColor } from "../../shared/style-info"; import { FloatingPanel } from "~/builder/shared/floating-panel"; import { humanizeString } from "~/shared/string-utils"; import { PropertyLabel } from "../../property-label"; +import { useComputedStyleDecl } from "../../shared/model"; +import { deleteProperty } from "../../shared/use-style-data"; const SizeProperty = ({ property }: { property: StyleProperty }) => { return ( @@ -44,40 +39,24 @@ const SizeProperty = ({ property }: { property: StyleProperty }) => { ); }; -const ObjectPosition = ({ - property, - currentStyle, - setProperty, - deleteProperty, - isAdvanced, -}: ControlProps) => { - const styleSourceColor = getStyleSourceColor({ - properties: [property], - currentStyle, - }); - +const ObjectPosition = () => { + const styleDecl = useComputedStyleDecl("objectPosition"); return ( - + } > { if (event.altKey) { event.preventDefault(); - deleteProperty(property); + deleteProperty("objectPosition"); } }} > @@ -108,11 +87,7 @@ const SectionLayout = styled(Grid, { px: theme.spacing[9], }); -export const Section = ({ - currentStyle, - setProperty, - deleteProperty, -}: SectionProps) => { +export const Section = () => { return ( @@ -178,12 +153,7 @@ export const Section = ({ description={propertyDescriptions.objectPosition} properties={["objectPosition"]} /> - + );