Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

refactor type assertions

Sultanebf59bf217fd
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.tsx
index bbd3d78cc6..f92544cf75 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
@@ -54,9 +54,10 @@ export const useUnitSelect = ({
const [isOpen, setIsOpen] = useState(false);
const renderUnits = useMemo(
() =>
+ value &&
units
.filter((unit) => {
- return isValid(property, toValue({ ...value, unit } as typeof value));
+ return isValid(property, toValue({ ...value, unit }));
})
.map((unit) => unitRenderMap.get(unit) ?? unit),
[units, property, value]
@@ -64,7 +65,11 @@ export const useUnitSelect = ({
const renderValue = value && unitRenderMap.get(value.unit);
- if (value == undefined || renderValue === undefined) {
+ if (
+ value === undefined ||
+ renderUnits == undefined ||
+ renderValue === undefined
+ ) {
return [isOpen, null];
}
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.ts
index 9e4e229ac3..ccdf9d8ce1 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
@@ -3,7 +3,6 @@ import {
StyleValue,
StyleProperty,
toValue,
- InvalidValue,
} from "@webstudio-is/react-sdk";
import type { InheritedStyle } from "./get-inherited-style";
import { isValid } from "./parse-css-value";
@@ -32,7 +31,7 @@ export const getFinalValue = ({
toValue({ ...currentValue, value: Math.abs(currentValue.value) })
) === false
) {
- return { ...(currentValue as unknown as InvalidValue), type: "invalid" };
+ return { value: String(currentValue.value), type: "invalid" };
}
return currentValue;
};
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.ts
index 52e592d854..8ede09de52 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
@@ -2,9 +2,7 @@ import hyphenate from "hyphenate-style-name";
import { units } from "@webstudio-is/react-sdk";
import type { StyleProperty, StyleValue, Unit } from "@webstudio-is/react-sdk";
-const unitRegex = new RegExp(
- `${(units as unknown as string[]).concat("number").join("|")}`
-);
+const unitRegex = new RegExp(`${[...units, "number"].join("|")}`);
export const isValid = (property: string, value: string): boolean => {
// Only browsers with houdini api will provide validation for now