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
Drop getFinalValue (#699)
Bogdan Chadkinb6a1688d4444
diff --git a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsxindex 28885f80b0..4bc47ae958 100644--- a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx@@ -1,6 +1,5 @@import { Flex } from "@webstudio-is/design-system";import { toValue } from "@webstudio-is/css-engine";-import { getFinalValue } from "../../shared/get-final-value";import type { ControlProps } from "../../style-sections";import { ColorPicker } from "../../shared/color-picker";import { colord } from "colord";@@ -10,10 +9,7 @@ export const ColorControl = ({setProperty,styleConfig,}: ControlProps) => {- let value = getFinalValue({- currentStyle,- property: styleConfig.property,- }) ?? {+ let value = currentStyle[styleConfig.property] ?? {// provide default value to avoid control hiding// when value is recomputedtype: "rgb" as const,diff --git a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsxindex 8a200cb23f..e27431fe68 100644--- a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx@@ -1,7 +1,6 @@import { TextField } from "@webstudio-is/design-system";import { FontsManager } from "~/designer/shared/fonts-manager";import type { ControlProps } from "../../style-sections";-import { getFinalValue } from "../../shared/get-final-value";import { FloatingPanel } from "~/designer/shared/floating-panel";import { useState } from "react";import { toValue } from "@webstudio-is/css-engine";@@ -11,11 +10,7 @@ export const FontFamilyControl = ({setProperty,styleConfig,}: ControlProps) => {- // @todo show which instance we inherited the value from- const value = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const value = currentStyle[styleConfig.property];const [isOpen, setIsOpen] = useState(false);const setValue = setProperty(styleConfig.property);diff --git a/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsxindex 27986c1458..4bb44844b2 100644--- a/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx@@ -3,7 +3,6 @@ import { FontWeight, fontWeights } from "@webstudio-is/fonts";import { toValue } from "@webstudio-is/css-engine";import { useMemo } from "react";import { useAssets } from "~/designer/shared/assets";-import { getFinalValue } from "../../shared/get-final-value";import type { ControlProps } from "../../style-sections";type FontWeightItem = {@@ -72,17 +71,10 @@ export const FontWeightControl = ({setProperty,styleConfig,}: ControlProps) => {- // @todo show which instance we inherited the value from- const fontWeight = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const fontWeight = currentStyle[styleConfig.property];// We need the font family to determine which font weights are available- const fontFamily = getFinalValue({- currentStyle,- property: "fontFamily",- });+ const fontFamily = currentStyle.fontFamily;const availableFontWeights = useAvailableFontWeights(toValue(fontFamily, { withFallback: false })diff --git a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx b/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsxindex a4c8e3f0cc..7be6455b5b 100644--- a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx@@ -1,6 +1,5 @@import { TextField } from "@webstudio-is/design-system";import type { ControlProps } from "../../style-sections";-import { getFinalValue } from "../../shared/get-final-value";import { FloatingPanel } from "~/designer/shared/floating-panel";import { ImageManager } from "~/designer/shared/image-manager";import { useAssets } from "~/designer/shared/assets";@@ -12,11 +11,7 @@ export const ImageControl = ({styleConfig,}: ControlProps) => {const { assetContainers } = useAssets("image");- // @todo show which instance we inherited the value from- const value = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const value = currentStyle[styleConfig.property];if (value === undefined) {return null;diff --git a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsxindex 58e535ff0e..c6969a8a87 100644--- a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx@@ -1,5 +1,4 @@import { IconButtonWithMenu } from "@webstudio-is/design-system";-import { getFinalValue } from "../../shared/get-final-value";import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";import type { ControlProps } from "../../style-sections";import { iconConfigs } from "../../shared/configs";@@ -10,10 +9,7 @@ export const MenuControl = ({setProperty,styleConfig,}: ControlProps) => {- const value = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const value = currentStyle[styleConfig.property];const isFromCurrentBreakpoint = useIsFromCurrentBreakpoint(styleConfig.property);diff --git a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsxindex d74075ec44..138f9fe38a 100644--- a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx@@ -1,6 +1,5 @@import { toValue } from "@webstudio-is/css-engine";import { Select } from "@webstudio-is/design-system";-import { getFinalValue } from "../../shared/get-final-value";import type { ControlProps } from "../../style-sections";export const SelectControl = ({@@ -8,11 +7,7 @@ export const SelectControl = ({setProperty,styleConfig,}: ControlProps) => {- // @todo show which instance we inherited the value from- const value = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const value = currentStyle[styleConfig.property];const setValue = setProperty(styleConfig.property);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 6565d23394..ed29a82ad2 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@@ -2,7 +2,6 @@ import {CssValueInput,type IntermediateStyleValue,} from "../../shared/css-value-input";-import { getFinalValue } from "../../shared/get-final-value";import { ControlProps } from "../../style-sections";import type { StyleValue } from "@webstudio-is/css-data";import { useState } from "react";@@ -15,10 +14,7 @@ export const TextControl = ({styleConfig,icon,}: ControlProps & { icon?: JSX.Element }) => {- const value = getFinalValue({- currentStyle,- property: styleConfig.property,- });+ const value = currentStyle[styleConfig.property];const setValue = setProperty(styleConfig.property);diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsxindex e413fdf754..c6ed754723 100644--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx@@ -7,7 +7,6 @@ import { renderProperty } from "../../style-sections";import { MenuControl, SelectControl, TextControl } from "../../controls";import { PropertyName } from "../../shared/property-name";import { ColumnGapIcon, RowGapIcon } from "@webstudio-is/icons";-import { getFinalValue } from "../../shared/get-final-value";const LayoutSectionFlex = ({currentStyle,@@ -37,10 +36,7 @@ const LayoutSectionFlex = ({alignContent,].some((config) => config !== undefined);- const flexWrapValue = getFinalValue({- currentStyle: flexWrap.currentStyle,- property: flexWrap.styleConfig.property,- });+ const flexWrapValue = flexWrap.currentStyle[flexWrap.styleConfig.property];// From design: Notice that the align-content icon button is not visible by default.// This property only applies when flex-wrap is set to "wrap".diff --git a/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx b/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsxindex 8c7fa92a80..3392f0d5b1 100644--- a/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx@@ -1,8 +1,6 @@-import type { UnitValue } from "@webstudio-is/css-data";+import type { StyleValue, UnitValue } from "@webstudio-is/css-data";import { numericScrubControl } from "@webstudio-is/design-system";import { useState, useEffect, useRef } from "react";-import { getFinalValue } from "../../shared/get-final-value";-import type { RenderCategoryProps } from "../../style-sections";import type {StyleChangeHandler,SpacingStyleProperty,@@ -14,7 +12,7 @@ type ScrubStatus =| { isActive: true; property: SpacingStyleProperty; value: UnitValue };export const useScrub = (props: {- currentStyle: RenderCategoryProps["currentStyle"];+ value?: StyleValue;target: HoverTagret | undefined;onChange: StyleChangeHandler;}): ScrubStatus => {@@ -43,11 +41,7 @@ export const useScrub = (props: {? "horizontal": "vertical",getValue() {- const { currentStyle } = latestProps.current;- const value = getFinalValue({- property: property,- currentStyle,- });+ const { value } = latestProps.current;if (value?.type === "unit") {unitRef.current = value.unit;return value.value;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 ba593e488b..62607991a9 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,5 +1,4 @@import { useState } from "react";-import { getFinalValue } from "../../shared/get-final-value";import { useIsFromCurrentBreakpoint } from "../../shared/use-is-from-current-breakpoint";import type { RenderCategoryProps } from "../../style-sections";import { SpacingLayout } from "./layout";@@ -34,10 +33,7 @@ const Cell = ({}) => {const isFromCurrentBreakpoint = useIsFromCurrentBreakpoint(property);- const styleValue = getFinalValue({- property,- currentStyle,- });+ const styleValue = currentStyle[property];const finalValue = scrubStatus.isActive ? scrubStatus.value : styleValue;@@ -96,9 +92,12 @@ export const SpacingSection = ({};const scrubStatus = useScrub({+ value:+ hoverTarget === undefined+ ? undefined+ : currentStyle[hoverTarget.property],target: hoverTarget,onChange: handleChange,- currentStyle,});const [openProperty, setOpenProperty] = useState<SpacingStyleProperty>();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.tsdeleted file mode 100644index 875cb2a97c..0000000000--- a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts+++ /dev/null@@ -1,35 +0,0 @@-import type { Style, StyleValue, StyleProperty } from "@webstudio-is/css-data";-import { toValue } from "@webstudio-is/css-engine";-import { isValid } from "./parse-css-value";--export const isNumericString = (input: string) =>- String(input).trim().length !== 0 && isNaN(Number(input)) === false;--// @todo expose which instance we inherited the value from-export const getFinalValue = ({- currentStyle,- property,-}: {- currentStyle: Style;- property: StyleProperty;-}): StyleValue | undefined => {- const currentValue = currentStyle[property];- if (currentValue?.type !== "unit" && isNumericString(toValue(currentValue))) {- return {- value: Number(toValue(currentValue)),- type: "unit",- unit: "number",- };- }- if (- currentValue &&- currentValue.type === "unit" &&- isValid(- property,- toValue({ ...currentValue, value: Math.abs(currentValue.value) })- ) === false- ) {- return { value: String(currentValue.value), type: "invalid" };- }- return currentValue;-};