fix: skip unsupported style updates
This commit is contained in:
@@ -10,7 +10,15 @@ import {
|
|||||||
import { Excalidraw } from "../index";
|
import { Excalidraw } from "../index";
|
||||||
import { API } from "../tests/helpers/api";
|
import { API } from "../tests/helpers/api";
|
||||||
import { UI } from "../tests/helpers/ui";
|
import { UI } from "../tests/helpers/ui";
|
||||||
import { render } from "../tests/test-utils";
|
import { act, render } from "../tests/test-utils";
|
||||||
|
|
||||||
|
import {
|
||||||
|
actionChangeBackgroundColor,
|
||||||
|
actionChangeRoundness,
|
||||||
|
actionChangeStrokeWidth,
|
||||||
|
} from "./actionProperties";
|
||||||
|
|
||||||
|
const { h } = window;
|
||||||
|
|
||||||
describe("element locking", () => {
|
describe("element locking", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -184,5 +192,72 @@ describe("element locking", () => {
|
|||||||
"active",
|
"active",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not update text background when changing background in mixed frame selection", () => {
|
||||||
|
const frame = API.createElement({
|
||||||
|
type: "frame",
|
||||||
|
});
|
||||||
|
const text = API.createElement({
|
||||||
|
type: "text",
|
||||||
|
backgroundColor: COLOR_PALETTE.transparent,
|
||||||
|
});
|
||||||
|
API.setElements([text, frame]);
|
||||||
|
API.setSelectedElements([text, frame]);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
h.app.actionManager.executeAction(actionChangeBackgroundColor, "ui", {
|
||||||
|
currentItemBackgroundColor: "#ffc9c9",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(API.getElement(frame).backgroundColor).toBe("#ffc9c9");
|
||||||
|
expect(API.getElement(text).backgroundColor).toBe(
|
||||||
|
COLOR_PALETTE.transparent,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not update frame stroke width when changing stroke width in mixed selection", () => {
|
||||||
|
const frame = API.createElement({
|
||||||
|
type: "frame",
|
||||||
|
});
|
||||||
|
const rect = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
strokeWidth: STROKE_WIDTH.thin,
|
||||||
|
});
|
||||||
|
API.setElements([rect, frame]);
|
||||||
|
API.setSelectedElements([rect, frame]);
|
||||||
|
|
||||||
|
const originalFrameStrokeWidth = API.getElement(frame).strokeWidth;
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
h.app.actionManager.executeAction(
|
||||||
|
actionChangeStrokeWidth,
|
||||||
|
"ui",
|
||||||
|
STROKE_WIDTH.extraBold,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(API.getElement(rect).strokeWidth).toBe(STROKE_WIDTH.extraBold);
|
||||||
|
expect(API.getElement(frame).strokeWidth).toBe(originalFrameStrokeWidth);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not update frame roundness when changing roundness in mixed selection", () => {
|
||||||
|
const frame = API.createElement({
|
||||||
|
type: "frame",
|
||||||
|
});
|
||||||
|
const rect = API.createElement({
|
||||||
|
type: "rectangle",
|
||||||
|
roundness: null,
|
||||||
|
});
|
||||||
|
API.setElements([rect, frame]);
|
||||||
|
API.setSelectedElements([rect, frame]);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
h.app.actionManager.executeAction(actionChangeRoundness, "ui", "round");
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(API.getElement(rect).roundness).not.toBe(null);
|
||||||
|
expect(API.getElement(frame).roundness).toBe(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
isBoundToContainer,
|
isBoundToContainer,
|
||||||
|
isFrameElement,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isLineElement,
|
isLineElement,
|
||||||
@@ -52,7 +53,13 @@ import {
|
|||||||
isUsingAdaptiveRadius,
|
isUsingAdaptiveRadius,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import { hasStrokeColor } from "@excalidraw/element";
|
import {
|
||||||
|
canChangeRoundness,
|
||||||
|
hasBackground,
|
||||||
|
hasStrokeColor,
|
||||||
|
hasStrokeStyle,
|
||||||
|
hasStrokeWidth,
|
||||||
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
updateElbowArrowPoints,
|
updateElbowArrowPoints,
|
||||||
@@ -409,11 +416,13 @@ export const actionChangeBackgroundColor = register<
|
|||||||
return el;
|
return el;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
nextElements = changeProperty(elements, appState, (el) =>
|
nextElements = changeProperty(elements, appState, (el) => {
|
||||||
newElementWith(el, {
|
return hasBackground(el.type) || isFrameElement(el)
|
||||||
backgroundColor: value.currentItemBackgroundColor,
|
? newElementWith(el, {
|
||||||
}),
|
backgroundColor: value.currentItemBackgroundColor,
|
||||||
);
|
})
|
||||||
|
: el;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -476,11 +485,13 @@ export const actionChangeFillStyle = register<ExcalidrawElement["fillStyle"]>({
|
|||||||
})`,
|
})`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
newElementWith(el, {
|
return hasBackground(el.type)
|
||||||
fillStyle: value,
|
? newElementWith(el, {
|
||||||
}),
|
fillStyle: value,
|
||||||
),
|
})
|
||||||
|
: el;
|
||||||
|
}),
|
||||||
appState: { ...appState, currentItemFillStyle: value },
|
appState: { ...appState, currentItemFillStyle: value },
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -553,11 +564,13 @@ export const actionChangeStrokeWidth = register<
|
|||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
newElementWith(el, {
|
return hasStrokeWidth(el.type)
|
||||||
strokeWidth: value,
|
? newElementWith(el, {
|
||||||
}),
|
strokeWidth: value,
|
||||||
),
|
})
|
||||||
|
: el;
|
||||||
|
}),
|
||||||
appState: { ...appState, currentItemStrokeWidth: value },
|
appState: { ...appState, currentItemStrokeWidth: value },
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -609,12 +622,14 @@ export const actionChangeSloppiness = register<ExcalidrawElement["roughness"]>({
|
|||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
newElementWith(el, {
|
return hasStrokeStyle(el.type)
|
||||||
seed: randomInteger(),
|
? newElementWith(el, {
|
||||||
roughness: value,
|
seed: randomInteger(),
|
||||||
}),
|
roughness: value,
|
||||||
),
|
})
|
||||||
|
: el;
|
||||||
|
}),
|
||||||
appState: { ...appState, currentItemRoughness: value },
|
appState: { ...appState, currentItemRoughness: value },
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -665,11 +680,13 @@ export const actionChangeStrokeStyle = register<
|
|||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) =>
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
newElementWith(el, {
|
return hasStrokeStyle(el.type)
|
||||||
strokeStyle: value,
|
? newElementWith(el, {
|
||||||
}),
|
strokeStyle: value,
|
||||||
),
|
})
|
||||||
|
: el;
|
||||||
|
}),
|
||||||
appState: { ...appState, currentItemStrokeStyle: value },
|
appState: { ...appState, currentItemStrokeStyle: value },
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
@@ -1481,7 +1498,7 @@ export const actionChangeRoundness = register<"sharp" | "round">({
|
|||||||
perform: (elements, appState, value) => {
|
perform: (elements, appState, value) => {
|
||||||
return {
|
return {
|
||||||
elements: changeProperty(elements, appState, (el) => {
|
elements: changeProperty(elements, appState, (el) => {
|
||||||
if (isElbowArrow(el)) {
|
if (isElbowArrow(el) || !canChangeRoundness(el.type)) {
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user