frame bg: normalize false flag to transparent
This commit is contained in:
@@ -509,17 +509,16 @@ export const restoreElement = (
|
|||||||
name: element.name ?? null,
|
name: element.name ?? null,
|
||||||
});
|
});
|
||||||
case "frame":
|
case "frame":
|
||||||
const hasBackgroundEnabled =
|
const backgroundEnabled =
|
||||||
typeof (element as any).backgroundEnabled === "boolean";
|
typeof (element as any).backgroundEnabled === "boolean"
|
||||||
const backgroundEnabled = hasBackgroundEnabled
|
? (element as any).backgroundEnabled
|
||||||
? (element as any).backgroundEnabled
|
: false;
|
||||||
: false;
|
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
name: element.name ?? null,
|
name: element.name ?? null,
|
||||||
backgroundEnabled,
|
backgroundEnabled,
|
||||||
...(hasBackgroundEnabled
|
...(!backgroundEnabled
|
||||||
? {}
|
? { backgroundColor: DEFAULT_ELEMENT_PROPS.backgroundColor }
|
||||||
: { backgroundColor: DEFAULT_ELEMENT_PROPS.backgroundColor }),
|
: {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Don't use default case so as to catch a missing an element type case.
|
// Don't use default case so as to catch a missing an element type case.
|
||||||
|
|||||||
@@ -118,6 +118,22 @@ describe("restoreElements", () => {
|
|||||||
expect(restoredFrame.backgroundEnabled).toBe(false);
|
expect(restoredFrame.backgroundEnabled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should normalize frame background color when backgroundEnabled is false", () => {
|
||||||
|
const frame = API.createElement({
|
||||||
|
type: "frame",
|
||||||
|
backgroundColor: "#ffc9c9",
|
||||||
|
});
|
||||||
|
frame.backgroundEnabled = false;
|
||||||
|
|
||||||
|
const restoredFrame = restore.restoreElements(
|
||||||
|
[frame],
|
||||||
|
null,
|
||||||
|
)[0] as ExcalidrawFrameElement;
|
||||||
|
|
||||||
|
expect(restoredFrame.backgroundColor).toBe("transparent");
|
||||||
|
expect(restoredFrame.backgroundEnabled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("should preserve frame backgroundEnabled when present", () => {
|
it("should preserve frame backgroundEnabled when present", () => {
|
||||||
const frame = API.createElement({
|
const frame = API.createElement({
|
||||||
type: "frame",
|
type: "frame",
|
||||||
@@ -130,6 +146,7 @@ describe("restoreElements", () => {
|
|||||||
null,
|
null,
|
||||||
)[0] as ExcalidrawFrameElement;
|
)[0] as ExcalidrawFrameElement;
|
||||||
|
|
||||||
|
expect(restoredFrame.backgroundColor).toBe("#ffc9c9");
|
||||||
expect(restoredFrame.backgroundEnabled).toBe(true);
|
expect(restoredFrame.backgroundEnabled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user