From 2cdd3fc89325619e4595169fbba26a9ffdfc0537 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Tue, 11 Feb 2025 13:06:34 +0000 Subject: [PATCH] code review --- .../sections/advanced/advanced.tsx | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx index d1cceffd1c18..f6877c2a4423 100644 --- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx @@ -42,6 +42,7 @@ import { propertyDescriptions, } from "@webstudio-is/css-data"; import { + cssWideKeywords, hyphenateProperty, toValue, type StyleProperty, @@ -126,30 +127,28 @@ const getAutocompleteItems = () => { if (autoCompleteItems.length > 0) { return autoCompleteItems; } - Object.keys(propertiesData).forEach((property) => { + for (const property in propertiesData) { autoCompleteItems.push({ property, label: hyphenateProperty(property), }); - }); + } - const ignoreValues = ["inherit", "initial", "unset", ...keywordValues.color]; + const ignoreValues = new Set([...cssWideKeywords, ...keywordValues.color]); - (Object.keys(keywordValues) as Array).forEach( - (property) => { - const values = keywordValues[property]; - for (const value of values) { - if (ignoreValues.includes(value)) { - continue; - } - autoCompleteItems.push({ - property, - value, - label: `${hyphenateProperty(property)}: ${value}`, - }); + for (const property in keywordValues) { + const values = keywordValues[property as keyof typeof keywordValues]; + for (const value of values) { + if (ignoreValues.has(value)) { + continue; } + autoCompleteItems.push({ + property, + value, + label: `${hyphenateProperty(property)}: ${value}`, + }); } - ); + } autoCompleteItems.sort((a, b) => Intl.Collator().compare(a.property, b.property) @@ -253,7 +252,7 @@ const AddProperty = forwardRef< onChange: (value) => setItem({ property: value ?? "", label: value ?? "" }), onItemSelect: (item) => { clear(); - return onSubmit(`${item.property}: ${item.value ?? "unset"}`); + onSubmit(`${item.property}: ${item.value ?? "unset"}`); }, }); @@ -273,7 +272,7 @@ const AddProperty = forwardRef< } if (event.key === "Enter") { clear(); - onSubmit(`${item.property}`); + onSubmit(item.property); return; } if (event.key === "Escape") {