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.

experimental: preview css variables on highlight in combobox (#4224)

Bogdan Chadkin26d7e041c338
diff --git a/apps/builder/app/canvas/shared/styles.ts b/apps/builder/app/canvas/shared/styles.ts
index f91ff87c46..2e27ceb4b4 100644
--- a/apps/builder/app/canvas/shared/styles.ts
+++ b/apps/builder/app/canvas/shared/styles.ts
@@ -20,7 +20,6 @@ import {
import {
type VarValue,
createRegularStyleSheet,
- isValidStaticStyleValue,
toValue,
} from "@webstudio-is/css-engine";
import {
@@ -148,20 +147,14 @@ const getEphemeralProperty = (styleDecl: StyleDecl) => {
// between all token usages
const toVarValue = (styleDecl: StyleDecl): undefined | VarValue => {
const { value } = styleDecl;
- if (value.type === "var") {
- return value;
- }
- // Values like InvalidValue, UnsetValue, VarValue don't need to be wrapped
- if (isValidStaticStyleValue(value)) {
- return {
- type: "var",
- // var style value is relying on name without leading "--"
- // escape complex selectors in state like ":hover"
- // setProperty and removeProperty escape automatically
- value: CSS.escape(getEphemeralProperty(styleDecl).slice(2)),
- fallback: { type: "unparsed", value: toValue(value) },
- };
- }
+ return {
+ type: "var",
+ // var style value is relying on name without leading "--"
+ // escape complex selectors in state like ":hover"
+ // setProperty and removeProperty escape automatically
+ value: CSS.escape(getEphemeralProperty(styleDecl).slice(2)),
+ fallback: { type: "unparsed", value: toValue(value) },
+ };
};
const $descendantSelectors = computed(
diff --git a/packages/css-engine/src/schema.ts b/packages/css-engine/src/schema.ts
index f90be7ca39..47fe0ef29a 100644
--- a/packages/css-engine/src/schema.ts
+++ b/packages/css-engine/src/schema.ts
@@ -151,45 +151,6 @@ export const LayersValue = z.object({
export type LayersValue = z.infer<typeof LayersValue>;
-const ValidStaticStyleValue = z.union([
- ImageValue,
- LayersValue,
- UnitValue,
- KeywordValue,
- FontFamilyValue,
- RgbValue,
- UnparsedValue,
- TupleValue,
- FunctionValue,
- GuaranteedInvalidValue,
-]);
-
-export type ValidStaticStyleValue = z.infer<typeof ValidStaticStyleValue>;
-
-/**
- * All StyleValue types that going to need wrapping into a CSS variable when rendered
- * on canvas inside builder.
- * Values like InvalidValue, UnsetValue, VarValue don't need to be wrapped
- */
-export const isValidStaticStyleValue = (
- styleValue: StyleValue
-): styleValue is ValidStaticStyleValue => {
- // guard against invalid checks
- const staticStyleValue = styleValue as ValidStaticStyleValue;
- return (
- staticStyleValue.type === "image" ||
- staticStyleValue.type === "layers" ||
- staticStyleValue.type === "unit" ||
- staticStyleValue.type === "keyword" ||
- staticStyleValue.type === "fontFamily" ||
- staticStyleValue.type === "rgb" ||
- staticStyleValue.type === "unparsed" ||
- staticStyleValue.type === "tuple" ||
- staticStyleValue.type === "function" ||
- staticStyleValue.type === "guaranteedInvalid"
- );
-};
-
export const VarFallback = z.union([UnparsedValue, KeywordValue]);
export type VarFallback = z.infer<typeof VarFallback>;
@@ -202,7 +163,16 @@ const VarValue = z.object({
export type VarValue = z.infer<typeof VarValue>;
export const StyleValue = z.union([
- ValidStaticStyleValue,
+ ImageValue,
+ LayersValue,
+ UnitValue,
+ KeywordValue,
+ FontFamilyValue,
+ RgbValue,
+ UnparsedValue,
+ TupleValue,
+ FunctionValue,
+ GuaranteedInvalidValue,
InvalidValue,
UnsetValue,
VarValue,