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.

Do not show flex properties in style panel when layout is not flex (#722)

Ivan Starkovd73ec1b45907
diff --git a/apps/designer/app/designer/features/style-panel/shared/dependencies.ts b/apps/designer/app/designer/features/style-panel/shared/dependencies.ts
index fee57c247a..90a3a8326b 100644
--- a/apps/designer/app/designer/features/style-panel/shared/dependencies.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/dependencies.ts
@@ -31,18 +31,26 @@ export const dependencies: Dependencies = {
},
flexContainers: {
property: "display",
- values: ["flex"],
+ values: ["flex", "inline-flex"],
},
// @todo this should actually check on parent
flexItemsAndInFlowPseudos: {
property: "display",
- values: ["flex"],
+ values: ["flex", "inline-flex"],
},
// @todo needs to also check flex-wrap
multilineFlexContainers: {
property: "flexWrap",
values: ["wrap", "wrap-reverse"],
},
+ multiColumnElementsFlexContainersGridContainers: {
+ property: "display",
+ values: ["flex", "inline-flex", "grid"],
+ },
+ flexContainersGridContainers: {
+ property: "display",
+ values: ["flex", "inline-flex", "grid"],
+ },
// Used by alignSelf
// @todo needs to check parent to be display: flex or grid, position: absolute
diff --git a/apps/designer/app/designer/features/style-panel/style-settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsx
index f0fa646d4d..5b127756c3 100644
--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx
@@ -58,6 +58,7 @@ const appliesTo = (
currentStyle: StyleInfo
): boolean => {
const { appliesTo } = styleConfig;
+
if (appliesTo in dependencies) {
const dependency = dependencies[appliesTo];
if (dependency === undefined) {
diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.ts
index 38f01a5d2d..f8f12cbc0d 100755
--- a/packages/css-data/bin/mdn-data.ts
+++ b/packages/css-data/bin/mdn-data.ts
@@ -102,6 +102,25 @@ const propertiesData: {
};
} = {};
+const patchAppliesTo = (property: Property, config: Value) => {
+ // see https://github.com/mdn/data/issues/585 alignItems and justifyItems have appliesTo = "allElements"
+ // this specification https://www.w3.org/TR/css-align-3/ - "block containers", "grid containers", "flex containers"
+ // chrome devtools check grid or flex here https://github.com/ChromeDevTools/devtools-frontend/blob/354fb0fd3fc0a4af43ef760450e7d644d0e04daf/front_end/panels/elements/CSSRuleValidator.ts#L374
+ // our opinion is that it must be "grid containers", "flex containers"
+ if (property === "align-items" || property === "justify-items") {
+ if (config.appliesto !== "allElements") {
+ throw new Error(
+ "Specification has changed, please check and update the code"
+ );
+ }
+
+ // flexContainersGridContainers not exists in mdn-data, it's our custom value
+ return "flexContainersGridContainers";
+ }
+
+ return config.appliesto;
+};
+
let property: Property;
for (property in filteredProperties) {
@@ -141,7 +160,8 @@ for (property in filteredProperties) {
popularity:
popularityIndex.find((data) => data.property === property)
?.dayPercentage || 0,
- appliesTo: config.appliesto,
+
+ appliesTo: patchAppliesTo(property, config),
};
}
@@ -176,7 +196,9 @@ const keywordValues = (() => {
// When there is syntax - there are keyword references
if (syntax) {
- if (parsedSyntaxes.has(syntax)) return parsedSyntaxes.get(syntax);
+ if (parsedSyntaxes.has(syntax)) {
+ return parsedSyntaxes.get(syntax);
+ }
const ast = definitionSyntax.parse(syntax);
definitionSyntax.walk(ast, (node) => {
keywords = new Set([...keywords, ...getKeywords(node)]);
diff --git a/packages/css-data/src/__generated__/keyword-values.ts b/packages/css-data/src/__generated__/keyword-values.ts
index b745c19056..6c1be388c9 100644
--- a/packages/css-data/src/__generated__/keyword-values.ts
+++ b/packages/css-data/src/__generated__/keyword-values.ts
@@ -1,4 +1,4 @@
-// This file was generated by yarn mdn-data
+// This file was generated by pnpm mdn-data
export const keywordValues = {
accentColor: [
"auto",
diff --git a/packages/css-data/src/__generated__/properties.ts b/packages/css-data/src/__generated__/properties.ts
index 9ce5f8dfd4..6b4143bd7e 100644
--- a/packages/css-data/src/__generated__/properties.ts
+++ b/packages/css-data/src/__generated__/properties.ts
@@ -1,4 +1,4 @@
-// This file was generated by yarn mdn-data
+// This file was generated by pnpm mdn-data
export const properties = {
accentColor: {
inherited: true,
@@ -25,7 +25,7 @@ export const properties = {
value: "normal",
},
popularity: 0.71654912,
- appliesTo: "allElements",
+ appliesTo: "flexContainersGridContainers",
},
alignSelf: {
inherited: false,
@@ -1486,7 +1486,7 @@ export const properties = {
value: "legacy",
},
popularity: 0.05716411,
- appliesTo: "allElements",
+ appliesTo: "flexContainersGridContainers",
},
justifySelf: {
inherited: false,
diff --git a/packages/css-data/src/__generated__/units.ts b/packages/css-data/src/__generated__/units.ts
index a733273860..6fb8a4f2f4 100644
--- a/packages/css-data/src/__generated__/units.ts
+++ b/packages/css-data/src/__generated__/units.ts
@@ -1,4 +1,4 @@
-// This file was generated by yarn mdn-data
+// This file was generated by pnpm mdn-data
export const units = [
"ch",
"cm",