fix: allow to paste multiple gradients at pnce (#3842)

Ref
https://discord.com/channels/955905230107738152/1268162090934206494/1268162090934206494

This regressed while refactoring with new parser.
This commit is contained in:
Bogdan Chadkin authored and GitHub committed 2024-07-31 13:49:14 +02:00
1 parent 87d841f808
commit 2dd08eda6d
1 file changed
+13 -7
@@ -1,4 +1,8 @@
import type { InvalidValue, StyleValue } from "@webstudio-is/css-engine";
import type {
InvalidValue,
LayersValue,
StyleValue,
} from "@webstudio-is/css-engine";
import { parseCssValue } from "@webstudio-is/css-data";
import {
Flex,
@@ -69,16 +73,17 @@ export const BackgroundGradient = (
const parsed = parseCssFragment(intermediateValue.value, "background");
const backgroundImage = parsed.get("backgroundImage");
const backgroundColor = parsed.get("backgroundColor");
const [layer] =
const layers: LayersValue =
backgroundImage?.type === "layers"
? backgroundImage.value
: [backgroundImage];
? backgroundImage
: { type: "layers", value: [] };
const [firstLayer] = layers.value;
// set invalid state
if (
backgroundColor?.type === "invalid" ||
layer === undefined ||
layer.type === "invalid"
layers.value.length === 0 ||
firstLayer.type === "invalid"
) {
setIntermediateValue({ type: "invalid", value: intermediateValue.value });
props.deleteProperty(property, { isEphemeral: true });
@@ -88,7 +93,8 @@ export const BackgroundGradient = (
if (backgroundColor && isTransparent(backgroundColor) === false) {
props.setBackgroundColor(backgroundColor);
}
props.setProperty(property)(layer);
// insert all new layers at current position
props.setProperty(property)(layers);
};
const handleOnCompleteRef = useRef(handleOnComplete);