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: Paste from webflow 9 (#3602)

Oleg Isonen25d72a11ffff
diff --git a/apps/builder/app/builder/shared/assets/use-assets.tsx b/apps/builder/app/builder/shared/assets/use-assets.tsx
index 31804d9503..574b7b3632 100644
--- a/apps/builder/app/builder/shared/assets/use-assets.tsx
+++ b/apps/builder/app/builder/shared/assets/use-assets.tsx
@@ -396,7 +396,7 @@ export async function uploadAssets(
toast.warn(
<ToastMessage
- title="Warning"
+ title="Info"
assetId={fileData.assetId}
objectURL={fileData.objectURL}
>
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
index 1f62670cd2..c38555baa9 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/__generated__/style-presets.ts
@@ -3,15 +3,7 @@
export const styles = {
html: [
{
- property: "webkitTextSizeAdjust",
- value: {
- type: "unit",
- unit: "%",
- value: 100,
- },
- },
- {
- property: "msTextSizeAdjust",
+ property: "textSizeAdjust",
value: {
type: "unit",
unit: "%",
@@ -910,9 +902,9 @@ export const styles = {
},
},
{
- property: "fontWidth",
+ property: "fontStretch",
value: {
- type: "invalid",
+ type: "keyword",
value: "initial",
},
},
@@ -933,8 +925,8 @@ export const styles = {
{
property: "fontFamily",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "unset",
},
},
{
@@ -1030,10 +1022,10 @@ export const styles = {
},
},
{
- property: "webkitAppearance",
+ property: "appearance",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "button",
},
},
{
@@ -1155,9 +1147,9 @@ export const styles = {
},
},
{
- property: "fontWidth",
+ property: "fontStretch",
value: {
- type: "invalid",
+ type: "keyword",
value: "initial",
},
},
@@ -1171,8 +1163,8 @@ export const styles = {
{
property: "fontFamily",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "unset",
},
},
{
@@ -1356,10 +1348,10 @@ export const styles = {
},
},
{
- property: "webkitAppearance",
+ property: "appearance",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "button",
},
},
],
@@ -1386,9 +1378,9 @@ export const styles = {
},
},
{
- property: "fontWidth",
+ property: "fontStretch",
value: {
- type: "invalid",
+ type: "keyword",
value: "initial",
},
},
@@ -1409,8 +1401,8 @@ export const styles = {
{
property: "fontFamily",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "unset",
},
},
{
@@ -1483,9 +1475,9 @@ export const styles = {
},
},
{
- property: "fontWidth",
+ property: "fontStretch",
value: {
- type: "invalid",
+ type: "keyword",
value: "initial",
},
},
@@ -1506,8 +1498,8 @@ export const styles = {
{
property: "fontFamily",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "unset",
},
},
{
@@ -1580,9 +1572,9 @@ export const styles = {
},
},
{
- property: "fontWidth",
+ property: "fontStretch",
value: {
- type: "invalid",
+ type: "keyword",
value: "initial",
},
},
@@ -1603,8 +1595,8 @@ export const styles = {
{
property: "fontFamily",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "unset",
},
},
{
@@ -2648,10 +2640,10 @@ export const styles = {
},
},
{
- property: "webkitAppearance",
+ property: "appearance",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "button",
},
},
],
@@ -2798,13 +2790,6 @@ export const styles = {
value: "inherit",
},
},
- {
- property: "webkitTextDecoration",
- value: {
- type: "invalid",
- value: "",
- },
- },
{
property: "textIndent",
value: {
@@ -3061,7 +3046,7 @@ export const styles = {
property: "boxShadow",
value: {
type: "unparsed",
- value: "0 0 0 1px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.1)",
+ value: "0 0 0 1px rgba(0,0,0,0.1),0 1px 3px rgba(0,0,0,0.1)",
},
},
{
@@ -7691,7 +7676,7 @@ export const styles = {
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "rgb",
alpha: 0,
@@ -7879,7 +7864,7 @@ export const styles = {
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "rgb",
alpha: 0,
@@ -8049,7 +8034,7 @@ export const styles = {
property: "boxShadow",
value: {
type: "unparsed",
- value: "0 0 3px rgba(51,51,51,.4)",
+ value: "0 0 3px rgba(51,51,51,0.4)",
},
},
],
@@ -8151,7 +8136,7 @@ export const styles = {
property: "transitionDuration",
value: {
type: "unparsed",
- value: ".1s,.1s",
+ value: "0.1s,0.1s",
},
},
{
@@ -8165,7 +8150,7 @@ export const styles = {
property: "transitionDelay",
value: {
type: "unparsed",
- value: ".1s,.1s",
+ value: "0.1s,0.1s",
},
},
{
@@ -8251,7 +8236,7 @@ export const styles = {
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "rgb",
alpha: 0,
@@ -8267,20 +8252,6 @@ export const styles = {
value: "rgba(0,0,0,0)",
},
},
- {
- property: "webkitUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
- {
- property: "msUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
{
property: "userSelect",
value: {
@@ -8437,7 +8408,7 @@ export const styles = {
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "rgb",
alpha: 0,
@@ -8453,20 +8424,6 @@ export const styles = {
value: "rgba(0,0,0,0)",
},
},
- {
- property: "webkitUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
- {
- property: "msUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
{
property: "userSelect",
value: {
@@ -9058,20 +9015,6 @@ export const styles = {
value: "relative",
},
},
- {
- property: "webkitUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
- {
- property: "msUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
{
property: "userSelect",
value: {
@@ -9519,21 +9462,14 @@ export const styles = {
},
},
{
- property: "webkitUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
- {
- property: "mozUserSelect",
+ property: "userSelect",
value: {
- type: "invalid",
- value: "",
+ type: "keyword",
+ value: "none",
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "invalid",
value: "",
@@ -9677,14 +9613,14 @@ export const styles = {
},
},
{
- property: "webkitTransform",
+ property: "transform",
value: {
type: "unparsed",
value: "translate(0)",
},
},
{
- property: "webkitOverflowScrolling",
+ property: "WebkitOverflowScrolling",
value: {
type: "invalid",
value: "",
@@ -9715,7 +9651,7 @@ export const styles = {
],
"w-lightbox-container": [
{
- property: "webkitOverflowScrolling",
+ property: "WebkitOverflowScrolling",
value: {
type: "invalid",
value: "",
@@ -10524,7 +10460,7 @@ export const styles = {
},
},
{
- property: "webkitTransform",
+ property: "transform",
value: {
type: "unparsed",
value: "translate3d(0,0,0)",
@@ -11814,7 +11750,7 @@ export const styles = {
},
},
{
- property: "webkitTapHighlightColor",
+ property: "WebkitTapHighlightColor",
value: {
type: "rgb",
alpha: 0,
@@ -11830,20 +11766,6 @@ export const styles = {
value: "rgba(0,0,0,0)",
},
},
- {
- property: "webkitUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
- {
- property: "msUserSelect",
- value: {
- type: "invalid",
- value: "",
- },
- },
{
property: "userSelect",
value: {
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/instances-properties.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/instances-properties.ts
index 38aa2246b1..7d66f79892 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/instances-properties.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/instances-properties.ts
@@ -305,6 +305,16 @@ const toFragment = (
addInstance(component);
return fragment;
}
+ case "FormSelect": {
+ // @todo https://github.com/webstudio-is/webstudio/issues/3601
+ const component = "Input";
+ const data = wfNode.data;
+ addProp("name", data.attr.name);
+ addProp("required", data.attr.required, "boolean");
+ addProp("multiple", data.attr.multiple, "boolean");
+ addInstance(component);
+ return fragment;
+ }
}
(component) satisfies never;
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.tsx
index 6e1d5f4090..bfc029a240 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
@@ -1466,6 +1466,57 @@ test("FormRadioWrapper, FormRadioInput, FormInlineLabel", async () => {
);
});
+test("FormSelect", async () => {
+ const fragment = await toWebstudioFragment({
+ type: "@webflow/XscpData",
+ payload: {
+ nodes: [
+ {
+ _id: "a68c34ca-e4c3-3dbc-0036-2554387bd7a4",
+ type: "FormSelect",
+ tag: "select",
+ classes: [],
+ children: [],
+ data: {
+ form: {
+ opts: [
+ {
+ t: "Select one...",
+ v: "",
+ },
+ {
+ t: "First choice",
+ v: "First",
+ },
+ {
+ t: "Second choice",
+ v: "Second",
+ },
+ {
+ t: "Third choice",
+ v: "Third",
+ },
+ ],
+ },
+ attr: {
+ id: "field-3",
+ name: "field-3",
+ required: false,
+ multiple: false,
+ },
+ },
+ },
+ ],
+ styles: [],
+ },
+ });
+
+ equalFragment(
+ fragment,
+ <$.Input id="field-3" name="field-3" required={false} multiple={false} />
+ );
+});
+
describe("Custom attributes", () => {
test("Basic", async () => {
const fragment = await toWebstudioFragment({
@@ -1639,6 +1690,40 @@ describe("Styles", () => {
}"
`);
});
+
+ test("Webflow @variable syntax used by Relume (legacy?)", async () => {
+ const fragment = await toWebstudioFragment({
+ type: "@webflow/XscpData",
+ payload: {
+ nodes: [
+ {
+ _id: "5f7ab979-89b3-c705-6ab9-35f77dfb209f",
+ type: "Block",
+ tag: "div",
+ classes: ["194e7d07-469d-6ffa-3925-1f51bdad7e44"],
+ children: [],
+ },
+ ],
+ styles: [
+ {
+ _id: "194e7d07-469d-6ffa-3925-1f51bdad7e44",
+ type: "class",
+ name: "block",
+ styleLess: "color: @var_relume-variable-color-neutral-1",
+ children: [],
+ },
+ ],
+ },
+ });
+
+ expect(toCss(fragment)).toMatchInlineSnapshot(`
+ "@media all {
+ block {
+ color: unset
+ }
+ }"
+ `);
+ });
});
test("Breakpoints", async () => {
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts
index b0699449a3..8371538861 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts
@@ -13,7 +13,6 @@ import {
$selectedInstanceSelector,
$selectedPage,
} from "../../nano-states";
-import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import { WfData, WfNode, WfStyle, wfNodeTypes } from "./schema";
import { addInstanceAndProperties } from "./instances-properties";
import { addStyles } from "./styles";
@@ -112,9 +111,6 @@ const parse = (clipboardData: string) => {
};
export const onPaste = async (clipboardData: string) => {
- if (isFeatureEnabled("pasteFromWebflow") === false) {
- return false;
- }
const wfData = parse(clipboardData);
if (wfData === undefined) {
return false;
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts
index dc3504b89d..923a768267 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts
@@ -60,6 +60,7 @@ export const wfNodeTypes = [
"FormInlineLabel",
"FormRadioWrapper",
"FormRadioInput",
+ "FormSelect",
] as const;
export const WfElementNode = z.union([
@@ -212,6 +213,24 @@ export const WfElementNode = z.union([
}),
}),
}),
+ WfBaseNode.extend({
+ type: z.enum(["FormSelect"]),
+ data: WfNodeData.extend({
+ attr: Attr.extend({
+ name: z.string(),
+ required: z.boolean(),
+ multiple: z.boolean(),
+ }),
+ form: z.object({
+ opts: z.array(
+ z.object({
+ t: z.string(),
+ v: z.string(),
+ })
+ ),
+ }),
+ }),
+ }),
]);
export type WfElementNode = z.infer<typeof WfElementNode>;
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
index fda7a709f1..54d917e332 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
@@ -48,6 +48,14 @@ const findWsBreakpoint = (
});
};
+// Apparently webflow supports this variable notation: `color: @var_relume-variable-color-neutral-1`
+// Until actual variables are supported, we need to replace it with "unset",
+// otherwise property will be skipped and that will result in an inherited value, which is more problematic.
+// @todo use CSS variables once this is done https://github.com/webstudio-is/webstudio/issues/3399
+const replaceAtVariables = (styles: string) => {
+ return styles.replace(/@var_[\w-]+/g, "unset");
+};
+
type UnparsedVariants = Map<
WfBreakpointName,
string | Array<EmbedTemplateStyleDecl>
@@ -65,7 +73,8 @@ const toParsedVariants = (variants: UnparsedVariants) => {
for (const [breakpointName, styles] of variants) {
if (typeof styles === "string") {
try {
- const parsed = parseCss(`.styles {${styles}}`).styles ?? [];
+ const parsed =
+ parseCss(`.styles {${replaceAtVariables(styles)}}`).styles ?? [];
parsedVariants.set(breakpointName, parsed);
} catch (error) {
console.error("Failed to parse style", error, breakpointName, styles);
@@ -176,7 +185,7 @@ const addNodeStyles = ({
state: style.state,
});
if (style.value.type === "invalid") {
- const error = `Invalid style value: "${kebabCase(style.property)}: ${style.value.value}"`;
+ const error = `Invalid style value: ${name} "${kebabCase(style.property)}: ${style.value.value}"`;
toast.error(error);
console.error(error);
}
diff --git a/packages/css-data/src/parse-css-value.ts b/packages/css-data/src/parse-css-value.ts
index d41f28851e..97354b41fc 100644
--- a/packages/css-data/src/parse-css-value.ts
+++ b/packages/css-data/src/parse-css-value.ts
@@ -18,7 +18,7 @@ export const cssTryParseValue = (input: string) => {
const ast = csstree.parse(input, { context: "value" });
return ast;
} catch {
- return undefined;
+ return;
}
};
diff --git a/packages/css-data/src/parse-css.test.ts b/packages/css-data/src/parse-css.test.ts
index 0c626112da..6020476700 100644
--- a/packages/css-data/src/parse-css.test.ts
+++ b/packages/css-data/src/parse-css.test.ts
@@ -344,6 +344,81 @@ describe("Parse CSS", () => {
`);
});
+ // @todo https://github.com/webstudio-is/webstudio/issues/3399
+ test("parse variable", () => {
+ expect(parseCss(`a { color: var(--color) }`)).toMatchInlineSnapshot(`
+ {
+ "a": [
+ {
+ "property": "color",
+ "value": {
+ "type": "keyword",
+ "value": "unset",
+ },
+ },
+ ],
+ }
+ `);
+ });
+
+ test("parse empty value as unset", () => {
+ expect(parseCss(`a { color: ; background-color: red }`))
+ .toMatchInlineSnapshot(`
+ {
+ "a": [
+ {
+ "property": "color",
+ "value": {
+ "type": "keyword",
+ "value": "unset",
+ },
+ },
+ {
+ "property": "backgroundColor",
+ "value": {
+ "type": "keyword",
+ "value": "red",
+ },
+ },
+ ],
+ }
+ `);
+ });
+
+ test("unprefix property that doesn't need a prefix", () => {
+ expect(parseCss(`a { -webkit-color: red; }`)).toMatchInlineSnapshot(`
+ {
+ "a": [
+ {
+ "property": "color",
+ "value": {
+ "type": "keyword",
+ "value": "red",
+ },
+ },
+ ],
+ }
+ `);
+ });
+
+ test("keep prefix for property that needs one", () => {
+ // @todo parser is wrong here, it should be keyword horizontal
+ expect(parseCss(`a { -webkit-box-orient: horizontal; }`))
+ .toMatchInlineSnapshot(`
+ {
+ "a": [
+ {
+ "property": "WebkitBoxOrient",
+ "value": {
+ "type": "invalid",
+ "value": "",
+ },
+ },
+ ],
+ }
+ `);
+ });
+
test("parse child combinator", () => {
expect(parseCss(`a > b { color: #ff0000 }`)).toMatchInlineSnapshot(`{}`);
});
diff --git a/packages/css-data/src/parse-css.ts b/packages/css-data/src/parse-css.ts
index 3dbe573e93..4a07b65c01 100644
--- a/packages/css-data/src/parse-css.ts
+++ b/packages/css-data/src/parse-css.ts
@@ -7,6 +7,33 @@ import * as toLonghand from "./property-parsers/to-longhand";
import { camelCase } from "change-case";
import { expandShorthands } from "./shorthands";
+// @todo we don't parse correctly most of them if not all
+const prefixedProperties = [
+ "-webkit-box-orient",
+ "-webkit-line-clamp",
+ "-webkit-font-smoothing",
+ "-moz-osx-font-smoothing",
+ "-webkit-tap-highlight-color",
+ "-webkit-overflow-scrolling",
+];
+const prefixes = ["webkit", "moz", "ms", "o"];
+const prefixRegex = new RegExp(`^-(${prefixes.join("|")})-`);
+
+const unprefixProperty = (property: string) => {
+ if (prefixedProperties.includes(property)) {
+ return property;
+ }
+ return property.replace(prefixRegex, "");
+};
+
+const camelCaseProperty = (property: string) => {
+ let camelcased = camelCase(property);
+ if (property[0] === "-") {
+ camelcased = camelcased[0].toLocaleUpperCase() + camelcased.slice(1);
+ }
+ return camelcased;
+};
+
type Selector = string;
export type Styles = Record<Selector, Array<EmbedTemplateStyleDecl>>;
@@ -31,7 +58,6 @@ const parseCssValue = (
if (typeof valueParser === "function") {
return [property, valueParser(value)];
}
-
if (Array.isArray(value)) {
return [
property,
@@ -57,6 +83,19 @@ const parseCssValue = (
const expanded = new Map(expandShorthands([[property, value]]));
const final = new Map();
for (const [property, value] of expanded) {
+ if (value === "") {
+ // Keep the browser behavior when property is defined with an empty value e.g. `color:;`
+ // It may override some existing value and effectively set it to "unset";
+ final.set(property, { type: "keyword", value: "unset" });
+ continue;
+ }
+
+ // @todo https://github.com/webstudio-is/webstudio/issues/3399
+ if (value.startsWith("var(")) {
+ final.set(property, { type: "keyword", value: "unset" });
+ continue;
+ }
+
final.set(
property,
parseCssValueLonghand(property as StyleProperty, value)
@@ -117,7 +156,7 @@ export const parseCss = (css: string) => {
const stringValue = csstree.generate(node.value);
const parsedCss = parseCssValue(
- node.property as Longhand | StyleProperty,
+ unprefixProperty(node.property) as Longhand | StyleProperty,
stringValue
);
@@ -130,9 +169,12 @@ export const parseCss = (css: string) => {
declarations = styles[selector] = [];
}
const styleDecl: EmbedTemplateStyleDecl = {
- property: camelCase(property) as StyleProperty,
+ property: camelCaseProperty(
+ unprefixProperty(property)
+ ) as StyleProperty,
value,
};
+
const statesArray = states.get(selector) ?? [];
if (statesArray[index]) {
styleDecl.state = statesArray[index];
diff --git a/packages/feature-flags/src/flags.ts b/packages/feature-flags/src/flags.ts
index 03cd16f3b5..64c5105bad 100644
--- a/packages/feature-flags/src/flags.ts
+++ b/packages/feature-flags/src/flags.ts
@@ -7,4 +7,3 @@ export const cms = false;
export const cssVars = false;
export const filters = false;
export const xmlElement = false;
-export const pasteFromWebflow = false;