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.

fix: autocomplete properties with invalid values (#5118)

Bogdan Chadkin8fbda555e5a6
diff --git a/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts b/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
index 8816aef283..7f815c5f6e 100644
--- a/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
+++ b/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
@@ -87,4 +87,11 @@ describe("parseStyleInput", () => {
new Map([["color", { type: "keyword", value: "red" }]])
);
});
+
+ test("output property with invalid value", () => {
+ const result = parseStyleInput("rotate: z 0;");
+ expect(result).toEqual(
+ new Map([["rotate", { type: "invalid", value: "z 0" }]])
+ );
+ });
});
diff --git a/apps/builder/app/builder/shared/css-editor/parse-style-input.ts b/apps/builder/app/builder/shared/css-editor/parse-style-input.ts
index 4266fcc4fe..68e193697c 100644
--- a/apps/builder/app/builder/shared/css-editor/parse-style-input.ts
+++ b/apps/builder/app/builder/shared/css-editor/parse-style-input.ts
@@ -43,24 +43,20 @@ const ensureValue = (css: string) => {
*/
export const parseStyleInput = (css: string): CssStyleMap => {
css = ensureValue(css);
-
const styles = parseCss(`selector{${css}}`);
-
const styleMap: CssStyleMap = new Map();
-
for (const { property, value } of styles) {
+ if (property.startsWith("--")) {
+ styleMap.set(property, value);
+ continue;
+ }
// somethingunknown: red; -> --somethingunknown: red;
- if (
- // Note: currently in tests it returns unparsed, but in the client it returns invalid,
- // because we use native APIs when available in parseCss.
- value.type === "invalid" ||
- (value.type === "unparsed" && property.startsWith("--") === false)
- ) {
+ if (propertiesData[property] === undefined) {
styleMap.set(`--${property}`, value);
- } else {
- // @todo This should be returning { type: "guaranteedInvalid" }
- styleMap.set(property, value);
+ continue;
}
+ // @todo This should be returning { type: "guaranteedInvalid" }
+ styleMap.set(property, value);
}
return styleMap;
};