frame bg: treat non-boolean legacy flag as missing
This commit is contained in:
@@ -509,11 +509,11 @@ export const restoreElement = (
|
|||||||
name: element.name ?? null,
|
name: element.name ?? null,
|
||||||
});
|
});
|
||||||
case "frame":
|
case "frame":
|
||||||
const hasBackgroundEnabled = Object.prototype.hasOwnProperty.call(
|
const hasBackgroundEnabled =
|
||||||
element,
|
typeof (element as any).backgroundEnabled === "boolean";
|
||||||
"backgroundEnabled",
|
const backgroundEnabled = hasBackgroundEnabled
|
||||||
);
|
? (element as any).backgroundEnabled
|
||||||
const backgroundEnabled = (element as any).backgroundEnabled ?? false;
|
: false;
|
||||||
return restoreElementWithProperties(element, {
|
return restoreElementWithProperties(element, {
|
||||||
name: element.name ?? null,
|
name: element.name ?? null,
|
||||||
backgroundEnabled,
|
backgroundEnabled,
|
||||||
|
|||||||
@@ -99,6 +99,25 @@ describe("restoreElements", () => {
|
|||||||
expect(restoredFrame.backgroundEnabled).toBe(false);
|
expect(restoredFrame.backgroundEnabled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should disable frame background when legacy backgroundEnabled is non-boolean", () => {
|
||||||
|
const frame = API.createElement({
|
||||||
|
type: "frame",
|
||||||
|
backgroundColor: "#ffc9c9",
|
||||||
|
});
|
||||||
|
const legacyFrame = {
|
||||||
|
...frame,
|
||||||
|
backgroundEnabled: undefined,
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
const restoredFrame = restore.restoreElements(
|
||||||
|
[legacyFrame],
|
||||||
|
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",
|
||||||
|
|||||||
Reference in New Issue
Block a user