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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Skip empty combo class when pasting from webflow (#3755)
Oleg Isonen30c760014321
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsxindex 8e81dcd004..78dce0d89f 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx@@ -2597,7 +2597,7 @@ describe("Styles", () => {type: "class",name: "is-small",comb: "&",- styleLess: "",+ styleLess: "padding: 1rem;",},{_id: "194e7d07-469d-6ffa-3925-1f51bdad7e46",@@ -2648,7 +2648,92 @@ describe("Styles", () => {}button.is-small.is-secondary {text-align: center;- background-color: transparent+ background-color: transparent;+ padding: 1rem+ }+ }"+ `);+ });++ test("Skip empty combo class", async () => {+ const fragment = await toWebstudioFragment({+ type: "@webflow/XscpData",+ payload: {+ nodes: [+ {+ _id: "56ede23d-6dcc-a320-0af4-3a803d8efd88",+ type: "Block",+ tag: "div",+ classes: ["08c3532a-4e88-1106-9fda-e4dcd66f93f0"],+ children: [+ "d06c01f8-da59-b31e-a910-55a6d33898f0",+ "b67fb4c4-ce52-b441-1d89-55b165282c99",+ ],+ },+ {+ _id: "d06c01f8-da59-b31e-a910-55a6d33898f0",+ type: "Block",+ tag: "div",+ classes: ["6569b562-7de4-bd09-3d2d-59d7c11ec988"],+ children: [],+ },+ {+ _id: "b67fb4c4-ce52-b441-1d89-55b165282c99",+ type: "Block",+ tag: "div",+ classes: [+ "08c3532a-4e88-1106-9fda-e4dcd66f93f0",+ "c4851546-799d-c6bf-fb17-0b5765f48d72",+ ],+ children: [],+ },+ ],+ styles: [+ {+ _id: "08c3532a-4e88-1106-9fda-e4dcd66f93f0",+ fake: false,+ type: "class",+ name: "d1",+ namespace: "",+ comb: "",+ styleLess: "color: hsla(0, 70.45%, 48.11%, 1.00);",+ variants: {},+ children: ["c4851546-799d-c6bf-fb17-0b5765f48d72"],+ },+ {+ _id: "6569b562-7de4-bd09-3d2d-59d7c11ec988",+ fake: false,+ type: "class",+ name: "d2",+ namespace: "",+ comb: "",+ styleLess: "font-size: 200px;",+ variants: {},+ children: [],+ },+ {+ _id: "c4851546-799d-c6bf-fb17-0b5765f48d72",+ fake: false,+ type: "class",+ name: "d2",+ namespace: "",+ comb: "&",+ styleLess: "",+ variants: {},+ children: [],+ },+ ],+ assets: [],+ },+ });++ expect(toCss(fragment)).toMatchInlineSnapshot(`+ "@media all {+ d1 {+ color: rgba(209, 36, 36, 1)+ }+ d2 {+ font-size: 200px}}"`);diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.tsindex e6fc623df8..0d8bdc05fb 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts@@ -441,17 +441,28 @@ const mapComponentAndPresetStyles = (// Checks if a style source with that name already exists and the new one has new styles and is not empty - if so, adds a number to a name.const mergeComboStyles = (wfStyles: Array<WfStyle>) => {const classes = new Set<string>();+ const skip = new Set<string>();let mergedStyle;for (const wfStyle of wfStyles) {const { name } = wfStyle;classes.add(name);+if (mergedStyle === undefined) {mergedStyle = { variants: {}, ...wfStyle, name };continue;}++ const comboClass = mergedStyle.name + "." + name;++ // We need to avoid creating combo classes when they have no additional styles.+ if (wfStyle.comb === "&" && wfStyle.styleLess === "") {+ skip.add(comboClass);+ continue;+ }+mergedStyle.styleLess += wfStyle.styleLess;- mergedStyle.name += "." + name;+ mergedStyle.name = comboClass;for (const key in wfStyle.variants) {if (key in mergedStyle.variants === false) {mergedStyle.variants[key] = { styleLess: "" };@@ -464,9 +475,9 @@ const mergeComboStyles = (wfStyles: Array<WfStyle>) => {// Produce all possible combinations of combo classes so we can check later if they alredy exist.// This is needed to achieve the same end-result as with combo-classes in webflow.// Example .a.b.c -> .a, .b, .c, .a.b, .a.c, .b.c, .a.b.c- const comboClasses = classesArray.flatMap((name1) =>- classesArray.map((name2) => `${name1}.${name2}`)- );+ const comboClasses = classesArray+ .flatMap((name1) => classesArray.map((name2) => `${name1}.${name2}`))+ .filter((name) => skip.has(name) === false);return {mergedStyle,